}
private COORDINATORAPP createAndGetCoord(Feed feed, Cluster srcCluster, Cluster trgCluster, Path bundlePath)
throws FalconException {
COORDINATORAPP replicationCoord;
String coordName;
try {
replicationCoord = getCoordinatorTemplate(REPLICATION_COORD_TEMPLATE);
coordName = EntityUtil.getWorkflowName(Tag.REPLICATION, Arrays.asList(srcCluster.getName()),
feed).toString();
replicationCoord.setName(coordName);
replicationCoord.setFrequency("${coord:" + feed.getFrequency().toString() + "}");
long frequencyInMillis = ExpressionHelper.get().
evaluate(feed.getFrequency().toString(), Long.class);
long timeoutInMillis = frequencyInMillis * 6;
if (timeoutInMillis < THIRTY_MINUTES) {
timeoutInMillis = THIRTY_MINUTES;
}
Map<String, String> props = getEntityProperties();
String timeout = props.get(TIMEOUT);
if (timeout!=null) {
try{
timeoutInMillis= ExpressionHelper.get().
evaluate(timeout, Long.class);
} catch (Exception ignore) {
LOG.error("Unable to evaluate timeout:", ignore);
}
}
String parallelProp = props.get(PARALLEL);
int parallel = 1;
if (parallelProp != null) {
try {
parallel = Integer.parseInt(parallelProp);
} catch (NumberFormatException ignore) {
LOG.error("Unable to parse parallel:", ignore);
}
}
replicationCoord.getControls().setTimeout(String.valueOf(timeoutInMillis / (1000 * 60)));
replicationCoord.getControls().setThrottle(String.valueOf(timeoutInMillis / frequencyInMillis * 2));
replicationCoord.getControls().setConcurrency(String.valueOf(parallel));
Frequency replicationDelay = FeedHelper.getCluster(feed,
srcCluster.getName()).getDelay();
long delayInMillis=0;
if (replicationDelay != null) {
delayInMillis = ExpressionHelper.get().evaluate(
replicationDelay.toString(), Long.class);
long delayInMins = -1 * delayInMillis / (1000 * 60);
String elExp = "${now(0," + delayInMins + ")}";
replicationCoord.getInputEvents().getDataIn().get(0)
.getInstance().set(0, elExp);
replicationCoord.getOutputEvents().getDataOut().get(0)
.setInstance(elExp);
}
Date srcStartDate = FeedHelper.getCluster(feed, srcCluster.getName()).getValidity().getStart();
srcStartDate=new Date(srcStartDate.getTime()+delayInMillis);
Date srcEndDate = FeedHelper.getCluster(feed, srcCluster.getName()).getValidity().getEnd();
Date trgStartDate = FeedHelper.getCluster(feed, trgCluster.getName()).getValidity().getStart();
Date trgEndDate = FeedHelper.getCluster(feed, trgCluster.getName()).getValidity().getEnd();
trgStartDate=new Date(trgStartDate.getTime()+delayInMillis);
if (srcStartDate.after(trgEndDate)
|| trgStartDate.after(srcEndDate)) {
LOG.warn("Not creating replication coordinator, as the source cluster:"
+ srcCluster.getName()
+ " and target cluster: "
+ trgCluster.getName()
+ " do not have overlapping dates");
return null;
}
replicationCoord.setStart(
srcStartDate.after(trgStartDate) ? SchemaHelper.formatDateUTC(srcStartDate) : SchemaHelper
.formatDateUTC(trgStartDate));
replicationCoord.setEnd(
srcEndDate.before(trgEndDate) ? SchemaHelper.formatDateUTC(srcEndDate) : SchemaHelper
.formatDateUTC(trgEndDate));
replicationCoord.setTimezone(feed.getTimezone().getID());
SYNCDATASET inputDataset = (SYNCDATASET) replicationCoord.getDatasets().getDatasetOrAsyncDataset().get(0);
SYNCDATASET outputDataset = (SYNCDATASET) replicationCoord.getDatasets().getDatasetOrAsyncDataset().get(1);
inputDataset.setUriTemplate(new Path(ClusterHelper.getStorageUrl(srcCluster),
FeedHelper.getLocation(feed, LocationType.DATA, srcCluster.getName()).getPath()).toString());
outputDataset.setUriTemplate(getStoragePath(
FeedHelper.getLocation(feed, LocationType.DATA, trgCluster.getName()).getPath()));
setDatasetValues(inputDataset, feed, srcCluster);
setDatasetValues(outputDataset, feed, srcCluster);
if (feed.getAvailabilityFlag() == null) {
inputDataset.setDoneFlag("");
} else {
inputDataset.setDoneFlag(feed.getAvailabilityFlag());
}
} catch (FalconException e) {
throw new FalconException("Cannot unmarshall replication coordinator template", e);
}
Path wfPath = getCoordPath(bundlePath, coordName);
replicationCoord.setAction(getReplicationWorkflowAction(srcCluster, trgCluster, wfPath, coordName));
return replicationCoord;
}