Skip to content

Commit 4450abc

Browse files
committed
Fixing the issue where microservices cannot be registered when enabling RBAC authentication in a dual-engine disaster recovery scenario.
1 parent 6c85f1b commit 4450abc

File tree

32 files changed

+291
-114
lines changed

32 files changed

+291
-114
lines changed

clients/config-center-client/src/main/java/org/apache/servicecomb/config/center/client/ConfigCenterAddressManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.servicecomb.config.center.client;
1919

20+
import java.util.ArrayList;
2021
import java.util.List;
2122

2223
import org.apache.servicecomb.http.client.common.AbstractAddressManager;
@@ -28,8 +29,9 @@
2829

2930
public class ConfigCenterAddressManager extends AbstractAddressManager {
3031

31-
public ConfigCenterAddressManager(String projectName, List<String> addresses, EventBus eventBus) {
32-
super(projectName, addresses);
32+
public ConfigCenterAddressManager(String projectName, List<String> addresses, List<String> sameSideAddresses,
33+
List<String> diffSideAddresses, EventBus eventBus) {
34+
super(projectName, addresses, sameSideAddresses, diffSideAddresses);
3335
eventBus.register(this);
3436
}
3537

clients/config-center-client/src/main/java/org/apache/servicecomb/config/center/client/ConfigCenterClient.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.servicecomb.http.client.common.HttpResponse;
3333
import org.apache.servicecomb.http.client.common.HttpTransport;
3434
import org.apache.servicecomb.http.client.common.HttpUtils;
35+
import org.apache.servicecomb.http.client.event.OperationEvents.UnAuthorizedOperationEvent;
3536
import org.apache.servicecomb.http.client.utils.ServiceCombServiceAvailableUtils;
3637
import org.slf4j.Logger;
3738
import org.slf4j.LoggerFactory;
@@ -61,12 +62,15 @@ public class ConfigCenterClient implements ConfigCenterOperation {
6162

6263
private final Map<String, List<String>> dimensionConfigNames = new HashMap<>();
6364

65+
private EventBus eventBus;
66+
6467
public ConfigCenterClient(ConfigCenterAddressManager addressManager, HttpTransport httpTransport) {
6568
this.addressManager = addressManager;
6669
this.httpTransport = httpTransport;
6770
}
6871

6972
public void setEventBus(EventBus eventBus) {
73+
this.eventBus = eventBus;
7074
addressManager.setEventBus(eventBus);
7175
}
7276

@@ -88,6 +92,7 @@ public QueryConfigurationsResponse queryConfigurations(QueryConfigurationsReques
8892
HttpRequest.GET);
8993

9094
HttpResponse httpResponse = httpTransport.doRequest(httpRequest);
95+
recordAndSendUnAuthorizedEvent(httpResponse, address);
9196
if (httpResponse.getStatusCode() == HttpStatus.SC_OK) {
9297
Map<String, Map<String, Object>> allConfigMap = HttpUtils.deserialize(
9398
httpResponse.getContent(),
@@ -121,21 +126,17 @@ public QueryConfigurationsResponse queryConfigurations(QueryConfigurationsReques
121126
}
122127
queryConfigurationsResponse.setConfigurations(configurations);
123128
queryConfigurationsResponse.setChanged(true);
124-
addressManager.recordSuccessState(address);
125129
return queryConfigurationsResponse;
126130
} else if (httpResponse.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
127131
queryConfigurationsResponse.setChanged(false);
128-
addressManager.recordSuccessState(address);
129132
return queryConfigurationsResponse;
130133
} else if (httpResponse.getStatusCode() == HttpStatus.SC_TOO_MANY_REQUESTS) {
131134
LOGGER.warn("rate limited, keep the local dimension [{}] configs unchanged.", dimensionsInfo);
132135
queryConfigurationsResponse.setChanged(false);
133-
addressManager.recordSuccessState(address);
134136
return queryConfigurationsResponse;
135137
} else if (httpResponse.getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
136138
throw new OperationException("Bad request for query configurations.");
137139
} else {
138-
addressManager.recordFailState(address);
139140
throw new OperationException(
140141
"read response failed. status:"
141142
+ httpResponse.getStatusCode()
@@ -151,6 +152,16 @@ public QueryConfigurationsResponse queryConfigurations(QueryConfigurationsReques
151152
}
152153
}
153154

155+
private void recordAndSendUnAuthorizedEvent(HttpResponse response, String address) {
156+
if (this.eventBus != null && response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
157+
LOGGER.warn("query configuration unauthorized from server [{}], message [{}]", address, response.getMessage());
158+
addressManager.recordFailState(address);
159+
this.eventBus.post(new UnAuthorizedOperationEvent(address));
160+
} else {
161+
addressManager.recordSuccessState(address);
162+
}
163+
}
164+
154165
/**
155166
* Only the name of the new configuration item is printed.
156167
* No log is printed when the configuration content is updated.

clients/config-kie-client/src/main/java/org/apache/servicecomb/config/kie/client/KieClient.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.servicecomb.http.client.common.HttpResponse;
4747
import org.apache.servicecomb.http.client.common.HttpTransport;
4848
import org.apache.servicecomb.http.client.common.HttpUtils;
49+
import org.apache.servicecomb.http.client.event.OperationEvents.UnAuthorizedOperationEvent;
4950
import org.apache.servicecomb.http.client.utils.ServiceCombServiceAvailableUtils;
5051
import org.slf4j.Logger;
5152
import org.slf4j.LoggerFactory;
@@ -71,13 +72,16 @@ public class KieClient implements KieConfigOperation {
7172

7273
private final Map<String, List<String>> dimensionConfigNames = new HashMap<>();
7374

75+
private EventBus eventBus;
76+
7477
public KieClient(KieAddressManager addressManager, HttpTransport httpTransport, KieConfiguration kieConfiguration) {
7578
this.httpTransport = httpTransport;
7679
this.addressManager = addressManager;
7780
this.kieConfiguration = kieConfiguration;
7881
}
7982

8083
public void setEventBus(EventBus eventBus) {
84+
this.eventBus = eventBus;
8185
addressManager.setEventBus(eventBus);
8286
}
8387

@@ -91,6 +95,7 @@ public ConfigurationsResponse queryConfigurations(ConfigurationsRequest request,
9195

9296
HttpRequest httpRequest = new HttpRequest(url, null, null, HttpRequest.GET);
9397
HttpResponse httpResponse = httpTransport.doRequest(httpRequest);
98+
recordAndSendUnAuthorizedEvent(httpResponse, address);
9499
ConfigurationsResponse configurationsResponse = new ConfigurationsResponse();
95100
if (httpResponse.getStatusCode() == HttpStatus.SC_OK) {
96101
revision = httpResponse.getHeader("X-Kie-Revision");
@@ -100,24 +105,20 @@ public ConfigurationsResponse queryConfigurations(ConfigurationsRequest request,
100105
configurationsResponse.setConfigurations(configurations);
101106
configurationsResponse.setChanged(true);
102107
configurationsResponse.setRevision(revision);
103-
addressManager.recordSuccessState(address);
104108
return configurationsResponse;
105109
}
106110
if (httpResponse.getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
107111
throw new OperationException("Bad request for query configurations.");
108112
}
109113
if (httpResponse.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
110114
configurationsResponse.setChanged(false);
111-
addressManager.recordSuccessState(address);
112115
return configurationsResponse;
113116
}
114117
if (httpResponse.getStatusCode() == HttpStatus.SC_TOO_MANY_REQUESTS) {
115118
LOGGER.warn("rate limited, keep the local dimension [{}] configs unchanged.", request.getLabelsQuery());
116119
configurationsResponse.setChanged(false);
117-
addressManager.recordSuccessState(address);
118120
return configurationsResponse;
119121
}
120-
addressManager.recordFailState(address);
121122
throw new OperationException(
122123
"read response failed. status:" + httpResponse.getStatusCode() + "; message:" +
123124
httpResponse.getMessage() + "; content:" + httpResponse.getContent());
@@ -128,6 +129,16 @@ public ConfigurationsResponse queryConfigurations(ConfigurationsRequest request,
128129
}
129130
}
130131

132+
private void recordAndSendUnAuthorizedEvent(HttpResponse response, String address) {
133+
if (this.eventBus != null && response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
134+
LOGGER.warn("query configuration unauthorized from server [{}], message [{}]", address, response.getMessage());
135+
addressManager.recordFailState(address);
136+
this.eventBus.post(new UnAuthorizedOperationEvent(address));
137+
} else {
138+
addressManager.recordSuccessState(address);
139+
}
140+
}
141+
131142
/**
132143
* Only the name of the new configuration item is printed.
133144
* No log is printed when the configuration content is updated.

clients/config-kie-client/src/main/java/org/apache/servicecomb/config/kie/client/model/KieAddressManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727

2828
public class KieAddressManager extends AbstractAddressManager {
2929

30-
public KieAddressManager(List<String> addresses, EventBus eventBus) {
31-
super(addresses);
30+
public KieAddressManager(List<String> addresses, List<String> sameSideAddresses, List<String> diffSideAddresses,
31+
EventBus eventBus) {
32+
super(addresses, sameSideAddresses, diffSideAddresses);
3233
eventBus.register(this);
3334
}
3435

clients/config-kie-client/src/test/java/org/apache/servicecomb/config/kie/client/model/KieAddressManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class KieAddressManagerTest {
4040
public void kieAddressManagerTest() throws NoSuchFieldException, IllegalAccessException {
4141
addresses.add("http://127.0.0.1:30103");
4242
addresses.add("https://127.0.0.2:30103");
43-
addressManager1 = new KieAddressManager(addresses, new EventBus());
43+
addressManager1 = new KieAddressManager(addresses, new ArrayList<>(), new ArrayList<>(), new EventBus());
4444
Field addressManagerField = addressManager1.getClass().getSuperclass().getDeclaredField("index");
4545
addressManagerField.setAccessible(true);
4646
addressManagerField.set(addressManager1, 0);
@@ -64,7 +64,7 @@ public void onRefreshEndpointEvent() {
6464
Map<String, List<String>> zoneAndRegion = new HashMap<>();
6565
zoneAndRegion.put("sameZone", addressAZ);
6666
zoneAndRegion.put("sameRegion", addressRG);
67-
addressManager1 = new KieAddressManager(addresses, new EventBus());
67+
addressManager1 = new KieAddressManager(addresses, new ArrayList<>(), new ArrayList<>(), new EventBus());
6868
RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "KIE");
6969
addressManager1.refreshEndpoint(event, "KIE");
7070

clients/dashboard-client/src/main/java/org/apache/servicecomb/dashboard/client/DashboardAddressManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929

3030
public class DashboardAddressManager extends AbstractAddressManager {
3131

32-
public DashboardAddressManager(List<String> addresses, EventBus eventBus) {
33-
super(addresses);
32+
public DashboardAddressManager(List<String> addresses, List<String> sameSideAddresses,
33+
List<String> diffSideAddresses, EventBus eventBus) {
34+
super(addresses, sameSideAddresses, diffSideAddresses);
3435
eventBus.register(this);
3536
}
3637

clients/dashboard-client/src/test/java/org/apache/servicecomb/dashboard/client/AddressManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AddressManagerTest {
4141
public void kieAddressManagerTest() throws IllegalAccessException, NoSuchFieldException {
4242
addresses.add("http://127.0.0.1:30103");
4343
addresses.add("https://127.0.0.2:30103");
44-
addressManager1 = new DashboardAddressManager(addresses, new EventBus());
44+
addressManager1 = new DashboardAddressManager(addresses, new ArrayList<>(), new ArrayList<>(), new EventBus());
4545
Field addressManagerField = addressManager1.getClass().getSuperclass().getDeclaredField("index");
4646
addressManagerField.setAccessible(true);
4747
addressManagerField.set(addressManager1, 0);
@@ -65,7 +65,7 @@ public void onRefreshEndpointEvent() {
6565
Map<String, List<String>> zoneAndRegion = new HashMap<>();
6666
zoneAndRegion.put("sameZone", addressAZ);
6767
zoneAndRegion.put("sameRegion", addressRG);
68-
addressManager1 = new DashboardAddressManager(addresses, new EventBus());
68+
addressManager1 = new DashboardAddressManager(addresses, new ArrayList<>(), new ArrayList<>(), new EventBus());
6969
RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "CseMonitoring");
7070
addressManager1.refreshEndpoint(event, "CseMonitoring");
7171

0 commit comments

Comments
 (0)