1
|
package eu.dnetlib.msro.workflows.nodes.actionmanager;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import com.google.common.base.Predicate;
|
7
|
import com.google.common.collect.Maps;
|
8
|
import com.google.gson.Gson;
|
9
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
10
|
import eu.dnetlib.miscutils.datetime.DateUtils;
|
11
|
import eu.dnetlib.msro.workflows.graph.Arc;
|
12
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
13
|
import eu.dnetlib.msro.workflows.procs.Env;
|
14
|
import eu.dnetlib.rmi.data.hadoop.actionmanager.RawSet;
|
15
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
16
|
import org.apache.commons.logging.Log;
|
17
|
import org.apache.commons.logging.LogFactory;
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
19
|
|
20
|
public class PrepareActionSetsJobNode extends SimpleJobNode {
|
21
|
|
22
|
/**
|
23
|
* logger.
|
24
|
*/
|
25
|
private static final Log log = LogFactory.getLog(PrepareActionSetsJobNode.class);
|
26
|
|
27
|
@Autowired
|
28
|
private UniqueServiceLocator serviceLocator;
|
29
|
|
30
|
private String sets;
|
31
|
|
32
|
@Override
|
33
|
protected String execute(final Env env) throws Exception {
|
34
|
|
35
|
final List<Map<String, String>> setList = getSetList();
|
36
|
final String now = DateUtils.now_ISO8601();
|
37
|
|
38
|
final String basePath = this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(
|
39
|
"/RESOURCE_PROFILE[./HEADER/RESOURCE_TYPE/@value='ActionManagerServiceResourceType']//SERVICE_PROPERTIES/PROPERTY[@key='basePath']/@value/string()");
|
40
|
|
41
|
for (final Map<String, String> set : setList) {
|
42
|
|
43
|
set.put("rawset", RawSet.newInstance().getId());
|
44
|
set.put("creationDate", now);
|
45
|
set.put("path", getPath(basePath, set));
|
46
|
|
47
|
if (set.get("enabled").equals("true")) {
|
48
|
log.info("preparing set: " + simplifySetInfo(set));
|
49
|
}
|
50
|
// setting the job properties needed to name the rawsets
|
51
|
env.setAttribute(set.get("jobProperty"), set.get("rawset"));
|
52
|
}
|
53
|
|
54
|
env.setAttribute("sets", new Gson().toJson(setList));
|
55
|
env.setAttribute("actionManagerBasePath", basePath);
|
56
|
|
57
|
return Arc.DEFAULT_ARC;
|
58
|
}
|
59
|
|
60
|
private String getPath(final String basePath, final Map<String, String> set) {
|
61
|
final StringBuilder sb = new StringBuilder();
|
62
|
sb.append(basePath).append("/").append(set.get("set")).append("/").append(set.get("rawset"));
|
63
|
final String path = sb.toString();
|
64
|
log.debug("path: " + path);
|
65
|
return path;
|
66
|
}
|
67
|
|
68
|
private Map<String, String> simplifySetInfo(final Map<String, String> set) {
|
69
|
return Maps.filterKeys(set, new Predicate<String>() {
|
70
|
|
71
|
@Override
|
72
|
public boolean apply(final String k) {
|
73
|
|
74
|
return k.equals("set") || k.equals("rawset");
|
75
|
}
|
76
|
});
|
77
|
}
|
78
|
|
79
|
@SuppressWarnings("unchecked")
|
80
|
protected List<Map<String, String>> getSetList() {
|
81
|
return new Gson().fromJson(getSets(), List.class);
|
82
|
}
|
83
|
|
84
|
public String getSets() {
|
85
|
return this.sets;
|
86
|
}
|
87
|
|
88
|
public void setSets(final String sets) {
|
89
|
this.sets = sets;
|
90
|
}
|
91
|
|
92
|
}
|