List of usage examples for org.springframework.batch.core.job.builder SimpleJobBuilder build
public Job build()
From source file:org.duracloud.snapshot.service.impl.SnapshotJobBuilder.java
@Override public Job buildJob(Snapshot snapshot, SnapshotJobManagerConfig config) throws SnapshotException { Job job;/*from ww w . j a v a 2 s .c o m*/ try { DuracloudEndPointConfig source = snapshot.getSource(); StoreClientUtil clientUtil = new StoreClientUtil(); ContentStore contentStore = clientUtil.createContentStore(source.getHost(), source.getPort(), SnapshotServiceConstants.DURASTORE_CONTEXT, config.getDuracloudUsername(), config.getDuracloudPassword(), source.getStoreId()); List<String> spaces = new ArrayList<>(); spaces.add(source.getSpaceId()); RetrievalSource retrievalSource = new DuraStoreStitchingRetrievalSource(contentStore, spaces, false); ItemReader<ContentItem> itemReader = new SpaceItemReader(retrievalSource); File contentDir = new File( ContentDirUtils.getDestinationPath(snapshot.getName(), config.getContentRootDir())); if (!contentDir.exists()) { contentDir.mkdirs(); } File workDir = config.getWorkDir(); OutputWriter outputWriter = new CSVFileOutputWriter(workDir); BufferedWriter propsWriter = createWriter(contentDir, SnapshotServiceConstants.CONTENT_PROPERTIES_JSON_FILENAME); BufferedWriter md5Writer = createWriter(contentDir, MANIFEST_MD5_TXT_FILE_NAME); BufferedWriter sha256Writer = createWriter(contentDir, MANIFEST_SHA256_TXT_FILE_NAME); ItemWriter itemWriter = new SpaceItemWriter(snapshot, retrievalSource, contentDir, outputWriter, propsWriter, md5Writer, sha256Writer, snapshotManager); SimpleStepFactoryBean<ContentItem, File> stepFactory = new SimpleStepFactoryBean<>(); stepFactory.setJobRepository(jobRepository); stepFactory.setTransactionManager(transactionManager); stepFactory.setBeanName("step1"); stepFactory.setItemReader(itemReader); stepFactory.setItemWriter(itemWriter); stepFactory.setCommitInterval(1); stepFactory.setThrottleLimit(20); stepFactory.setTaskExecutor(taskExecutor); Step step = (Step) stepFactory.getObject(); JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(jobRepository); JobBuilder jobBuilder = jobBuilderFactory.get(SnapshotServiceConstants.SNAPSHOT_JOB_NAME); SimpleJobBuilder simpleJobBuilder = jobBuilder.start(step); simpleJobBuilder.listener(jobListener); job = simpleJobBuilder.build(); log.debug("build job {}", job); } catch (Exception e) { log.error("Error creating job: {}", e.getMessage(), e); throw new SnapshotException(e.getMessage(), e); } return job; }
From source file:org.duracloud.snapshot.service.impl.RestoreJobBuilder.java
@Override public Job buildJob(Restoration restoration, SnapshotJobManagerConfig jobManagerConfig) throws SnapshotException { Job job;/*www.j ava 2 s . c om*/ try { DuracloudEndPointConfig destination = restoration.getDestination(); String destinationSpaceId = destination.getSpaceId(); String restoreId = restoration.getRestorationId(); StoreClientUtil clientUtil = new StoreClientUtil(); ContentStore contentStore = clientUtil.createContentStore(destination.getHost(), destination.getPort(), SnapshotServiceConstants.DURASTORE_CONTEXT, jobManagerConfig.getDuracloudUsername(), jobManagerConfig.getDuracloudPassword(), destination.getStoreId()); Step restoreContentStep = buildRestoreContentStep(restoreId, destinationSpaceId, contentStore, jobManagerConfig); Step restorePropertiesStep = buildRestoreContentPropertiesStep(restoreId, destinationSpaceId, contentStore, jobManagerConfig); JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(jobRepository); JobBuilder jobBuilder = jobBuilderFactory.get(SnapshotServiceConstants.RESTORE_JOB_NAME); SimpleJobBuilder simpleJobBuilder = jobBuilder.start(restoreContentStep).next(restorePropertiesStep); simpleJobBuilder.listener(jobListener); job = simpleJobBuilder.build(); log.debug("build job {}", job); } catch (Exception e) { log.error("Error creating job: {}", e.getMessage(), e); throw new SnapshotException(e.getMessage(), e); } return job; }