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

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

Introduction

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

Prototype

public Long getJobExecutionId() 

Source Link

Document

Accessor for the job execution id.

Usage

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

@Override
public void updateStepExecution(StepExecution stepExecution) {

    Assert.notNull(stepExecution.getJobExecutionId());

    //If the job execution data doesn't exist, can't update   
    if (!executionsByJobExecutionId.containsKey(stepExecution.getJobExecutionId())) {
        return;//from w w  w .  j  av  a  2s.c  om
    }

    Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
    Assert.notNull(executions, "step executions for given job execution are expected to be already saved");

    final StepExecution persistedExecution = executionsByStepExecutionId.get(stepExecution.getId());
    Assert.notNull(persistedExecution, "step execution is expected to be already saved");

    synchronized (stepExecution) {
        if (!persistedExecution.getVersion().equals(stepExecution.getVersion())) {
            throw new OptimisticLockingFailureException("Attempt to update step execution id="
                    + stepExecution.getId() + " with wrong version (" + stepExecution.getVersion()
                    + "), where current version is " + persistedExecution.getVersion());
        }

        stepExecution.incrementVersion();
        StepExecution copy = new StepExecution(stepExecution.getStepName(), stepExecution.getJobExecution());
        copy(stepExecution, copy);
        executions.put(stepExecution.getId(), copy);
        executionsByStepExecutionId.put(stepExecution.getId(), copy);
    }
}

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);
    }/*from  w ww  .ja  v  a2s .  c  om*/

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

}

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/*w ww . j  av a  2s .c  o m*/
 */
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());
    }

}

From source file:org.springframework.batch.core.job.SimpleStepHandler.java

/**
 * Detect whether a step execution belongs to this job execution.
 * @param jobExecution the current job execution
 * @param stepExecution an existing step execution
 * @return true if the {@link org.springframework.batch.core.StepExecution} is part of the {@link org.springframework.batch.core.JobExecution}
 *///from   www  . j ava  2s .c o  m
private boolean stepExecutionPartOfExistingJobExecution(JobExecution jobExecution,
        StepExecution stepExecution) {
    return stepExecution != null && stepExecution.getJobExecutionId() != null
            && stepExecution.getJobExecutionId().equals(jobExecution.getId());
}

From source file:org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.java

private List<Object[]> buildStepExecutionParameters(StepExecution stepExecution) {
    Assert.isNull(stepExecution.getId(),
            "to-be-saved (not updated) StepExecution can't already have an id assigned");
    Assert.isNull(stepExecution.getVersion(),
            "to-be-saved (not updated) StepExecution can't already have a version assigned");
    validateStepExecution(stepExecution);
    stepExecution.setId(stepExecutionIncrementer.nextLongValue());
    stepExecution.incrementVersion(); //Should be 0
    List<Object[]> parameters = new ArrayList<Object[]>();
    String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription());
    Object[] parameterValues = new Object[] { stepExecution.getId(), stepExecution.getVersion(),
            stepExecution.getStepName(), stepExecution.getJobExecutionId(), stepExecution.getStartTime(),
            stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(),
            stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(),
            stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(),
            stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(),
            stepExecution.getRollbackCount(), stepExecution.getLastUpdated() };
    Integer[] parameterTypes = new Integer[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT,
            Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
            Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
            Types.INTEGER, Types.TIMESTAMP };
    parameters.add(0, Arrays.copyOf(parameterValues, parameterValues.length));
    parameters.add(1, Arrays.copyOf(parameterTypes, parameterTypes.length));
    return parameters;
}

From source file:org.springframework.batch.core.repository.support.SimpleJobRepository.java

private void validateStepExecution(StepExecution stepExecution) {
    Assert.notNull(stepExecution, "StepExecution cannot be null.");
    Assert.notNull(stepExecution.getStepName(), "StepExecution's step name cannot be null.");
    Assert.notNull(stepExecution.getJobExecutionId(), "StepExecution must belong to persisted JobExecution");
}

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanTests.java

