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


Golang report.MakeIDList函數代碼示例

本文整理匯總了Golang中github.com/weaveworks/scope/report.MakeIDList函數的典型用法代碼示例。如果您正苦於以下問題:Golang MakeIDList函數的具體用法?Golang MakeIDList怎麽用?Golang MakeIDList使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: TestMergeRenderableNode

func TestMergeRenderableNode(t *testing.T) {
	node1 := render.RenderableNode{
		ID:         "foo",
		LabelMajor: "",
		LabelMinor: "minor",
		Rank:       "",
		Pseudo:     false,
		Node:       report.MakeNode().WithAdjacent("a1"),
		Origins:    report.MakeIDList("o1"),
	}
	node2 := render.RenderableNode{
		ID:         "foo",
		LabelMajor: "major",
		LabelMinor: "",
		Rank:       "rank",
		Pseudo:     false,
		Node:       report.MakeNode().WithAdjacent("a2"),
		Origins:    report.MakeIDList("o2"),
	}
	want := render.RenderableNode{
		ID:           "foo",
		LabelMajor:   "major",
		LabelMinor:   "minor",
		Rank:         "rank",
		Pseudo:       false,
		Node:         report.MakeNode().WithAdjacency(report.MakeIDList("a1", "a2")),
		Origins:      report.MakeIDList("o1", "o2"),
		EdgeMetadata: report.EdgeMetadata{},
	}
	have := node1.Merge(node2)
	if !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}
}
開發者ID:philipz,項目名稱:scope,代碼行數:34,代碼來源:renderable_node_test.go

示例2: Set

// Set the list of endpoints for the given hostname.
func (c *multiClient) Set(hostname string, endpoints []string) {
	wg := sync.WaitGroup{}
	wg.Add(len(endpoints))
	clients := make(chan clientTuple, len(endpoints))
	for _, endpoint := range endpoints {
		go func(endpoint string) {
			c.sema.acquire()
			defer c.sema.release()
			defer wg.Done()

			client, err := c.clientFactory(hostname, endpoint)
			if err != nil {
				log.Errorf("Error creating new app client: %v", err)
				return
			}

			details, err := client.Details()
			if err != nil {
				log.Errorf("Error fetching app details: %v", err)
				return
			}

			clients <- clientTuple{details, client}
		}(endpoint)
	}

	wg.Wait()
	close(clients)
	c.mtx.Lock()
	defer c.mtx.Unlock()

	// Start any new apps, and replace the list of app ids for this hostname
	hostIDs := report.MakeIDList()
	for tuple := range clients {
		hostIDs = hostIDs.Add(tuple.ID)

		_, ok := c.clients[tuple.ID]
		if !ok {
			c.clients[tuple.ID] = tuple.AppClient
			tuple.AppClient.ControlConnection()
		}
	}
	c.ids[hostname] = hostIDs

	// Remove apps that are no longer referenced (by id) from any hostname
	allReferencedIDs := report.MakeIDList()
	for _, ids := range c.ids {
		allReferencedIDs = allReferencedIDs.Add(ids...)
	}
	for id, client := range c.clients {
		if !allReferencedIDs.Contains(id) {
			client.Stop()
			delete(c.clients, id)
		}
	}
}
開發者ID:pauloheck,項目名稱:scope,代碼行數:57,代碼來源:multi_client.go

示例3: assertAdjacent

func assertAdjacent(t *testing.T, n report.RenderableNode, ids ...string) {
	want := report.MakeIDList(ids...)

	if have := n.Adjacency; !reflect.DeepEqual(want, have) {
		t.Fatalf("want adjacency list %v, have %v", want, have)
	}
}
開發者ID:rnd-ua,項目名稱:scope,代碼行數:7,代碼來源:easy_test.go

示例4: MakeRenderableNodes

// MakeRenderableNodes converts a topology to a set of RenderableNodes
func MakeRenderableNodes(t report.Topology) RenderableNodes {
	result := RenderableNodes{}
	for id, nmd := range t.Nodes {
		rn := NewRenderableNode(id).WithNode(nmd)
		rn.Origins = report.MakeIDList(id)
		if hostNodeID, ok := nmd.Metadata[report.HostNodeID]; ok {
			rn.Origins = rn.Origins.Add(hostNodeID)
		}
		result[id] = rn
	}

	// Push EdgeMetadata to both ends of the edges
	for srcID, srcNode := range result {
		for dstID, emd := range srcNode.Edges {
			srcNode.EdgeMetadata = srcNode.EdgeMetadata.Flatten(emd)

			dstNode := result[dstID]
			dstNode.EdgeMetadata = dstNode.EdgeMetadata.Flatten(emd.Reversed())
			result[dstID] = dstNode
		}

		result[srcID] = srcNode
	}
	return result
}
開發者ID:hrhelena,項目名稱:scope,代碼行數:26,代碼來源:selectors.go

