Search in sources :

Example 1 with DirectedGraph

use of org.jgrapht.DirectedGraph in project ambrose by twitter.

the class AmbroseCascadingNotifier method onStarting.

/**
   * The onStarting event is fired when a Flow instance receives the start() message. A Flow is cut
   * down into executing units called stepFlow. A stepFlow contains a stepFlowJob which represents
   * the mapreduce job to be submitted to Hadoop. The ambrose graph is constructed from the step
   * graph found in flow object.
   *
   * @param flow the flow.
   */
@Override
@SuppressWarnings("unchecked")
public void onStarting(Flow flow) {
    // init flow
    List<FlowStep> steps = flow.getFlowSteps();
    totalNumberOfJobs = steps.size();
    currentFlowId = flow.getID();
    Properties props = new Properties();
    props.putAll(flow.getConfigAsProperties());
    try {
        statsWriteService.initWriteService(props);
    } catch (IOException e) {
        LOG.error("Failed to initialize statsWriteService", e);
    }
    // convert graph from cascading to jgrapht
    FlowStepGraph flowStepGraph = Flows.getStepGraphFrom(flow);
    DirectedGraph graph = new DefaultDirectedGraph<BaseFlowStep, FlowGraphEdge>(new EdgeFactory<BaseFlowStep, FlowGraphEdge>() {

        @Override
        public FlowGraphEdge createEdge(BaseFlowStep src, BaseFlowStep dest) {
            return new FlowGraphEdge(src.getID(), dest.getID());
        }
    });
    for (FlowStep v : flowStepGraph.vertexSet()) {
        graph.addVertex(v);
    }
    for (ProcessEdge e : flowStepGraph.edgeSet()) {
        graph.addEdge(e.getSourceProcessID(), e.getSinkProcessID());
    }
    // convert graph from jgrapht to ambrose
    AmbroseCascadingGraphConverter converter = new AmbroseCascadingGraphConverter(graph, nodesByName);
    converter.convert();
    AmbroseUtils.sendDagNodeNameMap(statsWriteService, currentFlowId, nodesByName);
}
Also used : DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) FlowStepGraph(cascading.flow.planner.process.FlowStepGraph) BaseFlowStep(cascading.flow.planner.BaseFlowStep) FlowStep(cascading.flow.FlowStep) BaseFlowStep(cascading.flow.planner.BaseFlowStep) IOException(java.io.IOException) Properties(java.util.Properties) DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) DirectedGraph(org.jgrapht.DirectedGraph) ProcessEdge(cascading.flow.planner.process.ProcessEdge)

Example 2 with DirectedGraph

use of org.jgrapht.DirectedGraph in project candle-decompiler by bradsdavis.

the class DOTExporter method export.

//~ Methods ----------------------------------------------------------------
/**
     * Exports a graph into a plain text file in DOT format.
     *
     * @param writer the writer to which the graph to be exported
     * @param g the graph to be exported
     */
public void export(Writer writer, Graph<V, E> g, List<Subgraph> subGraphs) {
    PrintWriter out = new PrintWriter(writer);
    String indent = "  ";
    String connector;
    if (g instanceof DirectedGraph<?, ?>) {
        out.println("digraph G {");
        connector = " -> ";
    } else {
        out.println("graph G {");
        connector = " -- ";
    }
    if (subGraphs != null) {
        for (Subgraph sub : subGraphs) {
            this.subgraphExporter.export(writer, sub);
        }
    }
    for (V v : g.vertexSet()) {
        out.print(indent + getVertexID(v));
        String labelName = null;
        if (vertexLabelProvider != null) {
            labelName = vertexLabelProvider.getVertexName(v);
        }
        Map<String, String> attributes = null;
        if (vertexAttributeProvider != null) {
            attributes = vertexAttributeProvider.getComponentAttributes(v);
        }
        renderAttributes(out, labelName, attributes);
        out.println(";");
    }
    for (E e : g.edgeSet()) {
        String source = getVertexID(g.getEdgeSource(e));
        String target = getVertexID(g.getEdgeTarget(e));
        out.print(indent + source + connector + target);
        String labelName = null;
        if (edgeLabelProvider != null) {
            labelName = edgeLabelProvider.getEdgeName(e);
        }
        Map<String, String> attributes = null;
        if (edgeAttributeProvider != null) {
            attributes = edgeAttributeProvider.getComponentAttributes(e);
        }
        renderAttributes(out, labelName, attributes);
        out.println(";");
    }
    out.println("}");
    out.flush();
}
Also used : DirectedGraph(org.jgrapht.DirectedGraph) Subgraph(org.jgrapht.graph.Subgraph) PrintWriter(java.io.PrintWriter)

Example 3 with DirectedGraph

use of org.jgrapht.DirectedGraph in project candle-decompiler by bradsdavis.

the class DOTSubgraphExporter method export.

//~ Methods ----------------------------------------------------------------
/**
     * Exports a graph into a plain text file in DOT format.
     *
     * @param writer the writer to which the graph to be exported
     * @param g the graph to be exported
     */
public void export(Writer writer, Subgraph<V, E, ?> g) {
    String name = UUID.randomUUID().toString();
    if (g instanceof NamedDirectedSubgraph) {
        name = ((NamedDirectedSubgraph) g).getName();
    }
    PrintWriter out = new PrintWriter(writer);
    String indent = "  ";
    String connector;
    if (g instanceof DirectedGraph<?, ?>) {
        out.println("subgraph cluster_" + name + " {");
        connector = " -> ";
    } else {
        out.println("subgraph cluster_" + name + " {");
        connector = " -- ";
    }
    for (V v : g.vertexSet()) {
        out.print(indent + getVertexID(v));
        String labelName = null;
        if (vertexLabelProvider != null) {
            labelName = vertexLabelProvider.getVertexName(v);
        }
        Map<String, String> attributes = null;
        if (vertexAttributeProvider != null) {
            attributes = vertexAttributeProvider.getComponentAttributes(v);
        }
        renderAttributes(out, labelName, attributes);
        out.println(";");
    }
    out.println("label=\"" + name + "\";");
    out.println("}");
    out.flush();
}
Also used : DirectedGraph(org.jgrapht.DirectedGraph) NamedDirectedSubgraph(org.candle.decompiler.instruction.graph.vertex.NamedDirectedSubgraph) PrintWriter(java.io.PrintWriter)

Aggregations

DirectedGraph (org.jgrapht.DirectedGraph)3 PrintWriter (java.io.PrintWriter)2 FlowStep (cascading.flow.FlowStep)1 BaseFlowStep (cascading.flow.planner.BaseFlowStep)1 FlowStepGraph (cascading.flow.planner.process.FlowStepGraph)1 ProcessEdge (cascading.flow.planner.process.ProcessEdge)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 NamedDirectedSubgraph (org.candle.decompiler.instruction.graph.vertex.NamedDirectedSubgraph)1 DefaultDirectedGraph (org.jgrapht.graph.DefaultDirectedGraph)1 Subgraph (org.jgrapht.graph.Subgraph)1