Skip to content
This repository was archived by the owner on Apr 22, 2022. It is now read-only.

Commit f7b58f1

Browse files
committed
added exitDetail on failed executions
1 parent 2394166 commit f7b58f1

File tree

7 files changed

+127
-30
lines changed

7 files changed

+127
-30
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
<artifactId>tomcat7-maven-plugin</artifactId>
214214
<version>2.2</version>
215215
<configuration>
216-
<server>generator</server>
216+
<server>localhost</server>
217217
<url>${tomcat.deploy.url}</url>
218218
<path>/${project.build.finalName}</path>
219219
<update>true</update>

src/main/java/eu/geoknow/generator/workflow/BatchAdminClient.java

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.util.ArrayList;
6+
import java.util.Iterator;
67
import java.util.List;
78
import java.util.Map.Entry;
89

@@ -46,6 +47,9 @@
4647
import eu.geoknow.generator.workflow.beans.JobWraper;
4748
import eu.geoknow.generator.workflow.beans.JobsRegistered;
4849
import eu.geoknow.generator.workflow.beans.Registration;
50+
import eu.geoknow.generator.workflow.beans.Status;
51+
import eu.geoknow.generator.workflow.beans.StepExecution;
52+
import eu.geoknow.generator.workflow.beans.StepJobExecution;
4953

