You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/08/08 08:46:25 UTC

[shardingsphere] branch master updated: Refactor YamlJobProgressSwapper to impl YamlConfigurationSwapper (#19970)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new ae5d4418077 Refactor YamlJobProgressSwapper to impl YamlConfigurationSwapper (#19970)
ae5d4418077 is described below

commit ae5d4418077d77ba39f1d39c66f1197dc69e3d12
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Aug 8 16:46:11 2022 +0800

    Refactor YamlJobProgressSwapper to impl YamlConfigurationSwapper (#19970)
    
    * Update doc
    
    * Refactor YamlJobProgressSwapper to impl YamlConfigurationSwapper
---
 .../core/api/impl/GovernanceRepositoryAPIImpl.java    |  4 ++--
 .../core/job/progress/yaml/YamlJobProgress.java       |  5 +++--
 .../job/progress/yaml/YamlJobProgressSwapper.java     | 19 +++++--------------
 .../api/impl/GovernanceRepositoryAPIImplTest.java     |  2 +-
 .../job/progress/yaml/YamlJobProgressSwapperTest.java |  8 ++++----
 5 files changed, 15 insertions(+), 23 deletions(-)

diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/GovernanceRepositoryAPIImpl.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/GovernanceRepositoryAPIImpl.java
index fd2ff4068d4..97f8f661d2d 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/GovernanceRepositoryAPIImpl.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/GovernanceRepositoryAPIImpl.java
@@ -64,7 +64,7 @@ public final class GovernanceRepositoryAPIImpl implements GovernanceRepositoryAP
         jobProgress.setSourceDatabaseType(jobContext.getJobConfig().getSourceDatabaseType());
         jobProgress.setIncremental(getIncrementalTasksProgress(jobContext));
         jobProgress.setInventory(getInventoryTasksProgress(jobContext));
-        String value = YamlEngine.marshal(SWAPPER.swapToYaml(jobProgress));
+        String value = YamlEngine.marshal(SWAPPER.swapToYamlConfiguration(jobProgress));
         repository.persist(PipelineMetaDataNode.getScalingJobOffsetPath(jobContext.getJobId(), jobContext.getShardingItem()), value);
     }
     
@@ -138,6 +138,6 @@ public final class GovernanceRepositoryAPIImpl implements GovernanceRepositoryAP
             return;
         }
         jobProgress.setStatus(status);
-        persist(PipelineMetaDataNode.getScalingJobOffsetPath(jobId, shardingItem), YamlEngine.marshal(SWAPPER.swapToYaml(jobProgress)));
+        persist(PipelineMetaDataNode.getScalingJobOffsetPath(jobId, shardingItem), YamlEngine.marshal(SWAPPER.swapToYamlConfiguration(jobProgress)));
     }
 }
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgress.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgress.java
index a5be79669b7..0bba26fa9cc 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgress.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgress.java
@@ -19,13 +19,14 @@ package org.apache.shardingsphere.data.pipeline.core.job.progress.yaml;
 
 import lombok.Getter;
 import lombok.Setter;
+import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
 
 /**
- * Yaml job progress.
+ * YAML job progress.
  */
 @Getter
 @Setter
