Ejemplo n.º 1
0
func materialize(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	log.Println("[materialize]")

	rq := new(protocol.NetworkMaterializationRequest)
	err := protocol.Unpack(r.Body, rq)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		w.Header().Set("Content-Type", "application/json")
		d := protocol.Diagnostic{"error", "malformed json"}
		w.Write(protocol.PackWire(d))
		return
	}

	err, em := embed(&rq.Net, rq.Mapper)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		w.Header().Set("Content-Type", "application/json")
		d := protocol.Diagnostic{"error", fmt.Sprintf("materialization: %s", err)}
		w.Write(protocol.PackWire(d))
		return
	}

	xpdir := "/marina/xp/" + rq.Net.Name
	os.MkdirAll(xpdir, 0755)
	ioutil.WriteFile(xpdir+"/net.json", protocol.PackLegible(rq.Net), 0644)
	ioutil.WriteFile(xpdir+"/map.json", protocol.PackLegible(em), 0644)

}
Ejemplo n.º 2
0
func TestHarbor(t *testing.T) {

	//Build the network
	net := Build()

	netrq := protocol.NetworkMaterializationRequest{*net, "mcl"}

	//Pack the network into a json file
	js := protocol.PackLegible(netrq)

	//Request Materialization from harbormaster
	client := protocol.InsecureClient()
	resp, err := client.Post("https://localhost:4676/materialize", "application/json",
		bytes.NewBuffer(js))
	if err != nil {
		t.Fatal(err)
	}
	if resp.StatusCode == 200 {
		body, _ := ioutil.ReadAll(resp.Body)
		t.Log(string(body))
	} else {
		t.Logf("Response Status %d", resp.StatusCode)
		var diag protocol.Diagnostic
		protocol.Unpack(resp.Body, &diag)
		t.Fatal(diag)
	}

}