1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.data.pipeline.scenario.migration;
19
20 import org.apache.shardingsphere.data.pipeline.core.job.config.PipelineJobConfiguration;
21 import org.apache.shardingsphere.data.pipeline.core.context.TransmissionProcessContext;
22 import org.apache.shardingsphere.data.pipeline.core.datanode.DataNodeUtils;
23 import org.apache.shardingsphere.data.pipeline.core.job.progress.yaml.swapper.YamlTransmissionJobItemProgressSwapper;
24 import org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType;
25 import org.apache.shardingsphere.data.pipeline.core.pojo.PipelineJobInfo;
26 import org.apache.shardingsphere.data.pipeline.core.pojo.PipelineJobMetaData;
27 import org.apache.shardingsphere.data.pipeline.core.consistencycheck.ConsistencyCheckJobItemProgressContext;
28 import org.apache.shardingsphere.data.pipeline.core.consistencycheck.PipelineDataConsistencyChecker;
29 import org.apache.shardingsphere.data.pipeline.core.job.id.PipelineJobIdUtils;
30 import org.apache.shardingsphere.data.pipeline.core.job.service.PipelineJobConfigurationManager;
31 import org.apache.shardingsphere.data.pipeline.scenario.migration.check.consistency.MigrationDataConsistencyChecker;
32 import org.apache.shardingsphere.data.pipeline.scenario.migration.config.MigrationJobConfiguration;
33 import org.apache.shardingsphere.data.pipeline.scenario.migration.config.yaml.swapper.YamlMigrationJobConfigurationSwapper;
34
35 import java.util.Collection;
36 import java.util.LinkedList;
37 import java.util.Optional;
38
39
40
41
42 public final class MigrationJobType implements PipelineJobType {
43
44 @Override
45 public String getCode() {
46 return "01";
47 }
48
49 @SuppressWarnings("unchecked")
50 @Override
51 public YamlMigrationJobConfigurationSwapper getYamlJobConfigurationSwapper() {
52 return new YamlMigrationJobConfigurationSwapper();
53 }
54
55 @SuppressWarnings("unchecked")
56 @Override
57 public YamlTransmissionJobItemProgressSwapper getYamlJobItemProgressSwapper() {
58 return new YamlTransmissionJobItemProgressSwapper();
59 }
60
61 @Override
62 public Class<MigrationJob> getJobClass() {
63 return MigrationJob.class;
64 }
65
66 @Override
67 public Optional<String> getToBeStartDisabledNextJobType() {
68 return Optional.of("CONSISTENCY_CHECK");
69 }
70
71 @Override
72 public Optional<String> getToBeStoppedPreviousJobType() {
73 return Optional.of("CONSISTENCY_CHECK");
74 }
75
76 @Override
77 public PipelineJobInfo getJobInfo(final String jobId) {
78 PipelineJobMetaData jobMetaData = new PipelineJobMetaData(PipelineJobIdUtils.getElasticJobConfigurationPOJO(jobId));
79 Collection<String> sourceTables = new LinkedList<>();
80 new PipelineJobConfigurationManager(new MigrationJobType()).<MigrationJobConfiguration>getJobConfiguration(jobId).getJobShardingDataNodes()
81 .forEach(each -> each.getEntries().forEach(entry -> entry.getDataNodes().forEach(dataNode -> sourceTables.add(DataNodeUtils.formatWithSchema(dataNode)))));
82 return new PipelineJobInfo(jobMetaData, null, String.join(",", sourceTables));
83 }
84
85 @Override
86 public PipelineDataConsistencyChecker buildDataConsistencyChecker(final PipelineJobConfiguration jobConfig, final TransmissionProcessContext processContext,
87 final ConsistencyCheckJobItemProgressContext progressContext) {
88 return new MigrationDataConsistencyChecker((MigrationJobConfiguration) jobConfig, processContext, progressContext);
89 }
90
91 @Override
92 public String getType() {
93 return "MIGRATION";
94 }
95 }