Files
spring-cloud-dataflow-samples/dataflow-migrate-schedules/src/main/java/io/spring/migrateschedule/configuration/BatchConfiguration.java
Glenn Renfro c3f5c9e65c Migrates existing schedules to SCDF 2.3.0
resolves #121

This app pulls in data from the PCFScheduler, AppSummary, AppManifest, the SCDF Task Definition Schema
to construct the new schedule for the migration.

You will note that for the App Summary, the code was pulled directly from the CF-Deployer, the reason
this was done was to obtain additional schedule information required for the migration, without having to make
another call to retrieve the app summary (i.e. obtain this detail while its still there).

As discussed in the README, you will see that not all properties could be obtained from the
available resources and thus have to be populated by a property that user can establish at runtime.
However this also means this affects all schedules to be migrated.

Updated to allow user to setup maven repository

Updated instructions to include how to execute migration

Updated docs

Updated to support deployer format for tasks

Also updated deployers to current release
2019-12-17 11:37:29 -06:00

101 lines
3.5 KiB
Java

/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.migrateschedule.configuration;
import io.spring.migrateschedule.service.ConvertScheduleInfo;
import io.spring.migrateschedule.service.MigrateScheduleService;
import io.spring.migrateschedule.service.MigrateProperties;
import io.spring.migrateschedule.batch.SchedulerProcessor;
import io.spring.migrateschedule.batch.SchedulerReader;
import io.spring.migrateschedule.batch.SchedulerWriter;
import io.spring.migrateschedule.service.ScheduleProcessedException;
import io.spring.migrateschedule.service.SchedulerSkipPolicy;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.deployer.spi.scheduler.ScheduleInfo;
import org.springframework.cloud.deployer.spi.scheduler.Scheduler;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Glenn Renfro
*/
@Configuration
@EnableBatchProcessing
@EnableTask
public class BatchConfiguration {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Bean
public Job importUserJob(Step migrationStep) {
return this.jobBuilderFactory.get("migrationJob")
.incrementer(new RunIdIncrementer())
.start(migrationStep)
.build();
}
@Bean
public Step migrationStep(SchedulerReader itemReader,
SchedulerProcessor schedulerProcessor, SchedulerWriter writer) {
return this.stepBuilderFactory.get("migrationStep")
.<ScheduleInfo, ScheduleInfo> chunk(1)
.reader(itemReader)
.processor(schedulerProcessor)
.writer(writer)
.faultTolerant()
.skip(ScheduleProcessedException.class)
.skipPolicy(new SchedulerSkipPolicy())
.build();
}
@Bean
public SchedulerReader<ConvertScheduleInfo> itemReader(MigrateScheduleService scheduler) {
return new SchedulerReader(scheduler);
}
@Bean
public SchedulerWriter<ConvertScheduleInfo> itemWriter(Scheduler scheduler, MigrateScheduleService scheduleService) {
return new SchedulerWriter(scheduleService, scheduler);
}
@Bean
public SchedulerProcessor<ConvertScheduleInfo, ConvertScheduleInfo> itemProcessor(MigrateScheduleService migrateScheduleService, MigrateProperties migrateProperties) {
return new SchedulerProcessor(migrateScheduleService, migrateProperties);
}
@Bean
@ConfigurationProperties
public MigrateProperties converterProperties() {
return new MigrateProperties();
}
}