org.springframework.batch.core.JobParameter Java Examples
The following examples show how to use
org.springframework.batch.core.JobParameter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobCommandTests.java From spring-cloud-dataflow with Apache License 2.0 | 9 votes |
private static long createSampleJob(String jobName, int jobExecutionCount) { JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters()); jobInstances.add(instance); TaskExecution taskExecution = dao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null); Map<String, JobParameter> jobParameterMap = new HashMap<>(); jobParameterMap.put("foo", new JobParameter("FOO", true)); jobParameterMap.put("bar", new JobParameter("BAR", false)); JobParameters jobParameters = new JobParameters(jobParameterMap); JobExecution jobExecution; for (int i = 0; i < jobExecutionCount; i++) { jobExecution = jobRepository.createJobExecution(instance, jobParameters, null); taskBatchDao.saveRelationship(taskExecution, jobExecution); StepExecution stepExecution = new StepExecution("foobar", jobExecution); jobRepository.add(stepExecution); } return taskExecution.getExecutionId(); }
Example #2
Source File: DefaultTaskJobService.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
/** * Apply identifying job parameters to arguments. There are cases (incrementers) * that add parameters to a job and thus must be added for each restart so that the * JobInstanceId does not change. * @param taskExecutionArgs original set of task execution arguments * @param jobParameters for the job to be restarted. * @return deduped list of arguments that contains the original arguments and any * identifying job parameters not in the original task execution arguments. */ private List<String>restartExecutionArgs(List<String> taskExecutionArgs, JobParameters jobParameters) { List<String> result = new ArrayList<>(taskExecutionArgs); Map<String, JobParameter> jobParametersMap = jobParameters.getParameters(); for (String key : jobParametersMap.keySet()) { if (!key.startsWith("-")) { boolean existsFlag = false; for(String arg : taskExecutionArgs) { if(arg.startsWith(key)) { existsFlag = true; break; } } if(!existsFlag) { result.add(String.format("%s(%s)=%s", key, jobParametersMap.get(key).getType().toString().toLowerCase(), jobParameters.getString(key))); } } } return result; }
Example #3
Source File: DefaultTaskJobServiceTests.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
@Before public void setup() { // not adding platform name as default as we want to check that this only one // gets replaced this.launcherRepository.save(new Launcher("fakeplatformname", "local", this.taskLauncher)); Map<String, JobParameter> jobParameterMap = new HashMap<>(); jobParameterMap.put("-spring.cloud.data.flow.platformname", new JobParameter("demo")); jobParameterMap.put("identifying.param", new JobParameter("testparam")); this.jobParameters = new JobParameters(jobParameterMap); JdbcTemplate template = new JdbcTemplate(this.dataSource); template.execute("DELETE FROM TASK_EXECUTION_PARAMS"); template.execute("DELETE FROM TASK_EXECUTION;"); initializeSuccessfulRegistry(this.appRegistry); template.execute("INSERT INTO TASK_EXECUTION (TASK_EXECUTION_ID, TASK_NAME) VALUES (0, 'myTask_ORIG');"); initializeJobs(); when(this.taskLauncher.launch(any())).thenReturn("1234"); }
Example #4
Source File: JobParametersEvent.java From spring-cloud-task with Apache License 2.0 | 6 votes |
public JobParametersEvent(Map<String, JobParameter> jobParameters) { this.parameters = new LinkedHashMap<>(); for (Map.Entry<String, JobParameter> entry : jobParameters.entrySet()) { if (entry.getValue().getValue() instanceof String) { this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue())); } else if (entry.getValue().getValue() instanceof Long) { this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue())); } else if (entry.getValue().getValue() instanceof Date) { this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue())); } else if (entry.getValue().getValue() instanceof Double) { this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue())); } } }
Example #5
Source File: JobParameterEvent.java From spring-cloud-task with Apache License 2.0 | 6 votes |
public static ParameterType convert(JobParameter.ParameterType type) { if (JobParameter.ParameterType.DATE.equals(type)) { return DATE; } else if (JobParameter.ParameterType.DOUBLE.equals(type)) { return DOUBLE; } else if (JobParameter.ParameterType.LONG.equals(type)) { return LONG; } else if (JobParameter.ParameterType.STRING.equals(type)) { return STRING; } else { throw new IllegalArgumentException("Unable to convert type"); } }
Example #6
Source File: JobParamUtil.java From spring-batch-rest with Apache License 2.0 | 5 votes |
public static JobParameter createJobParameter(Object value) { if (value instanceof Date) return new JobParameter((Date) value); else if (value instanceof Long) return new JobParameter((Long) value); else if (value instanceof Double) return new JobParameter((Double) value); else return new JobParameter("" + value); }
Example #7
Source File: ProtocolListener.java From spring-boot-starter-batch-web with Apache License 2.0 | 5 votes |
@Override public void beforeJob(JobExecution jobExecution) { StringBuilder protocol = new StringBuilder(); protocol.append(createFilledLine('-')); protocol.append("Job " + jobExecution.getJobInstance().getJobName() + " started with Job-Execution-Id " + jobExecution.getId() + " \n"); protocol.append("Job-Parameter: \n"); JobParameters jp = jobExecution.getJobParameters(); for (Iterator<Entry<String, JobParameter>> iter = jp.getParameters().entrySet().iterator(); iter.hasNext();) { Entry<String, JobParameter> entry = iter.next(); protocol.append(" " + entry.getKey() + "=" + entry.getValue() + "\n"); } protocol.append(createFilledLine('-')); LOGGER.info(protocol.toString()); }
Example #8
Source File: SingleJVMJobProgressListenerTest.java From batchers with Apache License 2.0 | 5 votes |
public void startAStepWithEmployees(int size) { Mockito.when(employeeService.getEmployeeCount()).thenReturn((long) size); Map<String, JobParameter> parameters = new HashMap<>(); parameters.put("year", new JobParameter(YEAR, true)); parameters.put("month", new JobParameter(MONTH, true)); jobProgressListener.beforeStep(new StepExecution(STEP_NAME, new JobExecution(1L, new JobParameters(parameters)), 1L)); }
Example #9
Source File: EmployeeBatchJobITest.java From batchers with Apache License 2.0 | 5 votes |
@Before public void setUp() { mockServer = MockRestServiceServer.createServer(restTemplate); SmtpServerStub.start(); Map<String, JobParameter> jobParamsMap = new HashMap<>(); jobParamsMap.put("month", new JobParameter(MONTH)); jobParamsMap.put("year", new JobParameter(YEAR)); jobParams = new JobParameters(jobParamsMap); setInternalState(emailSenderService, "emailSendCounter", 0); }
Example #10
Source File: CampusProcess.java From olat with Apache License 2.0 | 5 votes |
/** * Delegates the actual launching of the given job to the given jobLauncher <br> * only in the case that the process is in the enabled status. * * @param status * the status indicating whether the job is enabled or disabled * @param campusProcess * the name of the process */ public void process(String status, String campusProcess) throws Exception { LOG.info("THE " + campusProcess + " IS: [" + status + "]"); if (PROCESS_DISABLED.equalsIgnoreCase(status)) { return; } parameters.put("run.ts", new JobParameter(System.currentTimeMillis())); jobLauncher.run(job, new JobParameters(parameters)); }
Example #11
Source File: TaskJobLauncherCommandLineRunner.java From spring-cloud-task with Apache License 2.0 | 5 votes |
private JobParameters removeNonIdentifying(JobParameters parameters) { Map<String, JobParameter> parameterMap = parameters.getParameters(); HashMap<String, JobParameter> copy = new HashMap<>(parameterMap); for (Map.Entry<String, JobParameter> parameter : copy.entrySet()) { if (!parameter.getValue().isIdentifying()) { parameterMap.remove(parameter.getKey()); } } return new JobParameters(parameterMap); }
Example #12
Source File: JobParameterEventTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Test public void testValidHashCode() { final String EXPECTED_VALUE = "FOO"; JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true); JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter); assertThat(jobParameterEvent.hashCode()).isNotNull(); }
Example #13
Source File: JobParameterEventTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Test(expected = NullPointerException.class) public void testInvalidHashCode() { JobParameterEvent jobParameterEvent = new JobParameterEvent(); assertThat(jobParameterEvent.hashCode()).isNull(); final String EXPECTED_VALUE = "FOO"; JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true); jobParameterEvent = new JobParameterEvent(jobParameter); assertThat(jobParameterEvent.hashCode()).isNotNull(); }
Example #14
Source File: JobParameterEventTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Test public void testEquals() { final String EXPECTED_VALUE = "FOO"; JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true); JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter); JobParameterEvent anotherJobParameterEvent = new JobParameterEvent(jobParameter); assertTrue(jobParameterEvent.equals(jobParameterEvent)); assertFalse(jobParameterEvent.equals("nope")); assertTrue(jobParameterEvent.equals(anotherJobParameterEvent)); }
Example #15
Source File: JobParametersEventTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
public JobParametersEvent getPopulatedParametersEvent() { Map<String, JobParameter> jobParameters = new HashMap<>(); jobParameters.put(DATE_KEY, DATE_PARAM); jobParameters.put(STRING_KEY, STRING_PARAM); jobParameters.put(LONG_KEY, LONG_PARAM); jobParameters.put(DOUBLE_KEY, DOUBLE_PARAM); return new JobParametersEvent(jobParameters); }
Example #16
Source File: DomainParameterParser.java From spring-batch-lightmin with Apache License 2.0 | 5 votes |
/** * maps {@link JobParameters} to a String representation * * @param jobParameters {@link JobParameters} to map * @return a String representation of {@link JobParameters} */ public static String parseJobParametersToString(final JobParameters jobParameters) { final Map<String, JobParameter> jobParametersMap = jobParameters.getParameters(); final Map<String, Object> paramatersMap = new HashMap<>(); for (final Entry<String, JobParameter> entry : jobParametersMap.entrySet()) { paramatersMap.put(entry.getKey(), entry.getValue().getValue()); } return parseParameterMapToString(paramatersMap); }
Example #17
Source File: ArgumentSanitizerTest.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void testSanitizeJobParameters() { String[] JOB_PARAM_KEYS = {"username", "password", "name", "C", "D", "E"}; Date testDate = new Date(); JobParameter[] PARAMETERS = {new JobParameter("foo", true), new JobParameter("bar", true), new JobParameter("baz", true), new JobParameter(1L, true), new JobParameter(1D, true), new JobParameter(testDate, false)}; Map<String, JobParameter> jobParamMap = new LinkedHashMap<>(); for (int paramCount = 0; paramCount < JOB_PARAM_KEYS.length; paramCount++) { jobParamMap.put(JOB_PARAM_KEYS[paramCount], PARAMETERS[paramCount]); } JobParameters jobParameters = new JobParameters(jobParamMap); JobParameters sanitizedJobParameters = this.sanitizer.sanitizeJobParameters(jobParameters); for(Map.Entry<String, JobParameter> entry : sanitizedJobParameters.getParameters().entrySet()) { if (entry.getKey().equals("username") || entry.getKey().equals("password")) { Assert.assertEquals("******", entry.getValue().getValue()); } else if (entry.getKey().equals("name")) { Assert.assertEquals("baz", entry.getValue().getValue()); } else if (entry.getKey().equals("C")) { Assert.assertEquals(1L, entry.getValue().getValue()); } else if (entry.getKey().equals("D")) { Assert.assertEquals(1D, entry.getValue().getValue()); } else if (entry.getKey().equals("E")) { Assert.assertEquals(testDate, entry.getValue().getValue()); } } }
Example #18
Source File: JobExecutionsDocumentation.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
private void createJobExecution(String name, BatchStatus status) { TaskExecution taskExecution = this.dao.createTaskExecution(name, new Date(), new ArrayList<>(), null); Map<String, JobParameter> jobParameterMap = new HashMap<>(); jobParameterMap.put("-spring.cloud.data.flow.platformname", new JobParameter("default")); JobParameters jobParameters = new JobParameters(jobParameterMap); JobExecution jobExecution = this.jobRepository.createJobExecution(this.jobRepository.createJobInstance(name, new JobParameters()), jobParameters, null); this.taskBatchDao.saveRelationship(taskExecution, jobExecution); jobExecution.setStatus(status); jobExecution.setStartTime(new Date()); this.jobRepository.update(jobExecution); }
Example #19
Source File: DataflowTemplateTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
private void assertCorrectMixins(ObjectMapper objectMapper) { assertNotNull(objectMapper.findMixInClassFor(JobExecution.class)); assertNotNull(objectMapper.findMixInClassFor(JobParameters.class)); assertNotNull(objectMapper.findMixInClassFor(JobParameter.class)); assertNotNull(objectMapper.findMixInClassFor(JobInstance.class)); assertNotNull(objectMapper.findMixInClassFor(ExitStatus.class)); assertNotNull(objectMapper.findMixInClassFor(StepExecution.class)); assertNotNull(objectMapper.findMixInClassFor(ExecutionContext.class)); assertNotNull(objectMapper.findMixInClassFor(StepExecutionHistory.class)); }
Example #20
Source File: DataFlowTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Mutable operation to add several required MixIns to the provided * {@link ObjectMapper}. * * @param objectMapper Must not be null * @return ObjectMapper with several mixIns applied */ public static ObjectMapper prepareObjectMapper(ObjectMapper objectMapper) { Assert.notNull(objectMapper, "The objectMapper must not be null."); return objectMapper .registerModule(new Jackson2HalModule()) .addMixIn(JobExecution.class, JobExecutionJacksonMixIn.class) .addMixIn(JobParameters.class, JobParametersJacksonMixIn.class) .addMixIn(JobParameter.class, JobParameterJacksonMixIn.class) .addMixIn(JobInstance.class, JobInstanceJacksonMixIn.class) .addMixIn(ExitStatus.class, ExitStatusJacksonMixIn.class) .addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class) .addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class) .addMixIn(StepExecutionHistory.class, StepExecutionHistoryJacksonMixIn.class); }
Example #21
Source File: ArgumentSanitizer.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Replaces the sensitive String values in the JobParameter value. * * @param jobParameters the original job parameters * @return the sanitized job parameters */ public JobParameters sanitizeJobParameters(JobParameters jobParameters) { Map<String,JobParameter> newJobParameters = new HashMap<>(); jobParameters.getParameters().forEach( (key, jobParameter) -> { String updatedKey = !jobParameter.isIdentifying() ? "-" + key : key; if (jobParameter.getType().equals(JobParameter.ParameterType.STRING)) { newJobParameters.put(updatedKey, new JobParameter(this.sanitize(key, jobParameter.toString()))); } else { newJobParameters.put(updatedKey, jobParameter); } }); return new JobParameters(newJobParameters); }
Example #22
Source File: JobResource.java From patient-batch-loader with GNU General Public License v3.0 | 5 votes |
/** * POST /job/:fileName : post to execute a job using the file name given * * @param fileName * the fileName of the job file to run * @return the ResponseEntity with status 200 (OK) or status 500 (Job Failure) */ @GetMapping("/{fileName:.+}") public ResponseEntity<String> runJob(@PathVariable String fileName) { Map<String, JobParameter> parameterMap = new HashMap<>(); parameterMap.put(Constants.JOB_PARAM_FILE_NAME, new JobParameter(fileName)); try { jobLauncher.run(job, new JobParameters(parameterMap)); } catch (Exception e) { return new ResponseEntity<String>("Failure: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<String>("Success", HttpStatus.OK); }
Example #23
Source File: JobParamUtilTest.java From spring-batch-rest with Apache License 2.0 | 5 votes |
@Test public void testObjectConversionHappy() { Date date = new Date(); JobParameter dateParam = JobParamUtil.createJobParameter(date); Assertions.assertEquals(dateParam.getValue(), date); Long longVar = new Long(1234); JobParameter longParam = JobParamUtil.createJobParameter(longVar); Assertions.assertEquals(longParam.getValue(), longVar); Double doubleVar = new Double(123.123); JobParameter doubleParam = JobParamUtil.createJobParameter(doubleVar); Assertions.assertEquals(doubleParam.getValue(), doubleVar); }
Example #24
Source File: JobParameterEvent.java From spring-cloud-task with Apache License 2.0 | 4 votes |
public JobParameterEvent(JobParameter jobParameter) { this.parameter = jobParameter.getValue(); this.parameterType = ParameterType.convert(jobParameter.getType()); this.identifying = jobParameter.isIdentifying(); }
Example #25
Source File: TaskJobLauncherCommandLineRunner.java From spring-cloud-task with Apache License 2.0 | 4 votes |
private JobParameters merge(JobParameters parameters, JobParameters additionals) { Map<String, JobParameter> merged = new HashMap<>(); merged.putAll(parameters.getParameters()); merged.putAll(additionals.getParameters()); return new JobParameters(merged); }
Example #26
Source File: BatchJobConfigurationTest.java From patient-batch-loader with GNU General Public License v3.0 | 4 votes |
@Before public void setUp() { Map<String, JobParameter> params = new HashMap<>(); params.put(Constants.JOB_PARAM_FILE_NAME, new JobParameter("test-unit-testing.csv")); jobParameters = new JobParameters(params); }
Example #27
Source File: AlarmJobTest.java From pinpoint with Apache License 2.0 | 4 votes |
private static JobParameters getParameters() { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); parameters.put("schedule.scheduledFireTime", new JobParameter(new Date())); return new JobParameters(parameters); }
Example #28
Source File: JobParamUtil.java From spring-batch-rest with Apache License 2.0 | 4 votes |
public static Map<String, JobParameter> convertRawToParamMap(Map<String, Object> properties) { return Optional.ofNullable(properties).orElse(emptyMap()).entrySet().stream() .collect(toMap(Map.Entry::getKey, e -> createJobParameter(e.getValue()))); }
Example #29
Source File: CampusProcess.java From olat with Apache License 2.0 | 2 votes |
/** * Sets the Map of the JobParameters needed to run the job * * @param parameters * the map of the JobParameters */ public void setParameters(Map<String, JobParameter> parameters) { this.parameters = parameters; }