Example usage for org.springframework.batch.core StepExecution getId

List of usage examples for org.springframework.batch.core StepExecution getId

Introduction

In this page you can find the example usage for org.springframework.batch.core StepExecution getId.

Prototype

public Long getId() 

Source Link

Usage

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java

/**
 * Returns a copy of {@link StepExecution}, by adding new Objects for every field(no references are passed)
 * /* www . j  av  a  2  s .  co m*/
 * @param original StepExecution to be copied
 * @return StepExecution copy
 */
private static StepExecution copy(StepExecution original) {
    StepExecution copy = new StepExecution(original.getStepName(), original.getJobExecution());
    copy.setCommitCount(original.getCommitCount());
    if (original.getEndTime() != null) {
        copy.setEndTime((Date) original.getEndTime().clone());
    }
    //Warning: no deep copy
    if (original.getExitStatus() != null) {
        copy.setExitStatus(new ExitStatus(original.getExitStatus().getExitCode(),
                original.getExitStatus().getExitDescription()));
    }
    copy.setFilterCount(original.getFilterCount());
    copy.setId(original.getId());
    if (original.getLastUpdated() != null) {
        copy.setLastUpdated((Date) original.getLastUpdated().clone());
    }
    copy.setProcessSkipCount(original.getProcessSkipCount());
    copy.setReadCount(original.getReadCount());
    copy.setReadSkipCount(original.getReadSkipCount());
    copy.setRollbackCount(original.getRollbackCount());
    if (original.getStartTime() != null) {
        copy.setStartTime((Date) original.getStartTime().clone());
    }
    if (original.getStatus() != null) {
        copy.setStatus(BatchStatus.valueOf(original.getStatus().name()));
    }
    if (original.isTerminateOnly()) {
        copy.setTerminateOnly();
    }
    copy.setVersion(original.getVersion());
    copy.setWriteCount(original.getWriteCount());
    copy.setWriteSkipCount(original.getWriteSkipCount());
    return copy;
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapExecutionContextDao.java

/**
 * Removes all the executionContexts for given stepExecution
 * @param jobExecution//from   w  w  w.jav  a2 s  . c  om
 */
public void removeExecutionContext(StepExecution stepExecution) {
    contexts.remove(ContextKey.step(stepExecution.getId()));
}

From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionResource.java

/**
 * Retrieves the list of all steps by job execution id.
 *
 * @param jobExecutionId the job execution id
 * @return the response//  w ww  .  j a v a2s .  c  o  m
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions("seed:monitoring:batch:read")
public Response list(@PathParam("jobExecutionId") long jobExecutionId) {

    Collection<StepExecutionRepresentation> stepExecutionRepresentations = new ArrayList<StepExecutionRepresentation>();
    try {
        for (StepExecution stepExecution : jobService.getStepExecutions(jobExecutionId)) {
            if (stepExecution.getId() != null) {
                stepExecutionRepresentations
                        .add(new StepExecutionRepresentation(stepExecution, TimeZone.getTimeZone("GMT")));
            }
        }

    } catch (NoSuchJobExecutionException e) {
        return Response.status(Response.Status.BAD_REQUEST)
                .entity("There is no such job execution (" + jobExecutionId + ")").type(MediaType.TEXT_PLAIN)
                .build();
    }
    return Response.ok(stepExecutionRepresentations).build();

}

From source file:admin.jmx.SimpleStepExecutionMetrics.java

public long getLatestExecutionId() {
    StepExecution stepExecution = getLatestStepExecution(stepName);
    return stepExecution == null ? -1 : stepExecution.getId();
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapExecutionContextDao.java

@Override
public ExecutionContext getExecutionContext(StepExecution stepExecution) {
    return copy(contexts.get(ContextKey.step(stepExecution.getId())));
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java

@Override
public void saveStepExecution(StepExecution stepExecution) {

    Assert.isTrue(stepExecution.getId() == null);
    Assert.isTrue(stepExecution.getVersion() == null);
    Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already.");

    Long jobExecutionID = stepExecution.getJobExecutionId();

    Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
    if (executions == null) {
        executions = new ConcurrentHashMap<Long, StepExecution>();
        executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions);
    }//  w ww  .  j  a v a2  s  .c o  m

    stepExecution.setId(currentId.incrementAndGet());
    stepExecution.incrementVersion();
    StepExecution copy = copy(stepExecution);
    executions.put(stepExecution.getId(), copy);
    executionsByStepExecutionId.put(stepExecution.getId(), copy);

}

From source file:org.obiba.onyx.core.service.impl.DefaultAppointmentManagementServiceImpl.java

public List<AppointmentUpdateLog> getLogListForDate(Date date) {
    List<AppointmentUpdateLog> logList = new ArrayList<AppointmentUpdateLog>();
    List<JobInstance> jobsList = jobExplorer.getJobInstances(job.getName(), 0, 10);

    JobExecution jobExecution = null;/*from  w  w  w.j  a  v a  2  s .co  m*/

    for (JobInstance jobInstance : jobsList) {
        if (jobInstance.getJobParameters().getDate("date").toString().equals(date.toString())) {
            jobExecution = jobExplorer.getJobExecutions(jobInstance).get(0);
            break;
        }
    }

    if (jobExecution == null)
        return null;

    for (StepExecution stepExec : jobExecution.getStepExecutions()) {
        StepExecution stepExecution = jobExplorer.getStepExecution(jobExecution.getId(), stepExec.getId());
        if (stepExecution.getExecutionContext().get("logList") != null) {
            logList.addAll((List<AppointmentUpdateLog>) (stepExecution.getExecutionContext().get("logList")));
        }
    }

    return logList;
}

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
 *//*  w ww.  j a  v a  2  s . c o m*/
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.MapExecutionContextDao.java

@Override
public void updateExecutionContext(StepExecution stepExecution) {
    ExecutionContext executionContext = stepExecution.getExecutionContext();
    if (executionContext != null) {
        contexts.put(ContextKey.step(stepExecution.getId()), copy(executionContext));
    }/*w w  w  .  ja  va 2s .c  o m*/
}

From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionRepresentation.java

/**
 * Instantiates a new step execution representation.
 *
 * @param stepExecution the step execution
 * @param timeZone      the time zone//from w  w w.  ja v  a2 s .  com
 */
public StepExecutionRepresentation(StepExecution stepExecution, TimeZone timeZone) {

    this.setStepExecutionDetailsRepresentation(new StepExecutionDetailsRepresentation(stepExecution));
    this.id = stepExecution.getId();
    this.name = stepExecution.getStepName();
    this.jobName = stepExecution.getJobExecution() == null
            || stepExecution.getJobExecution().getJobInstance() == null ? "?"
                    : stepExecution.getJobExecution().getJobInstance().getJobName();
    this.jobExecutionId = stepExecution.getJobExecutionId();
    // Duration is always in GMT
    durationFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    timeFormat.setTimeZone(timeZone);
    dateFormat.setTimeZone(timeZone);
    if (stepExecution.getStartTime() != null) {
        this.startDate = dateFormat.format(stepExecution.getStartTime());
        this.startTime = timeFormat.format(stepExecution.getStartTime());
        Date endTime = stepExecution.getEndTime() != null ? stepExecution.getEndTime() : new Date();

        this.durationMillis = endTime.getTime() - stepExecution.getStartTime().getTime();
        this.duration = durationFormat.format(new Date(durationMillis));
    }
    if (stepExecution.getEndTime() != null) {
        this.endTime = timeFormat.format(stepExecution.getEndTime());
    }

}