1
|
package eu.dnetlib.msro.workflows.hadoop;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import javax.annotation.Resource;
|
6
|
|
7
|
import org.apache.commons.lang.StringUtils;
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
|
11
|
import com.google.common.collect.Iterables;
|
12
|
import com.googlecode.sarasvati.NodeToken;
|
13
|
|
14
|
import eu.dnetlib.data.hadoop.rmi.HadoopBlackboardActions;
|
15
|
import eu.dnetlib.data.hadoop.rmi.HadoopJobType;
|
16
|
import eu.dnetlib.data.hadoop.rmi.HadoopService;
|
17
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
18
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
19
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
20
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
21
|
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
|
22
|
|
23
|
public class SubmitHadoopJobNode extends BlackboardJobNode {
|
24
|
|
25
|
/**
|
26
|
* logger.
|
27
|
*/
|
28
|
private static final Log log = LogFactory.getLog(SubmitHadoopJobNode.class);
|
29
|
|
30
|
public static final String OOZIE_REPORT_ACTIONS = "oozie.report.actions.csv";
|
31
|
|
32
|
@Resource
|
33
|
private UniqueServiceLocator serviceLocator;
|
34
|
|
35
|
private String hadoopJob;
|
36
|
|
37
|
private String cluster;
|
38
|
|
39
|
private boolean simulation = false;
|
40
|
|
41
|
private String oozieReportActionsCsv;
|
42
|
|
43
|
@Override
|
44
|
protected String obtainServiceId(final NodeToken token) {
|
45
|
return getServiceLocator().getServiceId(HadoopService.class);
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception {
|
50
|
String type = getJobType(getHadoopJob());
|
51
|
|
52
|
log.info("submitting job " + getHadoopJob() + " type: " + type);
|
53
|
|
54
|
job.setAction(type);
|
55
|
job.getParameters().put("job.name", getHadoopJob());
|
56
|
job.getParameters().put("cluster", cluster(token));
|
57
|
job.getParameters().put("simulation", String.valueOf(isSimulation()));
|
58
|
|
59
|
if (StringUtils.isNotBlank(getOozieReportActionsCsv())) {
|
60
|
job.getParameters().put(OOZIE_REPORT_ACTIONS, getOozieReportActionsCsv());
|
61
|
}
|
62
|
|
63
|
job.getParameters().putAll(parseJsonParameters(token));
|
64
|
}
|
65
|
|
66
|
private String cluster(final NodeToken token) {
|
67
|
if (token.getEnv().hasAttribute("cluster")) {
|
68
|
String cluster = token.getEnv().getAttribute("cluster");
|
69
|
log.info("found override value in wfEnv for 'cluster' param: " + cluster);
|
70
|
return cluster;
|
71
|
}
|
72
|
return getCluster();
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* reads the job type for the given job name
|
77
|
*
|
78
|
* @param jobName
|
79
|
* @return
|
80
|
* @throws ISLookUpException
|
81
|
*/
|
82
|
private String getJobType(final String jobName) throws ISLookUpException {
|
83
|
List<String> res =
|
84
|
serviceLocator.getService(ISLookUpService.class).quickSearchProfile(
|
85
|
"/RESOURCE_PROFILE[.//RESOURCE_TYPE/@value = 'HadoopJobConfigurationDSResourceType']//HADOOP_JOB[./@name='" + jobName
|
86
|
+ "']/@type/string()");
|
87
|
if (res.isEmpty()) { throw new IllegalStateException("unable to find job type for job: " + jobName); }
|
88
|
|
89
|
final HadoopJobType type = HadoopJobType.valueOf(Iterables.getOnlyElement(res));
|
90
|
|
91
|
switch (type) {
|
92
|
case mapreduce:
|
93
|
return HadoopBlackboardActions.SUBMIT_MAPREDUCE_JOB.toString();
|
94
|
case admin:
|
95
|
return HadoopBlackboardActions.SUBMIT_ADMIN_JOB.toString();
|
96
|
case oozie:
|
97
|
return HadoopBlackboardActions.SUBMIT_OOZIE_JOB.toString();
|
98
|
default:
|
99
|
throw new IllegalStateException("undefined job type: " + type.toString());
|
100
|
}
|
101
|
}
|
102
|
|
103
|
public String getHadoopJob() {
|
104
|
return hadoopJob;
|
105
|
}
|
106
|
|
107
|
public void setHadoopJob(final String hadoopJob) {
|
108
|
this.hadoopJob = hadoopJob;
|
109
|
}
|
110
|
|
111
|
public String getCluster() {
|
112
|
return cluster;
|
113
|
}
|
114
|
|
115
|
public void setCluster(final String cluster) {
|
116
|
this.cluster = cluster;
|
117
|
}
|
118
|
|
119
|
public boolean isSimulation() {
|
120
|
return simulation;
|
121
|
}
|
122
|
|
123
|
public void setSimulation(final boolean simulation) {
|
124
|
this.simulation = simulation;
|
125
|
}
|
126
|
|
127
|
public String getOozieReportActionsCsv() {
|
128
|
return oozieReportActionsCsv;
|
129
|
}
|
130
|
|
131
|
public void setOozieReportActionsCsv(final String oozieReportActionsCsv) {
|
132
|
this.oozieReportActionsCsv = oozieReportActionsCsv;
|
133
|
}
|
134
|
}
|