@Override public Properties getProperties(JobParameters params) { return PropertiesConverter.stringToProperties("a=b"); } });
/** * Create a {@link JobExecution} with the parameters provided. * * @param jobName the name of the job * @param instanceId the Id of the {@link JobInstance} * @param executionId the id for the {@link JobExecution} * @param jobParameters comma or new line separated name=value pairs * @return a {@link JobExecution} */ public static JobExecution createJobExecution(String jobName, Long instanceId, Long executionId, String jobParameters) { JobParameters params = new DefaultJobParametersConverter().getJobParameters(PropertiesConverter .stringToProperties(jobParameters)); return createJobExecution(jobName, instanceId, executionId, params); }
/** * Check that Properties can be newline delimited. */ @Test public void testRegularConversionWithCommaAndNewline() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); props = PropertiesConverter.stringToProperties("key1=value1\n key2=value2"); assertEquals(storedProps, props); }
/** * Check that Properties can be comma delimited. */ @Test public void testRegularConversionWithComma() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); props = PropertiesConverter.stringToProperties("key1=value1,key2=value2"); assertEquals(storedProps, props); }
/** * Check that Properties can be comma delimited with extra whitespace. */ @Test public void testRegularConversionWithCommaAndWhitespace() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); props = PropertiesConverter.stringToProperties("key1=value1, key2=value2"); assertEquals(storedProps, props); }
@Override public Long start(String jobName, String parameters) throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException { logger.info("Checking status of job with name=" + jobName); JobParameters jobParameters = jobParametersConverter.getJobParameters(PropertiesConverter .stringToProperties(parameters)); if (jobRepository.isJobInstanceExists(jobName, jobParameters)) { throw new JobInstanceAlreadyExistsException(String.format( "Cannot start a job instance that already exists with name=%s and parameters=%s", jobName, parameters)); } Job job = jobRegistry.getJob(jobName); logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters)); try { return jobLauncher.run(job, jobParameters).getId(); } catch (JobExecutionAlreadyRunningException e) { throw new UnexpectedJobExecutionException(String.format(ILLEGAL_STATE_MSG, "job execution already running", jobName, parameters), e); } catch (JobRestartException e) { throw new UnexpectedJobExecutionException(String.format(ILLEGAL_STATE_MSG, "job not restartable", jobName, parameters), e); } catch (JobInstanceAlreadyCompleteException e) { throw new UnexpectedJobExecutionException(String.format(ILLEGAL_STATE_MSG, "job already complete", jobName, parameters), e); } }
@Test public void testEscapedColon() throws Exception { Properties props = new Properties(); props.setProperty("test", "C:/test"); String str = PropertiesConverter.propertiesToString(props); props = PropertiesConverter.stringToProperties(str); assertEquals("C:/test", props.getProperty("test")); }
/** * Check that Properties can be converted to String and back correctly. */ @Test public void testTwoWayRegularConversion() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); props = PropertiesConverter.stringToProperties(PropertiesConverter.propertiesToString(storedProps)); assertEquals(storedProps, props); }
/** * Null String should be converted to empty Properties */ @Test public void testStringToPropertiesNull() { props = PropertiesConverter.stringToProperties(null); assertNotNull(props); assertEquals("properties are empty", 0, props.size()); }
private JobExecution runJobForRestartTest() throws Exception { return jobLauncherTestUtils .launchJob(new DefaultJobParametersConverter() .getJobParameters(PropertiesConverter .stringToProperties("run.id(long)=1,parameter=true,run.date=20070122,input.file=classpath:data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt"))); } }
@Test public void testJobLaunch() throws Exception { jdbcTemplate.update("DELETE FROM TRADE"); jobLauncherTestUtils.launchJob(new DefaultJobParametersConverter() .getJobParameters(PropertiesConverter .stringToProperties("run.id(long)=1,parameter=true,run.date=20070122,input.file=classpath:data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt"))); int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM TRADE", Integer.class); assertEquals(5, after); } }
/** * @param parameters * @return */ private StepExecution getStepExecution(String parameters) { JobParameters jobParameters = new DefaultJobParametersConverter().getJobParameters(PropertiesConverter.stringToProperties(parameters)); return new StepExecution("step", new JobExecution(new JobInstance(1L, "job"), jobParameters)); }
private void initializeProxy() throws Exception { if (proxyFactory == null) { proxyFactory = new ProxyFactory(); TransactionInterceptor advice = new TransactionInterceptor(transactionManager, PropertiesConverter.stringToProperties("create*=PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate + "\ngetLastJobExecution*=PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate + "\n*=PROPAGATION_REQUIRED")); if (validateTransactionState) { DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(new MethodInterceptor() { @Override public Object invoke(MethodInvocation invocation) throws Throwable { if (TransactionSynchronizationManager.isActualTransactionActive()) { throw new IllegalStateException( "Existing transaction detected in JobRepository. " + "Please fix this and try again (e.g. remove @Transactional annotations from client)."); } return invocation.proceed(); } }); NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut(); pointcut.addMethodName("create*"); advisor.setPointcut(pointcut); proxyFactory.addAdvisor(advisor); } proxyFactory.addAdvice(advice); proxyFactory.setProxyTargetClass(false); proxyFactory.addInterface(JobRepository.class); proxyFactory.setTarget(getTarget()); } }
public JobParameters fromString(String params) { Properties properties = PropertiesConverter.stringToProperties(params); return converter.getJobParameters(properties); }
public JobParameters fromString(String params) { Properties properties = PropertiesConverter.stringToProperties(params); return converter.getJobParameters(properties); }
public JobParameters fromString(String params) { Properties properties = PropertiesConverter.stringToProperties(params); return converter.getJobParameters(properties); }
@RequestMapping(value = "/{jobName}/start", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void startJob(@PathVariable("jobName") String jobName, @RequestParam(required = false) MultiValueMap<String, String> payload) { if (isEmpty(payload) || !payload.containsKey(JOB_PARAMETERS)) { jobService.startJob(jobName); } JobParameters jobParameters = jobParametersConverter.getJobParameters(stringToProperties(payload.getFirst(JOB_PARAMETERS))); jobService.startJob(jobName, jobParameters); }
/** * Create a {@link JobInstance} with the parameters provided. * * @param jobName the name of the job * @param instanceId the Id of the {@link JobInstance} * @param jobParameters comma or new line separated name=value pairs * @return a {@link JobInstance} */ public static JobInstance createJobInstance(String jobName, Long instanceId, String jobParameters) { JobParameters params = new DefaultJobParametersConverter().getJobParameters(PropertiesConverter .stringToProperties(jobParameters)); return createJobInstance(jobName, instanceId, params); }
/** * Create a {@link JobExecution} with the parameters provided. * * @param jobName the name of the job * @param instanceId the Id of the {@link JobInstance} * @param executionId the id for the {@link JobExecution} * @param jobParameters comma or new line separated name=value pairs * @return a {@link JobExecution} */ public static JobExecution createJobExecution(String jobName, Long instanceId, Long executionId, String jobParameters) { JobParameters params = new DefaultJobParametersConverter().getJobParameters(PropertiesConverter .stringToProperties(jobParameters)); return createJobExecution(jobName, instanceId, executionId, params); }
private void initializeProxy() throws Exception { if (proxyFactory == null) { proxyFactory = new ProxyFactory(); TransactionInterceptor advice = new TransactionInterceptor(transactionManager, PropertiesConverter .stringToProperties("create*=PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate + "\ngetLastJobExecution*=PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate + "\n*=PROPAGATION_REQUIRED")); DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(advice); NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut(); pointcut.addMethodName("*"); advisor.setPointcut(pointcut); proxyFactory.addAdvisor(advisor); proxyFactory.setProxyTargetClass(false); proxyFactory.addInterface(JobRepository.class); proxyFactory.setTarget(getTarget()); } }