liubao68 closed pull request #788: [SCB-712]Do not register service path to
service center when not necessary
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/788
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/core/src/main/java/org/apache/servicecomb/core/definition/loader/SchemaLoader.java
b/core/src/main/java/org/apache/servicecomb/core/definition/loader/SchemaLoader.java
index 29b03da01..aa612c324 100644
---
a/core/src/main/java/org/apache/servicecomb/core/definition/loader/SchemaLoader.java
+++
b/core/src/main/java/org/apache/servicecomb/core/definition/loader/SchemaLoader.java
@@ -40,6 +40,8 @@
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
+import com.netflix.config.DynamicPropertyFactory;
+
import io.swagger.models.Swagger;
@Component
@@ -100,12 +102,18 @@ public SchemaMeta registerSchema(MicroserviceMeta
microserviceMeta, String schem
microserviceMeta.regSchemaMeta(schemaMeta);
- putSelfBasePathIfAbsent(microserviceName, swagger.getBasePath());
+ addSchemaPath2Microservice(microserviceName, swagger.getBasePath());
return schemaMeta;
}
- public void putSelfBasePathIfAbsent(String microserviceName, String
basePath) {
+ void addSchemaPath2Microservice(String microserviceName, String basePath) {
+ if
(DynamicPropertyFactory.getInstance().getBooleanProperty(Const.REGISTER_SERVICE_PATH,
false).get()) {
+ putSelfBasePathIfAbsent(microserviceName, basePath);
+ }
+ }
+
+ void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
if (basePath == null || basePath.length() == 0) {
return;
}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/unittest/UnitTestMeta.java
b/core/src/main/java/org/apache/servicecomb/core/unittest/UnitTestMeta.java
index fd1eece78..8d9c5b543 100644
--- a/core/src/main/java/org/apache/servicecomb/core/unittest/UnitTestMeta.java
+++ b/core/src/main/java/org/apache/servicecomb/core/unittest/UnitTestMeta.java
@@ -67,11 +67,7 @@ public ConsumerProviderManager getConsumerProviderManager() {
private ConsumerSchemaFactory consumerSchemaFactory;
- private SchemaLoader schemaLoader = new SchemaLoader() {
- @Override
- public void putSelfBasePathIfAbsent(String microserviceName, String
basePath) {
- }
- };
+ private SchemaLoader schemaLoader = new SchemaLoader();
private ServiceRegistry serviceRegistry;
diff --git a/core/src/main/resources/microservice.yaml
b/core/src/main/resources/microservice.yaml
index 9e415d6f7..c51b1defe 100644
--- a/core/src/main/resources/microservice.yaml
+++ b/core/src/main/resources/microservice.yaml
@@ -15,6 +15,6 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-cse-config-order: -500
+servicecomb-config-order: -500
servicecomb:
microserviceVersionFactory:
org.apache.servicecomb.core.definition.PrivateMicroserviceVersionMetaFactory
diff --git
a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
index fc3a4a709..6500c6439 100644
---
a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
+++
b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
@@ -78,11 +78,7 @@ public static void init() {
producerArgsMapperFactory.setConverterMgr(converterMgr);
MicroserviceMetaManager microserviceMetaManager = new
MicroserviceMetaManager();
- SchemaLoader schemaLoader = new SchemaLoader() {
- @Override
- public void putSelfBasePathIfAbsent(String microserviceName, String
basePath) {
- }
- };
+ SchemaLoader schemaLoader = new SchemaLoader();
CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new
CompositeSwaggerGeneratorContext();
producerSchemaFactory.setSwaggerEnv(swaggerEnv);
diff --git
a/demo/demo-multiple/multiple-client/src/main/resources/microservice.yaml
b/demo/demo-multiple/multiple-client/src/main/resources/microservice.yaml
index a9ddcdeeb..f06dd95db 100644
--- a/demo/demo-multiple/multiple-client/src/main/resources/microservice.yaml
+++ b/demo/demo-multiple/multiple-client/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-cse-config-order: 1000
+servicecomb-config-order: 1000
a-server.name: merged-server
b-server.name: merged-server
APPLICATION_ID: multiple
diff --git
a/demo/demo-multiple/multiple-server/src/main/resources/microservice.yaml
b/demo/demo-multiple/multiple-server/src/main/resources/microservice.yaml
index c3dd81b1b..94fb8d2bc 100644
--- a/demo/demo-multiple/multiple-server/src/main/resources/microservice.yaml
+++ b/demo/demo-multiple/multiple-server/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-cse-config-order: 1000
+servicecomb-config-order: 1000
APPLICATION_ID: multiple
service_description:
name: merged-server
diff --git a/demo/demo-schema/src/main/resources/microservice.yaml
b/demo/demo-schema/src/main/resources/microservice.yaml
index 92b69592c..d26c026d5 100644
--- a/demo/demo-schema/src/main/resources/microservice.yaml
+++ b/demo/demo-schema/src/main/resources/microservice.yaml
@@ -14,7 +14,7 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-cse-config-order: -1
+servicecomb-config-order: -1
cse:
test:
diff --git a/demo/demo-server-servlet/src/main/resources/microservice.yaml
b/demo/demo-server-servlet/src/main/resources/microservice.yaml
index 469a68eed..cb4ae437d 100644
--- a/demo/demo-server-servlet/src/main/resources/microservice.yaml
+++ b/demo/demo-server-servlet/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-cse-config-order: 100
+servicecomb-config-order: 100
servicecomb:
rest:
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/main/resources/microservice.yaml
b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/main/resources/microservice.yaml
index c6e5a22fe..0a7457f94 100644
---
a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/main/resources/microservice.yaml
+++
b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-cse-config-order: 1
+servicecomb-config-order: 1
APPLICATION_ID: spring-boot-jaxrstest
service_description:
name: jaxrsClient
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-server/src/main/resources/microservice.yaml
b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-server/src/main/resources/microservice.yaml
index 76a37044b..09c50e3fe 100644
---
a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-server/src/main/resources/microservice.yaml
+++
b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-server/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-cse-config-order: 1
+servicecomb-config-order: 1
APPLICATION_ID: spring-boot-jaxrstest
service_description:
name: jaxrs
diff --git
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/ConsumerTestsAfterBootup.java
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/ConsumerTestsAfterBootup.java
new file mode 100644
index 000000000..d89f20da1
--- /dev/null
+++
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/ConsumerTestsAfterBootup.java
@@ -0,0 +1,43 @@
+package org.apache.servicecomb.demo.springmvc.client;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+import org.apache.servicecomb.core.BootListener;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.springframework.stereotype.Component;
+
+/**
+ * Testing after bootup.
+ */
+@Component
+public class ConsumerTestsAfterBootup implements BootListener {
+ public void testRegisterPath() {
+ TestMgr.check(RegistryUtils.getMicroservice().getPaths().size(), 0);
+ }
+
+ @Override
+ public void onBootEvent(BootEvent event) {
+ if (event.getEventType() == BootListener.EventType.AFTER_REGISTRY) {
+ testRegisterPath();
+ if (!TestMgr.isSuccess()) {
+ TestMgr.summary();
+ throw new IllegalStateException("some tests are failed. ");
+ }
+ }
+ }
+}
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerSchemaFactoryHolder.java
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
similarity index 82%
rename from
demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerSchemaFactoryHolder.java
rename to
demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
index 687273b5b..d2d201aa3 100644
---
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerSchemaFactoryHolder.java
+++
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
@@ -29,26 +29,24 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectWriter;
-import com.google.common.base.Charsets;
-import com.google.common.hash.Hashing;
import io.swagger.models.Swagger;
import io.swagger.util.Yaml;
/**
- * Testing schemas generation should be same for each boot up and accommodate
swagger.
+ * Testing after bootup.
*/
@Component
-public class ProducerSchemaFactoryHolder implements BootListener {
- private static final Logger LOGGER =
LoggerFactory.getLogger(ProducerSchemaFactoryHolder.class);
+public class ProducerTestsAfterBootup implements BootListener {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(ProducerTestsAfterBootup.class);
private ObjectWriter writer = Yaml.pretty();
@Autowired
private ProducerSchemaFactory factory;
- public void test() {
- LOGGER.info("ProducerSchemaFactoryHolder testing start");
+ public void testSchemaNotChange() {
+ LOGGER.info("ProducerTestsAfterBootup testing start");
SchemaMeta meta =
factory.getOrCreateProducerSchema("customer-service",
"test1",
@@ -58,13 +56,11 @@ public void test() {
TestMgr.check("07a48acef4cc1a7f2387d695923c49e98951a974e4f51cf1356d6878db48888f",
RegistryUtils.calcSchemaSummary(codeFirst));
TestMgr.check(codeFirst.length(), 899);
-
- if (!TestMgr.isSuccess()) {
- TestMgr.summary();
- throw new IllegalStateException("schema not the same. ");
- }
}
+ public void testRegisterPath() {
+ TestMgr.check(RegistryUtils.getMicroservice().getPaths().size(), 9);
+ }
private String getSwaggerContent(Swagger swagger) {
try {
return writer.writeValueAsString(swagger);
@@ -76,7 +72,12 @@ private String getSwaggerContent(Swagger swagger) {
@Override
public void onBootEvent(BootEvent event) {
if (event.getEventType() == BootListener.EventType.AFTER_REGISTRY) {
- test();
+ testSchemaNotChange();
+ testRegisterPath();
+ if (!TestMgr.isSuccess()) {
+ TestMgr.summary();
+ throw new IllegalStateException("some tests are failed. ");
+ }
}
}
}
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
index 7098320ef..68fd39c7b 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
@@ -32,6 +32,7 @@ service_description:
servicecomb:
service:
registry:
+ registerPath: true
address: http://127.0.0.1:30100
client:
timeout:
diff --git a/foundations/foundation-config/src/test/resources/test1.yaml
b/foundations/foundation-config/src/test/resources/test1.yaml
index 5a544a23c..708d0e82f 100644
--- a/foundations/foundation-config/src/test/resources/test1.yaml
+++ b/foundations/foundation-config/src/test/resources/test1.yaml
@@ -15,7 +15,7 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-cse-config-order: "1"
+servicecomb-config-order: "1"
trace:
handler:
diff --git a/foundations/foundation-config/src/test/resources/test2.yaml
b/foundations/foundation-config/src/test/resources/test2.yaml
index a0aa39006..dc00542b2 100644
--- a/foundations/foundation-config/src/test/resources/test2.yaml
+++ b/foundations/foundation-config/src/test/resources/test2.yaml
@@ -15,7 +15,7 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-cse-config-order: 0
+servicecomb-config-order: 0
dsf:
serializer:
diff --git
a/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
b/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
index b67cd534d..7eb6f43a8 100644
---
a/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
+++
b/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
@@ -68,7 +68,7 @@ public void remoteHelloPojo_sayHelloAgain() {
assertThat(result, is("Hello Message slow"));
assertThat(elapsedTime,
- is(both(greaterThan(5000L)).and(lessThan(6000L))));
+ is(both(greaterThan(4000L)).and(lessThan(7000L))));
}
@Test
diff --git
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
index 9f1d48274..84e842485 100644
---
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
+++
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
@@ -182,4 +182,6 @@ private Const() {
public static final String INSTANCE_PUBKEY_PRO = "publickey";
public static final String SERVICECENTER_FRAMEWORK_VERSION = "1.0.0";
+
+ public static final String REGISTER_SERVICE_PATH =
"servicecomb.service.registry.registerPath";
}
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services