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


Golang report.MakeContainerNodeID函數代碼示例

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


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

示例1: TestReporter

func TestReporter(t *testing.T) {
	want := report.MakeReport()
	want.Container = report.Topology{
		Adjacency:     report.Adjacency{},
		EdgeMetadatas: report.EdgeMetadatas{},
		NodeMetadatas: report.NodeMetadatas{
			report.MakeContainerNodeID("", "ping"): report.NewNodeMetadata(map[string]string{
				docker.ContainerID:   "ping",
				docker.ContainerName: "pong",
				docker.ImageID:       "baz",
			}),
		},
	}
	want.ContainerImage = report.Topology{
		Adjacency:     report.Adjacency{},
		EdgeMetadatas: report.EdgeMetadatas{},
		NodeMetadatas: report.NodeMetadatas{
			report.MakeContainerNodeID("", "baz"): report.NewNodeMetadata(map[string]string{
				docker.ImageID:   "baz",
				docker.ImageName: "bang",
			}),
		},
	}

	reporter := docker.NewReporter(mockRegistryInstance, "")
	have, _ := reporter.Report()
	if !reflect.DeepEqual(want, have) {
		t.Errorf("%s", test.Diff(want, have))
	}
}
開發者ID:neviim,項目名稱:scope,代碼行數:30,代碼來源:reporter_test.go

示例2: TestReporter

func TestReporter(t *testing.T) {
	want := report.MakeReport()
	pod1ID := report.MakePodNodeID("ping", "pong-a")
	pod2ID := report.MakePodNodeID("ping", "pong-b")
	serviceID := report.MakeServiceNodeID("ping", "pongservice")
	want.Pod = report.MakeTopology().AddNode(pod1ID, report.MakeNodeWith(map[string]string{
		kubernetes.PodID:           "ping/pong-a",
		kubernetes.PodName:         "pong-a",
		kubernetes.Namespace:       "ping",
		kubernetes.PodCreated:      pod1.Created(),
		kubernetes.PodContainerIDs: "container1 container2",
		kubernetes.ServiceIDs:      "ping/pongservice",
	}).WithParents(report.Sets{
		report.Service: report.MakeStringSet(serviceID),
	})).AddNode(pod2ID, report.MakeNodeWith(map[string]string{
		kubernetes.PodID:           "ping/pong-b",
		kubernetes.PodName:         "pong-b",
		kubernetes.Namespace:       "ping",
		kubernetes.PodCreated:      pod1.Created(),
		kubernetes.PodContainerIDs: "container3 container4",
		kubernetes.ServiceIDs:      "ping/pongservice",
	}).WithParents(report.Sets{
		report.Service: report.MakeStringSet(serviceID),
	}))
	want.Service = report.MakeTopology().AddNode(serviceID, report.MakeNodeWith(map[string]string{
		kubernetes.ServiceID:      "ping/pongservice",
		kubernetes.ServiceName:    "pongservice",
		kubernetes.Namespace:      "ping",
		kubernetes.ServiceCreated: pod1.Created(),
	}))
	want.Container = report.MakeTopology().AddNode(report.MakeContainerNodeID("container1"), report.MakeNodeWith(map[string]string{
		kubernetes.PodID:     "ping/pong-a",
		kubernetes.Namespace: "ping",
	}).WithParents(report.Sets{
		report.Pod: report.MakeStringSet(pod1ID),
	})).AddNode(report.MakeContainerNodeID("container2"), report.MakeNodeWith(map[string]string{
		kubernetes.PodID:     "ping/pong-a",
		kubernetes.Namespace: "ping",
	}).WithParents(report.Sets{
		report.Pod: report.MakeStringSet(pod1ID),
	})).AddNode(report.MakeContainerNodeID("container3"), report.MakeNodeWith(map[string]string{
		kubernetes.PodID:     "ping/pong-b",
		kubernetes.Namespace: "ping",
	}).WithParents(report.Sets{
		report.Pod: report.MakeStringSet(pod2ID),
	})).AddNode(report.MakeContainerNodeID("container4"), report.MakeNodeWith(map[string]string{
		kubernetes.PodID:     "ping/pong-b",
		kubernetes.Namespace: "ping",
	}).WithParents(report.Sets{
		report.Pod: report.MakeStringSet(pod2ID),
	}))

	reporter := kubernetes.NewReporter(mockClientInstance)
	have, _ := reporter.Report()
	if !reflect.DeepEqual(want, have) {
		t.Errorf("%s", test.Diff(want, have))
	}
}
開發者ID:rnd-ua,項目名稱:scope,代碼行數:58,代碼來源:reporter_test.go