示例5: TestFilterRender

func TestFilterRender(t *testing.T) {
	renderer := render.FilterUnconnected(
		mockRenderer{RenderableNodes: render.RenderableNodes{
			"foo": {ID: "foo", Adjacency: report.MakeIDList("bar"), NodeMetadata: report.MakeNodeMetadata()},
			"bar": {ID: "bar", Adjacency: report.MakeIDList("foo"), NodeMetadata: report.MakeNodeMetadata()},
			"baz": {ID: "baz", Adjacency: report.MakeIDList(), NodeMetadata: report.MakeNodeMetadata()},
		}})
	want := render.RenderableNodes{
		"foo": {ID: "foo", Adjacency: report.MakeIDList("bar"), NodeMetadata: report.MakeNodeMetadata()},
		"bar": {ID: "bar", Adjacency: report.MakeIDList("foo"), NodeMetadata: report.MakeNodeMetadata()},
	}
	have := sterilize(renderer.Render(report.MakeReport()), true)
	if !reflect.DeepEqual(want, have) {
		t.Errorf("want %+v, have %+v", want, have)
	}
}
開發者ID:cgvarela,項目名稱:scope,代碼行數:16,代碼來源:render_test.go

示例6: ids

func ids(nodes RenderableNodes) report.IDList {
	result := report.MakeIDList()
	for id := range nodes {
		result = result.Add(id)
	}
	return result
}
開發者ID:cgvarela,項目名稱:scope,代碼行數:7,代碼來源:render.go

示例7: TestMapEdge

func TestMapEdge(t *testing.T) {
	selector := func(_ report.Report) report.Topology {
		return report.Topology{
			NodeMetadatas: report.NodeMetadatas{
				"foo": report.NewNodeMetadata(map[string]string{"id": "foo"}),
				"bar": report.NewNodeMetadata(map[string]string{"id": "bar"}),
			},
			Adjacency: report.Adjacency{
				">foo": report.MakeIDList("bar"),
				">bar": report.MakeIDList("foo"),
			},
			EdgeMetadatas: report.EdgeMetadatas{
				"foo|bar": report.EdgeMetadata{WithBytes: true, BytesIngress: 1, BytesEgress: 2},
				"bar|foo": report.EdgeMetadata{WithBytes: true, BytesIngress: 3, BytesEgress: 4},
			},
		}
	}

	identity := func(nmd report.NodeMetadata) (render.RenderableNode, bool) {
		return render.NewRenderableNode(nmd.Metadata["id"], "", "", "", nmd), true
	}

	mapper := render.Map{
		MapFunc: func(nodes render.RenderableNode) (render.RenderableNode, bool) {
			return render.RenderableNode{ID: "_" + nodes.ID}, true
		},
		Renderer: render.LeafMap{
			Selector: selector,
			Mapper:   identity,
			Pseudo:   nil,
		},
	}

	want := render.AggregateMetadata{
		render.KeyBytesIngress: 1,
		render.KeyBytesEgress:  2,
	}
	have := mapper.AggregateMetadata(report.MakeReport(), "_foo", "_bar")
	if !reflect.DeepEqual(want, have) {
		t.Errorf("want %+v, have %+v", want, have)
	}
}
開發者ID:neviim,項目名稱:scope,代碼行數:42,代碼來源:render_test.go

示例8: TestMapRender3

