Skip to content

Commit 230e103

Browse files
authored
Rename ClusterState to ShardingSphereState (#34942)
* Rename ClusterState to ShardingSphereState * Rename ClusterState to ShardingSphereState
1 parent 5e171e5 commit 230e103

File tree

29 files changed

+105
-138
lines changed

29 files changed

+105
-138
lines changed

jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
2424
import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
2525
import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
26-
import org.apache.shardingsphere.mode.state.ClusterState;
26+
import org.apache.shardingsphere.mode.state.ShardingSphereState;
2727
import org.apache.shardingsphere.infra.state.instance.InstanceState;
2828
import org.apache.shardingsphere.mode.manager.ContextManager;
2929
import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
@@ -56,7 +56,7 @@ void assertNewConstructorWithModeConfigurationOnly() throws Exception {
5656
try (ShardingSphereDataSource actual = new ShardingSphereDataSource("foo_db", null)) {
5757
ContextManager contextManager = getContextManager(actual);
5858
assertNotNull(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db"));
59-
assertThat(contextManager.getStateContext().getState(), is(ClusterState.OK));
59+
assertThat(contextManager.getStateContext().getState(), is(ShardingSphereState.OK));
6060
assertThat(contextManager.getComputeNodeInstanceContext().getInstance().getState().getCurrentState(), is(InstanceState.OK));
6161
assertTrue(contextManager.getStorageUnits("foo_db").isEmpty());
6262
}
@@ -69,7 +69,7 @@ void assertNewConstructorWithAllArguments() throws Exception {
6969
try (ShardingSphereDataSource actual = createShardingSphereDataSource(new MockedDataSource(connection))) {
7070
ContextManager contextManager = getContextManager(actual);
7171
assertNotNull(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db"));
72-
assertThat(contextManager.getStateContext().getState(), is(ClusterState.OK));
72+
assertThat(contextManager.getStateContext().getState(), is(ShardingSphereState.OK));
7373
assertThat(contextManager.getComputeNodeInstanceContext().getInstance().getState().getCurrentState(), is(InstanceState.OK));
7474
assertThat(contextManager.getStorageUnits("foo_db").size(), is(1));
7575
assertThat(contextManager.getStorageUnits("foo_db").get("ds").getDataSource().getConnection().getMetaData().getURL(), is("jdbc:mock://127.0.0.1/foo_ds"));

mode/core/src/main/java/org/apache/shardingsphere/mode/exception/ClusterStateException.java mode/core/src/main/java/org/apache/shardingsphere/mode/exception/ShardingSphereStateException.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
2323

2424
/**
25-
* Cluster state exception.
25+
* ShardingSphere state exception.
2626
*/
27-
public final class ClusterStateException extends ClusterSQLException {
27+
public final class ShardingSphereStateException extends ClusterSQLException {
2828

2929
private static final long serialVersionUID = 3834132923835083492L;
3030

31-
public ClusterStateException(final String type, final SQLStatement sqlStatement) {
31+
public ShardingSphereStateException(final String type, final SQLStatement sqlStatement) {
3232
super(XOpenSQLState.GENERAL_ERROR, 20, "The cluster state is %s, can not support SQL statement '%s'.", type, sqlStatement.getClass().getSimpleName());
3333
}
3434
}

mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import org.apache.shardingsphere.mode.metadata.manager.resource.SwitchingResource;
4848
import org.apache.shardingsphere.mode.persist.PersistServiceFacade;
4949
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
50-
import org.apache.shardingsphere.mode.state.ClusterStateContext;
50+
import org.apache.shardingsphere.mode.state.StateContext;
5151

5252
import java.sql.SQLException;
5353
import java.util.Collection;
@@ -67,7 +67,7 @@ public final class ContextManager implements AutoCloseable {
6767

6868
private final ExecutorEngine executorEngine;
6969

70-
private final ClusterStateContext stateContext;
70+
private final StateContext stateContext;
7171

7272
private final PersistServiceFacade persistServiceFacade;
7373

@@ -78,7 +78,7 @@ public ContextManager(final MetaDataContexts metaDataContexts, final ComputeNode
7878
this.computeNodeInstanceContext = computeNodeInstanceContext;
7979
metaDataContextManager = new MetaDataContextManager(metaDataContexts, computeNodeInstanceContext, repository);
8080
persistServiceFacade = new PersistServiceFacade(repository, computeNodeInstanceContext.getModeConfiguration(), metaDataContextManager);
81-
stateContext = new ClusterStateContext(persistServiceFacade.getClusterStatePersistService().load());
81+
stateContext = new StateContext(persistServiceFacade.getStatePersistService().load());
8282
executorEngine = ExecutorEngine.createExecutorEngineWithSize(metaDataContexts.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE));
8383
for (ContextManagerLifecycleListener each : ShardingSphereServiceLoader.getServiceInstances(ContextManagerLifecycleListener.class)) {
8484
each.onInitialized(this);

mode/core/src/main/java/org/apache/shardingsphere/mode/persist/PersistServiceFacade.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder;
2828
import org.apache.shardingsphere.mode.persist.service.ProcessPersistService;
2929
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
30-
import org.apache.shardingsphere.mode.state.ClusterStatePersistService;
30+
import org.apache.shardingsphere.mode.state.StatePersistService;
3131
import org.apache.shardingsphere.mode.node.ComputeNodePersistService;
3232
import org.apache.shardingsphere.mode.node.QualifiedDataSourceStatePersistService;
3333

@@ -43,7 +43,7 @@ public final class PersistServiceFacade {
4343

4444
private final ComputeNodePersistService computeNodePersistService;
4545

46-
private final ClusterStatePersistService clusterStatePersistService;
46+
private final StatePersistService statePersistService;
4747

4848
private final MetaDataManagerPersistService metaDataManagerPersistService;
4949

@@ -55,7 +55,7 @@ public PersistServiceFacade(final PersistRepository repository, final ModeConfig
5555
this.repository = repository;
5656
metaDataPersistFacade = new MetaDataPersistFacade(repository);
5757
computeNodePersistService = new ComputeNodePersistService(repository);
58-
clusterStatePersistService = new ClusterStatePersistService(repository);
58+
statePersistService = new StatePersistService(repository);
5959
qualifiedDataSourceStatePersistService = new QualifiedDataSourceStatePersistService(repository);
6060
PersistServiceBuilder persistServiceBuilder = TypedSPILoader.getService(PersistServiceBuilder.class, modeConfig.getType());
6161
metaDataManagerPersistService = persistServiceBuilder.buildMetaDataManagerPersistService(repository, metaDataContextManager);

mode/core/src/main/java/org/apache/shardingsphere/mode/state/ClusterState.java mode/core/src/main/java/org/apache/shardingsphere/mode/state/ShardingSphereState.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
import com.google.common.base.Strings;
2121

2222
/**
23-
* Cluster state.
23+
* ShardingSphere state.
2424
*/
25-
public enum ClusterState {
25+
public enum ShardingSphereState {
2626

2727
OK, READ_ONLY, UNAVAILABLE;
2828

2929
/**
3030
* Value from.
3131
*
3232
* @param value value
33-
* @return cluster state
33+
* @return state
3434
*/
35-
public static ClusterState valueFrom(final String value) {
36-
return Strings.isNullOrEmpty(value) ? ClusterState.OK : ClusterState.valueOf(value);
35+
public static ShardingSphereState valueFrom(final String value) {
36+
return Strings.isNullOrEmpty(value) ? ShardingSphereState.OK : ShardingSphereState.valueOf(value);
3737
}
3838
}

mode/core/src/main/java/org/apache/shardingsphere/mode/state/ClusterStateContext.java mode/core/src/main/java/org/apache/shardingsphere/mode/state/StateContext.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,31 @@
2020
import java.util.concurrent.atomic.AtomicReference;
2121

2222
/**
23-
* Cluster state context.
23+
* State context.
2424
*/
25-
public final class ClusterStateContext {
25+
public final class StateContext {
2626

27-
private final AtomicReference<ClusterState> clusterState;
27+
private final AtomicReference<ShardingSphereState> state;
2828

29-
public ClusterStateContext(final ClusterState clusterState) {
30-
this.clusterState = new AtomicReference<>(clusterState);
29+
public StateContext(final ShardingSphereState state) {
30+
this.state = new AtomicReference<>(state);
3131
}
3232

3333
/**
34-
* Get cluster state.
34+
* Get state.
3535
*
36-
* @return cluster state
36+
* @return state
3737
*/
38-
public ClusterState getState() {
39-
return clusterState.get();
38+
public ShardingSphereState getState() {
39+
return state.get();
4040
}
4141

4242
/**
43-
* Switch cluster state.
43+
* Switch state.
4444
*
45-
* @param state to be switched cluster state
45+
* @param state to be switched state
4646
*/
47-
public void switchState(final ClusterState state) {
48-
clusterState.set(state);
47+
public void switchState(final ShardingSphereState state) {
48+
this.state.set(state);
4949
}
5050
}

mode/core/src/main/java/org/apache/shardingsphere/mode/state/ClusterStatePersistService.java mode/core/src/main/java/org/apache/shardingsphere/mode/state/StatePersistService.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@
1919

2020
import lombok.RequiredArgsConstructor;
2121
import org.apache.shardingsphere.mode.node.path.engine.generator.NodePathGenerator;
22-
import org.apache.shardingsphere.mode.node.path.type.global.state.ClusterNodePath;
22+
import org.apache.shardingsphere.mode.node.path.type.global.state.StateNodePath;
2323
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
2424

2525
/**
26-
* Cluster state persist service.
26+
* State persist service.
2727
*/
2828
@RequiredArgsConstructor
29-
public final class ClusterStatePersistService {
29+
public final class StatePersistService {
3030

3131
private final PersistRepository repository;
3232

3333
/**
34-
* Update cluster state.
34+
* Update state.
3535
*
36-
* @param state to be updated cluster state
36+
* @param state to be updated state
3737
*/
38-
public void update(final ClusterState state) {
39-
repository.persist(NodePathGenerator.toPath(new ClusterNodePath(), false), state.name());
38+
public void update(final ShardingSphereState state) {
39+
repository.persist(NodePathGenerator.toPath(new StateNodePath(), false), state.name());
4040
}
4141

4242
/**
43-
* Load cluster state.
43+
* Load state.
4444
*
45-
* @return loaded cluster state
45+
* @return loaded state
4646
*/
47-
public ClusterState load() {
48-
return ClusterState.valueFrom(repository.query(NodePathGenerator.toPath(new ClusterNodePath(), false)));
47+
public ShardingSphereState load() {
48+
return ShardingSphereState.valueFrom(repository.query(NodePathGenerator.toPath(new StateNodePath(), false)));
4949
}
5050
}

mode/core/src/test/java/org/apache/shardingsphere/mode/state/ClusterStateContextTest.java

-33
This file was deleted.

mode/core/src/test/java/org/apache/shardingsphere/mode/state/ClusterStateTest.java mode/core/src/test/java/org/apache/shardingsphere/mode/state/ShardingSphereStateTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
import static org.hamcrest.CoreMatchers.is;
2323
import static org.hamcrest.MatcherAssert.assertThat;
2424

25-
class ClusterStateTest {
25+
class ShardingSphereStateTest {
2626

2727
@Test
2828
void assertValueFromEmptyValue() {
29-
assertThat(ClusterState.valueFrom(""), is(ClusterState.OK));
29+
assertThat(ShardingSphereState.valueFrom(""), is(ShardingSphereState.OK));
3030
}
3131

3232
@Test
3333
void assertValueFrom() {
34-
assertThat(ClusterState.valueFrom("UNAVAILABLE"), is(ClusterState.UNAVAILABLE));
34+
assertThat(ShardingSphereState.valueFrom("UNAVAILABLE"), is(ShardingSphereState.UNAVAILABLE));
3535
}
3636
}

mode/core/src/test/java/org/apache/shardingsphere/mode/state/StateContextTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424

2525
class StateContextTest {
2626

27-
private final ClusterStateContext stateContext = new ClusterStateContext(ClusterState.OK);
27+
private final StateContext stateContext = new StateContext(ShardingSphereState.OK);
2828

2929
@Test
3030
void assertGetClusterState() {
31-
assertThat(stateContext.getState(), is(ClusterState.OK));
31+
assertThat(stateContext.getState(), is(ShardingSphereState.OK));
3232
}
3333

3434
@Test
3535
void assertSwitchClusterState() {
36-
assertThat(stateContext.getState(), is(ClusterState.OK));
37-
stateContext.switchState(ClusterState.UNAVAILABLE);
38-
assertThat(stateContext.getState(), is(ClusterState.UNAVAILABLE));
36+
assertThat(stateContext.getState(), is(ShardingSphereState.OK));
37+
stateContext.switchState(ShardingSphereState.UNAVAILABLE);
38+
assertThat(stateContext.getState(), is(ShardingSphereState.UNAVAILABLE));
3939
}
4040
}

mode/core/src/test/java/org/apache/shardingsphere/mode/state/ClusterStatePersistServiceTest.java mode/core/src/test/java/org/apache/shardingsphere/mode/state/StatePersistServiceTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,33 @@
3030
import static org.mockito.Mockito.when;
3131

3232
@ExtendWith(MockitoExtension.class)
33-
class ClusterStatePersistServiceTest {
33+
class StatePersistServiceTest {
3434

35-
private ClusterStatePersistService clusterStatePersistService;
35+
private StatePersistService statePersistService;
3636

3737
@Mock
3838
private PersistRepository repository;
3939

4040
@BeforeEach
4141
void setUp() {
42-
clusterStatePersistService = new ClusterStatePersistService(repository);
42+
statePersistService = new StatePersistService(repository);
4343
}
4444

4545
@Test
4646
void assertUpdate() {
47-
clusterStatePersistService.update(ClusterState.OK);
48-
verify(repository).persist("/states/cluster_state", ClusterState.OK.name());
47+
statePersistService.update(ShardingSphereState.OK);
48+
verify(repository).persist("/states/cluster_state", ShardingSphereState.OK.name());
4949
}
5050

5151
@Test
5252
void assertLoad() {
53-
when(repository.query("/states/cluster_state")).thenReturn(ClusterState.READ_ONLY.name());
54-
assertThat(clusterStatePersistService.load(), is(ClusterState.READ_ONLY));
53+
when(repository.query("/states/cluster_state")).thenReturn(ShardingSphereState.READ_ONLY.name());
54+
assertThat(statePersistService.load(), is(ShardingSphereState.READ_ONLY));
5555
}
5656

5757
@Test
5858
void assertLoadWithEmptyState() {
5959
when(repository.query("/states/cluster_state")).thenReturn("");
60-
assertThat(clusterStatePersistService.load(), is(ClusterState.OK));
60+
assertThat(statePersistService.load(), is(ShardingSphereState.OK));
6161
}
6262
}

mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/global/state/ClusterNodePath.java mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/global/state/StateNodePath.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.apache.shardingsphere.mode.node.path.NodePathEntity;
2222

2323
/**
24-
* Cluster node path.
24+
* State node path.
2525
*/
2626
@NodePathEntity("/states/cluster_state")
27-
public final class ClusterNodePath implements NodePath {
27+
public final class StateNodePath implements NodePath {
2828
}

mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/global/state/ClusterNodePathTest.java mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/global/state/StateNodePathTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import static org.hamcrest.CoreMatchers.is;
2424
import static org.hamcrest.MatcherAssert.assertThat;
2525

26-
class ClusterNodePathTest {
26+
class StateNodePathTest {
2727

2828
@Test
2929
void assertToPath() {
30-
assertThat(NodePathGenerator.toPath(new ClusterNodePath(), false), is("/states/cluster_state"));
30+
assertThat(NodePathGenerator.toPath(new StateNodePath(), false), is("/states/cluster_state"));
3131
}
3232
}
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
import org.apache.shardingsphere.mode.manager.ContextManager;
2323
import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler;
2424
import org.apache.shardingsphere.mode.node.path.NodePath;
25-
import org.apache.shardingsphere.mode.node.path.type.global.state.ClusterNodePath;
26-
import org.apache.shardingsphere.mode.state.ClusterState;
25+
import org.apache.shardingsphere.mode.node.path.type.global.state.StateNodePath;
26+
import org.apache.shardingsphere.mode.state.ShardingSphereState;
2727

2828
import java.util.Arrays;
2929
import java.util.Collection;
3030

3131
/**
32-
* Cluster state changed handler.
32+
* State changed handler.
3333
*/
34-
public final class ClusterStateChangedHandler implements GlobalDataChangedEventHandler {
34+
public final class StateChangedHandler implements GlobalDataChangedEventHandler {
3535

3636
@Override
3737
public NodePath getSubscribedNodePath() {
38-
return new ClusterNodePath();
38+
return new StateNodePath();
3939
}
4040

4141
@Override
@@ -45,6 +45,6 @@ public Collection<Type> getSubscribedTypes() {
4545

4646
@Override
4747
public void handle(final ContextManager contextManager, final DataChangedEvent event) {
48-
contextManager.getStateContext().switchState(ClusterState.valueFrom(event.getValue()));
48+
contextManager.getStateContext().switchState(ShardingSphereState.valueFrom(event.getValue()));
4949
}
5050
}

mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.config.type.GlobalRuleChangedHandler
1919
org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.config.type.PropertiesChangedHandler
2020
org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.state.DatabaseListenerChangedHandler
21-
org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.state.ClusterStateChangedHandler
21+
org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.state.StateChangedHandler
2222
org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.node.QualifiedDataSourceChangedHandler
2323
org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.node.ComputeNodeOnlineHandler
2424
org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.node.ComputeNodeStateChangedHandler

0 commit comments

Comments
 (0)