This is an automated email from the ASF dual-hosted git repository. zhangliang 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 89f0a92f5be Refactor NodeNodePath (#34722) 89f0a92f5be is described below commit 89f0a92f5be1c944a79b6a65ee1c3869c2ba0ec7 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Wed Feb 19 17:08:07 2025 +0800 Refactor NodeNodePath (#34722) * Refactor NodeNodePath * Refactor NodeNodePath * Refactor NodeNodePath * Refactor NodeNodePath --- ...ittingQualifiedDataSourceChangedSubscriber.java | 2 +- .../mode/state/node/ComputeNodePersistService.java | 32 ++-- .../QualifiedDataSourceStatePersistService.java | 2 +- .../node/path/node/ComputeNodePathGenerator.java | 161 --------------------- ...edDataSourceNodePath.java => NodeNodePath.java} | 8 +- .../compute/ComputeNodePath.java} | 14 +- .../node/{ => compute}/ComputeNodePathParser.java | 4 +- .../compute/label/LabelNodePath.java} | 14 +- .../process/KillProcessTriggerNodePath.java} | 14 +- .../process/ShowProcessListTriggerNodePath.java} | 14 +- .../compute/status/OnlineInstanceNodePath.java} | 16 +- .../compute/status/OnlineTypeNodePath.java} | 14 +- .../compute/status/StatusNodePath.java} | 14 +- .../workerid/ComputeNodeWorkerIDNodePath.java} | 12 +- .../storage/QualifiedDataSourceNodePath.java} | 14 +- .../QualifiedDataSourceNodePathParser.java | 2 +- ...ePath.java => WorkerIDReservationNodePath.java} | 4 +- .../mode/node/path/node/ComputeNodePathTest.java | 90 ------------ .../NodeNodePathTest.java} | 6 +- .../{ => compute}/ComputeNodePathParserTest.java | 2 +- .../compute/ComputeNodePathTest.java} | 6 +- .../compute/label/LabelNodePathTest.java} | 6 +- .../process/KillProcessTriggerNodePathTest.java} | 6 +- .../ShowProcessListTriggerNodePathTest.java} | 6 +- .../status/OnlineInstanceNodePathTest.java} | 8 +- .../compute/status/OnlineTypeNodePathTest.java} | 6 +- .../compute/status/StatusNodePathTest.java} | 6 +- .../workerid/ComputeNodeWorkerIDNodePathTest.java} | 6 +- .../QualifiedDataSourceNodePathParserTest.java | 2 +- .../QualifiedDataSourceNodePathTest.java | 2 +- ...t.java => WorkerIDReservationNodePathTest.java} | 4 +- .../global/type/ComputeNodeOnlineHandler.java | 8 +- .../type/ComputeNodeStateChangedHandler.java | 16 +- .../handler/global/type/KillProcessHandler.java | 10 +- .../type/QualifiedDataSourceChangedHandler.java | 4 +- .../global/type/ShowProcessListHandler.java | 10 +- .../process/ClusterProcessPersistCoordinator.java | 7 +- .../service/ClusterProcessPersistService.java | 12 +- .../workerid/ReservationPersistService.java | 4 +- .../service/ClusterProcessPersistServiceTest.java | 10 +- 40 files changed, 170 insertions(+), 408 deletions(-) diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/deliver/ReadwriteSplittingQualifiedDataSourceChangedSubscriber.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/deliver/ReadwriteSplittingQualifiedDataSourceChangedSubscriber.java index 13fae89ba7c..44a9420e26a 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/deliver/ReadwriteSplittingQualifiedDataSourceChangedSubscriber.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/deliver/ReadwriteSplittingQualifiedDataSourceChangedSubscriber.java @@ -21,7 +21,7 @@ import com.google.common.eventbus.Subscribe; import lombok.Setter; import org.apache.shardingsphere.mode.deliver.DeliverEventSubscriber; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.node.QualifiedDataSourceNodePath; +import org.apache.shardingsphere.mode.node.path.node.storage.QualifiedDataSourceNodePath; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; /** diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/node/ComputeNodePersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/node/ComputeNodePersistService.java index b7d52797ef8..c43e8b91089 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/node/ComputeNodePersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/node/ComputeNodePersistService.java @@ -29,7 +29,12 @@ import org.apache.shardingsphere.infra.instance.yaml.YamlComputeNodeData; import org.apache.shardingsphere.infra.instance.yaml.YamlComputeNodeDataSwapper; import org.apache.shardingsphere.infra.state.instance.InstanceState; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.node.compute.label.LabelNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.status.OnlineInstanceNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.status.OnlineTypeNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.status.StatusNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.workerid.ComputeNodeWorkerIDNodePath; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; import java.util.Arrays; @@ -63,7 +68,7 @@ public final class ComputeNodePersistService { private void persistOnline(final ComputeNodeInstance computeNodeInstance) { ComputeNodeData computeNodeData = new ComputeNodeData( computeNodeInstance.getMetaData().getDatabaseName(), computeNodeInstance.getMetaData().getAttributes(), computeNodeInstance.getMetaData().getVersion()); - repository.persistEphemeral(ComputeNodePathGenerator.getOnlinePath(computeNodeInstance.getMetaData().getId(), computeNodeInstance.getMetaData().getType()), + repository.persistEphemeral(new NodePathGenerator(new OnlineInstanceNodePath(computeNodeInstance.getMetaData().getType())).getPath(computeNodeInstance.getMetaData().getId()), YamlEngine.marshal(new YamlComputeNodeDataSwapper().swapToYamlConfiguration(computeNodeData))); } @@ -73,7 +78,7 @@ public final class ComputeNodePersistService { * @param computeNodeInstance compute node instance */ public void offline(final ComputeNodeInstance computeNodeInstance) { - repository.delete(ComputeNodePathGenerator.getOnlinePath(computeNodeInstance.getMetaData().getId(), computeNodeInstance.getMetaData().getType())); + repository.delete(new NodePathGenerator(new OnlineInstanceNodePath(computeNodeInstance.getMetaData().getType())).getPath(computeNodeInstance.getMetaData().getId())); } /** @@ -87,8 +92,8 @@ public final class ComputeNodePersistService { private Collection<ComputeNodeInstance> loadInstances(final InstanceType instanceType) { Collection<ComputeNodeInstance> result = new LinkedList<>(); - for (String each : repository.getChildrenKeys(ComputeNodePathGenerator.getOnlinePath(instanceType))) { - String value = repository.query(ComputeNodePathGenerator.getOnlinePath(each, instanceType)); + for (String each : repository.getChildrenKeys(new NodePathGenerator(new OnlineTypeNodePath()).getPath(instanceType.name().toLowerCase()))) { + String value = repository.query(new NodePathGenerator(new OnlineInstanceNodePath(instanceType)).getPath(each)); if (!Strings.isNullOrEmpty(value)) { ComputeNodeData computeNodeData = new YamlComputeNodeDataSwapper().swapToObject(YamlEngine.unmarshal(value, YamlComputeNodeData.class)); ComputeNodeInstance instance = loadInstance(InstanceMetaDataFactory.create(each, instanceType, computeNodeData)); @@ -113,12 +118,12 @@ public final class ComputeNodePersistService { } private String loadState(final String instanceId) { - return repository.query(ComputeNodePathGenerator.getStatePath(instanceId)); + return repository.query(new NodePathGenerator(new StatusNodePath()).getPath(instanceId)); } @SuppressWarnings("unchecked") private Collection<String> loadLabels(final String instanceId) { - String yamlContent = repository.query(ComputeNodePathGenerator.getLabelsPath(instanceId)); + String yamlContent = repository.query(new NodePathGenerator(new LabelNodePath()).getPath(instanceId)); return Strings.isNullOrEmpty(yamlContent) ? Collections.emptyList() : YamlEngine.unmarshal(yamlContent, Collection.class); } @@ -129,7 +134,7 @@ public final class ComputeNodePersistService { * @param instanceState instance state */ public void updateState(final String instanceId, final InstanceState instanceState) { - repository.persistEphemeral(ComputeNodePathGenerator.getStatePath(instanceId), instanceState.name()); + repository.persistEphemeral(new NodePathGenerator(new StatusNodePath()).getPath(instanceId), instanceState.name()); } /** @@ -139,7 +144,7 @@ public final class ComputeNodePersistService { * @param labels instance labels */ public void persistLabels(final String instanceId, final Collection<String> labels) { - repository.persistEphemeral(ComputeNodePathGenerator.getLabelsPath(instanceId), YamlEngine.marshal(labels)); + repository.persistEphemeral(new NodePathGenerator(new LabelNodePath()).getPath(instanceId), YamlEngine.marshal(labels)); } /** @@ -149,7 +154,7 @@ public final class ComputeNodePersistService { * @param workerId worker ID */ public void persistWorkerId(final String instanceId, final int workerId) { - repository.persistEphemeral(ComputeNodePathGenerator.getWorkerIdPath(instanceId), String.valueOf(workerId)); + repository.persistEphemeral(new NodePathGenerator(new ComputeNodeWorkerIDNodePath()).getPath(instanceId), String.valueOf(workerId)); } /** @@ -160,7 +165,7 @@ public final class ComputeNodePersistService { */ public Optional<Integer> loadWorkerId(final String instanceId) { try { - String workerId = repository.query(ComputeNodePathGenerator.getWorkerIdPath(instanceId)); + String workerId = repository.query(new NodePathGenerator(new ComputeNodeWorkerIDNodePath()).getPath(instanceId)); return Strings.isNullOrEmpty(workerId) ? Optional.empty() : Optional.of(Integer.valueOf(workerId)); } catch (final NumberFormatException ex) { log.error("Invalid worker id for instance: {}", instanceId); @@ -174,7 +179,8 @@ public final class ComputeNodePersistService { * @return assigned worker IDs */ public Collection<Integer> getAssignedWorkerIds() { - Collection<String> instanceIds = repository.getChildrenKeys(ComputeNodePathGenerator.getWorkerIdRootPath()); - return instanceIds.stream().map(each -> repository.query(ComputeNodePathGenerator.getWorkerIdPath(each))).filter(Objects::nonNull).map(Integer::parseInt).collect(Collectors.toSet()); + Collection<String> instanceIds = repository.getChildrenKeys(new ComputeNodeWorkerIDNodePath().getRootPath()); + return instanceIds.stream() + .map(each -> repository.query(new NodePathGenerator(new ComputeNodeWorkerIDNodePath()).getPath(each))).filter(Objects::nonNull).map(Integer::parseInt).collect(Collectors.toSet()); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/node/QualifiedDataSourceStatePersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/node/QualifiedDataSourceStatePersistService.java index 9276550dabb..c2ddbcfc863 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/node/QualifiedDataSourceStatePersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/node/QualifiedDataSourceStatePersistService.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.state.datasource.qualified.yaml.YamlQuali import org.apache.shardingsphere.infra.state.datasource.qualified.yaml.YamlQualifiedDataSourceStateSwapper; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.node.QualifiedDataSourceNodePath; +import org.apache.shardingsphere.mode.node.path.node.storage.QualifiedDataSourceNodePath; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; import java.util.Collection; diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathGenerator.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathGenerator.java deleted file mode 100644 index 69c9b8f1307..00000000000 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathGenerator.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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.mode.node.path.node; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.shardingsphere.infra.instance.metadata.InstanceType; - -/** - * Compute node path generator. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ComputeNodePathGenerator { - - private static final String ROOT_NODE = "/nodes/compute_nodes"; - - private static final String ONLINE_NODE = "online"; - - private static final String SHOW_PROCESS_LIST_TRIGGER_NODE = "show_process_list_trigger"; - - private static final String KILL_PROCESS_TRIGGER_NODE = "kill_process_trigger"; - - private static final String STATUS_NODE = "status"; - - private static final String WORKER_ID_NODE = "worker_id"; - - private static final String LABELS_NODE = "labels"; - - /** - * Get compute node root path. - * - * @return compute node root path - */ - public static String getRootPath() { - return ROOT_NODE; - } - - /** - * Get online root path. - * - * @return online root path - */ - public static String getOnlineRootPath() { - return String.join("/", getRootPath(), ONLINE_NODE); - } - - /** - * Get online path. - * - * @param instanceType instance type - * @return online path - */ - public static String getOnlinePath(final InstanceType instanceType) { - return String.join("/", getOnlineRootPath(), instanceType.name().toLowerCase()); - } - - /** - * Get online path. - * - * @param instanceId instance ID - * @param instanceType instance type - * @return online path - */ - public static String getOnlinePath(final String instanceId, final InstanceType instanceType) { - return String.join("/", getOnlinePath(instanceType), instanceId); - } - - /** - * Get show process list trigger root path. - * - * @return show process list trigger root path - */ - public static String getShowProcessListTriggerRootPath() { - return String.join("/", ROOT_NODE, SHOW_PROCESS_LIST_TRIGGER_NODE); - } - - /** - * Get show process list trigger path. - * - * @param instanceId instance ID - * @param taskId show process list task ID - * @return show process list trigger path - */ - public static String getShowProcessListTriggerPath(final String instanceId, final String taskId) { - return String.join("/", getShowProcessListTriggerRootPath(), String.join(":", instanceId, taskId)); - } - - /** - * Get kill process trigger root path. - * - * @return kill process trigger root path - */ - public static String getKillProcessTriggerRootPath() { - return String.join("/", ROOT_NODE, KILL_PROCESS_TRIGGER_NODE); - } - - /** - * Get kill process trigger path. - * - * @param instanceId instance ID - * @param processId process ID - * @return kill process trigger path - */ - public static String getKillProcessTriggerPath(final String instanceId, final String processId) { - return String.join("/", getKillProcessTriggerRootPath(), String.join(":", instanceId, processId)); - } - - /** - * Get state path. - * - * @param instanceId instance ID - * @return state path - */ - public static String getStatePath(final String instanceId) { - return String.join("/", ROOT_NODE, STATUS_NODE, instanceId); - } - - /** - * Get worker ID root path. - * - * @return worker ID root path - */ - public static String getWorkerIdRootPath() { - return String.join("/", ROOT_NODE, WORKER_ID_NODE); - } - - /** - * Get worker ID path. - * - * @param instanceId instance ID - * @return worker ID path - */ - public static String getWorkerIdPath(final String instanceId) { - return String.join("/", getWorkerIdRootPath(), instanceId); - } - - /** - * Get labels path. - * - * @param instanceId instance ID - * @return labels path - */ - public static String getLabelsPath(final String instanceId) { - return String.join("/", ROOT_NODE, LABELS_NODE, instanceId); - } -} diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/NodeNodePath.java similarity index 79% rename from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePath.java rename to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/NodeNodePath.java index 8a3a5a8f1e2..3ab380cfc2f 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/NodeNodePath.java @@ -20,16 +20,14 @@ package org.apache.shardingsphere.mode.node.path.node; import org.apache.shardingsphere.mode.node.path.NodePath; /** - * Qualified data source node path. + * Node node path. */ -public final class QualifiedDataSourceNodePath implements NodePath { +public final class NodeNodePath implements NodePath { private static final String ROOT_NODE = "/nodes"; - private static final String QUALIFIED_DATA_SOURCES_NODE = "qualified_data_sources"; - @Override public String getRootPath() { - return String.join("/", ROOT_NODE, QUALIFIED_DATA_SOURCES_NODE); + return ROOT_NODE; } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePath.java similarity index 72% copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePath.java index d21328f2fbc..15b4ade89e3 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePath.java @@ -15,23 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute; import org.apache.shardingsphere.mode.node.path.NodePath; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; +import org.apache.shardingsphere.mode.node.path.node.NodeNodePath; /** - * Worker ID node path. + * Compute node path. */ -public final class WorkerIDNodePath implements NodePath { +public final class ComputeNodePath implements NodePath { - private static final String ROOT_NODE = "worker_id"; + private static final String ROOT_NODE = "compute_nodes"; - private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new NodeNodePath()); @Override public String getRootPath() { - return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + return nodePathGenerator.getPath(ROOT_NODE); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathParser.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePathParser.java similarity index 86% rename from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathParser.java rename to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePathParser.java index 17fa40717cc..9bf48a141ea 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathParser.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePathParser.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.node; +package org.apache.shardingsphere.mode.node.path.node.compute; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -39,7 +39,7 @@ public final class ComputeNodePathParser { * @return found instance ID */ public static Optional<String> findInstanceId(final String computeNodePath) { - Pattern pattern = Pattern.compile(ComputeNodePathGenerator.getRootPath() + "(/status|/worker_id|/labels)" + "/" + INSTANCE_ID_PATTERN + "$", Pattern.CASE_INSENSITIVE); + Pattern pattern = Pattern.compile(new ComputeNodePath().getRootPath() + "(/status|/worker_id|/labels)" + "/" + INSTANCE_ID_PATTERN + "$", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(computeNodePath); return matcher.find() ? Optional.of(matcher.group(2)) : Optional.empty(); } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/label/LabelNodePath.java similarity index 72% copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/label/LabelNodePath.java index d21328f2fbc..bb20bfa9e82 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/label/LabelNodePath.java @@ -15,23 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.label; import org.apache.shardingsphere.mode.node.path.NodePath; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.ComputeNodePath; /** - * Worker ID node path. + * Label node path. */ -public final class WorkerIDNodePath implements NodePath { +public final class LabelNodePath implements NodePath { - private static final String ROOT_NODE = "worker_id"; + private static final String ROOT_NODE = "labels"; - private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ComputeNodePath()); @Override public String getRootPath() { - return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + return nodePathGenerator.getPath(ROOT_NODE); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/process/KillProcessTriggerNodePath.java similarity index 72% copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/process/KillProcessTriggerNodePath.java index d21328f2fbc..c910ec40380 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/process/KillProcessTriggerNodePath.java @@ -15,23 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.process; import org.apache.shardingsphere.mode.node.path.NodePath; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.ComputeNodePath; /** - * Worker ID node path. + * Kill process trigger node path. */ -public final class WorkerIDNodePath implements NodePath { +public final class KillProcessTriggerNodePath implements NodePath { - private static final String ROOT_NODE = "worker_id"; + private static final String ROOT_NODE = "kill_process_trigger"; - private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ComputeNodePath()); @Override public String getRootPath() { - return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + return nodePathGenerator.getPath(ROOT_NODE); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/process/ShowProcessListTriggerNodePath.java similarity index 71% copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/process/ShowProcessListTriggerNodePath.java index d21328f2fbc..9bf1d255193 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/process/ShowProcessListTriggerNodePath.java @@ -15,23 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.process; import org.apache.shardingsphere.mode.node.path.NodePath; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.ComputeNodePath; /** - * Worker ID node path. + * Show process list trigger node path. */ -public final class WorkerIDNodePath implements NodePath { +public final class ShowProcessListTriggerNodePath implements NodePath { - private static final String ROOT_NODE = "worker_id"; + private static final String ROOT_NODE = "show_process_list_trigger"; - private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ComputeNodePath()); @Override public String getRootPath() { - return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + return nodePathGenerator.getPath(ROOT_NODE); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineInstanceNodePath.java similarity index 69% copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineInstanceNodePath.java index d21328f2fbc..8a1c31caa0b 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineInstanceNodePath.java @@ -15,23 +15,25 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.status; +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.mode.node.path.NodePath; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; /** - * Worker ID node path. + * Online instance node path. */ -public final class WorkerIDNodePath implements NodePath { +@RequiredArgsConstructor +public final class OnlineInstanceNodePath implements NodePath { - private static final String ROOT_NODE = "worker_id"; + private final InstanceType instanceType; - private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new OnlineTypeNodePath()); @Override public String getRootPath() { - return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + return nodePathGenerator.getPath(instanceType.name().toLowerCase()); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineTypeNodePath.java similarity index 72% copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineTypeNodePath.java index d21328f2fbc..0d6c8514c95 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineTypeNodePath.java @@ -15,23 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.status; import org.apache.shardingsphere.mode.node.path.NodePath; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.ComputeNodePath; /** - * Worker ID node path. + * Online type node path. */ -public final class WorkerIDNodePath implements NodePath { +public final class OnlineTypeNodePath implements NodePath { - private static final String ROOT_NODE = "worker_id"; + private static final String ROOT_NODE = "online"; - private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ComputeNodePath()); @Override public String getRootPath() { - return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + return nodePathGenerator.getPath(ROOT_NODE); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/status/StatusNodePath.java similarity index 72% copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/status/StatusNodePath.java index d21328f2fbc..4194d236103 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/status/StatusNodePath.java @@ -15,23 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.status; import org.apache.shardingsphere.mode.node.path.NodePath; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.ComputeNodePath; /** - * Worker ID node path. + * Status node path. */ -public final class WorkerIDNodePath implements NodePath { +public final class StatusNodePath implements NodePath { - private static final String ROOT_NODE = "worker_id"; + private static final String ROOT_NODE = "status"; - private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ComputeNodePath()); @Override public String getRootPath() { - return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + return nodePathGenerator.getPath(ROOT_NODE); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/workerid/ComputeNodeWorkerIDNodePath.java similarity index 76% copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/workerid/ComputeNodeWorkerIDNodePath.java index d21328f2fbc..22bc4bea1b7 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/compute/workerid/ComputeNodeWorkerIDNodePath.java @@ -15,23 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.workerid; import org.apache.shardingsphere.mode.node.path.NodePath; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.ComputeNodePath; /** - * Worker ID node path. + * Compute node worker ID node path. */ -public final class WorkerIDNodePath implements NodePath { +public final class ComputeNodeWorkerIDNodePath implements NodePath { private static final String ROOT_NODE = "worker_id"; - private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ComputeNodePath()); @Override public String getRootPath() { - return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + return nodePathGenerator.getPath(ROOT_NODE); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePath.java similarity index 72% copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePath.java index d21328f2fbc..eb6e1d8f908 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePath.java @@ -15,23 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.storage; import org.apache.shardingsphere.mode.node.path.NodePath; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; +import org.apache.shardingsphere.mode.node.path.node.NodeNodePath; /** - * Worker ID node path. + * Qualified data source node path. */ -public final class WorkerIDNodePath implements NodePath { +public final class QualifiedDataSourceNodePath implements NodePath { - private static final String ROOT_NODE = "worker_id"; + private static final String ROOT_NODE = "qualified_data_sources"; - private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new NodeNodePath()); @Override public String getRootPath() { - return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + return nodePathGenerator.getPath(ROOT_NODE); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePathParser.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePathParser.java similarity index 96% rename from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePathParser.java rename to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePathParser.java index c93622c27f4..5a73ec81b06 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePathParser.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePathParser.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.node; +package org.apache.shardingsphere.mode.node.path.node.storage; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDReservationNodePath.java similarity index 93% rename from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java rename to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDReservationNodePath.java index d21328f2fbc..6a70949f0b3 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDReservationNodePath.java @@ -22,9 +22,9 @@ import org.apache.shardingsphere.mode.node.path.NodePathGenerator; import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; /** - * Worker ID node path. + * Worker ID reservation node path. */ -public final class WorkerIDNodePath implements NodePath { +public final class WorkerIDReservationNodePath implements NodePath { private static final String ROOT_NODE = "worker_id"; diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathTest.java deleted file mode 100644 index 15ea5e186e6..00000000000 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.mode.node.path.node; - -import org.apache.shardingsphere.infra.instance.metadata.InstanceType; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -class ComputeNodePathTest { - - @Test - void assertGetRootPath() { - assertThat(ComputeNodePathGenerator.getRootPath(), is("/nodes/compute_nodes")); - } - - @Test - void assertGetOnlineRootPath() { - assertThat(ComputeNodePathGenerator.getOnlineRootPath(), is("/nodes/compute_nodes/online")); - } - - @Test - void assertGetOnlinePathWithInstanceType() { - assertThat(ComputeNodePathGenerator.getOnlinePath(InstanceType.PROXY), is("/nodes/compute_nodes/online/proxy")); - assertThat(ComputeNodePathGenerator.getOnlinePath(InstanceType.JDBC), is("/nodes/compute_nodes/online/jdbc")); - } - - @Test - void assertGetOnlinePathWithInstanceId() { - assertThat(ComputeNodePathGenerator.getOnlinePath("foo_instance_1", InstanceType.PROXY), is("/nodes/compute_nodes/online/proxy/foo_instance_1")); - assertThat(ComputeNodePathGenerator.getOnlinePath("foo_instance_2", InstanceType.JDBC), is("/nodes/compute_nodes/online/jdbc/foo_instance_2")); - } - - @Test - void assertGetShowProcessListTriggerRootPath() { - assertThat(ComputeNodePathGenerator.getShowProcessListTriggerRootPath(), is("/nodes/compute_nodes/show_process_list_trigger")); - } - - @Test - void assertGetShowProcessListTriggerPathWithInstanceId() { - assertThat(ComputeNodePathGenerator.getShowProcessListTriggerPath("foo_instance", "foo_process_id"), is("/nodes/compute_nodes/show_process_list_trigger/foo_instance:foo_process_id")); - assertThat(ComputeNodePathGenerator.getShowProcessListTriggerPath("foo_instance", "foo_process_id"), is("/nodes/compute_nodes/show_process_list_trigger/foo_instance:foo_process_id")); - } - - @Test - void assertGetKillProcessTriggerRootPath() { - assertThat(ComputeNodePathGenerator.getKillProcessTriggerRootPath(), is("/nodes/compute_nodes/kill_process_trigger")); - } - - @Test - void assertGetKillProcessTriggerPathWithInstanceId() { - assertThat(ComputeNodePathGenerator.getKillProcessTriggerPath("foo_instance", "foo_process_id"), is("/nodes/compute_nodes/kill_process_trigger/foo_instance:foo_process_id")); - } - - @Test - void assertGetStatePath() { - assertThat(ComputeNodePathGenerator.getStatePath("foo_instance"), is("/nodes/compute_nodes/status/foo_instance")); - } - - @Test - void assertGetWorkerIdRootPath() { - assertThat(ComputeNodePathGenerator.getWorkerIdRootPath(), is("/nodes/compute_nodes/worker_id")); - } - - @Test - void assertGetWorkerIdPathWithInstanceId() { - assertThat(ComputeNodePathGenerator.getWorkerIdPath("foo_instance"), is("/nodes/compute_nodes/worker_id/foo_instance")); - } - - @Test - void assertGetLabelsPath() { - assertThat(ComputeNodePathGenerator.getLabelsPath("foo_instance"), is("/nodes/compute_nodes/labels/foo_instance")); - } -} diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/NodeNodePathTest.java similarity index 84% copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/NodeNodePathTest.java index 612bd8b3c0c..7691f3bb910 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/NodeNodePathTest.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class NodeNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new NodeNodePath().getRootPath(), is("/nodes")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathParserTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePathParserTest.java similarity index 96% rename from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathParserTest.java rename to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePathParserTest.java index d59314a4d0d..b6cfbfa1034 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/ComputeNodePathParserTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePathParserTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.node; +package org.apache.shardingsphere.mode.node.path.node.compute; import org.junit.jupiter.api.Test; diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePathTest.java similarity index 84% copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePathTest.java index 612bd8b3c0c..e4fdaab9206 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/ComputeNodePathTest.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class ComputeNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new ComputeNodePath().getRootPath(), is("/nodes/compute_nodes")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/label/LabelNodePathTest.java similarity index 84% copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/label/LabelNodePathTest.java index 612bd8b3c0c..e7a999bc5b2 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/label/LabelNodePathTest.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.label; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class LabelNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new LabelNodePath().getRootPath(), is("/nodes/compute_nodes/labels")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/process/KillProcessTriggerNodePathTest.java similarity index 81% copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/process/KillProcessTriggerNodePathTest.java index 612bd8b3c0c..845ad68acdd 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/process/KillProcessTriggerNodePathTest.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.process; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class KillProcessTriggerNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new KillProcessTriggerNodePath().getRootPath(), is("/nodes/compute_nodes/kill_process_trigger")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/process/ShowProcessListTriggerNodePathTest.java similarity index 80% copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/process/ShowProcessListTriggerNodePathTest.java index 612bd8b3c0c..4160d0ab4f2 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/process/ShowProcessListTriggerNodePathTest.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.process; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class ShowProcessListTriggerNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new ShowProcessListTriggerNodePath().getRootPath(), is("/nodes/compute_nodes/show_process_list_trigger")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineInstanceNodePathTest.java similarity index 70% copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineInstanceNodePathTest.java index 612bd8b3c0c..6e8281456c6 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineInstanceNodePathTest.java @@ -15,17 +15,19 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.status; +import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class OnlineInstanceNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new OnlineInstanceNodePath(InstanceType.JDBC).getRootPath(), is("/nodes/compute_nodes/online/jdbc")); + assertThat(new OnlineInstanceNodePath(InstanceType.PROXY).getRootPath(), is("/nodes/compute_nodes/online/proxy")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineTypeNodePathTest.java similarity index 83% copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineTypeNodePathTest.java index 612bd8b3c0c..af293f23d2e 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/status/OnlineTypeNodePathTest.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.status; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class OnlineTypeNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new OnlineTypeNodePath().getRootPath(), is("/nodes/compute_nodes/online")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/status/StatusNodePathTest.java similarity index 84% copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/status/StatusNodePathTest.java index 612bd8b3c0c..1fd5879f951 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/status/StatusNodePathTest.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.status; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class StatusNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new StatusNodePath().getRootPath(), is("/nodes/compute_nodes/status")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/workerid/ComputeNodeWorkerIDNodePathTest.java similarity index 81% copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/workerid/ComputeNodeWorkerIDNodePathTest.java index 612bd8b3c0c..35e8a0480f3 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/compute/workerid/ComputeNodeWorkerIDNodePathTest.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.reservation.workerid; +package org.apache.shardingsphere.mode.node.path.node.compute.workerid; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class ComputeNodeWorkerIDNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new ComputeNodeWorkerIDNodePath().getRootPath(), is("/nodes/compute_nodes/worker_id")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePathParserTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePathParserTest.java similarity index 96% rename from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePathParserTest.java rename to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePathParserTest.java index e3617b2588a..b5e21128ac4 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePathParserTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePathParserTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.node; +package org.apache.shardingsphere.mode.node.path.node.storage; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.junit.jupiter.api.Test; diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePathTest.java similarity index 94% rename from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePathTest.java rename to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePathTest.java index 1a521087b8e..460c3df10d2 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/QualifiedDataSourceNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePathTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.node; +package org.apache.shardingsphere.mode.node.path.node.storage; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDReservationNodePathTest.java similarity index 88% rename from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java rename to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDReservationNodePathTest.java index 612bd8b3c0c..a687e7a2538 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDReservationNodePathTest.java @@ -22,10 +22,10 @@ import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class WorkerIDNodePathTest { +class WorkerIDReservationNodePathTest { @Test void assertGetRootPath() { - assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + assertThat(new WorkerIDReservationNodePath().getRootPath(), is("/reservation/worker_id")); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ComputeNodeOnlineHandler.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ComputeNodeOnlineHandler.java index fba5a38a10b..90367f1fe0a 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ComputeNodeOnlineHandler.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ComputeNodeOnlineHandler.java @@ -25,11 +25,11 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.infra.instance.yaml.YamlComputeNodeData; import org.apache.shardingsphere.infra.instance.yaml.YamlComputeNodeDataSwapper; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; -import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; +import org.apache.shardingsphere.mode.node.path.node.compute.status.OnlineTypeNodePath; import java.util.Arrays; import java.util.Collection; @@ -43,7 +43,7 @@ public final class ComputeNodeOnlineHandler implements GlobalDataChangedEventHan @Override public String getSubscribedKey() { - return ComputeNodePathGenerator.getOnlineRootPath(); + return new OnlineTypeNodePath().getRootPath(); } @Override @@ -67,6 +67,6 @@ public final class ComputeNodeOnlineHandler implements GlobalDataChangedEventHan } private Matcher getInstanceOnlinePathMatcher(final String onlineInstancePath) { - return Pattern.compile(ComputeNodePathGenerator.getOnlineRootPath() + "/([\\S]+)/([\\S]+)$", Pattern.CASE_INSENSITIVE).matcher(onlineInstancePath); + return Pattern.compile(new OnlineTypeNodePath().getRootPath() + "/([\\S]+)/([\\S]+)$", Pattern.CASE_INSENSITIVE).matcher(onlineInstancePath); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ComputeNodeStateChangedHandler.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ComputeNodeStateChangedHandler.java index 513221c3cd3..d720eefc410 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ComputeNodeStateChangedHandler.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ComputeNodeStateChangedHandler.java @@ -24,8 +24,12 @@ import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; -import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator; -import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathParser; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.node.compute.ComputeNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.ComputeNodePathParser; +import org.apache.shardingsphere.mode.node.path.node.compute.label.LabelNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.status.StatusNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.workerid.ComputeNodeWorkerIDNodePath; import java.util.ArrayList; import java.util.Arrays; @@ -38,7 +42,7 @@ public final class ComputeNodeStateChangedHandler implements GlobalDataChangedEv @Override public String getSubscribedKey() { - return ComputeNodePathGenerator.getRootPath(); + return new ComputeNodePath().getRootPath(); } @Override @@ -54,12 +58,12 @@ public final class ComputeNodeStateChangedHandler implements GlobalDataChangedEv @SuppressWarnings("unchecked") private void handle(final ContextManager contextManager, final DataChangedEvent event, final String instanceId) { ComputeNodeInstanceContext computeNodeInstanceContext = contextManager.getComputeNodeInstanceContext(); - if (event.getKey().equals(ComputeNodePathGenerator.getStatePath(instanceId)) && Type.DELETED != event.getType()) { + if (event.getKey().equals(new NodePathGenerator(new StatusNodePath()).getPath(instanceId)) && Type.DELETED != event.getType()) { computeNodeInstanceContext.updateStatus(instanceId, event.getValue()); - } else if (event.getKey().equals(ComputeNodePathGenerator.getLabelsPath(instanceId)) && Type.DELETED != event.getType()) { + } else if (event.getKey().equals(new NodePathGenerator(new LabelNodePath()).getPath(instanceId)) && Type.DELETED != event.getType()) { // TODO labels may be empty computeNodeInstanceContext.updateLabels(instanceId, Strings.isNullOrEmpty(event.getValue()) ? new ArrayList<>() : YamlEngine.unmarshal(event.getValue(), Collection.class)); - } else if (event.getKey().equals(ComputeNodePathGenerator.getWorkerIdPath(instanceId))) { + } else if (event.getKey().equals(new NodePathGenerator(new ComputeNodeWorkerIDNodePath()).getPath(instanceId))) { computeNodeInstanceContext.updateWorkerId(instanceId, Strings.isNullOrEmpty(event.getValue()) ? null : Integer.valueOf(event.getValue())); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/KillProcessHandler.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/KillProcessHandler.java index 5b7fe10cfed..0e991a14ac3 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/KillProcessHandler.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/KillProcessHandler.java @@ -20,12 +20,12 @@ package org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.t import org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException; import org.apache.shardingsphere.infra.executor.sql.process.ProcessRegistry; import org.apache.shardingsphere.infra.executor.sql.process.lock.ProcessOperationLockRegistry; -import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; -import org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.process.ClusterProcessPersistCoordinator; -import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; +import org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.process.ClusterProcessPersistCoordinator; +import org.apache.shardingsphere.mode.node.path.node.compute.process.KillProcessTriggerNodePath; import java.sql.SQLException; import java.util.Arrays; @@ -40,7 +40,7 @@ public final class KillProcessHandler implements GlobalDataChangedEventHandler { @Override public String getSubscribedKey() { - return ComputeNodePathGenerator.getKillProcessTriggerRootPath(); + return new KillProcessTriggerNodePath().getRootPath(); } @Override @@ -72,6 +72,6 @@ public final class KillProcessHandler implements GlobalDataChangedEventHandler { } private Matcher getKillProcessTriggerMatcher(final DataChangedEvent event) { - return Pattern.compile(ComputeNodePathGenerator.getKillProcessTriggerRootPath() + "/([\\S]+):([\\S]+)$", Pattern.CASE_INSENSITIVE).matcher(event.getKey()); + return Pattern.compile(new KillProcessTriggerNodePath().getRootPath() + "/([\\S]+):([\\S]+)$", Pattern.CASE_INSENSITIVE).matcher(event.getKey()); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/QualifiedDataSourceChangedHandler.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/QualifiedDataSourceChangedHandler.java index eec62523f3a..ee57fff9c07 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/QualifiedDataSourceChangedHandler.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/QualifiedDataSourceChangedHandler.java @@ -30,8 +30,8 @@ import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; -import org.apache.shardingsphere.mode.node.path.node.QualifiedDataSourceNodePath; -import org.apache.shardingsphere.mode.node.path.node.QualifiedDataSourceNodePathParser; +import org.apache.shardingsphere.mode.node.path.node.storage.QualifiedDataSourceNodePath; +import org.apache.shardingsphere.mode.node.path.node.storage.QualifiedDataSourceNodePathParser; import java.util.Arrays; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ShowProcessListHandler.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ShowProcessListHandler.java index e5784cd76bf..9fb142357ae 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ShowProcessListHandler.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/ShowProcessListHandler.java @@ -18,12 +18,12 @@ package org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.type; import org.apache.shardingsphere.infra.executor.sql.process.lock.ProcessOperationLockRegistry; -import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; -import org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.process.ClusterProcessPersistCoordinator; -import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; +import org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.process.ClusterProcessPersistCoordinator; +import org.apache.shardingsphere.mode.node.path.node.compute.process.ShowProcessListTriggerNodePath; import java.util.Arrays; import java.util.Collection; @@ -37,7 +37,7 @@ public final class ShowProcessListHandler implements GlobalDataChangedEventHandl @Override public String getSubscribedKey() { - return ComputeNodePathGenerator.getShowProcessListTriggerRootPath(); + return new ShowProcessListTriggerNodePath().getRootPath(); } @Override @@ -66,6 +66,6 @@ public final class ShowProcessListHandler implements GlobalDataChangedEventHandl } private Matcher getShowProcessListTriggerMatcher(final DataChangedEvent event) { - return Pattern.compile(ComputeNodePathGenerator.getShowProcessListTriggerRootPath() + "/([\\S]+):([\\S]+)$", Pattern.CASE_INSENSITIVE).matcher(event.getKey()); + return Pattern.compile(new ShowProcessListTriggerNodePath().getRootPath() + "/([\\S]+):([\\S]+)$", Pattern.CASE_INSENSITIVE).matcher(event.getKey()); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/process/ClusterProcessPersistCoordinator.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/process/ClusterProcessPersistCoordinator.java index 830d2d086cc..402e6c98af8 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/process/ClusterProcessPersistCoordinator.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/process/ClusterProcessPersistCoordinator.java @@ -23,8 +23,9 @@ import org.apache.shardingsphere.infra.executor.sql.process.ProcessRegistry; import org.apache.shardingsphere.infra.executor.sql.process.yaml.swapper.YamlProcessListSwapper; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator; import org.apache.shardingsphere.mode.node.path.execution.process.ProcessNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.process.KillProcessTriggerNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.process.ShowProcessListTriggerNodePath; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; import java.util.Collection; @@ -50,7 +51,7 @@ public final class ClusterProcessPersistCoordinator { if (!processes.isEmpty()) { repository.persist(new NodePathGenerator(new ProcessNodePath(taskId)).getPath(instanceId), YamlEngine.marshal(swapper.swapToYamlConfiguration(processes))); } - repository.delete(ComputeNodePathGenerator.getShowProcessListTriggerPath(instanceId, taskId)); + repository.delete(new NodePathGenerator(new ShowProcessListTriggerNodePath()).getPath(String.join(":", instanceId, taskId))); } /** @@ -60,6 +61,6 @@ public final class ClusterProcessPersistCoordinator { * @param processId process ID */ public void cleanProcess(final String instanceId, final String processId) { - repository.delete(ComputeNodePathGenerator.getKillProcessTriggerPath(instanceId, processId)); + repository.delete(new NodePathGenerator(new KillProcessTriggerNodePath()).getPath(String.join(":", instanceId, processId))); } } 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 2671431ed6b..b17ea0edace 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,8 +25,10 @@ import org.apache.shardingsphere.infra.executor.sql.process.yaml.swapper.YamlPro import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator; import org.apache.shardingsphere.mode.node.path.execution.process.ProcessNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.process.KillProcessTriggerNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.process.ShowProcessListTriggerNodePath; +import org.apache.shardingsphere.mode.node.path.node.compute.status.OnlineTypeNodePath; import org.apache.shardingsphere.mode.persist.service.ProcessPersistService; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; @@ -63,8 +65,8 @@ public final class ClusterProcessPersistService implements ProcessPersistService private Collection<String> getShowProcessListTriggerPaths(final String taskId) { return Stream.of(InstanceType.values()) - .flatMap(each -> repository.getChildrenKeys(ComputeNodePathGenerator.getOnlinePath(each)).stream() - .map(instanceId -> ComputeNodePathGenerator.getShowProcessListTriggerPath(instanceId, taskId))) + .flatMap(each -> repository.getChildrenKeys(new NodePathGenerator(new OnlineTypeNodePath()).getPath(each.name().toLowerCase())).stream() + .map(instanceId -> new NodePathGenerator(new ShowProcessListTriggerNodePath()).getPath(String.join(":", instanceId, taskId)))) .collect(Collectors.toList()); } @@ -93,8 +95,8 @@ public final class ClusterProcessPersistService implements ProcessPersistService private Collection<String> getKillProcessTriggerPaths(final String processId) { return Stream.of(InstanceType.values()) - .flatMap(each -> repository.getChildrenKeys(ComputeNodePathGenerator.getOnlinePath(each)).stream() - .map(onlinePath -> ComputeNodePathGenerator.getKillProcessTriggerPath(onlinePath, processId))) + .flatMap(each -> repository.getChildrenKeys(new NodePathGenerator(new OnlineTypeNodePath()).getPath(each.name().toLowerCase())).stream() + .map(onlinePath -> new NodePathGenerator(new KillProcessTriggerNodePath()).getPath(String.join(":", onlinePath, processId)))) .collect(Collectors.toList()); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ReservationPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ReservationPersistService.java index 1acbd4f60fb..70066a47758 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ReservationPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ReservationPersistService.java @@ -19,7 +19,7 @@ package org.apache.shardingsphere.mode.manager.cluster.workerid; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.workerid.WorkerIDNodePath; +import org.apache.shardingsphere.mode.node.path.reservation.workerid.WorkerIDReservationNodePath; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterRepositoryPersistException; @@ -43,7 +43,7 @@ public final class ReservationPersistService { public Optional<Integer> reserveWorkerId(final Integer preselectedWorkerId, final String instanceId) { try { return repository.persistExclusiveEphemeral( - new NodePathGenerator(new WorkerIDNodePath()).getPath(preselectedWorkerId), instanceId) ? Optional.of(preselectedWorkerId) : Optional.empty(); + new NodePathGenerator(new WorkerIDReservationNodePath()).getPath(preselectedWorkerId), instanceId) ? Optional.of(preselectedWorkerId) : Optional.empty(); } catch (final ClusterRepositoryPersistException ignore) { return Optional.empty(); } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistServiceTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistServiceTest.java index 3a5a45ea265..0b224a770f2 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistServiceTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistServiceTest.java @@ -22,9 +22,7 @@ import org.apache.shardingsphere.infra.executor.sql.process.ProcessRegistry; import org.apache.shardingsphere.infra.executor.sql.process.lock.ProcessOperationLockRegistry; import org.apache.shardingsphere.infra.executor.sql.process.yaml.YamlProcess; import org.apache.shardingsphere.infra.executor.sql.process.yaml.YamlProcessList; -import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -73,8 +71,8 @@ class ClusterProcessPersistServiceTest { } private void assertGetProcessList() { - when(repository.getChildrenKeys(ComputeNodePathGenerator.getOnlinePath(InstanceType.JDBC))).thenReturn(Collections.emptyList()); - when(repository.getChildrenKeys(ComputeNodePathGenerator.getOnlinePath(InstanceType.PROXY))).thenReturn(Collections.singletonList("abc")); + when(repository.getChildrenKeys("/nodes/compute_nodes/online/jdbc")).thenReturn(Collections.emptyList()); + when(repository.getChildrenKeys("/nodes/compute_nodes/online/proxy")).thenReturn(Collections.singletonList("abc")); when(repository.getChildrenKeys(contains("/execution_nodes/"))).thenReturn(Collections.singletonList("abc")); when(repository.query(contains("/execution_nodes/"))).thenReturn(YamlEngine.marshal(createYamlProcessList())); Collection<Process> actual = processPersistService.getProcessList(); @@ -107,8 +105,8 @@ class ClusterProcessPersistServiceTest { } private void assertKillProcess() { - when(repository.getChildrenKeys(ComputeNodePathGenerator.getOnlinePath(InstanceType.JDBC))).thenReturn(Collections.emptyList()); - when(repository.getChildrenKeys(ComputeNodePathGenerator.getOnlinePath(InstanceType.PROXY))).thenReturn(Collections.singletonList("abc")); + when(repository.getChildrenKeys("/nodes/compute_nodes/online/jdbc")).thenReturn(Collections.emptyList()); + when(repository.getChildrenKeys("/nodes/compute_nodes/online/proxy")).thenReturn(Collections.singletonList("abc")); processPersistService.killProcess("foo_process_id"); verify(repository).persist("/nodes/compute_nodes/kill_process_trigger/abc:foo_process_id", ""); }