Пример #1
0
Файл: spi.go Проект: cycps/addie
func CreateDeterXP(user string, dsg *addie.Design) error {

	xp := DesignTopDL(dsg)

	//create a session with the DeterLab SPI
	_, err := spi.Login("deterboss", "muffins")
	if err != nil {
		log.Println(err)
		return fmt.Errorf("unable to login as deterboss")
	}

	topdl, err := xml.MarshalIndent(xp, "  ", "  ")
	if err != nil {
		log.Println(err)
		return fmt.Errorf("failed to serialize topology to topdl xml")
	}

	createResponse, err := spi.CreateExperiment(
		user+":"+dsg.Name, "deterboss", string(topdl), false)

	if err != nil {
		log.Println(err)
		return fmt.Errorf("failed to create experiment")
	}
	log.Printf("createResponse: %v", createResponse)

	return nil
}
Пример #2
0
func create() {

	if *xpF == "" {
		cli.Fatal(
			"you must specify an experiment name with the -xp flag, " +
				"use the -help flag for details")
	}

	if *srcF == "" {
		cli.Fatal(
			"you must specify a TopDL source file with the -src flag, " +
				"use the -help flag for details")
	}

	cli.PreRun()

	src, err := ioutil.ReadFile(*srcF)
	if err != nil {
		cli.Fatal(fmt.Sprintf("Failed to read source file '%s'", *srcF))
	}

	rsp, err := spi.CreateExperiment(*xpF, cli.User, string(src), false)
	if err != nil {
		cli.Fatal("create experiment failed")
	}

	if rsp.Return != true {
		cli.Fatal("create experiment returned false")
	}

}
Пример #3
0
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"))
}