Beispiel #1
0
func newGraph(t *testing.T) *graph.Graph {
	backend, err := graph.NewMemoryBackend()
	if err != nil {
		t.Fatal(err.Error())
	}

	g, err := graph.NewGraph(backend)
	if err != nil {
		t.Fatal(err.Error())
	}

	return g
}
Beispiel #2
0
func NewAgent() *Agent {
	backend, err := graph.NewMemoryBackend()
	if err != nil {
		panic(err)
	}

	g, err := graph.NewGraph(backend)
	if err != nil {
		panic(err)
	}

	hostname, err := os.Hostname()
	if err != nil {
		panic(err)
	}

	ovsmon := ovsdb.NewOvsMonitorFromConfig()

	root := g.NewNode(graph.Identifier(hostname), graph.Metadatas{"Name": hostname, "Type": "host"})

	ns := tprobes.NewNetNSProbe(g, root)
	nl := tprobes.NewNetLinkProbe(g, root)
	ovs := tprobes.NewOvsdbProbe(g, root, ovsmon)

	router := mux.NewRouter().StrictSlash(true)

	server, err := topology.NewServerFromConfig("agent", g, router)
	if err != nil {
		panic(err)
	}

	server.RegisterStaticEndpoints()
	server.RegisterRpcEndpoints()

	gserver, err := graph.NewServerFromConfig(g, nil, router)
	if err != nil {
		panic(err)
	}

	return &Agent{
		Graph:       g,
		NsProbe:     ns,
		NlProbe:     nl,
		OvsMon:      ovsmon,
		OvsProbe:    ovs,
		TopoServer:  server,
		GraphServer: gserver,
		Root:        root,
	}
}
Beispiel #3
0
func NewAgent() *Agent {
	backend, err := graph.NewMemoryBackend()
	if err != nil {
		panic(err)
	}

	g, err := graph.NewGraph(backend)
	if err != nil {
		panic(err)
	}

	hostname, err := os.Hostname()
	if err != nil {
		panic(err)
	}

	hserver, err := shttp.NewServerFromConfig("agent")
	if err != nil {
		panic(err)
	}

	_, err = api.NewApi(hserver, nil)
	if err != nil {
		panic(err)
	}

	wsServer := shttp.NewWSServerFromConfig(hserver, "/ws")

	root := g.NewNode(graph.Identifier(hostname), graph.Metadata{"Name": hostname, "Type": "host"})

	api.RegisterTopologyApi("agent", g, hserver)

	gserver := graph.NewServer(g, wsServer)

	return &Agent{
		Graph:       g,
		WSServer:    wsServer,
		GraphServer: gserver,
		Root:        root,
		HTTPServer:  hserver,
	}
}
Beispiel #4
0
func NewAgent() *Agent {
	backend, err := graph.NewMemoryBackend()
	if err != nil {
		panic(err)
	}

	g, err := graph.NewGraph(backend)
	if err != nil {
		panic(err)
	}

	hostname, err := os.Hostname()
	if err != nil {
		panic(err)
	}

	root := g.NewNode(graph.Identifier(hostname), graph.Metadata{"Name": hostname, "Type": "host"})

	router := mux.NewRouter().StrictSlash(true)

	server, err := topology.NewServerFromConfig("agent", g, router)
	if err != nil {
		panic(err)
	}

	server.RegisterStaticEndpoints()
	server.RegisterRPCEndpoints()

	gserver, err := graph.NewServerFromConfig(g, nil, router)
	if err != nil {
		panic(err)
	}

	return &Agent{
		Graph:          g,
		TopologyServer: server,
		GraphServer:    gserver,
		Root:           root,
	}
}
Beispiel #5
0
func newGraph(t *testing.T) *graph.Graph {
	var backend graph.GraphBackend
	var err error
	switch graphBackend {
	case "gremlin-ws":
		backend, err = graph.NewGremlinBackend("ws://127.0.0.1:8182")
	case "gremlin-rest":
		backend, err = graph.NewGremlinBackend("http://127.0.0.1:8182?gremlin=")
	default:
		backend, err = graph.NewMemoryBackend()
	}

	if err != nil {
		t.Fatal(err.Error())
	}

	t.Logf("Using %s as backend", graphBackend)

	g, err := graph.NewGraph(backend)
	if err != nil {
		t.Fatal(err.Error())
	}

	hostname, err := os.Hostname()
	if err != nil {
		t.Fatal(err.Error())
	}

	root := g.LookupFirstNode(graph.Metadata{"Name": hostname, "Type": "host"})
	if root == nil {
		root = g.NewNode(graph.Identifier(hostname), graph.Metadata{"Name": hostname, "Type": "host"})
		if root == nil {
			t.Fatal("fail while adding root node")
		}
	}

	return g
}