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
commit d9673d342d06ce06f21034eea393e69ffc9be224 Author: liubao <[email protected]> AuthorDate: Wed Jun 3 11:52:04 2020 +0800 [SCB-1978]add samples to use two different service centers --- .../demo-multi-service-center-client/pom.xml | 205 +++++++++++++++++++++ .../demo/multiServiceCenterClient/Application.java | 48 +++++ .../multiServiceCenterClient/IServerEndpoint.java} | 23 +-- .../multiServiceCenterClient/ServerATest.java} | 29 ++- .../ServerBServiceCenterConfiguration.java | 61 ++++++ .../multiServiceCenterClient/ServerBTest.java} | 34 ++-- .../src/main/resources/application.yml | 38 ++++ .../MultiServiceCenterIT.java} | 32 ++-- .../demo-multi-service-center-serverA/pom.xml | 88 +++++++++ .../multiServiceCenter/ServerApplication.java} | 29 ++- .../demo/multiServiceCenter/ServerEndpoint.java | 42 +++++ .../src/main/resources/application.yml | 32 ++++ .../src/main/resources/logback.xml | 50 +++++ .../demo-multi-service-center-serverB/pom.xml | 88 +++++++++ .../ServerApplication.java} | 29 ++- .../multiServiceCenterServerB/ServerEndpoint.java | 42 +++++ .../src/main/resources/application.yml | 32 ++++ .../src/main/resources/logback.xml | 50 +++++ demo/demo-multi-service-center/pom.xml | 51 +++++ .../servicecomb/demo/CategorizedTestCase.java | 12 +- demo/pom.xml | 2 +- .../foundation/common/utils/BeanUtils.java | 11 +- .../servicecomb/serviceregistry/RegistryUtils.java | 15 +- .../config/ServiceRegistryConfig.java | 2 +- 24 files changed, 921 insertions(+), 124 deletions(-) diff --git a/demo/demo-multi-service-center/demo-multi-service-center-client/pom.xml b/demo/demo-multi-service-center/demo-multi-service-center-client/pom.xml new file mode 100644 index 0000000..65bb675 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-client/pom.xml @@ -0,0 +1,205 @@ +<?xml version="1.0"?> +<!-- + ~ 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. + --> + +<project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <artifactId>demo-multi-service-center-client</artifactId> + <name>Java Chassis::Demo::Multi Service Center Client</name> + <parent> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>demo-multi-service-center</artifactId> + <version>2.1.0-SNAPSHOT</version> + </parent> + + <properties> + <demo.main>org.apache.servicecomb.demo.multiServiceCenterClient.Application</demo.main> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>java-chassis-spring-boot-starter-servlet</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>demo-schema</artifactId> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>com.github.odavid.maven.plugins</groupId> + <artifactId>mixin-maven-plugin</artifactId> + <configuration> + <mixins> + <mixin> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>docker-run-config</artifactId> + <version>${project.version}</version> + </mixin> + </mixins> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>docker</id> + <properties> + <demo.service.name>demo-multi-registries-server</demo.service.name> + </properties> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + <configuration> + <images> + <image> + <name>servicecomb/service-center</name> + <alias>service-center-01</alias> + <run> + <wait> + <log>server is ready</log> + <tcp> + <ports> + <port>30100</port> + </ports> + </tcp> + <time>60000</time> + </wait> + <ports> + <port>30100:30100</port> + </ports> + </run> + </image> + <image> + <name>servicecomb/service-center</name> + <alias>service-center-02</alias> + <run> + <wait> + <log>server is ready</log> + <tcp> + <ports> + <port>30100</port> + </ports> + </tcp> + <time>60000</time> + </wait> + <ports> + <port>40100:30100</port> + </ports> + </run> + </image> + <image> + <name>demo-multi-service-center-serverA:${project.version}</name> + <alias>demo-multi-service-center-serverA</alias> + <run> + <env> + <JAVA_OPTS> + -Dservicecomb.service.registry.address=http://${service-center-01}:30100 + -Dservicecomb.service.publishAddress=${docker.hostname} + </JAVA_OPTS> + <JAR_PATH>/maven/maven/demo-multi-service-center-serverA-${project.version}.jar</JAR_PATH> + </env> + <links> + <link>service-center-01:service-center-01</link> + </links> + <wait> + <log>Register microservice instance success</log> + <tcp> + <ports> + <port>8080</port> + </ports> + </tcp> + <time>120000</time> + </wait> + <ports> + <port>8080:8080</port> + </ports> + <dependsOn> + <container>service-center-01</container> + </dependsOn> + </run> + </image> + <image> + <name>demo-multi-service-center-serverB:${project.version}</name> + <alias>demo-multi-service-center-serverB</alias> + <run> + <env> + <JAVA_OPTS> + -Dservicecomb.service.registry.address=http://${service-center-02}:30100 + -Dservicecomb.service.publishAddress=${docker.hostname} + </JAVA_OPTS> + <JAR_PATH>/maven/maven/demo-multi-service-center-serverB-${project.version}.jar</JAR_PATH> + </env> + <links> + <link>service-center-02:service-center-02</link> + </links> + <wait> + <log>Register microservice instance success</log> + <tcp> + <ports> + <port>8082</port> + </ports> + </tcp> + <time>120000</time> + </wait> + <ports> + <port>8082:8082</port> + </ports> + <dependsOn> + <container>service-center-02</container> + </dependsOn> + </run> + </image> + </images> + </configuration> + <executions> + <execution> + <id>start</id> + <phase>pre-integration-test</phase> + <goals> + <goal>start</goal> + </goals> + </execution> + <execution> + <id>stop</id> + <phase>post-integration-test</phase> + <goals> + <goal>stop</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + <plugins> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/Application.java b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/Application.java new file mode 100644 index 0000000..e0d7d65 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/Application.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package org.apache.servicecomb.demo.multiServiceCenterClient; + +import org.apache.servicecomb.demo.CategorizedTestCaseRunner; +import org.apache.servicecomb.demo.TestMgr; +import org.apache.servicecomb.springboot2.starter.EnableServiceComb; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.stereotype.Component; + +@SpringBootApplication +@EnableServiceComb +@Component +public class Application { + + public static void main(final String[] args) throws Exception { + new SpringApplicationBuilder().sources(Application.class) + .web(WebApplicationType.SERVLET).build().run(args); + + runTest(); + } + + public static void runTest() throws Exception { + CategorizedTestCaseRunner.runCategorizedTestCase("demo-multi-service-center-serverA"); + + TestMgr.summary(); + if (!TestMgr.errors().isEmpty()) { + throw new IllegalStateException("tests failed"); + } + } +} diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/IServerEndpoint.java similarity index 62% copy from demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java copy to demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/IServerEndpoint.java index dd144ed..9d10324 100644 --- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java +++ b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/IServerEndpoint.java @@ -15,25 +15,8 @@ * limitations under the License. */ -package org.apache.servicecomb.demo; +package org.apache.servicecomb.demo.multiServiceCenterClient; -public interface CategorizedTestCase { - /** - * test case which only successful in REST transport - */ - void testRestTransport() throws Exception; - - /** - * test case which only successful in HIGHWAY transport - */ - void testHighwayTransport() throws Exception; - - /** - * test case which successful in both REST and HIGHWAY transport - */ - void testAllTransport() throws Exception; - - default String getMicroserviceName() { - return null; - } +public interface IServerEndpoint { + String getName(String name); } diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/ServerATest.java similarity index 57% copy from demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java copy to demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/ServerATest.java index dd144ed..9ddd4d8 100644 --- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java +++ b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/ServerATest.java @@ -15,25 +15,20 @@ * limitations under the License. */ -package org.apache.servicecomb.demo; +package org.apache.servicecomb.demo.multiServiceCenterClient; -public interface CategorizedTestCase { - /** - * test case which only successful in REST transport - */ - void testRestTransport() throws Exception; +import org.apache.servicecomb.demo.CategorizedTestCase; +import org.apache.servicecomb.demo.TestMgr; +import org.apache.servicecomb.provider.pojo.RpcReference; +import org.springframework.stereotype.Component; - /** - * test case which only successful in HIGHWAY transport - */ - void testHighwayTransport() throws Exception; +@Component +public class ServerATest implements CategorizedTestCase { + @RpcReference(microserviceName = "demo-multi-service-center-serverA", schemaId = "ServerEndpoint") + private IServerEndpoint serverEndpoint; - /** - * test case which successful in both REST and HIGHWAY transport - */ - void testAllTransport() throws Exception; - - default String getMicroserviceName() { - return null; + @Override + public void testRestTransport() throws Exception { + TestMgr.check("hello", serverEndpoint.getName("hello")); } } diff --git a/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/ServerBServiceCenterConfiguration.java b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/ServerBServiceCenterConfiguration.java new file mode 100644 index 0000000..8e73d3c --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/ServerBServiceCenterConfiguration.java @@ -0,0 +1,61 @@ +/* + * 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. + */ + +package org.apache.servicecomb.demo.multiServiceCenterClient; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.servicecomb.foundation.common.net.IpPort; +import org.apache.servicecomb.foundation.common.net.NetUtils; +import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.netflix.config.DynamicPropertyFactory; + +@Configuration +public class ServerBServiceCenterConfiguration { + @Bean("serverBServiceCenterConfig") + public ServiceRegistryConfig serverBServiceCenterConfig() { + ServiceRegistryConfig config = ServiceRegistryConfig.buildFromConfiguration(); + String address = DynamicPropertyFactory.getInstance() + .getStringProperty("servicecomb.service.registry-serverB.address", null) + .get(); + if (address == null) { + throw new IllegalStateException("service center address is required."); + } + String[] urls = address.split(","); + List<String> uriList = Arrays.asList(urls); + ArrayList<IpPort> ipPortList = new ArrayList<>(); + uriList.forEach(anUriList -> { + try { + URI uri = new URI(anUriList.trim()); + if ("https".equals(uri.getScheme())) { + config.setSsl(true); + } + ipPortList.add(NetUtils.parseIpPort(uri)); + } catch (Exception e) { + throw new IllegalStateException("service center address is required.", e); + } + }); + config.setIpPort(ipPortList); + return config; + } +} diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/ServerBTest.java similarity index 53% copy from demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java copy to demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/ServerBTest.java index dd144ed..4aa9dc2 100644 --- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java +++ b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/java/org/apache/servicecomb/demo/multiServiceCenterClient/ServerBTest.java @@ -15,25 +15,25 @@ * limitations under the License. */ -package org.apache.servicecomb.demo; +package org.apache.servicecomb.demo.multiServiceCenterClient; -public interface CategorizedTestCase { - /** - * test case which only successful in REST transport - */ - void testRestTransport() throws Exception; +import org.apache.servicecomb.demo.CategorizedTestCase; +import org.apache.servicecomb.demo.TestMgr; +import org.apache.servicecomb.provider.pojo.RpcReference; +import org.springframework.stereotype.Component; - /** - * test case which only successful in HIGHWAY transport - */ - void testHighwayTransport() throws Exception; +@Component +public class ServerBTest implements CategorizedTestCase { + @RpcReference(microserviceName = "demo-multi-service-center-serverB", schemaId = "ServerEndpoint") + private IServerEndpoint serverEndpoint; - /** - * test case which successful in both REST and HIGHWAY transport - */ - void testAllTransport() throws Exception; + @Override + public void testRestTransport() throws Exception { + TestMgr.check("hello", serverEndpoint.getName("hello")); + } - default String getMicroserviceName() { - return null; + @Override + public String getMicroserviceName() { + return "demo-multi-service-center-serverB"; } -} +} \ No newline at end of file diff --git a/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/resources/application.yml b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/resources/application.yml new file mode 100644 index 0000000..ebba6a0 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-client/src/main/resources/application.yml @@ -0,0 +1,38 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +server: + port: 8084 + +# java-chassis configurations +APPLICATION_ID: demo-multi-service-center +service_description: + name: demo-multi-service-center-client + version: 0.0.2 +servicecomb: + service: + registry: + address: http://127.0.0.1:30100 + registry-serverB: + address: http://127.0.0.1:40100 + rest: + address: 0.0.0.0:8084 + + handler: + chain: + Consumer: + default: loadbalance \ No newline at end of file diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java b/demo/demo-multi-service-center/demo-multi-service-center-client/src/test/java/org/apache/servicecomb/demo/multiServiceCenterClient/MultiServiceCenterIT.java similarity index 61% copy from demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java copy to demo/demo-multi-service-center/demo-multi-service-center-client/src/test/java/org/apache/servicecomb/demo/multiServiceCenterClient/MultiServiceCenterIT.java index dd144ed..e1c9e8e 100644 --- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java +++ b/demo/demo-multi-service-center/demo-multi-service-center-client/src/test/java/org/apache/servicecomb/demo/multiServiceCenterClient/MultiServiceCenterIT.java @@ -15,25 +15,25 @@ * limitations under the License. */ -package org.apache.servicecomb.demo; +package org.apache.servicecomb.demo.multiServiceCenterClient; -public interface CategorizedTestCase { - /** - * test case which only successful in REST transport - */ - void testRestTransport() throws Exception; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; - /** - * test case which only successful in HIGHWAY transport - */ - void testHighwayTransport() throws Exception; +import org.apache.servicecomb.demo.TestMgr; +import org.junit.Before; +import org.junit.Test; - /** - * test case which successful in both REST and HIGHWAY transport - */ - void testAllTransport() throws Exception; +public class MultiServiceCenterIT { + @Before + public void setUp() throws Exception { + TestMgr.errors().clear(); + } + + @Test + public void clientGetsNoError() throws Exception { + Application.main(new String[0]); - default String getMicroserviceName() { - return null; + assertThat(TestMgr.errors().isEmpty(), is(true)); } } diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverA/pom.xml b/demo/demo-multi-service-center/demo-multi-service-center-serverA/pom.xml new file mode 100644 index 0000000..7e11ce2 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverA/pom.xml @@ -0,0 +1,88 @@ +<?xml version="1.0"?> +<!-- + ~ 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. + --> + +<project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <artifactId>demo-multi-service-center-serverA</artifactId> + <name>Java Chassis::Demo::Multi Registries Server</name> + <parent> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>demo-multi-service-center</artifactId> + <version>2.1.0-SNAPSHOT</version> + </parent> + + <properties> + <demo.main>org.apache.servicecomb.demo.multiServiceCenter.ServerApplication</demo.main> + </properties> + <dependencies> + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>java-chassis-spring-boot-starter-servlet</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>demo-schema</artifactId> + </dependency> + + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>com.github.odavid.maven.plugins</groupId> + <artifactId>mixin-maven-plugin</artifactId> + <configuration> + <mixins> + <mixin> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>docker-build-config</artifactId> + <version>${project.version}</version> + </mixin> + </mixins> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>docker</id> + <build> + <plugins> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.commonjava.maven.plugins</groupId> + <artifactId>directory-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerApplication.java similarity index 58% copy from demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java copy to demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerApplication.java index dd144ed..ad905c9 100644 --- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerApplication.java @@ -15,25 +15,18 @@ * limitations under the License. */ -package org.apache.servicecomb.demo; +package org.apache.servicecomb.demo.multiServiceCenter; -public interface CategorizedTestCase { - /** - * test case which only successful in REST transport - */ - void testRestTransport() throws Exception; +import org.apache.servicecomb.springboot2.starter.EnableServiceComb; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; - /** - * test case which only successful in HIGHWAY transport - */ - void testHighwayTransport() throws Exception; - - /** - * test case which successful in both REST and HIGHWAY transport - */ - void testAllTransport() throws Exception; - - default String getMicroserviceName() { - return null; +@SpringBootApplication +@EnableServiceComb +public class ServerApplication { + public static void main(final String[] args) throws Exception { + new SpringApplicationBuilder().sources(ServerApplication.class) + .web(WebApplicationType.SERVLET).build().run(args); } } diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerEndpoint.java b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerEndpoint.java new file mode 100644 index 0000000..2e6efa6 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerEndpoint.java @@ -0,0 +1,42 @@ +/* + * 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. + */ + +package org.apache.servicecomb.demo.multiServiceCenter; + +import javax.ws.rs.core.MediaType; + +import org.apache.servicecomb.core.Invocation; +import org.apache.servicecomb.provider.rest.common.RestSchema; +import org.apache.servicecomb.swagger.invocation.context.ContextUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@RestSchema(schemaId = "ServerEndpoint") +@RequestMapping(path = "/register/url/prefix", produces = MediaType.APPLICATION_JSON) +public class ServerEndpoint { + private static final Logger LOGGER + = LoggerFactory.getLogger(ServerEndpoint.class); + + @GetMapping(path = "/getName") + public String getName(@RequestParam(name = "name") String name) { + ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked."); + return name; + } +} diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/resources/application.yml b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/resources/application.yml new file mode 100644 index 0000000..0ff9269 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/resources/application.yml @@ -0,0 +1,32 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +server: + port: 8080 + +# java-chassis configurations + +APPLICATION_ID: demo-multi-service-center +service_description: + name: demo-multi-service-center-serverA + version: 0.0.2 +servicecomb: + service: + registry: + address: http://127.0.0.1:30100 + rest: + address: 0.0.0.0:8080 \ No newline at end of file diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/resources/logback.xml b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/resources/logback.xml new file mode 100644 index 0000000..0d627f2 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/resources/logback.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<configuration scan="true"> + <appender name="STDOUT-TRACING" class="ch.qos.logback.core.ConsoleAppender"> + <!-- If applicable, can use ch.qos.logback.classic.filter.MarkerFilter --> + <filter class="org.apache.servicecomb.foundation.logback.MarkerFilter"> + <Marker>SERVICECOMB_MARKER</Marker> + <OnMismatch>DENY</OnMismatch> + <OnMatch>ACCEPT</OnMatch> + </filter> + + <encoder> + <pattern>%d [%level] [%thread][%X{SERVICECOMB_TRACE_ID}] - %msg (%F:%L\)%n</pattern> + </encoder> + </appender> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <!-- If applicable, can use ch.qos.logback.classic.filter.MarkerFilter --> + <filter class="org.apache.servicecomb.foundation.logback.MarkerFilter"> + <Marker>SERVICECOMB_MARKER</Marker> + <OnMismatch>ACCEPT</OnMismatch> + <OnMatch>DENY</OnMatch> + </filter> + + <encoder> + <pattern>%d [%level] [%thread] - %msg (%F:%L\)%n</pattern> + </encoder> + </appender> + + <root level="info"> + <appender-ref ref="STDOUT"/> + <appender-ref ref="STDOUT-TRACING"/> + </root> +</configuration> \ No newline at end of file diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverB/pom.xml b/demo/demo-multi-service-center/demo-multi-service-center-serverB/pom.xml new file mode 100644 index 0000000..c933b1f --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverB/pom.xml @@ -0,0 +1,88 @@ +<?xml version="1.0"?> +<!-- + ~ 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. + --> + +<project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <artifactId>demo-multi-service-center-serverB</artifactId> + <name>Java Chassis::Demo::Multi Service Center ServerB</name> + <parent> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>demo-multi-service-center</artifactId> + <version>2.1.0-SNAPSHOT</version> + </parent> + + <properties> + <demo.main>org.apache.servicecomb.demo.multiServiceCenterServerB.ServerApplication</demo.main> + </properties> + <dependencies> + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>java-chassis-spring-boot-starter-servlet</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>demo-schema</artifactId> + </dependency> + + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>com.github.odavid.maven.plugins</groupId> + <artifactId>mixin-maven-plugin</artifactId> + <configuration> + <mixins> + <mixin> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>docker-build-config</artifactId> + <version>${project.version}</version> + </mixin> + </mixins> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>docker</id> + <build> + <plugins> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.commonjava.maven.plugins</groupId> + <artifactId>directory-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerApplication.java similarity index 57% copy from demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java copy to demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerApplication.java index dd144ed..531e8ff 100644 --- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerApplication.java @@ -15,25 +15,18 @@ * limitations under the License. */ -package org.apache.servicecomb.demo; +package org.apache.servicecomb.demo.multiServiceCenterServerB; -public interface CategorizedTestCase { - /** - * test case which only successful in REST transport - */ - void testRestTransport() throws Exception; +import org.apache.servicecomb.springboot2.starter.EnableServiceComb; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; - /** - * test case which only successful in HIGHWAY transport - */ - void testHighwayTransport() throws Exception; - - /** - * test case which successful in both REST and HIGHWAY transport - */ - void testAllTransport() throws Exception; - - default String getMicroserviceName() { - return null; +@SpringBootApplication +@EnableServiceComb +public class ServerApplication { + public static void main(final String[] args) throws Exception { + new SpringApplicationBuilder().sources(ServerApplication.class) + .web(WebApplicationType.SERVLET).build().run(args); } } diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerEndpoint.java b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerEndpoint.java new file mode 100644 index 0000000..af822e8 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerEndpoint.java @@ -0,0 +1,42 @@ +/* + * 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. + */ + +package org.apache.servicecomb.demo.multiServiceCenterServerB; + +import javax.ws.rs.core.MediaType; + +import org.apache.servicecomb.core.Invocation; +import org.apache.servicecomb.provider.rest.common.RestSchema; +import org.apache.servicecomb.swagger.invocation.context.ContextUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@RestSchema(schemaId = "ServerEndpoint") +@RequestMapping(path = "/register/url/prefix", produces = MediaType.APPLICATION_JSON) +public class ServerEndpoint { + private static final Logger LOGGER + = LoggerFactory.getLogger(ServerEndpoint.class); + + @GetMapping(path = "/getName") + public String getName(@RequestParam(name = "name") String name) { + ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked."); + return name; + } +} diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/resources/application.yml b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/resources/application.yml new file mode 100644 index 0000000..834ca56 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/resources/application.yml @@ -0,0 +1,32 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +server: + port: 8082 + +# java-chassis configurations + +APPLICATION_ID: demo-multi-service-center +service_description: + name: demo-multi-service-center-serverB + version: 0.0.2 +servicecomb: + service: + registry: + address: http://127.0.0.1:40100 + rest: + address: 0.0.0.0:8082 \ No newline at end of file diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/resources/logback.xml b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/resources/logback.xml new file mode 100644 index 0000000..0d627f2 --- /dev/null +++ b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/resources/logback.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<configuration scan="true"> + <appender name="STDOUT-TRACING" class="ch.qos.logback.core.ConsoleAppender"> + <!-- If applicable, can use ch.qos.logback.classic.filter.MarkerFilter --> + <filter class="org.apache.servicecomb.foundation.logback.MarkerFilter"> + <Marker>SERVICECOMB_MARKER</Marker> + <OnMismatch>DENY</OnMismatch> + <OnMatch>ACCEPT</OnMatch> + </filter> + + <encoder> + <pattern>%d [%level] [%thread][%X{SERVICECOMB_TRACE_ID}] - %msg (%F:%L\)%n</pattern> + </encoder> + </appender> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <!-- If applicable, can use ch.qos.logback.classic.filter.MarkerFilter --> + <filter class="org.apache.servicecomb.foundation.logback.MarkerFilter"> + <Marker>SERVICECOMB_MARKER</Marker> + <OnMismatch>ACCEPT</OnMismatch> + <OnMatch>DENY</OnMatch> + </filter> + + <encoder> + <pattern>%d [%level] [%thread] - %msg (%F:%L\)%n</pattern> + </encoder> + </appender> + + <root level="info"> + <appender-ref ref="STDOUT"/> + <appender-ref ref="STDOUT-TRACING"/> + </root> +</configuration> \ No newline at end of file diff --git a/demo/demo-multi-service-center/pom.xml b/demo/demo-multi-service-center/pom.xml new file mode 100644 index 0000000..9ca8ace --- /dev/null +++ b/demo/demo-multi-service-center/pom.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.servicecomb.demo</groupId> + <artifactId>demo-parent</artifactId> + <version>2.1.0-SNAPSHOT</version> + </parent> + <artifactId>demo-multi-service-center</artifactId> + <name>Java Chassis::Demo::Multi Registry</name> + <packaging>pom</packaging> + <modules> + <module>demo-multi-service-center-serverA</module> + <module>demo-multi-service-center-serverB</module> + <module>demo-multi-service-center-client</module> + </modules> + + <dependencies> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>java-chassis-spring-boot-starter-servlet</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>registry-service-center</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>foundation-test-scaffolding</artifactId> + <scope>compile</scope> + </dependency> + </dependencies> +</project> diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java index dd144ed..c526787 100644 --- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java +++ b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCase.java @@ -21,17 +21,23 @@ public interface CategorizedTestCase { /** * test case which only successful in REST transport */ - void testRestTransport() throws Exception; + default void testRestTransport() throws Exception { + + } /** * test case which only successful in HIGHWAY transport */ - void testHighwayTransport() throws Exception; + default void testHighwayTransport() throws Exception { + + } /** * test case which successful in both REST and HIGHWAY transport */ - void testAllTransport() throws Exception; + default void testAllTransport() throws Exception { + + } default String getMicroserviceName() { return null; diff --git a/demo/pom.xml b/demo/pom.xml index c0d40fc..d5bffc6 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -46,8 +46,8 @@ <module>demo-spring-boot-provider</module> <module>demo-spring-boot-transport</module> <module>demo-edge</module> - <module>demo-multiple</module> + <module>demo-multi-service-center</module> <module>demo-signature</module> <module>perf</module> </modules> diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java index f5d3957..0a45452 100644 --- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java +++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java @@ -18,7 +18,9 @@ package org.apache.servicecomb.foundation.common.utils; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashSet; +import java.util.Map; import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -131,6 +133,14 @@ public final class BeanUtils { return (T) context.getBean(name); } + public static <T> Map<String, T> getBeansOfType(Class<T> type) { + if (context == null) { + // for some test case + return Collections.emptyMap(); + } + return context.getBeansOfType(type); + } + /** * Get the implemented class of the given instance * @param bean the instance to get implemented class from @@ -140,5 +150,4 @@ public final class BeanUtils { public static Class<?> getImplClassFromBean(Object bean) { return AopProxyUtils.ultimateTargetClass(bean); } - } diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java index 5112e17..4a04459 100644 --- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java +++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java @@ -31,6 +31,7 @@ import org.apache.servicecomb.config.ConfigUtil; import org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader; import org.apache.servicecomb.foundation.common.Holder; import org.apache.servicecomb.foundation.common.event.EventManager; +import org.apache.servicecomb.foundation.common.utils.BeanUtils; import org.apache.servicecomb.registry.DiscoveryManager; import org.apache.servicecomb.registry.api.event.MicroserviceInstanceRegisteredEvent; import org.apache.servicecomb.registry.api.registry.FindInstancesResponse; @@ -62,8 +63,6 @@ public final class RegistryUtils { */ private static volatile ServiceRegistry serviceRegistry; - private static final Map<String, ServiceRegistryConfig> EXTRA_SERVICE_REGISTRY_CONFIGS = new LinkedHashMap<>(); - private static final Map<String, ServiceRegistry> EXTRA_SERVICE_REGISTRIES = new LinkedHashMap<>(); private static AggregateServiceRegistryCache aggregateServiceRegistryCache; @@ -103,7 +102,8 @@ public final class RegistryUtils { } private static void initializeServiceRegistries(MicroserviceDefinition microserviceDefinition) { - EXTRA_SERVICE_REGISTRY_CONFIGS.forEach((k, v) -> { + Map<String, ServiceRegistryConfig> configs = BeanUtils.getBeansOfType(ServiceRegistryConfig.class); + configs.forEach((k, v) -> { ServiceRegistry serviceRegistry = ServiceRegistryFactory.create(v, microserviceDefinition); addExtraServiceRegistry(serviceRegistry); }); @@ -254,15 +254,6 @@ public final class RegistryUtils { } /** - * Add the configuration object of {@link ServiceRegistry}. - * The corresponding {@link ServiceRegistry} instances are instantiated later in {@link #init()} - */ - public static void addExtraServiceRegistryConfig(ServiceRegistryConfig serviceRegistryConfig) { - validateRegistryConfig(serviceRegistryConfig); - EXTRA_SERVICE_REGISTRY_CONFIGS.put(serviceRegistryConfig.getRegistryName(), serviceRegistryConfig); - } - - /** * @throws NullPointerException serviceRegistryConfig is null * @throws IllegalArgumentException config value is illegal */ diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java index 407d712..bfc1009 100644 --- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java +++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java @@ -29,7 +29,7 @@ import org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientI import io.vertx.core.http.HttpVersion; -public final class ServiceRegistryConfig { +public class ServiceRegistryConfig { public static final ServiceRegistryConfig INSTANCE = buildFromConfiguration(); public static final int DEFAULT_TIMEOUT_IN_MS = 30000;