private void assertStepExecutionsAreEqual(StepExecution expected, StepExecution actual) {
    assertEquals(expected.getId(), actual.getId());
    assertEquals(expected.getStartTime(), actual.getStartTime());
    assertEquals(expected.getEndTime(), actual.getEndTime());
    assertEquals(expected.getSkipCount(), actual.getSkipCount());
    assertEquals(expected.getCommitCount(), actual.getCommitCount());
    assertEquals(expected.getReadCount(), actual.getReadCount());
    assertEquals(expected.getWriteCount(), actual.getWriteCount());
    assertEquals(expected.getFilterCount(), actual.getFilterCount());
    assertEquals(expected.getWriteSkipCount(), actual.getWriteSkipCount());
    assertEquals(expected.getReadSkipCount(), actual.getReadSkipCount());
    assertEquals(expected.getProcessSkipCount(), actual.getProcessSkipCount());
    assertEquals(expected.getRollbackCount(), actual.getRollbackCount());
    assertEquals(expected.getExitStatus(), actual.getExitStatus());
    assertEquals(expected.getLastUpdated(), actual.getLastUpdated());
    assertEquals(expected.getExitStatus(), actual.getExitStatus());
    assertEquals(expected.getJobExecutionId(), actual.getJobExecutionId());
}

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

private Collection<StepExecution> pollReplies(final StepExecution masterStepExecution,
        final Set<StepExecution> executed, final Set<StepExecution> candidates, final int size)
        throws Exception {

    final Collection<StepExecution> result = new ArrayList<>(executed.size());

    Callable<Collection<StepExecution>> callback = new Callable<Collection<StepExecution>>() {
        @Override//from   w  w  w  .  j  a va2  s  .co  m
        public Collection<StepExecution> call() throws Exception {
            Set<StepExecution> newExecuted = new HashSet<>();

            for (StepExecution curStepExecution : executed) {
                if (!result.contains(curStepExecution)) {
                    StepExecution partitionStepExecution = jobExplorer.getStepExecution(
                            masterStepExecution.getJobExecutionId(), curStepExecution.getId());

                    if (isComplete(partitionStepExecution.getStatus())) {
                        result.add(partitionStepExecution);
                        currentWorkers--;

                        if (!candidates.isEmpty()) {

                            launchWorkers(candidates, newExecuted);
                            candidates.removeAll(newExecuted);
                        }
                    }
                }
            }

            executed.addAll(newExecuted);

            if (result.size() == size) {
                return result;
            } else {
                return null;
            }
        }
    };

    Poller<Collection<StepExecution>> poller = new DirectPoller<>(this.pollInterval);
    Future<Collection<StepExecution>> resultsFuture = poller.poll(callback);

    if (timeout >= 0) {
        return resultsFuture.get(timeout, TimeUnit.MILLISECONDS);
    } else {
        return resultsFuture.get();
    }
}

From source file:org.springframework.yarn.batch.am.AbstractBatchAppmaster.java

@Override
public ContainerLaunchContext preLaunch(Container container, ContainerLaunchContext context) {
    AppmasterService service = getAppmasterService();

    if (log.isDebugEnabled()) {
        log.debug("Intercept launch context: " + context);
    }/*from  www .  jav a2  s  . com*/

    StepExecution stepExecution = containerToStepMap.get(container.getId());
    String jobName = remoteStepNames.get(stepExecution);

    if (service != null) {
        int port = service.getPort();
        String address = service.getHost();
        Map<String, String> env = new HashMap<String, String>(context.getEnvironment());
        env.put(YarnSystemConstants.FS_ADDRESS,
                getConfiguration().get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY));
        env.put(YarnSystemConstants.AMSERVICE_PORT, Integer.toString(port));
        env.put(YarnSystemConstants.AMSERVICE_HOST, address);
        env.put(YarnSystemConstants.AMSERVICE_BATCH_STEPNAME, jobName);
        env.put(YarnSystemConstants.AMSERVICE_BATCH_STEPNAME, jobName);
        env.put(YarnSystemConstants.AMSERVICE_BATCH_STEPEXECUTIONNAME, stepExecution.getStepName());
        env.put(YarnSystemConstants.AMSERVICE_BATCH_JOBEXECUTIONID,
                Long.toString(stepExecution.getJobExecutionId()));
        env.put(YarnSystemConstants.AMSERVICE_BATCH_STEPEXECUTIONID, Long.toString(stepExecution.getId()));
        context.setEnvironment(env);
        return context;
    } else {
        return context;
    }
}