log.error("Error constructing job execution context during outhandler invocation");
throw new GFacException(e);
}
launch(jobExecutionContext);
}
monitorPublisher.publish(new GfacExperimentStateChangeRequest(new MonitorID(jobExecutionContext), GfacExperimentState.OUTHANDLERSINVOKING));
for (GFacHandlerConfig handlerClassName : handlers) {
Class<? extends GFacHandler> handlerClass;
GFacHandler handler;
try {
handlerClass = Class.forName(handlerClassName.getClassName().trim()).asSubclass(GFacHandler.class);
handler = handlerClass.newInstance();
String plState = GFacUtils.getPluginState(zk, jobExecutionContext, handlerClassName.getClassName());
if (Integer.valueOf(plState) >= GfacPluginState.INVOKED.getValue()) {
if (handler instanceof GFacRecoverableHandler) {
// if these already ran we re-run only recoverable handlers
log.info(handlerClassName.getClassName() + " is a recoverable handler so we recover the handler");
GFacUtils.createPluginZnode(zk, jobExecutionContext, handlerClassName.getClassName(), GfacPluginState.INVOKING);
((GFacRecoverableHandler) handler).recover(jobExecutionContext);
GFacUtils.updatePluginState(zk, jobExecutionContext, handlerClassName.getClassName(), GfacPluginState.COMPLETED);
} else {
log.info(handlerClassName.getClassName() + " is not a recoverable handler so we do not run because it already ran in last-run");
}
} else {
log.info(handlerClassName.getClassName() + " never ran so we run this is normal mode");
GFacUtils.createPluginZnode(zk, jobExecutionContext, handlerClassName.getClassName(), GfacPluginState.INVOKING);
handler.initProperties(handlerClassName.getProperties());
handler.invoke(jobExecutionContext);
GFacUtils.updatePluginState(zk, jobExecutionContext, handlerClassName.getClassName(), GfacPluginState.COMPLETED);
}
} catch (ClassNotFoundException e) {
log.error(e.getMessage());
throw new GFacException("Cannot load handler class " + handlerClassName, e);
} catch (InstantiationException e) {
log.error(e.getMessage());
throw new GFacException("Cannot instantiate handler class " + handlerClassName, e);
} catch (IllegalAccessException e) {
log.error(e.getMessage());
throw new GFacException("Cannot instantiate handler class " + handlerClassName, e);
} catch (Exception e) {
// TODO: Better error reporting.
throw new GFacException("Error Executing a OutFlow Handler", e);
}
}
monitorPublisher.publish(new GfacExperimentStateChangeRequest(new MonitorID(jobExecutionContext), GfacExperimentState.OUTHANDLERSINVOKED));
// At this point all the execution is finished so we update the task and experiment statuses.
// Handler authors does not have to worry about updating experiment or task statuses.
monitorPublisher.publish(new
ExperimentStatusChangeRequest(new ExperimentIdentity(jobExecutionContext.getExperimentID()),
ExperimentState.COMPLETED));
// Updating the task status if there's any task associated
monitorPublisher.publish(new TaskStatusChangeRequest(
new TaskIdentity(jobExecutionContext.getExperimentID(),
jobExecutionContext.getWorkflowNodeDetails().getNodeInstanceId(),
jobExecutionContext.getTaskData().getTaskID()), TaskState.COMPLETED
));
monitorPublisher.publish(new GfacExperimentStateChangeRequest(new MonitorID(jobExecutionContext), GfacExperimentState.COMPLETED));
}