|
3 | 3 | import java.io.File; |
4 | 4 | import java.io.IOException; |
5 | 5 | import java.util.ArrayList; |
| 6 | +import java.util.Iterator; |
6 | 7 | import java.util.List; |
7 | 8 | import java.util.Map.Entry; |
8 | 9 |
|
|
46 | 47 | import eu.geoknow.generator.workflow.beans.JobWraper; |
47 | 48 | import eu.geoknow.generator.workflow.beans.JobsRegistered; |
48 | 49 | 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; |
49 | 53 |
|
50 | 54 | /** |
51 | 55 | * A client class for spring-batch-admin service. This service doesn't support authentication, thus |
@@ -76,34 +80,70 @@ public class BatchAdminClient { |
76 | 80 | * @throws ServiceInternalServerError |
77 | 81 | * @throws Exception |
78 | 82 | */ |
79 | | - public static JobExecutionWrapper getExecutionDetail(String jobName, String jobInstanceId, |
| 83 | + public static List<JobExecutionWrapper> getExecutionDetail(String jobName, String jobInstanceId, |
80 | 84 | String springBatchServiceUri) throws ResourceNotFoundException, UnknownException, |
81 | 85 | 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 |
84 | 88 | log.debug(springBatchServiceUri + "/jobs/" + jobName + "/" + jobInstanceId + ".json"); |
85 | 89 | HttpGet jobInstance = |
86 | 90 | new HttpGet(springBatchServiceUri + "/jobs/" + jobName + "/" + jobInstanceId + ".json"); |
87 | 91 | String jsonString = apiRequest(jobInstance); |
88 | | - log.debug(jsonString); |
| 92 | + |
| 93 | + List<JobExecutionWrapper> executionsList = new ArrayList<JobExecutionWrapper>(); |
89 | 94 | // create Java object |
90 | 95 | ObjectMapper mapper = new ObjectMapper(); |
| 96 | + Gson gson = new Gson(); |
| 97 | + |
91 | 98 | 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 | + } |
92 | 132 |
|
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; |
107 | 147 | } |
108 | 148 |
|
109 | 149 | /** |
|
0 commit comments