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


Golang Graph.EdgeSubgraph方法代碼示例

本文整理匯總了Golang中github.com/openshift/origin/pkg/api/graph.Graph.EdgeSubgraph方法的典型用法代碼示例。如果您正苦於以下問題:Golang Graph.EdgeSubgraph方法的具體用法?Golang Graph.EdgeSubgraph怎麽用?Golang Graph.EdgeSubgraph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/openshift/origin/pkg/api/graph.Graph的用法示例。


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

示例1: humanReadableOutput

// humanReadableOutput traverses the provided graph using DFS and outputs it
// in a human-readable format. It starts from the provided root, assuming it
// is an imageStreamTag node and continues to the rest of the graph handling
// only imageStreamTag and buildConfig nodes.
func (d *ChainDescriber) humanReadableOutput(g osgraph.Graph, f osgraph.Namer, root graph.Node, reverse bool) string {
	if reverse {
		g = g.EdgeSubgraph(osgraph.ReverseExistingDirectEdge)
	}

	var singleNamespace bool
	if len(d.namespaces) == 1 && !d.namespaces.Has(kapi.NamespaceAll) {
		singleNamespace = true
	}
	depth := map[graph.Node]int{
		root: 0,
	}
	out := ""

	dfs := &DepthFirst{
		Visit: func(u, v graph.Node) {
			depth[v] = depth[u] + 1
		},
	}

	until := func(node graph.Node) bool {
		var info string

		switch t := node.(type) {
		case *imagegraph.ImageStreamTagNode:
			info = outputHelper(f.ResourceName(t), t.Namespace, singleNamespace)
		case *buildgraph.BuildConfigNode:
			info = outputHelper(f.ResourceName(t), t.BuildConfig.Namespace, singleNamespace)
		default:
			panic("this graph contains node kinds other than imageStreamTags and buildConfigs")
		}

		if depth[node] != 0 {
			out += "\n"
		}
		out += fmt.Sprintf("%s", strings.Repeat("\t", depth[node]))
		out += fmt.Sprintf("%s", info)

		return false
	}

	dfs.Walk(g, root, until)

	return out
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:49,代碼來源:chaindescriber.go

示例2: DeploymentPipelines

// DeploymentPipelines returns a map of DeploymentConfigs to the deployment flows that create them,
// extracted from the provided Graph.
func DeploymentPipelines(g osgraph.Graph) (DeploymentPipelineMap, osgraph.NodeSet) {
	covered := make(osgraph.NodeSet)
	g = g.EdgeSubgraph(osgraph.ReverseGraphEdge)
	flows := make(DeploymentPipelineMap)
	for _, node := range g.NodeList() {
		switch t := node.(type) {
		case *deploygraph.DeploymentConfigNode:
			covered.Add(t.ID())
			images := []ImagePipeline{}
			for _, n := range g.Neighbors(node) {
				// find incoming image edges only
				switch g.EdgeKind(g.EdgeBetween(node, n)) {
				case deployedges.TriggersDeploymentEdgeKind, deployedges.UsedInDeploymentEdgeKind:
					if flow, ok := ImagePipelineFromNode(g, n, covered); ok {
						images = append(images, flow)
					}
				}
			}

			output := []ImagePipeline{}

			// ensure the list of images is ordered the same as what is in the template
			if template := t.DeploymentConfig.Template.ControllerTemplate.Template; template != nil {
				deployedges.EachTemplateImage(
					&template.Spec,
					deployedges.DeploymentConfigHasTrigger(t.DeploymentConfig),
					func(image deployedges.TemplateImage, err error) {
						if err != nil {
							return
						}
						for i := range images {
							switch t := images[i].Image.(type) {
							case *imagegraph.ImageStreamTagNode:
								if image.Ref != nil {
									continue
								}
								from := image.From
								if t.ImageStream.Name != from.Name || t.ImageStream.Namespace != from.Namespace {
									continue
								}
								output = append(output, images[i])
								return
							case *imagegraph.DockerImageRepositoryNode:
								if image.From != nil {
									continue
								}
								ref1, ref2 := t.Ref.Minimal(), image.Ref.DockerClientDefaults().Minimal()
								if ref1 != ref2 {
									continue
								}
								output = append(output, images[i])
								return
							}
						}
					},
				)
			}
			flows[t] = output
		}
	}
	return flows, covered
}
開發者ID:cjnygard,項目名稱:origin,代碼行數:64,代碼來源:deployment.go


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