Esempio 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)

}
Esempio 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)
	}

}
Esempio n. 3
0
func TestLocal(t *testing.T) {

	net := Build()
	t.Log(net)

	js := protocol.PackLegible(net)
	ioutil.WriteFile("/marina/site/testsite.json", js, 0644)
}
Esempio n. 4
0
func TestLocal(t *testing.T) {

	//Build the network
	net := Build()
	t.Log(net)

	return

	//Pack the network into a json file
	js := protocol.PackLegible(net)
	t.Log(string(js))

	//Unpack the network from a json file
	_net, err := protocol.UnpackNetwork(js)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(_net)

}