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

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new 69818904a [#4517] fixed for cross engine authentication failed at 
dual-az servicecomb engine (#4519)
69818904a is described below

commit 69818904a885ed4945d90469ada27cdea5f44a05
Author: Alex <[email protected]>
AuthorDate: Sat Sep 14 16:18:04 2024 +0800

    [#4517] fixed for cross engine authentication failed at dual-az servicecomb 
engine (#4519)
---
 .../config/center/client/ConfigCenterClient.java    |  5 +++++
 .../servicecomb/config/kie/client/KieClient.java    |  6 ++++++
 .../http/client/common/AbstractAddressManager.java  | 14 ++++++++++++++
 .../client/event/EngineConnectChangedEvent.java     | 21 +++++++++++++++++++++
 .../service/center/client/ServiceCenterClient.java  |  4 ++++
 .../servicestage/RBACBootStrapService.java          |  1 +
 .../huaweicloud/servicestage/TokenCacheManager.java |  6 ++++++
 7 files changed, 57 insertions(+)

diff --git 
a/clients/config-center-client/src/main/java/org/apache/servicecomb/config/center/client/ConfigCenterClient.java
 
b/clients/config-center-client/src/main/java/org/apache/servicecomb/config/center/client/ConfigCenterClient.java
index f41fbd228..cde37e920 100644
--- 
a/clients/config-center-client/src/main/java/org/apache/servicecomb/config/center/client/ConfigCenterClient.java
+++ 
b/clients/config-center-client/src/main/java/org/apache/servicecomb/config/center/client/ConfigCenterClient.java
@@ -34,6 +34,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.fasterxml.jackson.core.type.TypeReference;
+import com.google.common.eventbus.EventBus;
 
 public class ConfigCenterClient implements ConfigCenterOperation {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(ConfigCenterClient.class);
@@ -57,6 +58,10 @@ public class ConfigCenterClient implements 
ConfigCenterOperation {
     this.httpTransport = httpTransport;
   }
 
+  public void setEventBus(EventBus eventBus) {
+    addressManager.setEventBus(eventBus);
+  }
+
   @Override
   public QueryConfigurationsResponse 
queryConfigurations(QueryConfigurationsRequest request, String address) {
     String dimensionsInfo = buildDimensionsInfo(request, true);
diff --git 
a/clients/config-kie-client/src/main/java/org/apache/servicecomb/config/kie/client/KieClient.java
 
b/clients/config-kie-client/src/main/java/org/apache/servicecomb/config/kie/client/KieClient.java
index dc5c641f6..50cf2b873 100644
--- 
a/clients/config-kie-client/src/main/java/org/apache/servicecomb/config/kie/client/KieClient.java
+++ 
b/clients/config-kie-client/src/main/java/org/apache/servicecomb/config/kie/client/KieClient.java
@@ -17,6 +17,8 @@
 
 package org.apache.servicecomb.config.kie.client;
 
+import com.google.common.eventbus.EventBus;
+
 import java.io.StringReader;
 import java.nio.charset.StandardCharsets;
 import java.util.Collections;
@@ -67,6 +69,10 @@ public class KieClient implements KieConfigOperation {
     this.kieConfiguration = kieConfiguration;
   }
 
+  public void setEventBus(EventBus eventBus) {
+    addressManager.setEventBus(eventBus);
+  }
+
   @Override
   public ConfigurationsResponse queryConfigurations(ConfigurationsRequest 
request, String address) {
     String url = buildUrl(request, address);
diff --git 
a/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/AbstractAddressManager.java
 
b/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/AbstractAddressManager.java
index 2143c26c9..533a6e530 100644
--- 
a/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/AbstractAddressManager.java
+++ 
b/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/AbstractAddressManager.java
@@ -35,11 +35,13 @@ import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.servicecomb.http.client.event.EngineConnectChangedEvent;
 import org.apache.servicecomb.http.client.event.RefreshEndpointEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.eventbus.EventBus;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 
 public class AbstractAddressManager {
@@ -86,6 +88,8 @@ public class AbstractAddressManager {
 
   private final Random random = new Random();
 
+  private EventBus eventBus;
+
   private final ScheduledExecutorService executorService = 
Executors.newScheduledThreadPool(1,
       new ThreadFactoryBuilder()
           .setNameFormat("check-available-address-%d")
@@ -257,6 +261,9 @@ public class AbstractAddressManager {
     if (addressAutoRefreshed) {
       if (isolationZoneAddress.remove(address)) {
         LOGGER.warn("restore default address [{}]", address);
+        if (eventBus != null && availableZone.isEmpty()) {
+          eventBus.post(new EngineConnectChangedEvent());
+        }
         availableZone.add(address);
         return;
       }
@@ -305,6 +312,9 @@ public class AbstractAddressManager {
     if (availableZone.remove(address)) {
       LOGGER.warn("isolation same zone address [{}]", address);
       isolationZoneAddress.add(address);
+      if (eventBus != null && availableZone.isEmpty() && 
!availableRegion.isEmpty()) {
+        eventBus.post(new EngineConnectChangedEvent());
+      }
       return;
     }
     if (availableRegion.remove(address)) {
@@ -312,4 +322,8 @@ public class AbstractAddressManager {
       isolationRegionAddress.add(address);
     }
   }
+
+  public void setEventBus(EventBus eventBus) {
+    this.eventBus = eventBus;
+  }
 }
diff --git 
a/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/event/EngineConnectChangedEvent.java
 
b/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/event/EngineConnectChangedEvent.java
new file mode 100644
index 000000000..b2029f5c3
--- /dev/null
+++ 
b/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/event/EngineConnectChangedEvent.java
@@ -0,0 +1,21 @@
+/*
+ * 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.servicecomb.http.client.event;
+
+public class EngineConnectChangedEvent {
+}
diff --git 
a/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterClient.java
 
b/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterClient.java
index 09f30dc93..f5cec283e 100755
--- 
a/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterClient.java
+++ 
b/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterClient.java
@@ -69,12 +69,15 @@ public class ServiceCenterClient implements 
ServiceCenterOperation {
 
   private EventBus eventBus;
 
+  private ServiceCenterAddressManager addressManager;
+
   public ServiceCenterClient(ServiceCenterRawClient httpClient) {
     this.httpClient = httpClient;
   }
 
   public ServiceCenterClient setEventBus(EventBus eventBus) {
     this.eventBus = eventBus;
+    addressManager.setEventBus(eventBus);
     return this;
   }
 
@@ -90,6 +93,7 @@ public class ServiceCenterClient implements 
ServiceCenterOperation {
         .setTenantName(tenantName)
         .setAddressManager(addressManager)
         .setHttpTransport(httpTransport).build();
+    this.addressManager = addressManager;
   }
 
   @Override
diff --git 
a/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/RBACBootStrapService.java
 
b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/RBACBootStrapService.java
index b772a0eb0..2ba89f1a4 100644
--- 
a/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/RBACBootStrapService.java
+++ 
b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/RBACBootStrapService.java
@@ -73,6 +73,7 @@ public class RBACBootStrapService implements BootStrapService 
{
     }
 
     ServiceCenterAddressManager addressManager = 
createAddressManager(environment);
+    addressManager.setEventBus(EventManager.getEventBus());
     SSLProperties sslProperties = createSSLProperties(environment);
     sslProperties.setEnabled(addressManager.sslEnabled());
 
diff --git 
a/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/TokenCacheManager.java
 
b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/TokenCacheManager.java
index 9e92e0303..205f37381 100644
--- 
a/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/TokenCacheManager.java
+++ 
b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/TokenCacheManager.java
@@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.servicecomb.foundation.auth.Cipher;
 import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
 import org.apache.servicecomb.foundation.common.event.EventManager;
+import org.apache.servicecomb.http.client.event.EngineConnectChangedEvent;
 import org.apache.servicecomb.service.center.client.OperationEvents;
 import org.apache.servicecomb.service.center.client.ServiceCenterClient;
 import org.apache.servicecomb.service.center.client.model.RbacTokenRequest;
@@ -154,6 +155,11 @@ public final class TokenCacheManager {
       });
     }
 
+    @Subscribe
+    public void onEngineConnectChangedEvent(EngineConnectChangedEvent event) {
+      cache.refresh(registryName);
+    }
+
     private String createHeaders() {
       LOGGER.info("start to create RBAC headers");
 

Reply via email to