[ https://issues.apache.org/jira/browse/SCB-396?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16400373#comment-16400373 ]
ASF GitHub Bot commented on SCB-396: ------------------------------------ liubao68 closed pull request #591: [SCB-396] java-sdk needs to distinguish the services belongs to the devops stage(environment) URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/591 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): 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 e6613fa3e..22e4709cc 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 @@ -61,4 +61,7 @@ String CONFIG_DEFAULT_REGISTER_BY = "SDK"; + String SERVICECOMB_ENV = "SERVICECOMB_ENV"; + + String DEFAULT_SERVICECOMB_ENV = ""; } diff --git a/foundations/foundation-config/src/main/resources/mapping.yaml b/foundations/foundation-config/src/main/resources/mapping.yaml index baac846af..0346b782e 100644 --- a/foundations/foundation-config/src/main/resources/mapping.yaml +++ b/foundations/foundation-config/src/main/resources/mapping.yaml @@ -19,3 +19,6 @@ eureka: client: serviceUrl: defaultZone: registry.client.serviceUrl.defaultZone + +service_description: + environment: SERVICECOMB_ENV \ No newline at end of file diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/Microservice.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/Microservice.java index 1694ef0cb..6e9007259 100644 --- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/Microservice.java +++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/Microservice.java @@ -38,6 +38,8 @@ private String registerBy; + private String environment; + private String appId; private String serviceName; @@ -209,4 +211,12 @@ public String getRegisterBy() { public void setRegisterBy(String registerBy) { this.registerBy = registerBy; } + + public String getEnvironment() { + return environment; + } + + public void setEnvironment(String environment) { + this.environment = environment; + } } diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceFactory.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceFactory.java index 5c0c9735c..4e40aa10e 100644 --- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceFactory.java +++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceFactory.java @@ -24,6 +24,8 @@ import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_QUALIFIED_MICROSERVICE_ROLE_KEY; import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_QUALIFIED_MICROSERVICE_VERSION_KEY; import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.DEFAULT_MICROSERVICE_NAME; +import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.SERVICECOMB_ENV; +import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.DEFAULT_SERVICECOMB_ENV; import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.CONFIG_ALLOW_CROSS_APP_KEY; import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.DEFAULT_APPLICATION_ID; import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.DEFAULT_MICROSERVICE_VERSION; @@ -60,6 +62,7 @@ private Microservice createMicroserviceFromDefinition(Configuration configuratio microservice.setPaths(ConfigurePropertyUtils.getMicroservicePaths(configuration)); Map<String, String> propertiesMap = MicroservicePropertiesLoader.INSTANCE.loadProperties(configuration); microservice.setProperties(propertiesMap); + microservice.setEnvironment(configuration.getString(SERVICECOMB_ENV, DEFAULT_SERVICECOMB_ENV)); // set alias name when allow cross app if (allowCrossApp(propertiesMap)) { diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestMicroService.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestMicroService.java index 9db34da4e..c1ef3f5ab 100644 --- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestMicroService.java +++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestMicroService.java @@ -62,6 +62,7 @@ public void testDefaultValues() { Assert.assertNull(oMicroservice.getVersion()); Assert.assertEquals(0, oMicroservice.getPaths().size()); Assert.assertNull(oMicroservice.getFramework()); + Assert.assertNull(oMicroservice.getEnvironment()); } @Test @@ -80,6 +81,7 @@ public void testInitializedValues() { Assert.assertEquals("JAVA-CHASSIS", oMicroservice.getFramework().getName()); Assert.assertEquals("x.x.x", oMicroservice.getFramework().getVersion()); Assert.assertEquals("SDK", oMicroservice.getRegisterBy()); + Assert.assertEquals("development", oMicroservice.getEnvironment()); } private void initMicroservice() { @@ -100,5 +102,6 @@ private void initMicroservice() { framework.setVersion("x.x.x"); oMicroservice.setFramework(framework); oMicroservice.setRegisterBy("SDK"); + oMicroservice.setEnvironment("development"); } } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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 > java-sdk needs to distinguish the instance belongs to the devops > stage(environment) > ----------------------------------------------------------------------------------- > > Key: SCB-396 > URL: https://issues.apache.org/jira/browse/SCB-396 > Project: Apache ServiceComb > Issue Type: Task > Components: Java-Chassis > Reporter: WeiChao > Assignee: WeiChao > Priority: Major > Fix For: service-center-1.0.0-m2 > > > sdk support registers service environment according to environment variables. > servcie center registers the service interface, requesting the field with the > identification phase in the body,\{"service":{"serviceId":"xxx", > "environment":"production"}}. > the name of the environment variable should be aligned with GOSDK and be > unified. > the default value of this field is blank. -- This message was sent by Atlassian JIRA (v7.6.3#76005)