diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNode.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePath.java similarity index 60% rename from kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNode.java rename to kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePath.java index 90aa13e36e530..316df9d13ad51 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNode.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePath.java @@ -21,31 +21,31 @@ import lombok.NoArgsConstructor; /** - * Process node. + * Process node path. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ProcessNode { +public final class ProcessNodePath { - private static final String EXECUTION_NODES = "execution_nodes"; + private static final String ROOT_NODE = "execution_nodes"; /** - * Get process id path. + * Get process ID root path. * - * @param processId process id - * @return execution path + * @param processId process ID + * @return process ID root path */ - public static String getProcessIdPath(final String processId) { - return String.join("/", "", EXECUTION_NODES, processId); + public static String getRootPath(final String processId) { + return String.join("/", "", ROOT_NODE, processId); } /** - * Get process list instance path. + * Get instance process list. * - * @param processId process id - * @param instancePath instance path - * @return execution path + * @param processId process ID + * @param instanceId instance ID + * @return instance process list */ - public static String getProcessListInstancePath(final String processId, final String instancePath) { - return String.join("/", "", EXECUTION_NODES, processId, instancePath); + public static String getInstanceProcessList(final String processId, final String instanceId) { + return String.join("/", getRootPath(processId), instanceId); } } diff --git a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePathTest.java b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePathTest.java new file mode 100644 index 0000000000000..9652e3afbcf78 --- /dev/null +++ b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePathTest.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.metadata.persist.node; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class ProcessNodePathTest { + + @Test + void assertGetRootPath() { + assertThat(ProcessNodePath.getRootPath("foo_process_id"), is("/execution_nodes/foo_process_id")); + } + + @Test + void assertGetInstanceProcessList() { + assertThat(ProcessNodePath.getInstanceProcessList("foo_process_id", "foo_instance_id"), is("/execution_nodes/foo_process_id/foo_instance_id")); + } +} diff --git a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodeTest.java b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodeTest.java index 603077c3f1276..028951dae6c10 100644 --- a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodeTest.java +++ b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodeTest.java @@ -26,12 +26,12 @@ class ProcessNodeTest { @Test void assertGetProcessIdPath() { - assertThat(ProcessNode.getProcessIdPath("ae7d352a-ee1f-3cd6-8631-cd9e93b70a30"), is("/execution_nodes/ae7d352a-ee1f-3cd6-8631-cd9e93b70a30")); + assertThat(ProcessNodePath.getRootPath("ae7d352a-ee1f-3cd6-8631-cd9e93b70a30"), is("/execution_nodes/ae7d352a-ee1f-3cd6-8631-cd9e93b70a30")); } @Test void assertGetProcessListInstancePath() { - assertThat(ProcessNode.getProcessListInstancePath("ae7d352a-ee1f-3cd6-8631-cd9e93b70a30", "proxy_127.0.0.1@983481"), + assertThat(ProcessNodePath.getInstanceProcessList("ae7d352a-ee1f-3cd6-8631-cd9e93b70a30", "proxy_127.0.0.1@983481"), is("/execution_nodes/ae7d352a-ee1f-3cd6-8631-cd9e93b70a30/proxy_127.0.0.1@983481")); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/ClusterProcessPersistCoordinator.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/ClusterProcessPersistCoordinator.java index bc71eb39fa4b6..eb8d0a2aa2803 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/ClusterProcessPersistCoordinator.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/ClusterProcessPersistCoordinator.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.executor.sql.process.yaml.swapper.YamlProcessListSwapper; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.metadata.persist.node.ComputeNodePath; -import org.apache.shardingsphere.metadata.persist.node.ProcessNode; +import org.apache.shardingsphere.metadata.persist.node.ProcessNodePath; import org.apache.shardingsphere.mode.persist.coordinator.ProcessPersistCoordinator; import org.apache.shardingsphere.mode.spi.PersistRepository; @@ -43,7 +43,7 @@ public final class ClusterProcessPersistCoordinator implements ProcessPersistCoo public void reportLocalProcesses(final String instanceId, final String taskId) { Collection processes = ProcessRegistry.getInstance().listAll(); if (!processes.isEmpty()) { - repository.persist(ProcessNode.getProcessListInstancePath(taskId, instanceId), YamlEngine.marshal(swapper.swapToYamlConfiguration(processes))); + repository.persist(ProcessNodePath.getInstanceProcessList(taskId, instanceId), YamlEngine.marshal(swapper.swapToYamlConfiguration(processes))); } repository.delete(ComputeNodePath.getShowProcessListTriggerPath(instanceId, taskId)); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java index f368b9a326761..cc783b111e17f 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.metadata.persist.node.ComputeNodePath; -import org.apache.shardingsphere.metadata.persist.node.ProcessNode; +import org.apache.shardingsphere.metadata.persist.node.ProcessNodePath; import org.apache.shardingsphere.mode.persist.service.divided.ProcessPersistService; import org.apache.shardingsphere.mode.spi.PersistRepository; @@ -53,7 +53,7 @@ public Collection getProcessList() { isCompleted = ProcessOperationLockRegistry.getInstance().waitUntilReleaseReady(taskId, () -> isReady(triggerPaths)); return getShowProcessListData(taskId); } finally { - repository.delete(ProcessNode.getProcessIdPath(taskId)); + repository.delete(ProcessNodePath.getRootPath(taskId)); if (!isCompleted) { triggerPaths.forEach(repository::delete); } @@ -62,8 +62,8 @@ public Collection getProcessList() { private Collection getShowProcessListData(final String taskId) { YamlProcessList yamlProcessList = new YamlProcessList(); - for (String each : repository.getChildrenKeys(ProcessNode.getProcessIdPath(taskId)).stream() - .map(each -> repository.query(ProcessNode.getProcessListInstancePath(taskId, each))).collect(Collectors.toList())) { + for (String each : repository.getChildrenKeys(ProcessNodePath.getRootPath(taskId)).stream() + .map(each -> repository.query(ProcessNodePath.getInstanceProcessList(taskId, each))).collect(Collectors.toList())) { yamlProcessList.getProcesses().addAll(YamlEngine.unmarshal(each, YamlProcessList.class).getProcesses()); } return new YamlProcessListSwapper().swapToObject(yamlProcessList);