當前位置: 首頁>>代碼示例>>Golang>>正文


Golang graph.Graph類代碼示例

本文整理匯總了Golang中github.com/redhat-cip/skydive/topology/graph.Graph的典型用法代碼示例。如果您正苦於以下問題:Golang Graph類的具體用法?Golang Graph怎麽用?Golang Graph使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Graph類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: startTopologyClient

func startTopologyClient(t *testing.T, g *graph.Graph, onReady func(*websocket.Conn), onChange func(*websocket.Conn)) error {
	// ready when got a first ping
	ws, err := connectToAgent(5, onReady)
	if err != nil {
		return err
	}

	for {
		_, m, err := ws.ReadMessage()
		if err != nil {
			break
		}

		err = processGraphMessage(g, m)
		if err != nil {
			return err
		}

		logging.GetLogger().Debug("%s", string(m))
		logging.GetLogger().Debug("%s", g.String())

		onChange(ws)
	}

	return nil
}
開發者ID:mestery,項目名稱:skydive,代碼行數:26,代碼來源:topology_test.go

示例2: LookupNodeFromNodePathString

func LookupNodeFromNodePathString(g *graph.Graph, s string) *graph.Node {
	parts := strings.Split(s, "/")

	m, err := nodePathPartToMetadata(parts[0])
	if err != nil {
		logging.GetLogger().Errorf("Unable to parse a part of node path string (%s): %s", parts[0], err.Error())
		return nil
	}

	node := g.LookupFirstNode(m)
	if node == nil {
		return nil
	}

	for _, part := range parts[1:] {
		m, err := nodePathPartToMetadata(part)
		if err != nil {
			return nil
		}

		node = g.LookupFirstChild(node, m)
		if node == nil {
			return nil
		}
	}

	return node
}
開發者ID:fdebonneval,項目名稱:skydive,代碼行數:28,代碼來源:topology.go

示例3: testCleanup

func testCleanup(t *testing.T, g *graph.Graph, cmds []string, ints []string) {
	// cleanup side on the test
	testPassed := false
	onChange := func(ws *websocket.Conn) {
		g.Lock()
		defer g.Unlock()

		if !testPassed {
			clean := true
			for _, intf := range ints {
				n := g.LookupFirstNode(graph.Metadatas{"Name": intf})
				if n != nil {
					clean = false
					break
				}
			}

			if clean {
				testPassed = true

				ws.Close()
			}
		}
	}

	testTopology(t, g, cmds, onChange)
	if !testPassed {
		t.Error("test not executed or failed")
	}
}
開發者ID:mestery,項目名稱:skydive,代碼行數:30,代碼來源:topology_test.go

示例4: NewNeutronMapper

func NewNeutronMapper(g *graph.Graph, authURL string, username string, password string, tenantName string, regionName string) (*NeutronMapper, error) {
	mapper := &NeutronMapper{graph: g}

	opts := gophercloud.AuthOptions{
		IdentityEndpoint: authURL,
		Username:         username,
		Password:         password,
		TenantName:       tenantName,
		AllowReauth:      true,
	}

	provider, err := openstack.AuthenticatedClient(opts)
	if err != nil {
		return nil, err
	}

	/* TODO(safchain) add config param for the Availability */
	client, err := openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
		Name:         "neutron",
		Region:       regionName,
		Availability: gophercloud.AvailabilityPublic,
	})
	if err != nil {
		return nil, err
	}
	mapper.client = client

	// Create a cache with a default expiration time of 5 minutes, and which
	// purges expired items every 30 seconds
	expire := config.GetConfig().GetInt("cache.expire")
	cleanup := config.GetConfig().GetInt("cache.cleanup")
	mapper.cache = cache.New(time.Duration(expire)*time.Second, time.Duration(cleanup)*time.Second)
	mapper.nodeUpdaterChan = make(chan graph.Identifier, 500)

	g.AddEventListener(mapper)

	return mapper, nil
}
開發者ID:fdebonneval,項目名稱:skydive,代碼行數:38,代碼來源:neutron.go

示例5: processGraphMessage

func processGraphMessage(g *graph.Graph, m []byte) error {
	g.Lock()
	defer g.Unlock()

	msg, err := graph.UnmarshalWSMessage(m)
	if err != nil {
		return err
	}

	switch msg.Type {
	case "NodeUpdated":
		n := msg.Obj.(*graph.Node)
		node := g.GetNode(n.ID)
		if node != nil {
			g.SetMetadatas(node, n.Metadatas())
		}
	case "NodeDeleted":
		g.DelNode(msg.Obj.(*graph.Node))
	case "NodeAdded":
		n := msg.Obj.(*graph.Node)
		if g.GetNode(n.ID) == nil {
			g.AddNode(n)
		}
	case "EdgeUpdated":
		e := msg.Obj.(*graph.Edge)
		edge := g.GetEdge(e.ID)
		if edge != nil {
			g.SetMetadatas(edge, e.Metadatas())
		}
	case "EdgeDeleted":
		g.DelEdge(msg.Obj.(*graph.Edge))
	case "EdgeAdded":
		e := msg.Obj.(*graph.Edge)
		if g.GetEdge(e.ID) == nil {
			g.AddEdge(e)
		}
	}

	return nil
}
開發者ID:mestery,項目名稱:skydive,代碼行數:40,代碼來源:topology_test.go


注:本文中的github.com/redhat-cip/skydive/topology/graph.Graph類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。