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


Golang Graph.Successors方法代碼示例

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


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

示例1: addImageStreamsToGraph

// addImageStreamsToGraph adds all the streams to the graph. The most recent n
// image revisions for a tag will be preserved, where n is specified by the
// algorithm's tagRevisionsToKeep. Image revisions older than n are candidates
// for pruning.  if the image stream's age is at least as old as the minimum
// threshold in algorithm.  Otherwise, if the image stream is younger than the
// threshold, all image revisions for that stream are ineligible for pruning.
//
// addImageStreamsToGraph also adds references from each stream to all the
// layers it references (via each image a stream references).
func addImageStreamsToGraph(g graph.Graph, streams *imageapi.ImageStreamList, algorithm pruneAlgorithm) {
	for i := range streams.Items {
		stream := &streams.Items[i]

		glog.V(4).Infof("Examining ImageStream %s/%s", stream.Namespace, stream.Name)

		// use a weak reference for old image revisions by default
		oldImageRevisionReferenceKind := graph.WeakReferencedImageGraphEdgeKind

		age := util.Now().Sub(stream.CreationTimestamp.Time)
		if age < algorithm.keepYoungerThan {
			// stream's age is below threshold - use a strong reference for old image revisions instead
			glog.V(4).Infof("Stream %s/%s is below age threshold - none of its images are eligible for pruning", stream.Namespace, stream.Name)
			oldImageRevisionReferenceKind = graph.ReferencedImageGraphEdgeKind
		}

		glog.V(4).Infof("Adding ImageStream %s/%s to graph", stream.Namespace, stream.Name)
		isNode := graph.ImageStream(g, stream)
		imageStreamNode := isNode.(*graph.ImageStreamNode)

		for tag, history := range stream.Status.Tags {
			for i := range history.Items {
				n := graph.FindImage(g, history.Items[i].Image)
				if n == nil {
					glog.V(1).Infof("Unable to find image %q in graph (from tag=%q, revision=%d, dockerImageReference=%s)", history.Items[i].Image, tag, i, history.Items[i].DockerImageReference)
					continue
				}
				imageNode := n.(*graph.ImageNode)

				var kind int
				switch {
				case i < algorithm.tagRevisionsToKeep:
					kind = graph.ReferencedImageGraphEdgeKind
				default:
					kind = oldImageRevisionReferenceKind
				}

				glog.V(4).Infof("Checking for existing strong reference from stream %s/%s to image %s", stream.Namespace, stream.Name, imageNode.Image.Name)
				if edge := g.EdgeBetween(imageStreamNode, imageNode); edge != nil && g.EdgeKind(edge) == graph.ReferencedImageGraphEdgeKind {
					glog.V(4).Infof("Strong reference found")
					continue
				}

				glog.V(4).Infof("Adding edge (kind=%d) from %q to %q", kind, imageStreamNode.UniqueName.UniqueName(), imageNode.UniqueName.UniqueName())
				g.AddEdge(imageStreamNode, imageNode, kind)

				glog.V(4).Infof("Adding stream->layer references")
				// add stream -> layer references so we can prune them later
				for _, s := range g.Successors(imageNode) {
					if g.Kind(s) != graph.ImageLayerGraphKind {
						continue
					}
					glog.V(4).Infof("Adding reference from stream %q to layer %q", stream.Name, s.(*graph.ImageLayerNode).Layer)
					g.AddEdge(imageStreamNode, s, graph.ReferencedImageLayerGraphEdgeKind)
				}
			}
		}
	}
}
開發者ID:mignev,項目名稱:origin,代碼行數:68,代碼來源:imagepruner.go

示例2: DescendentNodesByNodeKind

// DescendentNodesByNodeKind starts at the root navigates down the root.  Every edge is checked against the edgeChecker
// to determine whether or not to follow it.  The nodes at the tail end of every chased edge are then checked against the
// the targetNodeKind.  Matches are added to the return and every checked node then has its edges checked: lather, rinse, repeat
func DescendentNodesByNodeKind(g osgraph.Graph, visitedNodes graphview.IntSet, node graph.Node, targetNodeKind string, edgeChecker osgraph.EdgeFunc) []graph.Node {
	if visitedNodes.Has(node.ID()) {
		return []graph.Node{}
	}
	visitedNodes.Insert(node.ID())

	ret := []graph.Node{}
	for _, successor := range g.Successors(node) {
		edge := g.EdgeBetween(node, successor)

		if edgeChecker(osgraph.New(), node, successor, g.EdgeKinds(edge)) {
			if g.Kind(successor) == targetNodeKind {
				ret = append(ret, successor)
			}

			ret = append(ret, DescendentNodesByNodeKind(g, visitedNodes, successor, targetNodeKind, edgeChecker)...)
		}
	}

	return ret
}
開發者ID:naheedmk,項目名稱:origin,代碼行數:24,代碼來源:dc.go


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