Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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 {
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 @@ -73,6 +73,7 @@ public void startup(Environment environment) {
}

ServiceCenterAddressManager addressManager = createAddressManager(environment);
addressManager.setEventBus(EventManager.getEventBus());
SSLProperties sslProperties = createSSLProperties(environment);
sslProperties.setEnabled(addressManager.sslEnabled());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -154,6 +155,11 @@ public void onNotPermittedEvent(OperationEvents.UnAuthorizedOperationEvent event
});
}

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

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

Expand Down