public RuntimeWorkUnitExecution(ModelNavigator<JSLJob> jobNavigator, TopLevelNameInstanceExecutionInfo topLevelNameInstanceExecutionInfo) { this.jobNavigator = jobNavigator; this.batchStatus = BatchStatus.STARTING; this.jobProperties = initTopLevelJobProperties(); this.jobContext = new JobContextImpl(this); this.topLevelNameInstanceExecutionInfo = topLevelNameInstanceExecutionInfo; }
public JobContextImpl(ModelNavigator<JSLJob> navigator, JSLProperties jslProperties) { this.navigator = navigator; this.id = navigator.getRootModelElement().getId(); this.batchStatus = BatchStatus.STARTING; this.properties = convertJSProperties(jslProperties); }
public BatchStatus getBatchStatus() { return this.jobContext.getBatchStatus(); }
private void setInJobContext(ExtendedBatchStatus flowBatchStatus, String exitStatus, String restartOn) { if (exitStatus != null) { jobContext.setExitStatus(exitStatus); } if (ExtendedBatchStatus.JSL_STOP.equals(flowBatchStatus)) { if (restartOn != null) { jobContext.setRestartOn(restartOn); } } }
public void prepareForExecution(JobContextImpl jobContext, String restartOn) { this.jobContext = jobContext; this.jobNavigator = jobContext.getNavigator(); jobContext.setExecutionId(executionId); jobContext.setInstanceId(jobInstance.getInstanceId()); this.restartOn = restartOn; operatorJobExecution.setJobContext(jobContext); }
protected void jslStop() { String restartOn = jobContext.getRestartOn(); logger.fine("Logging JSL stop(): exitStatus = " + jobContext.getExitStatus() + ", restartOn = " +restartOn ); batchStatusStopping(); jobStatusService.updateJobStatusFromJSLStop(jobInstanceId, restartOn); return; }
protected void endOfJob() { // 1. Execute the very last artifacts (jobListener) try { jobListenersAfterJob(); } catch (Throwable t) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); logger.warning("Error invoking jobListener.afterJob(). Stack trace: " + sw.toString()); batchStatusFailedFromException(); } // 2. transition to final batch status transitionToFinalBatchStatus(); // 3. default ExitStatus if necessary if (jobContext.getExitStatus() == null) { logger.fine("No job-level exitStatus set, defaulting to job batch Status = " + jobContext.getBatchStatus()); jobContext.setExitStatus(jobContext.getBatchStatus().name()); } // 4. persist statuses and end time data logger.fine("Job complete for job id=" + jobExecution.getJobInstance().getJobName() + ", executionId=" + jobExecution.getExecutionId() + ", batchStatus=" + jobContext.getBatchStatus() + ", exitStatus=" + jobContext.getExitStatus()); persistJobBatchAndExitStatus(); }
public static JSLJob buildFlowInSplitSubJob(JobContextImpl jobContext, Split split, Flow flow) { ObjectFactory jslFactory = new ObjectFactory(); JSLJob subJob = jslFactory.createJSLJob(); // Uses the true top-level job instance id, not an internal "subjob" id. String subJobId = generateSubJobId(jobContext.getInstanceId(), split.getId(), flow.getId()); subJob.setId(subJobId); //Copy all properties from parent JobContext to flow threads subJob.setProperties(CloneUtility.javaPropsTojslProperties(jobContext.getProperties())); //We don't need to do a deep copy here since each flow is already independent of all others, unlike in a partition //where one step instance can be executed with different properties on multiple threads. subJob.getExecutionElements().add(flow); jobContext.addTopLevelContextProperties(subJob.getProperties()); return subJob; }
private void persistJobBatchAndExitStatus() { BatchStatus batchStatus = jobContext.getBatchStatus(); // Take a current timestamp for last updated no matter what the status. long time = System.currentTimeMillis(); Timestamp timestamp = new Timestamp(time); jobExecution.setLastUpdateTime(timestamp); // Perhaps these should be coordinated in a tran but probably better still would be // rethinking the table design to let the database provide us consistently with a single update. jobStatusService.updateJobBatchStatus(jobInstanceId, batchStatus); jobStatusService.updateJobExecutionStatus(jobExecution.getInstanceId(), jobContext.getBatchStatus(), jobContext.getExitStatus()); if (batchStatus.equals(BatchStatus.COMPLETED) || batchStatus.equals(BatchStatus.STOPPED) || batchStatus.equals(BatchStatus.FAILED)) { jobExecution.setEndTime(timestamp); persistenceService.updateWithFinalExecutionStatusesAndTimestamps(jobExecution.getExecutionId(), batchStatus, jobContext.getExitStatus(), timestamp); } else { throw new IllegalStateException("Not expected to encounter batchStatus of " + batchStatus +" at this point. Aborting."); } }
public String getExitStatus() { return this.jobContext.getExitStatus(); }
protected void updateJobBatchStatus(BatchStatus batchStatus) { logger.fine("Setting job batch status to: " + batchStatus); jobContext.setBatchStatus(batchStatus); }
@Override public ExecutionStatus execute() { String deciderId = decision.getRef(); List<Property> propList = (decision.getProperties() == null) ? null : decision.getProperties().getPropertyList(); DeciderProxy deciderProxy; //Create a decider proxy and inject the associated properties /* Set the contexts associated with this scope */ //job context is always in scope //the parent controller will only pass one valid context to a decision controller //so two of these contexts will always be null InjectionReferences injectionRef = new InjectionReferences(jobExecution.getJobContext(), null, propList); try { deciderProxy = ProxyFactory.createDeciderProxy(deciderId,injectionRef ); } catch (ArtifactValidationException e) { throw new BatchContainerServiceException("Cannot create the decider [" + deciderId + "]", e); } String exitStatus = deciderProxy.decide(this.previousStepExecutions); logger.fine("Decider exiting and setting job-level exit status to " + exitStatus); //Set the value returned from the decider as the job context exit status. this.jobExecution.getJobContext().setExitStatus(exitStatus); return new ExecutionStatus(ExtendedBatchStatus.NORMAL_COMPLETION, exitStatus); }
protected void setContextProperties() { JSLJob jobModel = jobExecution.getJobNavigator().getRootModelElement(); JSLProperties jslProps = jobModel.getProperties(); if (jslProps != null) { Properties contextProps = jobContext.getProperties(); for (Property property : jslProps.getPropertyList()) { contextProps.setProperty(property.getName(), property.getValue()); } } }
public void prepareForExecution(JobContextImpl jobContext, String restartOn) { this.jobContext = jobContext; this.jobNavigator = jobContext.getNavigator(); jobContext.setExecutionId(executionId); jobContext.setInstanceId(jobInstance.getInstanceId()); this.restartOn = restartOn; operatorJobExecution.setJobContext(jobContext); }
protected void endOfJob() { // 1. Execute the very last artifacts (jobListener) try { jobListenersAfterJob(); } catch (Throwable t) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); logger.warning("Error invoking jobListener.afterJob(). Stack trace: " + sw.toString()); batchStatusFailedFromException(); } // 2. transition to final batch status transitionToFinalBatchStatus(); // 3. default ExitStatus if necessary if (jobContext.getExitStatus() == null) { logger.fine("No job-level exitStatus set, defaulting to job batch Status = " + jobContext.getBatchStatus()); jobContext.setExitStatus(jobContext.getBatchStatus().name()); } // 4. persist statuses and end time data logger.fine("Job complete for job id=" + jobExecution.getJobInstance().getJobName() + ", executionId=" + jobExecution.getExecutionId() + ", batchStatus=" + jobContext.getBatchStatus() + ", exitStatus=" + jobContext.getExitStatus()); persistJobBatchAndExitStatus(); }
private void setInJobContext(ExtendedBatchStatus flowBatchStatus, String exitStatus, String restartOn) { if (exitStatus != null) { jobContext.setExitStatus(exitStatus); } if (ExtendedBatchStatus.JSL_STOP.equals(flowBatchStatus)) { if (restartOn != null) { jobContext.setRestartOn(restartOn); } } }
protected void jslStop() { String restartOn = jobContext.getRestartOn(); logger.fine("Logging JSL stop(): exitStatus = " + jobContext.getExitStatus() + ", restartOn = " +restartOn ); batchStatusStopping(); jobStatusService.updateJobStatusFromJSLStop(jobInstanceId, restartOn); return; }
String subJobId = generateSubJobId(jobContext.getInstanceId(), step.getId(), partitionInstance); subJob.setId(subJobId); subJob.setProperties(CloneUtility.javaPropsTojslProperties(jobContext.getProperties())); jobContext.addTopLevelContextProperties(subJob.getProperties());
private void persistJobBatchAndExitStatus() { BatchStatus batchStatus = jobContext.getBatchStatus(); // Take a current timestamp for last updated no matter what the status. long time = System.currentTimeMillis(); Timestamp timestamp = new Timestamp(time); jobExecution.setLastUpdateTime(timestamp); // Perhaps these should be coordinated in a tran but probably better still would be // rethinking the table design to let the database provide us consistently with a single update. jobStatusService.updateJobBatchStatus(jobInstanceId, batchStatus); jobStatusService.updateJobExecutionStatus(jobExecution.getInstanceId(), jobContext.getBatchStatus(), jobContext.getExitStatus()); if (batchStatus.equals(BatchStatus.COMPLETED) || batchStatus.equals(BatchStatus.STOPPED) || batchStatus.equals(BatchStatus.FAILED)) { jobExecution.setEndTime(timestamp); persistenceService.updateWithFinalExecutionStatusesAndTimestamps(jobExecution.getExecutionId(), batchStatus, jobContext.getExitStatus(), timestamp); } else { throw new IllegalStateException("Not expected to encounter batchStatus of " + batchStatus +" at this point. Aborting."); } }
public String getExitStatus() { return this.jobContext.getExitStatus(); }