You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2020/08/06 09:15:05 UTC
[servicecomb-java-chassis] branch master updated: [SCB-2057] set
the AppId, ServiceName,
Version information by reading the environment variable (#1909)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new f8c550e [SCB-2057] set the AppId, ServiceName, Version information by reading the environment variable (#1909)
f8c550e is described below
commit f8c550edfd813e82d123a6537c529645ce174dce
Author: GuoYL <53...@users.noreply.github.com>
AuthorDate: Thu Aug 6 17:14:56 2020 +0800
[SCB-2057] set the AppId, ServiceName, Version information by reading the environment variable (#1909)
(cherry picked from commit 9f6c57220fa48cd2f53324124ae0271b5ddae16f)
---
.../common/base/ServiceCombConstants.java | 6 ++++
.../registry/api/registry/MicroserviceFactory.java | 37 ++++++++++++++++++----
2 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/base/ServiceCombConstants.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/base/ServiceCombConstants.java
index a4f3273..53214fa 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/base/ServiceCombConstants.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/base/ServiceCombConstants.java
@@ -68,4 +68,10 @@ public interface ServiceCombConstants {
String DEVELOPMENT_SERVICECOMB_ENV = "development";
String PRODUCTION_SERVICECOMB_ENV = "production";
+
+ String SERVICE_MAPPING = "SERVICE_MAPPING";
+
+ String VERSION_MAPPING = "VERSION_MAPPING";
+
+ String APP_MAPPING = "APP_MAPPING";
}
diff --git a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/registry/MicroserviceFactory.java b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/registry/MicroserviceFactory.java
index 855afa3..d3f9f31 100644
--- a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/registry/MicroserviceFactory.java
+++ b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/registry/MicroserviceFactory.java
@@ -24,10 +24,15 @@ import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants
import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.DEFAULT_MICROSERVICE_NAME;
import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.DEFAULT_SERVICECOMB_ENV;
import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.SERVICECOMB_ENV;
+import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.APP_MAPPING;
+import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.SERVICE_MAPPING;
+import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.VERSION_MAPPING;
import java.util.Map;
import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.EnvironmentConfiguration;
+import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.registry.config.ConfigurePropertyUtils;
import org.apache.servicecomb.registry.config.MicroservicePropertiesLoader;
import org.apache.servicecomb.registry.definition.DefinitionConst;
@@ -49,14 +54,34 @@ public class MicroserviceFactory {
private Microservice createMicroserviceFromDefinition(Configuration configuration) {
Microservice microservice = new Microservice();
- microservice.setServiceName(configuration.getString(CONFIG_QUALIFIED_MICROSERVICE_NAME_KEY,
- DEFAULT_MICROSERVICE_NAME));
- microservice.setAppId(configuration.getString(CONFIG_APPLICATION_ID_KEY, DefinitionConst.DEFAULT_APPLICATION_ID));
- String version = configuration.getString(CONFIG_QUALIFIED_MICROSERVICE_VERSION_KEY,
- DefinitionConst.DEFAULT_MICROSERVICE_VERSION);
+
+ EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
+ if (!StringUtils.isEmpty(envConfig.getString(APP_MAPPING)) &&
+ !StringUtils.isEmpty(envConfig.getString(envConfig.getString(APP_MAPPING)))) {
+ microservice.setAppId(envConfig.getString(envConfig.getString(APP_MAPPING)));
+ } else {
+ microservice.setAppId(configuration
+ .getString(CONFIG_APPLICATION_ID_KEY, DefinitionConst.DEFAULT_APPLICATION_ID));
+ }
+ if (!StringUtils.isEmpty(envConfig.getString(SERVICE_MAPPING)) &&
+ !StringUtils.isEmpty(envConfig.getString(envConfig.getString(SERVICE_MAPPING)))) {
+ microservice.setServiceName(envConfig.getString(envConfig.getString(SERVICE_MAPPING)));
+ } else {
+ microservice.setServiceName(configuration.getString(CONFIG_QUALIFIED_MICROSERVICE_NAME_KEY,
+ DEFAULT_MICROSERVICE_NAME));
+ }
+ String version;
+ if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) &&
+ !StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING)))) {
+ version = envConfig.getString(envConfig.getString(VERSION_MAPPING));
+ } else {
+ version = configuration.getString(CONFIG_QUALIFIED_MICROSERVICE_VERSION_KEY,
+ DefinitionConst.DEFAULT_MICROSERVICE_VERSION);
+ }
// just check version format
new Version(version);
microservice.setVersion(version);
+
setDescription(configuration, microservice);
microservice.setLevel(configuration.getString(CONFIG_QUALIFIED_MICROSERVICE_ROLE_KEY, "FRONT"));
microservice.setPaths(ConfigurePropertyUtils.getMicroservicePaths(configuration));
@@ -92,6 +117,6 @@ public class MicroserviceFactory {
}
private boolean allowCrossApp(Map<String, String> propertiesMap) {
- return Boolean.valueOf(propertiesMap.get(DefinitionConst.CONFIG_ALLOW_CROSS_APP_KEY));
+ return Boolean.parseBoolean(propertiesMap.get(DefinitionConst.CONFIG_ALLOW_CROSS_APP_KEY));
}
}