示例3: TestReporter

func TestReporter(t *testing.T) {
	want := report.MakeReport()
	want.Container = report.Topology{
		Nodes: report.Nodes{
			report.MakeContainerNodeID("", "ping"): report.MakeNodeWith(map[string]string{
				docker.ContainerID:   "ping",
				docker.ContainerName: "pong",
				docker.ImageID:       "baz",
			}),
		},
		Controls: report.Controls{
			docker.RestartContainer: report.Control{
				ID:    docker.RestartContainer,
				Human: "Restart",
				Icon:  "fa-repeat",
			},
			docker.StartContainer: report.Control{
				ID:    docker.StartContainer,
				Human: "Start",
				Icon:  "fa-play",
			},
			docker.StopContainer: report.Control{
				ID:    docker.StopContainer,
				Human: "Stop",
				Icon:  "fa-stop",
			},
			docker.PauseContainer: report.Control{
				ID:    docker.PauseContainer,
				Human: "Pause",
				Icon:  "fa-pause",
			},
			docker.UnpauseContainer: report.Control{
				ID:    docker.UnpauseContainer,
				Human: "Unpause",
				Icon:  "fa-play",
			},
		},
	}
	want.ContainerImage = report.Topology{
		Nodes: report.Nodes{
			report.MakeContainerNodeID("", "baz"): report.MakeNodeWith(map[string]string{
				docker.ImageID:   "baz",
				docker.ImageName: "bang",
			}),
		},
		Controls: report.Controls{},
	}

	reporter := docker.NewReporter(mockRegistryInstance, "")
	have, _ := reporter.Report()
	if !reflect.DeepEqual(want, have) {
		t.Errorf("%s", test.Diff(want, have))
	}
}
開發者ID:faddat,項目名稱:scope,代碼行數:54,代碼來源:reporter_test.go

示例4: TestControls

func TestControls(t *testing.T) {
	mdc := newMockClient()
	setupStubs(mdc, func() {
		registry, _ := docker.NewRegistry(10*time.Second, nil)
		defer registry.Stop()

		for _, tc := range []struct{ command, result string }{
			{docker.StopContainer, "stopped"},
			{docker.StartContainer, "started"},
			{docker.RestartContainer, "restarted"},
			{docker.PauseContainer, "paused"},
			{docker.UnpauseContainer, "unpaused"},
		} {
			result := controls.HandleControlRequest(xfer.Request{
				Control: tc.command,
				NodeID:  report.MakeContainerNodeID("a1b2c3d4e5"),
			})
			if !reflect.DeepEqual(result, xfer.Response{
				Error: tc.result,
			}) {
				t.Error(result)
			}
		}
	})
}
開發者ID:rnd-ua,項目名稱:scope,代碼行數:25,代碼來源:controls_test.go

示例5: Tag

// Tag implements Tagger.
func (w Weave) Tag(r report.Report) (report.Report, error) {
	status, err := w.update()
	if err != nil {
		return r, nil
	}

	for _, entry := range status.DNS.Entries {
		if entry.Tombstone > 0 {
			continue
		}
		nodeID := report.MakeContainerNodeID(w.hostID, entry.ContainerID)
		node, ok := r.Container.NodeMetadatas[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, " ")
		r.Container.NodeMetadatas[nodeID] = node
	}

	psEntries, err := w.ps()
	if err != nil {
		return r, nil
	}
	for _, e := range psEntries {
		w.tagContainer(r, e.containerIDPrefix, e.macAddress, e.ips)
	}
	return r, nil
}
開發者ID:cgvarela,項目名稱:scope,代碼行數:31,代碼來源:weave.go

示例6: TestPipes