func TestMapRender3(t *testing.T) {
	// 3. Check we can remap adjacencies
	mapper := render.Map{
		MapFunc: func(nodes render.RenderableNode) (render.RenderableNode, bool) {
			return render.RenderableNode{ID: "_" + nodes.ID}, true
		},
		Renderer: mockRenderer{RenderableNodes: render.RenderableNodes{
			"foo": {ID: "foo", Adjacency: report.MakeIDList("baz")},
			"baz": {ID: "baz", Adjacency: report.MakeIDList("foo")},
		}},
	}
	want := render.RenderableNodes{
		"_foo": {ID: "_foo", Adjacency: report.MakeIDList("_baz")},
		"_baz": {ID: "_baz", Adjacency: report.MakeIDList("_foo")},
	}
	have := mapper.Render(report.MakeReport())
	if !reflect.DeepEqual(want, have) {
		t.Errorf("want %+v, have %+v", want, have)
	}
}
開發者ID:neviim,項目名稱:scope,代碼行數:20,代碼來源:render_test.go

示例9: TestMapEdge

func TestMapEdge(t *testing.T) {
	selector := func(_ report.Report) report.Topology {
		return report.Topology{
			NodeMetadatas: report.NodeMetadatas{
				"foo": report.MakeNodeMetadataWith(map[string]string{"id": "foo"}),
				"bar": report.MakeNodeMetadataWith(map[string]string{"id": "bar"}),
			},
			Adjacency: report.Adjacency{
				">foo": report.MakeIDList("bar"),
				">bar": report.MakeIDList("foo"),
			},
			EdgeMetadatas: report.EdgeMetadatas{
				"foo|bar": report.EdgeMetadata{EgressPacketCount: newu64(1), EgressByteCount: newu64(2)},
				"bar|foo": report.EdgeMetadata{EgressPacketCount: newu64(3), EgressByteCount: newu64(4)},
			},
		}
	}

	identity := func(nmd report.NodeMetadata) render.RenderableNodes {
		return render.RenderableNodes{nmd.Metadata["id"]: render.NewRenderableNode(nmd.Metadata["id"], "", "", "", nmd)}
	}

	mapper := render.Map{
		MapFunc: func(nodes render.RenderableNode) render.RenderableNodes {
			id := "_" + nodes.ID
			return render.RenderableNodes{id: render.RenderableNode{ID: id}}
		},
		Renderer: render.LeafMap{
			Selector: selector,
			Mapper:   identity,
			Pseudo:   nil,
		},
	}

	if want, have := (report.EdgeMetadata{
		EgressPacketCount: newu64(1),
		EgressByteCount:   newu64(2),
	}), mapper.EdgeMetadata(report.MakeReport(), "_foo", "_bar"); !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}
}
開發者ID:cgvarela,項目名稱:scope,代碼行數:41,代碼來源:render_test.go

示例10: NewRenderableNode

// NewRenderableNode makes a new RenderableNode
func NewRenderableNode(id string) RenderableNode {
	return RenderableNode{
		ID:           id,
		LabelMajor:   "",
		LabelMinor:   "",
		Rank:         "",
		Pseudo:       false,
		Origins:      report.MakeIDList(),
		EdgeMetadata: report.EdgeMetadata{},
		Node:         report.MakeNode(),
	}
}
開發者ID:faddat,項目名稱:scope,代碼行數:13,代碼來源:renderable_node.go

示例11: TestMergeRenderableNode

func TestMergeRenderableNode(t *testing.T) {
	node1 := render.RenderableNode{
		ID:         "foo",
		LabelMajor: "",
		LabelMinor: "minor",
		Rank:       "",
		Pseudo:     false,
		Adjacency:  report.MakeIDList("a1"),
		Origins:    report.MakeIDList("o1"),
	}
	node2 := render.RenderableNode{
		ID:         "foo",
		LabelMajor: "major",
		LabelMinor: "",
		Rank:       "rank",
		Pseudo:     false,
		Adjacency:  report.MakeIDList("a2"),
		Origins:    report.MakeIDList("o2"),
	}

	want := render.RenderableNode{
		ID:         "foo",
		LabelMajor: "major",
		LabelMinor: "minor",
		Rank:       "rank",
		Pseudo:     false,
		Adjacency:  report.MakeIDList("a1", "a2"),
		Origins:    report.MakeIDList("o1", "o2"),
	}
	node1.Merge(node2)

	if !reflect.DeepEqual(want, node1) {
		t.Errorf("want %+v, have %+v", want, node1)
	}
}
開發者ID:neviim,項目名稱:scope,代碼行數:35,代碼來源:renderable_node_test.go

示例12: TestIDList

