liubao68 commented on a change in pull request #1909:
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1909#discussion_r465413381



##########
File path: 
foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/registry/MicroserviceFactory.java
##########
@@ -49,14 +54,33 @@ public Microservice create(MicroserviceDefinition 
microserviceDefinition) {
 
   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);
-    // just check version format
-    new Version(version);
-    microservice.setVersion(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));
+    }
+    if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) &&
+        
!StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING))))
 {
+      
microservice.setVersion(envConfig.getString(envConfig.getString(VERSION_MAPPING)));
+    } else {
+      // just check version format
+      String version = 
configuration.getString(CONFIG_QUALIFIED_MICROSERVICE_VERSION_KEY,
+          DefinitionConst.DEFAULT_MICROSERVICE_VERSION);
+      new Version(version);

Review comment:
       version check can be done in setter, or easily missed checking when 
setting. e.g. for environment, this check is missed. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to