Revision 49341
Added by Alessia Bardi over 6 years ago
modules/dnet-parthenos/trunk/src/main/java/eu/dnetlib/parthenos/workflows/nodes/PublishVirtuosoJobNode.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.parthenos.workflows.nodes; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 |
import java.util.Map; |
|
3 |
public class PublishVirtuosoJobNode extends PublishAbstractJobNode { |
|
5 | 4 |
|
6 |
import com.google.common.collect.Lists; |
|
7 |
import com.google.common.collect.Maps; |
|
8 |
import com.google.gson.Gson; |
|
9 |
import eu.dnetlib.enabling.resultset.client.ResultSetClient; |
|
10 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
11 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
12 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
13 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
14 |
import eu.dnetlib.rmi.common.ResultSet; |
|
15 |
import eu.dnetlib.rmi.manager.MSROException; |
|
16 |
import org.apache.commons.logging.Log; |
|
17 |
import org.apache.commons.logging.LogFactory; |
|
18 |
import org.apache.http.HttpResponse; |
|
19 |
import org.apache.http.NameValuePair; |
|
20 |
import org.apache.http.client.HttpClient; |
|
21 |
import org.apache.http.client.entity.UrlEncodedFormEntity; |
|
22 |
import org.apache.http.client.methods.HttpPost; |
|
23 |
import org.apache.http.impl.client.HttpClients; |
|
24 |
import org.apache.http.message.BasicNameValuePair; |
|
25 |
import org.springframework.beans.factory.annotation.Autowired; |
|
26 |
|
|
27 |
public class PublishVirtuosoJobNode extends SimpleJobNode { |
|
28 |
|
|
29 |
private static final Log log = LogFactory.getLog(PublishVirtuosoJobNode.class); |
|
30 |
|
|
31 |
private String inputEprParam; |
|
32 |
|
|
33 |
@Autowired |
|
34 |
private ResultSetClient resultSetClient; |
|
35 |
|
|
36 |
private String publisherEndpoint; |
|
37 |
|
|
38 | 5 |
@Override |
39 |
protected String execute(final Env env) throws Exception { |
|
40 |
|
|
41 |
final ResultSet<?> rsIn = env.getAttribute(getInputEprParam(), ResultSet.class); |
|
42 |
if ((rsIn == null)) { throw new MSROException("InputEprParam (" + getInputEprParam() + ") not found in ENV"); } |
|
43 |
|
|
44 |
int countAll = 0; |
|
45 |
int countOk = 0; |
|
46 |
Map<Integer, Integer> errors = Maps.newHashMap(); |
|
47 |
log.info("Publisher endpoint: " + getPublisherEndpoint()); |
|
48 |
|
|
49 |
//let's start sequentially |
|
50 |
for (String record : getResultSetClient().iter(rsIn, String.class)) { |
|
51 |
|
|
52 |
HttpPost post = new HttpPost(getPublisherEndpoint()); |
|
53 |
List<NameValuePair> params = Lists.newArrayList(); |
|
54 |
params.add(new BasicNameValuePair("record", record)); |
|
55 |
params.add(new BasicNameValuePair("parthenosTarget", "VIRTUOSO")); |
|
56 |
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params, "UTF-8"); |
|
57 |
post.setEntity(ent); |
|
58 |
HttpClient client = HttpClients.createDefault(); |
|
59 |
HttpResponse responsePOST = client.execute(post); |
|
60 |
countAll++; |
|
61 |
int statusCode = responsePOST.getStatusLine().getStatusCode(); |
|
62 |
switch (statusCode) { |
|
63 |
case 200: |
|
64 |
countOk++; |
|
65 |
break; |
|
66 |
default: |
|
67 |
log.error(responsePOST.getStatusLine().getStatusCode() + ": " + responsePOST.getStatusLine().getReasonPhrase()); |
|
68 |
errors.merge(statusCode, 1, Integer::sum); |
|
69 |
} |
|
70 |
|
|
71 |
} |
|
72 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "countOk", countOk); |
|
73 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "countAll", countAll); |
|
74 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "errorsMap", new Gson().toJson(errors)); |
|
75 |
|
|
76 |
if (!errors.isEmpty()) { |
|
77 |
throw new MSROException("Problems in publishing"); |
|
78 |
} else return Arc.DEFAULT_ARC; |
|
79 |
|
|
6 |
public String getTarget() { |
|
7 |
return "VIRTUOSO"; |
|
80 | 8 |
} |
81 | 9 |
|
82 |
public String getInputEprParam() { |
|
83 |
return this.inputEprParam; |
|
84 |
} |
|
85 |
|
|
86 |
public void setInputEprParam(final String inputEprParam) { |
|
87 |
this.inputEprParam = inputEprParam; |
|
88 |
} |
|
89 |
|
|
90 |
public String getPublisherEndpoint() { |
|
91 |
return publisherEndpoint; |
|
92 |
} |
|
93 |
|
|
94 |
public void setPublisherEndpoint(final String publisherEndpoint) { |
|
95 |
this.publisherEndpoint = publisherEndpoint; |
|
96 |
} |
|
97 |
|
|
98 |
public ResultSetClient getResultSetClient() { |
|
99 |
return resultSetClient; |
|
100 |
} |
|
101 |
|
|
102 |
public void setResultSetClient(final ResultSetClient resultSetClient) { |
|
103 |
this.resultSetClient = resultSetClient; |
|
104 |
} |
|
105 |
|
|
106 | 10 |
} |
modules/dnet-parthenos/trunk/src/main/java/eu/dnetlib/parthenos/workflows/nodes/PublishJRRJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.parthenos.workflows.nodes; |
|
2 |
|
|
3 |
public class PublishJRRJobNode extends PublishAbstractJobNode { |
|
4 |
|
|
5 |
@Override |
|
6 |
public String getTarget() { |
|
7 |
return "JRR"; |
|
8 |
} |
|
9 |
|
|
10 |
} |
modules/dnet-parthenos/trunk/src/main/java/eu/dnetlib/parthenos/workflows/nodes/PublishAbstractJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.parthenos.workflows.nodes; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import com.google.common.collect.Lists; |
|
7 |
import com.google.common.collect.Maps; |
|
8 |
import com.google.gson.Gson; |
|
9 |
import eu.dnetlib.enabling.resultset.client.ResultSetClient; |
|
10 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
11 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
12 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
13 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
14 |
import eu.dnetlib.rmi.common.ResultSet; |
|
15 |
import eu.dnetlib.rmi.manager.MSROException; |
|
16 |
import org.apache.commons.logging.Log; |
|
17 |
import org.apache.commons.logging.LogFactory; |
|
18 |
import org.apache.http.HttpResponse; |
|
19 |
import org.apache.http.NameValuePair; |
|
20 |
import org.apache.http.client.HttpClient; |
|
21 |
import org.apache.http.client.entity.UrlEncodedFormEntity; |
|
22 |
import org.apache.http.client.methods.HttpPost; |
|
23 |
import org.apache.http.impl.client.HttpClients; |
|
24 |
import org.apache.http.message.BasicNameValuePair; |
|
25 |
import org.springframework.beans.factory.annotation.Autowired; |
|
26 |
|
|
27 |
/** |
|
28 |
* Created by Alessia Bardi on 09/10/2017. |
|
29 |
* |
|
30 |
* @author Alessia Bardi |
|
31 |
*/ |
|
32 |
public abstract class PublishAbstractJobNode extends SimpleJobNode{ |
|
33 |
|
|
34 |
private static final Log log = LogFactory.getLog(PublishAbstractJobNode.class); |
|
35 |
|
|
36 |
private String inputEprParam; |
|
37 |
|
|
38 |
@Autowired |
|
39 |
private ResultSetClient resultSetClient; |
|
40 |
|
|
41 |
private String publisherEndpoint; |
|
42 |
|
|
43 |
@Override |
|
44 |
protected String execute(final Env env) throws Exception { |
|
45 |
|
|
46 |
final ResultSet<?> rsIn = env.getAttribute(getInputEprParam(), ResultSet.class); |
|
47 |
if ((rsIn == null)) { throw new MSROException("InputEprParam (" + getInputEprParam() + ") not found in ENV"); } |
|
48 |
|
|
49 |
int countAll = 0; |
|
50 |
int countOk = 0; |
|
51 |
Map<Integer, Integer> errors = Maps.newHashMap(); |
|
52 |
log.info("Publisher endpoint: " + getPublisherEndpoint()); |
|
53 |
|
|
54 |
//let's start sequentially |
|
55 |
for (String record : getResultSetClient().iter(rsIn, String.class)) { |
|
56 |
|
|
57 |
HttpPost post = new HttpPost(getPublisherEndpoint()); |
|
58 |
List<NameValuePair> params = Lists.newArrayList(); |
|
59 |
params.add(new BasicNameValuePair("record", record)); |
|
60 |
params.add(new BasicNameValuePair("parthenosTarget", getTarget())); |
|
61 |
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params, "UTF-8"); |
|
62 |
post.setEntity(ent); |
|
63 |
HttpClient client = HttpClients.createDefault(); |
|
64 |
HttpResponse responsePOST = client.execute(post); |
|
65 |
countAll++; |
|
66 |
int statusCode = responsePOST.getStatusLine().getStatusCode(); |
|
67 |
switch (statusCode) { |
|
68 |
case 200: |
|
69 |
countOk++; |
|
70 |
break; |
|
71 |
default: |
|
72 |
log.error(responsePOST.getStatusLine().getStatusCode() + ": " + responsePOST.getStatusLine().getReasonPhrase()); |
|
73 |
errors.merge(statusCode, 1, Integer::sum); |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
77 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "countOk", countOk); |
|
78 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "countAll", countAll); |
|
79 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "errorsMap", new Gson().toJson(errors)); |
|
80 |
|
|
81 |
if (!errors.isEmpty()) { |
|
82 |
throw new MSROException("Problems in publishing on "+getTarget()); |
|
83 |
} else return Arc.DEFAULT_ARC; |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
public abstract String getTarget(); |
|
88 |
|
|
89 |
public String getInputEprParam() { |
|
90 |
return this.inputEprParam; |
|
91 |
} |
|
92 |
|
|
93 |
public void setInputEprParam(final String inputEprParam) { |
|
94 |
this.inputEprParam = inputEprParam; |
|
95 |
} |
|
96 |
|
|
97 |
public String getPublisherEndpoint() { |
|
98 |
return publisherEndpoint; |
|
99 |
} |
|
100 |
|
|
101 |
public void setPublisherEndpoint(final String publisherEndpoint) { |
|
102 |
this.publisherEndpoint = publisherEndpoint; |
|
103 |
} |
|
104 |
|
|
105 |
public ResultSetClient getResultSetClient() { |
|
106 |
return resultSetClient; |
|
107 |
} |
|
108 |
|
|
109 |
public void setResultSetClient(final ResultSetClient resultSetClient) { |
|
110 |
this.resultSetClient = resultSetClient; |
|
111 |
} |
|
112 |
|
|
113 |
} |
modules/dnet-parthenos/trunk/src/main/resources/eu/dnetlib/parthenos/workflows/repo-hi/publish_wf.xml.st | ||
---|---|---|
61 | 61 |
</PARAM> |
62 | 62 |
</PARAMETERS> |
63 | 63 |
<ARCS> |
64 |
<ARC to="JRR"/> |
|
65 |
</ARCS> |
|
66 |
</NODE> |
|
67 |
<NODE name="JRR" type="LaunchWorkflowTemplate"> |
|
68 |
<DESCRIPTION>Store RDF files in Virtuoso</DESCRIPTION> |
|
69 |
<PARAMETERS> |
|
70 |
<PARAM name="wfTemplateId" value="52dcd406-0753-4257-b89c-fa03b71ef247_V29ya2Zsb3dUZW1wbGF0ZURTUmVzb3VyY2VzL1dvcmtmbG93VGVtcGxhdGVEU1Jlc291cmNlVHlwZQ==" /> |
|
71 |
<PARAM name="wfTemplateParams"> |
|
72 |
<MAP> |
|
73 |
<ENTRY key="publisherEndpoint" ref="publisherEndpoint" /> |
|
74 |
<ENTRY key="interface" value="$interface$" /> |
|
75 |
<ENTRY key="cleanMdstoreId" ref="cleanMdstoreId" /> |
|
76 |
</MAP> |
|
77 |
</PARAM> |
|
78 |
</PARAMETERS> |
|
79 |
<ARCS> |
|
64 | 80 |
<ARC to="success"/> |
65 | 81 |
</ARCS> |
66 | 82 |
</NODE> |
modules/dnet-parthenos/trunk/src/main/resources/eu/dnetlib/parthenos/workflows/nodes/applicationContext-parthenos-msro-nodes.xml | ||
---|---|---|
13 | 13 |
class="eu.dnetlib.parthenos.workflows.nodes.PublishVirtuosoJobNode" |
14 | 14 |
scope="prototype"/> |
15 | 15 |
|
16 |
<bean id="wfNodePublishJRR" |
|
17 |
class="eu.dnetlib.parthenos.workflows.nodes.PublishJRRJobNode" |
|
18 |
scope="prototype"/> |
|
19 |
|
|
16 | 20 |
<bean id="wfNodeUnpublishVirtuoso" |
17 | 21 |
class="eu.dnetlib.parthenos.workflows.nodes.UnpublishVirtuosoJobNode" |
18 | 22 |
scope="prototype"/> |
modules/dnet-parthenos/trunk/src/main/resources/eu/dnetlib/bootstrap/profiles/workflows/publish/jrr_publish_template.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<RESOURCE_PROFILE> |
|
3 |
<HEADER> |
|
4 |
<RESOURCE_IDENTIFIER value="52dcd406-0753-4257-b89c-fa03b71ef247_V29ya2Zsb3dUZW1wbGF0ZURTUmVzb3VyY2VzL1dvcmtmbG93VGVtcGxhdGVEU1Jlc291cmNlVHlwZQ=="/> |
|
5 |
<RESOURCE_TYPE value="WorkflowTemplateDSResourceType"/> |
|
6 |
<RESOURCE_KIND value="WorkflowTemplateDSResources"/> |
|
7 |
<RESOURCE_URI value=""/> |
|
8 |
<DATE_OF_CREATION value="2017-10-09T12:00:00.0Z"/> |
|
9 |
</HEADER> |
|
10 |
<BODY> |
|
11 |
<CONFIGURATION> |
|
12 |
<PARAMETERS> |
|
13 |
<PARAM name="publisherEndpoint" description="Parthenos Publisher Endpoint" required="true" type="string"/> |
|
14 |
<PARAM name="cleanMdstoreId" description="Store for transformed records" required="true" type="string"/> |
|
15 |
</PARAMETERS> |
|
16 |
<WORKFLOW> |
|
17 |
<NODE name="fetchMdStore" type="FetchMDStoreRecords" isStart="true"> |
|
18 |
<DESCRIPTION>Fetch records from MDStore</DESCRIPTION> |
|
19 |
<PARAMETERS> |
|
20 |
<PARAM name="mdId" ref="cleanMdstoreId"/> |
|
21 |
<PARAM name="eprParam" value="clean_epr"/> |
|
22 |
</PARAMETERS> |
|
23 |
<ARCS> |
|
24 |
<ARC to="publish"/> |
|
25 |
</ARCS> |
|
26 |
</NODE> |
|
27 |
<NODE name="publishJRR" type="PublishJRR"> |
|
28 |
<DESCRIPTION>Feed records into Virtuoso</DESCRIPTION> |
|
29 |
<PARAMETERS> |
|
30 |
<PARAM name="inputEprParam" value="clean_epr"/> |
|
31 |
<PARAM name="publisherEndpoint" ref="publisherEndpoint"/> |
|
32 |
</PARAMETERS> |
|
33 |
<ARCS> |
|
34 |
<ARC to="success"/> |
|
35 |
</ARCS> |
|
36 |
</NODE> |
|
37 |
</WORKFLOW> |
|
38 |
</CONFIGURATION> |
|
39 |
</BODY> |
|
40 |
</RESOURCE_PROFILE> |
modules/dnet-parthenos/trunk/dnet-parthenos.iml | ||
---|---|---|
22 | 22 |
<orderEntry type="library" scope="PROVIDED" name="Maven: org.springframework:spring-core:4.2.5.RELEASE" level="project" /> |
23 | 23 |
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" /> |
24 | 24 |
<orderEntry type="module" module-name="dnet-data-services" /> |
25 |
<orderEntry type="library" name="Maven: eu.dnetlib:dnet-core-components:2.0.0-SAXONHE-SNAPSHOT" level="project" />
|
|
25 |
<orderEntry type="module" module-name="dnet-core-components" />
|
|
26 | 26 |
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.2.5.RELEASE" level="project" /> |
27 | 27 |
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.5.RELEASE" level="project" /> |
28 | 28 |
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.2.5.RELEASE" level="project" /> |
... | ... | |
74 | 74 |
<orderEntry type="library" name="Maven: com.mycila:xmltool:3.3" level="project" /> |
75 | 75 |
<orderEntry type="library" name="Maven: joda-time:joda-time:2.9.9" level="project" /> |
76 | 76 |
<orderEntry type="library" name="Maven: org.springframework:spring-test:4.2.5.RELEASE" level="project" /> |
77 |
<orderEntry type="library" name="Maven: eu.dnetlib:dnet-core-services:2.0.0-SAXONHE-SNAPSHOT" level="project" />
|
|
77 |
<orderEntry type="module" module-name="dnet-core-services" />
|
|
78 | 78 |
<orderEntry type="library" name="Maven: org.codehaus.groovy:groovy-all:2.4.6" level="project" /> |
79 | 79 |
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.4.2" level="project" /> |
80 | 80 |
<orderEntry type="library" name="Maven: commons-net:commons-net:3.3" level="project" /> |
Also available in: Unified diff
Node and workflow to publish on JRR + code refactoring on publishing nodes.