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 fc75a14 Modify event type for drop resource (#8972)
fc75a14 is described below
commit fc75a14d2e60ee08de7fe04da007c2c2a1c45945
Author: Haoran Meng <[email protected]>
AuthorDate: Mon Jan 11 11:50:32 2021 +0800
Modify event type for drop resource (#8972)
---
.../governance/core/config/ConfigCenter.java | 8 +++--
.../model/datasource/DataSourceAlteredEvent.java | 36 ++++++++++++++++++++++
.../governance/core/config/ConfigCenterTest.java | 11 ++++++-
.../rdl/impl/DropResourceBackendHandler.java | 6 ++--
4 files changed, 54 insertions(+), 7 deletions(-)
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/ConfigCenter.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/ConfigCenter.java
index 5d4edf6..5d12300 100644
---
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/ConfigCenter.java
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/ConfigCenter.java
@@ -23,7 +23,7 @@ import com.google.common.base.Strings;
import com.google.common.eventbus.Subscribe;
import
org.apache.shardingsphere.governance.core.config.checker.RuleConfigurationChecker;
import
org.apache.shardingsphere.governance.core.config.checker.RuleConfigurationCheckerFactory;
-import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceChangedEvent;
+import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceAlteredEvent;
import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourcePersistEvent;
import
org.apache.shardingsphere.governance.core.event.model.rule.RuleConfigurationCachedEvent;
import
org.apache.shardingsphere.governance.core.event.model.rule.RuleConfigurationsAlteredEvent;
@@ -109,6 +109,7 @@ public final class ConfigCenter {
/**
* persist data source configurations.
+ *
* @param event Data source event.
*/
@Subscribe
@@ -118,10 +119,11 @@ public final class ConfigCenter {
/**
* Change data source configurations.
- * @param event Data source event.
+ *
+ * @param event Data source altered event.
*/
@Subscribe
- public synchronized void renew(final DataSourceChangedEvent event) {
+ public synchronized void renew(final DataSourceAlteredEvent event) {
persistDataSourceConfigurations(event.getSchemaName(),
event.getDataSourceConfigurations());
}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/event/model/datasource/DataSourceAlteredEvent.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/event/model/datasource/DataSourceAlteredEvent.java
new file mode 100644
index 0000000..320547b
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/event/model/datasource/DataSourceAlteredEvent.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.governance.core.event.model.datasource;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
+import java.util.Map;
+
+/**
+ * Data source altered event.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class DataSourceAlteredEvent {
+
+ private final String schemaName;
+
+ private final Map<String, DataSourceConfiguration>
dataSourceConfigurations;
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/config/ConfigCenterTest.java
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/config/ConfigCenterTest.java
index 3aed784..80a8311 100644
---
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/config/ConfigCenterTest.java
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/config/ConfigCenterTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.governance.core.config;
import lombok.SneakyThrows;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceAlteredEvent;
import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourcePersistEvent;
import
org.apache.shardingsphere.governance.core.event.model.rule.RuleConfigurationsPersistEvent;
import
org.apache.shardingsphere.governance.core.event.model.rule.SwitchRuleConfigurationEvent;
@@ -28,8 +29,8 @@ import
org.apache.shardingsphere.governance.core.yaml.config.schema.YamlSchema;
import
org.apache.shardingsphere.governance.core.yaml.swapper.SchemaYamlSwapper;
import
org.apache.shardingsphere.governance.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
-import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.auth.ShardingSphereUser;
+import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import
org.apache.shardingsphere.infra.auth.builtin.yaml.config.YamlAuthenticationConfiguration;
import
org.apache.shardingsphere.infra.auth.builtin.yaml.swapper.AuthenticationYamlSwapper;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -593,4 +594,12 @@ public final class ConfigCenterTest {
verify(configurationRepository).persist(eq("/metadata/sharding_db/rule"),
anyString());
verify(configCacheManager).deleteCache(eq("/metadata/sharding_db/rule"),
eq("testCacheId"));
}
+
+ @Test
+ public void assertRenewDataSourceAlteredEvent() {
+ DataSourceAlteredEvent event = new
DataSourceAlteredEvent("sharding_db", createDataSourceConfigurations());
+ ConfigCenter configCenter = new ConfigCenter(configurationRepository);
+ configCenter.renew(event);
+
verify(configurationRepository).persist(startsWith("/metadata/sharding_db/datasource"),
anyString());
+ }
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropResourceBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropResourceBackendHandler.java
index b128c18..22fac3b 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropResourceBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropResourceBackendHandler.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropResourceStatement;
-import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceChangedEvent;
+import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceAlteredEvent;
import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -28,8 +28,8 @@ import
org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
import org.apache.shardingsphere.infra.rule.type.DataSourceContainedRule;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
import
org.apache.shardingsphere.proxy.backend.exception.ResourceInUsedException;
+import
org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import
org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
@@ -115,6 +115,6 @@ public final class DropResourceBackendHandler extends
SchemaRequiredBackendHandl
private void post(final String schemaName, final Map<String, DataSource>
resourceMap) {
Map<String, DataSourceConfiguration> datasourceMap =
DataSourceConverter.getDataSourceConfigurationMap(resourceMap);
- ShardingSphereEventBus.getInstance().post(new
DataSourceChangedEvent(schemaName, datasourceMap));
+ ShardingSphereEventBus.getInstance().post(new
DataSourceAlteredEvent(schemaName, datasourceMap));
}
}