Package org.springframework.batch.core

Examples of org.springframework.batch.core.JobExecution


      mainJob.afterPropertiesSet();
      JobFactory jobFactory = new ReferenceJobFactory(mainJob);
      jobRegistry.register(jobFactory);
      logger.info("registered job: " + mainJob.getName());
      JobParameters mainJobParameters = new JobParameters(mainJobParams);
      JobExecution mainJobExecution =
            jobLauncher.run(mainJob, mainJobParameters);
      logger.info("launched main job: " + mainJob.getName());
      return mainJobExecution.getId();
   }
View Full Code Here


    * @param jobExecutionId
    * @return job status
    * @throws NoSuchJobException
    */
   public TaskRead getJobExecutionStatus(long jobExecutionId) {
      JobExecution jobExecution = jobExplorer.getJobExecution(jobExecutionId);
      if (jobExecution == null) {
         throw BddException.NOT_FOUND("Task", Long.toString(jobExecutionId));
      }

      TaskRead jobStatus = new TaskRead();
      jobStatus.setId(jobExecutionId);

      //identify VHM jobs
      String jobName = jobExecution.getJobInstance().getJobName();
      if (jobName.equals(JobConstants.SET_MANUAL_ELASTICITY_JOB_NAME)) {
         jobStatus.setType(Type.VHM);
      } else if (jobName.equals(JobConstants.DELETE_CLUSTER_JOB_NAME)) {
         jobStatus.setType(Type.DELETE);
      }

      JobParameters jobParameters =
            jobExecution.getJobInstance().getJobParameters();
      String clusterName =
            jobParameters.getString(JobConstants.CLUSTER_NAME_JOB_PARAM);
      jobStatus.setTarget(clusterName);
      long subJobEnabled = jobParameters.getLong(JobConstants.SUB_JOB_ENABLED);
      if (subJobEnabled != 1) {
         jobStatus.setProgress(jobExecutionStatusHolder
               .getCurrentProgress(jobExecutionId));
      } else {
         jobStatus.setProgress(mainJobExecutionStatusHolder
               .getCurrentProgress(jobExecutionId));
      }
      Status status = null;
      switch (jobExecution.getStatus()) {
      case ABANDONED:
         status = Status.ABANDONED;
         break;
      case COMPLETED:
         status = Status.COMPLETED;
         break;
      case FAILED:
         status = Status.FAILED;
         break;
      case STARTED:
         status = Status.STARTED;
         break;
      case STARTING:
         status = Status.STARTING;
         break;
      case STOPPED:
         status = Status.STOPPED;
         break;
      case STOPPING:
         status = Status.STOPPING;
         break;
      case UNKNOWN:
      default:
         status = Status.UNKNOWN;
      }
      jobStatus.setStatus(status);
      if (subJobEnabled == 1) {
         List<NodeOperationStatus> succeedNodes =
               (ArrayList<NodeOperationStatus>) jobExecution.getExecutionContext()
                     .get(JobConstants.SUB_JOB_NODES_SUCCEED);
         List<NodeOperationStatus> failNodes =
               (ArrayList<NodeOperationStatus>) jobExecution.getExecutionContext()
                     .get(JobConstants.SUB_JOB_NODES_FAIL);
         if (succeedNodes != null) {
            jobStatus.setSucceedNodes(convert(succeedNodes));
         }
         if (failNodes != null) {
            jobStatus.setFailNodes(convert(failNodes));
         }
      }
      if (status.equals(Status.FAILED) && subJobEnabled != 1) {
         String workDir =
               TrackableTasklet.getFromJobExecutionContext(
                     jobExecution.getExecutionContext(),
                     JobConstants.CURRENT_COMMAND_WORK_DIR, String.class);
         String errorMessage =
               TrackableTasklet.getFromJobExecutionContext(
                     jobExecution.getExecutionContext(),
                     JobConstants.CURRENT_ERROR_MESSAGE, String.class);
         jobStatus.setErrorMessage(errorMessage);
         jobStatus.setWorkDir(workDir);
         logger.error("mark task as failed: " + errorMessage);
      }
View Full Code Here

   }

   @Override
   public void beforeStep(StepExecution se) {
      logger.info("step started: " + se.getStepName());
      JobExecution je = se.getJobExecution();
      AbstractJob job = null;
      try {
         job =
               (AbstractJob) jobRegistry.getJob(je.getJobInstance()
                     .getJobName());
      } catch (NoSuchJobException ex) {
         throw BddException.INTERNAL(ex, "Illegal state.");
      }

      Collection<String> stepNames = job.getStepNames();

      int steps = stepNames.size();
      double done = 0;
      for (String stepName : stepNames) {
         ExecutionContext jec = se.getJobExecution().getExecutionContext();
         Boolean completed = (Boolean) jec.get(stepName + ".COMPLETED");

         if (completed != null && completed) {
            ++done;
         }
      }
      double progress = done / steps;
      jobExecutionStatusHolder.setCurrentStepWeight(je.getId(), 1.0 / steps);
      jobExecutionStatusHolder.setCurrentProgressBeforeStepStart(je.getId(),
            progress);
   }