func TestIDList(t *testing.T) {
	have := report.MakeIDList("alpha", "mu", "zeta")
	have = have.Add("alpha")
	have = have.Add("nu")
	have = have.Add("mu")
	have = have.Add("alpha")
	have = have.Add("alpha")
	have = have.Add("epsilon")
	have = have.Add("delta")
	if want := report.IDList([]string{"alpha", "delta", "epsilon", "mu", "nu", "zeta"}); !reflect.DeepEqual(want, have) {
		t.Errorf("want %+v, have %+v", want, have)
	}
}
開發者ID:rnd-ua,項目名稱:scope,代碼行數:13,代碼來源:id_list_test.go

示例13: tagContainer

func (w Weave) tagContainer(r report.Report, containerIDPrefix, macAddress string, ips []string) {
	for nodeid, nmd := range r.Container.NodeMetadatas {
		idPrefix := nmd.Metadata[docker.ContainerID][:12]
		if idPrefix != containerIDPrefix {
			continue
		}

		existingIPs := report.MakeIDList(docker.ExtractContainerIPs(nmd)...)
		existingIPs = existingIPs.Add(ips...)
		nmd.Metadata[docker.ContainerIPs] = strings.Join(existingIPs, " ")
		nmd.Metadata[WeaveMACAddress] = macAddress
		r.Container.NodeMetadatas[nodeid] = nmd
		break
	}
}
開發者ID:cgvarela,項目名稱:scope,代碼行數:15,代碼來源:weave.go

示例14: EdgeMetadata

// EdgeMetadata gives the metadata of an edge from the perspective of the
// srcRenderableID. Since an edgeID can have multiple edges on the address
// level, it uses the supplied mapping function to translate address IDs to
// renderable node (mapped) IDs.
func (m LeafMap) EdgeMetadata(rpt report.Report, srcRenderableID, dstRenderableID string) report.EdgeMetadata {
	t := m.Selector(rpt)
	metadata := report.EdgeMetadata{}
	for edgeID, edgeMeta := range t.EdgeMetadatas {
		src, dst, ok := report.ParseEdgeID(edgeID)
		if !ok {
			log.Printf("bad edge ID %q", edgeID)
			continue
		}
		srcs, dsts := report.MakeIDList(src), report.MakeIDList(dst)
		if src != report.TheInternet {
			mapped := m.Mapper(t.NodeMetadatas[src])
			srcs = ids(mapped)
		}
		if dst != report.TheInternet {
			mapped := m.Mapper(t.NodeMetadatas[dst])
			dsts = ids(mapped)
		}
		if srcs.Contains(srcRenderableID) && dsts.Contains(dstRenderableID) {
			metadata = metadata.Flatten(edgeMeta)
		}
	}
	return metadata
}
開發者ID:cgvarela,項目名稱:scope,代碼行數:28,代碼來源:render.go

示例15: Tag

// Tag implements Tagger.
func (w *Weave) Tag(r report.Report) (report.Report, error) {
	w.mtx.RLock()
	defer w.mtx.RUnlock()

	// Put information from weaveDNS on the container nodes
	for _, entry := range w.status.DNS.Entries {
		if entry.Tombstone > 0 {
			continue
		}
		nodeID := report.MakeContainerNodeID(w.hostID, entry.ContainerID)
		node, ok := r.Container.Nodes[nodeID]
		if !ok {
			continue
		}
		hostnames := report.IDList(strings.Fields(node.Metadata[WeaveDNSHostname]))
		hostnames = hostnames.Add(strings.TrimSuffix(entry.Hostname, "."))
		node.Metadata[WeaveDNSHostname] = strings.Join(hostnames, " ")
	}

	// Put information from weave ps on the container nodes
	psEntries, err := w.ps()
	if err != nil {
		return r, nil
	}
	containersByPrefix := map[string]report.Node{}
	for _, node := range r.Container.Nodes {
		prefix := node.Metadata[docker.ContainerID][:12]
		containersByPrefix[prefix] = node
	}
	for _, e := range psEntries {
		node, ok := containersByPrefix[e.containerIDPrefix]
		if !ok {
			continue
		}

		existingIPs := report.MakeIDList(docker.ExtractContainerIPs(node)...)
		existingIPs = existingIPs.Add(e.ips...)
		node.Metadata[docker.ContainerIPs] = strings.Join(existingIPs, " ")
		node.Metadata[WeaveMACAddress] = e.macAddress
	}
	return r, nil
}
開發者ID:webwurst,項目名稱:scope,代碼行數:43,代碼來源:weave.go


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