Merge pull request #1 from SkyeBeFreeman/dev/skye/2021-gw

refactor some code.
pull/1496/head
shedfreewu 7 months ago committed by GitHub
commit 4dcfad1c47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -57,7 +57,7 @@
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-gateway-plugin</artifactId>
<artifactId>spring-cloud-starter-tencent-gateway-plugin</artifactId>
</dependency>
<dependency>

@ -52,7 +52,7 @@ public class PolarisDiscoveryHandler {
* @return list of healthy instances
*/
public InstancesResponse getHealthyInstances(String service) {
String namespace = MetadataContextHolder.get().getFragmentContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
String namespace = MetadataContextHolder.get().getContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
MetadataConstant.POLARIS_TARGET_NAMESPACE, polarisDiscoveryProperties.getNamespace());
GetHealthyInstancesRequest getHealthyInstancesRequest = new GetHealthyInstancesRequest();

@ -74,7 +74,7 @@ public final class RouterUtils {
serviceMetadata = instanceList.get(0).getServiceMetadata();
}
String namespace = MetadataContextHolder.get().getFragmentContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
String namespace = MetadataContextHolder.get().getContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
MetadataConstant.POLARIS_TARGET_NAMESPACE, MetadataContext.LOCAL_NAMESPACE);
ServiceKey serviceKey = new ServiceKey(namespace, serviceName);

@ -74,7 +74,8 @@ public class RouterUtilsTest {
.thenReturn(testNamespaceAndService);
MetadataContext metadataContext = Mockito.mock(MetadataContext.class);
mockedMetadataContextHolder.when(MetadataContextHolder::get).thenReturn(metadataContext);
Mockito.when(metadataContext.getFragmentContext(anyString(), anyString(), anyString())).thenReturn(testNamespaceAndService);
Mockito.when(metadataContext.getContext(anyString(), anyString(), anyString()))
.thenReturn(testNamespaceAndService);
int instanceSize = 100;
int weight = 50;

@ -129,6 +129,10 @@ public class MetadataContext extends com.tencent.polaris.metadata.core.manager.M
super(MetadataConstant.POLARIS_TRANSITIVE_HEADER_PREFIX);
}
public static void setLocalService(String service) {
LOCAL_SERVICE = service;
}
private Map<String, String> getMetadataAsMap(MetadataType metadataType, TransitiveType transitiveType, boolean caller) {
MetadataContainer metadataContainer = getMetadataContainer(metadataType, caller);
Map<String, String> values = new HashMap<>();
@ -283,7 +287,7 @@ public class MetadataContext extends com.tencent.polaris.metadata.core.manager.M
}
}
public String getFragmentContext(String fragment, String key, String defaultValue) {
public String getContext(String fragment, String key, String defaultValue) {
return getFragmentContext(fragment).getOrDefault(key, defaultValue);
}
@ -338,8 +342,4 @@ public class MetadataContext extends com.tencent.polaris.metadata.core.manager.M
context.put(key, value);
putFragmentContext(fragment, context);
}
public static void setLocalService(String service) {
LOCAL_SERVICE = service;
}
}

@ -86,7 +86,7 @@
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-gateway-plugin</artifactId>
<artifactId>spring-cloud-starter-tencent-gateway-plugin</artifactId>
</dependency>
<dependency>

@ -194,7 +194,7 @@
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-gateway-plugin</artifactId>
<artifactId>spring-cloud-starter-tencent-gateway-plugin</artifactId>
<version>${revision}</version>
</dependency>

@ -20,7 +20,7 @@
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-gateway-plugin</artifactId>
<artifactId>spring-cloud-starter-tencent-gateway-plugin</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>

@ -21,7 +21,7 @@
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-gateway-plugin</artifactId>
<artifactId>spring-cloud-starter-tencent-gateway-plugin</artifactId>
</dependency>
<dependency>

@ -16,7 +16,7 @@
<modules>
<module>spring-cloud-tencent-featureenv-plugin</module>
<module>spring-cloud-tencent-gateway-plugin</module>
<module>spring-cloud-starter-tencent-gateway-plugin</module>
<module>spring-cloud-starter-tencent-discovery-adapter-plugin</module>
<module>spring-cloud-tencent-lossless-plugin</module>
<module>spring-cloud-starter-tencent-threadlocal-plugin</module>

@ -10,8 +10,8 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-tencent-gateway-plugin</artifactId>
<name>Spring Cloud Tencent Gateway Plugin</name>
<artifactId>spring-cloud-starter-tencent-gateway-plugin</artifactId>
<name>Spring Cloud Starter Tencent Gateway Plugin</name>
<dependencies>
<dependency>
@ -22,6 +22,7 @@
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
<optional>true</optional>
</dependency>
<dependency>

@ -79,7 +79,7 @@ public class EnhancedGatewayGlobalFilter implements GlobalFilter, Ordered {
metadataContext = MetadataContextHolder.get();
}
String governanceNamespace = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
String governanceNamespace = metadataContext.getContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
MetadataConstant.POLARIS_TARGET_NAMESPACE, MetadataContext.LOCAL_NAMESPACE);
@ -125,7 +125,8 @@ public class EnhancedGatewayGlobalFilter implements GlobalFilter, Ordered {
URI uri = exchange.getAttribute(GATEWAY_REQUEST_URL_ATTR);
enhancedPluginContext.getRequest().setUrl(uri);
if (uri != null) {
if (route != null && route.getUri().getScheme().contains("lb") && StringUtils.isNotEmpty(serviceId)) {
if (route != null && route.getUri().getScheme()
.contains("lb") && StringUtils.isNotEmpty(serviceId)) {
DefaultServiceInstance serviceInstance = new DefaultServiceInstance();
serviceInstance.setServiceId(serviceId);
serviceInstance.setHost(uri.getHost());

@ -136,7 +136,7 @@ public final class PolarisEnhancedPluginUtils {
@Nullable String calleeServiceName, @Nullable String calleeHost, @Nullable Integer calleePort,
URI uri, @Nullable Integer statusCode, long delay, @Nullable Throwable exception) {
String governanceNamespace = MetadataContextHolder.get().getFragmentContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
String governanceNamespace = MetadataContextHolder.get().getContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
MetadataConstant.POLARIS_TARGET_NAMESPACE, MetadataContext.LOCAL_NAMESPACE);
ServiceKey calleeServiceKey = new ServiceKey(governanceNamespace, StringUtils.isBlank(calleeServiceName) ? uri.getHost() : calleeServiceName);

@ -46,7 +46,7 @@ public class PolarisInstanceTransformer implements InstanceTransformer {
instance.setServiceMetadata(polarisServiceInstance.getServiceMetadata());
}
String namespace = MetadataContextHolder.get().getFragmentContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
String namespace = MetadataContextHolder.get().getContext(MetadataContext.FRAGMENT_APPLICATION_NONE,
MetadataConstant.POLARIS_TARGET_NAMESPACE, instance.getNamespace());
instance.setNamespace(namespace);

Loading…
Cancel
Save