View Full Code Here

         jobParameters =
               jobParametersExtractor.getJobParameters(job, stepExecution);
         executionContext.put(subJobParametersKey, jobParameters);
      }

      JobExecution subJobExecution = jobLauncher.run(job, jobParameters);
      //Wait for job completion
      while (true) {
         if (subJobExecution.getStatus().isRunning()) {
            double subJobProgress =
                  jobExecutionStatusHolder.getCurrentProgress(subJobExecution
                        .getId());
            mainJobExecutionStatusHolder.setCurrentStepProgress(stepExecution
                  .getJobExecution().getId(), subJobProgress);
            Thread.sleep(3000);
         } else {
            break;
         }
      }

      String nodeName = null;
      if (subJobExecution.getJobInstance().getJobParameters().getParameters()
            .containsKey(JobConstants.SUB_JOB_NODE_NAME)) {
         nodeName =
               subJobExecution.getJobInstance().getJobParameters()
                     .getString(JobConstants.SUB_JOB_NODE_NAME);
      } else {
         String stepName = stepExecution.getStepName();
         nodeName = stepName.substring(stepName.lastIndexOf("-") + 1);
      }
View Full Code Here

    Assert.isInstanceOf(JobLaunchRequest.class, payload, "The payload must be of type JobLaunchRequest.");

    final JobLaunchRequest jobLaunchRequest = (JobLaunchRequest) payload;

    final JobExecution jobExecution;

    try {
      jobExecution = this.jobLaunchingMessageHandler.launch(jobLaunchRequest);
    } catch (JobExecutionException e) {
      throw new MessageHandlingException(requestMessage, e);
View Full Code Here

    Collection<StepExecutionInfo> result = new ArrayList<StepExecutionInfo>();
    try {
      for (StepExecution stepExecution : jobService.getStepExecutions(jobExecutionId)) {
        result.add(new StepExecutionInfo(stepExecution, timeZone));
      }
      JobExecution jobExecution = jobService.getJobExecution(jobExecutionId);
      model.addAttribute(new JobExecutionInfo(jobExecution, timeZone));
    }
    catch (NoSuchJobExecutionException e) {
      errors.reject("no.such.job.execution", new Object[] { jobExecutionId }, "There is no such job execution ("
          + jobExecutionId + ")");
View Full Code Here

    return count;

  }

  public double getLatestDuration() {
    JobExecution jobExecution = getLatestJobExecution(jobName);
    JobExecutionHistory history = new JobExecutionHistory(jobName);
    history.append(jobExecution);
    return history.getDuration().getMean();
  }
View Full Code Here

    JobExecutionHistory history = computeHistory(jobName);
    return history.getDuration().getMax();
  }

  public Date getLatestStartTime() {
    JobExecution jobExecution = getLatestJobExecution(jobName);
    return jobExecution==null ? null : jobExecution.getStartTime();
  }
View Full Code Here

    JobExecution jobExecution = getLatestJobExecution(jobName);
    return jobExecution==null ? null : jobExecution.getStartTime();
  }

  public Date getLatestEndTime() {
    JobExecution jobExecution = getLatestJobExecution(jobName);
    return jobExecution==null ? null : jobExecution.getEndTime();
  }
View Full Code Here

    JobExecution jobExecution = getLatestJobExecution(jobName);
    return jobExecution==null ? null : jobExecution.getEndTime();
  }

  public String getLatestExitCode() {
    JobExecution jobExecution = getLatestJobExecution(jobName);
    return jobExecution==null ? "NONE" : jobExecution.getExitStatus().getExitCode();
  }
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.JobExecution

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.