You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/07/27 13:20:13 UTC

[shardingsphere] branch master updated: Add global rule for dist meta data persist (#11541)

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

zhangliang 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 147d10d  Add global rule for dist meta data persist (#11541)
147d10d is described below

commit 147d10d3b67c610de11dac6187c23f478ceddecf
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Tue Jul 27 21:19:47 2021 +0800

    Add global rule for dist meta data persist (#11541)
    
    * Add global rule for dist meta data persist
    
    * fix javadoc
---
 .../infra/constant/DistMetaDataPersistOrder.java   | 33 ++++++++++++
 .../DistMetaDataPersistRuleConfiguration.java      | 36 +++++++++++++
 .../YamlDistMetaDataPersistRuleConfiguration.java  | 42 +++++++++++++++
 ...etaDataPersistRuleConfigurationYamlSwapper.java | 59 ++++++++++++++++++++++
 ...ersist.repository.DistMetaDataPersistRepository | 18 +++++++
 ...aml.config.swapper.YamlRuleConfigurationSwapper | 18 +++++++
 .../YamlRuleConfigurationSwapperEngineTest.java    |  2 +-
 7 files changed, 207 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/DistMetaDataPersistOrder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/DistMetaDataPersistOrder.java
new file mode 100644
index 0000000..ba3f5d6
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/DistMetaDataPersistOrder.java
@@ -0,0 +1,33 @@
+/*
+ * 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.infra.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Dist meta data persist order.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DistMetaDataPersistOrder {
+    
+    /**
+     * Dist meta data persist order.
+     */
+    public static final int ORDER = 70;
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/persist/DistMetaDataPersistRuleConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/persist/DistMetaDataPersistRuleConfiguration.java
new file mode 100644
index 0000000..dff5b2b
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/persist/DistMetaDataPersistRuleConfiguration.java
@@ -0,0 +1,36 @@
+/*
+ * 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.infra.rule.persist;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.config.scope.GlobalRuleConfiguration;
+
+import java.util.Properties;
+
+/**
+ * Dist meta data persist rule configuration.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class DistMetaDataPersistRuleConfiguration implements GlobalRuleConfiguration {
+    
+    private final String type;
+    
+    private final Properties props;
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/pojo/persist/YamlDistMetaDataPersistRuleConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/pojo/persist/YamlDistMetaDataPersistRuleConfiguration.java
new file mode 100644
index 0000000..9de5640
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/pojo/persist/YamlDistMetaDataPersistRuleConfiguration.java
@@ -0,0 +1,42 @@
+/*
+ * 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.infra.yaml.config.pojo.persist;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.infra.rule.persist.DistMetaDataPersistRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRuleConfiguration;
+
+import java.util.Properties;
+
+/**
+ * Yaml dist meta data persist rule configuration.
+ */
+@Getter
+@Setter
+public final class YamlDistMetaDataPersistRuleConfiguration implements YamlRuleConfiguration {
+    
+    private String type;
+    
+    private Properties props = new Properties();
+    
+    @Override
+    public Class<DistMetaDataPersistRuleConfiguration> getRuleConfigurationType() {
+        return DistMetaDataPersistRuleConfiguration.class;
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapper.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapper.java
new file mode 100644
index 0000000..f4aedc5
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapper.java
@@ -0,0 +1,59 @@
+/*
+ * 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.infra.yaml.config.swapper.persist;
+
+import org.apache.shardingsphere.infra.constant.DistMetaDataPersistOrder;
+import org.apache.shardingsphere.infra.rule.persist.DistMetaDataPersistRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.pojo.persist.YamlDistMetaDataPersistRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapper;
+
+/**
+ * Dist meta data persist rule configuration YAML swapper.
+ */
+// TODO add unit test for me
+public final class DistMetaDataPersistRuleConfigurationYamlSwapper implements 
+        YamlRuleConfigurationSwapper<YamlDistMetaDataPersistRuleConfiguration, DistMetaDataPersistRuleConfiguration> {
+    
+    @Override
+    public int getOrder() {
+        return DistMetaDataPersistOrder.ORDER;
+    }
+    
+    @Override
+    public Class<DistMetaDataPersistRuleConfiguration> getTypeClass() {
+        return DistMetaDataPersistRuleConfiguration.class;
+    }
+    
+    @Override
+    public YamlDistMetaDataPersistRuleConfiguration swapToYamlConfiguration(final DistMetaDataPersistRuleConfiguration data) {
+        YamlDistMetaDataPersistRuleConfiguration result = new YamlDistMetaDataPersistRuleConfiguration();
+        result.setType(data.getType());
+        result.setProps(data.getProps());
+        return result;
+    }
+    
+    @Override
+    public DistMetaDataPersistRuleConfiguration swapToObject(final YamlDistMetaDataPersistRuleConfiguration yamlConfig) {
+        return new DistMetaDataPersistRuleConfiguration(yamlConfig.getType(), yamlConfig.getProps());
+    }
+    
+    @Override
+    public String getRuleTagName() {
+        return "DIST_METADATA_PERSIST";
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.persist.repository.DistMetaDataPersistRepository b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.persist.repository.DistMetaDataPersistRepository
new file mode 100644
index 0000000..df78c18
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.persist.repository.DistMetaDataPersistRepository
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.infra.config.persist.repository.LocalDistMetaDataPersistRepository
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapper b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapper
new file mode 100644
index 0000000..5327f7d
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapper
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.infra.yaml.config.swapper.persist.DistMetaDataPersistRuleConfigurationYamlSwapper
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlRuleConfigurationSwapperEngineTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlRuleConfigurationSwapperEngineTest.java
index 8d1a596..5abdbf0 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlRuleConfigurationSwapperEngineTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlRuleConfigurationSwapperEngineTest.java
@@ -54,7 +54,7 @@ public final class YamlRuleConfigurationSwapperEngineTest {
     @Test
     public void assertGetYamlShortcuts() {
         Map<String, Class<?>> actual = YamlRuleConfigurationSwapperEngine.getYamlShortcuts();
-        assertThat(actual.size(), is(1));
+        assertThat(actual.size(), is(2));
         assertTrue(actual.containsKey("!FIXTURE"));
     }
 }