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);
}
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();
}
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();
}
Aggregations