* @param program
* Optimized PACT plan that is translated into a JobGraph.
* @return JobGraph generated from PACT plan.
*/
public JobGraph compileJobGraph(OptimizedPlan program) {
this.jobGraph = new JobGraph(program.getJobName());
this.vertices = new HashMap<PlanNode, AbstractJobVertex>();
this.chainedTasks = new HashMap<PlanNode, TaskInChain>();
this.chainedTasksInSequence = new ArrayList<TaskInChain>();
this.auxVertices = new ArrayList<AbstractJobVertex>();
this.iterations = new HashMap<IterationPlanNode, IterationDescriptor>();
this.maxDegreeVertex = null;
// generate Nephele job graph
program.accept(this);
// finalize the iterations
for (IterationDescriptor iteration : this.iterations.values()) {
if (iteration.getIterationNode() instanceof BulkIterationPlanNode) {
finalizeBulkIteration(iteration);
} else if (iteration.getIterationNode() instanceof WorksetIterationPlanNode) {
finalizeWorksetIteration(iteration);
} else {
throw new CompilerException();
}
}
// now that the traversal is done, we have the chained tasks write their configs into their
// parents' configurations
for (int i = 0; i < this.chainedTasksInSequence.size(); i++) {
TaskInChain tic = this.chainedTasksInSequence.get(i);
TaskConfig t = new TaskConfig(tic.getContainingVertex().getConfiguration());
t.addChainedTask(tic.getChainedTask(), tic.getTaskConfig(), tic.getTaskName());
}
// now that all have been created, make sure that all share their instances with the one
// with the highest degree of parallelism
if (program.getInstanceTypeName() != null) {
this.maxDegreeVertex.setInstanceType(program.getInstanceTypeName());
} else {
LOG.warn("No instance type assigned to JobVertex.");
}
for (AbstractJobVertex vertex : this.vertices.values()) {
if (vertex != this.maxDegreeVertex) {
vertex.setVertexToShareInstancesWith(this.maxDegreeVertex);
}
}
for (AbstractJobVertex vertex : this.auxVertices) {
if (vertex != this.maxDegreeVertex) {
vertex.setVertexToShareInstancesWith(this.maxDegreeVertex);
}
}
// add registered cache file into job configuration
for (Entry<String, String> e: program.getOriginalPactPlan().getCachedFiles()) {
DistributedCache.addCachedFile(e.getKey(), e.getValue(), this.jobGraph.getJobConfiguration());
}
JobGraph graph = this.jobGraph;
// release all references again
this.maxDegreeVertex = null;
this.vertices = null;
this.chainedTasks = null;