Revision 55146
Added by Enrico Ottonello about 5 years ago
CreateMDStoreHadoopJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.hadoop; |
|
2 |
|
|
3 |
import java.net.URI; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
import org.apache.commons.logging.Log; |
|
8 |
import org.apache.commons.logging.LogFactory; |
|
9 |
import org.springframework.beans.factory.annotation.Required; |
|
10 |
import org.springframework.web.client.RestTemplate; |
|
11 |
import org.springframework.web.util.UriComponentsBuilder; |
|
12 |
|
|
13 |
import com.googlecode.sarasvati.Arc; |
|
14 |
import com.googlecode.sarasvati.NodeToken; |
|
15 |
|
|
16 |
import eu.dnetlib.data.mdstore.manager.common.model.MDStoreWithInfo; |
|
17 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
18 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
19 |
|
|
20 |
public class CreateMDStoreHadoopJobNode extends SimpleJobNode { |
|
21 |
|
|
22 |
private static final Log log = LogFactory.getLog(CreateMDStoreHadoopJobNode.class); |
|
23 |
|
|
24 |
/* Workflow params */ |
|
25 |
private String format; |
|
26 |
private String layout; |
|
27 |
private String interpretation; |
|
28 |
private String outputPrefix = "mdstore"; |
|
29 |
|
|
30 |
/* Spring managed params */ |
|
31 |
private String mdStoreManagerUrl; |
|
32 |
|
|
33 |
@Override |
|
34 |
protected String execute(final NodeToken token) throws Exception { |
|
35 |
final String url = getMdStoreManagerUrl() + "/mdstores/new/{format}/{layout}/{interpretation}"; |
|
36 |
|
|
37 |
final Map<String, Object> params = new HashMap<>(); |
|
38 |
params.put("format", getFormat()); |
|
39 |
params.put("layout", getLayout()); |
|
40 |
params.put("interpretation", getInterpretation()); |
|
41 |
|
|
42 |
final URI uri = UriComponentsBuilder.fromUriString(url) |
|
43 |
.queryParam("dsName", token.getEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_NAME)) |
|
44 |
.queryParam("dsId", token.getEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ID)) |
|
45 |
.queryParam("apiId", token.getEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE)) |
|
46 |
.buildAndExpand(params) |
|
47 |
.toUri(); |
|
48 |
|
|
49 |
final RestTemplate restTemplate = new RestTemplate(); |
|
50 |
final MDStoreWithInfo result = restTemplate.getForObject(uri, MDStoreWithInfo.class); |
|
51 |
|
|
52 |
log.info("mdstore created " + result.toString()); |
|
53 |
|
|
54 |
token.getEnv().setAttribute(getOutputPrefix() + "format", format); |
|
55 |
token.getEnv().setAttribute(getOutputPrefix() + "layout", layout); |
|
56 |
token.getEnv().setAttribute(getOutputPrefix() + "interpretation", interpretation); |
|
57 |
token.getEnv().setAttribute(getOutputPrefix() + "id", result.getId()); |
|
58 |
|
|
59 |
return Arc.DEFAULT_ARC; |
|
60 |
} |
|
61 |
|
|
62 |
public String getFormat() { |
|
63 |
return format; |
|
64 |
} |
|
65 |
|
|
66 |
public void setFormat(final String format) { |
|
67 |
this.format = format; |
|
68 |
} |
|
69 |
|
|
70 |
public String getLayout() { |
|
71 |
return layout; |
|
72 |
} |
|
73 |
|
|
74 |
public void setLayout(final String layout) { |
|
75 |
this.layout = layout; |
|
76 |
} |
|
77 |
|
|
78 |
public String getInterpretation() { |
|
79 |
return interpretation; |
|
80 |
} |
|
81 |
|
|
82 |
public void setInterpretation(final String interpretation) { |
|
83 |
this.interpretation = interpretation; |
|
84 |
} |
|
85 |
|
|
86 |
public String getOutputPrefix() { |
|
87 |
return outputPrefix; |
|
88 |
} |
|
89 |
|
|
90 |
public void setOutputPrefix(final String outputPrefix) { |
|
91 |
this.outputPrefix = outputPrefix; |
|
92 |
} |
|
93 |
|
|
94 |
public String getMdStoreManagerUrl() { |
|
95 |
return mdStoreManagerUrl; |
|
96 |
} |
|
97 |
|
|
98 |
@Required |
|
99 |
public void setMdStoreManagerUrl(final String mdStoreManagerUrl) { |
|
100 |
this.mdStoreManagerUrl = mdStoreManagerUrl; |
|
101 |
} |
|
102 |
|
|
103 |
} |
Also available in: Unified diff