View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.data.pipeline.cdc;
19  
20  import org.apache.shardingsphere.data.pipeline.cdc.config.job.CDCJobConfiguration;
21  import org.apache.shardingsphere.data.pipeline.cdc.config.yaml.swapper.YamlCDCJobConfigurationSwapper;
22  import org.apache.shardingsphere.data.pipeline.core.job.config.PipelineJobConfiguration;
23  import org.apache.shardingsphere.data.pipeline.core.context.TransmissionProcessContext;
24  import org.apache.shardingsphere.data.pipeline.core.job.progress.yaml.swapper.YamlTransmissionJobItemProgressSwapper;
25  import org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType;
26  import org.apache.shardingsphere.data.pipeline.core.pojo.PipelineJobInfo;
27  import org.apache.shardingsphere.data.pipeline.core.pojo.PipelineJobMetaData;
28  import org.apache.shardingsphere.data.pipeline.core.consistencycheck.ConsistencyCheckJobItemProgressContext;
29  import org.apache.shardingsphere.data.pipeline.core.consistencycheck.PipelineDataConsistencyChecker;
30  import org.apache.shardingsphere.data.pipeline.core.job.id.PipelineJobIdUtils;
31  import org.apache.shardingsphere.data.pipeline.core.job.service.PipelineJobConfigurationManager;
32  
33  /**
34   * CDC job type.
35   */
36  public final class CDCJobType implements PipelineJobType {
37      
38      @Override
39      public String getCode() {
40          return "03";
41      }
42      
43      @SuppressWarnings("unchecked")
44      @Override
45      public YamlCDCJobConfigurationSwapper getYamlJobConfigurationSwapper() {
46          return new YamlCDCJobConfigurationSwapper();
47      }
48      
49      @SuppressWarnings("unchecked")
50      @Override
51      public YamlTransmissionJobItemProgressSwapper getYamlJobItemProgressSwapper() {
52          return new YamlTransmissionJobItemProgressSwapper();
53      }
54      
55      @Override
56      public Class<CDCJob> getJobClass() {
57          return CDCJob.class;
58      }
59      
60      @Override
61      public boolean isForceNoShardingWhenConvertToJobConfigurationPOJO() {
62          return true;
63      }
64      
65      @Override
66      public PipelineJobInfo getJobInfo(final String jobId) {
67          PipelineJobMetaData jobMetaData = new PipelineJobMetaData(PipelineJobIdUtils.getElasticJobConfigurationPOJO(jobId));
68          CDCJobConfiguration jobConfig = new PipelineJobConfigurationManager(new CDCJobType()).getJobConfiguration(jobId);
69          return new PipelineJobInfo(jobMetaData, jobConfig.getDatabaseName(), String.join(", ", jobConfig.getSchemaTableNames()));
70      }
71      
72      @Override
73      public PipelineDataConsistencyChecker buildDataConsistencyChecker(final PipelineJobConfiguration jobConfig, final TransmissionProcessContext processContext,
74                                                                        final ConsistencyCheckJobItemProgressContext progressContext) {
75          throw new UnsupportedOperationException("");
76      }
77      
78      @Override
79      public String getType() {
80          return "STREAMING";
81      }
82  }