5054
/**
5155
* A client class for spring-batch-admin service. This service doesn't support authentication, thus
@@ -76,34 +80,70 @@ public class BatchAdminClient {
7680
* @throws ServiceInternalServerError
7781
* @throws Exception
7882
*/
79-
public static JobExecutionWrapper getExecutionDetail(String jobName, String jobInstanceId,
83+
public static List<JobExecutionWrapper> getExecutionDetail(String jobName, String jobInstanceId,
8084
String springBatchServiceUri) throws ResourceNotFoundException, UnknownException,
8185
IOException, ServiceNotAvailableException, ServiceInternalServerError {
82-
// first, we need to get the resource with ID. the URI is:
83-
// http://localhost:8080/spring-batch-admin-geoknow/jobs/jobName/jobInstanceId.json
86+
87+
// get executions of an instance
8488
log.debug(springBatchServiceUri + "/jobs/" + jobName + "/" + jobInstanceId + ".json");
8589
HttpGet jobInstance =
8690
new HttpGet(springBatchServiceUri + "/jobs/" + jobName + "/" + jobInstanceId + ".json");
8791
String jsonString = apiRequest(jobInstance);
88-
log.debug(jsonString);
92+
93+
List<JobExecutionWrapper> executionsList = new ArrayList<JobExecutionWrapper>();
8994
// create Java object
9095
ObjectMapper mapper = new ObjectMapper();
96+
Gson gson = new Gson();
97+
9198
JobExecutions jobExecutions = mapper.readValue(jsonString, JobExecutions.class);
99+
// a job instance may contain several executions
100+
Iterator<JobExecution> executionsIterator = jobExecutions.getJobExecutions().iterator();
101+
102+
// "http://generator.geoknow.eu:8080/spring-batch-admin-geoknow/jobs/executions/11.json",
103+
while (executionsIterator.hasNext()) {
104+
JobExecution execution = executionsIterator.next();
105+
// wrapper
106+
log.debug("get execution:" + execution.getResource());
107+
HttpGet JobExecution = new HttpGet(execution.getResource());
108+
jsonString = apiRequest(JobExecution);
109+
JobExecutionWrapper ewrap = gson.fromJson(jsonString, JobExecutionWrapper.class);
110+
List<StepJobExecution> failedSteps = new ArrayList<StepJobExecution>();
111+
112+
// get the URL with the execution detailed error message
113+
for (Entry<String, StepExecution> entries : ewrap.getJobExecution().getStepExecutions()
114+
.entrySet()) {
115+
log.debug(entries.getKey());
116+
// next values may be null if the step was not executed
117+
log.debug(entries.getValue().getId() == null);
118+
119+
if (entries.getValue().getId() != null) {
120+
if (entries.getValue().getExitCode() == Status.FAILED) {
121+
log.debug(entries.getValue().getResource());
122+
HttpGet stepExecution = new HttpGet(entries.getValue().getResource());
123+
jsonString = apiRequest(stepExecution);
124+
StepJobExecution failedStep = gson.fromJson(jsonString, StepJobExecution.class);
125+
failedSteps.add(failedStep);
126+
// we add the exit description to the step metadata
127+
entries.getValue().setExitDescription(
128+
failedStep.getStepExecution().getExitDescription());
129+
}
130+
}
131+
}
92132

93-
// List<JobExecution> executionList =
94-
// jobInst.getJobInstance().getJobExecutions().getJobExecutions();
95-
// List<JobExecution> executionList =
96-
// jobExecutions.getJobInstance().getJobExecutions().getJobExecutions();
97-
98-
// now, use first element (it has only one) to get the resource in the
99-
// execution, to get the
100-
// wrapper
101-
HttpGet JobExecution = new HttpGet(jobExecutions.getJobExecutions().get(0).getResource());
102-
jsonString = apiRequest(JobExecution);
103-
// create the required wrapper
104-
Gson gson = new Gson();
105-
JobExecutionWrapper execution = gson.fromJson(jsonString, JobExecutionWrapper.class);
106-
return execution;
133+
// here we add a exit description to the hole execution (i.e.) step 1 failed
134+
Iterator<StepJobExecution> iter = failedSteps.iterator();
135+
while (iter.hasNext()) {
136+
StepJobExecution fs = iter.next();
137+
String oldesc = ewrap.getJobExecution().getExitDescription();
138+
if (!oldesc.equals(""))
139+
oldesc += "<br/>";
140+
ewrap.getJobExecution().setExitDescription(
141+
oldesc + fs.getStepExecution().getName() + " : "
142+
+ fs.getStepExecution().getExitCode().toString());
143+
}
144+
executionsList.add(ewrap);
145+
}
146+
return executionsList;
107147
}
108148

109149
/**

src/main/java/eu/geoknow/generator/workflow/JobsManager.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,24 +326,40 @@ public Registration getJob(String jobName, UserProfile user) throws Exception {
326326
return job;
327327
}
328328

329+
/**
330+
* Get the executions of a JOB based on instances registered in the store
331+
*
332+
* @param job
333+
* @return
334+
* @throws IOException
335+
* @throws Exception
336+
*/
329337
public JobExecutions getExcecutions(Registration job) throws IOException, Exception {
330338

331339
// complete with execution information
332340
JobExecutions executions = new JobExecutions();
333341

342+
// TODO: check I think is instances are not sync to SBA instances- notice that if SBA is
343+
// restarted these doesnt exist anymore
334344
if (job.getJobInstances().size() > 0) {
335345
Set<Integer> instances = job.getJobInstances().keySet();
336346
log.debug(instances.size() + " instances ");
337347
Iterator<Integer> it = instances.iterator();
338348

349+
List<JobExecutionWrapper> instanceExecutions = null;
339350
while (it.hasNext()) {
340351
// this is just the instance number, no the ID:
341352
// http://localhost:8080/spring-batch-admin-geoknow/jobs/d2rq_2/4
342353
int id = it.next();
343-
JobExecutionWrapper execution =
354+
instanceExecutions =
344355
BatchAdminClient.getExecutionDetail(job.getName(), "" + id, springBatchServiceUri);
345-
executions.getJobExecutions().add(execution.getJobExecution());
346-
356+
}
357+
if (instanceExecutions != null) {
358+
Iterator<JobExecutionWrapper> instanceIterator = instanceExecutions.iterator();
359+
while (instanceIterator.hasNext()) {
360+
JobExecutionWrapper execution = instanceIterator.next();
361+
executions.getJobExecutions().add(execution.getJobExecution());
362+
}
347363
}
348364
}
349365
return executions;

src/main/java/eu/geoknow/generator/workflow/beans/JobExecutionWrapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
public class JobExecutionWrapper {
77
private JobExecution jobExecution;
8-
private Map<String, String> errors;
9-
8+
private Map<String, StepExecutionDetail> errors;
9+
1010
private String page;
1111

1212
public JobExecutionWrapper() {
13-
this.errors = new HashMap<String, String>();
13+
this.errors = new HashMap<String, StepExecutionDetail>();
1414
}
1515

1616
public JobExecution getJobExecution() {
@@ -21,11 +21,11 @@ public void setJobExecution(JobExecution jobExecution) {
2121
this.jobExecution = jobExecution;
2222
}
2323

24-
public Map<String, String> getErrors() {
24+
public Map<String, StepExecutionDetail> getErrors() {
2525
return errors;
2626
}
2727

28-
public void setErrors(Map<String, String> errors) {
28+
public void setErrors(Map<String, StepExecutionDetail> errors) {
2929
this.errors = errors;
3030
}
3131

@@ -37,5 +37,5 @@ public void setPage(String page) {
3737
this.page = page;
3838
}
3939

40-
40+
4141
}

src/main/java/eu/geoknow/generator/workflow/beans/StepExecution.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
package eu.geoknow.generator.workflow.beans;
22

3+
/**
4+
*
5+
*
6+
* @author alejandragarciarojas
7+
*
8+
*
9+
* "multiStep_actorsex1446562308585_2" : {
10+
"status" : "NONE",
11+
"exitCode" : "NONE",
12+
"readCount" : "0",
13+
"writeCount" : "0",
14+
"commitCount" : "0",
15+
"rollbackCount" : "0",
16+
"duration" : "-"
17+
},
18+
19+
"multiStep_actorsex1446562308585_1" : {
20+
"status" : "FAILED",
21+
"exitCode" : "FAILED",
22+
"id" : "29",
23+
"resource" : "http://generator.geoknow.eu:8080/spring-batch-admin-geoknow/jobs/executions/12/steps/29.json",
24+
"readCount" : "0",
25+
"writeCount" : "0",
26+
"commitCount" : "0",
27+
"rollbackCount" : "1",
28+
"duration" : "00:00:00"
29+
}
30+
*/
331
public class StepExecution {
432

533
private Status status;
@@ -11,7 +39,11 @@ public class StepExecution {
1139
private String commitCount;
1240
private String rollbackCount;
1341
private String duration;
42+
// exitDescription data is added after the POJO deserialization
43+
private String exitDescription;
1444

45+
public StepExecution(){}
46+
1547
public Status getStatus() {
1648
return status;
1749
}
@@ -84,4 +116,12 @@ public void setDuration(String duration) {
84116
this.duration = duration;
85117
}
86118

119+
public String getExitDescription() {
120+
return exitDescription;
121+
}
122+
123+
public void setExitDescription(String exitDescription) {
124+
this.exitDescription = exitDescription;
125+
}
126+
87127
}

src/main/resources/log4j.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ log4j.appender.stdout.Target=System.out
77
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
88
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
99

10-
log4j.logger.eu.geoknow=INFO
10+
log4j.logger.eu.geoknow=DEBUG

src/test/java/eu/geoknow/generator/workflow/BatchAdminClientIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.util.Calendar;
88
import java.util.GregorianCalendar;
9+
import java.util.List;
910

1011
import org.apache.log4j.Logger;
1112
import org.junit.Test;
@@ -84,7 +85,7 @@ public void getAJob() throws Exception {
8485

8586
@Test(expected = UnknownException.class)
8687
public void getUnexistingExecution() throws Exception {
87-
JobExecutionWrapper execution =
88+
List<JobExecutionWrapper> execution =
8889
BatchAdminClient.getExecutionDetail("mmxy", "91919", springBatchServiceUri);
8990
}
9091

0 commit comments

Comments
 (0)