Project

General

Profile

1
package eu.dnetlib.msro.workflows.nodes;
2

    
3
import eu.dnetlib.msro.workflows.graph.Arc;
4
import eu.dnetlib.msro.workflows.graph.Token;
5
import eu.dnetlib.msro.workflows.graph.WorkflowExecutor;
6
import eu.dnetlib.msro.workflows.procs.ProcessNode;
7
import eu.dnetlib.msro.workflows.util.ProcessCallback;
8
import org.apache.commons.logging.Log;
9
import org.apache.commons.logging.LogFactory;
10
import org.springframework.beans.factory.annotation.Autowired;
11

    
12
/**
13
 * Created by michele on 18/11/15.
14
 */
15
public class LaunchWorkflowJobNode extends ProcessNode {
16

    
17
	private static final Log log = LogFactory.getLog(LaunchWorkflowJobNode.class);
18
	private String wfId;
19

    
20
	@Autowired
21
	private WorkflowExecutor executor;
22

    
23
	@Override
24
	public final void execute(final Token token) {
25

    
26
		try {
27
			final String procId = executor.startWorkflow(getWfId(), null, new ProcessCallback() {
28

    
29
				@Override
30
				public void onSuccess() {
31
					log.debug("Child workflow has been completed successfully");
32

    
33
					token.setNextArc(Arc.DEFAULT_ARC);
34
					token.release();
35
				}
36

    
37
				@Override
38
				public void onFail() {
39
					log.error("Child workflow is failed");
40
					token.markAsFailed("Child workflow is failed");
41
					token.release();
42
				}
43
			});
44
			if (log.isDebugEnabled()) {
45
				log.debug("The child workflow [" + getWfId() + "] is starting with procId: " + procId);
46
			}
47
		} catch (Throwable e) {
48
			log.error("got exception while launching child workflow", e);
49
			token.markAsFailed(e);
50
			token.release();
51
		}
52
	}
53

    
54
	public String getWfId() {
55
		return wfId;
56
	}
57

    
58
	public void setWfId(final String wfId) {
59
		this.wfId = wfId;
60
	}
61

    
62
}
(3-3/9)