List of usage examples for org.springframework.batch.core JobExecution getId
public Long getId()
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobExecutionDao.java
@Override public void synchronizeStatus(JobExecution jobExecution) { JobExecution saved = getJobExecution(jobExecution.getId()); if (saved.getVersion().intValue() != jobExecution.getVersion().intValue()) { jobExecution.upgradeStatus(saved.getStatus()); jobExecution.setVersion(saved.getVersion()); }//from w ww. j a va 2 s .c om }
From source file:bamons.process.monitoring.service.listener.EmailMonitoringNotifier.java
private String createMessageContent(JobExecution jobExecution) { List<Throwable> exceptions = jobExecution.getFailureExceptions(); StringBuilder content = new StringBuilder(); content.append("Job execution ID #"); content.append(jobExecution.getId()); content.append(" of job instance ID #"); content.append(jobExecution.getJobInstance().getId()); content.append(" failed with following exceptions : "); for (Throwable exception : exceptions) { content.append(""); content.append(formatExceptionMessage(exception)); }//from www . ja v a2s . c o m return content.toString(); }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobExecutionDao.java
@Override public List<JobExecution> findJobExecutions(JobInstance jobInstance) { List<JobExecution> executions = new ArrayList<JobExecution>(); for (JobExecution exec : executionsById.values()) { if (exec.getJobInstance().equals(jobInstance)) { executions.add(copy(exec));/* ww w . jav a2 s . com*/ } } Collections.sort(executions, new Comparator<JobExecution>() { @Override public int compare(JobExecution e1, JobExecution e2) { long result = (e1.getId() - e2.getId()); if (result > 0) { return -1; } else if (result < 0) { return 1; } else { return 0; } } }); return executions; }
From source file:admin.jmx.SimpleJobExecutionMetrics.java
public long getLatestExecutionId() { JobExecution jobExecution = getLatestJobExecution(jobName); return jobExecution == null ? -1 : jobExecution.getId(); }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java
/** * Removes all the stepExecutions from the DAO * @param jobExecution JobExecution whose StepExecutions have to be deleted *//*from w ww . j av a 2 s .c om*/ public void removeStepExecutions(JobExecution jobExecution) { Map<Long, StepExecution> executions = executionsByJobExecutionId.get(jobExecution.getId()); if (executions == null || executions.isEmpty()) { return; } for (StepExecution step : executions.values()) { LOGGER.info("Removing stepExecution: " + step); executionsByStepExecutionId.remove(step.getId()); } executionsByJobExecutionId.remove(jobExecution.getId()); }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java
@Override public void addStepExecutions(JobExecution jobExecution) { Map<Long, StepExecution> executions = executionsByJobExecutionId.get(jobExecution.getId()); if (executions == null || executions.isEmpty()) { return;//from ww w . ja v a 2s . c o m } List<StepExecution> result = new ArrayList<StepExecution>(executions.values()); Collections.sort(result, new Comparator<Entity>() { @Override public int compare(Entity o1, Entity o2) { return Long.signum(o2.getId() - o1.getId()); } }); List<StepExecution> copy = new ArrayList<StepExecution>(result.size()); for (StepExecution exec : result) { copy.add(copy(exec)); } jobExecution.addStepExecutions(copy); }
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 ww . j a v a2s . 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:org.trpr.platform.batch.impl.spring.admin.repository.MapExecutionContextDao.java
@Override public void updateExecutionContext(JobExecution jobExecution) { ExecutionContext executionContext = jobExecution.getExecutionContext(); if (executionContext != null) { contexts.put(ContextKey.job(jobExecution.getId()), copy(executionContext)); }//from w w w . java 2s . c om }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobInstanceDao.java
public JobInstance createJobInstance(String jobName, JobParameters jobParameters) { Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist"); JobInstance jobInstance = new JobInstance(currentId++, jobParameters, jobName); jobInstance.incrementVersion();//w w w. ja v a 2s . c om //Removes the older jobInstances if (this.jobInstances.size() >= maxJobInstanceCount) { JobInstance toRemove = this.jobInstances.remove(); LOGGER.info("Removing jobInstance: " + toRemove.toString()); List<JobExecution> executions = this.jobExecutionDao.findJobExecutions(toRemove); for (JobExecution execution : executions) { //Remove job executions LOGGER.info("Removing JobExecution: " + execution.toString()); this.jobExecutionDao.removeExecution(execution.getId()); this.stepExecutionDao.removeStepExecutions(execution); //Remove execution contexts this.executionContextDao.removeExecutionContext(execution); } } jobInstances.add(jobInstance); return jobInstance; }
From source file:org.seedstack.monitoring.batch.internal.rest.job.JobResource.java
/** * Retrieves the jobs tree.//from w w w. j a va 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(); }