This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 4638a95dd44 Remove ClusterStateChangedEvent (#31327)
4638a95dd44 is described below

commit 4638a95dd4488f932c8a18433733fcf9e5464adf
Author: Haoran Meng <[email protected]>
AuthorDate: Tue May 21 16:15:20 2024 +0800

    Remove ClusterStateChangedEvent (#31327)
---
 .../infra/state/instance/InstanceState.java        | 10 +++----
 .../cluster/event/ClusterLockDeletedEvent.java     | 33 ----------------------
 .../cluster/event/ClusterStateChangedEvent.java    | 32 ---------------------
 .../subscriber/StateChangedSubscriber.java         | 12 --------
 .../subscriber/StateChangedSubscriberTest.java     |  8 ------
 5 files changed, 4 insertions(+), 91 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/state/instance/InstanceState.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/state/instance/InstanceState.java
index 8942898b0cb..49a7aabe210 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/state/instance/InstanceState.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/state/instance/InstanceState.java
@@ -33,12 +33,10 @@ public enum InstanceState {
      * @return instance state enum
      */
     public static Optional<InstanceState> get(final String state) {
-        if (OK.name().equals(state)) {
-            return Optional.of(OK);
+        try {
+            return Optional.ofNullable(state).isPresent() ? 
Optional.of(InstanceState.valueOf(state)) : Optional.empty();
+        } catch (final IllegalArgumentException ignore) {
+            return Optional.empty();
         }
-        if (CIRCUIT_BREAK.name().equals(state)) {
-            return Optional.of(CIRCUIT_BREAK);
-        }
-        return Optional.empty();
     }
 }
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/event/ClusterLockDeletedEvent.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/event/ClusterLockDeletedEvent.java
deleted file mode 100644
index 1227a908d86..00000000000
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/event/ClusterLockDeletedEvent.java
+++ /dev/null
@@ -1,33 +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.manager.cluster.coordinator.registry.status.cluster.event;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.state.cluster.ClusterState;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-
-/**
- * Cluster lock deleted event.
- */
-@RequiredArgsConstructor
-@Getter
-public final class ClusterLockDeletedEvent implements GovernanceEvent {
-    
-    private final ClusterState state;
-}
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/event/ClusterStateChangedEvent.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/event/ClusterStateChangedEvent.java
deleted file mode 100644
index 5c3b1627fbd..00000000000
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/event/ClusterStateChangedEvent.java
+++ /dev/null
@@ -1,32 +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.manager.cluster.coordinator.registry.status.cluster.event;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.state.cluster.ClusterState;
-
-/**
- * Cluster state changed event.
- */
-@RequiredArgsConstructor
-@Getter
-public final class ClusterStateChangedEvent {
-    
-    private final ClusterState state;
-}
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
index 50bffbe54cf..349461fc284 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
@@ -26,9 +26,7 @@ import 
org.apache.shardingsphere.infra.state.datasource.DataSourceState;
 import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager;
 import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber;
 import org.apache.shardingsphere.mode.manager.ContextManager;
-import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterLockDeletedEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterStateEvent;
-import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterStateChangedEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOfflineEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOnlineEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.LabelsEvent;
@@ -71,16 +69,6 @@ public final class StateChangedSubscriber implements 
EventSubscriber {
         }
     }
     
-    /**
-     * Reset cluster state.
-     * 
-     * @param event cluster lock deleted event
-     */
-    @Subscribe
-    public synchronized void renew(final ClusterLockDeletedEvent event) {
-        
contextManager.getComputeNodeInstanceContext().getEventBusContext().post(new 
ClusterStateChangedEvent(event.getState()));
-    }
-    
     /**
      * Renew cluster state.
      * 
diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
index 46c3c52e59e..1147704fb19 100644
--- 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
@@ -36,7 +36,6 @@ import 
org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
 import 
org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder;
-import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterLockDeletedEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterStateEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ComputeNodeInstanceStateChangedEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOfflineEvent;
@@ -121,13 +120,6 @@ class StateChangedSubscriberTest {
                 argThat(dataSourceState -> event.getStatus().getStatus() == 
dataSourceState));
     }
     
-    @Test
-    void assertResetClusterState() {
-        ClusterLockDeletedEvent mockLockDeletedEvent = new 
ClusterLockDeletedEvent(ClusterState.OK);
-        subscriber.renew(mockLockDeletedEvent);
-        assertThat(contextManager.getStateContext().getCurrentClusterState(), 
is(ClusterState.OK));
-    }
-    
     @Test
     void assertRenewClusterState() {
         ClusterStateEvent mockClusterStateEvent = new 
ClusterStateEvent(ClusterState.READ_ONLY);

Reply via email to