Skip to content

Commit

Permalink
[#] fixed for cross engine authentication failed at dual-az serviceco…
Browse files Browse the repository at this point in the history
…mb engine (#4518)
  • Loading branch information
chengyouling authored Sep 14, 2024
1 parent 42cc6c9 commit ec699f0
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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);
Expand All @@ -57,6 +58,10 @@ public ConfigCenterClient(ConfigCenterAddressManager addressManager, HttpTranspo
this.httpTransport = httpTransport;
}

public void setEventBus(EventBus eventBus) {
addressManager.setEventBus(eventBus);
}

@Override
public QueryConfigurationsResponse queryConfigurations(QueryConfigurationsRequest request, String address) {
String dimensionsInfo = buildDimensionsInfo(request, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,6 +69,10 @@ public KieClient(KieAddressManager addressManager, HttpTransport httpTransport,
this.kieConfiguration = kieConfiguration;
}

public void setEventBus(EventBus eventBus) {
addressManager.setEventBus(eventBus);
}

@Override
public ConfigurationsResponse queryConfigurations(ConfigurationsRequest request, String address) {
String url = buildUrl(request, address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import java.util.stream.Collectors;

import org.apache.commons.lang.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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -257,6 +261,9 @@ protected void findAndRestoreAddress(String address) {
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;
}
Expand Down Expand Up @@ -305,11 +312,18 @@ void removeAddress(String address) {
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)) {
LOGGER.warn("isolation same region address [{}]", address);
isolationRegionAddress.add(address);
}
}

public void setEventBus(EventBus eventBus) {
this.eventBus = eventBus;
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -90,6 +93,7 @@ public ServiceCenterClient(ServiceCenterAddressManager addressManager,
.setTenantName(tenantName)
.setAddressManager(addressManager)
.setHttpTransport(httpTransport).build();
this.addressManager = addressManager;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.servicecomb.foundation.ssl.SSLOption;
import org.apache.servicecomb.http.client.auth.DefaultRequestAuthHeaderProvider;
import org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties;
import org.apache.servicecomb.registry.api.event.ServiceCenterEventBus;
import org.apache.servicecomb.service.center.client.ServiceCenterAddressManager;
import org.apache.servicecomb.service.center.client.ServiceCenterClient;
import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
Expand Down Expand Up @@ -60,6 +61,7 @@ public void startup(Environment environment) {
}

ServiceCenterAddressManager addressManager = createAddressManager(environment);
addressManager.setEventBus(ServiceCenterEventBus.getEventBus());
SSLProperties sslProperties = createSSLProperties(environment, "sc.consumer");
sslProperties.setEnabled(addressManager.sslEnabled());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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.http.client.event.EngineConnectChangedEvent;
import org.apache.servicecomb.registry.api.event.ServiceCenterEventBus;
import org.apache.servicecomb.service.center.client.ServiceCenterClient;
import org.apache.servicecomb.service.center.client.model.RbacTokenRequest;
Expand Down Expand Up @@ -154,6 +155,11 @@ public void onNotPermittedEvent(NotPermittedEvent event) {
});
}

@Subscribe
public void onEngineConnectChangedEvent(EngineConnectChangedEvent event) {
cache.refresh(registryName);
}

private String createHeaders() {
LOGGER.info("start to create RBAC headers");

Expand Down

0 comments on commit ec699f0

Please sign in to comment.