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


Golang dag.VertexName函數代碼示例

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


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

示例1: Transform

func (t *VertexTransformer) Transform(g *Graph) error {
	for _, v := range g.Vertices() {
		for _, vt := range t.Transforms {
			newV, err := vt.Transform(v)
			if err != nil {
				return err
			}

			// If the vertex didn't change, then don't do anything more
			if newV == v {
				continue
			}

			// Vertex changed, replace it within the graph
			if ok := g.Replace(v, newV); !ok {
				// This should never happen, big problem
				return fmt.Errorf(
					"Failed to replace %s with %s!\n\nSource: %#v\n\nTarget: %#v",
					dag.VertexName(v), dag.VertexName(newV), v, newV)
			}

			// Replace v so that future transforms use the proper vertex
			v = newV
		}
	}

	return nil
}
開發者ID:AssertSelenium,項目名稱:terraform,代碼行數:28,代碼來源:transform_vertex.go

示例2: ExitEvalTree

func (w *ContextGraphWalker) ExitEvalTree(
	v dag.Vertex, output interface{}, err error) error {
	log.Printf("[TRACE] Exiting eval tree: %s", dag.VertexName(v))

	// Release the semaphore
	w.Context.parallelSem.Release()

	if err == nil {
		return nil
	}

	// Acquire the lock because anything is going to require a lock.
	w.errorLock.Lock()
	defer w.errorLock.Unlock()

	// Try to get a validation error out of it. If its not a validation
	// error, then just record the normal error.
	verr, ok := err.(*EvalValidateError)
	if !ok {
		return err
	}

	for _, msg := range verr.Warnings {
		w.ValidationWarnings = append(
			w.ValidationWarnings,
			fmt.Sprintf("%s: %s", dag.VertexName(v), msg))
	}
	for _, e := range verr.Errors {
		w.ValidationErrors = append(
			w.ValidationErrors,
			errwrap.Wrapf(fmt.Sprintf("%s: {{err}}", dag.VertexName(v)), e))
	}

	return nil
}
開發者ID:mnbbrown,項目名稱:terraform,代碼行數:35,代碼來源:graph_walk_context.go

示例3: testGraphHappensBefore

