96 lines
2.7 KiB
Java
96 lines
2.7 KiB
Java
package eu.dnetlib.manager.wf.nodes;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.UUID;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import eu.dnetlib.manager.wf.WorkflowManagerService;
|
|
import eu.dnetlib.manager.wf.model.WorkflowConfiguration;
|
|
import eu.dnetlib.manager.wf.workflows.procs.ExecutionStatus;
|
|
import eu.dnetlib.manager.wf.workflows.procs.ProcessAware;
|
|
import eu.dnetlib.manager.wf.workflows.procs.Token;
|
|
import eu.dnetlib.manager.wf.workflows.procs.WorkflowProcess;
|
|
import eu.dnetlib.manager.wf.workflows.util.NodeCallback;
|
|
import eu.dnetlib.manager.wf.workflows.util.ProcessCallback;
|
|
|
|
/**
|
|
* Created by michele on 18/11/15.
|
|
*/
|
|
public class LaunchWorkflowJobNode extends ProcessNode implements ProcessAware {
|
|
|
|
private static final Log log = LogFactory.getLog(LaunchWorkflowJobNode.class);
|
|
|
|
private String wfId;
|
|
|
|
@Autowired
|
|
private WorkflowManagerService wfManagerService;
|
|
|
|
private WorkflowProcess process;
|
|
|
|
@Override
|
|
public final void execute(final Token token, final NodeCallback nodeCallback) {
|
|
try {
|
|
final WorkflowConfiguration conf = new WorkflowConfiguration();
|
|
conf.setId("CHILD_" + UUID.randomUUID());
|
|
conf.setParentId(process.getWfConfId());
|
|
conf.setDetails(new HashMap<>());
|
|
conf.setPriority(100);
|
|
conf.setDsId(process.getDsId());
|
|
conf.setDsName(process.getDsName());
|
|
conf.setApiId(process.getDsInterface());
|
|
conf.setEnabled(true);
|
|
conf.setConfigured(true);
|
|
conf.setSchedulingEnabled(false);
|
|
conf.setCronExpression("");
|
|
conf.setCronMinInterval(0);
|
|
conf.setWorkflow(wfId);
|
|
conf.setDestroyWf(null);
|
|
conf.setSystemParams(process.getGlobalParams());
|
|
conf.setUserParams(new HashMap<>());
|
|
|
|
final ExecutionStatus info = wfManagerService.startWorkflow(wfId, conf, new ProcessCallback() {
|
|
|
|
@Override
|
|
public void onSuccess(final WorkflowProcess t) {
|
|
log.debug("Child workflow has been completed successfully");
|
|
nodeCallback.onComplete(token);
|
|
}
|
|
|
|
@Override
|
|
public void onFail(final WorkflowProcess t) {
|
|
log.error("Child workflow is failed");
|
|
nodeCallback.onFail(token);
|
|
}
|
|
|
|
});
|
|
|
|
if (log.isDebugEnabled()) {
|
|
log.debug("The child workflow [conf: " + conf.getId() + "] is starting with procId: " + info.getProcessId());
|
|
}
|
|
|
|
token.setProgressMessage("Launched sub workflow, proc: " + info.getProcessId());
|
|
|
|
} catch (final Throwable e) {
|
|
log.error("got exception while launching child workflow", e);
|
|
nodeCallback.onFail(token);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setProcess(final WorkflowProcess process) {
|
|
this.process = process;
|
|
}
|
|
|
|
public String getWfId() {
|
|
return wfId;
|
|
}
|
|
|
|
public void setWfId(final String wfId) {
|
|
this.wfId = wfId;
|
|
}
|
|
|
|
}
|