Refine search
@Override public void beforeJob(JobExecution jobExecution) { ExecutionContext jobContext = jobExecution.getExecutionContext(); for (Map.Entry<String, Object> entry : jobExecutionContext.entrySet()) { jobContext.put(entry.getKey(), entry.getValue()); } } } });
private void copy(final StepExecution source, final StepExecution target) { target.setVersion(source.getVersion()); target.setWriteCount(source.getWriteCount()); target.setFilterCount(source.getFilterCount()); target.setCommitCount(source.getCommitCount()); target.setExecutionContext(new ExecutionContext(source.getExecutionContext())); }
@BeforeStep public void createOutputNameFromInput(StepExecution stepExecution) { ExecutionContext executionContext = stepExecution.getExecutionContext(); String inputName = stepExecution.getStepName().replace(":", "-"); if (executionContext.containsKey(inputKeyName)) { inputName = executionContext.getString(inputKeyName); } if (!executionContext.containsKey(outputKeyName)) { executionContext.putString(outputKeyName, path + FilenameUtils.getBaseName(inputName) + ".csv"); } }
@Override public void open(ExecutionContext executionContext) { if (executionContext.containsKey(TOTAL_AMOUNT_KEY)) { this.totalPrice = (BigDecimal) executionContext.get(TOTAL_AMOUNT_KEY); } else { // // Fresh run. Disregard old state. // this.totalPrice = BigDecimal.ZERO; } }
/** * Typesafe Getter for the String represented by the provided key with * default value to return if key is not represented. * * @param key The key to get a value for * @param defaultString Default to return if key is not represented * @return The <code>String</code> value if key is represented, specified * default otherwise */ public String getString(String key, String defaultString) { if (!containsKey(key)) { return defaultString; } return getString(key); }
/** * Typesafe Getter for the Long represented by the provided key with default * value to return if key is not represented. * * @param key The key to get a value for * @param defaultLong Default to return if key is not represented * @return The <code>long</code> value if key is represented, specified * default otherwise */ public long getLong(String key, long defaultLong) { if (!containsKey(key)) { return defaultLong; } return getLong(key); }
/** * CONDITION: keys = {key, key2}. Only {key} exists in the ExecutionContext. * * EXPECTED: key is promoted. key2 is not. */ @Test public void promoteEntriesKeyNotFound() throws Exception { ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener(); JobExecution jobExecution = new JobExecution(1L); StepExecution stepExecution = jobExecution.createStepExecution("step1"); stepExecution.setExitStatus(ExitStatus.COMPLETED); Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty"); Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty"); stepExecution.getExecutionContext().putString(key, value); listener.setKeys(new String[] { key, key2 }); listener.afterPropertiesSet(); listener.afterStep(stepExecution); assertEquals(value, jobExecution.getExecutionContext().getString(key)); assertFalse(jobExecution.getExecutionContext().containsKey(key2)); }
private void start(String foo) { StepSynchronizationManager.close(); stepExecution = new StepExecution("foo", new JobExecution(11L), 123L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("foo", foo); executionContext.put("parent", bar); stepExecution.setExecutionContext(executionContext); StepSynchronizationManager.register(stepExecution); beanCount = beanFactory.getBeanDefinitionCount(); }
@Override public void execute(StepExecution stepExecution) throws JobInterruptedException { if (!stepExecution.getJobExecution().getExecutionContext().containsKey("STOPPED")) { stepExecution.getJobExecution().getExecutionContext().put("STOPPED", true); stepExecution.setStatus(BatchStatus.STOPPED); jobRepository.update(stepExecution); } else { fail("The Job should have stopped by now"); } } }), "end0"));
@Test public void testSaveUpdate() throws Exception { StepExecution stepExecution = new StepExecution("step", new JobExecution(11L)); stepExecution.setId(123L); stepExecution.getExecutionContext().put("foo", "bar"); dao.saveExecutionContext(stepExecution); ExecutionContext executionContext = dao.getExecutionContext(stepExecution); assertEquals("bar", executionContext.get("foo")); }
@Test public void testSimpleProperty() throws Exception { StepExecution stepExecution = new StepExecution("step", new JobExecution(0L), 123L); ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.put("foo", "bar"); StepSynchronizationManager.register(stepExecution); assertEquals("bar", simple.getName()); }
/** * @return a map containing the items from the job {@link ExecutionContext} */ public Map<String, Object> getJobExecutionContext() { Map<String, Object> result = new HashMap<>(); for (Entry<String, Object> entry : stepExecution.getJobExecution().getExecutionContext().entrySet()) { result.put(entry.getKey(), entry.getValue()); } return Collections.unmodifiableMap(result); }
@Before public void start() { JobSynchronizationManager.close(); jobExecution = new JobExecution(123L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("foo", "bar"); jobExecution.setExecutionContext(executionContext); JobSynchronizationManager.register(jobExecution); beanCount = beanFactory.getBeanDefinitionCount(); }
@Override public void beforeStep(StepExecution stepExecution) { this.jobName = stepExecution.getJobExecution().getJobInstance().getJobName().trim(); this.stepName = (String) stepExecution.getJobExecution().getExecutionContext().get("stepName"); this.stepExecution = stepExecution; stepExecution.getJobExecution().getExecutionContext().remove("stepName"); }
@Test public void testNormalUsage() { context.putString("1", "testString1"); context.putString("2", "testString2"); context.putLong("3", 3); context.putDouble("4", 4.4); context.putInt("5", 5); assertEquals("testString1", context.getString("1")); assertEquals("testString2", context.getString("2")); assertEquals("defaultString", context.getString("55", "defaultString")); assertEquals(4.4, context.getDouble("4"), 0); assertEquals(5.5, context.getDouble("55", 5.5), 0); assertEquals(3, context.getLong("3")); assertEquals(5, context.getLong("55", 5)); assertEquals(5, context.getInt("5")); assertEquals(6, context.getInt("55", 6)); }
@Test public void testExecutionContext() throws Exception { assertNotNull(execution.getExecutionContext()); ExecutionContext context = new ExecutionContext(); context.putString("foo", "bar"); execution.setExecutionContext(context); assertEquals("bar", execution.getExecutionContext().getString("foo")); }
@Test public void testDirectlyInjectedItemStream() throws Exception { step.setStreams(new ItemStream[] { new ItemStreamSupport() { @Override public void update(ExecutionContext executionContext) { super.update(executionContext); executionContext.putString("foo", "bar"); } } }); JobExecution jobExecution = new JobExecution(jobInstance, jobParameters); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); assertEquals(false, stepExecution.getExecutionContext().containsKey("foo")); step.execute(stepExecution); assertEquals("bar", stepExecution.getExecutionContext().getString("foo")); }
@Override protected State nextState(String stateName, FlowExecutionStatus status, StepExecution stepExecution) throws FlowExecutionException { State nextState = findState(stateName, status, stepExecution); if(stepExecution != null) { ExecutionContext executionContext = stepExecution.getJobExecution().getExecutionContext(); if(executionContext.containsKey("batch.stoppedStep")) { String stepName = executionContext.getString("batch.stoppedStep"); if(stateName.endsWith(stepName)) { if(nextState != null && executionContext.containsKey("batch.restartStep") && StringUtils.hasText(executionContext.getString("batch.restartStep"))) { nextState = findState(stateName, new FlowExecutionStatus(status.getName() + ".RESTART"), stepExecution); } } } } return nextState; }
private Map<String, ExecutionContext> getContexts(StepExecution stepExecution, int gridSize) { ExecutionContext context = stepExecution.getExecutionContext(); String key = SimpleStepExecutionSplitter.class.getSimpleName() + ".GRID_SIZE"; int splitSize = (int) context.getLong(key, gridSize); context.putLong(key, splitSize); if (context.isDirty()) { result.put(name, new ExecutionContext());
protected boolean isFlowContinued(State state, FlowExecutionStatus status, StepExecution stepExecution) { boolean continued = true; continued = state != null && status!=FlowExecutionStatus.STOPPED; if(stepExecution != null) { Boolean reRun = (Boolean) stepExecution.getExecutionContext().get("batch.restart"); Boolean executed = (Boolean) stepExecution.getExecutionContext().get("batch.executed"); if((executed == null || !executed) && reRun != null && reRun && status == FlowExecutionStatus.STOPPED && !state.getName().endsWith(stepExecution.getStepName()) ) { continued = true; } } return continued; }