sandynz commented on code in PR #20782:
URL: https://github.com/apache/shardingsphere/pull/20782#discussion_r962465054
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/PipelineJobExecutor.java:
##########
@@ -73,20 +72,17 @@ private Optional<JobConfigurationPOJO>
getJobConfigPOJO(final DataChangedEvent e
}
private void processEvent(final DataChangedEvent event, final
JobConfigurationPOJO jobConfigPOJO) {
+ log.info("process event, key:{}, type:{}", event.getKey(),
event.getType());
boolean isDeleted = DataChangedEvent.Type.DELETED == event.getType();
boolean isDisabled = jobConfigPOJO.isDisabled();
- 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());
- if (isDeleted) {
- new MigrationJobPreparer().cleanup(jobConfig);
- } else if
(PipelineJobProgressDetector.isJobSuccessful(jobConfig.getJobShardingCount(),
MigrationJobAPIFactory.getInstance().getJobProgress(jobConfig).values())) {
- log.info("isJobSuccessful=true");
- new MigrationJobPreparer().cleanup(jobConfig);
- }
- PipelineJobCenter.stop(jobId);
+ JobType jobType =
PipelineJobIdUtils.parseJobType(jobConfigPOJO.getJobName());
+ PipelineEventProcess process =
PipelineEventProcessFactory.getInstance(jobType);
+ if (isDeleted) {
+ process.deleteEventHandle(jobConfigPOJO);
+ return;
+ }
+ if (isDisabled) {
+ process.disableEventHandle(jobConfigPOJO);
return;
}
switch (event.getType()) {
Review Comment:
These code could be put to SPI impl
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/PipelineJobExecutor.java:
##########
@@ -73,20 +72,17 @@ private Optional<JobConfigurationPOJO>
getJobConfigPOJO(final DataChangedEvent e
}
private void processEvent(final DataChangedEvent event, final
JobConfigurationPOJO jobConfigPOJO) {
+ log.info("process event, key:{}, type:{}", event.getKey(),
event.getType());
boolean isDeleted = DataChangedEvent.Type.DELETED == event.getType();
boolean isDisabled = jobConfigPOJO.isDisabled();
- 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());
- if (isDeleted) {
- new MigrationJobPreparer().cleanup(jobConfig);
- } else if
(PipelineJobProgressDetector.isJobSuccessful(jobConfig.getJobShardingCount(),
MigrationJobAPIFactory.getInstance().getJobProgress(jobConfig).values())) {
- log.info("isJobSuccessful=true");
- new MigrationJobPreparer().cleanup(jobConfig);
- }
- PipelineJobCenter.stop(jobId);
+ JobType jobType =
PipelineJobIdUtils.parseJobType(jobConfigPOJO.getJobName());
+ PipelineEventProcess process =
PipelineEventProcessFactory.getInstance(jobType);
+ if (isDeleted) {
+ process.deleteEventHandle(jobConfigPOJO);
+ return;
+ }
+ if (isDisabled) {
+ process.disableEventHandle(jobConfigPOJO);
return;
}
switch (event.getType()) {
Review Comment:
Maybe we could finish another related refactor firstly
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/process/PipelineEventProcess.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.core.spi.process;
+
+import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
+
+/**
+ * Job config event process.
+ */
+public interface PipelineEventProcess extends TypedSPI {
+
+ /**
+ * Delete event handle.
+ *
+ * @param jobConfigPOJO job config
+ */
+ void deleteEventHandle(JobConfigurationPOJO jobConfigPOJO);
+
+ /**
+ * Disable event handle.
+ *
+ * @param jobConfigPOJO job config
+ */
+ void disableEventHandle(JobConfigurationPOJO jobConfigPOJO);
Review Comment:
Could we merge these methods?
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/PipelineJobExecutor.java:
##########
@@ -73,20 +72,17 @@ private Optional<JobConfigurationPOJO>
getJobConfigPOJO(final DataChangedEvent e
}
private void processEvent(final DataChangedEvent event, final
JobConfigurationPOJO jobConfigPOJO) {
+ log.info("process event, key:{}, type:{}", event.getKey(),
event.getType());
boolean isDeleted = DataChangedEvent.Type.DELETED == event.getType();
boolean isDisabled = jobConfigPOJO.isDisabled();
- 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());
- if (isDeleted) {
- new MigrationJobPreparer().cleanup(jobConfig);
- } else if
(PipelineJobProgressDetector.isJobSuccessful(jobConfig.getJobShardingCount(),
MigrationJobAPIFactory.getInstance().getJobProgress(jobConfig).values())) {
- log.info("isJobSuccessful=true");
- new MigrationJobPreparer().cleanup(jobConfig);
- }
- PipelineJobCenter.stop(jobId);
+ JobType jobType =
PipelineJobIdUtils.parseJobType(jobConfigPOJO.getJobName());
+ PipelineEventProcess process =
PipelineEventProcessFactory.getInstance(jobType);
+ if (isDeleted) {
+ process.deleteEventHandle(jobConfigPOJO);
+ return;
+ }
+ if (isDisabled) {
+ process.disableEventHandle(jobConfigPOJO);
return;
}
switch (event.getType()) {
Review Comment:
Maybe we could finish another related refactor firstly
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/process/PipelineEventProcess.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.core.spi.process;
+
+import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
+
+/**
+ * Job config event process.
+ */
+public interface PipelineEventProcess extends TypedSPI {
Review Comment:
Could we improve class name? e.g.
PipelineJobConfigurationChangedEventProcessor
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/process/PipelineEventProcess.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.core.spi.process;
+
+import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
+
+/**
+ * Job config event process.
+ */
+public interface PipelineEventProcess extends TypedSPI {
+
+ /**
+ * Delete event handle.
+ *
+ * @param jobConfigPOJO job config
+ */
+ void deleteEventHandle(JobConfigurationPOJO jobConfigPOJO);
+
+ /**
+ * Disable event handle.
+ *
+ * @param jobConfigPOJO job config
+ */
+ void disableEventHandle(JobConfigurationPOJO jobConfigPOJO);
Review Comment:
e.g. void process(DataChangedEvent event, JobConfigurationPOJO
jobConfigPOJO);
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]