feat:support namespace exports configuration if not created.

pull/1611/head
Haotian Zhang 3 months ago
parent 6f881b0cb6
commit dd5725a16d

@ -7,3 +7,4 @@
- [feat:support ipv6.](https://github.com/Tencent/spring-cloud-tencent/pull/1592) - [feat:support ipv6.](https://github.com/Tencent/spring-cloud-tencent/pull/1592)
- [feat:support config all recover enabled.](https://github.com/Tencent/spring-cloud-tencent/pull/1593) - [feat:support config all recover enabled.](https://github.com/Tencent/spring-cloud-tencent/pull/1593)
- [feat:support stat reporting path aggregation.](https://github.com/Tencent/spring-cloud-tencent/pull/1602) - [feat:support stat reporting path aggregation.](https://github.com/Tencent/spring-cloud-tencent/pull/1602)
- [feat:support namespace exports configuration if not created.](https://github.com/Tencent/spring-cloud-tencent/pull/1611)

@ -122,6 +122,11 @@ public class PolarisDiscoveryProperties {
*/ */
private Boolean allRecoverEnabled = true; private Boolean allRecoverEnabled = true;
/**
* namespace exports if not created.
*/
private String namespaceExports;
public String getInstanceId() { public String getInstanceId() {
return instanceId; return instanceId;
} }
@ -265,6 +270,14 @@ public class PolarisDiscoveryProperties {
this.registerEnabled = registerEnabled; this.registerEnabled = registerEnabled;
} }
public String getNamespaceExports() {
return namespaceExports;
}
public void setNamespaceExports(String namespaceExports) {
this.namespaceExports = namespaceExports;
}
@Override @Override
public String toString() { public String toString() {
return "PolarisDiscoveryProperties{" + return "PolarisDiscoveryProperties{" +
@ -284,6 +297,7 @@ public class PolarisDiscoveryProperties {
", zeroProtectionNeedTestConnectivity=" + zeroProtectionNeedTestConnectivity + ", zeroProtectionNeedTestConnectivity=" + zeroProtectionNeedTestConnectivity +
", preferIpv6=" + preferIpv6 + ", preferIpv6=" + preferIpv6 +
", allRecoverEnabled=" + allRecoverEnabled + ", allRecoverEnabled=" + allRecoverEnabled +
", namespaceExports='" + namespaceExports + '\'' +
'}'; '}';
} }
} }

@ -0,0 +1,43 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.polaris.registry;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.polaris.api.utils.StringUtils;
/**
* .
*
* @author Haotian Zhang
*/
public class NamespaceRegistrationCustomizer implements PolarisRegistrationCustomizer {
private final PolarisDiscoveryProperties polarisDiscoveryProperties;
public NamespaceRegistrationCustomizer(PolarisDiscoveryProperties polarisDiscoveryProperties) {
this.polarisDiscoveryProperties = polarisDiscoveryProperties;
}
@Override
public void customize(PolarisRegistration registration) {
String namespaceExports = polarisDiscoveryProperties.getNamespaceExports();
if (StringUtils.isNotBlank(namespaceExports)) {
registration.getMetadata().put("POLARIS_INTERNAL_NAMESPACE_EXPORTS", namespaceExports);
}
}
}

@ -95,4 +95,9 @@ public class PolarisServiceRegistryAutoConfiguration {
public PolarisWebApplicationCheck polarisWebApplicationCheck() { public PolarisWebApplicationCheck polarisWebApplicationCheck() {
return new PolarisWebApplicationCheck(); return new PolarisWebApplicationCheck();
} }
@Bean
public NamespaceRegistrationCustomizer namespaceRegistrationCustomizer(PolarisDiscoveryProperties polarisDiscoveryProperties) {
return new NamespaceRegistrationCustomizer(polarisDiscoveryProperties);
}
} }

@ -90,6 +90,11 @@
"defaultValue": true, "defaultValue": true,
"description": "is all recover enable. Default: true." "description": "is all recover enable. Default: true."
}, },
{
"name": "spring.cloud.polaris.discovery.namespace-exports",
"type": "java.lang.String",
"description": "namespace exports if not created."
},
{ {
"name": "spring.cloud.polaris.discovery.eager-load.enabled", "name": "spring.cloud.polaris.discovery.eager-load.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",

@ -25,6 +25,9 @@ import java.util.Set;
import com.tencent.cloud.common.spi.InstanceMetadataProvider; import com.tencent.cloud.common.spi.InstanceMetadataProvider;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils; import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.cloud.common.util.inet.PolarisInetUtils;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.metadata.core.constant.MetadataConstants;
import static com.tencent.cloud.common.constant.MetadataConstant.DefaultMetadata.DEFAULT_METADATA_SOURCE_SERVICE_NAME; import static com.tencent.cloud.common.constant.MetadataConstant.DefaultMetadata.DEFAULT_METADATA_SOURCE_SERVICE_NAME;
import static com.tencent.cloud.common.constant.MetadataConstant.DefaultMetadata.DEFAULT_METADATA_SOURCE_SERVICE_NAMESPACE; import static com.tencent.cloud.common.constant.MetadataConstant.DefaultMetadata.DEFAULT_METADATA_SOURCE_SERVICE_NAMESPACE;
@ -48,10 +51,20 @@ public class DefaultInstanceMetadataProvider implements InstanceMetadataProvider
@Override @Override
public Map<String, String> getMetadata() { public Map<String, String> getMetadata() {
return new HashMap<String, String>() {{ HashMap<String, String> defaultInstanceMetadata = new HashMap<>();
put(DEFAULT_METADATA_SOURCE_SERVICE_NAMESPACE, LOCAL_NAMESPACE); defaultInstanceMetadata.put(DEFAULT_METADATA_SOURCE_SERVICE_NAMESPACE, LOCAL_NAMESPACE);
put(DEFAULT_METADATA_SOURCE_SERVICE_NAME, LOCAL_SERVICE); defaultInstanceMetadata.put(DEFAULT_METADATA_SOURCE_SERVICE_NAME, LOCAL_SERVICE);
}};
String ipv4Address = PolarisInetUtils.getIpString(false);
if (StringUtils.isNotBlank(ipv4Address)) {
defaultInstanceMetadata.put(MetadataConstants.ADDRESS_IPV4, ipv4Address);
}
String ipv6Address = PolarisInetUtils.getIpString(true);
if (StringUtils.isNotBlank(ipv6Address)) {
defaultInstanceMetadata.put(MetadataConstants.ADDRESS_IPV6, ipv6Address);
}
return defaultInstanceMetadata;
} }
@Override @Override

@ -100,6 +100,12 @@ public final class PolarisContextEnvironmentPostProcessor implements Environment
polarisEnvProperties.put("spring.cloud.tencent.metadata.content.zone", zone); polarisEnvProperties.put("spring.cloud.tencent.metadata.content.zone", zone);
} }
// global namespace enabled
String globalNamespaceEnabled = environment.getProperty("global_namespace_enabled");
if (StringUtils.isNotBlank(globalNamespaceEnabled) && StringUtils.equals("true", globalNamespaceEnabled)) {
polarisEnvProperties.put("spring.cloud.polaris.discovery.namespace-exports", "*");
}
MapPropertySource propertySource = new MapPropertySource("polaris-env-properties", polarisEnvProperties); MapPropertySource propertySource = new MapPropertySource("polaris-env-properties", polarisEnvProperties);
environment.getPropertySources().addFirst(propertySource); environment.getPropertySources().addFirst(propertySource);
} }

Loading…
Cancel
Save