private void setContextProperties() { JSLProperties jslProps = step.getProperties(); if (jslProps != null) { for (Property property : jslProps.getPropertyList()) { Properties contextProps = stepContext.getProperties(); contextProps.setProperty(property.getName(), property.getValue()); } } // set up metrics stepContext.addMetric(MetricImpl.MetricType.READ_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.WRITE_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.READ_SKIP_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.PROCESS_SKIP_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.WRITE_SKIP_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.FILTER_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.COMMIT_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.ROLLBACK_COUNT, 0); ITransactionManagementService transMgr = ServicesManagerImpl.getInstance().getTransactionManagementService(); transactionManager = transMgr.getTransactionManager(stepContext); }
private void defaultExitStatusIfNecessary() { String stepExitStatus = stepContext.getExitStatus(); String processRetVal = stepContext.getBatchletProcessRetVal(); if (stepExitStatus != null) { logger.fine("Returning with user-set exit status: " + stepExitStatus); } else if (processRetVal != null) { logger.fine("Returning with exit status from batchlet.process(): " + processRetVal); stepContext.setExitStatus(processRetVal); } else { logger.fine("Returning with default exit status"); stepContext.setExitStatus(stepContext.getBatchStatus().name()); } }
@Override public Date getEndTime() { if (stepContext != null){ return this.stepContext.getEndTimeTS(); } else { if (endTime != null) { return new Date(endTime.getTime()); } else { return null; } } }
@Override public synchronized void stop() { // It is possible for stop() to be issued before process() if (BatchStatus.STARTING.equals(stepContext.getBatchStatus()) || BatchStatus.STARTED.equals(stepContext.getBatchStatus())) { stepContext.setBatchStatus(BatchStatus.STOPPING); if (batchletProxy != null) { batchletProxy.stop(); } } else { //TODO do we need to throw an error if the batchlet is already stopping/stopped //a stop gets issued twice } }
@Override public void updateStepExecution(long rootJobExecId, StepContextImpl stepContext) { long stepExecutionId = stepContext.getStepExecutionId(); String batchStatus = stepContext.getBatchStatus() == null ? BatchStatus.STARTING.name() : stepContext.getBatchStatus().name(); String exitStatus = stepContext.getExitStatus(); String stepName = stepContext.getStepName(); long filterCount = 0; long writeSkipCount = 0; Timestamp startTime = stepContext.getStartTimeTS(); Timestamp endTime = stepContext.getEndTimeTS(); Metric[] metrics = stepContext.getMetrics(); for (int i = 0; i < metrics.length; i++) { if (metrics[i].getType().equals(MetricImpl.MetricType.READ_COUNT)) { Serializable persistentData = stepContext.getPersistentUserData();
long writeSkipCount) { long stepExecutionId = stepContext.getInternalStepExecutionId(); String batchStatus = stepContext.getBatchStatus() == null ? BatchStatus.STARTING.name() : stepContext.getBatchStatus().name(); String exitStatus = stepContext.getExitStatus(); String stepName = stepContext.getStepName(); if (logger.isLoggable(Level.FINE)) { logger.fine("batchStatus: " + batchStatus + " | stepName: " + stepName + " | stepExecID: " + stepContext.getStepExecutionId()); Timestamp startTime = stepContext.getStartTimeTS(); Timestamp endTime = stepContext.getEndTimeTS(); Serializable persistentData = stepContext.getPersistentUserData();
public RuntimeStepExecution(StepThreadExecutionEntity stepThreadExecution) { this.stepName = stepThreadExecution.getStepName(); this.batchStatus = stepThreadExecution.getBatchStatus(); this.exitStatus = stepThreadExecution.getExitStatus(); this.stepCtx = new StepContextImpl(this); this.startTime = stepThreadExecution.getStartTime(); this.endTime = stepThreadExecution.getEndTime(); this.internalStepThreadExecutionId = stepThreadExecution.getStepExecutionId(); this.topLevelStepExecutionId = stepThreadExecution.getTopLevelStepExecution().getStepExecutionId(); this.persistentUserDataObject = initializePersistentUserDataObject(stepThreadExecution.getPersistentUserDataBytes()); //Adding the metrics which we want to be rolled back this.tranCoordinatedMetricTypes.add(MetricImpl.MetricType.COMMIT_COUNT); this.tranCoordinatedMetricTypes.add(MetricImpl.MetricType.READ_COUNT); this.tranCoordinatedMetricTypes.add(MetricImpl.MetricType.FILTER_COUNT); this.tranCoordinatedMetricTypes.add(MetricImpl.MetricType.WRITE_COUNT); }
writeListenerProxy.afterWrite(theChunk); stepContext.getMetric(MetricImpl.MetricType.WRITE_COUNT).incValueBy(theChunk.size()); } catch (Exception e) { this.stepContext.setException(e); for (ItemWriteListenerProxy writeListenerProxy : itemWriteListeners) { writeListenerProxy.onWriteError(theChunk, e); status.setRollback(true); stepContext.getMetric(MetricImpl.MetricType.ROLLBACK_COUNT).incValue(); stepContext.getMetric(MetricImpl.MetricType.WRITE_SKIP_COUNT).incValueBy(1); } else { throw new BatchContainerRuntimeException(e); stepContext.getMetric(MetricImpl.MetricType.WRITE_SKIP_COUNT).incValueBy(1); } else if (retryWriteException(e, theChunk)) { if (!retryHandler.isRollbackException(e)) { status.setRollback(true); stepContext.getMetric(MetricImpl.MetricType.ROLLBACK_COUNT).incValue();
protected void persistExitStatusAndEndTimestamp() { stepStatus.setExitStatus(stepContext.getExitStatus()); _jobStatusService.updateStepStatus(stepStatus.getStepExecutionId(), stepStatus); // set the end time metric before flushing long time = System.currentTimeMillis(); Timestamp endTS = new Timestamp(time); stepContext.setEndTime(endTS); _persistenceManagementService.updateStepExecution(rootJobExecutionId, stepContext); }
@Override public BatchStatus getBatchStatus() { if (stepContext != null) { return this.stepContext.getBatchStatus(); } else { return batchStatus; } }
private void updateNormalMetrics(int writeCount) { int readCount = currentChunkStatus.getItemsTouchedInCurrentChunk(); int filterCount = readCount - writeCount; if (readCount < 0 || filterCount < 0 || writeCount < 0) { throw new IllegalStateException("Somehow one of the metrics was zero. Read count: " + readCount + ", Filter count: " + filterCount + ", Write count: " + writeCount); } stepContext.getMetric(MetricImpl.MetricType.COMMIT_COUNT).incValue(); stepContext.getMetric(MetricImpl.MetricType.READ_COUNT).incValueBy(readCount); stepContext.getMetric(MetricImpl.MetricType.FILTER_COUNT).incValueBy(filterCount); stepContext.getMetric(MetricImpl.MetricType.WRITE_COUNT).incValueBy(writeCount); }
theStatus.setRollback(true); stepContext.getMetric(MetricImpl.MetricType.ROLLBACK_COUNT).incValue(); break; theStatus.setRollback(true); stepContext.getMetric(MetricImpl.MetricType.ROLLBACK_COUNT).incValue(); break; if (stepContext.getBatchStatus().equals(BatchStatus.STOPPING)) { theStatus.setFinished(true);
private void setContextProperties() { JSLProperties jslProps = step.getProperties(); if (jslProps != null) { for (Property property : jslProps.getPropertyList()) { Properties contextProps = stepContext.getJSLProperties(); contextProps.setProperty(property.getName(), property.getValue()); } } // set up metrics stepContext.addMetric(MetricImpl.MetricType.READ_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.WRITE_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.READ_SKIP_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.PROCESS_SKIP_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.WRITE_SKIP_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.FILTER_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.COMMIT_COUNT, 0); stepContext.addMetric(MetricImpl.MetricType.ROLLBACK_COUNT, 0); ITransactionManagementService transMgr = ServicesManagerImpl.getInstance().getTransactionManagementService(); transactionManager = transMgr.getTransactionManager(stepContext); }
@Override public Serializable getPersistentUserData() { if (stepContext != null){ return this.stepContext.getPersistentUserData(); } else { return this.persistentUserData; } }
@Override public Metric[] getMetrics() { if (stepContext != null) { return stepContext.getMetrics(); } else { Metric[] metrics = new MetricImpl[8]; metrics[0] = new MetricImpl(MetricImpl.MetricType.READ_COUNT, readCount); metrics[1] = new MetricImpl(MetricImpl.MetricType.WRITE_COUNT, writeCount); metrics[2] = new MetricImpl(MetricImpl.MetricType.COMMIT_COUNT, commitCount); metrics[3] = new MetricImpl(MetricImpl.MetricType.ROLLBACK_COUNT, rollbackCount); metrics[4] = new MetricImpl(MetricImpl.MetricType.READ_SKIP_COUNT, readSkipCount); metrics[5] = new MetricImpl(MetricImpl.MetricType.PROCESS_SKIP_COUNT, processSkipCount); metrics[6] = new MetricImpl(MetricImpl.MetricType.FILTER_COUNT, filterCount); metrics[7] = new MetricImpl(MetricImpl.MetricType.WRITE_SKIP_COUNT, writeSkipCount); return metrics; } }
@Override public String getExitStatus() { if (stepContext != null){ return this.stepContext.getExitStatus(); } else { return exitStatus; } }
/** * Note we can rely on the StepContext properties already having been set at this point. * * @return global transaction timeout defined in step properties. default */ private int initStepTransactionTimeout() { logger.entering(sourceClass, "initStepTransactionTimeout"); Properties p = stepContext.getProperties(); int timeout = DEFAULT_TRAN_TIMEOUT_SECONDS; // default as per spec. if (p != null && !p.isEmpty()) { String propertyTimeOut = p.getProperty("javax.transaction.global.timeout"); if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "javax.transaction.global.timeout = {0}", propertyTimeOut==null ? "<null>" : propertyTimeOut); } if (propertyTimeOut != null && !propertyTimeOut.isEmpty()) { timeout = Integer.parseInt(propertyTimeOut, 10); } } logger.exiting(sourceClass, "initStepTransactionTimeout", timeout); return timeout; }
@Override public StepExecutionImpl createStepExecution(long rootJobExecId, StepContextImpl stepContext) { StepExecutionImpl stepExecution = null; String batchStatus = stepContext.getBatchStatus() == null ? BatchStatus.STARTING.name() : stepContext.getBatchStatus().name(); String exitStatus = stepContext.getExitStatus(); String stepName = stepContext.getStepName(); if (logger.isLoggable(Level.FINE)) { logger.fine("batchStatus: " + batchStatus + " | stepName: " + stepName); long filterCount = 0; long writeSkipCount = 0; Timestamp startTime = stepContext.getStartTimeTS(); Timestamp endTime = stepContext.getEndTimeTS(); Metric[] metrics = stepContext.getMetrics(); for (int i = 0; i < metrics.length; i++) { if (metrics[i].getType().equals(MetricImpl.MetricType.READ_COUNT)) { Serializable persistentData = stepContext.getPersistentUserData();
private IExecutionElementController getNextElementController() { IExecutionElementController elementController =null; if (currentExecutionElement instanceof Decision) { Decision decision = (Decision)currentExecutionElement; elementController = ExecutionElementControllerFactory.getDecisionController(jobExecution, decision); DecisionControllerImpl decisionController = (DecisionControllerImpl)elementController; decisionController.setPreviousStepExecutions(previousExecutionElement, previousElementController); } else if (currentExecutionElement instanceof Flow) { Flow flow = (Flow)currentExecutionElement; elementController = ExecutionElementControllerFactory.getFlowController(jobExecution, flow, rootJobExecutionId); } else if (currentExecutionElement instanceof Split) { Split split = (Split)currentExecutionElement; elementController = ExecutionElementControllerFactory.getSplitController(jobExecution, split, rootJobExecutionId); } else if (currentExecutionElement instanceof Step) { Step step = (Step)currentExecutionElement; StepContextImpl stepContext = new StepContextImpl(step.getId()); elementController = ExecutionElementControllerFactory.getStepController(jobExecution, step, stepContext, rootJobExecutionId, analyzerQueue); } logger.fine("Next execution element controller = " + elementController); return elementController; }
stepContext.getMetric(MetricImpl.MetricType.READ_COUNT).incValue(); stepContext.setException(e); for (ItemReadListenerProxy readListenerProxy : itemReadListeners) { readListenerProxy.onReadError(e); rollbackRetry = true; stepContext.getMetric(MetricImpl.MetricType.ROLLBACK_COUNT).incValue(); stepContext.getMetric(MetricImpl.MetricType.READ_SKIP_COUNT).incValue(); stepContext.getMetric(MetricImpl.MetricType.READ_SKIP_COUNT).incValue(); status.setRollback(true); stepContext.getMetric(MetricImpl.MetricType.ROLLBACK_COUNT).incValue();