-public final class YamlJobProgress {
+public final class YamlJobProgress implements YamlConfiguration {
     
     private String status;
     
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgressSwapper.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgressSwapper.java
index 2cec5b1d453..2cddde02a02 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgressSwapper.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgressSwapper.java
@@ -19,23 +19,19 @@ package org.apache.shardingsphere.data.pipeline.core.job.progress.yaml;
 
 import org.apache.shardingsphere.data.pipeline.api.job.JobStatus;
 import org.apache.shardingsphere.data.pipeline.api.job.progress.JobProgress;
+import org.apache.shardingsphere.infra.yaml.config.swapper.YamlConfigurationSwapper;
 
 /**
  * YAML Job progress swapper.
  */
-public final class YamlJobProgressSwapper {
+public final class YamlJobProgressSwapper implements YamlConfigurationSwapper<YamlJobProgress, JobProgress> {
     
     private static final YamlJobItemInventoryTasksProgressSwapper INVENTORY_PROGRESS_SWAPPER = new YamlJobItemInventoryTasksProgressSwapper();
     
     private static final YamlJobItemIncrementalTasksProgressSwapper INCREMENTAL_PROGRESS_SWAPPER = new YamlJobItemIncrementalTasksProgressSwapper();
     
-    /**
-     * Swap to YAML.
-     *
-     * @param jobProgress job progress
-     * @return YAML job progress
-     */
-    public YamlJobProgress swapToYaml(final JobProgress jobProgress) {
+    @Override
+    public YamlJobProgress swapToYamlConfiguration(final JobProgress jobProgress) {
         YamlJobProgress result = new YamlJobProgress();
         result.setStatus(jobProgress.getStatus().name());
         result.setSourceDatabaseType(jobProgress.getSourceDatabaseType());
@@ -44,12 +40,7 @@ public final class YamlJobProgressSwapper {
         return result;
     }
     
-    /**
-     * Swap to object.
-     *
-     * @param yamlJobProgress yaml job progress
-     * @return job progress
-     */
+    @Override
     public JobProgress swapToObject(final YamlJobProgress yamlJobProgress) {
         JobProgress result = new JobProgress();
         result.setStatus(JobStatus.valueOf(yamlJobProgress.getStatus()));
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/api/impl/GovernanceRepositoryAPIImplTest.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/api/impl/GovernanceRepositoryAPIImplTest.java
index 83615933662..8457c4e1ff5 100644
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/api/impl/GovernanceRepositoryAPIImplTest.java
+++ b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/api/impl/GovernanceRepositoryAPIImplTest.java
@@ -77,7 +77,7 @@ public final class GovernanceRepositoryAPIImplTest {
         RuleAlteredJobContext jobContext = mockJobContext();
         governanceRepositoryAPI.persistJobProgress(jobContext);
         JobProgress actual = governanceRepositoryAPI.getJobProgress(jobContext.getJobId(), jobContext.getShardingItem());
-        assertThat(YamlEngine.marshal(SWAPPER.swapToYaml(actual)), is(ConfigurationFileUtil.readFileAndIgnoreComments("governance-repository.yaml")));
+        assertThat(YamlEngine.marshal(SWAPPER.swapToYamlConfiguration(actual)), is(ConfigurationFileUtil.readFileAndIgnoreComments("governance-repository.yaml")));
     }
     
     @Test
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgressSwapperTest.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgressSwapperTest.java
index 44c46f2e730..c385ac9a9f6 100644
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgressSwapperTest.java
+++ b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/YamlJobProgressSwapperTest.java
@@ -35,9 +35,9 @@ public final class YamlJobProgressSwapperTest {
     }
     
     @Test
-    public void assertFullSwapToYaml() {
+    public void assertFullSwapToYamlConfiguration() {
         JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress.yaml"));
-        YamlJobProgress actual = SWAPPER.swapToYaml(jobProgress);
+        YamlJobProgress actual = SWAPPER.swapToYamlConfiguration(jobProgress);
         assertThat(actual.getStatus(), is("RUNNING"));
         assertThat(actual.getSourceDatabaseType(), is("H2"));
         assertThat(actual.getInventory().getFinished().length, is(2));
@@ -50,9 +50,9 @@ public final class YamlJobProgressSwapperTest {
     }
     
     @Test
-    public void assertNullInventory() {
+    public void assertSwapToYamlConfigurationWithNullInventory() {
         JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress-no-inventory.yaml"));
-        YamlJobProgress actual = SWAPPER.swapToYaml(jobProgress);
+        YamlJobProgress actual = SWAPPER.swapToYamlConfiguration(jobProgress);
         assertThat(actual.getInventory().getFinished().length, is(0));
     }
 }