Revision 49082
Added by Alessia Bardi about 7 years ago
modules/dnet-parthenos/trunk/src/main/java/eu/dnetlib/parthenos/workflows/nodes/PublishVirtuosoJobNode.java | ||
---|---|---|
35 | 35 |
|
36 | 36 |
private String publisherEndpoint; |
37 | 37 |
|
38 |
|
|
39 | 38 |
@Override |
40 | 39 |
protected String execute(final Env env) throws Exception { |
41 | 40 |
|
42 | 41 |
final ResultSet<?> rsIn = env.getAttribute(getInputEprParam(), ResultSet.class); |
43 |
if ((rsIn == null)) { throw new MSROException("InputEprParam (" + getInputEprParam()+ ") not found in ENV"); } |
|
42 |
if ((rsIn == null)) { throw new MSROException("InputEprParam (" + getInputEprParam() + ") not found in ENV"); }
|
|
44 | 43 |
|
45 | 44 |
int countAll = 0; |
46 | 45 |
int countOk = 0; |
47 |
Map<Integer,Integer> errors = Maps.newHashMap(); |
|
48 |
log.info("Publisher endpoint: "+getPublisherEndpoint());
|
|
46 |
Map<Integer, Integer> errors = Maps.newHashMap();
|
|
47 |
log.info("Publisher endpoint: " + getPublisherEndpoint());
|
|
49 | 48 |
|
50 | 49 |
//let's start sequentially |
51 |
for(String record : getResultSetClient().iter(rsIn, String.class)){
|
|
50 |
for (String record : getResultSetClient().iter(rsIn, String.class)) {
|
|
52 | 51 |
|
53 | 52 |
HttpPost post = new HttpPost(getPublisherEndpoint()); |
54 | 53 |
List<NameValuePair> params = Lists.newArrayList(); |
... | ... | |
60 | 59 |
HttpResponse responsePOST = client.execute(post); |
61 | 60 |
countAll++; |
62 | 61 |
int statusCode = responsePOST.getStatusLine().getStatusCode(); |
63 |
switch(statusCode){
|
|
62 |
switch (statusCode) {
|
|
64 | 63 |
case 200: |
65 | 64 |
countOk++; |
66 | 65 |
break; |
67 | 66 |
default: |
68 |
log.error(responsePOST.getStatusLine().getStatusCode()+": "+responsePOST.getStatusLine().getReasonPhrase());
|
|
67 |
log.error(responsePOST.getStatusLine().getStatusCode() + ": " + responsePOST.getStatusLine().getReasonPhrase());
|
|
69 | 68 |
errors.merge(statusCode, 1, Integer::sum); |
70 | 69 |
} |
71 | 70 |
|
72 | 71 |
} |
73 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX+"countOk", countOk);
|
|
74 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX+"countAll", countAll);
|
|
75 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX+"errorsMap", new Gson().toJson(errors));
|
|
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));
|
|
76 | 75 |
|
77 |
log.debug("countOK: "+countOk); |
|
76 |
if (!errors.isEmpty()) { |
|
77 |
throw new MSROException("Problems in publishing"); |
|
78 |
} else return Arc.DEFAULT_ARC; |
|
78 | 79 |
|
79 |
return Arc.DEFAULT_ARC; |
|
80 |
|
|
81 | 80 |
} |
82 | 81 |
|
83 | 82 |
public String getInputEprParam() { |
Also available in: Unified diff
Fail if there was at least one non-200 reply from the parthenos publisher