You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/07/02 22:34:07 UTC
[shardingsphere] branch master updated: Remove CreateRuleItemEvent (#26735)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 2f801b0da01 Remove CreateRuleItemEvent (#26735)
2f801b0da01 is described below
commit 2f801b0da010a0d3bd539e9405908642d9c08d1d
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Jul 3 06:34:01 2023 +0800
Remove CreateRuleItemEvent (#26735)
---
.../subscriber/BroadcastTableSubscriber.java | 4 +-
.../encrypt/subscriber/EncryptTableSubscriber.java | 38 +++++++++++------
.../mask/subscriber/MaskTableSubscriber.java | 4 +-
.../ReadwriteSplittingDataSourceSubscriber.java | 8 ++--
.../ReadwriteSplittingLoadBalanceSubscriber.java | 4 +-
.../subscriber/ShadowAlgorithmSubscriber.java | 4 +-
.../subscriber/ShadowDataSourceSubscriber.java | 8 ++--
.../shadow/subscriber/ShadowTableSubscriber.java | 4 +-
.../subscriber/ShardingCacheSubscriber.java | 4 +-
.../ShardingDefaultStrategySubscriber.java | 16 ++++----
.../rule/create/CreateNamedRuleItemEvent.java | 37 -----------------
.../event/rule/create/CreateRuleItemEvent.java | 26 ------------
.../rule/create/CreateUniqueRuleItemEvent.java | 35 ----------------
.../config/global/NewPropertiesPersistService.java | 4 +-
.../SingleRuleConfigurationDecorator.java | 5 +--
.../single/subscriber/SingleTableSubscriber.java | 48 +++++++++++-----------
.../storage/service/StorageNodeStatusService.java | 6 +--
17 files changed, 83 insertions(+), 172 deletions(-)
diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/subscriber/BroadcastTableSubscriber.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/subscriber/BroadcastTableSubscriber.java
index 99ffc843bef..90d8da5488e 100644
--- a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/subscriber/BroadcastTableSubscriber.java
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/subscriber/BroadcastTableSubscriber.java
@@ -51,8 +51,8 @@ public final class BroadcastTableSubscriber implements RuleChangedSubscriber {
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- BroadcastRuleConfiguration toBeChangedConfig = new BroadcastRuleConfiguration(YamlEngine.unmarshal(yamlContext, YamlBroadcastRuleConfiguration.class).getTables());
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ BroadcastRuleConfiguration toBeChangedConfig = new BroadcastRuleConfiguration(YamlEngine.unmarshal(yamlContent, YamlBroadcastRuleConfiguration.class).getTables());
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
Optional<BroadcastRule> rule = database.getRuleMetaData().findSingleRule(BroadcastRule.class);
BroadcastRuleConfiguration config;
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/EncryptTableSubscriber.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/EncryptTableSubscriber.java
index 477060bf86f..654e075127c 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/EncryptTableSubscriber.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/EncryptTableSubscriber.java
@@ -54,16 +54,11 @@ public final class EncryptTableSubscriber implements RuleChangedSubscriber {
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- EncryptTableRuleConfiguration toBeChangedConfig = new YamlEncryptTableRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlEncryptTableRuleConfiguration.class));
- EncryptRuleConfiguration config = database.getRuleMetaData().findSingleRule(EncryptRule.class)
- .map(optional -> getEncryptRuleConfiguration((EncryptRuleConfiguration) optional.getConfiguration()))
- .orElseGet(() -> new EncryptRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>()));
- // TODO refactor DistSQL to only persist config
- config.getTables().removeIf(each -> each.getName().equals(toBeChangedConfig.getName()));
- config.getTables().add(toBeChangedConfig);
- contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
+ EncryptTableRuleConfiguration toBeChangedConfig = getToBeChangedConfiguration(yamlContent);
+ ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
+ EncryptRuleConfiguration changedConfig = getChangedConfiguration(toBeChangedConfig, database);
+ contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), changedConfig));
}
/**
@@ -77,12 +72,31 @@ public final class EncryptTableSubscriber implements RuleChangedSubscriber {
return;
}
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
- EncryptRuleConfiguration config = (EncryptRuleConfiguration) database.getRuleMetaData().getSingleRule(EncryptRule.class).getConfiguration();
- config.getTables().removeIf(each -> each.getName().equals(event.getItemName()));
- contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
+ EncryptRuleConfiguration droppedConfig = getDroppedConfiguration(database, event.getItemName());
+ contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), droppedConfig));
+ }
+
+ private EncryptTableRuleConfiguration getToBeChangedConfiguration(final String yamlContent) {
+ return new YamlEncryptTableRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlEncryptTableRuleConfiguration.class));
+ }
+
+ private EncryptRuleConfiguration getChangedConfiguration(final EncryptTableRuleConfiguration toBeChangedConfig, final ShardingSphereDatabase database) {
+ EncryptRuleConfiguration config = database.getRuleMetaData().findSingleRule(EncryptRule.class)
+ .map(optional -> getEncryptRuleConfiguration((EncryptRuleConfiguration) optional.getConfiguration()))
+ .orElseGet(() -> new EncryptRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>()));
+ // TODO refactor DistSQL to only persist config
+ config.getTables().removeIf(each -> each.getName().equals(toBeChangedConfig.getName()));
+ config.getTables().add(toBeChangedConfig);
+ return config;
}
private EncryptRuleConfiguration getEncryptRuleConfiguration(final EncryptRuleConfiguration config) {
return null == config.getTables() ? new EncryptRuleConfiguration(new LinkedList<>(), config.getEncryptors()) : config;
}
+
+ private EncryptRuleConfiguration getDroppedConfiguration(final ShardingSphereDatabase database, final String itemName) {
+ EncryptRuleConfiguration result = (EncryptRuleConfiguration) database.getRuleMetaData().getSingleRule(EncryptRule.class).getConfiguration();
+ result.getTables().removeIf(each -> each.getName().equals(itemName));
+ return result;
+ }
}
diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/subscriber/MaskTableSubscriber.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/subscriber/MaskTableSubscriber.java
index 3d3345fa101..1c778696ff2 100644
--- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/subscriber/MaskTableSubscriber.java
+++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/subscriber/MaskTableSubscriber.java
@@ -54,8 +54,8 @@ public final class MaskTableSubscriber implements RuleChangedSubscriber {
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- MaskTableRuleConfiguration toBeChangedConfig = new YamlMaskTableRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlMaskTableRuleConfiguration.class));
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ MaskTableRuleConfiguration toBeChangedConfig = new YamlMaskTableRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlMaskTableRuleConfiguration.class));
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
MaskRuleConfiguration config = getConfiguration(database, toBeChangedConfig);
contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingDataSourceSubscriber.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingDataSourceSubscriber.java
index d1c89c7bcb3..972f53f5537 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingDataSourceSubscriber.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingDataSourceSubscriber.java
@@ -57,8 +57,8 @@ public final class ReadwriteSplittingDataSourceSubscriber implements RuleChanged
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- ReadwriteSplittingDataSourceRuleConfiguration toBeChangedConfig = swapDataSource(event.getItemName(), yamlContext);
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ ReadwriteSplittingDataSourceRuleConfiguration toBeChangedConfig = swapDataSource(event.getItemName(), yamlContent);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
ReadwriteSplittingRuleConfiguration config = getConfiguration(database, toBeChangedConfig);
contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
@@ -102,8 +102,8 @@ public final class ReadwriteSplittingDataSourceSubscriber implements RuleChanged
return result;
}
- private ReadwriteSplittingDataSourceRuleConfiguration swapDataSource(final String name, final String yamlContext) {
- YamlReadwriteSplittingDataSourceRuleConfiguration yamlDataSourceRuleConfig = YamlEngine.unmarshal(yamlContext, YamlReadwriteSplittingDataSourceRuleConfiguration.class);
+ private ReadwriteSplittingDataSourceRuleConfiguration swapDataSource(final String name, final String yamlContent) {
+ YamlReadwriteSplittingDataSourceRuleConfiguration yamlDataSourceRuleConfig = YamlEngine.unmarshal(yamlContent, YamlReadwriteSplittingDataSourceRuleConfiguration.class);
return new ReadwriteSplittingDataSourceRuleConfiguration(name, yamlDataSourceRuleConfig.getWriteDataSourceName(), yamlDataSourceRuleConfig.getReadDataSourceNames(),
getTransactionalReadQueryStrategy(yamlDataSourceRuleConfig), yamlDataSourceRuleConfig.getLoadBalancerName());
}
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingLoadBalanceSubscriber.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingLoadBalanceSubscriber.java
index 038c129956e..c501021386c 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingLoadBalanceSubscriber.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingLoadBalanceSubscriber.java
@@ -98,7 +98,7 @@ public final class ReadwriteSplittingLoadBalanceSubscriber implements RuleChange
return result;
}
- private AlgorithmConfiguration swapToAlgorithmConfig(final String yamlContext) {
- return new YamlAlgorithmConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlAlgorithmConfiguration.class));
+ private AlgorithmConfiguration swapToAlgorithmConfig(final String yamlContent) {
+ return new YamlAlgorithmConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlAlgorithmConfiguration.class));
}
}
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowAlgorithmSubscriber.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowAlgorithmSubscriber.java
index e6d3d0d9865..216a6588f17 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowAlgorithmSubscriber.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowAlgorithmSubscriber.java
@@ -82,7 +82,7 @@ public final class ShadowAlgorithmSubscriber implements RuleChangedSubscriber {
contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
}
- private AlgorithmConfiguration swapToAlgorithmConfig(final String yamlContext) {
- return new YamlAlgorithmConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlAlgorithmConfiguration.class));
+ private AlgorithmConfiguration swapToAlgorithmConfig(final String yamlContent) {
+ return new YamlAlgorithmConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlAlgorithmConfiguration.class));
}
}
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
index d00e76d8455..cdf1dba2d91 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
@@ -50,8 +50,8 @@ public final class ShadowDataSourceSubscriber implements RuleChangedSubscriber {
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- ShadowDataSourceConfiguration toBeChangedConfig = swapShadowDataSourceRuleConfig(event.getItemName(), yamlContext);
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ ShadowDataSourceConfiguration toBeChangedConfig = swapShadowDataSourceRuleConfig(event.getItemName(), yamlContent);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
ShadowRuleConfiguration config = database.getRuleMetaData().findSingleRule(ShadowRule.class)
.map(optional -> (ShadowRuleConfiguration) optional.getConfiguration()).orElseGet(ShadowRuleConfiguration::new);
@@ -77,8 +77,8 @@ public final class ShadowDataSourceSubscriber implements RuleChangedSubscriber {
contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
}
- private ShadowDataSourceConfiguration swapShadowDataSourceRuleConfig(final String dataSourceName, final String yamlContext) {
- YamlShadowDataSourceConfiguration yamlConfig = YamlEngine.unmarshal(yamlContext, YamlShadowDataSourceConfiguration.class);
+ private ShadowDataSourceConfiguration swapShadowDataSourceRuleConfig(final String dataSourceName, final String yamlContent) {
+ YamlShadowDataSourceConfiguration yamlConfig = YamlEngine.unmarshal(yamlContent, YamlShadowDataSourceConfiguration.class);
return new ShadowDataSourceConfiguration(dataSourceName, yamlConfig.getProductionDataSourceName(), yamlConfig.getShadowDataSourceName());
}
}
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowTableSubscriber.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowTableSubscriber.java
index 9846f2d5cf2..64016c5aa97 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowTableSubscriber.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowTableSubscriber.java
@@ -51,8 +51,8 @@ public final class ShadowTableSubscriber implements RuleChangedSubscriber {
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- ShadowTableConfiguration toBeChangedConfig = new YamlShadowTableConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlShadowTableConfiguration.class));
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ ShadowTableConfiguration toBeChangedConfig = new YamlShadowTableConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShadowTableConfiguration.class));
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
ShadowRuleConfiguration config = database.getRuleMetaData().findSingleRule(ShadowRule.class)
.map(optional -> (ShadowRuleConfiguration) optional.getConfiguration()).orElseGet(ShadowRuleConfiguration::new);
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingCacheSubscriber.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingCacheSubscriber.java
index ccef12146bd..9a049fa75b3 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingCacheSubscriber.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingCacheSubscriber.java
@@ -51,8 +51,8 @@ public final class ShardingCacheSubscriber implements RuleChangedSubscriber {
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- ShardingCacheConfiguration toBeChangedConfig = new YamlShardingCacheConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlShardingCacheConfiguration.class));
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ ShardingCacheConfiguration toBeChangedConfig = new YamlShardingCacheConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShardingCacheConfiguration.class));
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
ShardingRuleConfiguration config = database.getRuleMetaData().findSingleRule(ShardingRule.class)
.map(optional -> (ShardingRuleConfiguration) optional.getConfiguration()).orElseGet(ShardingRuleConfiguration::new);
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingDefaultStrategySubscriber.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingDefaultStrategySubscriber.java
index 52bac4c16e2..a2d040348c5 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingDefaultStrategySubscriber.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingDefaultStrategySubscriber.java
@@ -65,8 +65,8 @@ public final class ShardingDefaultStrategySubscriber implements RuleChangedSubsc
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- ShardingStrategyConfiguration toBeChangedConfig = new YamlShardingStrategyConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlShardingStrategyConfiguration.class));
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ ShardingStrategyConfiguration toBeChangedConfig = new YamlShardingStrategyConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShardingStrategyConfiguration.class));
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
ShardingRuleConfiguration config = database.getRuleMetaData().findSingleRule(ShardingRule.class)
.map(optional -> (ShardingRuleConfiguration) optional.getConfiguration()).orElseGet(ShardingRuleConfiguration::new);
@@ -100,8 +100,8 @@ public final class ShardingDefaultStrategySubscriber implements RuleChangedSubsc
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- ShardingStrategyConfiguration toBeChangedConfig = new YamlShardingStrategyConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlShardingStrategyConfiguration.class));
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ ShardingStrategyConfiguration toBeChangedConfig = new YamlShardingStrategyConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShardingStrategyConfiguration.class));
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
ShardingRuleConfiguration config = database.getRuleMetaData().findSingleRule(ShardingRule.class)
.map(optional -> (ShardingRuleConfiguration) optional.getConfiguration()).orElseGet(ShardingRuleConfiguration::new);
@@ -135,9 +135,9 @@ public final class ShardingDefaultStrategySubscriber implements RuleChangedSubsc
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
KeyGenerateStrategyConfiguration toBeChangedConfig = new YamlKeyGenerateStrategyConfigurationSwapper().swapToObject(
- YamlEngine.unmarshal(yamlContext, YamlKeyGenerateStrategyConfiguration.class));
+ YamlEngine.unmarshal(yamlContent, YamlKeyGenerateStrategyConfiguration.class));
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
ShardingRuleConfiguration config = database.getRuleMetaData().findSingleRule(ShardingRule.class)
.map(optional -> (ShardingRuleConfiguration) optional.getConfiguration()).orElseGet(ShardingRuleConfiguration::new);
@@ -171,9 +171,9 @@ public final class ShardingDefaultStrategySubscriber implements RuleChangedSubsc
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
ShardingAuditStrategyConfiguration toBeChangedConfig = new YamlShardingAuditStrategyConfigurationSwapper().swapToObject(
- YamlEngine.unmarshal(yamlContext, YamlShardingAuditStrategyConfiguration.class));
+ YamlEngine.unmarshal(yamlContent, YamlShardingAuditStrategyConfiguration.class));
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
ShardingRuleConfiguration config = database.getRuleMetaData().findSingleRule(ShardingRule.class)
.map(optional -> (ShardingRuleConfiguration) optional.getConfiguration()).orElseGet(ShardingRuleConfiguration::new);
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/event/rule/create/CreateNamedRuleItemEvent.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/event/rule/create/CreateNamedRuleItemEvent.java
deleted file mode 100644
index 526a8b60e2d..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/event/rule/create/CreateNamedRuleItemEvent.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.event.rule.create;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * Create named rule item event.
- */
-@RequiredArgsConstructor
-@Getter
-public class CreateNamedRuleItemEvent implements CreateRuleItemEvent {
-
- private final String databaseName;
-
- private final String itemName;
-
- private final String activeVersionKey;
-
- private final String activeVersion;
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/event/rule/create/CreateRuleItemEvent.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/event/rule/create/CreateRuleItemEvent.java
deleted file mode 100644
index 82c781777e0..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/event/rule/create/CreateRuleItemEvent.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.event.rule.create;
-
-import org.apache.shardingsphere.infra.rule.event.rule.RuleItemChangedEvent;
-
-/**
- * Create rule item event.
- */
-public interface CreateRuleItemEvent extends RuleItemChangedEvent {
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/event/rule/create/CreateUniqueRuleItemEvent.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/event/rule/create/CreateUniqueRuleItemEvent.java
deleted file mode 100644
index ee083630ba9..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/event/rule/create/CreateUniqueRuleItemEvent.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.event.rule.create;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * Create unique rule item event.
- */
-@RequiredArgsConstructor
-@Getter
-public class CreateUniqueRuleItemEvent implements CreateRuleItemEvent {
-
- private final String databaseName;
-
- private final String activeVersionKey;
-
- private final String activeVersion;
-}
diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/NewPropertiesPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/NewPropertiesPersistService.java
index 97270411402..46e475cdd02 100644
--- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/NewPropertiesPersistService.java
+++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/NewPropertiesPersistService.java
@@ -66,8 +66,8 @@ public final class NewPropertiesPersistService implements GlobalPersistService<P
@Override
public Properties load() {
- String yamlContext = repository.getDirectly(NewGlobalNode.getPropsVersionNode(getActiveVersion()));
- return Strings.isNullOrEmpty(yamlContext) ? new Properties() : YamlEngine.unmarshal(yamlContext, Properties.class);
+ String yamlContent = repository.getDirectly(NewGlobalNode.getPropsVersionNode(getActiveVersion()));
+ return Strings.isNullOrEmpty(yamlContent) ? new Properties() : YamlEngine.unmarshal(yamlContent, Properties.class);
}
private String getActiveVersion() {
diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
index 8633bb69d4a..5c751a1971a 100644
--- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
+++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
@@ -49,10 +49,7 @@ public final class SingleRuleConfigurationDecorator implements RuleConfiguration
@Override
public SingleRuleConfiguration decorate(final String databaseName, final Map<String, DataSource> dataSources,
final Collection<ShardingSphereRule> builtRules, final SingleRuleConfiguration ruleConfig) {
- SingleRuleConfiguration result = new SingleRuleConfiguration();
- result.getTables().addAll(decorateTables(databaseName, dataSources, new LinkedList<>(builtRules), ruleConfig.getTables()));
- ruleConfig.getDefaultDataSource().ifPresent(result::setDefaultDataSource);
- return result;
+ return new SingleRuleConfiguration(decorateTables(databaseName, dataSources, new LinkedList<>(builtRules), ruleConfig.getTables()), ruleConfig.getDefaultDataSource().orElse(null));
}
private Collection<String> decorateTables(final String databaseName, final Map<String, DataSource> dataSources, final Collection<ShardingSphereRule> builtRules, final Collection<String> tables) {
diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/subscriber/SingleTableSubscriber.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/subscriber/SingleTableSubscriber.java
index f343a21778f..e7fd27523d5 100644
--- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/subscriber/SingleTableSubscriber.java
+++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/subscriber/SingleTableSubscriber.java
@@ -29,8 +29,7 @@ import org.apache.shardingsphere.single.event.config.AlterSingleTableEvent;
import org.apache.shardingsphere.single.event.config.DropSingleTableEvent;
import org.apache.shardingsphere.single.rule.SingleRule;
import org.apache.shardingsphere.single.yaml.config.pojo.YamlSingleRuleConfiguration;
-
-import java.util.Optional;
+import org.apache.shardingsphere.single.yaml.config.swapper.YamlSingleRuleConfigurationSwapper;
/**
* Single table subscriber.
@@ -51,19 +50,11 @@ public final class SingleTableSubscriber implements RuleChangedSubscriber {
if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
return;
}
- String yamlContext = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
- SingleRuleConfiguration toBeChangedConfig = swapSingleTableRuleConfig(yamlContext);
+ String yamlContent = contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion());
+ SingleRuleConfiguration toBeChangedConfig = getToBeChangedConfiguration(yamlContent);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
- Optional<SingleRule> rule = database.getRuleMetaData().findSingleRule(SingleRule.class);
- SingleRuleConfiguration config;
- if (rule.isPresent()) {
- config = rule.get().getConfiguration();
- config.getTables().clear();
- config.getTables().addAll(toBeChangedConfig.getTables());
- } else {
- config = new SingleRuleConfiguration(toBeChangedConfig.getTables(), toBeChangedConfig.getDefaultDataSource().orElse(null));
- }
- contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
+ SingleRuleConfiguration changedConfig = getChangedConfiguration(toBeChangedConfig, database);
+ contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), changedConfig));
}
/**
@@ -77,19 +68,26 @@ public final class SingleTableSubscriber implements RuleChangedSubscriber {
return;
}
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
- SingleRuleConfiguration config = database.getRuleMetaData().getSingleRule(SingleRule.class).getConfiguration();
- config.getTables().clear();
- config.setDefaultDataSource(null);
- contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
+ SingleRuleConfiguration droppedConfig = getDroppedConfiguration(database);
+ contextManager.getInstanceContext().getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), droppedConfig));
}
- private SingleRuleConfiguration swapSingleTableRuleConfig(final String yamlContent) {
- SingleRuleConfiguration result = new SingleRuleConfiguration();
- YamlSingleRuleConfiguration yamlSingleRuleConfig = YamlEngine.unmarshal(yamlContent, YamlSingleRuleConfiguration.class);
- if (null != yamlSingleRuleConfig.getTables()) {
- result.getTables().addAll(yamlSingleRuleConfig.getTables());
- }
- result.setDefaultDataSource(yamlSingleRuleConfig.getDefaultDataSource());
+ private SingleRuleConfiguration getToBeChangedConfiguration(final String yamlContent) {
+ return new YamlSingleRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlSingleRuleConfiguration.class));
+ }
+
+ private SingleRuleConfiguration getChangedConfiguration(final SingleRuleConfiguration toBeChangedConfig, final ShardingSphereDatabase database) {
+ SingleRuleConfiguration result = database.getRuleMetaData().findSingleRule(SingleRule.class).map(SingleRule::getConfiguration).orElseGet(SingleRuleConfiguration::new);
+ result.getTables().clear();
+ result.getTables().addAll(toBeChangedConfig.getTables());
+ toBeChangedConfig.getDefaultDataSource().ifPresent(optional -> result.setDefaultDataSource(toBeChangedConfig.getDefaultDataSource().get()));
+ return result;
+ }
+
+ private SingleRuleConfiguration getDroppedConfiguration(final ShardingSphereDatabase database) {
+ SingleRuleConfiguration result = database.getRuleMetaData().getSingleRule(SingleRule.class).getConfiguration();
+ result.getTables().clear();
+ result.setDefaultDataSource(null);
return result;
}
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/StorageNodeStatusService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/StorageNodeStatusService.java
index 79ba7039b04..a2f0710c295 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/StorageNodeStatusService.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/StorageNodeStatusService.java
@@ -47,9 +47,9 @@ public final class StorageNodeStatusService {
Collection<String> storageNodes = repository.getChildrenKeys(StorageNode.getRootPath());
Map<String, StorageNodeDataSource> result = new HashMap<>(storageNodes.size(), 1F);
storageNodes.forEach(each -> {
- String yamlContext = repository.getDirectly(StorageNode.getStorageNodesDataSourcePath(each));
- if (!Strings.isNullOrEmpty(yamlContext)) {
- result.put(each, new YamlStorageNodeDataSourceSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlStorageNodeDataSource.class)));
+ String yamlContent = repository.getDirectly(StorageNode.getStorageNodesDataSourcePath(each));
+ if (!Strings.isNullOrEmpty(yamlContent)) {
+ result.put(each, new YamlStorageNodeDataSourceSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlStorageNodeDataSource.class)));
}
});
return result;