From ca1ae1f4b6950733d810fa33eaa2764cefd946ab Mon Sep 17 00:00:00 2001 From: namelessssssssssss <100946116+namelessssssssssss@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:01:35 +0800 Subject: [PATCH] New metadata service (#14210) --- .../dubbo/config/ApplicationConfig.java | 30 + .../apache/dubbo/rpc/model/ModuleModel.java | 19 +- .../dubbo/rpc/model/ServiceRepository.java | 6 +- .../InternalServiceConfigBuilder.java | 13 +- .../ConfigurableMetadataServiceExporter.java | 118 +- .../metadata/ExporterDeployListener.java | 9 +- ...ataServiceURLParamsMetadataCustomizer.java | 36 +- dubbo-metadata/dubbo-metadata-api/pom.xml | 7 +- .../DubboMetadataServiceV2Triple.java | 200 +++ .../apache/dubbo/metadata/MetadataInfoV2.java | 895 +++++++++++ .../metadata/MetadataInfoV2OrBuilder.java | 75 + .../dubbo/metadata/MetadataServiceV2.java | 29 + .../metadata/MetadataServiceV2Detector.java | 53 + .../metadata/MetadataServiceV2OuterClass.java | 122 ++ .../org/apache/dubbo/metadata/Revision.java | 497 ++++++ .../dubbo/metadata/RevisionOrBuilder.java | 34 + .../apache/dubbo/metadata/ServiceInfoV2.java | 1347 +++++++++++++++++ .../metadata/ServiceInfoV2OrBuilder.java | 114 ++ .../util/MetadataServiceVersionUtils.java | 154 ++ .../src/main/proto/metadata_service_v2.proto | 47 + ...che.dubbo.rpc.model.BuiltinServiceDetector | 1 + .../ReflectionBasedServiceDiscovery.java | 11 +- .../metadata/MetadataServiceDelegation.java | 42 +- .../metadata/MetadataServiceDelegationV2.java | 78 + .../client/metadata/MetadataUtils.java | 162 +- .../ServiceInstanceMetadataUtils.java | 2 + 26 files changed, 3984 insertions(+), 117 deletions(-) create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DubboMetadataServiceV2Triple.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2OrBuilder.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2Detector.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2OuterClass.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/Revision.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/RevisionOrBuilder.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2OrBuilder.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/util/MetadataServiceVersionUtils.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/proto/metadata_service_v2.proto create mode 100644 dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegationV2.java diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ApplicationConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ApplicationConfig.java index cdb8c09954..098dcbb21b 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ApplicationConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ApplicationConfig.java @@ -295,6 +295,27 @@ public class ApplicationConfig extends AbstractConfig { */ private String executorManagementMode; + /** + * Only use the new version of metadataService (MetadataServiceV2). + *
MetadataServiceV2 have better compatibility with other language's dubbo implement (dubbo-go). + *
If set to false (default): + *
1. If your services are using triple protocol and {@link #metadataServiceProtocol} is not set + *
- Dubbo will export both MetadataService and MetadataServiceV2 with triple + *
2. Set {@link #metadataServiceProtocol} = tri + *
- Dubbo will export both MetadataService and MetadataServiceV2 with triple + *
3. Set {@link #metadataServiceProtocol} != tri + *
- Dubbo will only export MetadataService + *
4. Your services are not using triple protocol, and {@link #metadataServiceProtocol} is not set + *
- Dubbo will only export MetadataService + *
+ *
If set to true, dubbo will try to only use MetadataServiceV2. + *
It only activates when meet at least one of the following cases: + *
1. Manually set {@link #metadataServiceProtocol} = tri + *
2. Your services are using triple protocol + *
+ */ + private Boolean onlyUseMetadataV2; + public ApplicationConfig() {} public ApplicationConfig(ApplicationModel applicationModel) { @@ -794,6 +815,15 @@ public class ApplicationConfig extends AbstractConfig { return executorManagementMode; } + @Parameter(excluded = true) + public Boolean getOnlyUseMetadataV2() { + return onlyUseMetadataV2; + } + + public void setOnlyUseMetadataV2(Boolean onlyUseMetadataV2) { + this.onlyUseMetadataV2 = onlyUseMetadataV2; + } + @Override public void refresh() { super.refresh(); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java index 9af38b0428..130fe863dd 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java @@ -188,7 +188,8 @@ public class ModuleModel extends ScopeModel { this.moduleEnvironment = moduleEnvironment; } - public ConsumerModel registerInternalConsumer(Class internalService, URL url) { + public ConsumerModel registerInternalConsumer( + Class internalService, URL url, ServiceDescriptor serviceDescriptor, Object proxyObject) { ServiceMetadata serviceMetadata = new ServiceMetadata(); serviceMetadata.setVersion(url.getVersion()); serviceMetadata.setGroup(url.getGroup()); @@ -197,11 +198,12 @@ public class ModuleModel extends ScopeModel { serviceMetadata.setServiceType(internalService); String serviceKey = URL.buildKey(internalService.getName(), url.getGroup(), url.getVersion()); serviceMetadata.setServiceKey(serviceKey); - ConsumerModel consumerModel = new ConsumerModel( serviceMetadata.getServiceKey(), - "jdk", - serviceRepository.lookupService(serviceMetadata.getServiceInterfaceName()), + proxyObject, + serviceDescriptor == null + ? serviceRepository.lookupService(serviceMetadata.getServiceInterfaceName()) + : serviceDescriptor, this, serviceMetadata, new HashMap<>(0), @@ -212,6 +214,15 @@ public class ModuleModel extends ScopeModel { return consumerModel; } + public ConsumerModel registerInternalConsumer( + Class internalService, URL url, ServiceDescriptor serviceDescriptor) { + return registerInternalConsumer(internalService, url, serviceDescriptor, null); + } + + public ConsumerModel registerInternalConsumer(Class internalService, URL url) { + return registerInternalConsumer(internalService, url, null, null); + } + public boolean isLifeCycleManagedExternally() { return lifeCycleManagedExternally; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceRepository.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceRepository.java index b524b62281..8f6c0dddbf 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceRepository.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceRepository.java @@ -43,7 +43,11 @@ public class ServiceRepository { .getSupportedExtensionInstances(); if (CollectionUtils.isNotEmpty(builtinServices)) { for (BuiltinServiceDetector service : builtinServices) { - applicationModel.getInternalModule().getServiceRepository().registerService(service.getService()); + Class serviceClass = service.getService(); + if (serviceClass == null) { + continue; + } + applicationModel.getInternalModule().getServiceRepository().registerService(serviceClass); } } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java index e53490979d..f9915833a5 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java @@ -61,6 +61,7 @@ public class InternalServiceConfigBuilder { private Class interfaceClass; private Executor executor; private T ref; + private String version; private InternalServiceConfigBuilder(ApplicationModel applicationModel) { this.applicationModel = applicationModel; @@ -103,6 +104,11 @@ public class InternalServiceConfigBuilder { return getThis(); } + public InternalServiceConfigBuilder version(String version) { + this.version = version; + return getThis(); + } + /** * Get other configured protocol from environment in priority order. If get nothing, use default dubbo. * @@ -296,7 +302,12 @@ public class InternalServiceConfigBuilder { serviceConfig.setInterface(interfaceClass); serviceConfig.setRef(this.ref); serviceConfig.setGroup(applicationConfig.getName()); - serviceConfig.setVersion("1.0.0"); + + if (StringUtils.isNotEmpty(version)) { + serviceConfig.setVersion(version); + } else { + serviceConfig.setVersion("1.0.0"); + } serviceConfig.setFilter("-default"); serviceConfig.setExecutor(executor); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java index 6bfa5e3caf..0a29223ac9 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.config.metadata; -import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository; @@ -26,17 +25,22 @@ import org.apache.dubbo.config.MethodConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.bootstrap.builders.InternalServiceConfigBuilder; import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.metadata.MetadataServiceV2; +import org.apache.dubbo.metadata.util.MetadataServiceVersionUtils; import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation; +import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegationV2; import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutorService; -import static java.util.Collections.emptyList; import static org.apache.dubbo.common.constants.CommonConstants.METADATA_SERVICE_PORT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.METADATA_SERVICE_PROTOCOL_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TRIPLE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_METADATA_SERVICE_EXPORTED; +import static org.apache.dubbo.metadata.util.MetadataServiceVersionUtils.V1; +import static org.apache.dubbo.metadata.util.MetadataServiceVersionUtils.V2; /** * Export metadata service @@ -45,39 +49,34 @@ public class ConfigurableMetadataServiceExporter { private final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass()); - private MetadataServiceDelegation metadataService; + @Deprecated + private final MetadataServiceDelegation metadataService; + private final MetadataServiceDelegationV2 metadataServiceV2; + + @Deprecated private volatile ServiceConfig serviceConfig; + + private volatile ServiceConfig serviceConfigV2; + private final ApplicationModel applicationModel; public ConfigurableMetadataServiceExporter( - ApplicationModel applicationModel, MetadataServiceDelegation metadataService) { + ApplicationModel applicationModel, + MetadataServiceDelegation metadataService, + MetadataServiceDelegationV2 metadataServiceV2) { this.applicationModel = applicationModel; this.metadataService = metadataService; + this.metadataServiceV2 = metadataServiceV2; } public synchronized ConfigurableMetadataServiceExporter export() { if (serviceConfig == null || !isExported()) { - ExecutorService internalServiceExecutor = applicationModel - .getFrameworkModel() - .getBeanFactory() - .getBean(FrameworkExecutorRepository.class) - .getInternalServiceExecutor(); - this.serviceConfig = InternalServiceConfigBuilder.newBuilder(applicationModel) - .interfaceClass(MetadataService.class) - .protocol(getApplicationConfig().getMetadataServiceProtocol(), METADATA_SERVICE_PROTOCOL_KEY) - .port(getApplicationConfig().getMetadataServicePort(), METADATA_SERVICE_PORT_KEY) - .registryId("internal-metadata-registry") - .executor(internalServiceExecutor) - .ref(metadataService) - .build(configConsumer -> configConsumer.setMethods(generateMethodConfig())); - - // export - serviceConfig.export(); - - metadataService.setMetadataURL(serviceConfig.getExportedUrls().get(0)); - if (logger.isInfoEnabled()) { - logger.info("The MetadataService exports urls : " + serviceConfig.getExportedUrls()); + if (MetadataServiceVersionUtils.needExportV1(applicationModel)) { + exportV1(); + } + if (MetadataServiceVersionUtils.needExportV2(applicationModel)) { + exportV2(); } } else { if (logger.isWarnEnabled()) { @@ -92,18 +91,77 @@ public class ConfigurableMetadataServiceExporter { return this; } + private static final String INTERNAL_METADATA_REGISTRY_ID = "internal-metadata-registry"; + + private void exportV1() { + ExecutorService internalServiceExecutor = applicationModel + .getFrameworkModel() + .getBeanFactory() + .getBean(FrameworkExecutorRepository.class) + .getInternalServiceExecutor(); + this.serviceConfig = InternalServiceConfigBuilder.newBuilder(applicationModel) + .interfaceClass(MetadataService.class) + .protocol(getApplicationConfig().getMetadataServiceProtocol(), METADATA_SERVICE_PROTOCOL_KEY) + .port(getApplicationConfig().getMetadataServicePort(), METADATA_SERVICE_PORT_KEY) + .registryId(INTERNAL_METADATA_REGISTRY_ID) + .executor(internalServiceExecutor) + .ref(metadataService) + .version(V1) + .build(configConsumer -> configConsumer.setMethods(generateMethodConfig())); + + serviceConfig.export(); + metadataService.setMetadataURL(serviceConfig.getExportedUrls().get(0)); + + if (logger.isInfoEnabled()) { + logger.info("The MetadataService exports urls : " + serviceConfig.getExportedUrls()); + } + } + + private void exportV2() { + ExecutorService internalServiceExecutor = applicationModel + .getFrameworkModel() + .getBeanFactory() + .getBean(FrameworkExecutorRepository.class) + .getInternalServiceExecutor(); + this.serviceConfigV2 = InternalServiceConfigBuilder.newBuilder(applicationModel) + .interfaceClass(MetadataServiceV2.class) + .protocol(TRIPLE, METADATA_SERVICE_PROTOCOL_KEY) + .port(getApplicationConfig().getMetadataServicePort(), METADATA_SERVICE_PORT_KEY) + .registryId(INTERNAL_METADATA_REGISTRY_ID) + .executor(internalServiceExecutor) + .ref(metadataServiceV2) + .version(V2) + .build(); + + serviceConfigV2.export(); + metadataServiceV2.setMetadataUrl(serviceConfigV2.getExportedUrls().get(0)); + + if (logger.isInfoEnabled()) { + logger.info("The MetadataServiceV2 exports urls : " + serviceConfigV2.getExportedUrls()); + } + } + public ConfigurableMetadataServiceExporter unexport() { if (isExported()) { serviceConfig.unexport(); + serviceConfigV2.unexport(); metadataService.setMetadataURL(null); } return this; } - public boolean isExported() { + private boolean v1Exported() { return serviceConfig != null && serviceConfig.isExported() && !serviceConfig.isUnexported(); } + private boolean v2Exported() { + return serviceConfigV2 != null && serviceConfigV2.isExported() && !serviceConfigV2.isUnexported(); + } + + public boolean isExported() { + return v1Exported() || v2Exported(); + } + private ApplicationConfig getApplicationConfig() { return applicationModel.getApplicationConfigManager().getApplication().get(); } @@ -129,14 +187,4 @@ public class ConfigurableMetadataServiceExporter { return Collections.singletonList(methodConfig); } - - // for unit test - public void setMetadataService(MetadataServiceDelegation metadataService) { - this.metadataService = metadataService; - } - - // for unit test - public List getExportedURLs() { - return serviceConfig != null ? serviceConfig.getExportedUrls() : emptyList(); - } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ExporterDeployListener.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ExporterDeployListener.java index e9ede45636..11d2e5476f 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ExporterDeployListener.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ExporterDeployListener.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.deploy.ApplicationDeployListener; import org.apache.dubbo.common.lang.Prioritized; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation; +import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegationV2; import org.apache.dubbo.rpc.model.ApplicationModel; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE; @@ -78,10 +79,16 @@ public class ExporterDeployListener implements ApplicationDeployListener, Priori @Override public synchronized void onModuleStarted(ApplicationModel applicationModel) { // start metadata service exporter + @Deprecated MetadataServiceDelegation metadataService = applicationModel.getBeanFactory().getOrRegisterBean(MetadataServiceDelegation.class); + + MetadataServiceDelegationV2 metadataServiceV2 = + applicationModel.getBeanFactory().getOrRegisterBean(MetadataServiceDelegationV2.class); + if (metadataServiceExporter == null) { - metadataServiceExporter = new ConfigurableMetadataServiceExporter(applicationModel, metadataService); + metadataServiceExporter = + new ConfigurableMetadataServiceExporter(applicationModel, metadataService, metadataServiceV2); // fixme, let's disable local metadata service export at this moment if (!REMOTE_METADATA_STORAGE_TYPE.equals(getMetadataType(applicationModel)) && !INTERFACE_REGISTER_MODE.equals(getRegisterMode(applicationModel))) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/MetadataServiceURLParamsMetadataCustomizer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/MetadataServiceURLParamsMetadataCustomizer.java index 6bd1f7d5e4..3ac99915ef 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/MetadataServiceURLParamsMetadataCustomizer.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/MetadataServiceURLParamsMetadataCustomizer.java @@ -20,8 +20,12 @@ import org.apache.dubbo.common.BaseServiceMetadata; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.metadata.MetadataServiceV2; +import org.apache.dubbo.metadata.util.MetadataServiceVersionUtils; import org.apache.dubbo.registry.client.ServiceInstance; import org.apache.dubbo.registry.client.ServiceInstanceCustomizer; +import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation; +import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegationV2; import org.apache.dubbo.registry.client.metadata.SpringCloudMetadataServiceURLBuilder; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ModuleServiceRepository; @@ -32,6 +36,7 @@ import java.util.Map; import static org.apache.dubbo.common.utils.StringUtils.isBlank; import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME; +import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_VERSION_NAME; import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceParameter; /** @@ -41,15 +46,26 @@ public class MetadataServiceURLParamsMetadataCustomizer implements ServiceInstan @Override public void customize(ServiceInstance serviceInstance, ApplicationModel applicationModel) { - Map metadata = serviceInstance.getMetadata(); String propertyName = resolveMetadataPropertyName(serviceInstance); String propertyValue = resolveMetadataPropertyValue(applicationModel); - if (!isBlank(propertyName) && !isBlank(propertyValue)) { metadata.put(propertyName, propertyValue); } + String version = resolveMetadataServiceVersion(applicationModel); + metadata.put(METADATA_SERVICE_VERSION_NAME, version); + } + + public static String resolveMetadataServiceVersion(ApplicationModel applicationModel) { + boolean needExportV2 = MetadataServiceVersionUtils.needExportV2(applicationModel); + String version; + if (needExportV2) { + version = MetadataServiceDelegationV2.VERSION; + } else { + version = MetadataServiceDelegation.VERSION; + } + return version; } private String resolveMetadataPropertyName(ServiceInstance serviceInstance) { @@ -59,8 +75,20 @@ public class MetadataServiceURLParamsMetadataCustomizer implements ServiceInstan private String resolveMetadataPropertyValue(ApplicationModel applicationModel) { ModuleServiceRepository serviceRepository = applicationModel.getInternalModule().getServiceRepository(); - String key = BaseServiceMetadata.buildServiceKey( - MetadataService.class.getName(), applicationModel.getApplicationName(), MetadataService.VERSION); + + String key; + + if (MetadataServiceVersionUtils.needExportV2(applicationModel)) { + key = BaseServiceMetadata.buildServiceKey( + MetadataServiceV2.class.getName(), + applicationModel.getApplicationName(), + MetadataServiceDelegationV2.VERSION); + } else { + // If MetadataService and MetadataServiceV2 are both exported, use v1 path for capacity. + // Client will use version and protocol to judge if it needs to refer v2 path. + key = BaseServiceMetadata.buildServiceKey( + MetadataService.class.getName(), applicationModel.getApplicationName(), MetadataService.VERSION); + } ProviderModel providerModel = serviceRepository.lookupExportedService(key); String metadataValue = ""; if (providerModel != null) { diff --git a/dubbo-metadata/dubbo-metadata-api/pom.xml b/dubbo-metadata/dubbo-metadata-api/pom.xml index 8fc6af86ea..44e01099bd 100644 --- a/dubbo-metadata/dubbo-metadata-api/pom.xml +++ b/dubbo-metadata/dubbo-metadata-api/pom.xml @@ -74,6 +74,11 @@ log4j-slf4j-impl test - + + org.apache.dubbo + dubbo-rpc-triple + ${project.parent.version} + + diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DubboMetadataServiceV2Triple.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DubboMetadataServiceV2Triple.java new file mode 100644 index 0000000000..2cbb904e79 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DubboMetadataServiceV2Triple.java @@ -0,0 +1,200 @@ +/* + * 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; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.stream.StreamObserver; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.PathResolver; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.ServerService; +import org.apache.dubbo.rpc.TriRpcStatus; +import org.apache.dubbo.rpc.model.MethodDescriptor; +import org.apache.dubbo.rpc.model.ServiceDescriptor; +import org.apache.dubbo.rpc.model.StubMethodDescriptor; +import org.apache.dubbo.rpc.model.StubServiceDescriptor; +import org.apache.dubbo.rpc.stub.StubInvocationUtil; +import org.apache.dubbo.rpc.stub.StubInvoker; +import org.apache.dubbo.rpc.stub.StubMethodHandler; +import org.apache.dubbo.rpc.stub.StubSuppliers; +import org.apache.dubbo.rpc.stub.UnaryStubMethodHandler; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.function.BiConsumer; + +import com.google.protobuf.Message; + +public final class DubboMetadataServiceV2Triple { + + public static final String SERVICE_NAME = MetadataServiceV2.SERVICE_NAME; + + private static final StubServiceDescriptor serviceDescriptor = + new StubServiceDescriptor(SERVICE_NAME, MetadataServiceV2.class); + + static { + org.apache.dubbo.rpc.protocol.tri.service.SchemaDescriptorRegistry.addSchemaDescriptor( + SERVICE_NAME, MetadataServiceV2OuterClass.getDescriptor()); + StubSuppliers.addSupplier(SERVICE_NAME, DubboMetadataServiceV2Triple::newStub); + StubSuppliers.addSupplier(MetadataServiceV2.JAVA_SERVICE_NAME, DubboMetadataServiceV2Triple::newStub); + StubSuppliers.addDescriptor(SERVICE_NAME, serviceDescriptor); + StubSuppliers.addDescriptor(MetadataServiceV2.JAVA_SERVICE_NAME, serviceDescriptor); + } + + @SuppressWarnings("all") + public static MetadataServiceV2 newStub(Invoker invoker) { + return new MetadataServiceV2Stub((Invoker) invoker); + } + + private static final StubMethodDescriptor getMetadataInfoMethod = new StubMethodDescriptor( + "GetMetadataInfo", + Revision.class, + MetadataInfoV2.class, + MethodDescriptor.RpcType.UNARY, + obj -> ((Message) obj).toByteArray(), + obj -> ((Message) obj).toByteArray(), + Revision::parseFrom, + MetadataInfoV2::parseFrom); + + private static final StubMethodDescriptor getMetadataInfoAsyncMethod = new StubMethodDescriptor( + "GetMetadataInfo", + Revision.class, + CompletableFuture.class, + MethodDescriptor.RpcType.UNARY, + obj -> ((Message) obj).toByteArray(), + obj -> ((Message) obj).toByteArray(), + Revision::parseFrom, + MetadataInfoV2::parseFrom); + + private static final StubMethodDescriptor getMetadataInfoProxyAsyncMethod = new StubMethodDescriptor( + "GetMetadataInfoAsync", + Revision.class, + MetadataInfoV2.class, + MethodDescriptor.RpcType.UNARY, + obj -> ((Message) obj).toByteArray(), + obj -> ((Message) obj).toByteArray(), + Revision::parseFrom, + MetadataInfoV2::parseFrom); + + static { + serviceDescriptor.addMethod(getMetadataInfoMethod); + serviceDescriptor.addMethod(getMetadataInfoProxyAsyncMethod); + } + + public static class MetadataServiceV2Stub implements MetadataServiceV2 { + private final Invoker invoker; + + public MetadataServiceV2Stub(Invoker invoker) { + this.invoker = invoker; + } + + @Override + public MetadataInfoV2 getMetadataInfo(Revision request) { + return StubInvocationUtil.unaryCall(invoker, getMetadataInfoMethod, request); + } + + public CompletableFuture getMetadataInfoAsync(Revision request) { + return StubInvocationUtil.unaryCall(invoker, getMetadataInfoAsyncMethod, request); + } + + public void getMetadataInfo(Revision request, StreamObserver responseObserver) { + StubInvocationUtil.unaryCall(invoker, getMetadataInfoMethod, request, responseObserver); + } + } + + public abstract static class MetadataServiceV2ImplBase + implements MetadataServiceV2, ServerService { + + private BiConsumer> syncToAsync(java.util.function.Function syncFun) { + return new BiConsumer>() { + @Override + public void accept(T t, StreamObserver observer) { + try { + R ret = syncFun.apply(t); + observer.onNext(ret); + observer.onCompleted(); + } catch (Throwable e) { + observer.onError(e); + } + } + }; + } + + @Override + public CompletableFuture getMetadataInfoAsync(Revision request) { + return CompletableFuture.completedFuture(getMetadataInfo(request)); + } + + /** + * This server stream type unary method is only used for generated stub to support async unary method. + * It will not be called if you are NOT using Dubbo3 generated triple stub and DO NOT implement this method. + */ + public void getMetadataInfo(Revision request, StreamObserver responseObserver) { + getMetadataInfoAsync(request).whenComplete((r, t) -> { + if (t != null) { + responseObserver.onError(t); + } else { + responseObserver.onNext(r); + responseObserver.onCompleted(); + } + }); + } + + @Override + public final Invoker getInvoker(URL url) { + PathResolver pathResolver = url.getOrDefaultFrameworkModel() + .getExtensionLoader(PathResolver.class) + .getDefaultExtension(); + Map> handlers = new HashMap<>(); + + pathResolver.addNativeStub("/" + SERVICE_NAME + "/GetMetadataInfo"); + pathResolver.addNativeStub("/" + SERVICE_NAME + "/GetMetadataInfoAsync"); + // for compatibility + pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetMetadataInfo"); + pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetMetadataInfoAsync"); + + BiConsumer> getMetadataInfoFunc = this::getMetadataInfo; + handlers.put(getMetadataInfoMethod.getMethodName(), new UnaryStubMethodHandler<>(getMetadataInfoFunc)); + BiConsumer> getMetadataInfoAsyncFunc = + syncToAsync(this::getMetadataInfo); + handlers.put( + getMetadataInfoProxyAsyncMethod.getMethodName(), + new UnaryStubMethodHandler<>(getMetadataInfoAsyncFunc)); + + return new StubInvoker<>(this, url, MetadataServiceV2.class, handlers); + } + + @Override + public MetadataInfoV2 getMetadataInfo(Revision request) { + throw unimplementedMethodException(getMetadataInfoMethod); + } + + @Override + public final ServiceDescriptor getServiceDescriptor() { + return serviceDescriptor; + } + + private RpcException unimplementedMethodException(StubMethodDescriptor methodDescriptor) { + return TriRpcStatus.UNIMPLEMENTED + .withDescription(String.format( + "Method %s is unimplemented", + "/" + serviceDescriptor.getInterfaceName() + "/" + methodDescriptor.getMethodName())) + .asException(); + } + } +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2.java new file mode 100644 index 0000000000..520641396b --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2.java @@ -0,0 +1,895 @@ +/* + * 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; + +/** + * Protobuf type {@code org.apache.dubbo.metadata.MetadataInfoV2} + */ +public final class MetadataInfoV2 extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.MetadataInfoV2) + MetadataInfoV2OrBuilder { + private static final long serialVersionUID = 0L; + // Use MetadataInfoV2.newBuilder() to construct. + private MetadataInfoV2(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private MetadataInfoV2() { + app_ = ""; + version_ = ""; + } + + @Override + @SuppressWarnings({"unused"}) + protected Object newInstance(UnusedPrivateParameter unused) { + return new MetadataInfoV2(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + @Override + protected com.google.protobuf.MapField internalGetMapField(int number) { + switch (number) { + case 3: + return internalGetServices(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_fieldAccessorTable + .ensureFieldAccessorsInitialized(MetadataInfoV2.class, Builder.class); + } + + public static final int APP_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile Object app_ = ""; + /** + * string app = 1; + * @return The app. + */ + @Override + public String getApp() { + Object ref = app_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + app_ = s; + return s; + } + } + /** + * string app = 1; + * @return The bytes for app. + */ + @Override + public com.google.protobuf.ByteString getAppBytes() { + Object ref = app_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + app_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int VERSION_FIELD_NUMBER = 2; + + @SuppressWarnings("serial") + private volatile Object version_ = ""; + /** + * string version = 2; + * @return The version. + */ + @Override + public String getVersion() { + Object ref = version_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + version_ = s; + return s; + } + } + /** + * string version = 2; + * @return The bytes for version. + */ + @Override + public com.google.protobuf.ByteString getVersionBytes() { + Object ref = version_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + version_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int SERVICES_FIELD_NUMBER = 3; + + private static final class ServicesDefaultEntryHolder { + static final com.google.protobuf.MapEntry defaultEntry = + com.google.protobuf.MapEntry.newDefaultInstance( + MetadataServiceV2OuterClass + .internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.STRING, + "", + com.google.protobuf.WireFormat.FieldType.MESSAGE, + ServiceInfoV2.getDefaultInstance()); + } + + @SuppressWarnings("serial") + private com.google.protobuf.MapField services_; + + private com.google.protobuf.MapField internalGetServices() { + if (services_ == null) { + return com.google.protobuf.MapField.emptyMapField(ServicesDefaultEntryHolder.defaultEntry); + } + return services_; + } + + public int getServicesCount() { + return internalGetServices().getMap().size(); + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + @Override + public boolean containsServices(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetServices().getMap().containsKey(key); + } + /** + * Use {@link #getServicesMap()} instead. + */ + @Override + @Deprecated + public java.util.Map getServices() { + return getServicesMap(); + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + @Override + public java.util.Map getServicesMap() { + return internalGetServices().getMap(); + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + @Override + public /* nullable */ ServiceInfoV2 getServicesOrDefault( + String key, + /* nullable */ + ServiceInfoV2 defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = internalGetServices().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + @Override + public ServiceInfoV2 getServicesOrThrow(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = internalGetServices().getMap(); + if (!map.containsKey(key)) { + throw new IllegalArgumentException(); + } + return map.get(key); + } + + private byte memoizedIsInitialized = -1; + + @Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(app_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, app_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, version_); + } + com.google.protobuf.GeneratedMessageV3.serializeStringMapTo( + output, internalGetServices(), ServicesDefaultEntryHolder.defaultEntry, 3); + getUnknownFields().writeTo(output); + } + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(app_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, app_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, version_); + } + for (java.util.Map.Entry entry : + internalGetServices().getMap().entrySet()) { + com.google.protobuf.MapEntry services__ = ServicesDefaultEntryHolder.defaultEntry + .newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, services__); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof MetadataInfoV2)) { + return super.equals(obj); + } + MetadataInfoV2 other = (MetadataInfoV2) obj; + + if (!getApp().equals(other.getApp())) return false; + if (!getVersion().equals(other.getVersion())) return false; + if (!internalGetServices().equals(other.internalGetServices())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + APP_FIELD_NUMBER; + hash = (53 * hash) + getApp().hashCode(); + hash = (37 * hash) + VERSION_FIELD_NUMBER; + hash = (53 * hash) + getVersion().hashCode(); + if (!internalGetServices().getMap().isEmpty()) { + hash = (37 * hash) + SERVICES_FIELD_NUMBER; + hash = (53 * hash) + internalGetServices().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static MetadataInfoV2 parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static MetadataInfoV2 parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static MetadataInfoV2 parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static MetadataInfoV2 parseFrom( + com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static MetadataInfoV2 parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static MetadataInfoV2 parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static MetadataInfoV2 parseFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static MetadataInfoV2 parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + public static MetadataInfoV2 parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static MetadataInfoV2 parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + + public static MetadataInfoV2 parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static MetadataInfoV2 parseFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + @Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(MetadataInfoV2 prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @Override + protected Builder newBuilderForType(BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code org.apache.dubbo.metadata.MetadataInfoV2} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.MetadataInfoV2) + MetadataInfoV2OrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapField internalGetMapField(int number) { + switch (number) { + case 3: + return internalGetServices(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapField internalGetMutableMapField(int number) { + switch (number) { + case 3: + return internalGetMutableServices(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass + .internal_static_org_apache_dubbo_metadata_MetadataInfoV2_fieldAccessorTable + .ensureFieldAccessorsInitialized(MetadataInfoV2.class, Builder.class); + } + + // Construct using org.apache.dubbo.metadata.MetadataInfoV2.newBuilder() + private Builder() {} + + private Builder(BuilderParent parent) { + super(parent); + } + + @Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + app_ = ""; + version_ = ""; + internalGetMutableServices().clear(); + return this; + } + + @Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor; + } + + @Override + public MetadataInfoV2 getDefaultInstanceForType() { + return MetadataInfoV2.getDefaultInstance(); + } + + @Override + public MetadataInfoV2 build() { + MetadataInfoV2 result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @Override + public MetadataInfoV2 buildPartial() { + MetadataInfoV2 result = new MetadataInfoV2(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(MetadataInfoV2 result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.app_ = app_; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.version_ = version_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.services_ = internalGetServices(); + result.services_.makeImmutable(); + } + } + + @Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof MetadataInfoV2) { + return mergeFrom((MetadataInfoV2) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(MetadataInfoV2 other) { + if (other == MetadataInfoV2.getDefaultInstance()) return this; + if (!other.getApp().isEmpty()) { + app_ = other.app_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (!other.getVersion().isEmpty()) { + version_ = other.version_; + bitField0_ |= 0x00000002; + onChanged(); + } + internalGetMutableServices().mergeFrom(other.internalGetServices()); + bitField0_ |= 0x00000004; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @Override + public final boolean isInitialized() { + return true; + } + + @Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + app_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: { + version_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 26: { + com.google.protobuf.MapEntry services__ = input.readMessage( + ServicesDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); + internalGetMutableServices() + .getMutableMap() + .put(services__.getKey(), services__.getValue()); + bitField0_ |= 0x00000004; + break; + } // case 26 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private Object app_ = ""; + /** + * string app = 1; + * @return The app. + */ + public String getApp() { + Object ref = app_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + app_ = s; + return s; + } else { + return (String) ref; + } + } + /** + * string app = 1; + * @return The bytes for app. + */ + public com.google.protobuf.ByteString getAppBytes() { + Object ref = app_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + app_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string app = 1; + * @param value The app to set. + * @return This builder for chaining. + */ + public Builder setApp(String value) { + if (value == null) { + throw new NullPointerException(); + } + app_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * string app = 1; + * @return This builder for chaining. + */ + public Builder clearApp() { + app_ = getDefaultInstance().getApp(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * string app = 1; + * @param value The bytes for app to set. + * @return This builder for chaining. + */ + public Builder setAppBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + app_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private Object version_ = ""; + /** + * string version = 2; + * @return The version. + */ + public String getVersion() { + Object ref = version_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + version_ = s; + return s; + } else { + return (String) ref; + } + } + /** + * string version = 2; + * @return The bytes for version. + */ + public com.google.protobuf.ByteString getVersionBytes() { + Object ref = version_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + version_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string version = 2; + * @param value The version to set. + * @return This builder for chaining. + */ + public Builder setVersion(String value) { + if (value == null) { + throw new NullPointerException(); + } + version_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * string version = 2; + * @return This builder for chaining. + */ + public Builder clearVersion() { + version_ = getDefaultInstance().getVersion(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + return this; + } + /** + * string version = 2; + * @param value The bytes for version to set. + * @return This builder for chaining. + */ + public Builder setVersionBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + version_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + + private com.google.protobuf.MapField services_; + + private com.google.protobuf.MapField internalGetServices() { + if (services_ == null) { + return com.google.protobuf.MapField.emptyMapField(ServicesDefaultEntryHolder.defaultEntry); + } + return services_; + } + + private com.google.protobuf.MapField internalGetMutableServices() { + if (services_ == null) { + services_ = com.google.protobuf.MapField.newMapField(ServicesDefaultEntryHolder.defaultEntry); + } + if (!services_.isMutable()) { + services_ = services_.copy(); + } + bitField0_ |= 0x00000004; + onChanged(); + return services_; + } + + public int getServicesCount() { + return internalGetServices().getMap().size(); + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + @Override + public boolean containsServices(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetServices().getMap().containsKey(key); + } + /** + * Use {@link #getServicesMap()} instead. + */ + @Override + @Deprecated + public java.util.Map getServices() { + return getServicesMap(); + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + @Override + public java.util.Map getServicesMap() { + return internalGetServices().getMap(); + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + @Override + public /* nullable */ ServiceInfoV2 getServicesOrDefault( + String key, + /* nullable */ + ServiceInfoV2 defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = internalGetServices().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + @Override + public ServiceInfoV2 getServicesOrThrow(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = internalGetServices().getMap(); + if (!map.containsKey(key)) { + throw new IllegalArgumentException(); + } + return map.get(key); + } + + public Builder clearServices() { + bitField0_ = (bitField0_ & ~0x00000004); + internalGetMutableServices().getMutableMap().clear(); + return this; + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + public Builder removeServices(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + internalGetMutableServices().getMutableMap().remove(key); + return this; + } + /** + * Use alternate mutation accessors instead. + */ + @Deprecated + public java.util.Map getMutableServices() { + bitField0_ |= 0x00000004; + return internalGetMutableServices().getMutableMap(); + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + public Builder putServices(String key, ServiceInfoV2 value) { + if (key == null) { + throw new NullPointerException("map key"); + } + if (value == null) { + throw new NullPointerException("map value"); + } + internalGetMutableServices().getMutableMap().put(key, value); + bitField0_ |= 0x00000004; + return this; + } + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + public Builder putAllServices(java.util.Map values) { + internalGetMutableServices().getMutableMap().putAll(values); + bitField0_ |= 0x00000004; + return this; + } + + @Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @Override + public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:org.apache.dubbo.metadata.MetadataInfoV2) + } + + // @@protoc_insertion_point(class_scope:org.apache.dubbo.metadata.MetadataInfoV2) + private static final MetadataInfoV2 DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new MetadataInfoV2(); + } + + public static MetadataInfoV2 getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @Override + public MetadataInfoV2 parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @Override + public MetadataInfoV2 getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2OrBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2OrBuilder.java new file mode 100644 index 0000000000..cab7cdc934 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2OrBuilder.java @@ -0,0 +1,75 @@ +/* + * 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; + +public interface MetadataInfoV2OrBuilder + extends + // @@protoc_insertion_point(interface_extends:org.apache.dubbo.metadata.MetadataInfoV2) + com.google.protobuf.MessageOrBuilder { + + /** + * string app = 1; + * @return The app. + */ + String getApp(); + /** + * string app = 1; + * @return The bytes for app. + */ + com.google.protobuf.ByteString getAppBytes(); + + /** + * string version = 2; + * @return The version. + */ + String getVersion(); + /** + * string version = 2; + * @return The bytes for version. + */ + com.google.protobuf.ByteString getVersionBytes(); + + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + int getServicesCount(); + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + boolean containsServices(String key); + /** + * Use {@link #getServicesMap()} instead. + */ + @Deprecated + java.util.Map getServices(); + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + java.util.Map getServicesMap(); + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + /* nullable */ + ServiceInfoV2 getServicesOrDefault( + String key, + /* nullable */ + ServiceInfoV2 defaultValue); + /** + * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; + */ + ServiceInfoV2 getServicesOrThrow(String key); +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2.java new file mode 100644 index 0000000000..5ab5538403 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2.java @@ -0,0 +1,29 @@ +/* + * 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; + +import java.util.concurrent.CompletableFuture; + +public interface MetadataServiceV2 extends org.apache.dubbo.rpc.model.DubboStub { + + String JAVA_SERVICE_NAME = "org.apache.dubbo.metadata.MetadataServiceV2"; + String SERVICE_NAME = "org.apache.dubbo.metadata.MetadataServiceV2"; + + MetadataInfoV2 getMetadataInfo(Revision request); + + CompletableFuture getMetadataInfoAsync(Revision request); +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2Detector.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2Detector.java new file mode 100644 index 0000000000..3cd78c4c2a --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2Detector.java @@ -0,0 +1,53 @@ +/* + * 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; + +import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.rpc.model.BuiltinServiceDetector; + +import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_CLASS_NOT_FOUND; + +public class MetadataServiceV2Detector implements BuiltinServiceDetector { + + private static final ErrorTypeAwareLogger logger = + LoggerFactory.getErrorTypeAwareLogger(MetadataServiceV2Detector.class); + + public static final String NAME = "metadataV2"; + + @Override + public Class getService() { + if (!support()) { + logger.warn( + COMMON_CLASS_NOT_FOUND, + "", + "", + "To use MetadataServiceV2, Protobuf dependencies are required. Fallback to MetadataService(V1)."); + return null; + } + return org.apache.dubbo.metadata.MetadataServiceV2.class; + } + + public static boolean support() { + try { + Class.forName("com.google.protobuf.Message"); + } catch (ClassNotFoundException classNotFoundException) { + return false; + } + return true; + } +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2OuterClass.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2OuterClass.java new file mode 100644 index 0000000000..ff1e6a2374 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2OuterClass.java @@ -0,0 +1,122 @@ +/* + * 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; + +public final class MetadataServiceV2OuterClass { + private MetadataServiceV2OuterClass() {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); + } + + static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_metadata_Revision_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_metadata_Revision_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + + static { + String[] descriptorData = { + "\n\031metadata_service_v2.proto\022\031org.apache." + + "dubbo.metadata\"\031\n\010Revision\022\r\n\005value\030\001 \001(" + + "\t\"\324\001\n\016MetadataInfoV2\022\013\n\003app\030\001 \001(\t\022\017\n\007ver" + + "sion\030\002 \001(\t\022I\n\010services\030\003 \003(\01327.org.apach" + + "e.dubbo.metadata.MetadataInfoV2.Services" + + "Entry\032Y\n\rServicesEntry\022\013\n\003key\030\001 \001(\t\0227\n\005v" + + "alue\030\002 \001(\0132(.org.apache.dubbo.metadata.S" + + "erviceInfoV2:\0028\001\"\340\001\n\rServiceInfoV2\022\014\n\004na" + + "me\030\001 \001(\t\022\r\n\005group\030\002 \001(\t\022\017\n\007version\030\003 \001(\t" + + "\022\020\n\010protocol\030\004 \001(\t\022\014\n\004port\030\005 \001(\005\022\014\n\004path" + + "\030\006 \001(\t\022D\n\006params\030\007 \003(\01324.org.apache.dubb" + + "o.metadata.ServiceInfoV2.ParamsEntry\032-\n\013" + + "ParamsEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:" + + "\0028\0012v\n\021MetadataServiceV2\022a\n\017GetMetadataI" + + "nfo\022#.org.apache.dubbo.metadata.Revision" + + "\032).org.apache.dubbo.metadata.MetadataInf" + + "oV2BO\n\031org.apache.dubbo.metadataP\001Z0dubb" + + "o.apache.org/dubbo-go/v3/metadata/triple" + + "_apib\006proto3" + }; + descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {}); + internal_static_org_apache_dubbo_metadata_Revision_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_org_apache_dubbo_metadata_Revision_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_metadata_Revision_descriptor, new String[] { + "Value", + }); + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor, new String[] { + "App", "Version", "Services", + }); + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_descriptor = + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor + .getNestedTypes() + .get(0); + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_descriptor, + new String[] { + "Key", "Value", + }); + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor, new String[] { + "Name", "Group", "Version", "Protocol", "Port", "Path", "Params", + }); + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_descriptor = + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor + .getNestedTypes() + .get(0); + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_descriptor, new String[] { + "Key", "Value", + }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/Revision.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/Revision.java new file mode 100644 index 0000000000..e200128057 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/Revision.java @@ -0,0 +1,497 @@ +/* + * 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; + +/** + * Protobuf type {@code org.apache.dubbo.metadata.Revision} + */ +public final class Revision extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.Revision) + RevisionOrBuilder { + private static final long serialVersionUID = 0L; + // Use Revision.newBuilder() to construct. + private Revision(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private Revision() { + value_ = ""; + } + + @Override + @SuppressWarnings({"unused"}) + protected Object newInstance(UnusedPrivateParameter unused) { + return new Revision(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_descriptor; + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_fieldAccessorTable + .ensureFieldAccessorsInitialized(Revision.class, Builder.class); + } + + public static final int VALUE_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile Object value_ = ""; + /** + * string value = 1; + * @return The value. + */ + @Override + public String getValue() { + Object ref = value_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + value_ = s; + return s; + } + } + /** + * string value = 1; + * @return The bytes for value. + */ + @Override + public com.google.protobuf.ByteString getValueBytes() { + Object ref = value_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + value_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(value_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, value_); + } + getUnknownFields().writeTo(output); + } + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(value_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, value_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof Revision)) { + return super.equals(obj); + } + Revision other = (Revision) obj; + + if (!getValue().equals(other.getValue())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + VALUE_FIELD_NUMBER; + hash = (53 * hash) + getValue().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static Revision parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static Revision parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static Revision parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static Revision parseFrom( + com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static Revision parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static Revision parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static Revision parseFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static Revision parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + public static Revision parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static Revision parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + + public static Revision parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static Revision parseFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + @Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(Revision prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @Override + protected Builder newBuilderForType(BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code org.apache.dubbo.metadata.Revision} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.Revision) + RevisionOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_descriptor; + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_fieldAccessorTable + .ensureFieldAccessorsInitialized(Revision.class, Builder.class); + } + + // Construct using org.apache.dubbo.metadata.Revision.newBuilder() + private Builder() {} + + private Builder(BuilderParent parent) { + super(parent); + } + + @Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + value_ = ""; + return this; + } + + @Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_descriptor; + } + + @Override + public Revision getDefaultInstanceForType() { + return Revision.getDefaultInstance(); + } + + @Override + public Revision build() { + Revision result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @Override + public Revision buildPartial() { + Revision result = new Revision(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(Revision result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.value_ = value_; + } + } + + @Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof Revision) { + return mergeFrom((Revision) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(Revision other) { + if (other == Revision.getDefaultInstance()) return this; + if (!other.getValue().isEmpty()) { + value_ = other.value_; + bitField0_ |= 0x00000001; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @Override + public final boolean isInitialized() { + return true; + } + + @Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + value_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private Object value_ = ""; + /** + * string value = 1; + * @return The value. + */ + public String getValue() { + Object ref = value_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + value_ = s; + return s; + } else { + return (String) ref; + } + } + /** + * string value = 1; + * @return The bytes for value. + */ + public com.google.protobuf.ByteString getValueBytes() { + Object ref = value_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + value_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string value = 1; + * @param value The value to set. + * @return This builder for chaining. + */ + public Builder setValue(String value) { + if (value == null) { + throw new NullPointerException(); + } + value_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * string value = 1; + * @return This builder for chaining. + */ + public Builder clearValue() { + value_ = getDefaultInstance().getValue(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * string value = 1; + * @param value The bytes for value to set. + * @return This builder for chaining. + */ + public Builder setValueBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + value_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + @Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @Override + public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:org.apache.dubbo.metadata.Revision) + } + + // @@protoc_insertion_point(class_scope:org.apache.dubbo.metadata.Revision) + private static final Revision DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new Revision(); + } + + public static Revision getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @Override + public Revision parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @Override + public Revision getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/RevisionOrBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/RevisionOrBuilder.java new file mode 100644 index 0000000000..e8e1596246 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/RevisionOrBuilder.java @@ -0,0 +1,34 @@ +/* + * 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; + +public interface RevisionOrBuilder + extends + // @@protoc_insertion_point(interface_extends:org.apache.dubbo.metadata.Revision) + com.google.protobuf.MessageOrBuilder { + + /** + * string value = 1; + * @return The value. + */ + String getValue(); + /** + * string value = 1; + * @return The bytes for value. + */ + com.google.protobuf.ByteString getValueBytes(); +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2.java new file mode 100644 index 0000000000..8da76533c0 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2.java @@ -0,0 +1,1347 @@ +/* + * 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; + +/** + * Protobuf type {@code org.apache.dubbo.metadata.ServiceInfoV2} + */ +public final class ServiceInfoV2 extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.ServiceInfoV2) + ServiceInfoV2OrBuilder { + private static final long serialVersionUID = 0L; + // Use ServiceInfoV2.newBuilder() to construct. + private ServiceInfoV2(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ServiceInfoV2() { + name_ = ""; + group_ = ""; + version_ = ""; + protocol_ = ""; + path_ = ""; + } + + @Override + @SuppressWarnings({"unused"}) + protected Object newInstance(UnusedPrivateParameter unused) { + return new ServiceInfoV2(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + @Override + protected com.google.protobuf.MapField internalGetMapField(int number) { + switch (number) { + case 7: + return internalGetParams(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_ServiceInfoV2_fieldAccessorTable + .ensureFieldAccessorsInitialized(ServiceInfoV2.class, Builder.class); + } + + public static final int NAME_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile Object name_ = ""; + /** + * string name = 1; + * @return The name. + */ + @Override + public String getName() { + Object ref = name_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * string name = 1; + * @return The bytes for name. + */ + @Override + public com.google.protobuf.ByteString getNameBytes() { + Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int GROUP_FIELD_NUMBER = 2; + + @SuppressWarnings("serial") + private volatile Object group_ = ""; + /** + * string group = 2; + * @return The group. + */ + @Override + public String getGroup() { + Object ref = group_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + group_ = s; + return s; + } + } + /** + * string group = 2; + * @return The bytes for group. + */ + @Override + public com.google.protobuf.ByteString getGroupBytes() { + Object ref = group_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + group_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int VERSION_FIELD_NUMBER = 3; + + @SuppressWarnings("serial") + private volatile Object version_ = ""; + /** + * string version = 3; + * @return The version. + */ + @Override + public String getVersion() { + Object ref = version_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + version_ = s; + return s; + } + } + /** + * string version = 3; + * @return The bytes for version. + */ + @Override + public com.google.protobuf.ByteString getVersionBytes() { + Object ref = version_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + version_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int PROTOCOL_FIELD_NUMBER = 4; + + @SuppressWarnings("serial") + private volatile Object protocol_ = ""; + /** + * string protocol = 4; + * @return The protocol. + */ + @Override + public String getProtocol() { + Object ref = protocol_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + protocol_ = s; + return s; + } + } + /** + * string protocol = 4; + * @return The bytes for protocol. + */ + @Override + public com.google.protobuf.ByteString getProtocolBytes() { + Object ref = protocol_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + protocol_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int PORT_FIELD_NUMBER = 5; + private int port_ = 0; + /** + * int32 port = 5; + * @return The port. + */ + @Override + public int getPort() { + return port_; + } + + public static final int PATH_FIELD_NUMBER = 6; + + @SuppressWarnings("serial") + private volatile Object path_ = ""; + /** + * string path = 6; + * @return The path. + */ + @Override + public String getPath() { + Object ref = path_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + path_ = s; + return s; + } + } + /** + * string path = 6; + * @return The bytes for path. + */ + @Override + public com.google.protobuf.ByteString getPathBytes() { + Object ref = path_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + path_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int PARAMS_FIELD_NUMBER = 7; + + private static final class ParamsDefaultEntryHolder { + static final com.google.protobuf.MapEntry defaultEntry = + com.google.protobuf.MapEntry.newDefaultInstance( + MetadataServiceV2OuterClass + .internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.STRING, + "", + com.google.protobuf.WireFormat.FieldType.STRING, + ""); + } + + @SuppressWarnings("serial") + private com.google.protobuf.MapField params_; + + private com.google.protobuf.MapField internalGetParams() { + if (params_ == null) { + return com.google.protobuf.MapField.emptyMapField(ParamsDefaultEntryHolder.defaultEntry); + } + return params_; + } + + public int getParamsCount() { + return internalGetParams().getMap().size(); + } + /** + * map<string, string> params = 7; + */ + @Override + public boolean containsParams(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetParams().getMap().containsKey(key); + } + /** + * Use {@link #getParamsMap()} instead. + */ + @Override + @Deprecated + public java.util.Map getParams() { + return getParamsMap(); + } + /** + * map<string, string> params = 7; + */ + @Override + public java.util.Map getParamsMap() { + return internalGetParams().getMap(); + } + /** + * map<string, string> params = 7; + */ + @Override + public /* nullable */ String getParamsOrDefault( + String key, + /* nullable */ + String defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = internalGetParams().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + * map<string, string> params = 7; + */ + @Override + public String getParamsOrThrow(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = internalGetParams().getMap(); + if (!map.containsKey(key)) { + throw new IllegalArgumentException(); + } + return map.get(key); + } + + private byte memoizedIsInitialized = -1; + + @Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(group_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, group_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, version_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protocol_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 4, protocol_); + } + if (port_ != 0) { + output.writeInt32(5, port_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(path_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 6, path_); + } + com.google.protobuf.GeneratedMessageV3.serializeStringMapTo( + output, internalGetParams(), ParamsDefaultEntryHolder.defaultEntry, 7); + getUnknownFields().writeTo(output); + } + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(group_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, group_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, version_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protocol_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, protocol_); + } + if (port_ != 0) { + size += com.google.protobuf.CodedOutputStream.computeInt32Size(5, port_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(path_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, path_); + } + for (java.util.Map.Entry entry : + internalGetParams().getMap().entrySet()) { + com.google.protobuf.MapEntry params__ = ParamsDefaultEntryHolder.defaultEntry + .newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream.computeMessageSize(7, params__); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof ServiceInfoV2)) { + return super.equals(obj); + } + ServiceInfoV2 other = (ServiceInfoV2) obj; + + if (!getName().equals(other.getName())) return false; + if (!getGroup().equals(other.getGroup())) return false; + if (!getVersion().equals(other.getVersion())) return false; + if (!getProtocol().equals(other.getProtocol())) return false; + if (getPort() != other.getPort()) return false; + if (!getPath().equals(other.getPath())) return false; + if (!internalGetParams().equals(other.internalGetParams())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (37 * hash) + GROUP_FIELD_NUMBER; + hash = (53 * hash) + getGroup().hashCode(); + hash = (37 * hash) + VERSION_FIELD_NUMBER; + hash = (53 * hash) + getVersion().hashCode(); + hash = (37 * hash) + PROTOCOL_FIELD_NUMBER; + hash = (53 * hash) + getProtocol().hashCode(); + hash = (37 * hash) + PORT_FIELD_NUMBER; + hash = (53 * hash) + getPort(); + hash = (37 * hash) + PATH_FIELD_NUMBER; + hash = (53 * hash) + getPath().hashCode(); + if (!internalGetParams().getMap().isEmpty()) { + hash = (37 * hash) + PARAMS_FIELD_NUMBER; + hash = (53 * hash) + internalGetParams().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static ServiceInfoV2 parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static ServiceInfoV2 parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static ServiceInfoV2 parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static ServiceInfoV2 parseFrom( + com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static ServiceInfoV2 parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static ServiceInfoV2 parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static ServiceInfoV2 parseFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static ServiceInfoV2 parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + public static ServiceInfoV2 parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static ServiceInfoV2 parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + + public static ServiceInfoV2 parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static ServiceInfoV2 parseFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + @Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(ServiceInfoV2 prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @Override + protected Builder newBuilderForType(BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code org.apache.dubbo.metadata.ServiceInfoV2} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.ServiceInfoV2) + ServiceInfoV2OrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapField internalGetMapField(int number) { + switch (number) { + case 7: + return internalGetParams(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapField internalGetMutableMapField(int number) { + switch (number) { + case 7: + return internalGetMutableParams(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass + .internal_static_org_apache_dubbo_metadata_ServiceInfoV2_fieldAccessorTable + .ensureFieldAccessorsInitialized(ServiceInfoV2.class, Builder.class); + } + + // Construct using org.apache.dubbo.metadata.ServiceInfoV2.newBuilder() + private Builder() {} + + private Builder(BuilderParent parent) { + super(parent); + } + + @Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + group_ = ""; + version_ = ""; + protocol_ = ""; + port_ = 0; + path_ = ""; + internalGetMutableParams().clear(); + return this; + } + + @Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor; + } + + @Override + public ServiceInfoV2 getDefaultInstanceForType() { + return ServiceInfoV2.getDefaultInstance(); + } + + @Override + public ServiceInfoV2 build() { + ServiceInfoV2 result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @Override + public ServiceInfoV2 buildPartial() { + ServiceInfoV2 result = new ServiceInfoV2(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(ServiceInfoV2 result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.group_ = group_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.version_ = version_; + } + if (((from_bitField0_ & 0x00000008) != 0)) { + result.protocol_ = protocol_; + } + if (((from_bitField0_ & 0x00000010) != 0)) { + result.port_ = port_; + } + if (((from_bitField0_ & 0x00000020) != 0)) { + result.path_ = path_; + } + if (((from_bitField0_ & 0x00000040) != 0)) { + result.params_ = internalGetParams(); + result.params_.makeImmutable(); + } + } + + @Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof ServiceInfoV2) { + return mergeFrom((ServiceInfoV2) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(ServiceInfoV2 other) { + if (other == ServiceInfoV2.getDefaultInstance()) return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (!other.getGroup().isEmpty()) { + group_ = other.group_; + bitField0_ |= 0x00000002; + onChanged(); + } + if (!other.getVersion().isEmpty()) { + version_ = other.version_; + bitField0_ |= 0x00000004; + onChanged(); + } + if (!other.getProtocol().isEmpty()) { + protocol_ = other.protocol_; + bitField0_ |= 0x00000008; + onChanged(); + } + if (other.getPort() != 0) { + setPort(other.getPort()); + } + if (!other.getPath().isEmpty()) { + path_ = other.path_; + bitField0_ |= 0x00000020; + onChanged(); + } + internalGetMutableParams().mergeFrom(other.internalGetParams()); + bitField0_ |= 0x00000040; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @Override + public final boolean isInitialized() { + return true; + } + + @Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: { + group_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 26: { + version_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000004; + break; + } // case 26 + case 34: { + protocol_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000008; + break; + } // case 34 + case 40: { + port_ = input.readInt32(); + bitField0_ |= 0x00000010; + break; + } // case 40 + case 50: { + path_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000020; + break; + } // case 50 + case 58: { + com.google.protobuf.MapEntry params__ = input.readMessage( + ParamsDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); + internalGetMutableParams().getMutableMap().put(params__.getKey(), params__.getValue()); + bitField0_ |= 0x00000040; + break; + } // case 58 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private Object name_ = ""; + /** + * string name = 1; + * @return The name. + */ + public String getName() { + Object ref = name_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (String) ref; + } + } + /** + * string name = 1; + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string name = 1; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(String value) { + if (value == null) { + throw new NullPointerException(); + } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * string name = 1; + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * string name = 1; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private Object group_ = ""; + /** + * string group = 2; + * @return The group. + */ + public String getGroup() { + Object ref = group_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + group_ = s; + return s; + } else { + return (String) ref; + } + } + /** + * string group = 2; + * @return The bytes for group. + */ + public com.google.protobuf.ByteString getGroupBytes() { + Object ref = group_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + group_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string group = 2; + * @param value The group to set. + * @return This builder for chaining. + */ + public Builder setGroup(String value) { + if (value == null) { + throw new NullPointerException(); + } + group_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * string group = 2; + * @return This builder for chaining. + */ + public Builder clearGroup() { + group_ = getDefaultInstance().getGroup(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + return this; + } + /** + * string group = 2; + * @param value The bytes for group to set. + * @return This builder for chaining. + */ + public Builder setGroupBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + group_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + + private Object version_ = ""; + /** + * string version = 3; + * @return The version. + */ + public String getVersion() { + Object ref = version_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + version_ = s; + return s; + } else { + return (String) ref; + } + } + /** + * string version = 3; + * @return The bytes for version. + */ + public com.google.protobuf.ByteString getVersionBytes() { + Object ref = version_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + version_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string version = 3; + * @param value The version to set. + * @return This builder for chaining. + */ + public Builder setVersion(String value) { + if (value == null) { + throw new NullPointerException(); + } + version_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * string version = 3; + * @return This builder for chaining. + */ + public Builder clearVersion() { + version_ = getDefaultInstance().getVersion(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + return this; + } + /** + * string version = 3; + * @param value The bytes for version to set. + * @return This builder for chaining. + */ + public Builder setVersionBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + version_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + private Object protocol_ = ""; + /** + * string protocol = 4; + * @return The protocol. + */ + public String getProtocol() { + Object ref = protocol_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + protocol_ = s; + return s; + } else { + return (String) ref; + } + } + /** + * string protocol = 4; + * @return The bytes for protocol. + */ + public com.google.protobuf.ByteString getProtocolBytes() { + Object ref = protocol_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + protocol_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string protocol = 4; + * @param value The protocol to set. + * @return This builder for chaining. + */ + public Builder setProtocol(String value) { + if (value == null) { + throw new NullPointerException(); + } + protocol_ = value; + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * string protocol = 4; + * @return This builder for chaining. + */ + public Builder clearProtocol() { + protocol_ = getDefaultInstance().getProtocol(); + bitField0_ = (bitField0_ & ~0x00000008); + onChanged(); + return this; + } + /** + * string protocol = 4; + * @param value The bytes for protocol to set. + * @return This builder for chaining. + */ + public Builder setProtocolBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + protocol_ = value; + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + + private int port_; + /** + * int32 port = 5; + * @return The port. + */ + @Override + public int getPort() { + return port_; + } + /** + * int32 port = 5; + * @param value The port to set. + * @return This builder for chaining. + */ + public Builder setPort(int value) { + + port_ = value; + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + /** + * int32 port = 5; + * @return This builder for chaining. + */ + public Builder clearPort() { + bitField0_ = (bitField0_ & ~0x00000010); + port_ = 0; + onChanged(); + return this; + } + + private Object path_ = ""; + /** + * string path = 6; + * @return The path. + */ + public String getPath() { + Object ref = path_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + path_ = s; + return s; + } else { + return (String) ref; + } + } + /** + * string path = 6; + * @return The bytes for path. + */ + public com.google.protobuf.ByteString getPathBytes() { + Object ref = path_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + path_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string path = 6; + * @param value The path to set. + * @return This builder for chaining. + */ + public Builder setPath(String value) { + if (value == null) { + throw new NullPointerException(); + } + path_ = value; + bitField0_ |= 0x00000020; + onChanged(); + return this; + } + /** + * string path = 6; + * @return This builder for chaining. + */ + public Builder clearPath() { + path_ = getDefaultInstance().getPath(); + bitField0_ = (bitField0_ & ~0x00000020); + onChanged(); + return this; + } + /** + * string path = 6; + * @param value The bytes for path to set. + * @return This builder for chaining. + */ + public Builder setPathBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + path_ = value; + bitField0_ |= 0x00000020; + onChanged(); + return this; + } + + private com.google.protobuf.MapField params_; + + private com.google.protobuf.MapField internalGetParams() { + if (params_ == null) { + return com.google.protobuf.MapField.emptyMapField(ParamsDefaultEntryHolder.defaultEntry); + } + return params_; + } + + private com.google.protobuf.MapField internalGetMutableParams() { + if (params_ == null) { + params_ = com.google.protobuf.MapField.newMapField(ParamsDefaultEntryHolder.defaultEntry); + } + if (!params_.isMutable()) { + params_ = params_.copy(); + } + bitField0_ |= 0x00000040; + onChanged(); + return params_; + } + + public int getParamsCount() { + return internalGetParams().getMap().size(); + } + /** + * map<string, string> params = 7; + */ + @Override + public boolean containsParams(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetParams().getMap().containsKey(key); + } + /** + * Use {@link #getParamsMap()} instead. + */ + @Override + @Deprecated + public java.util.Map getParams() { + return getParamsMap(); + } + /** + * map<string, string> params = 7; + */ + @Override + public java.util.Map getParamsMap() { + return internalGetParams().getMap(); + } + /** + * map<string, string> params = 7; + */ + @Override + public /* nullable */ String getParamsOrDefault( + String key, + /* nullable */ + String defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = internalGetParams().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + * map<string, string> params = 7; + */ + @Override + public String getParamsOrThrow(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = internalGetParams().getMap(); + if (!map.containsKey(key)) { + throw new IllegalArgumentException(); + } + return map.get(key); + } + + public Builder clearParams() { + bitField0_ = (bitField0_ & ~0x00000040); + internalGetMutableParams().getMutableMap().clear(); + return this; + } + /** + * map<string, string> params = 7; + */ + public Builder removeParams(String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + internalGetMutableParams().getMutableMap().remove(key); + return this; + } + /** + * Use alternate mutation accessors instead. + */ + @Deprecated + public java.util.Map getMutableParams() { + bitField0_ |= 0x00000040; + return internalGetMutableParams().getMutableMap(); + } + /** + * map<string, string> params = 7; + */ + public Builder putParams(String key, String value) { + if (key == null) { + throw new NullPointerException("map key"); + } + if (value == null) { + throw new NullPointerException("map value"); + } + internalGetMutableParams().getMutableMap().put(key, value); + bitField0_ |= 0x00000040; + return this; + } + /** + * map<string, string> params = 7; + */ + public Builder putAllParams(java.util.Map values) { + internalGetMutableParams().getMutableMap().putAll(values); + bitField0_ |= 0x00000040; + return this; + } + + @Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @Override + public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:org.apache.dubbo.metadata.ServiceInfoV2) + } + + // @@protoc_insertion_point(class_scope:org.apache.dubbo.metadata.ServiceInfoV2) + private static final ServiceInfoV2 DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new ServiceInfoV2(); + } + + public static ServiceInfoV2 getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @Override + public ServiceInfoV2 parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @Override + public ServiceInfoV2 getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2OrBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2OrBuilder.java new file mode 100644 index 0000000000..6c39dd594f --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2OrBuilder.java @@ -0,0 +1,114 @@ +/* + * 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; + +public interface ServiceInfoV2OrBuilder + extends + // @@protoc_insertion_point(interface_extends:org.apache.dubbo.metadata.ServiceInfoV2) + com.google.protobuf.MessageOrBuilder { + + /** + * string name = 1; + * @return The name. + */ + String getName(); + /** + * string name = 1; + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); + + /** + * string group = 2; + * @return The group. + */ + String getGroup(); + /** + * string group = 2; + * @return The bytes for group. + */ + com.google.protobuf.ByteString getGroupBytes(); + + /** + * string version = 3; + * @return The version. + */ + String getVersion(); + /** + * string version = 3; + * @return The bytes for version. + */ + com.google.protobuf.ByteString getVersionBytes(); + + /** + * string protocol = 4; + * @return The protocol. + */ + String getProtocol(); + /** + * string protocol = 4; + * @return The bytes for protocol. + */ + com.google.protobuf.ByteString getProtocolBytes(); + + /** + * int32 port = 5; + * @return The port. + */ + int getPort(); + + /** + * string path = 6; + * @return The path. + */ + String getPath(); + /** + * string path = 6; + * @return The bytes for path. + */ + com.google.protobuf.ByteString getPathBytes(); + + /** + * map<string, string> params = 7; + */ + int getParamsCount(); + /** + * map<string, string> params = 7; + */ + boolean containsParams(String key); + /** + * Use {@link #getParamsMap()} instead. + */ + @Deprecated + java.util.Map getParams(); + /** + * map<string, string> params = 7; + */ + java.util.Map getParamsMap(); + /** + * map<string, string> params = 7; + */ + /* nullable */ + String getParamsOrDefault( + String key, + /* nullable */ + String defaultValue); + /** + * map<string, string> params = 7; + */ + String getParamsOrThrow(String key); +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/util/MetadataServiceVersionUtils.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/util/MetadataServiceVersionUtils.java new file mode 100644 index 0000000000..13d1ccc7c2 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/util/MetadataServiceVersionUtils.java @@ -0,0 +1,154 @@ +/* + * 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.util; + +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.context.ConfigManager; +import org.apache.dubbo.metadata.MetadataInfo; +import org.apache.dubbo.metadata.MetadataInfo.ServiceInfo; +import org.apache.dubbo.metadata.MetadataInfoV2; +import org.apache.dubbo.metadata.MetadataServiceV2Detector; +import org.apache.dubbo.metadata.ServiceInfoV2; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static org.apache.dubbo.common.constants.CommonConstants.TRIPLE; + +public class MetadataServiceVersionUtils { + + public static final String V1 = "1.0.0"; + + public static final String V2 = "2.0.0"; + + public static MetadataInfoV2 toV2(MetadataInfo metadataInfo) { + if (metadataInfo == null) { + return MetadataInfoV2.newBuilder().build(); + } + Map servicesV2 = new HashMap<>(); + + metadataInfo.getServices().forEach((name, serviceInfo) -> servicesV2.put(name, toV2(serviceInfo))); + return MetadataInfoV2.newBuilder() + .setVersion(ifNullSetEmpty(metadataInfo.getRevision())) + .setApp(ifNullSetEmpty(metadataInfo.getApp())) + .putAllServices(servicesV2) + .build(); + } + + public static ServiceInfoV2 toV2(ServiceInfo serviceInfo) { + if (serviceInfo == null) { + return ServiceInfoV2.newBuilder().build(); + } + return ServiceInfoV2.newBuilder() + .setVersion(ifNullSetEmpty(serviceInfo.getVersion())) + .setGroup(ifNullSetEmpty(serviceInfo.getGroup())) + .setName(ifNullSetEmpty(serviceInfo.getName())) + .setPort(serviceInfo.getPort()) + .setPath(ifNullSetEmpty(serviceInfo.getPath())) + .setProtocol(ifNullSetEmpty(serviceInfo.getProtocol())) + .putAllParams(serviceInfo.getAllParams()) + .build(); + } + + private static String ifNullSetEmpty(String value) { + return value == null ? "" : value; + } + + public static MetadataInfo toV1(MetadataInfoV2 metadataInfoV2) { + Map servicesV2Map = metadataInfoV2.getServicesMap(); + Map serviceMap = new HashMap<>(servicesV2Map.size()); + servicesV2Map.forEach((s, serviceInfoV2) -> serviceMap.put(s, toV1(serviceInfoV2))); + return new MetadataInfo(metadataInfoV2.getApp(), metadataInfoV2.getVersion(), serviceMap); + } + + public static ServiceInfo toV1(ServiceInfoV2 serviceInfoV2) { + ServiceInfo serviceInfo = new ServiceInfo(); + serviceInfo.setGroup(serviceInfoV2.getGroup()); + serviceInfo.setVersion(serviceInfoV2.getVersion()); + serviceInfo.setName(serviceInfoV2.getName()); + serviceInfo.setPort(serviceInfoV2.getPort()); + serviceInfo.setParams(serviceInfoV2.getParamsMap()); + serviceInfo.setProtocol(serviceInfoV2.getProtocol()); + serviceInfo.setPath(serviceInfoV2.getPath()); + return serviceInfo; + } + + /** + * check if we should export MetadataService + */ + public static boolean needExportV1(ApplicationModel applicationModel) { + return !MetadataServiceV2Detector.support() || !onlyExportV2(applicationModel); + } + + /** + * check if we should export MetadataServiceV2 + */ + public static boolean needExportV2(ApplicationModel applicationModel) { + return MetadataServiceV2Detector.support() + && (onlyExportV2(applicationModel) || tripleConfigured(applicationModel)); + } + + /** + * check if we should only export MetadataServiceV2 + */ + public static boolean onlyExportV2(ApplicationModel applicationModel) { + Optional applicationConfig = getApplicationConfig(applicationModel); + return applicationConfig + .filter(config -> + Boolean.TRUE.equals(config.getOnlyUseMetadataV2()) && tripleConfigured(applicationModel)) + .isPresent(); + } + + /** + * check if we can use triple as MetadataService protocol + */ + public static boolean tripleConfigured(ApplicationModel applicationModel) { + Optional configManager = Optional.ofNullable(applicationModel.getApplicationConfigManager()); + + Optional appConfig = getApplicationConfig(applicationModel); + + // if user configured MetadataService protocol + if (appConfig.isPresent() && appConfig.get().getMetadataServiceProtocol() != null) { + return TRIPLE.equals(appConfig.get().getMetadataServiceProtocol()); + } + // if not specified, check all protocol configs + if (configManager.isPresent() + && CollectionUtils.isNotEmpty(configManager.get().getProtocols())) { + Collection protocols = configManager.get().getProtocols(); + for (ProtocolConfig protocolConfig : protocols) { + if (TRIPLE.equals(protocolConfig.getName())) { + return true; + } + } + } + return false; + } + + private static Optional getApplicationConfig(ApplicationModel applicationModel) { + Optional configManager = Optional.ofNullable(applicationModel.getApplicationConfigManager()); + + if (configManager.isPresent() && configManager.get().getApplication().isPresent()) { + return configManager.get().getApplication(); + } + return Optional.empty(); + } +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/proto/metadata_service_v2.proto b/dubbo-metadata/dubbo-metadata-api/src/main/proto/metadata_service_v2.proto new file mode 100644 index 0000000000..709d35c1a1 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/proto/metadata_service_v2.proto @@ -0,0 +1,47 @@ +/* + * 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. + */ + +syntax = "proto3"; +package org.apache.dubbo.metadata; + +option go_package = "dubbo.apache.org/dubbo-go/v3/metadata/triple_api"; +option java_package = "org.apache.dubbo.metadata"; +option java_multiple_files = true; + +service MetadataServiceV2{ + rpc GetMetadataInfo(Revision) returns (MetadataInfoV2); +} + +message Revision{ + string value = 1; +} + +message MetadataInfoV2{ + string app = 1; + string version = 2; + map services = 3; +} + +message ServiceInfoV2{ + string name = 1; + string group = 2; + string version = 3; + string protocol = 4; + int32 port = 5; + string path = 6; + map params = 7; +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.BuiltinServiceDetector b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.BuiltinServiceDetector index 804f1f0718..c724c71320 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.BuiltinServiceDetector +++ b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.BuiltinServiceDetector @@ -1 +1,2 @@ metadata=org.apache.dubbo.metadata.MetadataServiceDetector +metadataV2=org.apache.dubbo.metadata.MetadataServiceV2Detector diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ReflectionBasedServiceDiscovery.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ReflectionBasedServiceDiscovery.java index dfb5e18ea4..0a7ba6d101 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ReflectionBasedServiceDiscovery.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ReflectionBasedServiceDiscovery.java @@ -277,9 +277,14 @@ public class ReflectionBasedServiceDiscovery extends AbstractServiceDiscovery { } private synchronized MetadataService getMetadataServiceProxy(ServiceInstance instance) { - return ConcurrentHashMapUtils.computeIfAbsent( - metadataServiceProxies, computeKey(instance), k -> MetadataUtils.referProxy(instance) - .getProxy()); + Object internalProxy = MetadataUtils.referMetadataService(instance).getInternalProxy(); + + if (internalProxy instanceof MetadataService) { + return ConcurrentHashMapUtils.computeIfAbsent( + metadataServiceProxies, computeKey(instance), k -> (MetadataService) internalProxy); + } + throw new RuntimeException("Service " + instance.getServiceName() + " at " + instance.getHost() + ":" + + instance.getPort() + "are using MetadataServiceV2, which is not support "); } private synchronized void destroyMetadataServiceProxy(ServiceInstance instance) { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegation.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegation.java index 7069d7a04a..55041f96e8 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegation.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegation.java @@ -61,6 +61,8 @@ public class MetadataServiceDelegation implements MetadataService, Disposable { // works only for DNS service discovery private String instanceMetadata; + public static final String VERSION = "1.0.0"; + public MetadataServiceDelegation(ApplicationModel applicationModel) { this.applicationModel = applicationModel; registryManager = RegistryManager.getInstance(applicationModel); @@ -96,21 +98,25 @@ public class MetadataServiceDelegation implements MetadataService, Disposable { for (ServiceDiscovery sd : serviceDiscoveries) { MetadataInfo metadataInfo = sd.getLocalMetadata(); Map> serviceURLs = metadataInfo.getExportedServiceURLs(); - if (serviceURLs == null) { - continue; - } - for (Map.Entry> entry : serviceURLs.entrySet()) { - SortedSet urls = entry.getValue(); - if (urls != null) { - for (URL url : urls) { - if (!MetadataService.class.getName().equals(url.getServiceInterface())) { - bizURLs.add(url); - } + joinNonMetadataServiceUrls(bizURLs, serviceURLs); + } + return MetadataService.toSortedStrings(bizURLs); + } + + private void joinNonMetadataServiceUrls(SortedSet bizURLs, Map> serviceURLs) { + if (serviceURLs == null) { + return; + } + for (Map.Entry> entry : serviceURLs.entrySet()) { + SortedSet urls = entry.getValue(); + if (urls != null) { + for (URL url : urls) { + if (!MetadataService.class.getName().equals(url.getServiceInterface())) { + bizURLs.add(url); } } } } - return MetadataService.toSortedStrings(bizURLs); } private SortedSet getAllUnmodifiableSubscribedURLs() { @@ -119,19 +125,7 @@ public class MetadataServiceDelegation implements MetadataService, Disposable { for (ServiceDiscovery sd : serviceDiscoveries) { MetadataInfo metadataInfo = sd.getLocalMetadata(); Map> serviceURLs = metadataInfo.getSubscribedServiceURLs(); - if (serviceURLs == null) { - continue; - } - for (Map.Entry> entry : serviceURLs.entrySet()) { - SortedSet urls = entry.getValue(); - if (urls != null) { - for (URL url : urls) { - if (!MetadataService.class.getName().equals(url.getServiceInterface())) { - bizURLs.add(url); - } - } - } - } + joinNonMetadataServiceUrls(bizURLs, serviceURLs); } return MetadataService.toSortedStrings(bizURLs); } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegationV2.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegationV2.java new file mode 100644 index 0000000000..1eec46e195 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegationV2.java @@ -0,0 +1,78 @@ +/* + * 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.client.metadata; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.metadata.DubboMetadataServiceV2Triple.MetadataServiceV2ImplBase; +import org.apache.dubbo.metadata.MetadataInfo; +import org.apache.dubbo.registry.client.ServiceDiscovery; +import org.apache.dubbo.registry.support.RegistryManager; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_LOAD_METADATA; +import static org.apache.dubbo.metadata.util.MetadataServiceVersionUtils.toV2; + +public class MetadataServiceDelegationV2 extends MetadataServiceV2ImplBase { + + ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass()); + + private final ApplicationModel applicationModel; + + private final RegistryManager registryManager; + + private URL metadataUrl; + + public static final String VERSION = "2.0.0"; + + public MetadataServiceDelegationV2(ApplicationModel applicationModel) { + this.applicationModel = applicationModel; + this.registryManager = RegistryManager.getInstance(applicationModel); + } + + @Override + public org.apache.dubbo.metadata.MetadataInfoV2 getMetadataInfo(org.apache.dubbo.metadata.Revision revisionV2) { + String revision = revisionV2.getValue(); + MetadataInfo info = null; + if (StringUtils.isEmpty(revision)) { + return null; + } + + for (ServiceDiscovery sd : registryManager.getServiceDiscoveries()) { + info = sd.getLocalMetadata(revision); + + if (info != null && revision.equals(info.getRevision())) { + return toV2(info); + } + } + + if (logger.isWarnEnabled()) { + logger.warn(REGISTRY_FAILED_LOAD_METADATA, "", "", "metadataV2 not found for revision: " + revisionV2); + } + return null; + } + + public URL getMetadataUrl() { + return metadataUrl; + } + + public void setMetadataUrl(URL metadataUrl) { + this.metadataUrl = metadataUrl; + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java index e75e133d9a..79c6208fad 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java @@ -25,11 +25,15 @@ import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.metadata.MetadataInfo; import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.metadata.MetadataServiceV2; +import org.apache.dubbo.metadata.MetadataServiceV2Detector; +import org.apache.dubbo.metadata.Revision; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; import org.apache.dubbo.metadata.report.MetadataReport; import org.apache.dubbo.metadata.report.MetadataReportInstance; import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier; +import org.apache.dubbo.metadata.util.MetadataServiceVersionUtils; import org.apache.dubbo.registry.client.ServiceInstance; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; @@ -39,6 +43,7 @@ import org.apache.dubbo.rpc.model.ConsumerModel; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ServiceDescriptor; import org.apache.dubbo.rpc.service.Destroyable; +import org.apache.dubbo.rpc.stub.StubSuppliers; import java.util.HashMap; import java.util.List; @@ -46,20 +51,25 @@ import java.util.Map; import java.util.concurrent.ThreadLocalRandom; import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.NATIVE_STUB; import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.PROXY_CLASS_REF; import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_CREATE_INSTANCE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_LOAD_METADATA; import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY; +import static org.apache.dubbo.metadata.util.MetadataServiceVersionUtils.V2; import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_URLS_PROPERTY_NAME; +import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_VERSION_NAME; +import static org.apache.dubbo.rpc.Constants.PROXY_KEY; public class MetadataUtils { public static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(MetadataUtils.class); public static void publishServiceDefinition( URL url, ServiceDescriptor serviceDescriptor, ApplicationModel applicationModel) { - if (getMetadataReports(applicationModel).size() == 0) { + if (getMetadataReports(applicationModel).isEmpty()) { String msg = "Remote Metadata Report Server is not provided or unavailable, will stop registering service definition to remote center!"; logger.warn(REGISTRY_FAILED_LOAD_METADATA, "", "", msg); @@ -115,7 +125,70 @@ public class MetadataUtils { } } - public static ProxyHolder referProxy(ServiceInstance instance) { + public static RemoteMetadataService referMetadataService(ServiceInstance instance) { + URL url = buildMetadataUrl(instance); + + // Simply rely on the first metadata url, as stated in MetadataServiceURLBuilder. + ApplicationModel applicationModel = instance.getApplicationModel(); + ModuleModel internalModel = applicationModel.getInternalModule(); + + ConsumerModel consumerModel; + + boolean useV2 = MetadataServiceDelegationV2.VERSION.equals(url.getAttribute(METADATA_SERVICE_VERSION_NAME)); + if (!MetadataServiceV2Detector.support()) { + useV2 = false; + } + boolean inNativeImage = NativeDetector.inNativeImage(); + + if (useV2 && !inNativeImage) { + // If provider supports, we use MetadataServiceV2 in priority + url = url.addParameter(PROXY_KEY, NATIVE_STUB); + url = url.setPath(MetadataServiceV2.class.getName()); + url = url.addParameter(VERSION_KEY, V2); + + consumerModel = applicationModel + .getInternalModule() + .registerInternalConsumer( + MetadataServiceV2.class, + url, + StubSuppliers.getServiceDescriptor(MetadataServiceV2.class.getName())); + } else { + consumerModel = applicationModel.getInternalModule().registerInternalConsumer(MetadataService.class, url); + } + + if (inNativeImage) { + url = url.addParameter(PROXY_KEY, "jdk"); + } + + Protocol protocol = applicationModel.getExtensionLoader(Protocol.class).getExtension(url.getProtocol(), false); + + url = url.setServiceModel(consumerModel); + + RemoteMetadataService remoteMetadataService; + ProxyFactory proxyFactory = + applicationModel.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); + if (useV2) { + Invoker invoker = protocol.refer(MetadataServiceV2.class, url); + + remoteMetadataService = + new RemoteMetadataService(consumerModel, proxyFactory.getProxy(invoker), internalModel); + } else { + Invoker invoker = protocol.refer(MetadataService.class, url); + + remoteMetadataService = + new RemoteMetadataService(consumerModel, proxyFactory.getProxy(invoker), internalModel); + } + + Object metadataServiceProxy = remoteMetadataService.getInternalProxy(); + consumerModel.getServiceMetadata().setTarget(metadataServiceProxy); + consumerModel.getServiceMetadata().addAttribute(PROXY_CLASS_REF, metadataServiceProxy); + consumerModel.setProxyObject(metadataServiceProxy); + consumerModel.initMethodModels(); + + return remoteMetadataService; + } + + private static URL buildMetadataUrl(ServiceInstance instance) { MetadataServiceURLBuilder builder; ExtensionLoader loader = instance.getApplicationModel().getExtensionLoader(MetadataServiceURLBuilder.class); @@ -134,36 +207,12 @@ public class MetadataUtils { throw new IllegalStateException("Introspection service discovery mode is enabled " + instance + ", but no metadata service can build from it."); } - URL url = urls.get(0); - // Simply rely on the first metadata url, as stated in MetadataServiceURLBuilder. - ApplicationModel applicationModel = instance.getApplicationModel(); - ModuleModel internalModel = applicationModel.getInternalModule(); - ConsumerModel consumerModel = - applicationModel.getInternalModule().registerInternalConsumer(MetadataService.class, url); + String version = metadata.get(METADATA_SERVICE_VERSION_NAME); + url = url.putAttribute(METADATA_SERVICE_VERSION_NAME, version); - Protocol protocol = applicationModel.getExtensionLoader(Protocol.class).getExtension(url.getProtocol(), false); - - url = url.setServiceModel(consumerModel); - - if (NativeDetector.inNativeImage()) { - url = url.addParameter("proxy", "jdk"); - } - - Invoker invoker = protocol.refer(MetadataService.class, url); - - ProxyFactory proxyFactory = - applicationModel.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); - - MetadataService metadataService = proxyFactory.getProxy(invoker); - - consumerModel.getServiceMetadata().setTarget(metadataService); - consumerModel.getServiceMetadata().addAttribute(PROXY_CLASS_REF, metadataService); - consumerModel.setProxyObject(metadataService); - consumerModel.initMethodModels(); - - return new ProxyHolder(consumerModel, metadataService, internalModel); + return url; } public static MetadataInfo getRemoteMetadata( @@ -179,14 +228,13 @@ public class MetadataUtils { metadataInfo = MetadataUtils.getMetadata(revision, instance, metadataReport); } else { // change the instance used to communicate to avoid all requests route to the same instance - ProxyHolder proxyHolder = null; + RemoteMetadataService remoteMetadataService = null; try { - proxyHolder = MetadataUtils.referProxy(instance); - metadataInfo = proxyHolder - .getProxy() - .getMetadataInfo(ServiceInstanceMetadataUtils.getExportedServicesRevision(instance)); + remoteMetadataService = MetadataUtils.referMetadataService(instance); + metadataInfo = remoteMetadataService.getRemoteMetadata( + ServiceInstanceMetadataUtils.getExportedServicesRevision(instance)); } finally { - MetadataUtils.destroyProxy(proxyHolder); + MetadataUtils.destroyProxy(remoteMetadataService); } } } catch (Exception e) { @@ -206,9 +254,9 @@ public class MetadataUtils { return metadataInfo; } - public static void destroyProxy(ProxyHolder proxyHolder) { - if (proxyHolder != null) { - proxyHolder.destroy(); + public static void destroyProxy(RemoteMetadataService remoteMetadataService) { + if (remoteMetadataService != null) { + remoteMetadataService.destroy(); } } @@ -242,21 +290,38 @@ public class MetadataUtils { return instances.get(ThreadLocalRandom.current().nextInt(0, instances.size())); } - public static class ProxyHolder { + public static class RemoteMetadataService { private final ConsumerModel consumerModel; - private final MetadataService proxy; + + @Deprecated + private MetadataService proxy; + + private MetadataServiceV2 proxyV2; + private final ModuleModel internalModel; - public ProxyHolder(ConsumerModel consumerModel, MetadataService proxy, ModuleModel internalModel) { + public RemoteMetadataService(ConsumerModel consumerModel, MetadataService proxy, ModuleModel internalModel) { this.consumerModel = consumerModel; this.proxy = proxy; this.internalModel = internalModel; } + public RemoteMetadataService( + ConsumerModel consumerModel, MetadataServiceV2 proxyV2, ModuleModel internalModel) { + this.consumerModel = consumerModel; + this.proxyV2 = proxyV2; + this.internalModel = internalModel; + } + public void destroy() { if (proxy instanceof Destroyable) { ((Destroyable) proxy).$destroy(); } + + if (proxyV2 instanceof Destroyable) { + ((Destroyable) proxyV2).$destroy(); + } + internalModel.getServiceRepository().unregisterConsumer(consumerModel); } @@ -264,12 +329,23 @@ public class MetadataUtils { return consumerModel; } - public MetadataService getProxy() { - return proxy; + public Object getInternalProxy() { + return proxy == null ? proxyV2 : proxy; } public ModuleModel getInternalModel() { return internalModel; } + + public MetadataInfo getRemoteMetadata(String revision) { + Object existProxy = getInternalProxy(); + if (existProxy instanceof MetadataService) { + return ((MetadataService) existProxy).getMetadataInfo(revision); + } else { + return MetadataServiceVersionUtils.toV1(((MetadataServiceV2) existProxy) + .getMetadataInfo( + Revision.newBuilder().setValue(revision).build())); + } + } } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java index bc26aad59f..ac10fd5835 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java @@ -96,6 +96,8 @@ public class ServiceInstanceMetadataUtils { */ public static final String METADATA_STORAGE_TYPE_PROPERTY_NAME = "dubbo.metadata.storage-type"; + public static final String METADATA_SERVICE_VERSION_NAME = "meta-v"; + public static final String METADATA_CLUSTER_PROPERTY_NAME = "dubbo.metadata.cluster"; public static String getMetadataServiceParameter(URL url) {