예제 #1
0
파일: main.go 프로젝트: cycps/addie
func onMstate(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	log.Println("addie fetching materialization state")

	ms, err := spi.ViewRealizations(user, ".*"+design.Name+".*")
	if err != nil {
		log.Println("spi call to get realizations failed")
		log.Println(err)
		w.WriteHeader(500)
		return
	}

	var js []byte
	if len(ms.Return) > 0 {
		js, err = json.Marshal(ms.Return[0])
	} else {
		js = []byte("[]")
	}

	if err != nil {
		log.Println(err)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.Write(js)

}
예제 #2
0
파일: main.go 프로젝트: cycps/addie
func onMaterialize(w http.ResponseWriter, r *http.Request,
	ps httprouter.Params) {
	log.Println("addie materializing experiment")

	topDL, err := ioutil.ReadFile(topdlFileName())
	if err != nil {
		log.Println("unable to read topdl file :" + topdlFileName())
		w.WriteHeader(500)
		return
	}

	// Get active realizations
	log.Println("checking to see if we are already materialized")
	ms, err := spi.ViewRealizations(user, ".*"+design.Name+".*")
	if err != nil {
		log.Println("spi call to get realizations failed")
		log.Println(err)
		w.WriteHeader(500)
		return
	}
	if len(ms.Return) > 0 {
		msg := "the design is already materialize, de-materialize first to re-materialize"
		log.Println(msg)
		w.WriteHeader(400)
		fmt.Fprintf(w, msg)
		return
	}

	//++ Create
	log.Println("creating experiment")
	response, err := spi.CreateExperiment(user+":"+design.Name, user, string(topDL),
		false)
	if err != nil {
		log.Println("spi call to create experiment failed")
		log.Println(err)
		w.WriteHeader(500)
		return
	}
	if response != nil && response.Return != true {
		log.Println("the badness happend with the spi call to create experiment")
		w.WriteHeader(500)
		return
	}

	//~~ Realize
	log.Println("realizing experiment")
	mresponse, err := spi.RealizeExperiment(user+":"+design.Name, "cypress:cypress", user)
	if err != nil {
		log.Println("spi call to realize experiment failed")
		log.Println(err)
		w.WriteHeader(500)
		return
	}

	log.Println("realization response")
	log.Println(mresponse.Return)

	w.Write([]byte("ok"))
}
예제 #3
0
func view() {

	cli.PreRun()

	rsp, err := spi.ViewRealizations(cli.User, ".*")
	if err != nil {
		cli.Fatal(fmt.Sprintf("view realizations failed: %v", err))
	}
	for _, x := range rsp.Return {
		fmt.Printf("%s : %s\n", x.Name, x.Status)
	}

}
예제 #4
0
파일: main.go 프로젝트: cycps/addie
func onDeMaterialize(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	log.Println("dematerializing")
	rr, err := spi.RemoveRealization(user + ":" + design.Name + "-cypress:cypress")
	if err != nil {
		log.Println("spi call to remove realization failed")
		log.Println(err)
		w.WriteHeader(500)
		return
	}
	if rr.Return != true {
		log.Println("the badness happened with the spi call to remove realization")
		w.WriteHeader(500)
		return
	}

	dmat := false
	for dmat == false {
		// check dematerialization status
		time.Sleep(1 * time.Second)
		log.Println("checking realization shutdown")
		ms, err := spi.ViewRealizations(user, ".*"+design.Name+".*")
		if err != nil {
			log.Println("[dmat] spi call to get realizations failed")
			log.Println(err)
			w.WriteHeader(500)
			return
		}
		if len(ms.Return) == 0 {
			log.Println("dematerialization finished")
			dmat = true
		}
	}

	log.Println("removing experiment")
	rx, err := spi.RemoveExperiment(user + ":" + design.Name)
	if err != nil {
		log.Println("spi call to remove experiment failed")
		log.Println(err)
		w.WriteHeader(500)
		return
	}
	if rx.Return != true {
		log.Println("the badness happened with the spi call to remove experiment")
		w.WriteHeader(500)
		return
	}

}