diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePath.java similarity index 76% rename from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java rename to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePath.java index 17fb5a245a043..e9133b7edd846 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePath.java @@ -15,23 +15,19 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.state; +package org.apache.shardingsphere.mode.node.path.execution; -import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.mode.node.path.NodePath; /** - * Process node path generator. + * Execution node path. */ -@RequiredArgsConstructor -public final class ProcessNodePath implements NodePath { +public final class ExecutionNodePath implements NodePath { private static final String ROOT_NODE = "/execution_nodes"; - private final String processId; - @Override public String getRootPath() { - return String.join("/", ROOT_NODE, processId); + return ROOT_NODE; } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePath.java new file mode 100644 index 0000000000000..9734f1c892255 --- /dev/null +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePath.java @@ -0,0 +1,39 @@ +/* + * 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.execution.process; + +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.mode.node.path.NodePath; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.execution.ExecutionNodePath; + +/** + * Process node path. + */ +@RequiredArgsConstructor +public final class ProcessNodePath implements NodePath { + + private final String processId; + + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ExecutionNodePath()); + + @Override + public String getRootPath() { + return String.join("/", nodePathGenerator.getPath(processId)); + } +} diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePath.java index 445c1543b0f1c..3798fc41af36b 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePath.java @@ -24,7 +24,7 @@ */ public final class ReservationNodePath implements NodePath { - private static final String ROOT_NODE = "/reservation/worker_id"; + private static final String ROOT_NODE = "/reservation"; @Override public String getRootPath() { 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/WorkerIDNodePath.java new file mode 100644 index 0000000000000..d21328f2fbc22 --- /dev/null +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java @@ -0,0 +1,37 @@ +/* + * 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.reservation.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; + +/** + * Worker ID node path. + */ +public final class WorkerIDNodePath implements NodePath { + + private static final String ROOT_NODE = "worker_id"; + + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath()); + + @Override + public String getRootPath() { + return String.join("/", nodePathGenerator.getPath(ROOT_NODE)); + } +} diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePathTest.java new file mode 100644 index 0000000000000..59a74a565594d --- /dev/null +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePathTest.java @@ -0,0 +1,31 @@ +/* + * 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.execution; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class ExecutionNodePathTest { + + @Test + void assertGetRootPath() { + assertThat(new ExecutionNodePath().getRootPath(), is("/execution_nodes")); + } +} diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePathTest.java similarity index 94% rename from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java rename to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePathTest.java index 79502d4a3dba8..c64632f838839 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePathTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.node.path.state; +package org.apache.shardingsphere.mode.node.path.execution.process; import org.junit.jupiter.api.Test; diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePathTest.java index 75ac97497d587..9f316e032288b 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePathTest.java @@ -25,7 +25,7 @@ class ReservationNodePathTest { @Test - void assertGetWorkerIdReservationPath() { - assertThat(new ReservationNodePath().getRootPath(), is("/reservation/worker_id")); + void assertGetRootPath() { + assertThat(new ReservationNodePath().getRootPath(), is("/reservation")); } } 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/WorkerIDNodePathTest.java new file mode 100644 index 0000000000000..612bd8b3c0c02 --- /dev/null +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java @@ -0,0 +1,31 @@ +/* + * 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.reservation.workerid; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class WorkerIDNodePathTest { + + @Test + void assertGetRootPath() { + assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id")); + } +} 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 2db5a4a780ac9..830d2d086cc93 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 @@ -24,7 +24,7 @@ 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.state.ProcessNodePath; +import org.apache.shardingsphere.mode.node.path.execution.process.ProcessNodePath; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; import java.util.Collection; 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 647844ca44fff..2671431ed6bce 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 @@ -26,7 +26,7 @@ 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.state.ProcessNodePath; +import org.apache.shardingsphere.mode.node.path.execution.process.ProcessNodePath; import org.apache.shardingsphere.mode.persist.service.ProcessPersistService; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; 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 ceaee1f6a1eb8..1acbd4f60fbae 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 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.mode.node.path.NodePathGenerator; -import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath; +import org.apache.shardingsphere.mode.node.path.reservation.workerid.WorkerIDNodePath; 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 reserveWorkerId(final Integer preselectedWorkerId, final String instanceId) { try { return repository.persistExclusiveEphemeral( - new NodePathGenerator(new ReservationNodePath()).getPath(preselectedWorkerId), instanceId) ? Optional.of(preselectedWorkerId) : Optional.empty(); + new NodePathGenerator(new WorkerIDNodePath()).getPath(preselectedWorkerId), instanceId) ? Optional.of(preselectedWorkerId) : Optional.empty(); } catch (final ClusterRepositoryPersistException ignore) { return Optional.empty(); }