public static Date addTime(Date date, long milliSecondsToAdd) {
return new Date(date.getTime() + milliSecondsToAdd);
}
public static Date getCutOffTime(Entity entity, String nominalTime) throws FalconException {
ExpressionHelper evaluator = ExpressionHelper.get();
Date instanceStart = EntityUtil.parseDateUTC(nominalTime);
ExpressionHelper.setReferenceDate(instanceStart);
Date endTime;
Date feedCutOff = new Date(0);
if (entity.getEntityType() == EntityType.FEED) {
if (((Feed) entity).getLateArrival() == null) {
LOG.debug("Feed's " + entity.getName()
+ " late arrival cut-off is not configured, returning");
return feedCutOff;
}
String lateCutOff = ((Feed) entity).getLateArrival().getCutOff()
.toString();
endTime = EntityUtil.parseDateUTC(nominalTime);
long feedCutOffPeriod = evaluator.evaluate(lateCutOff, Long.class);
endTime = addTime(endTime, feedCutOffPeriod);
return endTime;
} else if (entity.getEntityType() == EntityType.PROCESS) {
Process process = (Process) entity;
ConfigurationStore store = ConfigurationStore.get();
for (LateInput lp : process.getLateProcess().getLateInputs()) {
Feed feed = null;
String endInstanceTime = "";
for (Input input : process.getInputs().getInputs()) {
if (input.getName().equals(lp.getInput())) {
endInstanceTime = input.getEnd();
feed = store.get(EntityType.FEED, input.getFeed());
break;
}
}
if (feed == null) {
throw new IllegalStateException("No such feed: " + lp.getInput());
}
if (feed.getLateArrival() == null) {
LOG.debug("Feed's " + feed.getName()
+ " late arrival cut-off is not configured, ignoring this feed");
continue;
}
String lateCutOff = feed.getLateArrival().getCutOff()
.toString();
endTime = evaluator.evaluate(endInstanceTime, Date.class);
long feedCutOffPeriod = evaluator.evaluate(lateCutOff,
Long.class);
endTime = addTime(endTime, feedCutOffPeriod);
if (endTime.after(feedCutOff)) {
feedCutOff = endTime;