List of usage examples for org.springframework.batch.core JobExecution getJobParameters
public JobParameters getJobParameters()
From source file:de.codecentric.batch.listener.ProtocolListener.java
public void beforeJob(JobExecution jobExecution) { StringBuilder protocol = new StringBuilder(); protocol.append(createFilledLine('-')); protocol.append("Job " + jobExecution.getJobInstance().getJobName() + " started with Job-Execution-Id " + jobExecution.getId() + " \n"); protocol.append("Job-Parameter: \n"); JobParameters jp = jobExecution.getJobParameters(); for (Iterator<Entry<String, JobParameter>> iter = jp.getParameters().entrySet().iterator(); iter .hasNext();) {/*from w w w . j a v a2 s.c o m*/ Entry<String, JobParameter> entry = iter.next(); protocol.append(" " + entry.getKey() + "=" + entry.getValue() + "\n"); } protocol.append(createFilledLine('-')); LOGGER.info(protocol.toString()); }
From source file:uk.ac.ebi.intact.editor.controller.dbmanager.ImportJobController.java
public String extractJobId(JobExecution execution) { if (execution != null) { JobParameters param = execution.getJobParameters(); if (param != null) { return param.getString("MIJobId"); }//from ww w . j a v a 2 s . c o m } return null; }
From source file:org.seedstack.monitoring.batch.internal.rest.jobinstance.JobInstanceResource.java
/** * Retrieves the list of job instances by job name. * * @param jobName the job name/*from w ww. jav a2s . c om*/ * @param startJob the start job * @param pageSize the page size * @return the response */ @GET @Produces(MediaType.APPLICATION_JSON) public Response listJobInstancesForJobs(@PathParam("jobName") String jobName, @DefaultValue("0") @QueryParam("startJob") int startJob, @DefaultValue("20") @QueryParam("pageSize") int pageSize) { try { Collection<JobInstance> result = jobService.listJobInstances(jobName, startJob, pageSize); Collection<JobInstanceRepresentation> jobInstancesRepresentations = new ArrayList<JobInstanceRepresentation>(); for (JobInstance jobInstance : result) { Collection<JobExecutionInfo> executionRepresentations = new ArrayList<JobExecutionInfo>(); Collection<JobExecution> jobExecutionsForJobInstance = jobService .getJobExecutionsForJobInstance(jobName, jobInstance.getId()); for (JobExecution jobExecution : jobExecutionsForJobInstance) { executionRepresentations .add(new JobExecutionInfo(jobExecution, new GregorianCalendar().getTimeZone())); jobInstancesRepresentations.add(new JobInstanceRepresentation(jobInstance.getJobName(), jobInstance.getId(), jobExecution.getJobParameters(), executionRepresentations)); } } return Response.ok(jobInstancesRepresentations).build(); } catch (NoSuchJobException e) { String error = "There is no such job (" + jobName + ")"; return Response.status(Response.Status.BAD_REQUEST).entity(error).type(MediaType.TEXT_PLAIN).build(); } }
From source file:org.seedstack.monitoring.batch.internal.rest.job.JobResource.java
/** * Retrieves the jobs tree.//from ww w. j a v a 2 s.c o m * * @param jobName the job name * @return the response */ @GET @Produces(MediaType.APPLICATION_JSON) @Path("/jobs-tree/{jobName}") @RequiresPermissions("seed:monitoring:batch:read") public Response jobsTree(@PathParam("jobName") String jobName) { int countJobInstances; try { countJobInstances = jobService.countJobExecutionsForJob(jobName); } catch (NoSuchJobException e1) { return Response.status(Response.Status.BAD_REQUEST).entity("There is no such jobs ") .type(MediaType.TEXT_PLAIN).build(); } if (countJobInstances == 0) { String error = "wrong job name " + jobName; return Response.status(Response.Status.BAD_REQUEST).entity(error).type(MediaType.TEXT_PLAIN).build(); } JobsTreeRepresentation jobsTreeRepresentation = new JobsTreeRepresentation(); int countJobs = jobService.countJobs(); Collection<String> listJobs = jobService.listJobs(0, countJobs); jobsTreeRepresentation.setJobNameList(listJobs); jobsTreeRepresentation.setName(jobName); jobsTreeRepresentation.setStatus(TREE_MAINNODE); jobsTreeRepresentation.setLink(TREE_URL_BATCH_JOBS_LIST); Collection<JobExecution> listJobExecutionsForJob; try { listJobExecutionsForJob = jobService.listJobExecutionsForJob(jobName, 0, countJobInstances); } catch (NoSuchJobException e) { return Response.status(Response.Status.BAD_REQUEST) .entity("There is no such job execution by jobname (" + jobName + ")") .type(MediaType.TEXT_PLAIN).build(); } /* list of job execution by job */ List<JobsTreeRepresentation> childrenJobExecution = new ArrayList<JobsTreeRepresentation>(); for (JobExecution jobExecution : listJobExecutionsForJob) { JobsTreeRepresentation jobExecTreeRepresentation = new JobsTreeRepresentation(); jobExecTreeRepresentation.setName("[id= " + jobExecution.getId() + "];" + jobExecution.getJobParameters().getParameters().toString()); jobExecTreeRepresentation.setLink(TREE_URL_BATCH_JOBS_LIST + "/" + jobName); jobExecTreeRepresentation.setSize(TREE_SIZE_JOBEXECUTION); jobExecTreeRepresentation.setStatus(jobExecution.getExitStatus().getExitCode()); Collection<StepExecution> stepExecutions; try { stepExecutions = jobService.getStepExecutions(jobExecution.getId()); } catch (NoSuchJobExecutionException e) { return Response.status(Response.Status.BAD_REQUEST) .entity("There is no such job execution (" + jobExecution.getId() + ")") .type(MediaType.TEXT_PLAIN).build(); } /* list of step by job execution */ List<JobsTreeRepresentation> childrenStep = new ArrayList<JobsTreeRepresentation>(); for (StepExecution stepExecution : stepExecutions) { JobsTreeRepresentation stepTreeRepresentation = new JobsTreeRepresentation(); stepTreeRepresentation.setName(stepExecution.getStepName()); stepTreeRepresentation .setLink(TREE_URL_BATCH_JOBS_LIST + "/" + jobName + "/" + jobExecution.getId()); stepTreeRepresentation.setSize(TREE_SIZE_STEP); stepTreeRepresentation.setStatus(stepExecution.getExitStatus().getExitCode()); childrenStep.add(stepTreeRepresentation); } jobExecTreeRepresentation.setChildren(childrenStep); childrenJobExecution.add(jobExecTreeRepresentation); } jobsTreeRepresentation.setChildren(childrenJobExecution); return Response.ok(jobsTreeRepresentation).build(); }
From source file:uk.ac.ebi.intact.editor.controller.dbmanager.ImportJobController.java
public void acceptImport(ActionEvent evt) { if (!evt.getComponent().getChildren().isEmpty()) { UIParameter param = (UIParameter) evt.getComponent().getChildren().iterator().next(); long executionId = (Long) param.getValue(); JobExecution execution = getJobExplorer().getJobExecution(executionId); if (execution != null) { JobParameters params = execution.getJobParameters(); if (params != null) { String jobId = params.getString("MIJobId"); try { getDbImportService().acceptImport(jobId); getBatchJobService().deleteJob(executionId); addInfoMessage("Job accepted, import annotations removed", "Execution ID: " + executionId); } catch (Throwable e) { addErrorMessage("Cannot accept job import " + e.getMessage(), "Execution ID: " + executionId); }/*from w w w . j av a2 s . co m*/ } } } }
From source file:uk.ac.ebi.intact.editor.controller.dbmanager.ImportJobController.java
public void discardImport(ActionEvent evt) { if (!evt.getComponent().getChildren().isEmpty()) { UIParameter param = (UIParameter) evt.getComponent().getChildren().iterator().next(); long executionId = (Long) param.getValue(); JobExecution execution = getJobExplorer().getJobExecution(executionId); if (execution != null) { JobParameters params = execution.getJobParameters(); if (params != null) { String jobId = params.getString("MIJobId"); try { getDbImportService().deleteImportedFeatures(jobId); getDbImportService().deleteImportedParticipants(jobId); getDbImportService().deleteImportedInteractions(jobId); getDbImportService().deleteImportedExperiments(jobId); getDbImportService().deleteImportedPublications(jobId); getDbImportService().deleteImportedOrganisms(jobId); getDbImportService().deleteImportedSources(jobId); getDbImportService().deleteImportedCvs(jobId); getBatchJobService().deleteJob(executionId); addInfoMessage("Job cleared, import objects deleted", "Execution ID: " + executionId); } catch (Throwable e) { addErrorMessage("Cannot clear job import " + e.getMessage(), "Execution ID: " + executionId + ", " + ExceptionUtils.getFullStackTrace(e)); }/*from w ww . jav a 2 s . c o m*/ String errorFileName = params.getString("error.file"); String fileName = params.getString("input.file"); File file = new File(fileName); if (file.exists()) { file.delete(); } File errorFile = new File(errorFileName); if (errorFile.exists()) { errorFile.delete(); } } } } }
From source file:uk.ac.ebi.intact.editor.controller.dbmanager.ImportJobController.java
public void stopAndDiscardImport(ActionEvent evt) { if (!evt.getComponent().getChildren().isEmpty()) { UIParameter param = (UIParameter) evt.getComponent().getChildren().iterator().next(); long executionId = (Long) param.getValue(); try {/*ww w . j a v a2s . c o m*/ getPsiMIJobManager().getJobOperator().stop(executionId); addInfoMessage("Job stopped", "Execution ID: " + executionId); } catch (NoSuchJobExecutionException e) { addErrorMessage("Job does not exist: " + e.getMessage(), "Execution ID: " + executionId); e.printStackTrace(); } catch (JobExecutionNotRunningException e) { addErrorMessage("Job is not running anymore: " + e.getMessage(), "Execution ID: " + executionId); e.printStackTrace(); } JobExecution execution = getJobExplorer().getJobExecution(executionId); if (execution != null) { JobParameters params = execution.getJobParameters(); if (params != null) { String jobId = params.getString("MIJobId"); try { getDbImportService().deleteImportedFeatures(jobId); getDbImportService().deleteImportedParticipants(jobId); getDbImportService().deleteImportedInteractions(jobId); getDbImportService().deleteImportedExperiments(jobId); getDbImportService().deleteImportedPublications(jobId); getDbImportService().deleteImportedOrganisms(jobId); getDbImportService().deleteImportedSources(jobId); getDbImportService().deleteImportedCvs(jobId); getBatchJobService().deleteJob(executionId); addInfoMessage("Job cleared, import objects deleted", "Execution ID: " + executionId); } catch (Throwable e) { addErrorMessage("Cannot clear job import " + e.getMessage(), "Execution ID: " + executionId + ", " + ExceptionUtils.getFullStackTrace(e)); } String errorFileName = params.getString("error.file"); String fileName = params.getString("input.file"); File file = new File(fileName); if (file.exists()) { file.delete(); } File errorFile = new File(errorFileName); if (errorFile.exists()) { errorFile.delete(); } } } } }
From source file:org.springframework.batch.admin.domain.JobExecutionInfoResource.java
public JobExecutionInfoResource(JobExecution jobExecution, TimeZone timeZone) { if (timeZone != null) { this.timeZone = timeZone; } else {//from w w w . java2s . co m this.timeZone = TimeZone.getTimeZone("UTC"); } this.executionId = jobExecution.getId(); this.jobId = jobExecution.getJobId(); this.stepExecutionCount = jobExecution.getStepExecutions().size(); this.jobParameters = jobExecution.getJobParameters(); this.status = jobExecution.getStatus(); this.exitStatus = jobExecution.getExitStatus(); this.jobConfigurationName = jobExecution.getJobConfigurationName(); this.failureExceptions = jobExecution.getFailureExceptions(); Map<String, Object> executionContextEntires = new HashMap<String, Object>( jobExecution.getExecutionContext().size()); for (Map.Entry<String, Object> stringObjectEntry : jobExecution.getExecutionContext().entrySet()) { executionContextEntires.put(stringObjectEntry.getKey(), stringObjectEntry.getValue()); } this.executionContext = executionContextEntires; this.version = jobExecution.getVersion(); JobInstance jobInstance = jobExecution.getJobInstance(); if (jobInstance != null) { this.jobName = jobInstance.getJobName(); BatchStatus status = jobExecution.getStatus(); this.restartable = status.isGreaterThan(BatchStatus.STOPPING) && status.isLessThan(BatchStatus.ABANDONED); this.abandonable = status.isGreaterThan(BatchStatus.STARTED) && status != BatchStatus.ABANDONED; this.stoppable = status.isLessThan(BatchStatus.STOPPING) && status != BatchStatus.COMPLETED; } else { this.jobName = "?"; } this.dateFormat = this.dateFormat.withZone(DateTimeZone.forTimeZone(timeZone)); this.createDate = dateFormat.print(jobExecution.getCreateTime().getTime()); this.lastUpdated = dateFormat.print(jobExecution.getLastUpdated().getTime()); if (jobExecution.getStartTime() != null) { this.startTime = dateFormat.print(jobExecution.getStartTime().getTime()); this.endTime = dateFormat.print(jobExecution.getEndTime().getTime()); } }
From source file:admin.service.SimpleJobService.java
@Override public JobExecution restart(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException { JobExecution target = getJobExecution(jobExecutionId); JobInstance lastInstance = target.getJobInstance(); Job job = jobLocator.getJob(lastInstance.getJobName()); JobExecution jobExecution = jobLauncher.run(job, target.getJobParameters()); if (jobExecution.isRunning()) { activeExecutions.add(jobExecution); }/*from w w w . ja va 2 s . co m*/ return jobExecution; }
From source file:admin.service.SimpleJobService.java
@Override public JobParameters getLastJobParameters(String jobName) throws NoSuchJobException { Collection<JobExecution> executions = jobExecutionDao.getJobExecutions(jobName, 0, 1); JobExecution lastExecution = null; if (!CollectionUtils.isEmpty(executions)) { lastExecution = executions.iterator().next(); }//ww w. ja va 2 s . c o m JobParameters oldParameters = new JobParameters(); if (lastExecution != null) { oldParameters = lastExecution.getJobParameters(); } return oldParameters; }