本文整理匯總了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))
}
}
示例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)
}
}
}
示例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)
}
}
示例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
}
示例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)
}
}
示例6: ids
func ids(nodes RenderableNodes) report.IDList {
result := report.MakeIDList()
for id := range nodes {
result = result.Add(id)
}
return result
}
示例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)
}
}
示例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)
}
}
示例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))
}
}
示例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(),
}
}
示例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)
}
}
示例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)
}
}
示例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
}
}
示例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
}
示例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
}