This is an automated email from the ASF dual-hosted git repository.
kimmking 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 b99ae48 Rename event.shardingSchemaName to schemaName (#7109)
b99ae48 is described below
commit b99ae482ba38bd4ef1e23602915f6cae1c696fd2
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 27 21:29:22 2020 +0800
Rename event.shardingSchemaName to schemaName (#7109)
* Refactor OrchestrationSchemaContexts
* Refactor OrchestrationSchemaContexts
* Refactor OrchestrationSchemaContexts
* Refactor OrchestrationSchemaContexts
* Refactor OrchestrationSchemaContexts
* Refactor OrchestrationSchemaContexts
* Rename event.shardingSchemaName to schemaName
---
.../event/datasource/DataSourceChangedEvent.java | 2 +-
.../common/event/rule/EncryptRuleChangedEvent.java | 2 +-
.../event/rule/MasterSlaveRuleChangedEvent.java | 2 +-
.../event/rule/RuleConfigurationsChangedEvent.java | 2 +-
.../common/event/rule/ShadowRuleChangedEvent.java | 2 +-
.../config/listener/SchemaChangedListenerTest.java | 8 +--
.../core/schema/OrchestrationSchemaContexts.java | 80 +++++++++++-----------
7 files changed, 49 insertions(+), 49 deletions(-)
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/datasource/DataSourceChangedEvent.java
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/datasource/DataSourceChangedE
[...]
index 941cb70..ece153e 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/datasource/DataSourceChangedEvent.java
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/datasource/DataSourceChangedEvent.java
@@ -31,7 +31,7 @@ import java.util.Map;
@Getter
public final class DataSourceChangedEvent implements OrchestrationEvent {
- private final String shardingSchemaName;
+ private final String schemaName;
private final Map<String, DataSourceConfiguration>
dataSourceConfigurations;
}
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/EncryptRuleChangedEvent.java
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/EncryptRuleChangedEvent.java
index ec2bacc..80f6d8f 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/EncryptRuleChangedEvent.java
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/EncryptRuleChangedEvent.java
@@ -29,7 +29,7 @@ import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEv
@Getter
public final class EncryptRuleChangedEvent implements OrchestrationEvent {
- private final String shardingSchemaName;
+ private final String schemaName;
private final EncryptRuleConfiguration encryptRuleConfiguration;
}
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/MasterSlaveRuleChangedEvent.java
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/MasterSlaveRuleChangedEvent.java
index 81bb59a..1d6d7f9 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/MasterSlaveRuleChangedEvent.java
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/MasterSlaveRuleChangedEvent.java
@@ -29,7 +29,7 @@ import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEv
@Getter
public final class MasterSlaveRuleChangedEvent implements OrchestrationEvent {
- private final String shardingSchemaName;
+ private final String schemaName;
private final MasterSlaveRuleConfiguration masterSlaveRuleConfiguration;
}
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/RuleConfigurationsChangedEvent.java
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/RuleConfigurationsChan
[...]
index 820907d..dd0cb00 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/RuleConfigurationsChangedEvent.java
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/RuleConfigurationsChangedEvent.java
@@ -31,7 +31,7 @@ import java.util.Collection;
@Getter
public final class RuleConfigurationsChangedEvent implements
OrchestrationEvent {
- private final String shardingSchemaName;
+ private final String schemaName;
private final Collection<RuleConfiguration> ruleConfigurations;
}
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/ShadowRuleChangedEvent.java
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/ShadowRuleChangedEvent.java
index a9505d7..8639ac9 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/ShadowRuleChangedEvent.java
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/rule/ShadowRuleChangedEvent.java
@@ -29,7 +29,7 @@ import
org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
@Getter
public final class ShadowRuleChangedEvent implements OrchestrationEvent {
- private final String shardingSchemaName;
+ private final String schemaName;
private final ShadowRuleConfiguration shadowRuleConfiguration;
}
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListenerTest.java
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListenerTest.java
index f410933..05b1c53 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListenerTest.java
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListenerTest.java
@@ -85,7 +85,7 @@ public final class SchemaChangedListenerTest {
Optional<OrchestrationEvent> actual =
schemaChangedListener.createOrchestrationEvent(dataChangedEvent);
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(DataSourceChangedEvent.class));
- assertThat(((DataSourceChangedEvent)
actual.get()).getShardingSchemaName(), is("sharding_db"));
+ assertThat(((DataSourceChangedEvent) actual.get()).getSchemaName(),
is("sharding_db"));
}
@Test
@@ -94,7 +94,7 @@ public final class SchemaChangedListenerTest {
DataChangedEvent dataChangedEvent = new
DataChangedEvent("/config/schema/sharding_db/rule", shardingRule,
ChangedType.UPDATED);
Optional<OrchestrationEvent> actual =
schemaChangedListener.createOrchestrationEvent(dataChangedEvent);
assertTrue(actual.isPresent());
- assertThat(((RuleConfigurationsChangedEvent)
actual.get()).getShardingSchemaName(), is("sharding_db"));
+ assertThat(((RuleConfigurationsChangedEvent)
actual.get()).getSchemaName(), is("sharding_db"));
Collection<RuleConfiguration> ruleConfigurations =
((RuleConfigurationsChangedEvent) actual.get()).getRuleConfigurations();
assertThat(ruleConfigurations.size(), is(1));
assertThat(((ShardingRuleConfiguration)
ruleConfigurations.iterator().next()).getTables().size(), is(1));
@@ -107,7 +107,7 @@ public final class SchemaChangedListenerTest {
Optional<OrchestrationEvent> actual =
schemaChangedListener.createOrchestrationEvent(dataChangedEvent);
assertTrue(actual.isPresent());
RuleConfigurationsChangedEvent event =
(RuleConfigurationsChangedEvent) actual.get();
- assertThat(event.getShardingSchemaName(), is("masterslave_db"));
+ assertThat(event.getSchemaName(), is("masterslave_db"));
assertThat(event.getRuleConfigurations().iterator().next(),
instanceOf(MasterSlaveRuleConfiguration.class));
MasterSlaveRuleConfiguration masterSlaveRuleConfig =
(MasterSlaveRuleConfiguration) event.getRuleConfigurations().iterator().next();
assertThat(masterSlaveRuleConfig.getDataSources().iterator().next().getMasterDataSourceName(),
is("master_ds"));
@@ -120,7 +120,7 @@ public final class SchemaChangedListenerTest {
Optional<OrchestrationEvent> actual =
schemaChangedListener.createOrchestrationEvent(dataChangedEvent);
assertTrue(actual.isPresent());
RuleConfigurationsChangedEvent event =
(RuleConfigurationsChangedEvent) actual.get();
- assertThat(event.getShardingSchemaName(), is("encrypt_db"));
+ assertThat(event.getSchemaName(), is("encrypt_db"));
assertThat(event.getRuleConfigurations().iterator().next(),
instanceOf(EncryptRuleConfiguration.class));
EncryptRuleConfiguration encryptRuleConfig =
(EncryptRuleConfiguration) event.getRuleConfigurations().iterator().next();
assertThat(encryptRuleConfig.getEncryptors().size(), is(1));
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
index aefc8ca..271723d 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
@@ -198,63 +198,63 @@ public abstract class OrchestrationSchemaContexts
implements SchemaContexts {
*/
@Subscribe
public synchronized void renew(final MetaDataChangedEvent event) {
- Map<String, SchemaContext> schemaContexts = new
HashMap<>(this.schemaContexts.getSchemaContexts().size());
- for (Entry<String, SchemaContext> entry :
this.schemaContexts.getSchemaContexts().entrySet()) {
- if (event.getSchemaNames().contains(entry.getKey())) {
- schemaContexts.put(entry.getKey(), new
SchemaContext(entry.getValue().getName(),
-
getChangedShardingSphereSchema(entry.getValue().getSchema(),
event.getRuleSchemaMetaData()), entry.getValue().getRuntimeContext()));
- } else {
- schemaContexts.put(entry.getKey(), entry.getValue());
- }
+ Map<String, SchemaContext> newSchemaContexts = new
HashMap<>(schemaContexts.getSchemaContexts().size(), 1);
+ for (Entry<String, SchemaContext> entry :
schemaContexts.getSchemaContexts().entrySet()) {
+ String schemaName = entry.getKey();
+ SchemaContext oldSchemaContext = entry.getValue();
+ SchemaContext newSchemaContext =
event.getSchemaNames().contains(schemaName)
+ ? new SchemaContext(oldSchemaContext.getName(),
getChangedShardingSphereSchema(oldSchemaContext.getSchema(),
event.getRuleSchemaMetaData()), oldSchemaContext.getRuntimeContext())
+ : oldSchemaContext;
+ newSchemaContexts.put(schemaName, newSchemaContext);
}
- this.schemaContexts = new StandardSchemaContexts(schemaContexts,
this.schemaContexts.getAuthentication(), this.schemaContexts.getProps(),
this.schemaContexts.getDatabaseType());
+ schemaContexts = new StandardSchemaContexts(newSchemaContexts,
schemaContexts.getAuthentication(), schemaContexts.getProps(),
schemaContexts.getDatabaseType());
}
/**
* Renew rule configurations.
*
- * @param ruleConfigurationsChangedEvent rule configurations changed event
+ * @param event rule configurations changed event
* @throws SQLException SQL exception
*/
@Subscribe
- public synchronized void renew(final RuleConfigurationsChangedEvent
ruleConfigurationsChangedEvent) throws SQLException {
- Map<String, SchemaContext> schemaContexts = new
HashMap<>(this.schemaContexts.getSchemaContexts());
- String schemaName =
ruleConfigurationsChangedEvent.getShardingSchemaName();
- schemaContexts.remove(schemaName);
- schemaContexts.put(schemaName,
getChangedSchemaContext(this.schemaContexts.getSchemaContexts().get(schemaName),
ruleConfigurationsChangedEvent.getRuleConfigurations()));
- this.schemaContexts = new StandardSchemaContexts(schemaContexts,
this.schemaContexts.getAuthentication(), this.schemaContexts.getProps(),
this.schemaContexts.getDatabaseType());
-
orchestrationFacade.getMetaDataCenter().persistMetaDataCenterNode(schemaName,
schemaContexts.get(schemaName).getSchema().getMetaData().getSchema());
+ public synchronized void renew(final RuleConfigurationsChangedEvent event)
throws SQLException {
+ Map<String, SchemaContext> newSchemaContexts = new
HashMap<>(schemaContexts.getSchemaContexts());
+ String schemaName = event.getSchemaName();
+ newSchemaContexts.remove(schemaName);
+ newSchemaContexts.put(schemaName,
getChangedSchemaContext(schemaContexts.getSchemaContexts().get(schemaName),
event.getRuleConfigurations()));
+ schemaContexts = new StandardSchemaContexts(newSchemaContexts,
schemaContexts.getAuthentication(), schemaContexts.getProps(),
schemaContexts.getDatabaseType());
+
orchestrationFacade.getMetaDataCenter().persistMetaDataCenterNode(schemaName,
newSchemaContexts.get(schemaName).getSchema().getMetaData().getSchema());
}
/**
- * Renew disabled data source names.
+ * Renew data source configuration.
*
- * @param disabledStateChangedEvent disabled state changed event
+ * @param event data source changed event.
+ * @throws Exception exception
*/
@Subscribe
- public synchronized void renew(final DisabledStateChangedEvent
disabledStateChangedEvent) {
- OrchestrationSchema orchestrationSchema =
disabledStateChangedEvent.getOrchestrationSchema();
- Collection<ShardingSphereRule> rules =
schemaContexts.getSchemaContexts().get(orchestrationSchema.getSchemaName()).getSchema().getRules();
- for (ShardingSphereRule each : rules) {
- if (each instanceof StatusContainedRule) {
- ((StatusContainedRule) each).updateRuleStatus(new
DataSourceNameDisabledEvent(orchestrationSchema.getDataSourceName(),
disabledStateChangedEvent.isDisabled()));
- }
- }
+ public synchronized void renew(final DataSourceChangedEvent event) throws
Exception {
+ String schemaName = event.getSchemaName();
+ Map<String, SchemaContext> newSchemaContexts = new
HashMap<>(schemaContexts.getSchemaContexts());
+ newSchemaContexts.remove(schemaName);
+ newSchemaContexts.put(schemaName,
getChangedSchemaContext(schemaContexts.getSchemaContexts().get(schemaName),
event.getDataSourceConfigurations()));
+ schemaContexts = new StandardSchemaContexts(newSchemaContexts,
schemaContexts.getAuthentication(), schemaContexts.getProps(),
schemaContexts.getDatabaseType());
}
/**
- * Renew data source configuration.
+ * Renew disabled data source names.
*
- * @param dataSourceChangedEvent data source changed event.
- * @throws Exception exception
+ * @param event disabled state changed event
*/
@Subscribe
- public synchronized void renew(final DataSourceChangedEvent
dataSourceChangedEvent) throws Exception {
- String schemaName = dataSourceChangedEvent.getShardingSchemaName();
- Map<String, SchemaContext> schemaContexts = new
HashMap<>(this.schemaContexts.getSchemaContexts());
- schemaContexts.remove(schemaName);
- schemaContexts.put(schemaName,
getChangedSchemaContext(this.schemaContexts.getSchemaContexts().get(schemaName),
dataSourceChangedEvent.getDataSourceConfigurations()));
- this.schemaContexts = new StandardSchemaContexts(schemaContexts,
this.schemaContexts.getAuthentication(), this.schemaContexts.getProps(),
this.schemaContexts.getDatabaseType());
+ public synchronized void renew(final DisabledStateChangedEvent event) {
+ OrchestrationSchema orchestrationSchema =
event.getOrchestrationSchema();
+ Collection<ShardingSphereRule> rules =
schemaContexts.getSchemaContexts().get(orchestrationSchema.getSchemaName()).getSchema().getRules();
+ for (ShardingSphereRule each : rules) {
+ if (each instanceof StatusContainedRule) {
+ ((StatusContainedRule) each).updateRuleStatus(new
DataSourceNameDisabledEvent(orchestrationSchema.getDataSourceName(),
event.isDisabled()));
+ }
+ }
}
/**
@@ -305,15 +305,15 @@ public abstract class OrchestrationSchemaContexts
implements SchemaContexts {
oldSchemaContext.getSchema().closeDataSources(deletedDataSources);
oldSchemaContext.getSchema().closeDataSources(modifiedDataSources.keySet());
oldSchemaContext.getRuntimeContext().getTransactionManagerEngine().close();
- Map<String, Map<String, DataSource>> dataSourcesMap =
Collections.singletonMap(oldSchemaContext.getName(),
getNewDataSources(oldSchemaContext.getSchema().getDataSources(),
- deletedDataSources, getAddedDataSources(oldSchemaContext,
newDataSources), modifiedDataSources));
+ Map<String, Map<String, DataSource>> dataSourcesMap =
Collections.singletonMap(oldSchemaContext.getName(),
+
getNewDataSources(oldSchemaContext.getSchema().getDataSources(),
getAddedDataSources(oldSchemaContext, newDataSources), modifiedDataSources,
deletedDataSources));
return new SchemaContextsBuilder(schemaContexts.getDatabaseType(),
dataSourcesMap,
Collections.singletonMap(oldSchemaContext.getName(),
oldSchemaContext.getSchema().getConfigurations()),
schemaContexts.getAuthentication(),
schemaContexts.getProps().getProps()).build().getSchemaContexts().get(oldSchemaContext.getName());
}
- private Map<String, DataSource> getNewDataSources(final Map<String,
DataSource> oldDataSources, final Collection<String> deletedDataSources,
- final Map<String,
DataSource> addedDataSources, final Map<String, DataSource>
modifiedDataSources) {
+ private Map<String, DataSource> getNewDataSources(final Map<String,
DataSource> oldDataSources,
+ final Map<String,
DataSource> addedDataSources, final Map<String, DataSource>
modifiedDataSources, final Collection<String> deletedDataSources) {
Map<String, DataSource> result = new LinkedHashMap<>(oldDataSources);
result.keySet().removeAll(deletedDataSources);
result.keySet().removeAll(modifiedDataSources.keySet());