You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/05/21 14:13:51 UTC
[shardingsphere] branch master updated: Move data source status
related event subscribe to DataSourceStatusRegistryService (#10428)
This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 b0a9f9e Move data source status related event subscribe to DataSourceStatusRegistryService (#10428)
b0a9f9e is described below
commit b0a9f9eda9bf11c5a44e1c6554396e6d2654e2a7
Author: Liang Zhang <te...@163.com>
AuthorDate: Fri May 21 22:13:29 2021 +0800
Move data source status related event subscribe to DataSourceStatusRegistryService (#10428)
---
.../governance/core/registry/RegistryCenter.java | 23 --------------
.../state/DataSourceStatusRegistryService.java | 35 ++++++++++++++++++++--
.../state/DataSourceStatusRegistryServiceTest.java | 2 ++
3 files changed, 34 insertions(+), 26 deletions(-)
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
index ba78cfa..ea7ff71 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
@@ -58,8 +58,6 @@ import org.apache.shardingsphere.infra.metadata.schema.refresher.event.SchemaAlt
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfigurationConverter;
-import org.apache.shardingsphere.infra.rule.event.impl.DataSourceDisabledEvent;
-import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceEvent;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
@@ -167,27 +165,6 @@ public final class RegistryCenter {
}
/**
- * Persist data source disabled state.
- *
- * @param event data source disabled event
- */
- @Subscribe
- public void renew(final DataSourceDisabledEvent event) {
- String value = event.isDisabled() ? RegistryCenterNodeStatus.DISABLED.toString() : "";
- repository.persist(node.getDataSourcePath(event.getSchemaName(), event.getDataSourceName()), value);
- }
-
- /**
- * Persist primary data source state.
- *
- * @param event primary data source event
- */
- @Subscribe
- public void renew(final PrimaryDataSourceEvent event) {
- repository.persist(node.getPrimaryDataSourcePath(event.getSchemaName(), event.getGroupName()), event.getDataSourceName());
- }
-
- /**
* Persist rule configurations.
*
* @param event rule configurations altered event
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryService.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryService.java
index 4ef9f8e..705c6bc 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryService.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryService.java
@@ -18,10 +18,13 @@
package org.apache.shardingsphere.governance.core.registry.service.state;
import com.google.common.base.Strings;
-import lombok.RequiredArgsConstructor;
+import com.google.common.eventbus.Subscribe;
import org.apache.shardingsphere.governance.core.registry.RegistryCenterNode;
import org.apache.shardingsphere.governance.core.registry.RegistryCenterNodeStatus;
import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
+import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
+import org.apache.shardingsphere.infra.rule.event.impl.DataSourceDisabledEvent;
+import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceEvent;
import java.util.Collection;
import java.util.stream.Collectors;
@@ -29,12 +32,17 @@ import java.util.stream.Collectors;
/**
* Data source status registry service.
*/
-@RequiredArgsConstructor
public final class DataSourceStatusRegistryService {
private final RegistryCenterRepository repository;
- private final RegistryCenterNode node = new RegistryCenterNode();
+ private final RegistryCenterNode node;
+
+ public DataSourceStatusRegistryService(final RegistryCenterRepository repository) {
+ this.repository = repository;
+ node = new RegistryCenterNode();
+ ShardingSphereEventBus.getInstance().register(this);
+ }
/**
* Load disabled data source names.
@@ -54,4 +62,25 @@ public final class DataSourceStatusRegistryService {
private String getDataSourceNodeData(final String schemaName, final String dataSourceName) {
return repository.get(node.getDataSourcePath(schemaName, dataSourceName));
}
+
+ /**
+ * Update data source disabled state.
+ *
+ * @param event data source disabled event
+ */
+ @Subscribe
+ public void update(final DataSourceDisabledEvent event) {
+ String value = event.isDisabled() ? RegistryCenterNodeStatus.DISABLED.toString() : "";
+ repository.persist(node.getDataSourcePath(event.getSchemaName(), event.getDataSourceName()), value);
+ }
+
+ /**
+ * Update primary data source state.
+ *
+ * @param event primary data source event
+ */
+ @Subscribe
+ public void update(final PrimaryDataSourceEvent event) {
+ repository.persist(node.getPrimaryDataSourcePath(event.getSchemaName(), event.getGroupName()), event.getDataSourceName());
+ }
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryServiceTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryServiceTest.java
index b27c1d3..4894cb4 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryServiceTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryServiceTest.java
@@ -56,4 +56,6 @@ public final class DataSourceStatusRegistryServiceTest {
verify(registryCenterRepository).getChildrenKeys(anyString());
verify(registryCenterRepository).get(anyString());
}
+
+ // TODO add update assertions
}