// testGraphHappensBefore is an assertion helper that tests that node
// A (dag.VertexName value) happens before node B.
func testGraphHappensBefore(t *testing.T, g *Graph, A, B string) {
	// Find the B vertex
	var vertexB dag.Vertex
	for _, v := range g.Vertices() {
		if dag.VertexName(v) == B {
			vertexB = v
			break
		}
	}
	if vertexB == nil {
		t.Fatalf(
			"Expected %q before %q. Couldn't find %q in:\n\n%s",
			A, B, B, g.String())
	}

	// Look at ancestors
	deps, err := g.Ancestors(vertexB)
	if err != nil {
		t.Fatalf("Error: %s in graph:\n\n%s", err, g.String())
	}

	// Make sure B is in there
	for _, v := range deps.List() {
		if dag.VertexName(v) == A {
			// Success
			return
		}
	}

	t.Fatalf(
		"Expected %q before %q in:\n\n%s",
		A, B, g.String())
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:35,代碼來源:graph_test.go

示例4: Noop

// GraphNodeNoopPrunable
func (n *GraphNodeConfigVariable) Noop(opts *NoopOpts) bool {
	log.Printf("[DEBUG] Checking variable noop: %s", n.Name())
	// If we have no diff, always keep this in the graph. We have to do
	// this primarily for validation: we want to validate that variable
	// interpolations are valid even if there are no resources that
	// depend on them.
	if opts.Diff == nil || opts.Diff.Empty() {
		log.Printf("[DEBUG] No diff, not a noop")
		return false
	}

	// We have to find our our module diff since we do funky things with
	// the flat node's implementation of Path() below.
	modDiff := opts.Diff.ModuleByPath(n.ModulePath)

	// If we're destroying, we have no need of variables.
	if modDiff != nil && modDiff.Destroy {
		log.Printf("[DEBUG] Destroy diff, treating variable as a noop")
		return true
	}

	for _, v := range opts.Graph.UpEdges(opts.Vertex).List() {
		// This is terrible, but I can't think of a better way to do this.
		if dag.VertexName(v) == rootNodeName {
			continue
		}

		log.Printf("[DEBUG] Found up edge to %s, var is not noop", dag.VertexName(v))
		return false
	}

	log.Printf("[DEBUG] No up edges, treating variable as a noop")
	return true
}
開發者ID:ack,項目名稱:terraform,代碼行數:35,代碼來源:graph_config_node_variable.go

示例5: walk

func (c *Core) walk(f func(app.App, *app.Context, bool) error) error {
	root, err := c.appfileCompiled.Graph.Root()
	if err != nil {
		return fmt.Errorf(
			"Error loading app: %s", err)
	}

	// Walk the appfile graph.
	var stop int32 = 0
	return c.appfileCompiled.Graph.Walk(func(raw dag.Vertex) (err error) {
		// If we're told to stop (something else had an error), then stop early.
		// Graphs walks by default will complete all disjoint parts of the
		// graph before failing, but Otto doesn't have to do that.
		if atomic.LoadInt32(&stop) != 0 {
			return nil
		}

		// If we exit with an error, then mark the stop atomic
		defer func() {
			if err != nil {
				atomic.StoreInt32(&stop, 1)
			}
		}()

		// Convert to the rich vertex type so that we can access data
		v := raw.(*appfile.CompiledGraphVertex)

		// Do some logging to help ourselves out
		log.Printf("[DEBUG] core walking app: %s", v.File.Application.Name)

		// Get the context and app for this appfile
		appCtx, err := c.appContext(v.File)
		if err != nil {
			return fmt.Errorf(
				"Error loading Appfile for '%s': %s",
				dag.VertexName(raw), err)
		}
		app, err := c.app(appCtx)
		if err != nil {
			return fmt.Errorf(
				"Error loading App implementation for '%s': %s",
				dag.VertexName(raw), err)
		}
		defer maybeClose(app)

		// Call our callback
		return f(app, appCtx, raw == root)
	})
}
開發者ID:mbrodala,項目名稱:otto,代碼行數:49,代碼來源:core.go

示例6: Transform

func (t *TargetsTransformer) Transform(g *Graph) error {
	if len(t.Targets) > 0 && len(t.ParsedTargets) == 0 {
		addrs, err := t.parseTargetAddresses()
		if err != nil {
			return err
		}
		t.ParsedTargets = addrs
	}
	if len(t.ParsedTargets) > 0 {
		targetedNodes, err := t.selectTargetedNodes(g, t.ParsedTargets)
		if err != nil {
			return err
		}

		for _, v := range g.Vertices() {
			removable := false
			if _, ok := v.(GraphNodeAddressable); ok {
				removable = true
			}
			if vr, ok := v.(RemovableIfNotTargeted); ok {
				removable = vr.RemoveIfNotTargeted()
			}
			if removable && !targetedNodes.Include(v) {
				log.Printf("[DEBUG] Removing %q, filtered by targeting.", dag.VertexName(v))
				g.Remove(v)
			}
		}
	}
	return nil
}
開發者ID:Originate,項目名稱:terraform,代碼行數:30,代碼來源:transform_targets.go

示例7: GraphDot

// GraphDot returns the dot formatting of a visual representation of
// the given Terraform graph.
func GraphDot(g *Graph, opts *GraphDotOpts) string {
	buf := new(bytes.Buffer)

	// Start the graph
	buf.WriteString("digraph {\n")
	buf.WriteString("\tcompound = true;\n")

	// Go through all the vertices and draw it
	vertices := g.Vertices()
	dotVertices := make(map[dag.Vertex]struct{}, len(vertices))
	for _, v := range vertices {
		if dn, ok := v.(GraphNodeDotter); !ok {
			continue
		} else if dn.Dot("fake") == "" {
			continue
		}

		dotVertices[v] = struct{}{}
	}

	for v, _ := range dotVertices {
		dn := v.(GraphNodeDotter)
		scanner := bufio.NewScanner(strings.NewReader(
			dn.Dot(dag.VertexName(v))))
		for scanner.Scan() {
			buf.WriteString("\t" + scanner.Text() + "\n")
		}

		// Draw all the edges
		for _, t := range g.DownEdges(v).List() {
			target := t.(dag.Vertex)
			if _, ok := dotVertices[target]; !ok {
				continue
			}

			buf.WriteString(fmt.Sprintf(
				"\t\"%s\" -> \"%s\";\n",
				dag.VertexName(v),
				dag.VertexName(target)))
		}
	}

	// End the graph
	buf.WriteString("}\n")
	return buf.String()
}
開發者ID:jrperritt,項目名稱:terraform,代碼行數:48,代碼來源:graph_dot.go

示例8: DotNode

// GraphNodeDotter impl.
func (n *graphNodeModuleExpanded) DotNode(name string, opts *dag.DotOpts) *dag.DotNode {
	return &dag.DotNode{
		Name: name,
		Attrs: map[string]string{
			"label": dag.VertexName(n.Original),
			"shape": "component",
		},
	}
}
開發者ID:ryane,項目名稱:terraform,代碼行數:10,代碼來源:graph_config_node_module.go

示例9: Dot

// GraphNodeDotter impl.
func (n *graphNodeModuleExpanded) Dot(name string) string {
	return fmt.Sprintf(
		"\"%s\" [\n"+
			"\tlabel=\"%s\"\n"+
			"\tshape=component\n"+
			"];",
		name,
		dag.VertexName(n.Original))
}
開發者ID:jrperritt,項目名稱:terraform,代碼行數:10,代碼來源:graph_config_node.go

示例10: walk

func (c *Core) walk(f func(app.App, *app.Context, bool) error) error {
	root, err := c.appfileCompiled.Graph.Root()
	if err != nil {
		return fmt.Errorf("裝載App報錯: %s", err)
	}

	//Walk the appfile graph
	var stop int32 = 0
	return c.appfileCompiled.Graph.Walk(func(raw dag.Vertex) (err error) {
		// 如果stop(發生一些錯誤),那麽盡早stop.
		// If we're told to stop (something else had an error), then stop early.
		// Graphs walks by default will complete all disjoint parts of the
		// graph before failing, but Otto doesn't have to do that.
		if atomic.LoadInt32(&stop) != 0 {
			return nil
		}

		//如果報錯退出,我們標記stop atomic
		defer func() {
			if err != nil {
				atomic.StoreInt32(&stop, 1)
			}
		}()

		// 轉換至豐富的Vertex以便我們能夠訪問數據
		v := raw.(*appfile.CompiledGraphVertex)

		// 給appfile獲取App上下文
		appCtx, err := c.appContext(v.File)
		if err != nil {
			return fmt.Errorf(
				"loading Appfile for '%s': %s 報錯", dag.VertexName(raw), err)
		}

		app, err := c.app(appCtx)
		if err != nil {
			return fmt.Errorf(
				"獲取App實現報錯 '%s': %s", dag.VertexName(raw), err)
		}

		// 執行回調
		return f(app, appCtx, raw == root)
	})
}
開發者ID:kuuyee,項目名稱:otto-learn,代碼行數:44,代碼來源:core.go

示例11: Transform

func (t *AttachStateTransformer) Transform(g *Graph) error {
	// If no state, then nothing to do
	if t.State == nil {
		log.Printf("[DEBUG] Not attaching any state: state is nil")
		return nil
	}

	filter := &StateFilter{State: t.State}
	for _, v := range g.Vertices() {
		// Only care about nodes requesting we're adding state
		an, ok := v.(GraphNodeAttachResourceState)
		if !ok {
			continue
		}
		addr := an.ResourceAddr()

		// Get the module state
		results, err := filter.Filter(addr.String())
		if err != nil {
			return err
		}

		// Attach the first resource state we get
		found := false
		for _, result := range results {
			if rs, ok := result.Value.(*ResourceState); ok {
				log.Printf(
					"[DEBUG] Attaching resource state to %q: %s",
					dag.VertexName(v), rs)
				an.AttachResourceState(rs)
				found = true
				break
			}
		}

		if !found {
			log.Printf(
				"[DEBUG] Resource state not found for %q: %s",
				dag.VertexName(v), addr)
		}
	}

	return nil
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:44,代碼來源:transform_attach_state.go

示例12: EnterEvalTree

func (w *ContextGraphWalker) EnterEvalTree(v dag.Vertex, n EvalNode) EvalNode {
	log.Printf("[TRACE] Entering eval tree: %s", dag.VertexName(v))

	// Acquire a lock on the semaphore
	w.Context.parallelSem.Acquire()

	// We want to filter the evaluation tree to only include operations
	// that belong in this operation.
	return EvalFilter(n, EvalNodeFilterOp(w.Operation))
}
開發者ID:mnbbrown,項目名稱:terraform,代碼行數:10,代碼來源:graph_walk_context.go

示例13: Transform

func (t *ExpandTransform) Transform(v dag.Vertex) (dag.Vertex, error) {
	ev, ok := v.(GraphNodeExpandable)
	if !ok {
		// This isn't an expandable vertex, so just ignore it.
		return v, nil
	}

	// Expand the subgraph!
	log.Printf("[DEBUG] vertex %q: static expanding", dag.VertexName(ev))
	return ev.Expand(t.Builder)
}
開發者ID:ryane,項目名稱:terraform,代碼行數:11,代碼來源:transform_expand.go

示例14: DestroyEdgeInclude

// GraphNodeDestroyEdgeInclude impl.
func (n *GraphNodeConfigVariable) DestroyEdgeInclude(v dag.Vertex) bool {
	// Only include this variable in a destroy edge if the source vertex
	// "v" has a count dependency on this variable.
	log.Printf("[DEBUG] DestroyEdgeInclude: Checking: %s", dag.VertexName(v))
	cv, ok := v.(GraphNodeCountDependent)
	if !ok {
		log.Printf("[DEBUG] DestroyEdgeInclude: Not GraphNodeCountDependent: %s", dag.VertexName(v))
		return false
	}

	for _, d := range cv.CountDependentOn() {
		for _, d2 := range n.DependableName() {
			log.Printf("[DEBUG] DestroyEdgeInclude: d = %s : d2 = %s", d, d2)
			if d == d2 {
				return true
			}
		}
	}

	return false
}
開發者ID:srikalyan,項目名稱:terraform,代碼行數:22,代碼來源:graph_config_node_variable.go

示例15: Transform

func (t *ReferenceTransformer) Transform(g *Graph) error {
	// Build a reference map so we can efficiently look up the references
	vs := g.Vertices()
	m := NewReferenceMap(vs)

	// Find the things that reference things and connect them
	for _, v := range vs {
		parents, _ := m.References(v)
		parentsDbg := make([]string, len(parents))
		for i, v := range parents {
			parentsDbg[i] = dag.VertexName(v)
		}
		log.Printf(
			"[DEBUG] ReferenceTransformer: %q references: %v",
			dag.VertexName(v), parentsDbg)

		for _, parent := range parents {
			g.Connect(dag.BasicEdge(v, parent))
		}
	}

	return nil
}
開發者ID:paultyng,項目名稱:terraform,代碼行數:23,代碼來源:transform_reference.go


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