1 |
26600
|
sandro.lab
|
package eu.dnetlib.data.hadoop;
|
2 |
|
|
|
3 |
49795
|
claudio.at
|
import java.io.IOException;
|
4 |
34224
|
claudio.at
|
import java.util.Map;
|
5 |
|
|
|
6 |
49795
|
claudio.at
|
import eu.dnetlib.data.hadoop.mapred.JobClientFactory;
|
7 |
|
|
import eu.dnetlib.data.hadoop.rmi.HadoopServiceException;
|
8 |
26600
|
sandro.lab
|
import org.apache.commons.logging.Log;
|
9 |
|
|
import org.apache.commons.logging.LogFactory;
|
10 |
|
|
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
11 |
|
|
import org.apache.hadoop.mapred.JobClient;
|
12 |
|
|
import org.apache.oozie.client.OozieClient;
|
13 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
14 |
26980
|
claudio.at
|
import org.springframework.beans.factory.annotation.Required;
|
15 |
31644
|
claudio.at
|
import org.springframework.context.annotation.Lazy;
|
16 |
26600
|
sandro.lab
|
|
17 |
34224
|
claudio.at
|
import com.google.common.collect.Maps;
|
18 |
|
|
import com.google.gson.Gson;
|
19 |
26600
|
sandro.lab
|
|
20 |
34224
|
claudio.at
|
import eu.dnetlib.data.hadoop.config.ClusterName;
|
21 |
|
|
import eu.dnetlib.data.hadoop.hbase.HBaseAdminFactory;
|
22 |
|
|
import eu.dnetlib.data.hadoop.oozie.OozieClientFactory;
|
23 |
|
|
|
24 |
49795
|
claudio.at
|
|
25 |
26600
|
sandro.lab
|
public class HadoopClientMap {
|
26 |
|
|
|
27 |
|
|
private static final Log log = LogFactory.getLog(HadoopClientMap.class); // NOPMD by marko on 11/24/08 5:02 PM
|
28 |
|
|
|
29 |
31644
|
claudio.at
|
@Lazy
|
30 |
26600
|
sandro.lab
|
@Autowired
|
31 |
|
|
private JobClientFactory jobClientFactory;
|
32 |
|
|
|
33 |
31644
|
claudio.at
|
@Lazy
|
34 |
26600
|
sandro.lab
|
@Autowired
|
35 |
|
|
private OozieClientFactory oozieClientFactory;
|
36 |
|
|
|
37 |
31644
|
claudio.at
|
@Lazy
|
38 |
26600
|
sandro.lab
|
@Autowired
|
39 |
|
|
private HBaseAdminFactory hbaseAdminFactory;
|
40 |
|
|
|
41 |
26980
|
claudio.at
|
private Map<String, Map<String, String>> enabledClients = Maps.newHashMap();
|
42 |
26600
|
sandro.lab
|
|
43 |
49795
|
claudio.at
|
public boolean isMapreduceAvailable(final ClusterName name) {
|
44 |
|
|
return isClientAvailable(name, "mapred");
|
45 |
34224
|
claudio.at
|
}
|
46 |
26600
|
sandro.lab
|
|
47 |
49795
|
claudio.at
|
public boolean isOozieAvailable(final ClusterName name) {
|
48 |
|
|
return isClientAvailable(name, "oozie");
|
49 |
26600
|
sandro.lab
|
}
|
50 |
|
|
|
51 |
49795
|
claudio.at
|
public boolean isHbaseAvailable(final ClusterName name) {
|
52 |
|
|
return isClientAvailable(name, "hbase");
|
53 |
34224
|
claudio.at
|
}
|
54 |
|
|
|
55 |
49795
|
claudio.at
|
private boolean isClientAvailable(final ClusterName name, final String clientName) {
|
56 |
|
|
final String clusterName = name.toString();
|
57 |
|
|
return enabledClients.containsKey(clusterName) && "true".equals(enabledClients.get(clusterName).get(clientName));
|
58 |
26600
|
sandro.lab
|
}
|
59 |
|
|
|
60 |
49795
|
claudio.at
|
public JobClient getJtClient(final ClusterName clusterName, final String username) throws HadoopServiceException, IOException {
|
61 |
|
|
if (!isMapreduceAvailable(clusterName)) {
|
62 |
|
|
throw new HadoopServiceException("jobtracker is not available for cluster " + clusterName.toString());
|
63 |
|
|
}
|
64 |
|
|
return getJobClientFactory().newInstance(clusterName, username);
|
65 |
29516
|
claudio.at
|
}
|
66 |
|
|
|
67 |
49795
|
claudio.at
|
public JobClient getJtClient(final ClusterName clusterName) throws HadoopServiceException, IOException {
|
68 |
|
|
if (!isMapreduceAvailable(clusterName)) {
|
69 |
|
|
throw new HadoopServiceException("jobtracker is not available for cluster " + clusterName.toString());
|
70 |
|
|
}
|
71 |
|
|
return getJobClientFactory().newInstance(clusterName);
|
72 |
26600
|
sandro.lab
|
}
|
73 |
|
|
|
74 |
49795
|
claudio.at
|
public OozieClient getOozieClient(final ClusterName name) throws HadoopServiceException {
|
75 |
|
|
if (!isOozieAvailable(name)) {
|
76 |
|
|
throw new HadoopServiceException("oozie is not available for cluster " + name.toString());
|
77 |
|
|
}
|
78 |
|
|
return getOozieClientFactory().newInstance(name);
|
79 |
26600
|
sandro.lab
|
}
|
80 |
|
|
|
81 |
49795
|
claudio.at
|
public HBaseAdmin getHbaseAdmin(final ClusterName name) throws HadoopServiceException {
|
82 |
|
|
if (!isHbaseAvailable(name)) {
|
83 |
|
|
throw new HadoopServiceException("hbase is not available for cluster " + name.toString());
|
84 |
|
|
}
|
85 |
|
|
return getHbaseAdminFactory().newInstance(name);
|
86 |
26600
|
sandro.lab
|
}
|
87 |
|
|
|
88 |
|
|
// //////////
|
89 |
|
|
|
90 |
26980
|
claudio.at
|
public String getEnabledClients() {
|
91 |
|
|
return new Gson().toJson(enabledClients);
|
92 |
26600
|
sandro.lab
|
}
|
93 |
|
|
|
94 |
26980
|
claudio.at
|
@Required
|
95 |
|
|
@SuppressWarnings("unchecked")
|
96 |
29516
|
claudio.at
|
public void setEnabledClients(final String enabledClients) {
|
97 |
26980
|
claudio.at
|
this.enabledClients = new Gson().fromJson(enabledClients, Map.class);
|
98 |
26600
|
sandro.lab
|
}
|
99 |
|
|
|
100 |
34224
|
claudio.at
|
public JobClientFactory getJobClientFactory() {
|
101 |
|
|
return jobClientFactory;
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
public void setJobClientFactory(JobClientFactory jobClientFactory) {
|
105 |
|
|
this.jobClientFactory = jobClientFactory;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
public OozieClientFactory getOozieClientFactory() {
|
109 |
|
|
return oozieClientFactory;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
public void setOozieClientFactory(OozieClientFactory oozieClientFactory) {
|
113 |
|
|
this.oozieClientFactory = oozieClientFactory;
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
public HBaseAdminFactory getHbaseAdminFactory() {
|
117 |
|
|
return hbaseAdminFactory;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
public void setHbaseAdminFactory(HBaseAdminFactory hbaseAdminFactory) {
|
121 |
|
|
this.hbaseAdminFactory = hbaseAdminFactory;
|
122 |
|
|
}
|
123 |
|
|
|
124 |
26600
|
sandro.lab
|
}
|