1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.NoSuchElementException;
|
5
|
|
6
|
import javax.annotation.Resource;
|
7
|
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.apache.hadoop.conf.Configuration;
|
11
|
import org.springframework.beans.factory.annotation.Required;
|
12
|
|
13
|
import com.google.common.base.Joiner;
|
14
|
import com.google.common.base.Splitter;
|
15
|
import com.google.common.collect.Iterables;
|
16
|
import com.google.common.collect.Lists;
|
17
|
import com.googlecode.sarasvati.NodeToken;
|
18
|
|
19
|
import eu.dnetlib.data.hadoop.config.ClusterName;
|
20
|
import eu.dnetlib.data.hadoop.config.ConfigurationEnumerator;
|
21
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
22
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
23
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
24
|
import eu.dnetlib.msro.rmi.MSROException;
|
25
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
26
|
|
27
|
@Deprecated
|
28
|
public abstract class PrepareIISParams extends SimpleJobNode {
|
29
|
|
30
|
private static final Log log = LogFactory.getLog(PrepareIISParams.class);
|
31
|
|
32
|
@Resource
|
33
|
protected ConfigurationEnumerator configurationEnumerator;
|
34
|
|
35
|
@Resource
|
36
|
private UniqueServiceLocator serviceLocator;
|
37
|
|
38
|
private String clusterName;
|
39
|
|
40
|
private String clusterParam = "cluster";
|
41
|
|
42
|
private String zkQuorumParam = "export_action_hbase_remote_zookeeper_quorum";
|
43
|
|
44
|
private String zkPortParam = "export_action_hbase_remote_zookeeper_clientport";
|
45
|
|
46
|
private String oozieWfAppPath;
|
47
|
|
48
|
private String oozieWfAppPathParam = "oozie.wf.application.path";
|
49
|
|
50
|
private String xqueryMdStoreService;
|
51
|
|
52
|
private String mdStoreStoreLocationParam = "import_mdstore_service_location";
|
53
|
|
54
|
private String xqueryObjectStoreService;
|
55
|
|
56
|
private String objectStoreLocationParam = "import_content_object_store_location";
|
57
|
|
58
|
private String xqueryIsLookupService;
|
59
|
|
60
|
private String islookupLocationParam = "import_islookup_service_location";
|
61
|
|
62
|
private String importProjectConceptsContextIdParam = "import_project_concepts_context_id";
|
63
|
|
64
|
private String importProjectConceptsContextId;
|
65
|
|
66
|
private String xqueryDatasetStore;
|
67
|
|
68
|
private String mdStoreDatasetParam = "import_dataset_mdstore_ids_csv";
|
69
|
|
70
|
private String objectStoreBlacklistCSV = "";
|
71
|
|
72
|
protected void prepare(final NodeToken token) throws Exception {
|
73
|
|
74
|
token.getEnv().setAttribute(getClusterParam(), getClusterName());
|
75
|
|
76
|
// Assumes we only have one mdStore service instance
|
77
|
token.getEnv().setAttribute(getMdStoreStoreLocationParam(), getServiceEndpoint(getXqueryMdStoreService()));
|
78
|
// Assumes we only have one objectStore service instance
|
79
|
token.getEnv().setAttribute(getObjectStoreLocationParam(), getServiceEndpoint(getXqueryObjectStoreService()));
|
80
|
|
81
|
token.getEnv().setAttribute(getIslookupLocationParam(), getServiceEndpoint(getXqueryIsLookupService()));
|
82
|
|
83
|
token.getEnv().setAttribute(getImportProjectConceptsContextIdParam(), getImportProjectConceptsContextId());
|
84
|
|
85
|
Configuration conf = configurationEnumerator.get(ClusterName.valueOf(getClusterName()));
|
86
|
|
87
|
Configuration exportConf = configurationEnumerator.get(ClusterName.DM);
|
88
|
String zkPort = exportConf.get("hbase.zookeeper.property.clientPort");
|
89
|
String zkQuorum = getZkQuorumCSV(exportConf, zkPort);
|
90
|
|
91
|
token.getEnv().setAttribute(getZkQuorumParam(), zkQuorum);
|
92
|
token.getEnv().setAttribute(getZkPortParam(), zkPort);
|
93
|
|
94
|
String nameNode = conf.get("fs.defaultFS");
|
95
|
|
96
|
token.getEnv().setAttribute("nameNode", nameNode);
|
97
|
token.getEnv().setAttribute("jobTracker", conf.get("mapred.job.tracker"));
|
98
|
token.getEnv().setAttribute(getOozieWfAppPathParam(), getURI(nameNode, getOozieWfAppPath()));
|
99
|
token.getEnv().setAttribute(getMdStoreDatasetParam(), asCSV(getProfileIds(getXqueryDatasetStore())));
|
100
|
}
|
101
|
|
102
|
protected String getServiceEndpoint(final String xquery) throws MSROException {
|
103
|
try {
|
104
|
return Iterables.getOnlyElement(serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery));
|
105
|
} catch (ISLookUpException e) {
|
106
|
throw new MSROException("unable to fetch service endpoint", e);
|
107
|
} catch (NoSuchElementException e) {
|
108
|
throw new MSROException("unable to find service endpoint, xquery: " + getXqueryMdStoreService(), e);
|
109
|
} catch (IllegalArgumentException e) {
|
110
|
throw new MSROException("more than one services found, we assume to have only one available", e);
|
111
|
}
|
112
|
}
|
113
|
|
114
|
protected String getProfileId(final String xquery) throws MSROException {
|
115
|
try {
|
116
|
return Iterables.getOnlyElement(serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery));
|
117
|
} catch (ISLookUpException e) {
|
118
|
throw new MSROException("unable to fetch profile id", e);
|
119
|
} catch (NoSuchElementException e) {
|
120
|
throw new MSROException("unable to find profile profile, xquery: " + xquery, e);
|
121
|
} catch (IllegalArgumentException e) {
|
122
|
throw new MSROException("more than one profile profiles was found, we assume to have only one available, xquery: " + xquery, e);
|
123
|
}
|
124
|
}
|
125
|
|
126
|
protected List<String> getProfileIds(final String xquery) throws MSROException {
|
127
|
try {
|
128
|
List<String> ids = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery);
|
129
|
|
130
|
if (ids.isEmpty()) {
|
131
|
log.warn("couldn't find any profile, xquery: " + xquery);
|
132
|
}
|
133
|
|
134
|
return ids;
|
135
|
} catch (ISLookUpException e) {
|
136
|
throw new MSROException("unable to fetch profile ids, x query: " + xquery, e);
|
137
|
}
|
138
|
}
|
139
|
|
140
|
protected String getFilteredObjectStoreCSV(final String xquery) throws MSROException {
|
141
|
return asCSV(filter(getProfileIds(xquery), asList(getObjectStoreBlacklistCSV())));
|
142
|
}
|
143
|
|
144
|
protected List<String> filter(final List<String> list, final List<String> filter) {
|
145
|
if (filter == null || filter.isEmpty()) { return list; }
|
146
|
list.removeAll(filter);
|
147
|
return list;
|
148
|
}
|
149
|
|
150
|
protected String asCSV(final List<String> list) {
|
151
|
return Joiner.on(",").skipNulls().join(list);
|
152
|
}
|
153
|
|
154
|
protected List<String> asList(final String csv) {
|
155
|
return Lists.newArrayList(Splitter.on(",").trimResults().omitEmptyStrings().split(csv));
|
156
|
}
|
157
|
|
158
|
private String getURI(final String nameNode, final String relative) {
|
159
|
// TODO ensure to return a valid URI
|
160
|
return nameNode + relative;
|
161
|
}
|
162
|
|
163
|
private String getZkQuorumCSV(final Configuration conf, final String zkPort) {
|
164
|
return Joiner.on(":" + zkPort + ",").join(Splitter.on(",").omitEmptyStrings().split(conf.get("hbase.zookeeper.quorum")));
|
165
|
}
|
166
|
|
167
|
@Required
|
168
|
public void setXqueryMdStoreService(final String xqueryMdStoreService) {
|
169
|
this.xqueryMdStoreService = xqueryMdStoreService;
|
170
|
}
|
171
|
|
172
|
public String getXqueryMdStoreService() {
|
173
|
return xqueryMdStoreService;
|
174
|
}
|
175
|
|
176
|
public String getMdStoreStoreLocationParam() {
|
177
|
return mdStoreStoreLocationParam;
|
178
|
}
|
179
|
|
180
|
public void setMdStoreStoreLocationParam(final String mdStoreStoreLocationParam) {
|
181
|
this.mdStoreStoreLocationParam = mdStoreStoreLocationParam;
|
182
|
}
|
183
|
|
184
|
public String getClusterName() {
|
185
|
return clusterName;
|
186
|
}
|
187
|
|
188
|
public void setClusterName(final String clusterName) {
|
189
|
this.clusterName = clusterName;
|
190
|
}
|
191
|
|
192
|
public String getZkQuorumParam() {
|
193
|
return zkQuorumParam;
|
194
|
}
|
195
|
|
196
|
public void setZkQuorumParam(final String zkQuorumParam) {
|
197
|
this.zkQuorumParam = zkQuorumParam;
|
198
|
}
|
199
|
|
200
|
public String getZkPortParam() {
|
201
|
return zkPortParam;
|
202
|
}
|
203
|
|
204
|
public void setZkPortParam(final String zkPortParam) {
|
205
|
this.zkPortParam = zkPortParam;
|
206
|
}
|
207
|
|
208
|
public String getClusterParam() {
|
209
|
return clusterParam;
|
210
|
}
|
211
|
|
212
|
public void setClusterParam(final String clusterParam) {
|
213
|
this.clusterParam = clusterParam;
|
214
|
}
|
215
|
|
216
|
public String getOozieWfAppPathParam() {
|
217
|
return oozieWfAppPathParam;
|
218
|
}
|
219
|
|
220
|
public void setOozieWfAppPathParam(final String oozieWfAppPathParam) {
|
221
|
this.oozieWfAppPathParam = oozieWfAppPathParam;
|
222
|
}
|
223
|
|
224
|
public String getOozieWfAppPath() {
|
225
|
return oozieWfAppPath;
|
226
|
}
|
227
|
|
228
|
public void setOozieWfAppPath(final String oozieWfAppPath) {
|
229
|
this.oozieWfAppPath = oozieWfAppPath;
|
230
|
}
|
231
|
|
232
|
@Required
|
233
|
public String getXqueryDatasetStore() {
|
234
|
return xqueryDatasetStore;
|
235
|
}
|
236
|
|
237
|
public void setXqueryDatasetStore(final String xqueryDatasetStore) {
|
238
|
this.xqueryDatasetStore = xqueryDatasetStore;
|
239
|
}
|
240
|
|
241
|
public String getMdStoreDatasetParam() {
|
242
|
return mdStoreDatasetParam;
|
243
|
}
|
244
|
|
245
|
public void setMdStoreDatasetParam(final String mdStoreDatasetParam) {
|
246
|
this.mdStoreDatasetParam = mdStoreDatasetParam;
|
247
|
}
|
248
|
|
249
|
public String getXqueryObjectStoreService() {
|
250
|
return xqueryObjectStoreService;
|
251
|
}
|
252
|
|
253
|
@Required
|
254
|
public void setXqueryObjectStoreService(final String xqueryObjectStoreService) {
|
255
|
this.xqueryObjectStoreService = xqueryObjectStoreService;
|
256
|
}
|
257
|
|
258
|
public String getObjectStoreLocationParam() {
|
259
|
return objectStoreLocationParam;
|
260
|
}
|
261
|
|
262
|
public void setObjectStoreLocationParam(final String objectStoreLocationParam) {
|
263
|
this.objectStoreLocationParam = objectStoreLocationParam;
|
264
|
}
|
265
|
|
266
|
public String getObjectStoreBlacklistCSV() {
|
267
|
return objectStoreBlacklistCSV;
|
268
|
}
|
269
|
|
270
|
public void setObjectStoreBlacklistCSV(final String objectStoreBlacklistCSV) {
|
271
|
this.objectStoreBlacklistCSV = objectStoreBlacklistCSV;
|
272
|
}
|
273
|
|
274
|
public String getXqueryIsLookupService() {
|
275
|
return xqueryIsLookupService;
|
276
|
}
|
277
|
|
278
|
@Required
|
279
|
public void setXqueryIsLookupService(final String xqueryIsLookupService) {
|
280
|
this.xqueryIsLookupService = xqueryIsLookupService;
|
281
|
}
|
282
|
|
283
|
public String getIslookupLocationParam() {
|
284
|
return islookupLocationParam;
|
285
|
}
|
286
|
|
287
|
public void setIslookupLocationParam(final String islookupLocationParam) {
|
288
|
this.islookupLocationParam = islookupLocationParam;
|
289
|
}
|
290
|
|
291
|
public String getImportProjectConceptsContextIdParam() {
|
292
|
return importProjectConceptsContextIdParam;
|
293
|
}
|
294
|
|
295
|
public void setImportProjectConceptsContextIdParam(final String importProjectConceptsContextIdParam) {
|
296
|
this.importProjectConceptsContextIdParam = importProjectConceptsContextIdParam;
|
297
|
}
|
298
|
|
299
|
public String getImportProjectConceptsContextId() {
|
300
|
return importProjectConceptsContextId;
|
301
|
}
|
302
|
|
303
|
public void setImportProjectConceptsContextId(final String importProjectConceptsContextId) {
|
304
|
this.importProjectConceptsContextId = importProjectConceptsContextId;
|
305
|
}
|
306
|
|
307
|
}
|