You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/09/05 02:23:09 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #20782: Extract job configuration change event handler SPI and impl in PipelineJobExecutor for common usage

sandynz commented on code in PR #20782:
URL: https://github.com/apache/shardingsphere/pull/20782#discussion_r962429198


##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/process/JobConfigEventProcess.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shardingsphere.data.pipeline.spi.process;
+
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
+
+/**
+ * Job config event process.
+ */
+public interface JobConfigEventProcess extends TypedSPI {
+    
+    /**
+     * Cleanup pipeline job config.
+     *
+     * @param jobParameter job parameter
+     */
+    void cleanup(String jobParameter);
+    
+    /**
+     * Check job is successful.
+     *
+     * @param jobParameter job parameter
+     * @return true if job is successful otherwise is false
+     */
+    boolean isJobSuccessful(String jobParameter);
+}

Review Comment:
   SPI name and methods could be updated, it's too detailed, could to be higher level.



##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/PipelineJobExecutor.java:
##########
@@ -75,16 +74,16 @@ private Optional<JobConfigurationPOJO> getJobConfigPOJO(final DataChangedEvent e
     private void processEvent(final DataChangedEvent event, final JobConfigurationPOJO jobConfigPOJO) {
         boolean isDeleted = DataChangedEvent.Type.DELETED == event.getType();
         boolean isDisabled = jobConfigPOJO.isDisabled();
+        String jobId = jobConfigPOJO.getJobName();
+        JobType jobType = PipelineJobIdUtils.parseJobType(jobId);
         if (isDeleted || isDisabled) {
-            String jobId = jobConfigPOJO.getJobName();
             log.info("jobId={}, deleted={}, disabled={}", jobId, isDeleted, isDisabled);
-            // TODO refactor: dispatch to different job types
-            MigrationJobConfiguration jobConfig = YamlMigrationJobConfigurationSwapper.swapToObject(jobConfigPOJO.getJobParameter());
+            JobConfigEventProcess process = JobConfigEventProcessFactory.getInstance(jobType);
             if (isDeleted) {
-                new MigrationJobPreparer().cleanup(jobConfig);
-            } else if (PipelineJobProgressDetector.isJobSuccessful(jobConfig.getJobShardingCount(), MigrationJobAPIFactory.getInstance().getJobProgress(jobConfig).values())) {
+                process.cleanup(jobConfigPOJO.getJobParameter());
+            } else if (process.isJobSuccessful(jobConfigPOJO.getJobParameter())) {
                 log.info("isJobSuccessful=true");
-                new MigrationJobPreparer().cleanup(jobConfig);
+                process.cleanup(jobConfigPOJO.getJobParameter());
             }
             PipelineJobCenter.stop(jobId);
             return;

Review Comment:
   After getting `jobType`, we could delegate all implementation to SPI and impl, so new type of job is free to implement it as needed.



##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/process/JobConfigEventProcessFactory.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shardingsphere.data.pipeline.spi.process;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.data.pipeline.api.job.JobType;
+import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
+
+/**
+ * Job config event process factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class JobConfigEventProcessFactory {
+    
+    static {
+        ShardingSphereServiceLoader.register(JobConfigEventProcess.class);
+    }
+    
+    /**
+     * Get importer creator instance.
+     *
+     * @param jobType job type
+     * @return importer creator
+     */

Review Comment:
   Looks javadoc doesn't match method



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org