1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.dhp;
|
2
|
|
3
|
import org.apache.commons.logging.Log;
|
4
|
import org.apache.commons.logging.LogFactory;
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
|
7
|
import com.googlecode.sarasvati.Engine;
|
8
|
import com.googlecode.sarasvati.NodeToken;
|
9
|
|
10
|
import eu.dnetlib.dhp.message.Message;
|
11
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
12
|
import eu.dnetlib.msro.openaireplus.workflows.nodes.dhp.message.DnetMessageManager;
|
13
|
import eu.dnetlib.msro.workflows.hadoop.SubmitHadoopJobNode;
|
14
|
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode;
|
15
|
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener;
|
16
|
import eu.dnetlib.msro.workflows.util.ProgressProvider;
|
17
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
18
|
|
19
|
public class SubmitDnetHadoopJobNode extends SubmitHadoopJobNode implements ProgressProvider, ProgressJobNode {
|
20
|
|
21
|
private static final Log log = LogFactory.getLog(SubmitDnetHadoopJobNode.class);
|
22
|
|
23
|
@Autowired
|
24
|
private DnetMessageManager dnetMessageManager;
|
25
|
|
26
|
private int currentValue = 0;
|
27
|
|
28
|
private int totalValue = 0;
|
29
|
|
30
|
private boolean accurate = false;
|
31
|
|
32
|
private String wfId;
|
33
|
|
34
|
@Override
|
35
|
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception {
|
36
|
this.wfId = token.getProcess().getEnv().getAttribute("system:processId");
|
37
|
super.prepareJob(job, token);
|
38
|
}
|
39
|
|
40
|
private void updateProgressProvider() {
|
41
|
final Message mess = dnetMessageManager.findMessage(wfId);
|
42
|
if (mess != null && mess.getBody() != null) {
|
43
|
if (mess.getBody().containsKey(Message.CURRENT_PARAM)) {
|
44
|
try {
|
45
|
setCurrentValue(Integer.parseInt(mess.getBody().get(Message.CURRENT_PARAM)));
|
46
|
} catch (final Throwable e) {
|
47
|
log.error("Error parsing value", e);
|
48
|
}
|
49
|
}
|
50
|
if (mess.getBody().containsKey(Message.TOTAL_PARAM)) {
|
51
|
try {
|
52
|
setTotalValue(Integer.parseInt(mess.getBody().get(Message.TOTAL_PARAM)));
|
53
|
setAccurate(true);
|
54
|
} catch (final Throwable e) {
|
55
|
log.error("Error parsing value", e);
|
56
|
}
|
57
|
}
|
58
|
}
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
protected BlackboardWorkflowJobListener generateBlackboardListener(final Engine engine, final NodeToken token) {
|
63
|
return new BlackboardWorkflowJobListener(engine, token) {
|
64
|
|
65
|
@Override
|
66
|
protected void onFailed(final BlackboardJob job) {
|
67
|
log.warn("Blackboard workflow node FAILED: " + job.getError());
|
68
|
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_HAS_FAILED, true);
|
69
|
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_ERROR, job.getError());
|
70
|
complete(job, "abort");
|
71
|
}
|
72
|
|
73
|
};
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public ProgressProvider getProgressProvider() {
|
78
|
return this;
|
79
|
}
|
80
|
|
81
|
public String getWfId() {
|
82
|
return wfId;
|
83
|
}
|
84
|
|
85
|
public void setWfId(final String wfId) {
|
86
|
this.wfId = wfId;
|
87
|
}
|
88
|
|
89
|
public boolean isAccurate() {
|
90
|
return accurate;
|
91
|
}
|
92
|
|
93
|
public void setAccurate(final boolean accurate) {
|
94
|
this.accurate = accurate;
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
public int getCurrentValue() {
|
99
|
updateProgressProvider();
|
100
|
return currentValue;
|
101
|
}
|
102
|
|
103
|
public void setCurrentValue(final int currentValue) {
|
104
|
this.currentValue = currentValue;
|
105
|
}
|
106
|
|
107
|
@Override
|
108
|
public int getTotalValue() {
|
109
|
return totalValue;
|
110
|
}
|
111
|
|
112
|
public void setTotalValue(final int totalValue) {
|
113
|
this.totalValue = totalValue;
|
114
|
}
|
115
|
|
116
|
@Override
|
117
|
public boolean isInaccurate() {
|
118
|
return !accurate;
|
119
|
}
|
120
|
|
121
|
}
|