1 |
26600
|
sandro.lab
|
package eu.dnetlib.data.hadoop.action;
|
2 |
|
|
|
3 |
|
|
import java.util.Map;
|
4 |
|
|
import java.util.Map.Entry;
|
5 |
|
|
import java.util.Properties;
|
6 |
47222
|
claudio.at
|
import java.util.Set;
|
7 |
26600
|
sandro.lab
|
|
8 |
47222
|
claudio.at
|
import com.google.common.base.Splitter;
|
9 |
|
|
import com.google.common.collect.Sets;
|
10 |
|
|
import org.apache.commons.lang.StringUtils;
|
11 |
26600
|
sandro.lab
|
import org.apache.commons.logging.Log;
|
12 |
|
|
import org.apache.commons.logging.LogFactory;
|
13 |
|
|
import org.apache.hadoop.conf.Configuration;
|
14 |
|
|
import org.apache.oozie.client.OozieClient;
|
15 |
34703
|
claudio.at
|
import org.apache.oozie.client.OozieClientException;
|
16 |
26600
|
sandro.lab
|
|
17 |
|
|
import eu.dnetlib.data.hadoop.HadoopJob;
|
18 |
|
|
import eu.dnetlib.data.hadoop.config.ClusterName;
|
19 |
|
|
import eu.dnetlib.data.hadoop.oozie.OozieJobMonitor;
|
20 |
|
|
import eu.dnetlib.data.hadoop.rmi.HadoopServiceException;
|
21 |
|
|
import eu.dnetlib.data.hadoop.utils.JobProfile;
|
22 |
|
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
23 |
|
|
|
24 |
|
|
public class SubmitOozieJobAction extends AbstractSubmitAction {
|
25 |
|
|
|
26 |
|
|
private static final Log log = LogFactory.getLog(SubmitOozieJobAction.class); // NOPMD by marko on 11/24/08 5:02 PM
|
27 |
|
|
|
28 |
47222
|
claudio.at
|
public static final String OOZIE_REPORT_ACTIONS = "oozie.report.actions.csv";
|
29 |
|
|
|
30 |
26600
|
sandro.lab
|
@Override
|
31 |
34703
|
claudio.at
|
public void submit(final JobCompletion callback, final BlackboardJob bbJob, final String jobName, final JobProfile jobProfile)
|
32 |
|
|
throws HadoopServiceException {
|
33 |
26600
|
sandro.lab
|
|
34 |
|
|
final ClusterName clusterName = ClusterName.valueOf(bbJob.getParameters().get("cluster"));
|
35 |
|
|
|
36 |
|
|
try {
|
37 |
34703
|
claudio.at
|
final Properties jobConf = prepareJob(getConf(clusterName), jobName, jobProfile, bbJob.getParameters());
|
38 |
26983
|
claudio.at
|
log.debug("oozie job configuration:\n" + jobConf);
|
39 |
26600
|
sandro.lab
|
|
40 |
32295
|
claudio.at
|
if (!hadoopClientMap.isOozieAvailable(clusterName)) throw new HadoopServiceException("oozie not available for cluster: " + clusterName.toString());
|
41 |
26600
|
sandro.lab
|
|
42 |
31337
|
claudio.at
|
logJobDetails(jobConf);
|
43 |
|
|
|
44 |
32295
|
claudio.at
|
final OozieClient oozieClient = hadoopClientMap.getOozieClient(clusterName);
|
45 |
26600
|
sandro.lab
|
final String internalId = oozieClient.run(jobConf);
|
46 |
31337
|
claudio.at
|
final String jobId = newJobId(clusterName, internalId);
|
47 |
26600
|
sandro.lab
|
|
48 |
31337
|
claudio.at
|
jobRegistry.registerJob(HadoopJob.newInstance(jobId, clusterName, jobProfile,
|
49 |
47222
|
claudio.at
|
new OozieJobMonitor(oozieClient, internalId, callback, getWorkflowActions(bbJob))));
|
50 |
26600
|
sandro.lab
|
|
51 |
34703
|
claudio.at
|
} catch (final OozieClientException e) {
|
52 |
32818
|
claudio.at
|
throw new HadoopServiceException("error executing hadoop job: " + jobName, e);
|
53 |
26600
|
sandro.lab
|
}
|
54 |
|
|
}
|
55 |
|
|
|
56 |
47222
|
claudio.at
|
/**
|
57 |
|
|
* Extracts from the blackboard job params the oozie action names as csv and returns them as a set.
|
58 |
|
|
* @param bbJob
|
59 |
|
|
* @return
|
60 |
|
|
*/
|
61 |
|
|
private Set<String> getWorkflowActions(final BlackboardJob bbJob) {
|
62 |
|
|
final String actions = bbJob.getParameters().get(OOZIE_REPORT_ACTIONS);
|
63 |
|
|
if (StringUtils.isNotBlank(actions)) {
|
64 |
|
|
return Sets.newHashSet(Splitter.on(",").split(actions));
|
65 |
|
|
}
|
66 |
|
|
return Sets.newHashSet();
|
67 |
|
|
}
|
68 |
|
|
|
69 |
32295
|
claudio.at
|
private Properties prepareJob(final Configuration configuration, final String jobName, final JobProfile jobProfile, final Map<String, String> parameters) {
|
70 |
26600
|
sandro.lab
|
|
71 |
|
|
log.info("creating job: " + jobName);
|
72 |
|
|
|
73 |
34703
|
claudio.at
|
final Properties p = new Properties();
|
74 |
26600
|
sandro.lab
|
|
75 |
26983
|
claudio.at
|
merge(p, configuration);
|
76 |
26600
|
sandro.lab
|
merge(p, jobProfile.getJobDefinition().entrySet());
|
77 |
|
|
merge(p, parameters.entrySet());
|
78 |
|
|
|
79 |
|
|
return p;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
31337
|
claudio.at
|
private void merge(final Properties p, final Iterable<Entry<String, String>> entrySet) {
|
83 |
34703
|
claudio.at
|
for (final Entry<String, String> e : entrySet) {
|
84 |
26600
|
sandro.lab
|
p.setProperty(e.getKey(), e.getValue());
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
|
88 |
31337
|
claudio.at
|
protected void logJobDetails(final Properties jobConf) {
|
89 |
34703
|
claudio.at
|
for (final Entry<?, ?> e : jobConf.entrySet()) {
|
90 |
31337
|
claudio.at
|
if (log.isDebugEnabled()) {
|
91 |
|
|
log.debug("\n" + e.getKey().toString() + " : " + e.getValue().toString());
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
}
|
95 |
|
|
|
96 |
26600
|
sandro.lab
|
}
|