Revision 47491
Added by Michele Artini almost 7 years ago
LaunchWorkflowJobNode.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.workflows.nodes; |
2 | 2 |
|
3 |
import org.apache.commons.logging.Log; |
|
4 |
import org.apache.commons.logging.LogFactory; |
|
5 | 3 |
import org.springframework.beans.factory.annotation.Autowired; |
6 | 4 |
import org.springframework.context.annotation.Scope; |
7 | 5 |
import org.springframework.stereotype.Component; |
... | ... | |
10 | 8 |
import eu.dnetlib.clients.msro.MsroClient; |
11 | 9 |
import eu.dnetlib.msro.annotations.ProcessNode; |
12 | 10 |
import eu.dnetlib.msro.controllers.MsroWorkerController; |
13 |
import eu.dnetlib.msro.workflows.Arc;
|
|
11 |
import eu.dnetlib.msro.workflows.procs.AsyncProcessNode;
|
|
14 | 12 |
import eu.dnetlib.msro.workflows.procs.ProcessAware; |
15 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
16 | 13 |
import eu.dnetlib.msro.workflows.procs.WorkflowProcess; |
17 | 14 |
import eu.dnetlib.services.async.AsyncClientCallback; |
18 |
import eu.dnetlib.services.async.AsyncResponse; |
|
19 | 15 |
|
20 | 16 |
@Component |
21 | 17 |
@Scope("prototype") |
22 | 18 |
@ProcessNode("LaunchWorkflow") |
23 |
public class LaunchWorkflowJobNode extends AbstractProcessNode implements ProcessAware {
|
|
19 |
public class LaunchWorkflowJobNode extends AsyncProcessNode implements ProcessAware {
|
|
24 | 20 |
|
25 |
private static final Log log = LogFactory.getLog(LaunchWorkflowJobNode.class); |
|
26 | 21 |
private String wfId; |
27 | 22 |
|
28 | 23 |
@Autowired |
... | ... | |
34 | 29 |
private MsroWorkerController worker; |
35 | 30 |
|
36 | 31 |
@Override |
37 |
public final void execute(final Token token) { |
|
38 |
|
|
39 |
final String nodeDesc = toString(); |
|
40 |
|
|
41 |
log.info("START NODE: " + nodeDesc); |
|
42 |
try { |
|
43 |
final MsroClient msro = serviceClientFactory.getClient(MsroClient.class); |
|
44 |
|
|
45 |
msro.startWorkflow(getWfId(), process.getProfileId(), worker.getBaseUrl(), new AsyncClientCallback() { |
|
46 |
|
|
47 |
@Override |
|
48 |
public void onGoing(final AsyncResponse res) { |
|
49 |
log.debug("Child workflow is running"); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public void onFailed(final AsyncResponse res) { |
|
54 |
log.error("Child workflow is failed"); |
|
55 |
log.info("END NODE: " + nodeDesc); |
|
56 |
token.releaseAsFailed("Child workflow is failed"); |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public void onDone(final AsyncResponse res) { |
|
61 |
log.debug("Child workflow has been completed successfully"); |
|
62 |
log.info("END NODE: " + nodeDesc); |
|
63 |
token.release(Arc.DEFAULT_ARC); |
|
64 |
} |
|
65 |
}); |
|
66 |
|
|
67 |
} catch (final Throwable e) { |
|
68 |
log.error("got exception while launching child workflow", e); |
|
69 |
token.releaseAsFailed(e); |
|
70 |
} |
|
32 |
public void execute(final AsyncClientCallback callback) { |
|
33 |
serviceClientFactory.getClient(MsroClient.class).startWorkflow(getWfId(), process.getProfileId(), worker.getBaseUrl(), callback); |
|
71 | 34 |
} |
72 | 35 |
|
73 | 36 |
public String getWfId() { |
Also available in: Unified diff
refacoring