Package com.puppetlabs.graph.elements

Examples of com.puppetlabs.graph.elements.RootGraph


    else {
      // mark all
      for(ModuleNodeData x : fileMap.values())
        x.mark();
    }
    RootGraph g = produceRootGraph(cancel, title, moduleData, exportData, renderAll, chain);

    instanceRules.addAll(theme.getInstanceRules());
    dotRenderer.write(cancel, output, g, theme.getDefaultRules(), instanceRules);
  }
View Full Code Here


    if(title == null)
      title = "";
    if(cancel == null)
      cancel = new NullIndicator();

    RootGraph g = new RootGraph(title, "RootGraph", "root");

    // Create Graph vertexes, one per existing module
    // and one for the root/non-modular
    for(ModuleNodeData mnd : moduleNodeData.values()) {
      cancel.assertContinue();
      if(renderAll || mnd.marked)
        if(mnd.isNode())
          g.addVertex(createVertexForPPNodeNode(mnd));
        else
          g.addVertex(createVertexForModuleNode(mnd));
    }

    // only draw the root node if it has been marked (incoming dependency), or has outgoing
    // when not rendering all, the non modular must have incoming dependencies to show.
    if(renderAll && nonModularNode.outgoing.size() > 0 || nonModularNode.marked) {
      Vertex v = createVertexForRootNode(nonModularNode);
      g.addVertex(v);
    }

    // Create Vertexes for all Edges that have data
    // (very large labels on edges does not work that well as they often overlap)
    // Skip edges that are from non marked module nodes unless everything is rendered
    for(ModuleEdge me : moduleEdges) {
      // filter out self references
      if(me.from == me.to)
        continue;
      if(renderAll || me.from.marked) {
        cancel.assertContinue();
        Vertex v = createVertexForEdge(me);
        if(v != null) {
          g.addVertex(v);
        }
      }
    }

    // Create Edges
    // If an edge has a vertex, it needs to be drawn as two separate graph edges

    for(ModuleNodeData a : Iterables.concat(moduleNodeData.values(), Collections.singleton(nonModularNode))) {
      if(!(renderAll || a.marked))
        continue; // skip non marked unless all is rendered

      for(ModuleNodeData b : a.outgoing.keySet()) {
        cancel.assertContinue();

        int resolved = 0;
        int unresolved = 0;
        int implied = 0;
        int count = 0;
        List<ModuleEdge> edges = new ArrayList<ModuleEdge>();
        Collection<ModuleEdge> outgoing = a.outgoing.get(b);
        for(ModuleEdge e : outgoing) {
          edges.add(e);
          switch(e.edgeType) {
            case IMPLIED:
              implied++;
              break;
            case UNRESOLVED:
              unresolved++;
              break;
            case RESOLVED:
              resolved++;
              break;
            default:
              throw new IllegalStateException("Illegal edge type found");
          }
          ++count;
        }
        String tooltipString = makeTooltip(a, b);
        List<String> styleClasses = classesFor(a, b);

        // CASE 1
        // A --> [...] --> B
        // A imports from resolved B
        if(count == 2 && resolved == 1 && implied == 1) {
          Edge e1 = new Edge("", STYLE_EDGE__IMPORT, a.getVertex(), edges.get(1).getVertex());
          Edge e2 = new Edge(getVersionLabel(edges.get(0)), STYLE_EDGE__RESOLVED_DEP, //
          edges.get(1).getVertex(), b.getVertex());
          g.addEdge(e1, e2);
          addTooltip(tooltipString, e1, e2);
          addStyleClasses(styleClasses, e1, e2);
          addEdgeHref(a, b, e1, e2);
        }
        else if(count == 1 && implied == 1) {
          // CASE 5
          // A --> [...]
          if(edges.get(0).to == null) {
            Edge e1 = new Edge("unresolved", STYLE_EDGE__UIMPORT, a.getVertex(), edges.get(0).getVertex());
            g.addEdge(e1);
            addTooltip(tooltipString, e1);
            addStyleClasses(styleClasses, e1);
            addEdgeHref(a, b, e1);
          }
          // CASE 8 (reference to pptp - do not draw imports -> pptp part)
          // A -->[...]
          else if(edges.get(0).to == pptpNode) {
            Edge e1 = new Edge("puppet", STYLE_EDGE__IMPORT, a.getVertex(), edges.get(0).getVertex());
            g.addEdge(e1);
            // default tooltip == label
            addStyleClasses(styleClasses, e1);
            addEdgeHref(a, b, e1);

          }
          // CASE 2 (and CASE 0 - self reference)
          // A -->[...] ~~> B
          else {
            if(edges.get(0).from != edges.get(0).to) { // skip self references
              Edge e1 = new Edge("", STYLE_EDGE__IMPORT, a.getVertex(), edges.get(0).getVertex());
              Edge e2 = new Edge(
                "implicit", STYLE_EDGE__IMPLIED_DEP, edges.get(0).getVertex(),
                edges.get(0).to.getVertex());
              g.addEdge(e1, e2);
              addTooltip(tooltipString, e1, e2);
              addStyleClasses(styleClasses, e1, e2);
              addEdgeHref(a, b, e1, e2);
            }
          }
        }
        // CASE 3
        // A --> [...] ~~>(not in range) B
        else if(count == 2 && implied == 1 && unresolved == 1) {
          Edge e1 = new Edge("", STYLE_EDGE__IMPORT, a.getVertex(), edges.get(1).getVertex());
          String label = "implicit\\nunresolved\\n" + getVersionLabel(edges.get(0));
          Edge e2 = new Edge(label, STYLE_EDGE__UNRESOLVED_IMPLIED_DEP, //
          edges.get(1).getVertex(), edges.get(1).to.getVertex());
          g.addEdge(e1, e2);
          addTooltip(tooltipString, e1, e2);
          addStyleClasses(styleClasses, e1, e2);
          addEdgeHref(a, b, e1, e2);
        }

        else if(count == 1 && unresolved == 1) {
          // CASE 7
          // A ~~> B where B is not in range
          if(edges.get(0).to.exists()) {
            String label = "unresolved\\n" + getVersionLabel(edges.get(0));
            Edge e1 = new Edge(label, STYLE_EDGE__UNRESOLVED_IMPLIED_DEP, //
            a.getVertex(), b.getVertex());
            g.addEdge(e1);
            addTooltip(tooltipString, e1);
            addStyleClasses(styleClasses, e1);
            addEdgeHref(a, b, e1);
          }
          // CASE 4
          // A --> B where B does not exist
          else {
            String label = "unresolved\\n" + getVersionLabel(edges.get(0));
            Edge e1 = new Edge(label, STYLE_EDGE__UNRESOLVED_DEP, //
            a.getVertex(), b.getVertex());
            g.addEdge(e1);
            addTooltip(tooltipString, e1);
            addStyleClasses(styleClasses, e1);
            addEdgeHref(a, b, e1);
          }
        }
        // CASE 6
        // A --> B
        // (nothing is imported from B)
        else if(count == 1 && resolved == 1) {
          Edge e1 = new Edge(getVersionLabel(edges.get(0)), STYLE_EDGE__RESOLVED_DEP, //
          a.getVertex(), b.getVertex());
          g.addEdge(e1);
          addTooltip(tooltipString, e1);
          addStyleClasses(styleClasses, e1);
          addEdgeHref(a, b, e1);
        }
        else if(count == implied) {
View Full Code Here

   */
  public void produceGraph(ICancel cancel, Catalog catalog, String catalogName, OutputStream out, IPath root) {
    if(cancel == null || catalog == null || out == null)
      throw new IllegalArgumentException("one or more parameters are null");

    RootGraph g = produceRootGraph(cancel, catalog, catalogName, root);
    GraphCSS instanceRules = getInstanceRules();
    instanceRules.addAll(getTheme().getInstanceRules());
    getDotRenderer().write(cancel, out, g, getTheme().getDefaultRules(), instanceRules);
  }
View Full Code Here

   * Produces the graph data structure (RootGraph, Vertexes, Edges).
   *
   */
  private RootGraph produceRootGraph(ICancel cancel, Catalog catalog, String catalogName, final IPath root) {

    RootGraph g = new RootGraph(catalogName, "RootGraph", "root");

    // Iterate the catalog
    // What to do with these? Are they of any value?
    // catalog.getClasses(); // list of classnames
    // catalog.getTags(); // don't know if these have any value...

    Map<String, Vertex> vertexMap = Maps.newHashMap();
    Map<CatalogResource, Vertex> resourceVertexMap = Maps.newHashMap();

    for(CatalogResource r : catalog.getResources()) {
      StringBuilder builder = new StringBuilder();
      builder.append(r.getType().toLowerCase());
      builder.append("[");
      builder.append(r.getTitle().toLowerCase());
      builder.append("]");

      Vertex v = createVertexFor(r, root);
      g.addVertex(v);
      vertexMap.put(builder.toString(), v);
      resourceVertexMap.put(r, v);
    }

    for(CatalogResource r : catalog.getResources()) {
      final Vertex source = resourceVertexMap.get(r);
      for(CatalogResourceParameter p : Iterables.filter(
        getParameterIterable(r), Predicates.not(regularParameterPredicate))) {
        String aName = p.getName();
        String style = null;
        if("subscribe".equals(aName))
          style = CatalogGraphStyles.STYLE_SubscribeEdge;
        else if("before".equals(aName))
          style = CatalogGraphStyles.STYLE_BeforeEdge;
        else if("notify".equals(aName))
          style = CatalogGraphStyles.STYLE_NotifyEdge;
        else
          style = CatalogGraphStyles.STYLE_RequireEdge;
        for(String ref : p.getValue()) {
          Vertex target = vertexMap.get(ref.toLowerCase());
          if(target == null) {
            target = createVertexForMissingResource(ref);
            vertexMap.put(ref.toLowerCase(), target); // keep it if there are more references
            g.addVertex(target);
          }
          Edge edge = new Edge(aName, style, source, target);
          g.addEdge(edge);
        }
      }
    }
    for(CatalogEdge e : catalog.getEdges()) {
      Vertex source = vertexMap.get(e.getSource().toLowerCase());
      Vertex target = vertexMap.get(e.getTarget().toLowerCase());
      Edge edge = new Edge("", STYLE_ResourceEdge, source, target);
      g.addEdge(edge);
    }

    return g;
  }
View Full Code Here

  public void produceGraph(ICancel cancel, String title, Catalog oldCatalog, IPath oldRoot, Catalog newCatalog,
      IPath newRoot, OutputStream out) {
    if(cancel == null || oldCatalog == null || newCatalog == null || out == null)
      throw new IllegalArgumentException("one or more parameters are null");

    RootGraph g = produceRootGraph(cancel, title, oldCatalog, oldRoot, newCatalog, newRoot);
    getInstanceRules().addAll(getTheme().getInstanceRules());
    getDotRenderer().write(cancel, out, g, getTheme().getDefaultRules(), getInstanceRules());
  }
View Full Code Here

   *
   */
  private RootGraph produceRootGraph(ICancel cancel, String title, Catalog oldCatalog, IPath oldRoot,
      Catalog newCatalog, IPath newRoot) {

    RootGraph g = new RootGraph(title, "RootGraph", "root");

    // Iterate the catalog
    // What to do with classes and tags? Are they of any value?
    // catalog.getClasses(); // list of classnames
    // catalog.getTags(); // don't know if these have any value...

    Map<String, Vertex> oldVertexMap = Maps.newHashMap();
    Map<String, Vertex> newVertexMap = Maps.newHashMap();
    Map<CatalogResource, Vertex> oldResourceVertexMap = Maps.newHashMap();
    Map<CatalogResource, Vertex> newResourceVertexMap = Maps.newHashMap();
    Map<Vertex, CatalogResource> catalogMap = Maps.newHashMap();

    // create all vertexes for old
    createVertexesFor(oldCatalog.getResources(), oldVertexMap, oldResourceVertexMap, catalogMap);

    // create all vertexes for new
    createVertexesFor(newCatalog.getResources(), newVertexMap, newResourceVertexMap, catalogMap);

    // compute Venn set
    Set<String> oldKeys = oldVertexMap.keySet();
    Set<String> newKeys = newVertexMap.keySet();
    SetView<String> inBoth = Sets.intersection(oldKeys, newKeys);
    SetView<String> removedInNew = Sets.difference(oldKeys, newKeys);
    SetView<String> addedInNew = Sets.difference(newKeys, oldKeys);
    Map<String, Vertex> resultingVertexMap = Maps.newHashMap();

    for(String s : removedInNew) {
      Vertex v = oldVertexMap.get(s);
      v.addStyleClass(STYLE_Removed);
      v.setStyles(labelStyleForResource(catalogMap.get(v), oldRoot, null, null, new String[1]));
      resultingVertexMap.put(s, v);
      g.addVertex(v);
    }
    for(String s : addedInNew) {
      Vertex v = newVertexMap.get(s);
      v.addStyleClass(STYLE_Added);
      v.setStyles(labelStyleForResource(null, null, catalogMap.get(v), newRoot, new String[1]));
      resultingVertexMap.put(s, v);
      g.addVertex(v);
    }
    for(String s : inBoth) {
      Vertex vOld = oldVertexMap.get(s);
      Vertex vNew = newVertexMap.get(s);

      Vertex v = new Vertex("", STYLE_Resource);
      String computedStyle[] = new String[1];
      v.setStyles(labelStyleForResource(
        catalogMap.get(vOld), oldRoot, catalogMap.get(vNew), newRoot, computedStyle));
      v.addStyleClass(computedStyle[0]);
      resultingVertexMap.put(s, v);
      g.addVertex(v);
    }

    // Process Edges
    Map<String, Edge> oldEdgeMap = Maps.newHashMap();
    Map<String, Edge> newEdgeMap = Maps.newHashMap();
View Full Code Here

TOP

Related Classes of com.puppetlabs.graph.elements.RootGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.