You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2021/09/18 05:56:13 UTC
[shardingsphere] branch master updated: Refactor StatusNode (#12541)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 c551460 Refactor StatusNode (#12541)
c551460 is described below
commit c551460cdf187cecb18e75135b549a3f0ae999fd
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Sep 18 13:55:36 2021 +0800
Refactor StatusNode (#12541)
* Refactor StatusNode
* Remove ComputeNode
* Fix checkstyle
---
.../registry/status/node/StatusNode.java | 52 +++++++++++-----------
.../status/service/ComputeNodeStatusService.java | 2 +-
.../DataSourceStatusRegistrySubscriber.java | 6 +--
.../watcher/ComputeNodeStateChangedWatcher.java | 2 +-
.../watcher/StorageNodeStateChangedWatcher.java | 3 +-
.../registry/status/node/StatusNodeTest.java | 21 ++++-----
.../DataSourceStatusRegistrySubscriberTest.java | 6 +--
7 files changed, 47 insertions(+), 45 deletions(-)
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
index 65c4fb4..a9c8340 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
@@ -42,62 +42,62 @@ public final class StatusNode {
private static final String PRIVILEGE_NODE = "privilegenode";
/**
- * Get compute node status path.
+ * Get compute node root path.
*
- * @param status compute node status
- * @return compute node path
+ * @return root path of compute node
*/
- public static String getComputeNodeStatusPath(final ComputeNodeStatus status) {
- return String.join("/", "", ROOT_NODE, COMPUTE_NODE, status.name().toLowerCase());
+ public static String getComputeNodeRootPath() {
+ return String.join("/", "", ROOT_NODE, COMPUTE_NODE);
}
/**
- * Get compute node path.
+ * Get compute node status path.
*
- * @return compute node path
+ * @param status status of compute node
+ * @return status path of compute node
*/
- public static String getComputeNodePath() {
- return String.join("/", "", ROOT_NODE, COMPUTE_NODE);
+ public static String getComputeNodeStatusPath(final ComputeNodeStatus status) {
+ return String.join("/", "", ROOT_NODE, COMPUTE_NODE, status.name().toLowerCase());
}
/**
- * Get compute node path.
+ * Get compute node status path.
*
- * @param status compute node status
+ * @param status status of compute node
* @param instanceId instance id
- * @return compute node path
+ * @return status path of compute node
*/
- public static String getComputeNodePath(final ComputeNodeStatus status, final String instanceId) {
+ public static String getComputeNodeStatusPath(final ComputeNodeStatus status, final String instanceId) {
return String.join("/", "", ROOT_NODE, COMPUTE_NODE, status.name().toLowerCase(), instanceId);
}
/**
- * Get storage node status path.
+ * Get storage node root path.
*
- * @param status storage node status
- * @return storage node path
+ * @return root path of storage node
*/
- public static String getStorageNodeStatusPath(final StorageNodeStatus status) {
- return String.join("/", "", ROOT_NODE, STORAGE_NODE, status.name().toLowerCase());
+ public static String getStorageNodeRootPath() {
+ return String.join("/", "", ROOT_NODE, STORAGE_NODE);
}
/**
- * Get storage node path.
+ * Get storage node status path.
*
- * @return storage node path
+ * @param status storage node status
+ * @return status path of storage node
*/
- public static String getStorageNodePath() {
- return String.join("/", "", ROOT_NODE, STORAGE_NODE);
+ public static String getStorageNodeStatusPath(final StorageNodeStatus status) {
+ return String.join("/", "", ROOT_NODE, STORAGE_NODE, status.name().toLowerCase());
}
/**
- * Get storage node path.
+ * Get storage node status path.
*
* @param status storage node status
* @param schema cluster schema
- * @return storage node path
+ * @return status path of storage node
*/
- public static String getStorageNodePath(final StorageNodeStatus status, final ClusterSchema schema) {
+ public static String getStorageNodeStatusPath(final StorageNodeStatus status, final ClusterSchema schema) {
return String.join("/", "", ROOT_NODE, STORAGE_NODE, status.name().toLowerCase(), schema.toString());
}
@@ -109,7 +109,7 @@ public final class StatusNode {
* @return cluster schema
*/
public static Optional<ClusterSchema> findClusterSchema(final StorageNodeStatus status, final String storageNodeFullPath) {
- Pattern pattern = Pattern.compile(getStorageNodePath() + "/" + status.name().toLowerCase() + "/(\\S+)$", Pattern.CASE_INSENSITIVE);
+ Pattern pattern = Pattern.compile(getStorageNodeRootPath() + "/" + status.name().toLowerCase() + "/(\\S+)$", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(storageNodeFullPath);
return matcher.find() ? Optional.of(new ClusterSchema(matcher.group(1))) : Optional.empty();
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/ComputeNodeStatusService.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/ComputeNodeStatusService.java
index 941be76..1d03030 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/ComputeNodeStatusService.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/ComputeNodeStatusService.java
@@ -36,6 +36,6 @@ public final class ComputeNodeStatusService {
* @param instanceId instance ID
*/
public void registerOnline(final String instanceId) {
- repository.persistEphemeral(StatusNode.getComputeNodePath(ComputeNodeStatus.ONLINE, instanceId), "");
+ repository.persistEphemeral(StatusNode.getComputeNodeStatusPath(ComputeNodeStatus.ONLINE, instanceId), "");
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/subscriber/DataSourceStatusRegistrySubscriber.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/subscriber/DataSourceStatusRegistrySu [...]
index 93148a9..bb82f66 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/subscriber/DataSourceStatusRegistrySubscriber.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/subscriber/DataSourceStatusRegistrySubscriber.java
@@ -46,9 +46,9 @@ public final class DataSourceStatusRegistrySubscriber {
@Subscribe
public void update(final DataSourceDisabledEvent event) {
if (event.isDisabled()) {
- repository.persist(StatusNode.getStorageNodePath(StorageNodeStatus.DISABLE, new ClusterSchema(event.getSchemaName(), event.getDataSourceName())), "");
+ repository.persist(StatusNode.getStorageNodeStatusPath(StorageNodeStatus.DISABLE, new ClusterSchema(event.getSchemaName(), event.getDataSourceName())), "");
} else {
- repository.delete(StatusNode.getStorageNodePath(StorageNodeStatus.DISABLE, new ClusterSchema(event.getSchemaName(), event.getDataSourceName())));
+ repository.delete(StatusNode.getStorageNodeStatusPath(StorageNodeStatus.DISABLE, new ClusterSchema(event.getSchemaName(), event.getDataSourceName())));
}
}
@@ -59,6 +59,6 @@ public final class DataSourceStatusRegistrySubscriber {
*/
@Subscribe
public void update(final PrimaryDataSourceChangedEvent event) {
- repository.persist(StatusNode.getStorageNodePath(StorageNodeStatus.PRIMARY, new ClusterSchema(event.getSchemaName(), event.getGroupName())), event.getDataSourceName());
+ repository.persist(StatusNode.getStorageNodeStatusPath(StorageNodeStatus.PRIMARY, new ClusterSchema(event.getSchemaName(), event.getGroupName())), event.getDataSourceName());
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcher.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcher.java
index d60dc90..3ac93b0 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcher.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcher.java
@@ -38,7 +38,7 @@ public final class ComputeNodeStateChangedWatcher implements GovernanceWatcher<S
@Override
public Collection<String> getWatchingKeys() {
- return Collections.singleton(StatusNode.getComputeNodePath());
+ return Collections.singleton(StatusNode.getComputeNodeRootPath());
}
@Override
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java
index 0b0f31a..8906b4c 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEve
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Optional;
/**
@@ -37,7 +38,7 @@ public final class StorageNodeStateChangedWatcher implements GovernanceWatcher<G
@Override
public Collection<String> getWatchingKeys() {
- return Arrays.asList(StatusNode.getStorageNodePath());
+ return Collections.singletonList(StatusNode.getStorageNodeRootPath());
}
@Override
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
index 570c70b..d119eae 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
@@ -31,18 +31,23 @@ import static org.junit.Assert.assertTrue;
public final class StatusNodeTest {
@Test
+ public void assertGetComputeNodeRootPath() {
+ assertThat(StatusNode.getComputeNodeRootPath(), is("/status/compute_nodes"));
+ }
+
+ @Test
public void assertGetComputeNodeStatusPath() {
assertThat(StatusNode.getComputeNodeStatusPath(ComputeNodeStatus.CIRCUIT_BREAKER), is("/status/compute_nodes/circuit_breaker"));
}
@Test
- public void assertGetComputeNodePath() {
- assertThat(StatusNode.getComputeNodePath(), is("/status/compute_nodes"));
+ public void assertGetComputeNodeStatusPathWithInstanceId() {
+ assertThat(StatusNode.getComputeNodeStatusPath(ComputeNodeStatus.ONLINE, "127.0.0.0@3307"), is("/status/compute_nodes/online/127.0.0.0@3307"));
}
@Test
- public void assertGetComputeNodePathWithInstanceId() {
- assertThat(StatusNode.getComputeNodePath(ComputeNodeStatus.ONLINE, "127.0.0.0@3307"), is("/status/compute_nodes/online/127.0.0.0@3307"));
+ public void assertGetStorageNodeRootPath() {
+ assertThat(StatusNode.getStorageNodeRootPath(), is("/status/storage_nodes"));
}
@Test
@@ -51,13 +56,9 @@ public final class StatusNodeTest {
}
@Test
- public void assertGetStorageNodePath() {
- assertThat(StatusNode.getStorageNodePath(), is("/status/storage_nodes"));
- }
-
- @Test
public void assertGetStorageNodePathWithSchema() {
- assertThat(StatusNode.getStorageNodePath(StorageNodeStatus.PRIMARY, new ClusterSchema("replica_query_db.replica_ds_0")), is("/status/storage_nodes/primary/replica_query_db.replica_ds_0"));
+ assertThat(StatusNode.getStorageNodeStatusPath(StorageNodeStatus.PRIMARY, new ClusterSchema("replica_query_db.replica_ds_0")),
+ is("/status/storage_nodes/primary/replica_query_db.replica_ds_0"));
}
@Test
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/subscriber/DataSourceStatusRegistrySubscriberTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/subscriber/DataSourceStatusRegist [...]
index d9df05c..eba3905 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/subscriber/DataSourceStatusRegistrySubscriberTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/subscriber/DataSourceStatusRegistrySubscriberTest.java
@@ -42,7 +42,7 @@ public final class DataSourceStatusRegistrySubscriberTest {
String dataSourceName = "replica_ds_0";
DataSourceDisabledEvent dataSourceDisabledEvent = new DataSourceDisabledEvent(schemaName, dataSourceName, true);
new DataSourceStatusRegistrySubscriber(repository).update(dataSourceDisabledEvent);
- verify(repository).persist(StatusNode.getStorageNodePath(StorageNodeStatus.DISABLE, new ClusterSchema(schemaName, dataSourceName)), "");
+ verify(repository).persist(StatusNode.getStorageNodeStatusPath(StorageNodeStatus.DISABLE, new ClusterSchema(schemaName, dataSourceName)), "");
}
@Test
@@ -51,7 +51,7 @@ public final class DataSourceStatusRegistrySubscriberTest {
String dataSourceName = "replica_ds_0";
DataSourceDisabledEvent dataSourceDisabledEvent = new DataSourceDisabledEvent(schemaName, dataSourceName, false);
new DataSourceStatusRegistrySubscriber(repository).update(dataSourceDisabledEvent);
- verify(repository).delete(StatusNode.getStorageNodePath(StorageNodeStatus.DISABLE, new ClusterSchema(schemaName, dataSourceName)));
+ verify(repository).delete(StatusNode.getStorageNodeStatusPath(StorageNodeStatus.DISABLE, new ClusterSchema(schemaName, dataSourceName)));
}
@Test
@@ -61,6 +61,6 @@ public final class DataSourceStatusRegistrySubscriberTest {
String dataSourceName = "replica_ds_0";
PrimaryDataSourceChangedEvent event = new PrimaryDataSourceChangedEvent(schemaName, groupName, dataSourceName);
new DataSourceStatusRegistrySubscriber(repository).update(event);
- verify(repository).persist(StatusNode.getStorageNodePath(StorageNodeStatus.PRIMARY, new ClusterSchema(schemaName, groupName)), dataSourceName);
+ verify(repository).persist(StatusNode.getStorageNodeStatusPath(StorageNodeStatus.PRIMARY, new ClusterSchema(schemaName, groupName)), dataSourceName);
}
}