func TestPipes(t *testing.T) {
	oldNewPipe := controls.NewPipe
	defer func() { controls.NewPipe = oldNewPipe }()
	controls.NewPipe = func(_ controls.PipeClient, _ string) (string, xfer.Pipe, error) {
		return "pipeid", mockPipe{}, nil
	}

	mdc := newMockClient()
	setupStubs(mdc, func() {
		registry, _ := docker.NewRegistry(10*time.Second, nil)
		defer registry.Stop()

		test.Poll(t, 100*time.Millisecond, true, func() interface{} {
			_, ok := registry.GetContainer("ping")
			return ok
		})

		for _, tc := range []string{
			docker.AttachContainer,
			docker.ExecContainer,
		} {
			result := controls.HandleControlRequest(xfer.Request{
				Control: tc,
				NodeID:  report.MakeContainerNodeID("ping"),
			})
			want := xfer.Response{
				Pipe:   "pipeid",
				RawTTY: true,
			}
			if !reflect.DeepEqual(result, want) {
				t.Errorf("diff: %s", test.Diff(want, result))
			}
		}
	})
}
開發者ID:rnd-ua,項目名稱:scope,代碼行數:35,代碼來源:controls_test.go

示例7: containerTopology

func (r *Reporter) containerTopology(localAddrs []net.IP) report.Topology {
	result := report.MakeTopology()
	result.Controls.AddControl(report.Control{
		ID:    StopContainer,
		Human: "Stop",
		Icon:  "fa-stop",
	})
	result.Controls.AddControl(report.Control{
		ID:    StartContainer,
		Human: "Start",
		Icon:  "fa-play",
	})
	result.Controls.AddControl(report.Control{
		ID:    RestartContainer,
		Human: "Restart",
		Icon:  "fa-repeat",
	})
	result.Controls.AddControl(report.Control{
		ID:    PauseContainer,
		Human: "Pause",
		Icon:  "fa-pause",
	})
	result.Controls.AddControl(report.Control{
		ID:    UnpauseContainer,
		Human: "Unpause",
		Icon:  "fa-play",
	})

	r.registry.WalkContainers(func(c Container) {
		nodeID := report.MakeContainerNodeID(r.hostID, c.ID())
		result.AddNode(nodeID, c.GetNode(r.hostID, localAddrs))
	})

	return result
}
開發者ID:faddat,項目名稱:scope,代碼行數:35,代碼來源:reporter.go

示例8: podTopology

func (r *Reporter) podTopology(services []Service) (report.Topology, report.Topology, error) {
	pods, containers := report.MakeTopology(), report.MakeTopology()
	selectors := map[string]labels.Selector{}
	for _, service := range services {
		selectors[service.ID()] = service.Selector()
	}
	err := r.client.WalkPods(func(p Pod) error {
		for serviceID, selector := range selectors {
			if selector.Matches(p.Labels()) {
				p.AddServiceID(serviceID)
			}
		}
		nodeID := report.MakePodNodeID(p.Namespace(), p.Name())
		pods = pods.AddNode(nodeID, p.GetNode())

		container := report.MakeNodeWith(map[string]string{
			PodID:     p.ID(),
			Namespace: p.Namespace(),
		}).WithParents(report.EmptySets.Add(report.Pod, report.MakeStringSet(nodeID)))
		for _, containerID := range p.ContainerIDs() {
			containers.AddNode(report.MakeContainerNodeID(containerID), container)
		}
		return nil
	})
	return pods, containers, err
}
開發者ID:pauloheck,項目名稱:scope,代碼行數:26,代碼來源:reporter.go

示例9: MapProcess2Container

