This is an automated email from the ASF dual-hosted git repository. victory pushed a commit to branch cloud-native in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 03173f82e5f4630d28747b5b6764e0de50c8d1c2 Merge: d7ed829 e7ce16d Author: cvictory <shenglic...@gmail.com> AuthorDate: Thu Aug 8 11:36:42 2019 +0800 fix conflict and add medadata-definition-protobuf .travis.yml | 2 +- dubbo-bom/pom.xml | 1 + dubbo-bootstrap/pom.xml | 40 +- .../org/apache/dubbo/bootstrap/DubboBootstrap.java | 50 +- .../bootstrap/DubboServiceConsumerBootstrap.java | 1 - .../bootstrap/DubboServiceProviderBootstrap.java | 1 + dubbo-cluster/pom.xml | 1 + .../router/condition/config/ListenableRouter.java | 2 +- .../dubbo/rpc/cluster/router/tag/TagRouter.java | 2 +- .../support/wrapper/MockClusterInvoker.java | 2 +- .../dubbo/rpc/cluster/router/TagRouterTest.java | 5 +- .../support/AbstractClusterInvokerTest.java | 2 +- dubbo-common/pom.xml | 1 + .../apache/dubbo/common/config/Configuration.java | 2 - .../configcenter/AbstractDynamicConfiguration.java | 182 ++ .../config/configcenter/DynamicConfiguration.java | 86 +- .../file/FileSystemDynamicConfiguration.java | 23 +- .../configcenter/nop/NopDynamicConfiguration.java | 6 +- .../wrapper/CompositeDynamicConfiguration.java | 5 + .../dubbo/common/constants/CommonConstants.java | 2 +- .../extension/AdaptiveClassCodeGenerator.java | 10 +- .../apache/dubbo/common/bytecode/MixinTest.java | 1 - .../common/config/InmemoryConfigurationTest.java | 6 +- .../threadlocal/InternalThreadLocalTest.java | 1 - .../apache/dubbo/common/utils/PojoUtilsTest.java | 5 +- dubbo-compatible/pom.xml | 1 + .../dubbo/rpc/protocol/dubbo/FutureAdapter.java | 6 +- .../org/apache/dubbo/config/MethodConfigTest.java | 1 - .../org/apache/dubbo/filter/LegacyInvoker.java | 2 +- .../java/org/apache/dubbo/rpc/RpcContextTest.java | 6 +- dubbo-config/dubbo-config-api/pom.xml | 1 + .../org/apache/dubbo/config/ApplicationConfig.java | 1 - .../org/apache/dubbo/config/ReferenceConfig.java | 14 +- .../org/apache/dubbo/config/RegistryConfig.java | 10 +- .../org/apache/dubbo/config/ServiceConfig.java | 5 +- .../apache/dubbo/config/ReferenceConfigTest.java | 8 +- .../ConfigurableMetadataServiceExporterTest.java | 5 +- dubbo-config/dubbo-config-spring/pom.xml | 1 + .../factory/annotation/ReferenceBeanBuilder.java | 9 + .../ServiceAnnotationBeanPostProcessor.java | 14 + .../dubbo/config/spring/util/AnnotationUtils.java | 20 +- .../ReferenceAnnotationBeanPostProcessorTest.java | 89 +- .../ServiceAnnotationBeanPostProcessorTest.java | 13 + .../context/annotation/EnableDubboConfigTest.java | 11 + .../annotation/provider/DemoServiceImpl.java | 4 +- .../DubboComponentScanRegistrarTest.java | 118 - .../DubboConfigBindingRegistrarTest.java | 88 - .../DubboConfigBindingsRegistrarTest.java | 63 - .../annotation/DubboConfigConfigurationTest.java | 99 - .../context/annotation/EnableDubboConfigTest.java | 120 - .../context/annotation/EnableDubboTest.java | 162 - .../annotation/consumer/ConsumerConfiguration.java | 126 - .../consumer/test/TestConsumerConfiguration.java | 96 - .../annotation/provider/DemoServiceImpl.java | 55 - .../annotation/provider/ProviderConfiguration.java | 109 - .../properties/DefaultDubboConfigBinderTest.java | 94 - dubbo-config/pom.xml | 1 + .../support/nop/NopDynamicConfigurationTest.java | 70 - .../dubbo-configcenter-apollo/pom.xml | 1 + .../support/apollo/ApolloDynamicConfiguration.java | 10 +- .../dubbo-configcenter-consul/pom.xml | 3 +- .../consul/ConsulDynamicConfiguration.java | 6 +- dubbo-configcenter/dubbo-configcenter-etcd/pom.xml | 3 +- .../support/etcd/EtcdDynamicConfiguration.java | 20 +- .../dubbo-configcenter-nacos/pom.xml | 3 +- .../support/nacos/NacosDynamicConfiguration.java | 8 +- .../nacos/NacosDynamicConfigurationTest.java | 6 +- .../dubbo-configcenter-zookeeper/pom.xml | 1 + .../zookeeper/ZookeeperDynamicConfiguration.java | 84 +- .../ZookeeperDynamicConfigurationTest.java | 2 +- dubbo-configcenter/pom.xml | 1 + dubbo-container/dubbo-container-api/pom.xml | 1 + dubbo-container/dubbo-container-log4j/pom.xml | 1 + dubbo-container/dubbo-container-logback/pom.xml | 1 + dubbo-container/dubbo-container-spring/pom.xml | 1 + dubbo-container/pom.xml | 1 + .../dubbo-demo-annotation-consumer/pom.xml | 3 +- .../resources/spring/dubbo-consumer.properties | 2 +- .../dubbo-demo-annotation-provider/pom.xml | 3 +- .../apache/dubbo/demo/provider/Application.java | 6 +- .../dubbo-demo-api/dubbo-demo-api-consumer/pom.xml | 3 +- .../apache/dubbo/demo/consumer/Application.java | 6 +- .../dubbo-demo-api/dubbo-demo-api-provider/pom.xml | 3 +- .../apache/dubbo/demo/provider/Application.java | 6 +- dubbo-demo/dubbo-demo-api/pom.xml | 3 +- dubbo-demo/dubbo-demo-interface/pom.xml | 1 + .../dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml | 1 + .../apache/dubbo/demo/consumer/Application.java | 4 - .../src/main/resources/spring/dubbo-consumer.xml | 4 +- .../dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml | 4 +- .../apache/dubbo/demo/provider/Application.java | 4 - .../src/main/resources/spring/dubbo-provider.xml | 6 +- dubbo-demo/dubbo-demo-xml/pom.xml | 3 +- dubbo-demo/pom.xml | 1 + dubbo-dependencies/pom.xml | 3 +- dubbo-distribution/pom.xml | 1 + dubbo-filter/dubbo-filter-cache/pom.xml | 1 + dubbo-filter/dubbo-filter-validation/pom.xml | 1 + dubbo-filter/pom.xml | 1 + dubbo-metadata/dubbo-metadata-api/pom.xml | 1 + .../DynamicConfigurationServiceNameMapping.java | 13 +- .../org/apache/dubbo/metadata/MetadataService.java | 99 +- .../dubbo/metadata/WritableMetadataService.java | 2 +- .../definition/model/MethodDefinition.java | 18 +- .../store/InMemoryWritableMetadataService.java | 101 +- .../store/RemoteWritableMetadataService.java | 20 +- ...g.apache.dubbo.metadata.WritableMetadataService | 2 +- ...DynamicConfigurationServiceNameMappingTest.java | 38 +- .../InMemoryWritableMetadataServiceTest.java | 32 +- .../report/identifier/MetadataIdentifierTest.java | 2 +- .../report/support/AbstractMetadataReportTest.java | 14 +- .../store/RemoteWritableMeatadataServiceTest.java | 4 +- ...che.dubbo.metadata.report.MetadataReportFactory | 1 + .../pom.xml | 18 +- .../definition/protobuf/ProtobufTypeBuilder.java | 308 ++ ...e.dubbo.metadata.definition.builder.TypeBuilder | 1 + .../protobuf/ProtobufTypeBuilderTest.java | 71 + .../definition/protobuf/model/GooglePB.java | 3431 ++++++++++++++++++++ .../protobuf/model/ServiceInterface.java | 19 +- .../dubbo-metadata-report-consul/pom.xml | 3 +- dubbo-metadata/dubbo-metadata-report-etcd/pom.xml | 3 +- dubbo-metadata/dubbo-metadata-report-nacos/pom.xml | 3 +- dubbo-metadata/dubbo-metadata-report-redis/pom.xml | 3 +- .../dubbo-metadata-report-zookeeper/pom.xml | 4 +- dubbo-metadata/pom.xml | 2 +- dubbo-monitor/dubbo-monitor-api/pom.xml | 1 + dubbo-monitor/dubbo-monitor-default/pom.xml | 1 + .../dubbo/monitor/dubbo/MetricsFilterTest.java | 2 - dubbo-monitor/pom.xml | 1 + dubbo-plugin/dubbo-qos/pom.xml | 1 + .../dubbo/qos/command/util/CommandHelperTest.java | 3 +- dubbo-plugin/pom.xml | 3 +- dubbo-registry/dubbo-registry-api/pom.xml | 1 + .../dubbo/registry/client/ServiceInstance.java | 43 - .../CompositeMetadataServiceURLBuilder.java | 81 + ...ExportedServicesRevisionMetadataCustomizer.java | 4 +- .../client/metadata/MetadataServiceProxy.java | 9 +- .../client/metadata/MetadataServiceURLBuilder.java | 60 +- ...MetadataServiceURLParamsMetadataCustomizer.java | 4 +- .../metadata/ServiceInstanceMetadataUtils.java | 14 +- .../SpringCloudMetadataServiceURLBuilder.java | 49 + ...java => StandardMetadataServiceURLBuilder.java} | 13 +- .../proxy/DefaultMetadataServiceProxyFactory.java | 11 +- .../proxy/MetadataServiceProxyFactory.java | 2 +- .../registry/support/ServiceOrientedRegistry.java | 32 +- ...try.client.metadata.MetadataServiceProxyFactory | 1 - ...ient.metadata.proxy.MetadataServiceProxyFactory | 2 +- ...istry.client.metadata.MetadataServiceURLBuilder | 2 + .../client/DefaultServiceInstanceTest.java | 36 +- .../CustomizableServiceInstanceListenerTest.java | 29 +- .../event/listener/LoggingEventListenerTest.java | 85 + .../ServiceInstancesChangedListenerTest.java | 54 + .../metadata/MetadataServiceURLBuilderTest.java | 53 + .../metadata/ServiceInstanceMetadataUtilsTest.java | 17 +- .../SpringCloudMetadataServiceURLBuilderTest.java | 51 + .../support/ServiceOrientedRegistryTest.java | 32 +- dubbo-registry/dubbo-registry-consul/pom.xml | 1 + .../registry/consul/ConsulServiceDiscovery.java | 22 +- dubbo-registry/dubbo-registry-default/pom.xml | 1 + .../dubbo/registry/dubbo/RegistryProtocolTest.java | 2 +- dubbo-registry/dubbo-registry-etcd3/pom.xml | 1 + .../dubbo/registry/etcd/EtcdServiceDiscovery.java | 1 + .../dubbo/registry/etcd/EtcdRegistryTest.java | 2 +- dubbo-registry/dubbo-registry-multicast/pom.xml | 1 + .../registry/multicast/MulticastRegistry.java | 6 +- dubbo-registry/dubbo-registry-multiple/pom.xml | 1 + .../dubbo/registry/nacos/NacosRegistryFactory.java | 3 - .../nacos/util/NacosNamingServiceUtils.java | 3 +- dubbo-registry/dubbo-registry-redis/pom.xml | 1 + dubbo-registry/dubbo-registry-zookeeper/pom.xml | 1 + .../registry/zookeeper/ZookeeperRegistry.java | 2 - .../zookeeper/ZookeeperServiceDiscovery.java | 37 + .../registry/zookeeper/ZookeeperRegistryTest.java | 3 +- .../zookeeper/ZookeeperServiceDiscoveryTest.java | 2 + dubbo-registry/pom.xml | 1 + dubbo-remoting/dubbo-remoting-api/pom.xml | 1 + .../dubbo/remoting/PerformanceClientFixedTest.java | 2 +- .../remoting/transport/AbstractCodecTest.java | 5 +- dubbo-remoting/dubbo-remoting-etcd3/pom.xml | 1 + dubbo-remoting/dubbo-remoting-grizzly/pom.xml | 1 + dubbo-remoting/dubbo-remoting-http/pom.xml | 1 + dubbo-remoting/dubbo-remoting-mina/pom.xml | 1 + dubbo-remoting/dubbo-remoting-netty/pom.xml | 1 + dubbo-remoting/dubbo-remoting-netty4/pom.xml | 1 + dubbo-remoting/dubbo-remoting-p2p/pom.xml | 1 + dubbo-remoting/dubbo-remoting-zookeeper/pom.xml | 1 + .../zookeeper/curator/CuratorZookeeperClient.java | 5 + dubbo-remoting/pom.xml | 1 + dubbo-rpc/dubbo-rpc-api/pom.xml | 1 + .../dubbo/rpc/filter/AccessLogFilterTest.java | 7 +- .../apache/dubbo/rpc/support/BlockMyInvoker.java | 2 +- .../apache/dubbo/rpc/support/MockInvokerTest.java | 11 +- .../org/apache/dubbo/rpc/support/MyInvoker.java | 2 +- .../org/apache/dubbo/rpc/support/RpcUtilsTest.java | 4 +- dubbo-rpc/dubbo-rpc-dubbo/pom.xml | 1 + .../dubbo/rpc/protocol/dubbo/DubboProtocol.java | 2 +- .../dubbo/ReferenceCountExchangeClient.java | 3 + dubbo-rpc/dubbo-rpc-hessian/pom.xml | 1 + .../rpc/protocol/hessian/HessianProtocol.java | 4 +- dubbo-rpc/dubbo-rpc-http/pom.xml | 1 + dubbo-rpc/dubbo-rpc-injvm/pom.xml | 1 + dubbo-rpc/dubbo-rpc-jsonrpc/pom.xml | 1 + dubbo-rpc/dubbo-rpc-memcached/pom.xml | 1 + dubbo-rpc/dubbo-rpc-native-thrift/pom.xml | 1 + dubbo-rpc/dubbo-rpc-redis/pom.xml | 1 + dubbo-rpc/dubbo-rpc-rest/pom.xml | 1 + .../DubboSwaggerApiListingResourceTest.java | 4 +- dubbo-rpc/dubbo-rpc-rmi/pom.xml | 1 + .../dubbo/rpc/protocol/rmi/RmiProtocolTest.java | 4 +- dubbo-rpc/dubbo-rpc-thrift/pom.xml | 1 + dubbo-rpc/dubbo-rpc-webservice/pom.xml | 1 + dubbo-rpc/dubbo-rpc-xml/pom.xml | 1 + .../xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java | 2 +- dubbo-rpc/pom.xml | 1 + .../dubbo-serialization-api/pom.xml | 1 + .../dubbo-serialization-avro/pom.xml | 1 + .../common/serialize/avro/AvroObjectInput.java | 3 +- .../common/serialize/avro/AvroObjectOutput.java | 3 +- .../dubbo-serialization-fastjson/pom.xml | 1 + .../dubbo-serialization-fst/pom.xml | 1 + .../dubbo-serialization-gson/pom.xml | 1 + .../dubbo-serialization-hessian2/pom.xml | 1 + .../dubbo-serialization-jdk/pom.xml | 1 + .../dubbo-serialization-kryo/pom.xml | 1 + .../dubbo-serialization-native-hession/pom.xml | 3 +- .../dubbo-serialization-protobuf-json/pom.xml | 3 +- .../dubbo-serialization-protostuff/pom.xml | 3 +- .../serialize/protostuff/utils/WrapperUtils.java | 2 +- .../dubbo-serialization-test/pom.xml | 3 +- .../serialize/hessian2/Hessian2PersonOkTest.java | 1 + .../support/GenericProtobufObjectOutputTest.java | 1 + .../protostuff/ProtostuffObjectOutputTest.java | 10 +- .../support/SerializableClassRegistryTest.java | 3 +- dubbo-serialization/pom.xml | 1 + 234 files changed, 5290 insertions(+), 1921 deletions(-) diff --cc dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java index de24c85,1ed573f..45c9c0e --- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java +++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java @@@ -29,8 -29,7 +29,9 @@@ public class DubboServiceProviderBootst // Zookeeper in service registry type .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service")) // Nacos - .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service")) +// .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service")) +// .registry(RegistryBuilder.newBuilder().address("etcd3://127.0.0.1:2379?registry-type=service").build()) ++// .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service")) .protocol(builder -> builder.port(-1).name("dubbo")) .service(builder -> builder.id("test").interfaceClass(EchoService.class).ref(new EchoServiceImpl())) .start() diff --cc dubbo-metadata/dubbo-metadata-definition-protobuf/pom.xml index e93a39a,099fc56..9e8c409 --- a/dubbo-metadata/dubbo-metadata-definition-protobuf/pom.xml +++ b/dubbo-metadata/dubbo-metadata-definition-protobuf/pom.xml @@@ -16,29 -16,28 +16,27 @@@ --> <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"> <parent> - <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-metadata</artifactId> + <groupId>org.apache.dubbo</groupId> <version>${revision}</version> - <relativePath>../pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> + <artifactId>dubbo-metadata-definition-protobuf</artifactId> - <artifactId>dubbo-metadata-report-zookeeper</artifactId> <dependencies> <dependency> - <groupId>org.apache.dubbo</groupId> - <artifactId>dubbo-metadata-api</artifactId> - <version>${project.parent.version}</version> + <groupId>com.google.protobuf</groupId> + <artifactId>protobuf-java</artifactId> </dependency> <dependency> - <groupId>org.apache.dubbo</groupId> - <artifactId>dubbo-remoting-zookeeper</artifactId> - <version>${project.parent.version}</version> + <groupId>com.google.protobuf</groupId> + <artifactId>protobuf-java-util</artifactId> </dependency> <dependency> - <groupId>org.apache.curator</groupId> - <artifactId>curator-test</artifactId> - <scope>test</scope> + <groupId>org.apache.dubbo</groupId> - <artifactId>dubbo-metadata-definition</artifactId> ++ <artifactId>dubbo-metadata-api</artifactId> + <version>${project.parent.version}</version> </dependency> </dependencies> </project> diff --cc dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilder.java index 0000000,0000000..498f882 new file mode 100644 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilder.java @@@ -1,0 -1,0 +1,308 @@@ ++/* ++ * 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.dubbo.metadata.definition.protobuf; ++ ++import org.apache.dubbo.common.logger.Logger; ++import org.apache.dubbo.common.logger.LoggerFactory; ++import org.apache.dubbo.metadata.definition.TypeDefinitionBuilder; ++import org.apache.dubbo.metadata.definition.builder.TypeBuilder; ++import org.apache.dubbo.metadata.definition.model.TypeDefinition; ++ ++import com.google.protobuf.ByteString; ++import com.google.protobuf.Descriptors; ++import com.google.protobuf.GeneratedMessageV3; ++import com.google.protobuf.ProtocolStringList; ++import com.google.protobuf.UnknownFieldSet; ++ ++import java.lang.reflect.Method; ++import java.lang.reflect.Type; ++import java.util.HashMap; ++import java.util.List; ++import java.util.Map; ++import java.util.regex.Matcher; ++import java.util.regex.Pattern; ++ ++public class ProtobufTypeBuilder implements TypeBuilder { ++ private final Logger logger = LoggerFactory.getLogger(getClass()); ++ private static final Pattern MAP_PATTERN = Pattern.compile("^java\\.util\\.Map<(\\S+), (\\S+)>$"); ++ private static final Pattern LIST_PATTERN = Pattern.compile("^java\\.util\\.List<(\\S+)>$"); ++ private static final List<String> list = null; ++ /** ++ * provide a List<String> type for TypeDefinitionBuilder.build(type,class,cache) ++ * "repeated string" transform to ProtocolStringList, should be build as List<String> type. ++ */ ++ private static Type STRING_LIST_TYPE; ++ ++ static { ++ try { ++ STRING_LIST_TYPE = ProtobufTypeBuilder.class.getDeclaredField("list").getGenericType(); ++ } catch (NoSuchFieldException e) { ++ // do nothing ++ } ++ } ++ ++ @Override ++ public boolean accept(Type type, Class<?> clazz) { ++ if (clazz == null) { ++ return false; ++ } ++ ++ return GeneratedMessageV3.class.isAssignableFrom(clazz); ++ } ++ ++ @Override ++ public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) { ++ TypeDefinition typeDefinition = new TypeDefinition(clazz.getName()); ++ try { ++ GeneratedMessageV3.Builder builder = getMessageBuilder(clazz); ++ typeDefinition = buildProtobufTypeDefinition(clazz, builder, typeCache); ++ } catch (Exception e) { ++ logger.info("TypeDefinition build failed.", e); ++ } ++ ++ return typeDefinition; ++ } ++ ++ private GeneratedMessageV3.Builder getMessageBuilder(Class<?> requestType) throws Exception { ++ Method method = requestType.getMethod("newBuilder"); ++ return (GeneratedMessageV3.Builder) method.invoke(null, null); ++ } ++ ++ private TypeDefinition buildProtobufTypeDefinition(Class<?> clazz, GeneratedMessageV3.Builder builder, Map<Class<?>, TypeDefinition> typeCache) { ++ TypeDefinition typeDefinition = new TypeDefinition(clazz.getName()); ++ if (builder == null) { ++ return typeDefinition; ++ } ++ ++ Map<String, TypeDefinition> properties = new HashMap<>(); ++ Method[] methods = builder.getClass().getDeclaredMethods(); ++ for (Method method : methods) { ++ String methodName = method.getName(); ++ ++ if (isSimplePropertySettingMethod(method)) { ++ // property of custom type or primitive type ++ properties.put(generateSimpleFiledName(methodName), TypeDefinitionBuilder.build(method.getGenericParameterTypes()[0], method.getParameterTypes()[0], typeCache)); ++ } else if (isMapPropertySettingMethod(method)) { ++ // property of map ++ Type type = method.getGenericParameterTypes()[0]; ++ String fieldName = generateMapFieldName(methodName); ++ validateMapType(fieldName, type.toString()); ++ properties.put(fieldName, TypeDefinitionBuilder.build(type, method.getParameterTypes()[0], typeCache)); ++ } else if (isListPropertySettingMethod(method)) { ++ // property of list ++ Type type = method.getGenericReturnType(); ++ String fieldName = generateListFieldName(methodName); ++ validateListType(fieldName, type.toString()); ++ TypeDefinition td; ++ if (ProtocolStringList.class.isAssignableFrom(method.getReturnType())) { ++ // property defined as "repeated string" transform to ProtocolStringList, ++ // should be build as List<String>. ++ td = TypeDefinitionBuilder.build(STRING_LIST_TYPE, List.class, typeCache); ++ } else { ++ td = TypeDefinitionBuilder.build(type, method.getReturnType(), typeCache); ++ } ++ properties.put(fieldName, td); ++ } ++ } ++ typeDefinition.setProperties(properties); ++ typeCache.put(clazz, typeDefinition); ++ return typeDefinition; ++ } ++ ++ /** ++ * 1. Unsupported List with value type is Bytes <br/> ++ * Bytes is a primitive type in Proto, transform to ByteString.class in java<br/> ++ * ++ * @param fieldName ++ * @param typeName ++ * @return ++ */ ++ private void validateListType(String fieldName, String typeName) { ++ Matcher matcher = LIST_PATTERN.matcher(typeName); ++ if (!matcher.matches()) { ++ throw new IllegalArgumentException("List protobuf property " + fieldName + "of Type " + ++ typeName + " can't be parsed.The type name should mathch[" + LIST_PATTERN.toString() + "]."); ++ } ++ ++ if (ByteString.class.getName().equals(matcher.group(1))) { ++ throw new IllegalArgumentException("List protobuf property " + fieldName + "of Type " + ++ typeName + " can't be parsed.List of ByteString is not supported."); ++ } ++ } ++ ++ /** ++ * 1. Unsupported Map with value type is Bytes <br/> ++ * 2. Unsupported Map with key type is not String <br/> ++ * Bytes is a primitive type in Proto, transform to ByteString.class in java<br/> ++ * ++ * @param fieldName ++ * @param typeName ++ * @return ++ */ ++ private void validateMapType(String fieldName, String typeName) { ++ Matcher matcher = MAP_PATTERN.matcher(typeName); ++ if (!matcher.matches()) { ++ throw new IllegalArgumentException("Map protobuf property " + fieldName + "of Type " + ++ typeName + " can't be parsed.The type name should mathch[" + MAP_PATTERN.toString() + "]."); ++ } ++ ++ if (!String.class.getName().equals(matcher.group(1)) || ByteString.class.getName().equals(matcher.group(2))) { ++ throw new IllegalArgumentException("Map protobuf property " + fieldName + "of Type " + ++ typeName + " can't be parsed.Map with unString key or ByteString value is not supported."); ++ } ++ } ++ ++ /** ++ * get unCollection unMap property name from setting method.<br/> ++ * ex:setXXX();<br/> ++ * ++ * @param methodName ++ * @return ++ */ ++ private String generateSimpleFiledName(String methodName) { ++ return toCamelCase(methodName.substring(3)); ++ } ++ ++ /** ++ * get map property name from setting method.<br/> ++ * ex: putAllXXX();<br/> ++ * ++ * @param methodName ++ * @return ++ */ ++ private String generateMapFieldName(String methodName) { ++ return toCamelCase(methodName.substring(6)); ++ } ++ ++ /** ++ * get list property name from setting method.<br/> ++ * ex: getXXXList()<br/> ++ * ++ * @param methodName ++ * @return ++ */ ++ private String generateListFieldName(String methodName) { ++ return toCamelCase(methodName.substring(3, methodName.length() - 4)); ++ } ++ ++ ++ private String toCamelCase(String nameString) { ++ char[] chars = nameString.toCharArray(); ++ chars[0] = Character.toLowerCase(chars[0]); ++ return new String(chars); ++ } ++ ++ /** ++ * judge custom type or primitive type property<br/> ++ * 1. proto3 grammar ex: string name = 1 <br/> ++ * 2. proto3 grammar ex: optional string name =1 <br/> ++ * generated setting method setNameValue(String name); ++ * ++ * @param method ++ * @return ++ */ ++ private boolean isSimplePropertySettingMethod(Method method) { ++ String methodName = method.getName(); ++ Class<?>[] types = method.getParameterTypes(); ++ ++ if (!methodName.startsWith("set") || types.length != 1) { ++ return false; ++ } ++ ++ // filter general setting method ++ // 1. - setUnknownFields( com.google.protobuf.UnknownFieldSet unknownFields) ++ // 2. - setField(com.google.protobuf.Descriptors.FieldDescriptor field,java.lang.Object value) ++ // 3. - setRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field,int index,java.lang.Object value) ++ if ("setField".equals(methodName) && types[0].equals(Descriptors.FieldDescriptor.class) ++ || "setUnknownFields".equals(methodName) && types[0].equals(UnknownFieldSet.class) ++ || "setRepeatedField".equals(methodName) && types[0].equals(Descriptors.FieldDescriptor.class)) { ++ return false; ++ } ++ ++ // String property has two setting method. ++ // skip setXXXBytes(com.google.protobuf.ByteString value) ++ // parse setXXX(String string) ++ if (methodName.endsWith("Bytes") && types[0].equals(ByteString.class)) { ++ return false; ++ } ++ ++ // Protobuf property has two setting method. ++ // skip setXXX(com.google.protobuf.Builder value) ++ // parse setXXX(com.google.protobuf.Message value) ++ if (GeneratedMessageV3.Builder.class.isAssignableFrom(types[0])) { ++ return false; ++ } ++ ++ // Enum property has two setting method. ++ // skip setXXX(int value) ++ // parse setXXX(SomeEnum value) ++ if (methodName.endsWith("Value") && types[0] == int.class) { ++ return false; ++ } ++ ++ return true; ++ } ++ ++ ++ /** ++ * judge List property</br> ++ * proto3 grammar ex: repeated string names; </br> ++ * generated setting method:List<String> getNamesList() ++ * ++ * @param method ++ * @return ++ */ ++ boolean isListPropertySettingMethod(Method method) { ++ String methodName = method.getName(); ++ Class<?> type = method.getReturnType(); ++ ++ ++ if (!methodName.startsWith("get") || !methodName.endsWith("List")) { ++ return false; ++ } ++ ++ // skip the setting method with Pb entity builder as parameter ++ if (methodName.endsWith("BuilderList")) { ++ return false; ++ } ++ ++ // if field name end with List, should skip ++ if (!List.class.isAssignableFrom(type)) { ++ return false; ++ } ++ ++ return true; ++ } ++ ++ /** ++ * judge map property</br> ++ * proto3 grammar : map<string,string> card = 1; </br> ++ * generated setting method: putAllCards(java.util.Map<String, string> values) </br> ++ * ++ * @param methodTemp ++ * @return ++ */ ++ private boolean isMapPropertySettingMethod(Method methodTemp) { ++ String methodName = methodTemp.getName(); ++ Class[] parameters = methodTemp.getParameterTypes(); ++ if (methodName.startsWith("putAll") && parameters.length == 1 && Map.class.isAssignableFrom(parameters[0])) { ++ return true; ++ } ++ ++ return false; ++ } ++} diff --cc dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder index 0000000,615ed7e..615ed7e mode 000000,100644..100644 --- a/dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder +++ b/dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder diff --cc dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilderTest.java index 0000000,0000000..3cdd79b new file mode 100644 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilderTest.java @@@ -1,0 -1,0 +1,71 @@@ ++/* ++ * 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.dubbo.metadata.definition.protobuf; ++ ++import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; ++import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; ++import org.apache.dubbo.metadata.definition.model.MethodDefinition; ++import org.apache.dubbo.metadata.definition.model.TypeDefinition; ++import org.apache.dubbo.metadata.definition.protobuf.model.ServiceInterface; ++ ++import org.junit.jupiter.api.Test; ++ ++import java.util.Map; ++ ++import static org.hamcrest.CoreMatchers.equalTo; ++import static org.hamcrest.CoreMatchers.is; ++import static org.hamcrest.MatcherAssert.assertThat; ++ ++/** ++ * 2019-07-01 ++ */ ++public class ProtobufTypeBuilderTest { ++ @Test ++ public void testProtobufBuilder() { ++ // TEST Pb Service metaData builder ++ FullServiceDefinition serviceDefinition = ServiceDefinitionBuilder.buildFullDefinition(ServiceInterface.class); ++ MethodDefinition methodDefinition = serviceDefinition.getMethods().get(0); ++ String parameterName = methodDefinition.getParameterTypes()[0]; ++ TypeDefinition typeDefinition = null; ++ for (TypeDefinition type : serviceDefinition.getTypes()) { ++ if (parameterName.equals(type.getType())) { ++ typeDefinition = type; ++ break; ++ } ++ } ++ Map<String, TypeDefinition> propertiesMap = typeDefinition.getProperties(); ++ assertThat(propertiesMap.size(), is(9)); ++ assertThat(propertiesMap.containsKey("money"), is(true)); ++ assertThat(propertiesMap.get("money").getType(), equalTo("double")); ++ assertThat(propertiesMap.containsKey("cash"), is(true)); ++ assertThat(propertiesMap.get("cash").getType(), equalTo("float")); ++ assertThat(propertiesMap.containsKey("age"), is(true)); ++ assertThat(propertiesMap.get("age").getType(), equalTo("int")); ++ assertThat(propertiesMap.containsKey("num"), is(true)); ++ assertThat(propertiesMap.get("num").getType(), equalTo("long")); ++ assertThat(propertiesMap.containsKey("sex"), is(true)); ++ assertThat(propertiesMap.get("sex").getType(), equalTo("boolean")); ++ assertThat(propertiesMap.containsKey("name"), is(true)); ++ assertThat(propertiesMap.get("name").getType(), equalTo("java.lang.String")); ++ assertThat(propertiesMap.containsKey("msg"), is(true)); ++ assertThat(propertiesMap.get("msg").getType(), equalTo("com.google.protobuf.ByteString")); ++ assertThat(propertiesMap.containsKey("phone"), is(true)); ++ assertThat(propertiesMap.get("phone").getType(), equalTo("java.util.List<org.apache.dubbo.metadata.definition.protobuf.model.GooglePB$PhoneNumber>")); ++ assertThat(propertiesMap.containsKey("doubleMap"), is(true)); ++ assertThat(propertiesMap.get("doubleMap").getType(), equalTo("java.util.Map<java.lang.String, org.apache.dubbo.metadata.definition.protobuf.model.GooglePB$PhoneNumber>")); ++ } ++} diff --cc dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/model/GooglePB.java index 0000000,d662339..d662339 mode 000000,100644..100644 --- a/dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/model/GooglePB.java +++ b/dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/model/GooglePB.java diff --cc dubbo-metadata/pom.xml index 36cc61a,2c8bb6b..fefa364 --- a/dubbo-metadata/pom.xml +++ b/dubbo-metadata/pom.xml @@@ -29,9 -29,8 +29,9 @@@ <packaging>pom</packaging> <modules> <module>dubbo-metadata-api</module> ++ <module>dubbo-metadata-definition-protobuf</module> <module>dubbo-metadata-report-zookeeper</module> <module>dubbo-metadata-report-redis</module> - <!-- <module>dubbo-metadata-definition-protobuf</module>--> <module>dubbo-metadata-report-consul</module> <module>dubbo-metadata-report-etcd</module> <module>dubbo-metadata-report-nacos</module> diff --cc dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java index 17925e7,0000000..3f8f6bd mode 100644,000000..100644 --- a/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java +++ b/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java @@@ -1,196 -1,0 +1,196 @@@ +/* + * 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.dubbo.registry.consul; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.NamedThreadFactory; +import org.apache.dubbo.event.EventDispatcher; +import org.apache.dubbo.event.EventListener; +import org.apache.dubbo.registry.NotifyListener; +import org.apache.dubbo.registry.client.ServiceDiscovery; +import org.apache.dubbo.registry.client.ServiceInstance; +import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent; +import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener; + +import com.ecwid.consul.v1.ConsulClient; +import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.agent.model.NewService; +import com.ecwid.consul.v1.health.model.HealthService; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import static java.util.concurrent.Executors.newCachedThreadPool; +import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; +import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.CHECK_PASS_INTERVAL; +import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.DEFAULT_CHECK_PASS_INTERVAL; +import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.DEFAULT_DEREGISTER_TIME; +import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.DEFAULT_PORT; +import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.DEFAULT_WATCH_TIMEOUT; +import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.DEREGISTER_AFTER; +import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.SERVICE_TAG; +import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.URL_META_KEY; +import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.WATCH_TIMEOUT; + +/** + * 2019-07-31 + */ +public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<ServiceInstancesChangedEvent> { + + private ConsulClient client; + private long checkPassInterval; + private ExecutorService notifierExecutor = newCachedThreadPool( + new NamedThreadFactory("dubbo-consul-notifier", true)); + private ScheduledExecutorService ttlConsulCheckExecutor; + + + public ConsulServiceDiscovery(URL url) { + String host = url.getHost(); + int port = url.getPort() != 0 ? url.getPort() : DEFAULT_PORT; + client = new ConsulClient(host, port); + checkPassInterval = url.getParameter(CHECK_PASS_INTERVAL, DEFAULT_CHECK_PASS_INTERVAL); + ttlConsulCheckExecutor = Executors.newSingleThreadScheduledExecutor(); +// ttlConsulCheckExecutor.scheduleAtFixedRate(this::checkPass, checkPassInterval / 8, +// checkPassInterval / 8, TimeUnit.MILLISECONDS); + } + + @Override + public void onEvent(ServiceInstancesChangedEvent event) { + + } + + @Override + public void start() { + + } + + @Override + public void stop() { + + } + + @Override + public void register(ServiceInstance serviceInstance) throws RuntimeException { + client.agentServiceRegister(buildService(serviceInstance)); + } + + @Override + public void update(ServiceInstance serviceInstance) throws RuntimeException { + + } + + @Override + public void unregister(ServiceInstance serviceInstance) throws RuntimeException { + client.agentServiceDeregister(buildId(serviceInstance)); + } + + @Override + public Set<String> getServices() { + return null; + } + + @Override + public void addServiceInstancesChangedListener(String serviceName, ServiceInstancesChangedListener listener) throws NullPointerException, IllegalArgumentException { + + } + + private NewService buildService(ServiceInstance serviceInstance) { + NewService service = new NewService(); + service.setAddress(serviceInstance.getHost()); + service.setPort(serviceInstance.getPort()); + service.setId(buildId(serviceInstance)); + service.setName(serviceInstance.getServiceName()); + service.setCheck(buildCheck(serviceInstance)); + service.setTags(buildTags(serviceInstance)); + service.setMeta(Collections.singletonMap(URL_META_KEY, serviceInstance.toString())); + return service; + } + + private String buildId(ServiceInstance serviceInstance) { + // let's simply use url's hashcode to generate unique service id for now + return Integer.toHexString(serviceInstance.hashCode()); + } + + private List<String> buildTags(ServiceInstance serviceInstance) { + Map<String, String> params = serviceInstance.getMetadata(); + List<String> tags = params.keySet().stream() + .map(k -> k + "=" + params.get(k)) + .collect(Collectors.toList()); + tags.add(SERVICE_TAG); + return tags; + } + + private NewService.Check buildCheck(ServiceInstance serviceInstance) { + NewService.Check check = new NewService.Check(); + check.setTtl((checkPassInterval / 1000) + "s"); + String deregister = serviceInstance.getMetadata().get(DEREGISTER_AFTER); + check.setDeregisterCriticalServiceAfter(deregister == null ? DEFAULT_DEREGISTER_TIME : deregister); + + return check; + } + + private int buildWatchTimeout(URL url) { + return url.getParameter(WATCH_TIMEOUT, DEFAULT_WATCH_TIMEOUT) / 1000; + } + + + private class ConsulNotifier implements Runnable { + private ServiceInstance serviceInstance; + private long consulIndex; + private boolean running; + + ConsulNotifier(ServiceInstance serviceInstance, long consulIndex) { + this.serviceInstance = serviceInstance; + this.consulIndex = consulIndex; + this.running = true; + } + + @Override + public void run() { + while (this.running) { + processService(); + } + } + + private void processService() { - String service = url.getServiceKey(); - Response<List<HealthService>> response = getHealthServices(service, consulIndex, buildWatchTimeout(url)); - Long currentIndex = response.getConsulIndex(); - if (currentIndex != null && currentIndex > consulIndex) { - consulIndex = currentIndex; - List<HealthService> services = response.getValue(); - List<URL> urls = convert(services, url); - for (NotifyListener listener : getSubscribed().get(url)) { - doNotify(url, listener, urls); - } - } ++// String service = url.getServiceKey(); ++// Response<List<HealthService>> response = getHealthServices(service, consulIndex, buildWatchTimeout(url)); ++// Long currentIndex = response.getConsulIndex(); ++// if (currentIndex != null && currentIndex > consulIndex) { ++// consulIndex = currentIndex; ++// List<HealthService> services = response.getValue(); ++// List<URL> urls = convert(services, url); ++// for (NotifyListener listener : getSubscribed().get(url)) { ++// doNotify(url, listener, urls); ++// } ++// } + } + + void stop() { + this.running = false; + } + } +} diff --cc dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java index a684c2c,f10a0b0..70fede0 --- a/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java +++ b/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java @@@ -38,6 -38,7 +38,7 @@@ import com.google.gson.Gson import java.io.File; import java.util.Collections; -import java.util.List; ++ import java.util.Map; import java.util.Optional; import java.util.Set;