Example usage for org.springframework.batch.core BatchStatus isGreaterThan

List of usage examples for org.springframework.batch.core BatchStatus isGreaterThan

Introduction

In this page you can find the example usage for org.springframework.batch.core BatchStatus isGreaterThan.

Prototype

public boolean isGreaterThan(BatchStatus other) 

Source Link

Usage

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 ww. j a va  2s. com
        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:org.geoserver.backuprestore.Backup.java

/**
 * Stop a running Backup/Restore Execution
 * //from  ww w.  j a v  a  2s  .c  o  m
 * @param executionId
 * @return
 * @throws NoSuchJobExecutionException
 * @throws JobExecutionNotRunningException
 */
public void stopExecution(Long executionId)
        throws NoSuchJobExecutionException, JobExecutionNotRunningException {
    LOGGER.info("Stopping execution id [" + executionId + "]");

    JobExecution jobExecution = null;
    try {
        if (this.backupExecutions.get(executionId) != null) {
            jobExecution = this.backupExecutions.get(executionId).getDelegate();
        } else if (this.restoreExecutions.get(executionId) != null) {
            jobExecution = this.restoreExecutions.get(executionId).getDelegate();
        }

        jobOperator.stop(executionId);
    } finally {
        if (jobExecution != null) {
            final BatchStatus status = jobExecution.getStatus();

            if (!status.isGreaterThan(BatchStatus.STARTED)) {
                jobExecution.setStatus(BatchStatus.STOPPING);
                jobExecution.setEndTime(new Date());
                jobRepository.update(jobExecution);
            }
        }

        // Release locks on GeoServer Configuration:
        try {
            List<BackupRestoreCallback> callbacks = GeoServerExtensions.extensions(BackupRestoreCallback.class);
            for (BackupRestoreCallback callback : callbacks) {
                callback.onEndRequest();
            }
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Could not unlock GeoServer Catalog Configuration!", e);
        }
    }
}

From source file:org.springframework.batch.admin.web.server.JsonIntegrationTests.java

@Test
public void testJobStop() throws Exception {

    RestTemplate template = new RestTemplate();
    ResponseEntity<String> result = template.exchange(serverRunning.getUrl()
            + "/jobs/infinite.json?jobParameters=timestamp=" + System.currentTimeMillis(), HttpMethod.POST,
            null, String.class);
    JsonWrapper wrapper = new JsonWrapper(result.getBody());
    // System.err.println(wrapper);
    assertNotNull(wrapper.get("jobExecution.resource"));
    assertNotNull(wrapper.get("jobExecution.status"));
    assertNotNull(wrapper.get("jobExecution.id"));

    template.exchange(wrapper.get("jobExecution.resource", String.class), HttpMethod.DELETE, null,
            String.class);

    // Poll for the completed job execution
    final String resource = wrapper.get("jobExecution.resource", String.class);
    Poller<JsonWrapper> poller = new DirectPoller<JsonWrapper>(100L);
    Future<JsonWrapper> poll = poller.poll(new Callable<JsonWrapper>() {
        public JsonWrapper call() throws Exception {
            RestTemplate template = new RestTemplate();
            ResponseEntity<String> result = template.exchange(resource, HttpMethod.GET, null, String.class);
            JsonWrapper wrapper = new JsonWrapper(result.getBody());
            // System.err.println(wrapper);
            BatchStatus status = wrapper.get("jobExecution.status", BatchStatus.class);
            return status.isGreaterThan(BatchStatus.STOPPING) ? wrapper : null;
        }/*from   ww  w  .j  a  va 2  s  . c om*/
    });
    JsonWrapper jobExecution = poll.get(500L, TimeUnit.MILLISECONDS);
    assertNotNull(jobExecution);

    BatchStatus status = jobExecution.get("jobExecution.status", BatchStatus.class);
    assertEquals(BatchStatus.STOPPED, status);

}

From source file:org.springframework.cloud.task.batch.partition.DeployerPartitionHandler.java

private boolean isComplete(BatchStatus status) {
    return status.equals(BatchStatus.COMPLETED) || status.isGreaterThan(BatchStatus.STARTED);
}