// MapProcess2Container maps process Nodes to container
// Nodes.
//
// If this function is given a node without a docker_container_id
// (including other pseudo nodes), it will produce an "Uncontained"
// pseudo node.
//
// Otherwise, this function will produce a node with the correct ID
// format for a container, but without any Major or Minor labels.
// It does not have enough info to do that, and the resulting graph
// must be merged with a container graph to get that info.
func MapProcess2Container(n report.Node, _ report.Networks) report.Nodes {
	// Propagate pseudo nodes
	if n.Topology == Pseudo {
		return report.Nodes{n.ID: n}
	}

	// Otherwise, if the process is not in a container, group it
	// into an per-host "Uncontained" node.  If for whatever reason
	// this node doesn't have a host id in their nodemetadata, it'll
	// all get grouped into a single uncontained node.
	var (
		id   string
		node report.Node
	)
	if containerID, ok := n.Latest.Lookup(docker.ContainerID); ok {
		id = report.MakeContainerNodeID(containerID)
		node = NewDerivedNode(id, n).WithTopology(report.Container)
	} else {
		id = MakePseudoNodeID(UncontainedID, report.ExtractHostID(n))
		node = NewDerivedPseudoNode(id, n)
		node = propagateLatest(report.HostNodeID, n, node)
		node = propagateLatest(IsConnected, n, node)
	}
	return report.Nodes{id: node}
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:36,代碼來源:container.go

示例10: TestReporter

func TestReporter(t *testing.T) {
	containerImageNodeID := report.MakeContainerImageNodeID("baz")
	rpt, err := docker.NewReporter(mockRegistryInstance, "host1", nil).Report()
	if err != nil {
		t.Fatal(err)
	}

	// Reporter should add a container
	{
		containerNodeID := report.MakeContainerNodeID("ping")
		node, ok := rpt.Container.Nodes[containerNodeID]
		if !ok {
			t.Fatalf("Expected report to have container image %q, but not found", containerNodeID)
		}

		for k, want := range map[string]string{
			docker.ContainerID:   "ping",
			docker.ContainerName: "pong",
			docker.ImageID:       "baz",
		} {
			if have, ok := node.Latest.Lookup(k); !ok || have != want {
				t.Errorf("Expected container %s latest %q: %q, got %q", containerNodeID, k, want, have)
			}
		}

		// container should have controls
		if len(rpt.Container.Controls) == 0 {
			t.Errorf("Container should have some controls")
		}

		// container should have the image as a parent
		if parents, ok := node.Parents.Lookup(report.ContainerImage); !ok || !parents.Contains(containerImageNodeID) {
			t.Errorf("Expected container %s to have parent container image %q, got %q", containerNodeID, containerImageNodeID, parents)
		}
	}

	// Reporter should add a container image
	{
		node, ok := rpt.ContainerImage.Nodes[containerImageNodeID]
		if !ok {
			t.Fatalf("Expected report to have container image %q, but not found", containerImageNodeID)
		}

		for k, want := range map[string]string{
			docker.ImageID:   "baz",
			docker.ImageName: "bang",
		} {
			if have, ok := node.Latest.Lookup(k); !ok || have != want {
				t.Errorf("Expected container image %s latest %q: %q, got %q", containerImageNodeID, k, want, have)
			}
		}

		// container image should have no controls
		if len(rpt.ContainerImage.Controls) != 0 {
			t.Errorf("Container images should not have any controls")
		}
	}
}
開發者ID:pauloheck,項目名稱:scope,代碼行數:58,代碼來源:reporter_test.go

示例11: containerTopology

func (r *Reporter) containerTopology() report.Topology {
	result := report.NewTopology()

	r.registry.WalkContainers(func(c Container) {
		nodeID := report.MakeContainerNodeID(r.scope, c.ID())
		result.NodeMetadatas[nodeID] = c.GetNodeMetadata()
	})

	return result
}
開發者ID:davkal,項目名稱:scope,代碼行數:10,代碼來源:reporter.go

示例12: containerTopology

func (r *Reporter) containerTopology() report.Topology {
	result := report.MakeTopology()

	r.registry.WalkContainers(func(c Container) {
		nodeID := report.MakeContainerNodeID(r.hostID, c.ID())
		result.AddNode(nodeID, c.GetNode())
	})

	return result
}
開發者ID:webwurst,項目名稱:scope,代碼行數:10,代碼來源:reporter.go

示例13: TestWeaveTaggerOverlayTopology

func TestWeaveTaggerOverlayTopology(t *testing.T) {
	oldExecCmd := exec.Command
	defer func() { exec.Command = oldExecCmd }()
	exec.Command = func(name string, args ...string) exec.Cmd {
		return testExec.NewMockCmdString(fmt.Sprintf("%s %s %s/24\n", mockContainerID, mockContainerMAC, mockContainerIP))
	}

	s := httptest.NewServer(http.HandlerFunc(mockWeaveRouter))
	defer s.Close()

	w := overlay.NewWeave(mockHostID, s.URL)
	defer w.Stop()
	w.Tick()

	{
		have, err := w.Report()
		if err != nil {
			t.Fatal(err)
		}
		if want, have := report.MakeTopology().AddNode(
			report.MakeOverlayNodeID(mockWeavePeerName),
			report.MakeNodeWith(map[string]string{
				overlay.WeavePeerName:     mockWeavePeerName,
				overlay.WeavePeerNickName: mockWeavePeerNickName,
			}),
		), have.Overlay; !reflect.DeepEqual(want, have) {
			t.Error(test.Diff(want, have))
		}
	}

	{
		nodeID := report.MakeContainerNodeID(mockHostID, mockContainerID)
		want := report.Report{
			Container: report.MakeTopology().AddNode(nodeID, report.MakeNodeWith(map[string]string{
				docker.ContainerID:       mockContainerID,
				overlay.WeaveDNSHostname: mockHostname,
				overlay.WeaveMACAddress:  mockContainerMAC,
			}).WithSets(report.Sets{
				docker.ContainerIPs:           report.MakeStringSet(mockContainerIP),
				docker.ContainerIPsWithScopes: report.MakeStringSet(mockContainerIPWithScope),
			})),
		}
		have, err := w.Tag(report.Report{
			Container: report.MakeTopology().AddNode(nodeID, report.MakeNodeWith(map[string]string{
				docker.ContainerID: mockContainerID,
			})),
		})
		if err != nil {
			t.Fatal(err)
		}
		if !reflect.DeepEqual(want, have) {
			t.Error(test.Diff(want, have))
		}
	}
}
開發者ID:hrhelena,項目名稱:scope,代碼行數:55,代碼來源:weave_test.go

示例14: tag

func (t *Tagger) tag(tree process.Tree, topology *report.Topology) {
	for nodeID, node := range topology.Nodes {
		pidStr, ok := node.Latest.Lookup(process.PID)
		if !ok {
			continue
		}

		pid, err := strconv.ParseUint(pidStr, 10, 64)
		if err != nil {
			continue
		}

		var (
			c         Container
			candidate = int(pid)
		)

		t.registry.LockedPIDLookup(func(lookup func(int) Container) {
			for {
				c = lookup(candidate)
				if c != nil {
					break
				}

				candidate, err = tree.GetParent(candidate)
				if err != nil {
					break
				}
			}
		})

		if c == nil || ContainerIsStopped(c) || c.PID() == 1 {
			continue
		}

		node := report.MakeNodeWith(nodeID, map[string]string{
			ContainerID: c.ID(),
		}).WithParents(report.EmptySets.
			Add(report.Container, report.MakeStringSet(report.MakeContainerNodeID(c.ID()))),
		)

		// If we can work out the image name, add a parent tag for it
		image, ok := t.registry.GetContainerImage(c.Image())
		if ok && len(image.RepoTags) > 0 {
			imageName := ImageNameWithoutVersion(image.RepoTags[0])
			node = node.WithParents(report.EmptySets.
				Add(report.ContainerImage, report.MakeStringSet(report.MakeContainerImageNodeID(imageName))),
			)
		}

		topology.AddNode(node)
	}
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:53,代碼來源:tagger.go

示例15: ContainerUpdated

// ContainerUpdated should be called whenever a container is updated.
func (r *Reporter) ContainerUpdated(c Container) {
	localAddrs, err := report.LocalAddresses()
	if err != nil {
		log.Errorf("Error getting local address: %v", err)
		return
	}

	// Publish a 'short cut' report container just this container
	rpt := report.MakeReport()
	rpt.Shortcut = true
	rpt.Container.AddNode(report.MakeContainerNodeID(c.ID()), c.GetNode(r.hostID, localAddrs))
	r.probe.Publish(rpt)
}
開發者ID:pauloheck,項目名稱:scope,代碼行數:14,代碼來源:reporter.go


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