public COORDINATORAPP createDefaultCoordinator(Cluster cluster, Path bundlePath) throws IvoryException {
Process process = getEntity();
if (process == null)
return null;
COORDINATORAPP coord = new COORDINATORAPP();
String coordName = EntityUtil.getWorkflowName(Tag.DEFAULT,process).toString();
Path coordPath = getCoordPath(bundlePath, coordName);
// coord attributes
coord.setName(coordName);
org.apache.ivory.entity.v0.process.Cluster processCluster = ProcessHelper.getCluster(process, cluster.getName());
coord.setStart(SchemaHelper.formatDateUTC(processCluster.getValidity().getStart()));
coord.setEnd(SchemaHelper.formatDateUTC(processCluster.getValidity().getEnd()));
coord.setTimezone(process.getTimezone().getID());
coord.setFrequency("${coord:" + process.getFrequency().toString() + "}");
// controls
CONTROLS controls = new CONTROLS();
controls.setConcurrency(String.valueOf(process.getParallel()));
controls.setExecution(process.getOrder().name());
Frequency timeout = process.getTimeout();
long frequency_ms = ExpressionHelper.get().
evaluate(process.getFrequency().toString(), Long.class);
long timeout_ms;
if (timeout != null) {
timeout_ms = ExpressionHelper.get().
evaluate(process.getTimeout().toString(), Long.class);
} else {
timeout_ms = frequency_ms * 6;
if (timeout_ms < THIRTY_MINUTES) timeout_ms = THIRTY_MINUTES;
}
controls.setTimeout(String.valueOf(timeout_ms / (1000 * 60)));
if (timeout_ms / frequency_ms * 2 > 0) {
controls.setThrottle(String.valueOf(timeout_ms / frequency_ms * 2));
}
coord.setControls(controls);
// Configuration
Map<String, String> props = createCoordDefaultConfiguration(cluster, coordPath, coordName);
List<String> inputFeeds = new ArrayList<String>();
List<String> inputPaths = new ArrayList<String>();
// inputs
if (process.getInputs() != null) {
for (Input input : process.getInputs().getInputs()) {
if(!input.isOptional()) {
if (coord.getDatasets() == null)
coord.setDatasets(new DATASETS());
if (coord.getInputEvents() == null)
coord.setInputEvents(new INPUTEVENTS());
SYNCDATASET syncdataset = createDataSet(input.getFeed(), cluster, input.getName(), LocationType.DATA);
coord.getDatasets().getDatasetOrAsyncDataset().add(syncdataset);
DATAIN datain = createDataIn(input);
coord.getInputEvents().getDataIn().add(datain);
}
String inputExpr = getELExpression("dataIn('" + input.getName() + "', '" + input.getPartition() + "')");
props.put(input.getName(), inputExpr);
inputFeeds.add(input.getName());
inputPaths.add(inputExpr);
}
}
props.put("ivoryInPaths", join(inputPaths.iterator(), '#'));
props.put("ivoryInputFeeds", join(inputFeeds.iterator(), '#'));
// outputs
List<String> outputFeeds = new ArrayList<String>();
List<String> outputPaths = new ArrayList<String>();
if (process.getOutputs() != null) {
if (coord.getDatasets() == null)
coord.setDatasets(new DATASETS());
if (coord.getOutputEvents() == null)
coord.setOutputEvents(new OUTPUTEVENTS());
for (Output output : process.getOutputs().getOutputs()) {
SYNCDATASET syncdataset = createDataSet(output.getFeed(), cluster, output.getName(),LocationType.DATA);
coord.getDatasets().getDatasetOrAsyncDataset().add(syncdataset);
DATAOUT dataout = createDataOut(output);
coord.getOutputEvents().getDataOut().add(dataout);
String outputExpr = "${coord:dataOut('" + output.getName() + "')}";
props.put(output.getName(), outputExpr);
outputFeeds.add(output.getName());
outputPaths.add(outputExpr);
// stats and meta paths
createOutputEvent(output.getFeed(),output.getName(), cluster, "stats",
LocationType.STATS, coord, props, output.getInstance());
createOutputEvent(output.getFeed(),output.getName(), cluster, "meta",
LocationType.META, coord, props,output.getInstance());
createOutputEvent(output.getFeed(),output.getName(), cluster, "tmp",
LocationType.TMP, coord, props,output.getInstance());
}
}
// Output feed name and path for parent workflow
props.put(ARG.feedNames.getPropName(), join(outputFeeds.iterator(), ','));
props.put(ARG.feedInstancePaths.getPropName(), join(outputPaths.iterator(), ','));
// create parent wf
createWorkflow(cluster, DEFAULT_WF_TEMPLATE, coordName, coordPath);
WORKFLOW wf = new WORKFLOW();
wf.setAppPath(getStoragePath(coordPath.toString()));
wf.setConfiguration(getCoordConfig(props));
// set coord action to parent wf
org.apache.ivory.oozie.coordinator.ACTION action = new org.apache.ivory.oozie.coordinator.ACTION();
action.setWorkflow(wf);
coord.setAction(action);
return coord;
}