diff --git a/dubbo-all/pom.xml b/dubbo-all/pom.xml index eaf17722461..8b9a4c53c9d 100644 --- a/dubbo-all/pom.xml +++ b/dubbo-all/pom.xml @@ -408,13 +408,6 @@ compile true - - org.apache.dubbo - dubbo-configcenter-api - ${project.version} - compile - true - org.apache.dubbo dubbo-configcenter-zookeeper @@ -466,7 +459,7 @@ org.apache.dubbo - dubbo-metadata-report-api + dubbo-metadata-api ${project.version} compile true @@ -516,14 +509,6 @@ true - - org.apache.dubbo - dubbo-metadata - ${project.version} - compile - true - - org.springframework @@ -640,15 +625,13 @@ org.apache.dubbo:dubbo-serialization-protostuff org.apache.dubbo:dubbo-serialization-gson org.apache.dubbo:dubbo-serialization-googlePb - org.apache.dubbo:dubbo-configcenter-api org.apache.dubbo:dubbo-configcenter-definition org.apache.dubbo:dubbo-configcenter-apollo org.apache.dubbo:dubbo-configcenter-zookeeper org.apache.dubbo:dubbo-configcenter-consul org.apache.dubbo:dubbo-configcenter-etcd org.apache.dubbo:dubbo-configcenter-nacos - org.apache.dubbo:dubbo-metadata-report-api - org.apache.dubbo:dubbo-metadata-definition + org.apache.dubbo:dubbo-metadata-api org.apache.dubbo:dubbo-metadata-report-redis org.apache.dubbo:dubbo-metadata-report-zookeeper org.apache.dubbo:dubbo-metadata-report-consul @@ -656,10 +639,7 @@ org.apache.dubbo:dubbo-metadata-report-nacos org.apache.dubbo:dubbo-serialization-native-hession org.apache.dubbo:dubbo-rpc-native-thrift - - org.apache.dubbo:dubbo-event - org.apache.dubbo:dubbo-metadata @@ -778,11 +758,11 @@ - META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory + META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory - META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory + META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory @@ -795,7 +775,19 @@ - META-INF/dubbo/internal/org.apache.dubbo.metadata.LocalMetadataService + META-INF/dubbo/internal/org.apache.dubbo.metadata.WritableMetadataService + + + + META-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping + + + + META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.MetadataServiceProxyFactory + + + + META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory diff --git a/dubbo-bom/pom.xml b/dubbo-bom/pom.xml index 8b69673ec9f..202af02701f 100644 --- a/dubbo-bom/pom.xml +++ b/dubbo-bom/pom.xml @@ -362,11 +362,22 @@ dubbo-compatible ${project.version} + + + org.apache.dubbo + dubbo-metadata-api + ${project.version} + org.apache.dubbo dubbo-metadata-report-api ${project.version} + + org.apache.dubbo + dubbo-metadata-definition + ${project.version} + org.apache.dubbo dubbo-metadata-report-zookeeper @@ -392,11 +403,8 @@ dubbo-metadata-report-nacos ${project.version} - - org.apache.dubbo - dubbo-configcenter-api - ${project.version} - + + org.apache.dubbo dubbo-configcenter-zookeeper @@ -422,11 +430,6 @@ dubbo-configcenter-nacos ${project.version} - - org.apache.dubbo - dubbo-metadata-definition - ${project.version} - diff --git a/dubbo-bootstrap/pom.xml b/dubbo-bootstrap/pom.xml index ef3cad3f05f..17df1344efa 100644 --- a/dubbo-bootstrap/pom.xml +++ b/dubbo-bootstrap/pom.xml @@ -34,6 +34,13 @@ test + + org.apache.dubbo + dubbo-metadata-report-zookeeper + ${project.parent.version} + test + + org.apache.dubbo dubbo-configcenter-zookeeper @@ -83,12 +90,6 @@ test - - org.apache.curator - curator-test - test - - \ No newline at end of file diff --git a/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java b/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java index c6c26062b64..1273dcfc74c 100644 --- a/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java +++ b/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java @@ -17,19 +17,32 @@ package org.apache.dubbo.bootstrap; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.Environment; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory; +import org.apache.dubbo.common.config.configcenter.wrapper.CompositeDynamicConfiguration; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.AbstractConfig; -import org.apache.dubbo.config.AbstractInterfaceConfig; import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ConfigCenterConfig; +import org.apache.dubbo.config.ConsumerConfig; +import org.apache.dubbo.config.DubboShutdownHook; +import org.apache.dubbo.config.MetadataReportConfig; import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.ProviderConfig; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.builders.AbstractBuilder; import org.apache.dubbo.config.builders.ApplicationBuilder; +import org.apache.dubbo.config.builders.ConsumerBuilder; import org.apache.dubbo.config.builders.ProtocolBuilder; +import org.apache.dubbo.config.builders.ProviderBuilder; import org.apache.dubbo.config.builders.ReferenceBuilder; import org.apache.dubbo.config.builders.RegistryBuilder; import org.apache.dubbo.config.builders.ServiceBuilder; @@ -37,16 +50,19 @@ import org.apache.dubbo.config.metadata.ConfigurableMetadataServiceExporter; import org.apache.dubbo.event.EventDispatcher; import org.apache.dubbo.event.EventListener; -import org.apache.dubbo.metadata.MetadataServiceExporter; +import org.apache.dubbo.metadata.WritableMetadataService; +import org.apache.dubbo.metadata.store.RemoteWritableMetadataService; import org.apache.dubbo.registry.client.DefaultServiceInstance; import org.apache.dubbo.registry.client.ServiceDiscovery; import org.apache.dubbo.registry.client.ServiceInstance; import org.apache.dubbo.registry.support.ServiceOrientedRegistry; +import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.Condition; @@ -55,12 +71,9 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -import static java.util.Collections.emptyMap; import static java.util.concurrent.Executors.newSingleThreadExecutor; +import static org.apache.dubbo.common.config.ConfigurationUtils.parseProperties; import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; -import static org.apache.dubbo.common.utils.StringUtils.isBlank; -import static org.apache.dubbo.common.utils.StringUtils.split; -import static org.apache.dubbo.common.utils.StringUtils.trim; import static org.apache.dubbo.registry.support.AbstractRegistryFactory.getRegistries; /** @@ -82,8 +95,6 @@ public class DubboBootstrap { private final Logger logger = LoggerFactory.getLogger(getClass()); - private final MetadataServiceExporter metadataServiceExporter = new ConfigurableMetadataServiceExporter(); - private final AtomicBoolean awaited = new AtomicBoolean(false); private final Lock lock = new ReentrantLock(); @@ -112,6 +123,10 @@ public class DubboBootstrap { private ApplicationBuilder applicationBuilder; + private ConsumerBuilder consumerBuilder; + + private ProviderBuilder providerBuilder; + private Map registryBuilders = new HashMap<>(); private Map protocolBuilders = new HashMap<>(); @@ -120,70 +135,88 @@ public class DubboBootstrap { private Map> referenceBuilders = new HashMap<>(); - /** - * The global {@link ApplicationConfig} - */ - private ApplicationConfig applicationConfig; + public DubboBootstrap() { + DubboShutdownHook.getDubboShutdownHook().register(); + } /** - * the global {@link RegistryConfig registries} + * Set only register provider or not + * + * @param onlyRegisterProvider if true, only register the provider and reduce the registries' load. + * @return {@link DubboBootstrap} */ - private Map registryConfigs = emptyMap(); + public DubboBootstrap onlyRegisterProvider(boolean onlyRegisterProvider) { + this.onlyRegisterProvider = onlyRegisterProvider; + return this; + } - /** - * the global {@link RegistryConfig registries} - */ - private Map protocolConfigs = emptyMap(); + /* accept Config instance */ + public DubboBootstrap application(ApplicationConfig applicationConfig) { + ConfigManager.getInstance().setApplication(applicationConfig); + return this; + } - /** - * the global {@link ServiceConfig services} - */ - private Map> serviceConfigs = emptyMap(); + public DubboBootstrap configCenter(ConfigCenterConfig configCenterConfig) { + ConfigManager.getInstance().addConfigCenter(configCenterConfig); + return this; + } - /** - * the global {@link ReferenceConfig references} - */ - private Map> referenceConfigs = new HashMap<>(); + public DubboBootstrap configCenter(List configCenterConfigs) { + ConfigManager.getInstance().addConfigCenter(configCenterConfigs); + return this; + } + + public DubboBootstrap metadataReport(MetadataReportConfig metadataReportConfig) { + ConfigManager.getInstance().addMetadataReport(metadataReportConfig); + return this; + } - public ApplicationSettings application(String name) { - return new ApplicationSettings(initApplicationBuilder(name), this); + public DubboBootstrap metadataReport(List metadataReportConfigs) { + ConfigManager.getInstance().addMetadataReport(metadataReportConfigs); + return this; } - public RegistrySettings registry() { - return registry(DEFAULT_REGISTRY_ID); + public DubboBootstrap registry(RegistryConfig registryConfig) { + ConfigManager.getInstance().addRegistry(registryConfig, true); + return this; } - public RegistrySettings registry(String id) { - return new RegistrySettings(initRegistryBuilder(id), this); + public DubboBootstrap registry(List registryConfigs) { + ConfigManager.getInstance().addRegistries(registryConfigs, true); + return this; } - public ProtocolSettings protocol() { - return protocol(DEFAULT_PROTOCOL_ID); + public DubboBootstrap protocol(ProtocolConfig protocolConfig) { + ConfigManager.getInstance().addProtocol(protocolConfig, true); + return this; } - public ProtocolSettings protocol(String id) { - return new ProtocolSettings(initProtocolBuilder(id), this); + public DubboBootstrap protocols(List protocolConfigs) { + ConfigManager.getInstance().addProtocols(protocolConfigs, true); + return this; } - public ServiceSettings service(String id) { - return new ServiceSettings(initServiceBuilder(id), this); + public DubboBootstrap consumer(ConsumerConfig consumerConfig) { + ConfigManager.getInstance().addConsumer(consumerConfig); + return this; } - public ReferenceSettings reference(String id) { - return new ReferenceSettings<>(initReferenceBuilder(id), this); + public DubboBootstrap provider(ProviderConfig providerConfig) { + ConfigManager.getInstance().addProvider(providerConfig); + return this; } - /** - * Set only register provider or not - * - * @param onlyRegisterProvider if true, only register the provider and reduce the registries' load. - * @return {@link DubboBootstrap} - */ - public DubboBootstrap onlyRegisterProvider(boolean onlyRegisterProvider) { - this.onlyRegisterProvider = onlyRegisterProvider; + public DubboBootstrap service(ServiceConfig serviceConfig) { + ConfigManager.getInstance().addService(serviceConfig); return this; } + public DubboBootstrap reference(ReferenceConfig referenceConfig) { + ConfigManager.getInstance().addReference(referenceConfig); + return this; + } + + /* accept builder functional interface */ public DubboBootstrap application(String name, Consumer builder) { initApplicationBuilder(name); builder.accept(applicationBuilder); @@ -219,18 +252,31 @@ public void init() { return; } - initApplicationConfig(); + buildApplicationConfig(); - initRegistryConfigs(); + buildRegistryConfigs(); - initProtocolConfigs(); + buildProtocolConfigs(); - initServiceConfigs(); + buildServiceConfigs(); - initReferenceConfigs(); + buildReferenceConfigs(); clearBuilders(); + startConfigCenter(); + startMetadataReport(); + + loadRemoteConfigs(); + useRegistryAsConfigCenterIfNecessary(); + +// checkApplication(); +// checkProvider(); +// chcckConsumer(); +// checkRegistry(); +// checkProtocol(); +// checkMonitor(); + initialized = true; if (logger.isInfoEnabled()) { @@ -238,26 +284,67 @@ public void init() { } } - /** - * Get the {@link ServiceConfig} by specified id - * - * @param id The {@link ServiceConfig#getId() id} of {@link ServiceConfig} - * @param the type of service interface - * @return null if not found - */ - public ServiceConfig serviceConfig(String id) { - return (ServiceConfig) serviceConfigs.get(id); + private void loadRemoteConfigs() { + ConfigManager configManager = ConfigManager.getInstance(); + + // registry ids to registry configs + List tmpRegistries = new ArrayList<>(); + Set registryIds = configManager.getRegistryIds(); + registryIds.forEach(id -> { + if (tmpRegistries.stream().noneMatch(reg -> reg.getId().equals(id))) { + tmpRegistries.add(configManager.getRegistry(id).orElseGet(() -> { + RegistryConfig registryConfig = new RegistryConfig(); + registryConfig.setId(id); + registryConfig.refresh(); + return registryConfig; + })); + } + }); + + configManager.addRegistries(tmpRegistries, true); + + // protocol ids to protocol configs + List tmpProtocols = new ArrayList<>(); + Set protocolIds = configManager.getProtocolIds(); + protocolIds.forEach(id -> { + if (tmpProtocols.stream().noneMatch(prot -> prot.getId().equals(id))) { + tmpProtocols.add(configManager.getProtocol(id).orElseGet(() -> { + ProtocolConfig protocolConfig = new ProtocolConfig(); + protocolConfig.setId(id); + protocolConfig.refresh(); + return protocolConfig; + })); + } + }); + + configManager.addProtocols(tmpProtocols, true); } /** - * Get the {@link ReferenceConfig} by specified id - * - * @param id The {@link ReferenceConfig#getId() id} of {@link ReferenceConfig} - * @param the type of service interface - * @return null if not found + * For compatibility purpose, use registry as the default config center when the registry protocol is zookeeper and + * there's no config center specified explicitly. */ - public ReferenceConfig referenceConfig(String id) { - return (ReferenceConfig) referenceConfigs.get(id); + private void useRegistryAsConfigCenterIfNecessary() { + ConfigManager configManager = ConfigManager.getInstance(); + configManager.getDefaultRegistries().ifPresent(registryConfigs -> { + for (RegistryConfig registryConfig : registryConfigs) { + if (registryConfig != null && registryConfig.isZookeeperProtocol()) { + // we use the loading status of DynamicConfiguration to decide whether ConfigCenter has been initiated. + Environment.getInstance().getDynamicConfiguration().orElseGet(() -> { + Set configCenters = configManager.getConfigCenters(); + if (CollectionUtils.isEmpty(configCenters)) { + ConfigCenterConfig cc = new ConfigCenterConfig(); + cc.setProtocol(registryConfig.getProtocol()); + cc.setAddress(registryConfig.getAddress()); + cc.setHighestPriority(false); + configManager.addConfigCenter(cc); + } + return null; + }); + } + } + startConfigCenter(); + }); } private List getServiceDiscoveries() { @@ -282,11 +369,17 @@ public DubboBootstrap start() { exportServices(); // Not only provider register and some services are exported - if (!onlyRegisterProvider && !serviceConfigs.isEmpty()) { + if (!onlyRegisterProvider && !ConfigManager.getInstance().getServiceConfigs().isEmpty()) { /** * export {@link MetadataService} */ - List exportedURLs = exportMetadataService(applicationConfig, registryConfigs, protocolConfigs); + ConfigManager configManager = ConfigManager.getInstance(); + // TODO, only export to default registry? + List exportedURLs = exportMetadataService ( + configManager.getApplication().orElseThrow(() -> new IllegalStateException("ApplicationConfig cannot be null")), + configManager.getDefaultRegistries().orElseThrow(() -> new IllegalStateException("No default RegistryConfig")), + configManager.getDefaultProtocols().orElseThrow(() -> new IllegalStateException("No default ProtocolConfig")) + ); /** * Register the local {@link ServiceInstance} @@ -357,6 +450,7 @@ public boolean isStarted() { return started; } + /* serve for builder apis, begin */ private ApplicationBuilder initApplicationBuilder(String name) { applicationBuilder = new ApplicationBuilder().name(name); return applicationBuilder; @@ -394,21 +488,76 @@ private ReferenceBuilder initReferenceBuilder(String id) { return referenceBuilders.computeIfAbsent(id, this::createReferenceBuilder); } - private void initApplicationConfig() { - this.applicationConfig = buildApplicationConfig(); + /* serve for builder apis, end */ + + private void startMetadataReport() { + ApplicationConfig applicationConfig = ConfigManager.getInstance().getApplication().orElseThrow(() -> new IllegalStateException("There's no ApplicationConfig specified.")); + + // FIXME, multiple metadata config support. + Set metadataReportConfigs = ConfigManager.getInstance().getMetadataConfigs(); + if (CollectionUtils.isEmpty(metadataReportConfigs)) { + if (CommonConstants.METADATA_REMOTE.equals(applicationConfig.getMetadata())) { + throw new IllegalStateException("No MetadataConfig found, you must specify the remote Metadata Center address when set 'metadata=remote'."); + } + return; + } + MetadataReportConfig metadataReportConfig = metadataReportConfigs.iterator().next(); + if (!metadataReportConfig.isValid()) { + return; + } + + RemoteWritableMetadataService remoteMetadataService = + (RemoteWritableMetadataService) WritableMetadataService.getExtension(applicationConfig.getMetadata()); + remoteMetadataService.initMetadataReport(metadataReportConfig.toUrl()); } - private void initRegistryConfigs() { - this.registryConfigs = buildRegistryConfigs(); + private void startConfigCenter() { + Set configCenters = ConfigManager.getInstance().getConfigCenters(); + + if (CollectionUtils.isNotEmpty(configCenters)) { + CompositeDynamicConfiguration compositeDynamicConfiguration = new CompositeDynamicConfiguration(); + for (ConfigCenterConfig configCenter : configCenters) { + configCenter.refresh(); + compositeDynamicConfiguration.addConfiguration(prepareEnvironment(configCenter)); + } + Environment.getInstance().setDynamicConfiguration(compositeDynamicConfiguration); + } + ConfigManager.getInstance().refreshAll(); } - private void initProtocolConfigs() { - this.protocolConfigs = buildProtocolConfigs(); + private DynamicConfiguration prepareEnvironment(ConfigCenterConfig configCenter) { + if (configCenter.isValid()) { + if (!configCenter.checkOrUpdateInited()) { + return null; + } + DynamicConfiguration dynamicConfiguration = getDynamicConfiguration(configCenter.toUrl()); + String configContent = dynamicConfiguration.getConfigs(configCenter.getConfigFile(), configCenter.getGroup()); + + String appGroup = ConfigManager.getInstance().getApplication().orElse(new ApplicationConfig()).getName(); + String appConfigContent = null; + if (StringUtils.isNotEmpty(appGroup)) { + appConfigContent = dynamicConfiguration.getConfigs + (StringUtils.isNotEmpty(configCenter.getAppConfigFile()) ? configCenter.getAppConfigFile() : configCenter.getConfigFile(), + appGroup + ); + } + try { + Environment.getInstance().setConfigCenterFirst(configCenter.isHighestPriority()); + Environment.getInstance().updateExternalConfigurationMap(parseProperties(configContent)); + Environment.getInstance().updateAppExternalConfigurationMap(parseProperties(appConfigContent)); + } catch (IOException e) { + throw new IllegalStateException("Failed to parse configurations from Config Center.", e); + } + return dynamicConfiguration; + } + return null; } - private void initReferenceConfigs() { - this.referenceConfigs = buildReferenceConfigs(); - this.referenceConfigs.values().forEach(this::initReferenceConfig); + private DynamicConfiguration getDynamicConfiguration(URL url) { + DynamicConfigurationFactory factory = ExtensionLoader + .getExtensionLoader(DynamicConfigurationFactory.class) + .getExtension(url.getProtocol()); + return factory.getDynamicConfiguration(url); } /** @@ -422,103 +571,49 @@ public DubboBootstrap addEventListener(EventListener listener) { return this; } - private void initServiceConfigs() { - this.serviceConfigs = buildServiceConfigs(); - this.serviceConfigs.values().forEach(this::initServiceConfig); - } - private List exportMetadataService(ApplicationConfig applicationConfig, - Map globalRegistryConfigs, - Map globalProtocolConfigs) { + List globalRegistryConfigs, + List globalProtocolConfigs) { ConfigurableMetadataServiceExporter exporter = new ConfigurableMetadataServiceExporter(); exporter.setApplicationConfig(applicationConfig); - exporter.setRegistries(globalRegistryConfigs.values()); - exporter.setProtocols(globalProtocolConfigs.values()); + exporter.setRegistries(globalRegistryConfigs); + exporter.setProtocols(globalProtocolConfigs); return exporter.export(); } - private ApplicationConfig buildApplicationConfig() { - return applicationBuilder.build(); + private void buildApplicationConfig() { + ApplicationConfig applicationConfig = null; + if (applicationBuilder != null) { + applicationConfig = applicationBuilder.build(); + } + ConfigManager.getInstance().setApplication(applicationConfig); } - private Map buildProtocolConfigs() { - return buildConfigs(protocolBuilders); + private void buildProtocolConfigs() { + List protocolConfigs = buildConfigs(protocolBuilders); + ConfigManager.getInstance().addProtocols(protocolConfigs, true); } - private Map buildRegistryConfigs() { - return buildConfigs(registryBuilders); + private void buildRegistryConfigs() { + List registryConfigs = buildConfigs(registryBuilders); + ConfigManager.getInstance().addRegistries(registryConfigs, true); } - private Map> buildServiceConfigs() { - return buildConfigs(serviceBuilders); + private void buildServiceConfigs() { + List> serviceConfigs = buildConfigs(serviceBuilders); + serviceConfigs.forEach(ConfigManager.getInstance()::addService); } - private Map> buildReferenceConfigs() { - return buildConfigs(referenceBuilders); + private void buildReferenceConfigs() { + List> referenceConfigs = buildConfigs(referenceBuilders); + referenceConfigs.forEach(ConfigManager.getInstance()::addReference); } private void exportServices() { - serviceConfigs.values().forEach(this::exportServiceConfig); - } - - private void initServiceConfig(ServiceConfig serviceConfig) { - initConfig(serviceConfig); - initProtocols(serviceConfig); - } - - private void initReferenceConfig(ReferenceConfig referenceConfig) { - initConfig(referenceConfig); - } - - private void initConfig(AbstractInterfaceConfig config) { - initApplication(config); - initRegistries(config); + ConfigManager.getInstance().getServiceConfigs().forEach(this::exportServiceConfig); } - private void initApplication(AbstractInterfaceConfig config) { - if (config.getApplication() == null) { - config.setApplication(applicationConfig); - } - } - - private void initRegistries(AbstractInterfaceConfig config) { - List registries = config.getRegistries(); - if (CollectionUtils.isEmpty(registries)) { // If no registry present - registries = new LinkedList<>(); - String registerIds = config.getRegistryIds(); - if (!isBlank(registerIds)) { - for (String id : split(registerIds, ',')) { - RegistryConfig registryConfig = registryConfigs.get(trim(id)); - registries.add(registryConfig); - } - } - if (registries.isEmpty()) { // If empty, add all global registries - registries.addAll(registryConfigs.values()); - } - - config.setRegistries(registries); - } - } - - private void initProtocols(ServiceConfig serviceConfig) { - List protocols = serviceConfig.getProtocols(); - if (CollectionUtils.isEmpty(protocols)) { // If no protocols present - protocols = new LinkedList<>(); - String protocolIds = serviceConfig.getProtocolIds(); - if (!isBlank(protocolIds)) { - for (String id : split(protocolIds, ',')) { - ProtocolConfig protocol = protocolConfigs.get(trim(id)); - protocols.add(protocol); - } - } - if (protocols.isEmpty()) { // If empty, add all global protocols - protocols.addAll(protocolConfigs.values()); - } - serviceConfig.setProtocols(protocols); - } - } - - private void exportServiceConfig(ServiceConfig serviceConfig) { + public void exportServiceConfig(ServiceConfig serviceConfig) { serviceConfig.export(); } @@ -563,14 +658,14 @@ private void destroy() { } private void destroyProtocolConfigs() { - protocolConfigs.values().forEach(ProtocolConfig::destroy); + ConfigManager.getInstance().getProtocols().values().forEach(ProtocolConfig::destroy); if (logger.isDebugEnabled()) { logger.debug(NAME + "'s all ProtocolConfigs have been destroyed."); } } private void destroyReferenceConfigs() { - referenceConfigs.values().forEach(ReferenceConfig::destroy); + ConfigManager.getInstance().getReferenceConfigs().forEach(ReferenceConfig::destroy); if (logger.isDebugEnabled()) { logger.debug(NAME + "'s all ReferenceConfigs have been destroyed."); } @@ -586,11 +681,7 @@ private void clear() { } private void clearConfigs() { - this.applicationConfig = null; - this.registryConfigs.clear(); - this.protocolConfigs.clear(); - this.serviceConfigs.clear(); - this.referenceConfigs.clear(); + ConfigManager.getInstance().clear(); if (logger.isDebugEnabled()) { logger.debug(NAME + "'s configs have been clear."); } @@ -634,10 +725,10 @@ private void executeMutually(Runnable runnable) { } } - private static Map buildConfigs(Map map) { - Map configs = new HashMap<>(); + private static List buildConfigs(Map map) { + List configs = new ArrayList<>(); map.entrySet().forEach(entry -> { - configs.put(entry.getKey(), (C) entry.getValue().build()); + configs.add((C) entry.getValue().build()); }); return configs; } diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboBootstrapTest.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboBootstrapTest.java index b9acd2961f2..302980a00fe 100644 --- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboBootstrapTest.java +++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboBootstrapTest.java @@ -16,11 +16,11 @@ */ package org.apache.dubbo.bootstrap; -import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.config.builders.ApplicationBuilder; +import org.apache.dubbo.config.builders.ProtocolBuilder; +import org.apache.dubbo.config.builders.RegistryBuilder; +import org.apache.dubbo.config.builders.ServiceBuilder; -import org.apache.curator.test.TestingServer; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -32,65 +32,17 @@ */ public class DubboBootstrapTest { - private static int zkServerPort = NetUtils.getAvailablePort(); - - private static TestingServer zkServer; - - - @BeforeAll - public static void init() throws Exception { - zkServer = new TestingServer(zkServerPort, true); - } - - @AfterAll - public static void destroy() throws IOException { - zkServer.stop(); - zkServer.close(); - } - @Test - public void testProviderInFluentAPI() { + public void test() throws IOException { new DubboBootstrap() - .application("dubbo-provider-demo") - .next() - .registry() - .address("zookeeper://127.0.0.1:" + zkServerPort + "?registry-type=service") - .next() - .protocol() - .name("dubbo") - .port(-1) - .next() - .service("test") - .interfaceClass(EchoService.class) - .ref(new EchoServiceImpl()) - .group("DEFAULT") - .version("1.0.0") - .next() + .application(ApplicationBuilder.newBuilder().name("dubbo-provider-demo").build()) + .registry(RegistryBuilder.newBuilder().address("zookeeper://127.0.0.1:2181?registry-type=service&metadata=remote").build()) + .protocol(ProtocolBuilder.newBuilder().port(-1).name("dubbo").build()) + .service(ServiceBuilder.newBuilder().id("test").interfaceClass(EchoService.class).ref(new EchoServiceImpl()).build()) .start() - .stop(); - - } + .await(); - @Test - public void testProviderInLambda() { - new DubboBootstrap() - .application("dubbo-provider-demo", builder -> { - }) - .registry("default", builder -> - builder.address("zookeeper://127.0.0.1:" + zkServerPort + "?registry-type=service") - ) - .protocol("defalt", builder -> - builder.name("dubbo") - .port(-1) - ) - .service("test", builder -> - builder.interfaceClass(EchoService.class) - .ref(new EchoServiceImpl()) - .group("DEFAULT") - .version("1.0.0") - ) - .start() - .stop(); + System.in.read(); } } diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java index 800f29de6e8..ef1efd350d9 100644 --- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java +++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java @@ -16,10 +16,9 @@ */ package org.apache.dubbo.bootstrap; -import org.apache.dubbo.config.ReferenceConfig; - -import static org.apache.dubbo.bootstrap.EchoService.GROUP; -import static org.apache.dubbo.bootstrap.EchoService.VERSION; +import org.apache.dubbo.config.builders.ApplicationBuilder; +import org.apache.dubbo.config.builders.ReferenceBuilder; +import org.apache.dubbo.config.builders.RegistryBuilder; /** * Dubbo Provider Bootstrap @@ -31,28 +30,22 @@ public class DubboServiceConsumerBootstrap { public static void main(String[] args) throws Exception { DubboBootstrap bootstrap = new DubboBootstrap() - .application("dubbo-consumer-demo") - .next() - .registry() - .address("nacos://127.0.0.1:8848?registry-type=service&subscribed-services=dubbo-provider-demo") - .next() - .reference("ref") - .interfaceClass(EchoService.class) - .group(GROUP) - .version(VERSION) - .next() + .application(ApplicationBuilder.newBuilder().name("dubbo-consumer-demo").build()) + .registry(RegistryBuilder.newBuilder().address("zookeeper://127.0.0.1:2181?registry-type=service&subscribed-services=dubbo-provider-demo&metadata=remote").build()) + .reference(ReferenceBuilder.newBuilder().id("ref").interfaceClass(EchoService.class).build()) .onlyRegisterProvider(true) .start() .await(); - ReferenceConfig referenceConfig = bootstrap.referenceConfig("ref"); - - EchoService echoService = referenceConfig.get(); - - for (int i = 0; i < 500; i++) { - Thread.sleep(2000L); - System.out.println(echoService.echo("Hello,World")); - } + // TODO, +// ReferenceConfig referenceConfig = ReferenceConfigCache.getCache().get(EchoService.class.getName(), EchoService.class); +// +// EchoService echoService = referenceConfig.get(); +// +// for (int i = 0; i < 500; i++) { +// Thread.sleep(2000L); +// System.out.println(echoService.echo("Hello,World")); +// } } } diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java index bb149ad7a5e..45ceed6965d 100644 --- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java +++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java @@ -16,10 +16,13 @@ */ package org.apache.dubbo.bootstrap; -import java.io.IOException; +import org.apache.dubbo.config.builders.ApplicationBuilder; +import org.apache.dubbo.config.builders.MetadataReportBuilder; +import org.apache.dubbo.config.builders.ProtocolBuilder; +import org.apache.dubbo.config.builders.RegistryBuilder; +import org.apache.dubbo.config.builders.ServiceBuilder; -import static org.apache.dubbo.bootstrap.EchoService.GROUP; -import static org.apache.dubbo.bootstrap.EchoService.VERSION; +import java.io.IOException; /** * Dubbo Provider Bootstrap @@ -31,21 +34,12 @@ public class DubboServiceProviderBootstrap { public static void main(String[] args) throws IOException { new DubboBootstrap() - .application("dubbo-provider-demo") - .next() - .registry() - .address("nacos://127.0.0.1:8848?registry-type=service") - .next() - .protocol() - .name("dubbo") - .port(-1) - .next() - .service("test") - .interfaceClass(EchoService.class) - .ref(new EchoServiceImpl()) - .group(GROUP) - .version(VERSION) - .next() + .application(ApplicationBuilder.newBuilder().name("dubbo-provider-demo").metadata("remote").build()) + .metadataReport(MetadataReportBuilder.newBuilder().address("zookeeper://127.0.0.1:2181").build()) +// .application(ApplicationBuilder.newBuilder().name("dubbo-provider-demo").build()) + .registry(RegistryBuilder.newBuilder().address("zookeeper://127.0.0.1:2181?registry-type=service").build()) + .protocol(ProtocolBuilder.newBuilder().port(-1).name("dubbo").build()) + .service(ServiceBuilder.newBuilder().id("test").interfaceClass(EchoService.class).ref(new EchoServiceImpl()).build()) .start() .await(); } diff --git a/dubbo-cluster/pom.xml b/dubbo-cluster/pom.xml index ff59682d847..864e7ccc77e 100644 --- a/dubbo-cluster/pom.xml +++ b/dubbo-cluster/pom.xml @@ -34,11 +34,6 @@ dubbo-rpc-api ${project.parent.version} - - org.apache.dubbo - dubbo-configcenter-api - ${project.parent.version} - org.yaml snakeyaml diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Directory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Directory.java index 67f021659e7..a03a78162b7 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Directory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Directory.java @@ -46,4 +46,6 @@ public interface Directory extends Node { */ List> list(Invocation invocation) throws RpcException; + List> getAllInvokers(); + } \ No newline at end of file diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java index c5a26a3f7d3..0595c6366ef 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java @@ -61,6 +61,11 @@ public Class getInterface() { return invokers.get(0).getInterface(); } + @Override + public List> getAllInvokers() { + return invokers; + } + @Override public boolean isAvailable() { if (isDestroyed()) { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java index 657ad866c28..b848cb1edb5 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java @@ -17,7 +17,7 @@ package org.apache.dubbo.rpc.cluster.router; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.rpc.cluster.Router; public abstract class AbstractRouter implements Router { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouter.java index b334e377bb1..852da6be5de 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouter.java @@ -17,8 +17,8 @@ package org.apache.dubbo.rpc.cluster.router.condition.config; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.configcenter.DynamicConfiguration; /** * Application level router, "application.condition-router" diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouterFactory.java index 066f865b65f..067a5232086 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouterFactory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouterFactory.java @@ -17,8 +17,8 @@ package org.apache.dubbo.rpc.cluster.router.condition.config; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.rpc.cluster.Router; import org.apache.dubbo.rpc.cluster.RouterFactory; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java index 564f371eac0..5931e850f00 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java @@ -17,14 +17,14 @@ package org.apache.dubbo.rpc.cluster.router.condition.config; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigChangeType; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigChangeType; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ServiceRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ServiceRouter.java index ed3748e0fd5..1bdf2612f95 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ServiceRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ServiceRouter.java @@ -17,7 +17,7 @@ package org.apache.dubbo.rpc.cluster.router.condition.config; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; /** * Service level router, "server-unique-name.condition-router" diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ServiceRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ServiceRouterFactory.java index 18d4a1dd3e8..12911ac4406 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ServiceRouterFactory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ServiceRouterFactory.java @@ -17,8 +17,8 @@ package org.apache.dubbo.rpc.cluster.router.condition.config; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.rpc.cluster.CacheableRouterFactory; import org.apache.dubbo.rpc.cluster.Router; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java index c6387fe3fc5..d33d103d964 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -17,16 +17,16 @@ package org.apache.dubbo.rpc.cluster.router.tag; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigChangeType; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigChangeType; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; @@ -40,8 +40,8 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -import static org.apache.dubbo.rpc.cluster.Constants.TAG_KEY; import static org.apache.dubbo.rpc.Constants.FORCE_USE_TAG; +import static org.apache.dubbo.rpc.cluster.Constants.TAG_KEY; /** * TagRouter, "application.tag-router" diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java index 7d3e013123f..0df085d6264 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java @@ -17,8 +17,8 @@ package org.apache.dubbo.rpc.cluster.router.tag; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.rpc.cluster.CacheableRouterFactory; import org.apache.dubbo.rpc.cluster.Router; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java index db2d401eba9..61ef95596ab 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java @@ -94,6 +94,10 @@ public boolean isAvailable() { return directory.isAvailable(); } + public Directory getDirectory() { + return directory; + } + @Override public void destroy() { if (destroyed.compareAndSet(false, true)) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java index 2da28183504..cf335b49826 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java @@ -155,7 +155,7 @@ public static Proxy getProxy(ClassLoader cl, Class... ics) { for (Method method : ics[i].getMethods()) { String desc = ReflectUtils.getDesc(method); - if (worked.contains(desc)) { + if (worked.contains(desc) || Modifier.isStatic(method.getModifiers())) { continue; } worked.add(desc); diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/AbstractDynamicConfigurationFactory.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/AbstractDynamicConfigurationFactory.java similarity index 70% rename from dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/AbstractDynamicConfigurationFactory.java rename to dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/AbstractDynamicConfigurationFactory.java index 324f2cbef76..15b9145dfa3 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/AbstractDynamicConfigurationFactory.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/AbstractDynamicConfigurationFactory.java @@ -14,27 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter; +package org.apache.dubbo.common.config.configcenter; import org.apache.dubbo.common.URL; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY; + /** * */ public abstract class AbstractDynamicConfigurationFactory implements DynamicConfigurationFactory { - private volatile DynamicConfiguration dynamicConfiguration; + private volatile Map dynamicConfigurations = new ConcurrentHashMap<>(); @Override public DynamicConfiguration getDynamicConfiguration(URL url) { - if (dynamicConfiguration == null) { - synchronized (this) { - if (dynamicConfiguration == null) { - dynamicConfiguration = createDynamicConfiguration(url); - } - } - } - return dynamicConfiguration; + String key = url == null ? DEFAULT_KEY : url.getAddress(); + return dynamicConfigurations.computeIfAbsent(key, k -> createDynamicConfiguration(url)); } protected abstract DynamicConfiguration createDynamicConfiguration(URL url); diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeEvent.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/ConfigChangeEvent.java similarity index 97% rename from dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeEvent.java rename to dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/ConfigChangeEvent.java index cdedd15e34e..751746f199d 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeEvent.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/ConfigChangeEvent.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter; +package org.apache.dubbo.common.config.configcenter; /** * Config change event, immutable. diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeType.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/ConfigChangeType.java similarity index 95% rename from dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeType.java rename to dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/ConfigChangeType.java index e810ddce600..fe43a2b1ab1 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeType.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/ConfigChangeType.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter; +package org.apache.dubbo.common.config.configcenter; /** * Config change event type diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigurationListener.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/ConfigurationListener.java similarity index 95% rename from dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigurationListener.java rename to dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/ConfigurationListener.java index 7c7a1310d46..09746c5bcee 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigurationListener.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/ConfigurationListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter; +package org.apache.dubbo.common.config.configcenter; /** * Config listener, will get notified when the config it listens on changes. diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/Constants.java similarity index 95% rename from dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/Constants.java rename to dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/Constants.java index fcf1a51fc56..d85f86b11cf 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/Constants.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter; +package org.apache.dubbo.common.config.configcenter; public interface Constants { String CONFIG_CLUSTER_KEY = "config.cluster"; diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java similarity index 99% rename from dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfiguration.java rename to dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java index 804dd8bd568..26e831d17e7 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfiguration.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter; +package org.apache.dubbo.common.config.configcenter; import org.apache.dubbo.common.config.Configuration; import org.apache.dubbo.common.config.Environment; diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfigurationFactory.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactory.java similarity index 95% rename from dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfigurationFactory.java rename to dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactory.java index 4e0b9b521c8..59c27ce0cb4 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfigurationFactory.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactory.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter; +package org.apache.dubbo.common.config.configcenter; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.SPI; diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfiguration.java similarity index 88% rename from dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfiguration.java rename to dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfiguration.java index 56e1191aa5f..7637e6471be 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfiguration.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfiguration.java @@ -14,11 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter.support.nop; +package org.apache.dubbo.common.config.configcenter.nop; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; + +import java.util.SortedSet; + +import static java.util.Collections.emptySortedSet; import java.util.SortedSet; diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfigurationFactory.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfigurationFactory.java similarity index 83% rename from dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfigurationFactory.java rename to dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfigurationFactory.java index 0b6aee6a351..bd45e7f736e 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfigurationFactory.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfigurationFactory.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter.support.nop; +package org.apache.dubbo.common.config.configcenter.nop; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory; -import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; /** * diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java new file mode 100644 index 00000000000..7f98d383d7d --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java @@ -0,0 +1,98 @@ +/* + * 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.common.config.configcenter.wrapper; + +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; + +import java.util.HashSet; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.function.Consumer; +import java.util.function.Function; + +/** + * support multiple config center, simply iterating each underlying config center. + */ +public class CompositeDynamicConfiguration implements DynamicConfiguration { + + public static final String NAME = "COMPOSITE"; + + private Set configurations = new HashSet<>(); + + public void addConfiguration(DynamicConfiguration configuration) { + this.configurations.add(configuration); + } + + @Override + public void addListener(String key, String group, ConfigurationListener listener) { + iterateListenerOperation(configuration -> configuration.addListener(key, group, listener)); + } + + @Override + public void removeListener(String key, String group, ConfigurationListener listener) { + iterateListenerOperation(configuration -> configuration.removeListener(key, group, listener)); + } + + @Override + public String getConfig(String key, String group, long timeout) throws IllegalStateException { + return (String) iterateConfigOperation(configuration -> configuration.getConfig(key, group, timeout)); + } + + @Override + public String getConfigs(String key, String group, long timeout) throws IllegalStateException { + return (String) iterateConfigOperation(configuration -> configuration.getConfigs(key, group, timeout)); + } + + @Override + public Object getInternalProperty(String key) { + return iterateConfigOperation(configuration -> configuration.getInternalProperty(key)); + } + + @Override + public boolean publishConfig(String key, String group, String content) throws UnsupportedOperationException { + return (boolean) iterateConfigOperation(configuration -> configuration.publishConfig(key, group, content)); + } + + @Override + public SortedSet getConfigKeys(String group) throws UnsupportedOperationException { + return (SortedSet) iterateConfigOperation(configuration -> configuration.getConfigKeys(group)); + } + + @Override + public SortedMap getConfigs(String group) throws UnsupportedOperationException { + return (SortedMap) iterateConfigOperation(configuration -> configuration.getConfigs(group)); + } + + private void iterateListenerOperation(Consumer consumer) { + for (DynamicConfiguration configuration : configurations) { + consumer.accept(configuration); + } + } + + private Object iterateConfigOperation(Function func) { + Object value = null; + for (DynamicConfiguration configuration : configurations) { + value = func.apply(configuration); + if (value != null) { + break; + } + } + return value; + } +} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java index d005ae931ae..c1a1357e0c9 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java @@ -151,6 +151,14 @@ public interface CommonConstants { String REVISION_KEY = "revision"; + String METADATA_REVISION = "metadata.revision"; + + String METADATA_KEY = "metadata"; + + String METADATA_DEFAULT = "local"; + + String METADATA_REMOTE = "remote"; + /** * package version in the manifest */ diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java index 548c48f4391..b4739f20735 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java @@ -498,4 +498,25 @@ static boolean isItemMatch(String pattern, String value) { return "*".equals(pattern) || pattern.equals(value); } } + + /** + * @param serviceKey, {group}/{interfaceName}:{version} + * @return [group, interfaceName, version] + */ + public static String[] parseServiceKey(String serviceKey) { + String[] arr = new String[3]; + int i = serviceKey.indexOf("/"); + if (i > 0) { + arr[0] = serviceKey.substring(0, i); + serviceKey = serviceKey.substring(i + 1); + } + + int j = serviceKey.indexOf(":"); + if (j > 0) { + arr[2] = serviceKey.substring(j + 1); + serviceKey = serviceKey.substring(0, j); + } + arr[1] = serviceKey; + return arr; + } } diff --git a/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory b/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory new file mode 100644 index 00000000000..42d6a251120 --- /dev/null +++ b/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory @@ -0,0 +1 @@ +nop=org.apache.dubbo.common.config.configcenter.nop.NopDynamicConfigurationFactory \ No newline at end of file diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java index 7b489a3e2c7..f488c8d65e1 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java @@ -36,7 +36,7 @@ public class Constants implements CommonConstants, org.apache.dubbo.rpc.Constants, org.apache.dubbo.rpc.protocol.dubbo.Constants, org.apache.dubbo.common.serialize.Constants, - org.apache.dubbo.configcenter.Constants, + org.apache.dubbo.common.config.configcenter.Constants, org.apache.dubbo.metadata.support.Constants, org.apache.dubbo.rpc.protocol.rest.Constants, org.apache.dubbo.registry.Constants { diff --git a/dubbo-config/dubbo-config-api/pom.xml b/dubbo-config/dubbo-config-api/pom.xml index b8f5938b112..896feef7aa4 100644 --- a/dubbo-config/dubbo-config-api/pom.xml +++ b/dubbo-config/dubbo-config-api/pom.xml @@ -66,12 +66,6 @@ ${project.parent.version} - - org.apache.dubbo - dubbo-metadata - ${project.parent.version} - - org.apache.dubbo diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 246694822a7..4d59f91f9d4 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -114,9 +114,6 @@ public abstract class AbstractConfig implements Serializable { LEGACY_PROPERTIES.put("dubbo.consumer.retries", "dubbo.service.max.retry.providers"); LEGACY_PROPERTIES.put("dubbo.consumer.check", "dubbo.service.allow.no.provider"); LEGACY_PROPERTIES.put("dubbo.service.url", "dubbo.service.address"); - - // this is only for compatibility - DubboShutdownHook.getDubboShutdownHook().register(); } /** diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java index 8130a5fc044..1ad15ecb725 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java @@ -19,8 +19,6 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.Version; -import org.apache.dubbo.common.config.Environment; -import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ConfigUtils; @@ -30,9 +28,6 @@ import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.support.Parameter; -import org.apache.dubbo.configcenter.DynamicConfiguration; -import org.apache.dubbo.configcenter.DynamicConfigurationFactory; -import org.apache.dubbo.metadata.integration.MetadataReportService; import org.apache.dubbo.monitor.MonitorFactory; import org.apache.dubbo.monitor.MonitorService; import org.apache.dubbo.registry.RegistryService; @@ -43,19 +38,14 @@ import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.support.MockInvoker; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; -import static org.apache.dubbo.common.config.ConfigurationUtils.parseProperties; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL; import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; @@ -73,7 +63,6 @@ import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY; import static org.apache.dubbo.config.Constants.LAYER_KEY; import static org.apache.dubbo.config.Constants.LISTENER_KEY; -import static org.apache.dubbo.config.Constants.REGISTRIES_SUFFIX; import static org.apache.dubbo.monitor.Constants.LOGSTAT_PROTOCOL; import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY; import static org.apache.dubbo.registry.Constants.REGISTER_KEY; @@ -203,8 +192,6 @@ protected void checkRegistry() { "The registry config is: " + registryConfig); } } - - useRegistryForConfigIfNecessary(); } @SuppressWarnings("deprecation") @@ -267,55 +254,6 @@ protected void checkMetadataReport() { } } - - void startConfigCenter() { - if (configCenter == null) { - ConfigManager.getInstance().getConfigCenter().ifPresent(cc -> this.configCenter = cc); - } - - if (this.configCenter != null) { - // TODO there may have duplicate refresh - this.configCenter.refresh(); - prepareEnvironment(); - } - ConfigManager.getInstance().refreshAll(); - } - - private void prepareEnvironment() { - if (configCenter.isValid()) { - if (!configCenter.checkOrUpdateInited()) { - return; - } - DynamicConfiguration dynamicConfiguration = getDynamicConfiguration(configCenter.toUrl()); - String configContent = dynamicConfiguration.getConfigs(configCenter.getConfigFile(), configCenter.getGroup()); - - String appGroup = application != null ? application.getName() : null; - String appConfigContent = null; - if (StringUtils.isNotEmpty(appGroup)) { - appConfigContent = dynamicConfiguration.getConfigs - (StringUtils.isNotEmpty(configCenter.getAppConfigFile()) ? configCenter.getAppConfigFile() : configCenter.getConfigFile(), - appGroup - ); - } - try { - Environment.getInstance().setConfigCenterFirst(configCenter.isHighestPriority()); - Environment.getInstance().updateExternalConfigurationMap(parseProperties(configContent)); - Environment.getInstance().updateAppExternalConfigurationMap(parseProperties(appConfigContent)); - } catch (IOException e) { - throw new IllegalStateException("Failed to parse configurations from Config Center.", e); - } - } - } - - private DynamicConfiguration getDynamicConfiguration(URL url) { - DynamicConfigurationFactory factories = ExtensionLoader - .getExtensionLoader(DynamicConfigurationFactory.class) - .getExtension(url.getProtocol()); - DynamicConfiguration configuration = factories.getDynamicConfiguration(url); - Environment.getInstance().setDynamicConfiguration(configuration); - return configuration; - } - /** * * Load the registry and conversion it to {@link URL}, the priority order is: system property > dubbo registry config @@ -415,24 +353,6 @@ static void appendRuntimeParameters(Map map) { } } - private URL loadMetadataReporterURL() { - String address = metadataReportConfig.getAddress(); - if (StringUtils.isEmpty(address)) { - return null; - } - Map map = new HashMap(); - appendParameters(map, metadataReportConfig); - return UrlUtils.parseURL(address, map); - } - - protected MetadataReportService getMetadataReportService() { - - if (metadataReportConfig == null || !metadataReportConfig.isValid()) { - return null; - } - return MetadataReportService.instance(this::loadMetadataReporterURL); - } - /** * Check whether the remote service interface and the methods meet with Dubbo's requirements.it mainly check, if the * methods configured in the configuration file are included in the interface of remote service @@ -544,16 +464,6 @@ private void verify(Class interfaceClass, Class localClass) { } private void convertRegistryIdsToRegistries() { - if (StringUtils.isEmpty(registryIds) && CollectionUtils.isEmpty(registries)) { - Set configedRegistries = new HashSet<>(); - configedRegistries.addAll(getSubProperties(Environment.getInstance().getExternalConfigurationMap(), - REGISTRIES_SUFFIX)); - configedRegistries.addAll(getSubProperties(Environment.getInstance().getAppExternalConfigurationMap(), - REGISTRIES_SUFFIX)); - - registryIds = String.join(COMMA_SEPARATOR, configedRegistries); - } - if (StringUtils.isEmpty(registryIds)) { if (CollectionUtils.isEmpty(registries)) { setRegistries( @@ -571,12 +481,7 @@ private void convertRegistryIdsToRegistries() { List tmpRegistries = CollectionUtils.isNotEmpty(registries) ? registries : new ArrayList<>(); Arrays.stream(ids).forEach(id -> { if (tmpRegistries.stream().noneMatch(reg -> reg.getId().equals(id))) { - tmpRegistries.add(ConfigManager.getInstance().getRegistry(id).orElseGet(() -> { - RegistryConfig registryConfig = new RegistryConfig(); - registryConfig.setId(id); - registryConfig.refresh(); - return registryConfig; - })); + ConfigManager.getInstance().getRegistry(id).ifPresent(tmpRegistries::add); } }); @@ -609,26 +514,6 @@ private void loadRegistriesFromBackwardConfig() { } } - /** - * For compatibility purpose, use registry as the default config center if the registry protocol is zookeeper and - * there's no config center specified explicitly. - */ - private void useRegistryForConfigIfNecessary() { - registries.stream().filter(RegistryConfig::isZookeeperProtocol).findFirst().ifPresent(rc -> { - // we use the loading status of DynamicConfiguration to decide whether ConfigCenter has been initiated. - Environment.getInstance().getDynamicConfiguration().orElseGet(() -> { - ConfigManager configManager = ConfigManager.getInstance(); - ConfigCenterConfig cc = configManager.getConfigCenter().orElse(new ConfigCenterConfig()); - cc.setProtocol(rc.getProtocol()); - cc.setAddress(rc.getAddress()); - cc.setHighestPriority(false); - setConfigCenter(cc); - startConfigCenter(); - return null; - }); - }); - } - /** * @return local * @deprecated Replace to getStub() @@ -783,7 +668,7 @@ public List getRegistries() { @SuppressWarnings({"unchecked"}) public void setRegistries(List registries) { - ConfigManager.getInstance().addRegistries((List) registries); + ConfigManager.getInstance().addRegistries((List) registries, false); this.registries = (List) registries; } @@ -823,7 +708,7 @@ public ConfigCenterConfig getConfigCenter() { } public void setConfigCenter(ConfigCenterConfig configCenter) { - ConfigManager.getInstance().setConfigCenter(configCenter); + ConfigManager.getInstance().addConfigCenter(configCenter); this.configCenter = configCenter; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java index 8aff2aa7a89..dc40e52bc9b 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java @@ -27,8 +27,8 @@ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.rpc.Constants.SERVICE_FILTER_KEY; import static org.apache.dubbo.rpc.Constants.EXPORTER_LISTENER_KEY; +import static org.apache.dubbo.rpc.Constants.SERVICE_FILTER_KEY; import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; /** @@ -206,7 +206,7 @@ public List getProtocols() { @SuppressWarnings({"unchecked"}) public void setProtocols(List protocols) { - ConfigManager.getInstance().addProtocols((List) protocols); + ConfigManager.getInstance().addProtocols((List) protocols, false); this.protocols = (List) protocols; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java index 83fc6db2e9a..b33ec75786c 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java @@ -137,6 +137,11 @@ public class ApplicationConfig extends AbstractConfig { */ private String shutwait; + /** + * Metadata type, local or remote, if choose remote, you need to further specify metadata center. + */ + private String metadata; + public ApplicationConfig() { } @@ -374,4 +379,11 @@ public boolean isValid() { return !StringUtils.isEmpty(name); } + public String getMetadata() { + return metadata; + } + + public void setMetadata(String metadata) { + this.metadata = metadata; + } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java index 7caae5634ec..fb8b2e52b33 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java @@ -26,17 +26,17 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_CHECK_KEY; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_CLUSTER_KEY; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_GROUP_KEY; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_NAMESPACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; -import static org.apache.dubbo.configcenter.Constants.CONFIG_CHECK_KEY; -import static org.apache.dubbo.configcenter.Constants.CONFIG_CLUSTER_KEY; -import static org.apache.dubbo.configcenter.Constants.CONFIG_GROUP_KEY; -import static org.apache.dubbo.configcenter.Constants.CONFIG_NAMESPACE_KEY; -import static org.apache.dubbo.config.Constants.ZOOKEEPER_PROTOCOL; import static org.apache.dubbo.config.Constants.CONFIG_CONFIGFILE_KEY; import static org.apache.dubbo.config.Constants.CONFIG_ENABLE_KEY; import static org.apache.dubbo.config.Constants.CONFIG_TIMEOUT_KEY; +import static org.apache.dubbo.config.Constants.ZOOKEEPER_PROTOCOL; /** * ConfigCenterConfig diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java index 5233171e011..30e5bcb600e 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java @@ -16,9 +16,12 @@ */ package org.apache.dubbo.config; +import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.config.support.Parameter; +import java.util.HashMap; import java.util.Map; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; @@ -83,6 +86,16 @@ public MetadataReportConfig(String address) { setAddress(address); } + public URL toUrl() { + String address = this.getAddress(); + if (StringUtils.isEmpty(address)) { + return null; + } + Map map = new HashMap(); + appendParameters(map, this); + return UrlUtils.parseURL(address, map); + } + @Parameter(excluded = true) public String getAddress() { return address; diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index ee2e9b63ebd..1b08ba00a02 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -32,7 +32,7 @@ import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.event.Event; import org.apache.dubbo.event.EventDispatcher; -import org.apache.dubbo.metadata.integration.MetadataReportService; +import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; @@ -66,6 +66,8 @@ import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.METADATA_DEFAULT; +import static org.apache.dubbo.common.constants.CommonConstants.METADATA_KEY; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY; @@ -228,7 +230,6 @@ public void checkAndUpdateSubConfigs() { throw new IllegalStateException(" interface not allow null!"); } completeCompoundConfigs(); - startConfigCenter(); // get consumer's global configuration checkDefault(); this.refresh(); @@ -340,10 +341,11 @@ private void init() { } map.put(REGISTER_IP_KEY, hostToRegistry); - ref = createProxy(map); - String serviceKey = URL.buildKey(interfaceName, group, version); ApplicationModel.initConsumerModel(serviceKey, buildConsumerModel(serviceKey, attributes)); + ref = createProxy(map); + ApplicationModel.getConsumerModel(serviceKey).setProxyObject(ref); + initialized = true; // dispatch a ReferenceConfigInitializedEvent since 2.7.3 @@ -441,10 +443,11 @@ private T createProxy(Map map) { * @since 2.7.0 * ServiceData Store */ - MetadataReportService metadataReportService = null; - if ((metadataReportService = getMetadataReportService()) != null) { + String metadata = map.get(METADATA_KEY); + WritableMetadataService metadataService = WritableMetadataService.getExtension(metadata == null ? METADATA_DEFAULT : metadata); + if (metadataService != null) { URL consumerURL = new URL(CONSUMER_PROTOCOL, map.remove(REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map); - metadataReportService.publishConsumer(consumerURL); + metadataService.publishServiceDefinition(consumerURL); } // create service proxy return (T) PROXY_FACTORY.getProxy(invoker); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index cc1138ae66b..dc7d5a97674 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -21,7 +21,6 @@ import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.bytecode.Wrapper; -import org.apache.dubbo.common.config.Environment; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.CollectionUtils; @@ -36,7 +35,7 @@ import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.event.Event; import org.apache.dubbo.event.EventDispatcher; -import org.apache.dubbo.metadata.integration.MetadataReportService; +import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; @@ -72,6 +71,8 @@ import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_IP_TO_BIND; import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.METADATA_DEFAULT; +import static org.apache.dubbo.common.constants.CommonConstants.METADATA_KEY; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; @@ -87,7 +88,6 @@ import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_BIND; import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_REGISTRY; import static org.apache.dubbo.config.Constants.MULTICAST; -import static org.apache.dubbo.config.Constants.PROTOCOLS_SUFFIX; import static org.apache.dubbo.config.Constants.SCOPE_NONE; import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL; @@ -301,10 +301,8 @@ public boolean isUnexported() { } public void checkAndUpdateSubConfigs() { - // Use default configs defined explicitly on global configs + // Use default configs defined explicitly on global scope completeCompoundConfigs(); - // Config Center should always being started first. - startConfigCenter(); checkDefault(); checkProtocol(); checkApplication(); @@ -635,9 +633,9 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List r * @since 2.7.0 * ServiceData Store */ - MetadataReportService metadataReportService = null; - if ((metadataReportService = getMetadataReportService()) != null) { - metadataReportService.publishProvider(url); + WritableMetadataService metadataService = WritableMetadataService.getExtension(url.getParameter(METADATA_KEY, METADATA_DEFAULT)); + if (metadataService != null) { + metadataService.publishServiceDefinition(url); } } } @@ -882,16 +880,6 @@ private void checkProtocol() { } private void convertProtocolIdsToProtocols() { - if (StringUtils.isEmpty(protocolIds) && CollectionUtils.isEmpty(protocols)) { - List configedProtocols = new ArrayList<>(); - configedProtocols.addAll(getSubProperties(Environment.getInstance() - .getExternalConfigurationMap(), PROTOCOLS_SUFFIX)); - configedProtocols.addAll(getSubProperties(Environment.getInstance() - .getAppExternalConfigurationMap(), PROTOCOLS_SUFFIX)); - - protocolIds = String.join(",", configedProtocols); - } - if (StringUtils.isEmpty(protocolIds)) { if (CollectionUtils.isEmpty(protocols)) { setProtocols( @@ -909,12 +897,7 @@ private void convertProtocolIdsToProtocols() { List tmpProtocols = CollectionUtils.isNotEmpty(protocols) ? protocols : new ArrayList<>(); Arrays.stream(arr).forEach(id -> { if (tmpProtocols.stream().noneMatch(prot -> prot.getId().equals(id))) { - tmpProtocols.add(ConfigManager.getInstance().getProtocol(id).orElseGet(() -> { - ProtocolConfig protocolConfig = new ProtocolConfig(); - protocolConfig.setId(id); - protocolConfig.refresh(); - return protocolConfig; - })); + ConfigManager.getInstance().getProtocol(id).ifPresent(tmpProtocols::add); } }); if (tmpProtocols.size() > arr.length) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/ApplicationBuilder.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/ApplicationBuilder.java index 7ab59a6bf8c..f4a804745c1 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/ApplicationBuilder.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/ApplicationBuilder.java @@ -33,6 +33,7 @@ */ public class ApplicationBuilder extends AbstractBuilder { private String name; + private String metadata; private String version; private String owner; private String organization; @@ -51,11 +52,20 @@ public class ApplicationBuilder extends AbstractBuilder parameters; private String shutwait; + public static ApplicationBuilder newBuilder() { + return new ApplicationBuilder(); + } + public ApplicationBuilder name(String name) { this.name = name; return getThis(); } + public ApplicationBuilder metadata(String metadata) { + this.metadata = metadata; + return getThis(); + } + public ApplicationBuilder version(String version) { this.version = version; return getThis(); @@ -167,6 +177,7 @@ public ApplicationConfig build() { super.build(config); config.setName(name); + config.setMetadata(metadata); config.setVersion(this.version); config.setOwner(this.owner); config.setOrganization(this.organization); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/MetadataReportBuilder.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/MetadataReportBuilder.java index 140ea137907..62777ef94b9 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/MetadataReportBuilder.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/MetadataReportBuilder.java @@ -60,6 +60,10 @@ public class MetadataReportBuilder extends AbstractBuilder extends AbstractReferenceBuilder id(String id) { return super.id(id); } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/RegistryBuilder.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/RegistryBuilder.java index 616e6af09a5..9dc9e1b68a7 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/RegistryBuilder.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/builders/RegistryBuilder.java @@ -134,6 +134,10 @@ public class RegistryBuilder extends AbstractBuilder extends AbstractServiceBuilder protocols = new ConcurrentHashMap<>(); private Map registries = new ConcurrentHashMap<>(); private Map providers = new ConcurrentHashMap<>(); private Map consumers = new ConcurrentHashMap<>(); + private List defaultProtocols = new ArrayList<>(); + private List defaultRegistries = new ArrayList<>(); + + private Set configCenters = new HashSet<>(); + private Set metadataConfigs = new HashSet<>(); + private Set registryIds = new HashSet<>(); + private Set protocolIds = new HashSet<>(); + + private List> serviceConfigs = new ArrayList<>(); + private List> referenceConfigs = new ArrayList<>(); + public static ConfigManager getInstance() { return CONFIG_MANAGER; } @@ -126,14 +146,35 @@ public void setModule(ModuleConfig module) { } } - public Optional getConfigCenter() { - return Optional.ofNullable(configCenter); + public Set getConfigCenters() { + return configCenters; + } + + public void addConfigCenter(ConfigCenterConfig configCenter) { + if (configCenter != null && !configCenters.contains(configCenter)) { + this.configCenters.add(configCenter); + } + } + + public void addConfigCenter(List configCenters) { + if (CollectionUtils.isNotEmpty(configCenters)) { + this.configCenters.addAll(configCenters); + } + } + + public Set getMetadataConfigs() { + return metadataConfigs; } - public void setConfigCenter(ConfigCenterConfig configCenter) { - if (configCenter != null) { - checkDuplicate(this.configCenter, configCenter); - this.configCenter = configCenter; + public void addMetadataReport(MetadataReportConfig metadataReportConfig) { + if (metadataReportConfig != null && !metadataConfigs.contains(metadataReportConfig)) { + this.metadataConfigs.add(metadataReportConfig); + } + } + + public void addMetadataReport(List metadataReportConfigs) { + if (CollectionUtils.isNotEmpty(metadataReportConfigs)) { + this.metadataConfigs.addAll(metadataReportConfigs); } } @@ -200,31 +241,28 @@ public Optional getProtocol(String id) { } public Optional> getDefaultProtocols() { - List defaults = new ArrayList<>(); - protocols.forEach((k, v) -> { - if (DEFAULT_KEY.equalsIgnoreCase(k)) { - defaults.add(v); - } else if (v.isDefault() == null || v.isDefault()) { - defaults.add(v); - } - }); - return Optional.of(defaults); - } - - public void addProtocols(List protocolConfigs) { + return Optional.of(defaultProtocols); + } + + public void addProtocols(List protocolConfigs, boolean canBeDefault) { if (protocolConfigs != null) { - protocolConfigs.forEach(this::addProtocol); + protocolConfigs.forEach(pc -> this.addProtocol(pc, canBeDefault)); } } - public void addProtocol(ProtocolConfig protocolConfig) { + public void addProtocol(ProtocolConfig protocolConfig, boolean canBeDefault) { if (protocolConfig == null) { return; } + // if isDefault is not false and a ProtocolConfig is not specified being false. + if (canBeDefault && (protocolConfig.isDefault() == null || protocolConfig.isDefault())) { + this.defaultProtocols.add(protocolConfig); + } + String key = StringUtils.isNotEmpty(protocolConfig.getId()) ? protocolConfig.getId() - : (protocolConfig.isDefault() == null || protocolConfig.isDefault()) ? DEFAULT_KEY : null; + : DEFAULT_KEY; if (StringUtils.isEmpty(key)) { throw new IllegalStateException("A ProtocolConfig should either has an id or it's the default one, " + protocolConfig); @@ -243,31 +281,26 @@ public Optional getRegistry(String id) { } public Optional> getDefaultRegistries() { - List defaults = new ArrayList<>(); - registries.forEach((k, v) -> { - if (DEFAULT_KEY.equalsIgnoreCase(k)) { - defaults.add(v); - } else if (v.isDefault() == null || v.isDefault()) { - defaults.add(v); - } - }); - return Optional.of(defaults); - } - - public void addRegistries(List registryConfigs) { + return Optional.of(defaultRegistries); + } + + public void addRegistries(List registryConfigs, boolean canBeDefault) { if (registryConfigs != null) { - registryConfigs.forEach(this::addRegistry); + registryConfigs.forEach(rc -> this.addRegistry(rc, canBeDefault)); } } - public void addRegistry(RegistryConfig registryConfig) { + public void addRegistry(RegistryConfig registryConfig, boolean canBeDefault) { if (registryConfig == null) { return; } + if (canBeDefault && (registryConfig.isDefault() == null || registryConfig.isDefault())) { + this.defaultRegistries.add(registryConfig); + } String key = StringUtils.isNotEmpty(registryConfig.getId()) ? registryConfig.getId() - : (registryConfig.isDefault() == null || registryConfig.isDefault()) ? DEFAULT_KEY : null; + : DEFAULT_KEY; if (StringUtils.isEmpty(key)) { throw new IllegalStateException("A RegistryConfig should either has an id or it's the default one, " + registryConfig); @@ -281,6 +314,51 @@ public void addRegistry(RegistryConfig registryConfig) { } } + public void addProtocolIds(List protocolIds) { + this.protocolIds.addAll(protocolIds); + } + + public void addRegistryIds(List registryIds) { + this.registryIds.addAll(registryIds); + } + + public void addService(ServiceConfig serviceConfig) { + this.serviceConfigs.add(serviceConfig); + } + + public void addReference(ReferenceConfig referenceConfig) { + this.referenceConfigs.add(referenceConfig); + } + + public Set getRegistryIds() { + Set configedRegistries = new HashSet<>(); + configedRegistries.addAll(getSubProperties(Environment.getInstance().getExternalConfigurationMap(), + REGISTRIES_SUFFIX)); + configedRegistries.addAll(getSubProperties(Environment.getInstance().getAppExternalConfigurationMap(), + REGISTRIES_SUFFIX)); + + configedRegistries.addAll(registryIds); + return configedRegistries; + } + + public Set getProtocolIds() { + Set configedProtocols = new HashSet<>(); + configedProtocols.addAll(getSubProperties(Environment.getInstance() + .getExternalConfigurationMap(), PROTOCOLS_SUFFIX)); + configedProtocols.addAll(getSubProperties(Environment.getInstance() + .getAppExternalConfigurationMap(), PROTOCOLS_SUFFIX)); + + configedProtocols.addAll(protocolIds); + return configedProtocols; + } + + protected static Set getSubProperties(Map properties, String prefix) { + return properties.keySet().stream().filter(k -> k.contains(prefix)).map(k -> { + k = k.substring(prefix.length()); + return k.substring(0, k.indexOf(".")); + }).collect(Collectors.toSet()); + } + public Map getProtocols() { return protocols; } @@ -297,6 +375,14 @@ public Map getConsumers() { return consumers; } + public List> getServiceConfigs() { + return serviceConfigs; + } + + public List> getReferenceConfigs() { + return referenceConfigs; + } + public void refreshAll() { // refresh all configs here, getApplication().ifPresent(ApplicationConfig::refresh); @@ -319,13 +405,16 @@ private void checkDuplicate(AbstractConfig oldOne, AbstractConfig newOne) { // For test purpose public void clear() { this.application = null; - this.configCenter = null; this.monitor = null; this.module = null; this.registries.clear(); this.protocols.clear(); this.providers.clear(); this.consumers.clear(); + this.configCenters.clear(); + this.metadataConfigs.clear(); + this.registryIds.clear(); + this.protocolIds.clear(); } } 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 ac36f9e477d..bf14658f5ac 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 @@ -25,9 +25,9 @@ import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.context.ConfigManager; -import org.apache.dubbo.metadata.LocalMetadataService; import org.apache.dubbo.metadata.MetadataService; import org.apache.dubbo.metadata.MetadataServiceExporter; +import org.apache.dubbo.metadata.WritableMetadataService; import java.util.Collection; import java.util.LinkedList; @@ -79,7 +79,7 @@ public List export() { if (!isExported()) { - LocalMetadataService metadataService = LocalMetadataService.getDefaultExtension(); + WritableMetadataService metadataService = WritableMetadataService.getDefaultExtension(); ServiceConfig serviceConfig = new ServiceConfig<>(); serviceConfig.setApplication(applicationConfig); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ShutdownTelnetHandler.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/telnet/ShutdownTelnetHandler.java similarity index 98% rename from dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ShutdownTelnetHandler.java rename to dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/telnet/ShutdownTelnetHandler.java index ff5bf07cb33..3c24cebb319 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ShutdownTelnetHandler.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/telnet/ShutdownTelnetHandler.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.rpc.protocol.dubbo.telnet; +package org.apache.dubbo.config.telnet; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.utils.StringUtils; diff --git a/dubbo-config/dubbo-config-api/src/main/resources/META-INF/services/org.apache.dubbo.remoting.telnet.TelnetHandler b/dubbo-config/dubbo-config-api/src/main/resources/META-INF/services/org.apache.dubbo.remoting.telnet.TelnetHandler new file mode 100644 index 00000000000..3e87526883d --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/main/resources/META-INF/services/org.apache.dubbo.remoting.telnet.TelnetHandler @@ -0,0 +1 @@ +shutdown=org.apache.dubbo.rpc.protocol.dubbo.telnet.ShutdownTelnetHandler \ No newline at end of file diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporterTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporterTest.java index 66200aca1ea..ec841a55a3c 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporterTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporterTest.java @@ -49,9 +49,9 @@ public static void init() { configManager.setApplication(applicationConfig); // Add ProtocolConfig - configManager.addProtocol(protocolConfig()); + configManager.addProtocol(protocolConfig(), true); // Add RegistryConfig - configManager.addRegistry(registryConfig()); + configManager.addRegistry(registryConfig(), true); } private static ProtocolConfig protocolConfig() { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/DemoException.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/DemoException.java similarity index 96% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/DemoException.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/DemoException.java index ceb187c0d9f..dc02d4e6062 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/DemoException.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/DemoException.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.dubbo.rpc.service; +package org.apache.dubbo.config.service; /** * DemoException diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/DemoService.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/DemoService.java similarity index 96% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/DemoService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/DemoService.java index 38ba742c679..cbc131a5cb3 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/DemoService.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/DemoService.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.dubbo.rpc.service; +package org.apache.dubbo.config.service; import java.util.List; diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/DemoServiceImpl.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/DemoServiceImpl.java similarity index 96% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/DemoServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/DemoServiceImpl.java index 4ef72c33352..7bd467e052e 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/DemoServiceImpl.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/DemoServiceImpl.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.dubbo.rpc.service; +package org.apache.dubbo.config.service; import java.util.List; diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/GenericServiceTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/GenericServiceTest.java similarity index 99% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/GenericServiceTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/GenericServiceTest.java index e99c6fce095..921800ccf58 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/GenericServiceTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/GenericServiceTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.dubbo.rpc.service; +package org.apache.dubbo.config.service; import org.apache.dubbo.common.beanutil.JavaBeanAccessor; import org.apache.dubbo.common.beanutil.JavaBeanDescriptor; @@ -29,6 +29,8 @@ import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.rpc.service.GenericException; +import org.apache.dubbo.rpc.service.GenericService; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; @@ -42,8 +44,8 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import static org.apache.dubbo.rpc.Constants.GENERIC_SERIALIZATION_NATIVE_JAVA; import static org.apache.dubbo.rpc.Constants.GENERIC_SERIALIZATION_BEAN; +import static org.apache.dubbo.rpc.Constants.GENERIC_SERIALIZATION_NATIVE_JAVA; /** * GenericServiceTest diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/User.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/User.java similarity index 97% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/User.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/User.java index 901001b56aa..7ba76a2eccf 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/service/User.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/service/User.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.dubbo.rpc.service; +package org.apache.dubbo.config.service; import java.io.Serializable; diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ShutdownTelnetHandlerTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/telnet/ShutdownTelnetHandlerTest.java similarity index 97% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ShutdownTelnetHandlerTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/telnet/ShutdownTelnetHandlerTest.java index 6dbd026300e..2fc4110d571 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ShutdownTelnetHandlerTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/telnet/ShutdownTelnetHandlerTest.java @@ -14,11 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.rpc.protocol.dubbo.telnet; +package org.apache.dubbo.config.telnet; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.telnet.TelnetHandler; + import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationParameter.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationParameter.java similarity index 98% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationParameter.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationParameter.java index 77841d51013..14a571df8c0 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationParameter.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationParameter.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.dubbo.rpc.validation; +package org.apache.dubbo.config.validation; import javax.validation.constraints.Future; import javax.validation.constraints.Max; diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationService.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationService.java similarity index 98% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationService.java index 262c9967eec..0d15b6dfb66 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationService.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationService.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.dubbo.rpc.validation; +package org.apache.dubbo.config.validation; import org.apache.dubbo.validation.MethodValidated; diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationServiceImpl.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationServiceImpl.java similarity index 96% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationServiceImpl.java index 8a621aaa27f..783cff524c9 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationServiceImpl.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationServiceImpl.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.dubbo.rpc.validation; +package org.apache.dubbo.config.validation; /** * ValidationServiceImpl diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationTest.java similarity index 99% rename from dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationTest.java index 691f925216c..04a45eac7f8 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/validation/ValidationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/validation/ValidationTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.dubbo.rpc.validation; +package org.apache.dubbo.config.validation; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd index 756f6dae665..4331ea45476 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd @@ -397,6 +397,11 @@ + + + + + diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd index 4a8cf56c8d8..f7124c856b0 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd @@ -392,6 +392,11 @@ + + + + + diff --git a/dubbo-configcenter/dubbo-configcenter-api/pom.xml b/dubbo-configcenter/dubbo-configcenter-api/pom.xml deleted file mode 100644 index bab80eb0fdc..00000000000 --- a/dubbo-configcenter/dubbo-configcenter-api/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - 4.0.0 - - org.apache.dubbo - dubbo-configcenter - ${revision} - - dubbo-configcenter-api - jar - ${project.artifactId} - The api definition of the service config-center module - - false - - - - - org.apache.dubbo - dubbo-common - ${project.parent.version} - - - diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory b/dubbo-configcenter/dubbo-configcenter-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory deleted file mode 100644 index 51c40041765..00000000000 --- a/dubbo-configcenter/dubbo-configcenter-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory +++ /dev/null @@ -1 +0,0 @@ -nop=org.apache.dubbo.configcenter.support.nop.NopDynamicConfigurationFactory \ No newline at end of file diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/AbstractDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/AbstractDynamicConfigurationTest.java deleted file mode 100644 index a5f669a2715..00000000000 --- a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/AbstractDynamicConfigurationTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.configcenter.mock; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.extension.ExtensionLoader; -import org.apache.dubbo.configcenter.DynamicConfiguration; -import org.apache.dubbo.configcenter.DynamicConfigurationFactory; -import org.apache.dubbo.configcenter.support.nop.NopDynamicConfigurationFactory; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * - */ -public class AbstractDynamicConfigurationTest { - public DynamicConfigurationFactory configurationFactory = ExtensionLoader.getExtensionLoader(DynamicConfigurationFactory.class).getExtension("mock"); - public URL url = URL.valueOf("nop://127.0.0.1:10880/DynamicConfiguration"); - - @Test - public void testInit() { - DynamicConfiguration configuration1 = configurationFactory.getDynamicConfiguration(url); - DynamicConfiguration configuration2 = configurationFactory.getDynamicConfiguration(url); - Assertions.assertEquals(configuration1, configuration2); - } - - @Test - public void testDefaultExtension() { - DynamicConfigurationFactory factory = ExtensionLoader.getExtensionLoader(DynamicConfigurationFactory.class).getDefaultExtension(); - Assertions.assertTrue(factory instanceof NopDynamicConfigurationFactory); - } -} diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfiguration.java deleted file mode 100644 index 05ce68b32d7..00000000000 --- a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfiguration.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.configcenter.mock; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; - -/** - * - */ -public class MockDynamicConfiguration implements DynamicConfiguration { - public MockDynamicConfiguration(URL url) { - } - - @Override - public Object getInternalProperty(String key) { - return null; - } - - @Override - public void addListener(String key, String group, ConfigurationListener listener) { - - } - - @Override - public void removeListener(String key, String group, ConfigurationListener listener) { - - } - - @Override - public String getConfig(String key, String group, long timeout) throws IllegalStateException { - return null; - } - - @Override - public String getConfigs(String key, String group, long timeout) throws IllegalStateException { - return null; - } -} diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory b/dubbo-configcenter/dubbo-configcenter-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory deleted file mode 100644 index 211d45e8a7c..00000000000 --- a/dubbo-configcenter/dubbo-configcenter-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory +++ /dev/null @@ -1 +0,0 @@ -mock=org.apache.dubbo.configcenter.mock.MockDynamicConfigurationFactory \ No newline at end of file diff --git a/dubbo-configcenter/dubbo-configcenter-apollo/pom.xml b/dubbo-configcenter/dubbo-configcenter-apollo/pom.xml index 26d2e88fb28..6f3d8de8b15 100644 --- a/dubbo-configcenter/dubbo-configcenter-apollo/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-apollo/pom.xml @@ -32,7 +32,7 @@ org.apache.dubbo - dubbo-configcenter-api + dubbo-common ${project.parent.version} diff --git a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java index f67c1e03236..e092b7155d6 100644 --- a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java @@ -17,13 +17,13 @@ package org.apache.dubbo.configcenter.support.apollo; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigChangeType; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigChangeType; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.ConfigChangeListener; @@ -42,12 +42,12 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.stream.Collectors; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_CHECK_KEY; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_CLUSTER_KEY; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_NAMESPACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; -import static org.apache.dubbo.configcenter.Constants.CONFIG_CHECK_KEY; -import static org.apache.dubbo.configcenter.Constants.CONFIG_CLUSTER_KEY; -import static org.apache.dubbo.configcenter.Constants.CONFIG_NAMESPACE_KEY; /** * Apollo implementation, https://github.com/ctripcorp/apollo diff --git a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationFactory.java b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationFactory.java index b7e877c2096..6a8ce304f4b 100644 --- a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationFactory.java +++ b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationFactory.java @@ -17,8 +17,8 @@ package org.apache.dubbo.configcenter.support.apollo; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory; -import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; /** * diff --git a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory similarity index 100% rename from dubbo-configcenter/dubbo-configcenter-apollo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory rename to dubbo-configcenter/dubbo-configcenter-apollo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory diff --git a/dubbo-configcenter/dubbo-configcenter-consul/pom.xml b/dubbo-configcenter/dubbo-configcenter-consul/pom.xml index 6f8b24ff666..830c6bd71b4 100644 --- a/dubbo-configcenter/dubbo-configcenter-consul/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-consul/pom.xml @@ -29,7 +29,7 @@ org.apache.dubbo - dubbo-configcenter-api + dubbo-common ${project.parent.version} diff --git a/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java index 2e67bbd7c89..030398481a3 100644 --- a/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java @@ -18,14 +18,14 @@ package org.apache.dubbo.configcenter.consul; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigChangeType; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigChangeType; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; @@ -39,9 +39,9 @@ import java.util.concurrent.ExecutorService; import static java.util.concurrent.Executors.newCachedThreadPool; +import static org.apache.dubbo.common.config.configcenter.ConfigChangeType.ADDED; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_NAMESPACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; -import static org.apache.dubbo.configcenter.Constants.CONFIG_NAMESPACE_KEY; -import static org.apache.dubbo.configcenter.ConfigChangeType.ADDED; /** * config center implementation for consul diff --git a/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfigurationFactory.java b/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfigurationFactory.java index 813b6174662..980a1562348 100644 --- a/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfigurationFactory.java +++ b/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfigurationFactory.java @@ -18,8 +18,8 @@ package org.apache.dubbo.configcenter.consul; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory; -import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; /** * Config center factory for consul diff --git a/dubbo-configcenter/dubbo-configcenter-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory b/dubbo-configcenter/dubbo-configcenter-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory similarity index 100% rename from dubbo-configcenter/dubbo-configcenter-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory rename to dubbo-configcenter/dubbo-configcenter-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml b/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml index 66d2dfa0f42..76eaeb3a368 100644 --- a/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml @@ -32,11 +32,6 @@ The etcd implementation of the config-center api - - org.apache.dubbo - dubbo-configcenter-api - ${project.parent.version} - io.etcd jetcd-launcher @@ -47,6 +42,12 @@ testcontainers test + + + org.apache.dubbo + dubbo-common + ${project.parent.version} + org.apache.dubbo dubbo-remoting-etcd3 diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java index 10c50b66dd0..6925f030a93 100644 --- a/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java @@ -18,11 +18,11 @@ package org.apache.dubbo.configcenter.support.etcd; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigChangeType; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigChangeType; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.remoting.etcd.StateListener; import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient; @@ -40,8 +40,8 @@ import java.util.concurrent.ConcurrentMap; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_NAMESPACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; -import static org.apache.dubbo.configcenter.Constants.CONFIG_NAMESPACE_KEY; /** * The etcd implementation of {@link DynamicConfiguration} diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationFactory.java b/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationFactory.java index 02e91a62db7..269cee6046e 100644 --- a/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationFactory.java +++ b/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationFactory.java @@ -18,8 +18,8 @@ package org.apache.dubbo.configcenter.support.etcd; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory; -import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; /** * The etcd implementation of {@link AbstractDynamicConfigurationFactory} diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory b/dubbo-configcenter/dubbo-configcenter-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory similarity index 100% rename from dubbo-configcenter/dubbo-configcenter-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory rename to dubbo-configcenter/dubbo-configcenter-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java index d56f3c4649c..8b4f739be17 100644 --- a/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java +++ b/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java @@ -18,8 +18,8 @@ package org.apache.dubbo.configcenter.support.etcd; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/pom.xml b/dubbo-configcenter/dubbo-configcenter-nacos/pom.xml index bd5397c92b6..68dc27150fa 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-nacos/pom.xml @@ -34,7 +34,7 @@ org.apache.dubbo - dubbo-configcenter-api + dubbo-common ${project.parent.version} diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java index 96bec25f1dd..8c827a332f1 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java @@ -18,13 +18,13 @@ package org.apache.dubbo.configcenter.support.nacos; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigChangeType; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigChangeType; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; import com.alibaba.nacos.api.NacosFactory; import com.alibaba.nacos.api.config.ConfigService; @@ -46,9 +46,9 @@ import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY; import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR; import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_NAMESPACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_CHAR_SEPERATOR; import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPERATOR; -import static org.apache.dubbo.configcenter.Constants.CONFIG_NAMESPACE_KEY; import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY; /** diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java index 804e216a590..61c02b48cfb 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java +++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java @@ -18,9 +18,9 @@ package org.apache.dubbo.configcenter.support.nacos; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory; -import org.apache.dubbo.configcenter.DynamicConfiguration; import com.alibaba.nacos.api.PropertyKeyConst; diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory similarity index 100% rename from dubbo-configcenter/dubbo-configcenter-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory rename to dubbo-configcenter/dubbo-configcenter-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java index ff785b974a6..e48699c6658 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java +++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java @@ -18,8 +18,8 @@ package org.apache.dubbo.configcenter.support.nacos; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml b/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml index 9f028ce05c7..54977b8954c 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml @@ -29,7 +29,7 @@ org.apache.dubbo - dubbo-configcenter-api + dubbo-common ${project.parent.version} diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/CacheListener.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/CacheListener.java index 3eaa96b28a9..baaaf8e4c64 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/CacheListener.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/CacheListener.java @@ -16,11 +16,11 @@ */ package org.apache.dubbo.configcenter.support.zookeeper; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigChangeType; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigChangeType; -import org.apache.dubbo.configcenter.ConfigurationListener; import org.apache.dubbo.remoting.zookeeper.DataListener; import org.apache.dubbo.remoting.zookeeper.EventType; diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java index 5b034ca3740..8ee45817d36 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java @@ -17,10 +17,10 @@ package org.apache.dubbo.configcenter.support.zookeeper; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; @@ -36,8 +36,8 @@ import static java.util.Collections.emptySortedSet; import static java.util.Collections.unmodifiableSortedSet; +import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_NAMESPACE_KEY; import static org.apache.dubbo.common.utils.CollectionUtils.isEmpty; -import static org.apache.dubbo.configcenter.Constants.CONFIG_NAMESPACE_KEY; /** * diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationFactory.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationFactory.java index 4d78133dbaf..0eb307ceac4 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationFactory.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationFactory.java @@ -17,8 +17,8 @@ package org.apache.dubbo.configcenter.support.zookeeper; import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory; -import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; /** diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory similarity index 100% rename from dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.configcenter.DynamicConfigurationFactory rename to dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java index df440acc620..c9fb747554e 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java @@ -17,12 +17,12 @@ package org.apache.dubbo.configcenter.support.zookeeper; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.NetUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; -import org.apache.dubbo.configcenter.DynamicConfigurationFactory; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; diff --git a/dubbo-configcenter/pom.xml b/dubbo-configcenter/pom.xml index 0de20d319c7..312fc3cbc3e 100644 --- a/dubbo-configcenter/pom.xml +++ b/dubbo-configcenter/pom.xml @@ -30,7 +30,6 @@ - dubbo-configcenter-api dubbo-configcenter-zookeeper dubbo-configcenter-apollo dubbo-configcenter-consul diff --git a/dubbo-container/dubbo-container-log4j/pom.xml b/dubbo-container/dubbo-container-log4j/pom.xml index a83b66165f5..d4503df1c88 100644 --- a/dubbo-container/dubbo-container-log4j/pom.xml +++ b/dubbo-container/dubbo-container-log4j/pom.xml @@ -34,10 +34,5 @@ dubbo-container-api ${project.parent.version} - - org.apache.dubbo - dubbo-configcenter-api - ${project.parent.version} - \ No newline at end of file diff --git a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/pom.xml b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/pom.xml index f668a8540db..e273e313737 100644 --- a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/pom.xml @@ -33,6 +33,11 @@ + + org.apache.dubbo + dubbo-config-api + ${project.parent.version} + org.apache.dubbo dubbo-demo-interface diff --git a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/pom.xml b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/pom.xml index ff5d9ced5b7..04a2ae29ff0 100644 --- a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/pom.xml +++ b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/pom.xml @@ -35,6 +35,11 @@ + + org.apache.dubbo + dubbo-config-api + ${project.parent.version} + org.apache.dubbo dubbo-demo-interface diff --git a/dubbo-metadata-report/dubbo-metadata-definition/pom.xml b/dubbo-metadata-report/dubbo-metadata-definition/pom.xml deleted file mode 100644 index 093c7e29824..00000000000 --- a/dubbo-metadata-report/dubbo-metadata-definition/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - dubbo-metadata-report - org.apache.dubbo - ${revision} - - 4.0.0 - dubbo-metadata-definition - - - - - com.google.code.gson - gson - - - org.apache.dubbo - dubbo-common - ${project.parent.version} - - - diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory deleted file mode 100644 index bf840236d34..00000000000 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory +++ /dev/null @@ -1 +0,0 @@ -JTest=org.apache.dubbo.metadata.store.test.JTestMetadataReportFactory4Test diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/pom.xml b/dubbo-metadata/dubbo-metadata-api/pom.xml similarity index 60% rename from dubbo-metadata-report/dubbo-metadata-report-api/pom.xml rename to dubbo-metadata/dubbo-metadata-api/pom.xml index b892598c800..3f5665a0917 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/pom.xml +++ b/dubbo-metadata/dubbo-metadata-api/pom.xml @@ -14,57 +14,55 @@ See the License for the specific language governing permissions and limitations under the License. --> - + - dubbo-metadata-report org.apache.dubbo + dubbo-metadata ${revision} + ../pom.xml 4.0.0 - dubbo-metadata-report-api + dubbo-metadata-api jar - - false - + dubbo-metadata-api + The metadata module of Dubbo project + org.apache.dubbo - dubbo-cluster + dubbo-rpc-api ${project.parent.version} + true + org.apache.dubbo - dubbo-common + dubbo-cluster ${project.parent.version} - org.apache.dubbo - dubbo-container-api - ${project.parent.version} - - - org.mortbay.jetty - jetty - - + com.google.code.gson + gson + org.apache.dubbo - dubbo-remoting-zookeeper + dubbo-configcenter-zookeeper ${project.parent.version} test + - org.apache.dubbo - dubbo-metadata-definition - ${project.parent.version} - - - com.google.code.gson - gson + org.apache.curator + curator-test + test + - + + \ No newline at end of file diff --git a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java similarity index 98% rename from dubbo-metadata/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java index f535a517dad..287ba734c52 100644 --- a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java @@ -16,9 +16,9 @@ */ package org.apache.dubbo.metadata; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.Collections; diff --git a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/MetadataService.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java similarity index 95% rename from dubbo-metadata/src/main/java/org/apache/dubbo/metadata/MetadataService.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java index f73d5f6e8cb..7dba967919b 100644 --- a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/MetadataService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java @@ -32,7 +32,7 @@ * {@link #getExportedURLs()} and {@link #getSubscribedURLs()} respectively. What's more, {@link MetadataService} * also providers the fine-grain methods for the precise queries. * - * @see LocalMetadataService + * @see WritableMetadataService * @since 2.7.3 */ public interface MetadataService { @@ -136,6 +136,17 @@ default List getExportedURLs(String serviceInterface, String group, Stri */ List getExportedURLs(String serviceInterface, String group, String version, String protocol); + /** + * Interface definition. + * @return + */ + String getServiceDefinition(String interfaceName, String version, String group); + + /** + * Interface definition. + * @return + */ + String getServiceDefinition(String serviceKey); /** * Convert the multiple {@link URL urls} to a {@link List list} of {@link URL urls} diff --git a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/MetadataServiceExporter.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceExporter.java similarity index 100% rename from dubbo-metadata/src/main/java/org/apache/dubbo/metadata/MetadataServiceExporter.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceExporter.java diff --git a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/ServiceNameMapping.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceNameMapping.java similarity index 100% rename from dubbo-metadata/src/main/java/org/apache/dubbo/metadata/ServiceNameMapping.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceNameMapping.java diff --git a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/LocalMetadataService.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/WritableMetadataService.java similarity index 79% rename from dubbo-metadata/src/main/java/org/apache/dubbo/metadata/LocalMetadataService.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/WritableMetadataService.java index 172409524ec..27f75a16857 100644 --- a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/LocalMetadataService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/WritableMetadataService.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.extension.SPI; +import org.apache.dubbo.metadata.store.InMemoryWritableMetadataService; import org.apache.dubbo.rpc.model.ApplicationModel; import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader; @@ -29,8 +30,8 @@ * * @since 2.7.3 */ -@SPI("default") -public interface LocalMetadataService extends MetadataService { +@SPI("local") +public interface WritableMetadataService extends MetadataService { /** * Gets the current Dubbo Service name @@ -74,15 +75,20 @@ default String serviceName() { */ boolean unsubscribeURL(URL url); + void publishServiceDefinition(URL providerUrl); /** - * Get {@link ExtensionLoader#getDefaultExtension() the defautl extension} of {@link LocalMetadataService} + * Get {@link ExtensionLoader#getDefaultExtension() the defautl extension} of {@link WritableMetadataService} * * @return non-null - * @see InMemoryLocalMetadataService + * @see InMemoryWritableMetadataService */ - public static LocalMetadataService getDefaultExtension() { - return getExtensionLoader(LocalMetadataService.class).getDefaultExtension(); + static WritableMetadataService getDefaultExtension() { + return getExtensionLoader(WritableMetadataService.class).getDefaultExtension(); + } + + static WritableMetadataService getExtension(String name) { + return getExtensionLoader(WritableMetadataService.class).getExtension(name); } } diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuilder.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuilder.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuilder.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilder.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilder.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilder.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/ArrayTypeBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/ArrayTypeBuilder.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/ArrayTypeBuilder.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/ArrayTypeBuilder.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/CollectionTypeBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/CollectionTypeBuilder.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/CollectionTypeBuilder.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/CollectionTypeBuilder.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/DefaultTypeBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/DefaultTypeBuilder.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/DefaultTypeBuilder.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/DefaultTypeBuilder.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/EnumTypeBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/EnumTypeBuilder.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/EnumTypeBuilder.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/EnumTypeBuilder.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/MapTypeBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/MapTypeBuilder.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/MapTypeBuilder.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/MapTypeBuilder.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/TypeBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/TypeBuilder.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/TypeBuilder.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/builder/TypeBuilder.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/FullServiceDefinition.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/FullServiceDefinition.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/FullServiceDefinition.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/FullServiceDefinition.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java similarity index 97% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java index 41ebda505cd..36356216c8b 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.metadata.definition.model; +import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -24,7 +25,7 @@ /** * 2015/1/27. */ -public class MethodDefinition { +public class MethodDefinition implements Serializable { private String name; private String[] parameterTypes; diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java similarity index 97% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java index ebc586d2629..8b202df8167 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.metadata.definition.model; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -23,7 +24,7 @@ /** * 2015/1/27. */ -public class ServiceDefinition { +public class ServiceDefinition implements Serializable { private String canonicalName; private String codeSource; diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java similarity index 97% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java index bb434dc848b..4ae4f462aa7 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java @@ -18,6 +18,7 @@ import com.google.gson.annotations.SerializedName; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -27,7 +28,7 @@ /** * 2015/1/27. */ -public class TypeDefinition { +public class TypeDefinition implements Serializable { private String id; private String type; diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/ClassUtils.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/util/ClassUtils.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/ClassUtils.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/util/ClassUtils.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/JaketConfigurationUtils.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/util/JaketConfigurationUtils.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/JaketConfigurationUtils.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/util/JaketConfigurationUtils.java diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReport.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReport.java similarity index 65% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReport.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReport.java index 1afcc83438b..ab6f7a85a28 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReport.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReport.java @@ -14,20 +14,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.store; +package org.apache.dubbo.metadata.report; -import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.metadata.definition.model.ServiceDefinition; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; +import java.util.List; import java.util.Map; /** */ public interface MetadataReport { - void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, FullServiceDefinition serviceDefinition); + void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, ServiceDefinition serviceDefinition); void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, Map serviceParameterMap); + void saveMetadata(URL url); + + void removeMetadata(URL url); + + List getExportedURLs(MetadataIdentifier metadataIdentifier); + + List getSubscribedURLs(); + + String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier); } diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReportFactory.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReportFactory.java similarity index 96% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReportFactory.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReportFactory.java index 7f42da75aa7..1414c8b2138 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReportFactory.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReportFactory.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.store; +package org.apache.dubbo.metadata.report; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.Adaptive; diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java similarity index 82% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java index f9b7e4c35f3..7ffa2a9ed4c 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java @@ -14,9 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.identifier; +package org.apache.dubbo.metadata.report.identifier; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.StringUtils; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; @@ -67,7 +68,11 @@ public String getUniqueKey(KeyTypeEnum keyType) { } public String getIdentifierKey() { - return serviceInterface + SEPARATOR + (version == null ? "" : version + SEPARATOR) + (group == null ? "" : group + SEPARATOR) + side + SEPARATOR + application; + return serviceInterface + + (version == null ? "" : (SEPARATOR + version)) + + (group == null ? "" : (SEPARATOR + version)) + + (side == null ? "" : (SEPARATOR + side)) + + (getApplication() == null ? "" : (SEPARATOR + getApplication())); } private String getFilePathKey() { @@ -75,8 +80,12 @@ private String getFilePathKey() { } private String getFilePathKey(String pathTag) { - return pathTag + PATH_SEPARATOR + toServicePath() + PATH_SEPARATOR + (version == null ? "" : (version + PATH_SEPARATOR)) - + (group == null ? "" : (group + PATH_SEPARATOR)) + side + PATH_SEPARATOR + getApplication(); + return pathTag + + (StringUtils.isEmpty(toServicePath()) ? "" : (PATH_SEPARATOR + toServicePath())) + + (version == null ? "" : (PATH_SEPARATOR + version)) + + (group == null ? "" : (PATH_SEPARATOR + group)) + + (side == null ? "" : (PATH_SEPARATOR + side)) + + (getApplication() == null ? "" : (PATH_SEPARATOR + getApplication())); } private String toServicePath() { diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java similarity index 88% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java index 12085084cbd..a64c88737fb 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.support; +package org.apache.dubbo.metadata.report.support; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; @@ -22,8 +22,9 @@ import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; -import org.apache.dubbo.metadata.store.MetadataReport; +import org.apache.dubbo.metadata.definition.model.ServiceDefinition; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import com.google.gson.Gson; @@ -37,6 +38,7 @@ import java.nio.channels.FileLock; import java.util.Calendar; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; @@ -55,13 +57,13 @@ import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; -import static org.apache.dubbo.metadata.support.Constants.CYCLE_REPORT_KEY; -import static org.apache.dubbo.metadata.support.Constants.DEFAULT_METADATA_REPORT_CYCLE_REPORT; -import static org.apache.dubbo.metadata.support.Constants.DEFAULT_METADATA_REPORT_RETRY_PERIOD; -import static org.apache.dubbo.metadata.support.Constants.DEFAULT_METADATA_REPORT_RETRY_TIMES; -import static org.apache.dubbo.metadata.support.Constants.RETRY_PERIOD_KEY; -import static org.apache.dubbo.metadata.support.Constants.RETRY_TIMES_KEY; -import static org.apache.dubbo.metadata.support.Constants.SYNC_REPORT_KEY; +import static org.apache.dubbo.metadata.report.support.Constants.CYCLE_REPORT_KEY; +import static org.apache.dubbo.metadata.report.support.Constants.DEFAULT_METADATA_REPORT_CYCLE_REPORT; +import static org.apache.dubbo.metadata.report.support.Constants.DEFAULT_METADATA_REPORT_RETRY_PERIOD; +import static org.apache.dubbo.metadata.report.support.Constants.DEFAULT_METADATA_REPORT_RETRY_TIMES; +import static org.apache.dubbo.metadata.report.support.Constants.RETRY_PERIOD_KEY; +import static org.apache.dubbo.metadata.report.support.Constants.RETRY_TIMES_KEY; +import static org.apache.dubbo.metadata.report.support.Constants.SYNC_REPORT_KEY; /** * @@ -225,7 +227,7 @@ public void run() { } @Override - public void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, FullServiceDefinition serviceDefinition) { + public void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, ServiceDefinition serviceDefinition) { if (syncReport) { storeProviderMetadataTask(providerMetadataIdentifier, serviceDefinition); } else { @@ -233,7 +235,7 @@ public void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, } } - private void storeProviderMetadataTask(MetadataIdentifier providerMetadataIdentifier, FullServiceDefinition serviceDefinition) { + private void storeProviderMetadataTask(MetadataIdentifier providerMetadataIdentifier, ServiceDefinition serviceDefinition) { try { if (logger.isInfoEnabled()) { logger.info("store provider metadata. Identifier : " + providerMetadataIdentifier + "; definition: " + serviceDefinition); @@ -281,6 +283,35 @@ public void storeConsumerMetadataTask(MetadataIdentifier consumerMetadataIdentif } } + @Override + public void saveMetadata(URL url) { + if (syncReport) { + doSaveMetadata(url); + } else { + reportCacheExecutor.execute(() -> doSaveMetadata(url)); + } + } + + @Override + public void removeMetadata(URL url) { + if (syncReport) { + doRemoveMetadata(url); + } else { + reportCacheExecutor.execute(() -> doRemoveMetadata(url)); + } + } + + @Override + public List getExportedURLs(MetadataIdentifier metadataIdentifier) { + // TODO, fallback to local cache + return doGetExportedURLs(); + } + + @Override + public List getSubscribedURLs() { + // TODO, fallback to local cache + return doGetSubscribedURLs(); + } String getProtocol(URL url) { String protocol = url.getParameter(SIDE_KEY); @@ -391,4 +422,12 @@ void cancelRetryTask() { protected abstract void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, String serviceParameterString); + protected abstract void doSaveMetadata(URL url); + + protected abstract void doRemoveMetadata(URL url); + + protected abstract List doGetExportedURLs(); + + protected abstract List doGetSubscribedURLs(); + } diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReportFactory.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactory.java similarity index 87% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReportFactory.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactory.java index fd4895c584c..9776e8c287a 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReportFactory.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactory.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.support; +package org.apache.dubbo.metadata.report.support; import org.apache.dubbo.common.URL; -import org.apache.dubbo.metadata.store.MetadataReport; -import org.apache.dubbo.metadata.store.MetadataReportFactory; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.MetadataReportFactory; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -31,7 +31,7 @@ public abstract class AbstractMetadataReportFactory implements MetadataReportFac // The lock for the acquisition process of the registry private static final ReentrantLock LOCK = new ReentrantLock(); - // Registry Collection Map + // Registry Collection Map private static final Map SERVICE_STORE_MAP = new ConcurrentHashMap(); @Override @@ -39,7 +39,7 @@ public MetadataReport getMetadataReport(URL url) { url = url.setPath(MetadataReport.class.getName()) .removeParameters(EXPORT_KEY, REFER_KEY); String key = url.toServiceString(); - // Lock the registry access process to ensure a single instance of the registry + // Lock the metadata access process to ensure a single instance of the metadata instance LOCK.lock(); try { MetadataReport metadataReport = SERVICE_STORE_MAP.get(key); diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/Constants.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/Constants.java similarity index 96% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/Constants.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/Constants.java index 3d74b2bbad9..8cee825051e 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/Constants.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/Constants.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.dubbo.metadata.support; +package org.apache.dubbo.metadata.report.support; public interface Constants { String METADATA_REPORT_KEY = "metadata"; diff --git a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/InMemoryLocalMetadataService.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/InMemoryWritableMetadataService.java similarity index 76% rename from dubbo-metadata/src/main/java/org/apache/dubbo/metadata/InMemoryLocalMetadataService.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/InMemoryWritableMetadataService.java index 947a9fbd284..41779036bd2 100644 --- a/dubbo-metadata/src/main/java/org/apache/dubbo/metadata/InMemoryLocalMetadataService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/InMemoryWritableMetadataService.java @@ -14,11 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata; +package org.apache.dubbo.metadata.store; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.metadata.WritableMetadataService; +import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; +import org.apache.dubbo.metadata.definition.model.ServiceDefinition; + +import com.google.gson.Gson; import java.util.Collection; import java.util.LinkedList; @@ -34,18 +41,19 @@ import static java.util.Collections.emptyList; import static java.util.Collections.unmodifiableList; import static org.apache.dubbo.common.URL.buildKey; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.utils.CollectionUtils.isEmpty; /** - * The {@link LocalMetadataService} implementation stores the metadata of Dubbo services in memory locally when they + * The {@link WritableMetadataService} implementation stores the metadata of Dubbo services in memory locally when they * exported. * * @see MetadataService - * @see LocalMetadataService + * @see WritableMetadataService * @since 2.7.3 */ -public class InMemoryLocalMetadataService implements LocalMetadataService { +public class InMemoryWritableMetadataService implements WritableMetadataService { /** * The class name of {@link MetadataService} @@ -75,6 +83,8 @@ public class InMemoryLocalMetadataService implements LocalMetadataService { */ private final ConcurrentMap> subscribedServiceURLs = new ConcurrentHashMap<>(); + private final ConcurrentHashMap serviceDefinitions = new ConcurrentHashMap<>(); + // ==================================================================================== // @Override @@ -117,6 +127,35 @@ public boolean unsubscribeURL(URL url) { return removeURL(subscribedServiceURLs, url); } + @Override + public void publishServiceDefinition(URL providerUrl) { + try { + String interfaceName = providerUrl.getParameter(INTERFACE_KEY); + if (StringUtils.isNotEmpty(interfaceName)) { + Class interfaceClass = Class.forName(interfaceName); + ServiceDefinition serviceDefinition = ServiceDefinitionBuilder.build(interfaceClass); + Gson gson = new Gson(); + String data = gson.toJson(serviceDefinition); + serviceDefinitions.put(providerUrl.getServiceKey(), data); + return; + } + logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString()); + } catch (ClassNotFoundException e) { + //ignore error + logger.error("publishProvider getServiceDescriptor error. providerUrl: " + providerUrl.toFullString(), e); + } + } + + @Override + public String getServiceDefinition(String interfaceName, String version, String group) { + return serviceDefinitions.get(URL.buildKey(interfaceName, group, version)); + } + + @Override + public String getServiceDefinition(String serviceKey) { + return serviceDefinitions.get(serviceKey); + } + private boolean addURL(Map> serviceURLs, URL url) { return executeMutually(() -> { List urls = serviceURLs.computeIfAbsent(url.getServiceKey(), s -> new LinkedList()); diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataService.java similarity index 55% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java rename to dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataService.java index 06d39b6f6ac..c52f5c8aa12 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.integration; +package org.apache.dubbo.metadata.store; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; @@ -22,15 +22,19 @@ import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.UrlUtils; +import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; -import org.apache.dubbo.metadata.store.MetadataReport; -import org.apache.dubbo.metadata.store.MetadataReportFactory; +import org.apache.dubbo.metadata.definition.model.ServiceDefinition; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.MetadataReportFactory; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.rpc.RpcException; -import java.util.function.Supplier; +import java.util.List; +import java.util.function.Consumer; import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; @@ -41,23 +45,21 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.metadata.support.Constants.METADATA_REPORT_KEY; +import static org.apache.dubbo.metadata.report.support.Constants.METADATA_REPORT_KEY; /** * @since 2.7.0 */ -public class MetadataReportService { +public class RemoteWritableMetadataService implements WritableMetadataService { protected final Logger logger = LoggerFactory.getLogger(getClass()); - private static volatile MetadataReportService metadataReportService; - private static Object lock = new Object(); - private MetadataReportFactory metadataReportFactory = ExtensionLoader.getExtensionLoader(MetadataReportFactory.class).getAdaptiveExtension(); - MetadataReport metadataReport; - URL metadataReportUrl; + private MetadataReport metadataReport; + + public RemoteWritableMetadataService() {} - MetadataReportService(URL metadataReportURL) { + public void initMetadataReport(URL metadataReportURL) { if (METADATA_REPORT_KEY.equals(metadataReportURL.getProtocol())) { String protocol = metadataReportURL.getParameter(METADATA_REPORT_KEY, DEFAULT_DIRECTORY); metadataReportURL = URLBuilder.from(metadataReportURL) @@ -65,27 +67,36 @@ public class MetadataReportService { .removeParameter(METADATA_REPORT_KEY) .build(); } - this.metadataReportUrl = metadataReportURL; - metadataReport = metadataReportFactory.getMetadataReport(this.metadataReportUrl); - + metadataReport = metadataReportFactory.getMetadataReport(metadataReportURL); } + public MetadataReport getMetadataReport() { + return metadataReport; + } - public static MetadataReportService instance(Supplier metadataReportUrl) { - if (metadataReportService == null) { - synchronized (lock) { - if (metadataReportService == null) { - URL metadataReportURLTmp = metadataReportUrl.get(); - if (metadataReportURLTmp == null) { - return null; - } - metadataReportService = new MetadataReportService(metadataReportURLTmp); - } + @Override + public void publishServiceDefinition(URL providerUrl) { + try { + String interfaceName = providerUrl.getParameter(INTERFACE_KEY); + if (StringUtils.isNotEmpty(interfaceName)) { + Class interfaceClass = Class.forName(interfaceName); + ServiceDefinition serviceDefinition = ServiceDefinitionBuilder.build(interfaceClass); + metadataReport.storeProviderMetadata(new MetadataIdentifier(providerUrl.getServiceInterface(), + providerUrl.getParameter(VERSION_KEY), providerUrl.getParameter(GROUP_KEY), + null, null), serviceDefinition); + return; } + logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString()); + } catch (ClassNotFoundException e) { + //ignore error + logger.error("publishProvider getServiceDescriptor error. providerUrl: " + providerUrl.toFullString(), e); } - return metadataReportService; + + // backward compatibility + publishProvider(providerUrl); } + @Deprecated public void publishProvider(URL providerUrl) throws RpcException { //first add into the list // remove the individul param @@ -108,6 +119,7 @@ public void publishProvider(URL providerUrl) throws RpcException { } } + @Deprecated public void publishConsumer(URL consumerURL) throws RpcException { consumerURL = consumerURL.removeParameters(PID_KEY, TIMESTAMP_KEY, Constants.BIND_IP_KEY, Constants.BIND_PORT_KEY, TIMESTAMP_KEY); metadataReport.storeConsumerMetadata(new MetadataIdentifier(consumerURL.getServiceInterface(), @@ -115,4 +127,58 @@ public void publishConsumer(URL consumerURL) throws RpcException { consumerURL.getParameter(APPLICATION_KEY)), consumerURL.getParameters()); } + @Override + public boolean exportURL(URL url) { + return throwableAction(metadataReport::saveMetadata, url); + } + + @Override + public boolean unexportURL(URL url) { + return throwableAction(metadataReport::removeMetadata, url); + } + + @Override + public boolean subscribeURL(URL url) { + return throwableAction(metadataReport::saveMetadata, url); + } + + @Override + public boolean unsubscribeURL(URL url) { + return throwableAction(metadataReport::removeMetadata, url); + } + + @Override + public List getSubscribedURLs() { + return metadataReport.getSubscribedURLs(); + } + + // TODO, protocol should be used + @Override + public List getExportedURLs(String serviceInterface, String group, String version, String protocol) { + return metadataReport.getExportedURLs(new MetadataIdentifier(serviceInterface, group, version, null, null)); + } + + @Override + public String getServiceDefinition(String interfaceName, String version, String group) { + return metadataReport.getServiceDefinition(new MetadataIdentifier(interfaceName, + version, group, null, null)); + } + + @Override + public String getServiceDefinition(String serviceKey) { + String[] services = UrlUtils.parseServiceKey(serviceKey); + return metadataReport.getServiceDefinition(new MetadataIdentifier(services[1], + services[0], services[2], null, null)); + } + + private boolean throwableAction(Consumer consumer, URL url) { + try { + consumer.accept(url); + } catch (Exception e) { + logger.error("Failed to remove url metadata to remote center, url is: " + url); + return false; + } + return true; + } + } diff --git a/dubbo-metadata/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping similarity index 100% rename from dubbo-metadata/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping rename to dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.WritableMetadataService b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.WritableMetadataService new file mode 100644 index 00000000000..26bc942e704 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.WritableMetadataService @@ -0,0 +1,2 @@ +local=org.apache.dubbo.metadata.store.InMemoryWritableMetadataService +remote=org.apache.dubbo.metadata.store.RemoteWritableMetadataService \ No newline at end of file diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder rename to dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder diff --git a/dubbo-metadata/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java similarity index 96% rename from dubbo-metadata/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java index 95e7a1689ad..4fa96178942 100644 --- a/dubbo-metadata/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java @@ -18,9 +18,9 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.Environment; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory; import org.apache.dubbo.common.utils.NetUtils; -import org.apache.dubbo.configcenter.DynamicConfiguration; -import org.apache.dubbo.configcenter.DynamicConfigurationFactory; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.curator.framework.CuratorFramework; diff --git a/dubbo-metadata/src/test/java/org/apache/dubbo/metadata/InMemoryLocalMetadataServiceTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/InMemoryWritableMetadataServiceTest.java similarity index 95% rename from dubbo-metadata/src/test/java/org/apache/dubbo/metadata/InMemoryLocalMetadataServiceTest.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/InMemoryWritableMetadataServiceTest.java index 406e4aeb98e..8ffbd4cddd0 100644 --- a/dubbo-metadata/src/test/java/org/apache/dubbo/metadata/InMemoryLocalMetadataServiceTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/InMemoryWritableMetadataServiceTest.java @@ -17,6 +17,7 @@ package org.apache.dubbo.metadata; import org.apache.dubbo.common.URL; +import org.apache.dubbo.metadata.store.InMemoryWritableMetadataService; import org.apache.dubbo.rpc.model.ApplicationModel; import org.junit.jupiter.api.BeforeAll; @@ -34,13 +35,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** - * {@link InMemoryLocalMetadataService} Test + * {@link InMemoryWritableMetadataService} Test * * @since 2.7.3 */ -public class InMemoryLocalMetadataServiceTest { +public class InMemoryWritableMetadataServiceTest { - private LocalMetadataService metadataService = new InMemoryLocalMetadataService(); + private WritableMetadataService metadataService = new InMemoryWritableMetadataService(); private static final String TEST_SERVICE = "org.apache.dubbo.test.TestService"; diff --git a/dubbo-metadata/src/test/java/org/apache/dubbo/metadata/LocalMetadataServiceTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/LocalMetadataServiceTest.java similarity index 82% rename from dubbo-metadata/src/test/java/org/apache/dubbo/metadata/LocalMetadataServiceTest.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/LocalMetadataServiceTest.java index 508a9598738..e34ed13c779 100644 --- a/dubbo-metadata/src/test/java/org/apache/dubbo/metadata/LocalMetadataServiceTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/LocalMetadataServiceTest.java @@ -16,12 +16,14 @@ */ package org.apache.dubbo.metadata; +import org.apache.dubbo.metadata.store.InMemoryWritableMetadataService; + import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; /** - * {@link LocalMetadataService} Test + * {@link WritableMetadataService} Test * * @since 2.7.3 */ @@ -29,6 +31,6 @@ public class LocalMetadataServiceTest { @Test public void testDefaultExtension() { - assertEquals(InMemoryLocalMetadataService.class, LocalMetadataService.getDefaultExtension().getClass()); + assertEquals(InMemoryWritableMetadataService.class, WritableMetadataService.getDefaultExtension().getClass()); } } diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/MetadataTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/MetadataTest.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/MetadataTest.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/MetadataTest.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/MetadataUtils.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/MetadataUtils.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/MetadataUtils.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/MetadataUtils.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuildderTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuildderTest.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuildderTest.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuildderTest.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/ClassExtendsMap.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/ClassExtendsMap.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/ClassExtendsMap.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/ClassExtendsMap.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/ColorEnum.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/ColorEnum.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/ColorEnum.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/ColorEnum.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/OuterClass.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/OuterClass.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/OuterClass.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/OuterClass.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/ResultWithRawCollections.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/ResultWithRawCollections.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/ResultWithRawCollections.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/ResultWithRawCollections.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/TestService.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/TestService.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/common/TestService.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/common/TestService.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/service/ComplexObject.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/service/ComplexObject.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/service/ComplexObject.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/service/ComplexObject.java diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/service/DemoService.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/service/DemoService.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-definition/src/test/java/org/apache/dubbo/metadata/definition/service/DemoService.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/definition/service/DemoService.java diff --git a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java new file mode 100644 index 00000000000..c85ee486a4f --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java @@ -0,0 +1,50 @@ +/* + * 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.identifier; + +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; + +/** + * 2019/1/7 + */ +public class MetadataIdentifierTest { + + @Test + public void testGetUniqueKey() { + String interfaceName = "org.apache.dubbo.metadata.integration.InterfaceNameTestService"; + String version = "1.0.0.zk.md"; + String group = null; + String application = "vic.zk.md"; + MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application); + Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH), + "metadata" + PATH_SEPARATOR + interfaceName + PATH_SEPARATOR + + (version == null ? "" : (version + PATH_SEPARATOR)) + + (group == null ? "" : (group + PATH_SEPARATOR)) + PROVIDER_SIDE + + PATH_SEPARATOR + application); + Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), + interfaceName + MetadataIdentifier.SEPARATOR + + (version == null ? "" : version + MetadataIdentifier.SEPARATOR) + + (group == null ? "" : group + MetadataIdentifier.SEPARATOR) + + PROVIDER_SIDE + MetadataIdentifier.SEPARATOR + application); + } +} diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportFactoryTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactoryTest.java similarity index 80% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportFactoryTest.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactoryTest.java index 62bcbe81365..1dfc4e74ec2 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportFactoryTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactoryTest.java @@ -14,19 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.support; +package org.apache.dubbo.metadata.report.support; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; -import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; -import org.apache.dubbo.metadata.store.MetadataReport; +import org.apache.dubbo.metadata.definition.model.ServiceDefinition; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import com.alibaba.fastjson.JSON; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -41,10 +41,35 @@ protected MetadataReport createMetadataReport(URL url) { return new MetadataReport() { @Override - public void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, FullServiceDefinition serviceDefinition) { + public void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, ServiceDefinition serviceDefinition) { store.put(providerMetadataIdentifier.getIdentifierKey(), JSON.toJSONString(serviceDefinition)); } + @Override + public void saveMetadata(URL url) { + + } + + @Override + public void removeMetadata(URL url) { + + } + + @Override + public List getExportedURLs(MetadataIdentifier metadataIdentifier) { + return null; + } + + @Override + public List getSubscribedURLs() { + return null; + } + + @Override + public String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier) { + return null; + } + @Override public void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, Map serviceParameterMap) { store.put(consumerMetadataIdentifier.getIdentifierKey(), JSON.toJSONString(serviceParameterMap)); diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java similarity index 87% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java index d74c7905437..0faf717a6d2 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java @@ -14,13 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.support; +package org.apache.dubbo.metadata.report.support; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import com.google.gson.Gson; import org.junit.jupiter.api.Assertions; @@ -30,6 +30,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -287,6 +288,31 @@ protected void doStoreProviderMetadata(MetadataIdentifier providerMetadataIdenti protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, String serviceParameterString) { store.put(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), serviceParameterString); } + + @Override + protected void doSaveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected void doRemoveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetExportedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetSubscribedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + public String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } } private static class RetryMetadataReport extends AbstractMetadataReport { @@ -319,6 +345,31 @@ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdenti store.put(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), serviceParameterString); } + @Override + protected void doSaveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected void doRemoveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetExportedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetSubscribedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + public String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + } diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/InterfaceNameTestService.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/InterfaceNameTestService.java similarity index 95% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/InterfaceNameTestService.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/InterfaceNameTestService.java index 3622062c312..e45fc382c6f 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/InterfaceNameTestService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/InterfaceNameTestService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.integration; +package org.apache.dubbo.metadata.store; /** * 2018/9/19 diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/InterfaceNameTestService2.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/InterfaceNameTestService2.java similarity index 95% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/InterfaceNameTestService2.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/InterfaceNameTestService2.java index 1c27f91525b..938efc249ae 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/InterfaceNameTestService2.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/InterfaceNameTestService2.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.integration; +package org.apache.dubbo.metadata.store; /** * 2018/9/19 diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/MetadataReportServiceTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RemoteWritableMeatadataServiceTest.java similarity index 77% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/MetadataReportServiceTest.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RemoteWritableMeatadataServiceTest.java index d6ec49112f5..64867a0d636 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/MetadataReportServiceTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RemoteWritableMeatadataServiceTest.java @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.integration; +package org.apache.dubbo.metadata.store; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.store.test.JTestMetadataReport4Test; +import org.apache.dubbo.metadata.test.JTestMetadataReport4Test; import com.google.gson.Gson; import org.junit.jupiter.api.Assertions; @@ -27,31 +28,27 @@ import org.junit.jupiter.api.Test; import java.util.Map; -import java.util.function.Supplier; + +import static org.apache.dubbo.common.constants.CommonConstants.METADATA_REMOTE; /** * 2018/9/14 */ -public class MetadataReportServiceTest { +public class RemoteWritableMeatadataServiceTest { URL url = URL.valueOf("JTest://" + NetUtils.getLocalAddress().getHostName() + ":4444/org.apache.dubbo.TestService?version=1.0.0&application=vic"); - MetadataReportService metadataReportService1; + RemoteWritableMetadataService metadataReportService1; @BeforeEach public void before() { - metadataReportService1 = MetadataReportService.instance(() -> url); + metadataReportService1 = (RemoteWritableMetadataService) WritableMetadataService.getExtension(METADATA_REMOTE); + metadataReportService1.initMetadataReport(url); } @Test public void testInstance() { - MetadataReportService metadataReportService2 = MetadataReportService.instance(new Supplier() { - @Override - public URL get() { - return url; - } - }); + RemoteWritableMetadataService metadataReportService2 = (RemoteWritableMetadataService) WritableMetadataService.getExtension(METADATA_REMOTE); Assertions.assertSame(metadataReportService1, metadataReportService2); - Assertions.assertEquals(metadataReportService1.metadataReportUrl, url); } @Test @@ -61,9 +58,9 @@ public void testPublishProviderNoInterfaceName() { URL publishUrl = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":4444/org.apache.dubbo.TestService?version=1.0.0&application=vicpubprovder&side=provider"); metadataReportService1.publishProvider(publishUrl); - Assertions.assertTrue(metadataReportService1.metadataReport instanceof JTestMetadataReport4Test); + Assertions.assertTrue(metadataReportService1.getMetadataReport() instanceof JTestMetadataReport4Test); - JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.metadataReport; + JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.getMetadataReport(); Assertions.assertTrue(!jTestMetadataReport4Test.store.containsKey(JTestMetadataReport4Test.getProviderKey(publishUrl))); } @@ -74,9 +71,9 @@ public void testPublishProviderWrongInterface() { URL publishUrl = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":4444/org.apache.dubbo.TestService?version=1.0.0&application=vicpu&interface=ccc&side=provider"); metadataReportService1.publishProvider(publishUrl); - Assertions.assertTrue(metadataReportService1.metadataReport instanceof JTestMetadataReport4Test); + Assertions.assertTrue(metadataReportService1.getMetadataReport() instanceof JTestMetadataReport4Test); - JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.metadataReport; + JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.getMetadataReport(); Assertions.assertTrue(!jTestMetadataReport4Test.store.containsKey(JTestMetadataReport4Test.getProviderKey(publishUrl))); } @@ -88,9 +85,9 @@ public void testPublishProviderContainInterface() throws InterruptedException { metadataReportService1.publishProvider(publishUrl); Thread.sleep(300); - Assertions.assertTrue(metadataReportService1.metadataReport instanceof JTestMetadataReport4Test); + Assertions.assertTrue(metadataReportService1.getMetadataReport() instanceof JTestMetadataReport4Test); - JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.metadataReport; + JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.getMetadataReport(); Assertions.assertTrue(jTestMetadataReport4Test.store.containsKey(JTestMetadataReport4Test.getProviderKey(publishUrl))); String value = jTestMetadataReport4Test.store.get(JTestMetadataReport4Test.getProviderKey(publishUrl)); @@ -108,9 +105,9 @@ public void testPublishConsumer() throws InterruptedException { metadataReportService1.publishConsumer(publishUrl); Thread.sleep(300); - Assertions.assertTrue(metadataReportService1.metadataReport instanceof JTestMetadataReport4Test); + Assertions.assertTrue(metadataReportService1.getMetadataReport() instanceof JTestMetadataReport4Test); - JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.metadataReport; + JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.getMetadataReport(); Assertions.assertTrue(jTestMetadataReport4Test.store.containsKey(JTestMetadataReport4Test.getConsumerKey(publishUrl))); String value = jTestMetadataReport4Test.store.get(JTestMetadataReport4Test.getConsumerKey(publishUrl)); diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/RetryTestService.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RetryTestService.java similarity index 95% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/RetryTestService.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RetryTestService.java index 43f0bbd12d8..9133d25ed75 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/RetryTestService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RetryTestService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.integration; +package org.apache.dubbo.metadata.store; /** * 2018/10/26 diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReport4Test.java similarity index 69% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReport4Test.java index e01a71ab5f4..603a27f5161 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReport4Test.java @@ -14,14 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.store.test; +package org.apache.dubbo.metadata.test; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; -import org.apache.dubbo.metadata.support.AbstractMetadataReport; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReport; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -58,6 +59,26 @@ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdenti store.put(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), serviceParameterString); } + @Override + protected void doSaveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected void doRemoveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetExportedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetSubscribedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + public static String getProviderKey(URL url) { return new MetadataIdentifier(url).getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY); } @@ -66,4 +87,8 @@ public static String getConsumerKey(URL url) { return new MetadataIdentifier(url).getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY); } + @Override + public String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier) { + return null; + } } diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReportFactory4Test.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReportFactory4Test.java similarity index 86% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReportFactory4Test.java rename to dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReportFactory4Test.java index 4e50a073fe1..6e264083008 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReportFactory4Test.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReportFactory4Test.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata.store.test; +package org.apache.dubbo.metadata.test; import org.apache.dubbo.common.URL; -import org.apache.dubbo.metadata.store.MetadataReport; -import org.apache.dubbo.metadata.support.AbstractMetadataReportFactory; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory; /** * ZookeeperRegistryFactory. diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java diff --git a/dubbo-metadata-report/dubbo-metadata-report-consul/pom.xml b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/pom.xml similarity index 96% rename from dubbo-metadata-report/dubbo-metadata-report-consul/pom.xml rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/pom.xml index ad3eb4946e7..fdf0527a83f 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-consul/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/pom.xml @@ -29,7 +29,7 @@ org.apache.dubbo - dubbo-metadata-report-api + dubbo-metadata-api ${project.parent.version} diff --git a/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java similarity index 68% rename from dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java index 42a2f600f63..89227e52db2 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java @@ -20,12 +20,14 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; -import org.apache.dubbo.metadata.support.AbstractMetadataReport; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReport; import org.apache.dubbo.rpc.RpcException; import com.ecwid.consul.v1.ConsulClient; +import java.util.List; + /** * metadata report impl for consul */ @@ -53,6 +55,26 @@ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdenti this.storeMetadata(consumerMetadataIdentifier, value); } + @Override + protected void doSaveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected void doRemoveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetExportedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetSubscribedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + private void storeMetadata(MetadataIdentifier identifier, String v) { try { client.setKVValue(identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), v); @@ -61,4 +83,9 @@ private void storeMetadata(MetadataIdentifier identifier, String v) { throw new RpcException("Failed to put " + identifier + " to consul " + v + ", cause: " + t.getMessage(), t); } } + + @Override + public String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } } diff --git a/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReportFactory.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReportFactory.java similarity index 89% rename from dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReportFactory.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReportFactory.java index 66d7b5e5e45..1d1f5bbd409 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReportFactory.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReportFactory.java @@ -18,8 +18,8 @@ package org.apache.dubbo.metadata.store.consul; import org.apache.dubbo.common.URL; -import org.apache.dubbo.metadata.store.MetadataReport; -import org.apache.dubbo.metadata.support.AbstractMetadataReportFactory; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory; /** * metadata report factory impl for consul diff --git a/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/pom.xml b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/pom.xml similarity index 97% rename from dubbo-metadata-report/dubbo-metadata-report-etcd/pom.xml rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/pom.xml index 45a1413e464..56e4a38f1a5 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-etcd/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/pom.xml @@ -31,7 +31,7 @@ org.apache.dubbo - dubbo-metadata-report-api + dubbo-metadata-api ${project.parent.version} diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java similarity index 76% rename from dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java index 5ee950611a2..d01e02d12b5 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java @@ -36,10 +36,12 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; -import org.apache.dubbo.metadata.support.AbstractMetadataReport; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReport; import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient; +import java.util.List; + import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; @@ -80,6 +82,31 @@ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdenti storeMetadata(consumerMetadataIdentifier, value); } + @Override + protected void doSaveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected void doRemoveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetExportedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetSubscribedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + public String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + private void storeMetadata(MetadataIdentifier identifier, String v) { String key = getNodeKey(identifier); if (!etcdClient.put(key, v)) { diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportFactory.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportFactory.java similarity index 93% rename from dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportFactory.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportFactory.java index f0572b64482..3bb9e92d3ef 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportFactory.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportFactory.java @@ -34,8 +34,8 @@ package org.apache.dubbo.metadata.store.etcd; import org.apache.dubbo.common.URL; -import org.apache.dubbo.metadata.store.MetadataReport; -import org.apache.dubbo.metadata.support.AbstractMetadataReportFactory; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory; /** * MetadataReportFactory to create an Etcd based {@link MetadataReport}. diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadata4TstService.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadata4TstService.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadata4TstService.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadata4TstService.java diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java similarity index 98% rename from dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java index 770b058e070..6ae18ca7871 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java @@ -21,7 +21,7 @@ import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import com.google.gson.Gson; import io.etcd.jetcd.ByteSequence; diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/pom.xml b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/pom.xml similarity index 96% rename from dubbo-metadata-report/dubbo-metadata-report-nacos/pom.xml rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/pom.xml index d324d5c49c1..95fcf158f62 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-nacos/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/pom.xml @@ -29,7 +29,7 @@ org.apache.dubbo - dubbo-metadata-report-api + dubbo-metadata-api ${project.parent.version} diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java similarity index 81% rename from dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java index 03bdeb8f958..846bc74e391 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java @@ -17,25 +17,27 @@ package org.apache.dubbo.metadata.store.nacos; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.exception.NacosException; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; -import org.apache.dubbo.metadata.support.AbstractMetadataReport; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReport; import org.apache.dubbo.rpc.RpcException; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; + +import java.util.List; import java.util.Properties; -import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR; -import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY; import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY; +import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT; import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; -import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; +import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY; +import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR; import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME; import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY; @@ -111,6 +113,31 @@ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdenti this.storeMetadata(consumerMetadataIdentifier, value); } + @Override + protected void doSaveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected void doRemoveMetadata(URL url) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetExportedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + protected List doGetSubscribedURLs() { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + + @Override + public String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + private void storeMetadata(MetadataIdentifier identifier, String value) { try { boolean publishResult = configService.publishConfig(identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), identifier.getGroup(), value); diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportFactory.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportFactory.java similarity index 89% rename from dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportFactory.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportFactory.java index b882042281c..2cff74c9a1b 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportFactory.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportFactory.java @@ -18,8 +18,8 @@ package org.apache.dubbo.metadata.store.nacos; import org.apache.dubbo.common.URL; -import org.apache.dubbo.metadata.store.MetadataReport; -import org.apache.dubbo.metadata.support.AbstractMetadataReportFactory; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory; /** * metadata report factory impl for nacos diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadata4TstService.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadata4TstService.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadata4TstService.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadata4TstService.java diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java similarity index 98% rename from dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java index 07d6f8b839a..909244ccf97 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java @@ -20,7 +20,7 @@ import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import com.alibaba.nacos.api.config.ConfigService; import com.google.gson.Gson; diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/pom.xml b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/pom.xml similarity index 97% rename from dubbo-metadata-report/dubbo-metadata-report-redis/pom.xml rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/pom.xml index 419c77f8839..da07d277447 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/pom.xml @@ -30,7 +30,7 @@ org.apache.dubbo - dubbo-metadata-report-api + dubbo-metadata-api ${project.parent.version} diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java similarity index 84% rename from dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java index 6f3810476c8..bc2b2eb2889 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java @@ -19,8 +19,8 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; -import org.apache.dubbo.metadata.support.AbstractMetadataReport; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReport; import org.apache.dubbo.rpc.RpcException; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; @@ -37,7 +37,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; -import static org.apache.dubbo.metadata.identifier.MetadataIdentifier.META_DATA_STORE_TAG; +import static org.apache.dubbo.metadata.report.identifier.MetadataIdentifier.META_DATA_STORE_TAG; /** * RedisMetadataReport @@ -76,6 +76,31 @@ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdenti this.storeMetadata(consumerMetadataIdentifier, value); } + @Override + protected void doSaveMetadata(URL url) { + + } + + @Override + protected void doRemoveMetadata(URL url) { + + } + + @Override + protected List doGetExportedURLs() { + return null; + } + + @Override + protected List doGetSubscribedURLs() { + return null; + } + + @Override + public String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + private void storeMetadata(MetadataIdentifier metadataIdentifier, String v) { if (pool != null) { storeMetadataStandalone(metadataIdentifier, v); diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java similarity index 89% rename from dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java index b507dbec21d..bd0887753fa 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java @@ -17,8 +17,8 @@ package org.apache.dubbo.metadata.store.redis; import org.apache.dubbo.common.URL; -import org.apache.dubbo.metadata.store.MetadataReport; -import org.apache.dubbo.metadata.support.AbstractMetadataReportFactory; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory; /** * RedisMetadataReportFactory. diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java similarity index 98% rename from dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java index 63a2a39514a..88105e276b9 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java @@ -20,7 +20,7 @@ import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import org.apache.dubbo.rpc.RpcException; import com.google.gson.Gson; @@ -40,7 +40,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; -import static org.apache.dubbo.metadata.support.Constants.SYNC_REPORT_KEY; +import static org.apache.dubbo.metadata.report.support.Constants.SYNC_REPORT_KEY; /** * 2018/10/9 diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/pom.xml b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/pom.xml similarity index 96% rename from dubbo-metadata-report/dubbo-metadata-report-zookeeper/pom.xml rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/pom.xml index a276f83b3bf..b84bd10c6d6 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/pom.xml @@ -27,7 +27,7 @@ org.apache.dubbo - dubbo-metadata-report-api + dubbo-metadata-api ${project.parent.version} diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java similarity index 78% rename from dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java index 66353f6817d..56499336027 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java @@ -19,11 +19,13 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; -import org.apache.dubbo.metadata.support.AbstractMetadataReport; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReport; import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; +import java.util.List; + import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; @@ -68,6 +70,31 @@ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdenti storeMetadata(consumerMetadataIdentifier, value); } + @Override + protected void doSaveMetadata(URL url) { +// zkClient.create(, URL.encode(url.toFullString())); + } + + @Override + protected void doRemoveMetadata(URL url) { + + } + + @Override + protected List doGetExportedURLs() { + return null; + } + + @Override + protected List doGetSubscribedURLs() { + return null; + } + + @Override + public String getServiceDefinition(MetadataIdentifier consumerMetadataIdentifier) { + throw new UnsupportedOperationException("This extension does not support working as a remote metadata center."); + } + private void storeMetadata(MetadataIdentifier metadataIdentifier, String v) { zkClient.create(getNodePath(metadataIdentifier), v, false); } diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java similarity index 91% rename from dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java index cf26d4af7a0..0ffed8db8e9 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java @@ -17,8 +17,8 @@ package org.apache.dubbo.metadata.store.zookeeper; import org.apache.dubbo.common.URL; -import org.apache.dubbo.metadata.store.MetadataReport; -import org.apache.dubbo.metadata.support.AbstractMetadataReportFactory; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory; import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; /** diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport4TstService.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport4TstService.java similarity index 100% rename from dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport4TstService.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport4TstService.java diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java similarity index 99% rename from dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java rename to dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java index 799a1bb04f4..55912f0e352 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java +++ b/dubbo-metadata/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java @@ -20,7 +20,7 @@ import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter; import com.google.gson.Gson; diff --git a/dubbo-metadata-report/pom.xml b/dubbo-metadata/dubbo-metadata-report/pom.xml similarity index 91% rename from dubbo-metadata-report/pom.xml rename to dubbo-metadata/dubbo-metadata-report/pom.xml index 5e0fb1a4287..3c2fa6019a8 100644 --- a/dubbo-metadata-report/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report/pom.xml @@ -16,7 +16,7 @@ --> - dubbo-parent + dubbo-metadata org.apache.dubbo ${revision} @@ -25,10 +25,8 @@ dubbo-metadata-report pom - dubbo-metadata-report-api dubbo-metadata-report-zookeeper dubbo-metadata-report-redis - dubbo-metadata-definition dubbo-metadata-report-consul dubbo-metadata-report-etcd dubbo-metadata-report-nacos diff --git a/dubbo-metadata/pom.xml b/dubbo-metadata/pom.xml index 9a690ae58a5..2115c452c67 100644 --- a/dubbo-metadata/pom.xml +++ b/dubbo-metadata/pom.xml @@ -26,41 +26,10 @@ 4.0.0 dubbo-metadata - jar - - dubbo-metadata - The metadata module of Dubbo project - - - - - org.apache.dubbo - dubbo-config-api - ${project.parent.version} - true - - - - org.apache.dubbo - dubbo-rpc-api - ${project.parent.version} - true - - - - - org.apache.dubbo - dubbo-configcenter-zookeeper - ${project.parent.version} - test - - - - org.apache.curator - curator-test - test - - - + pom + + dubbo-metadata-api + dubbo-metadata-report + \ No newline at end of file diff --git a/dubbo-metadata/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.LocalMetadataService b/dubbo-metadata/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.LocalMetadataService deleted file mode 100644 index 2af06fde611..00000000000 --- a/dubbo-metadata/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.LocalMetadataService +++ /dev/null @@ -1 +0,0 @@ -default=org.apache.dubbo.metadata.InMemoryLocalMetadataService \ No newline at end of file diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java index 469a40a3391..cf0dc68cf8d 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java @@ -20,15 +20,13 @@ import org.apache.dubbo.qos.command.CommandContext; import org.apache.dubbo.qos.command.annotation.Cmd; import org.apache.dubbo.qos.textui.TTable; +import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ConsumerModel; import org.apache.dubbo.rpc.model.ProviderModel; import java.util.Collection; -import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.getConsumerAddressNum; -import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.isRegistered; - @Cmd(name = "ls", summary = "ls service", example = { "ls" }) @@ -57,7 +55,7 @@ public String listProvider() { //Content for (ProviderModel providerModel : providerModelList) { - tTable.addRow(providerModel.getServiceName(), isRegistered(providerModel.getServiceName()) ? "Y" : "N"); + tTable.addRow(providerModel.getServiceKey(), ApplicationModel.isRegistered(providerModel.getServiceKey()) ? "Y" : "N"); } stringBuilder.append(tTable.rendering()); @@ -80,7 +78,8 @@ public String listConsumer() { //Content //TODO to calculate consumerAddressNum for (ConsumerModel consumerModel : consumerModelList) { - tTable.addRow(consumerModel.getServiceName(), getConsumerAddressNum(consumerModel.getServiceName())); + AbstractClusterInvoker clusterInvoker = (AbstractClusterInvoker) consumerModel.getInvoker(); + tTable.addRow(consumerModel.getServiceKey(), clusterInvoker.getDirectory().getAllInvokers().size()); } stringBuilder.append(tTable.rendering()); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java index 79c41f3b669..fcbf548a2f4 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java @@ -24,13 +24,11 @@ import org.apache.dubbo.qos.command.annotation.Cmd; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryFactory; -import org.apache.dubbo.registry.support.ProviderConsumerRegTable; -import org.apache.dubbo.registry.support.ProviderInvokerWrapper; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ProviderModel; +import org.apache.dubbo.rpc.model.invoker.ProviderInvokerWrapper; import java.util.Collection; -import java.util.Set; @Cmd(name = "offline", summary = "offline dubbo", example = { "offline dubbo", @@ -51,9 +49,9 @@ public String execute(CommandContext commandContext, String[] args) { Collection providerModelList = ApplicationModel.allProviderModels(); for (ProviderModel providerModel : providerModelList) { - if (providerModel.getServiceName().matches(servicePattern)) { + if (providerModel.getServiceKey().matches(servicePattern)) { hasService = true; - Set providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(providerModel.getServiceName()); + Collection providerInvokerWrapperSet = ApplicationModel.getProviderInvokers(providerModel.getServiceKey()); for (ProviderInvokerWrapper providerInvokerWrapper : providerInvokerWrapperSet) { if (!providerInvokerWrapper.isReg()) { continue; diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java index 30ba14b6fe0..ae3d17f266c 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java @@ -25,13 +25,11 @@ import org.apache.dubbo.qos.command.annotation.Cmd; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryFactory; -import org.apache.dubbo.registry.support.ProviderConsumerRegTable; -import org.apache.dubbo.registry.support.ProviderInvokerWrapper; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ProviderModel; +import org.apache.dubbo.rpc.model.invoker.ProviderInvokerWrapper; import java.util.Collection; -import java.util.Set; @Cmd(name = "online", summary = "online dubbo", example = { "online dubbo", @@ -53,9 +51,9 @@ public String execute(CommandContext commandContext, String[] args) { Collection providerModelList = ApplicationModel.allProviderModels(); for (ProviderModel providerModel : providerModelList) { - if (providerModel.getServiceName().matches(servicePattern)) { + if (providerModel.getServiceKey().matches(servicePattern)) { hasService = true; - Set providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(providerModel.getServiceName()); + Collection providerInvokerWrapperSet = ApplicationModel.getProviderInvokers(providerModel.getServiceKey()); for (ProviderInvokerWrapper providerInvokerWrapper : providerInvokerWrapperSet) { if (providerInvokerWrapper.isReg()) { continue; diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/LsTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/LsTest.java index c82e2d5d685..bef3088e4e0 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/LsTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/LsTest.java @@ -19,20 +19,19 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.qos.command.CommandContext; import org.apache.dubbo.registry.integration.RegistryDirectory; -import org.apache.dubbo.registry.support.ProviderConsumerRegTable; -import org.apache.dubbo.registry.support.ProviderInvokerWrapper; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ConsumerModel; import org.apache.dubbo.rpc.model.ProviderModel; +import org.apache.dubbo.rpc.model.invoker.ProviderInvokerWrapper; + import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.Map; -import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.getProviderInvoker; -import static org.hamcrest.Matchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -40,9 +39,9 @@ public class LsTest { @Test public void testExecute() throws Exception { ConsumerModel consumerModel = mock(ConsumerModel.class); - when(consumerModel.getServiceName()).thenReturn("org.apache.dubbo.FooService"); + when(consumerModel.getServiceKey()).thenReturn("org.apache.dubbo.FooService"); ProviderModel providerModel = mock(ProviderModel.class); - when(providerModel.getServiceName()).thenReturn("org.apache.dubbo.BarService"); + when(providerModel.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); ApplicationModel.initConsumerModel("org.apache.dubbo.FooService", consumerModel); ApplicationModel.initProviderModel("org.apache.dubbo.BarService", providerModel); @@ -53,8 +52,8 @@ public void testExecute() throws Exception { when(providerUrl.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); when(providerUrl.toFullString()).thenReturn("dubbo://localhost:8888/org.apache.dubbo.BarService"); when(providerInvoker.getUrl()).thenReturn(providerUrl); - ProviderConsumerRegTable.registerProvider(providerInvoker, registryUrl, providerUrl); - for (ProviderInvokerWrapper wrapper : getProviderInvoker("org.apache.dubbo.BarService")) { + ApplicationModel.registerProviderInvoker(providerInvoker, registryUrl, providerUrl); + for (ProviderInvokerWrapper wrapper : ApplicationModel.getProviderInvokers("org.apache.dubbo.BarService")) { wrapper.setReg(true); } @@ -67,7 +66,7 @@ public void testExecute() throws Exception { Map invokers = Mockito.mock(Map.class); when(invokers.size()).thenReturn(100); when(directory.getUrlInvokerMap()).thenReturn(invokers); - ProviderConsumerRegTable.registerConsumer(consumerInvoker, registryUrl, consumerUrl, directory); + ApplicationModel.registerConsumerInvoker(consumerInvoker, consumerUrl.getServiceKey()); Ls ls = new Ls(); String output = ls.execute(mock(CommandContext.class), null); diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OfflineTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OfflineTest.java index f498d5aeb34..8d27d12f309 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OfflineTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OfflineTest.java @@ -19,18 +19,17 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.qos.command.CommandContext; import org.apache.dubbo.registry.Registry; -import org.apache.dubbo.registry.support.ProviderConsumerRegTable; -import org.apache.dubbo.registry.support.ProviderInvokerWrapper; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ProviderModel; +import org.apache.dubbo.rpc.model.invoker.ProviderInvokerWrapper; + import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.getProviderInvoker; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.core.Is.is; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -38,7 +37,7 @@ public class OfflineTest { @Test public void testExecute() throws Exception { ProviderModel providerModel = mock(ProviderModel.class); - when(providerModel.getServiceName()).thenReturn("org.apache.dubbo.BarService"); + when(providerModel.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); ApplicationModel.initProviderModel("org.apache.dubbo.BarService", providerModel); Invoker providerInvoker = mock(Invoker.class); @@ -48,8 +47,8 @@ public void testExecute() throws Exception { when(providerUrl.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); when(providerUrl.toFullString()).thenReturn("dubbo://localhost:8888/org.apache.dubbo.BarService"); when(providerInvoker.getUrl()).thenReturn(providerUrl); - ProviderConsumerRegTable.registerProvider(providerInvoker, registryUrl, providerUrl); - for (ProviderInvokerWrapper wrapper : getProviderInvoker("org.apache.dubbo.BarService")) { + ApplicationModel.registerProviderInvoker(providerInvoker, registryUrl, providerUrl); + for (ProviderInvokerWrapper wrapper : ApplicationModel.getProviderInvokers("org.apache.dubbo.BarService")) { wrapper.setReg(true); } @@ -60,7 +59,7 @@ public void testExecute() throws Exception { String output = offline.execute(mock(CommandContext.class), new String[]{"org.apache.dubbo.BarService"}); assertThat(output, containsString("OK")); Mockito.verify(registry).unregister(providerUrl); - for (ProviderInvokerWrapper wrapper : getProviderInvoker("org.apache.dubbo.BarService")) { + for (ProviderInvokerWrapper wrapper : ApplicationModel.getProviderInvokers("org.apache.dubbo.BarService")) { assertThat(wrapper.isReg(), is(false)); } diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OnlineTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OnlineTest.java index 71132c09551..7474b68a516 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OnlineTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OnlineTest.java @@ -19,16 +19,15 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.qos.command.CommandContext; import org.apache.dubbo.registry.Registry; -import org.apache.dubbo.registry.support.ProviderConsumerRegTable; -import org.apache.dubbo.registry.support.ProviderInvokerWrapper; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ProviderModel; +import org.apache.dubbo.rpc.model.invoker.ProviderInvokerWrapper; + import org.junit.jupiter.api.Test; -import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.getProviderInvoker; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -37,7 +36,7 @@ public class OnlineTest { @Test public void testExecute() throws Exception { ProviderModel providerModel = mock(ProviderModel.class); - when(providerModel.getServiceName()).thenReturn("org.apache.dubbo.BarService"); + when(providerModel.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); ApplicationModel.initProviderModel("org.apache.dubbo.BarService", providerModel); Invoker providerInvoker = mock(Invoker.class); @@ -47,7 +46,7 @@ public void testExecute() throws Exception { when(providerUrl.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); when(providerUrl.toFullString()).thenReturn("dubbo://localhost:8888/org.apache.dubbo.BarService"); when(providerInvoker.getUrl()).thenReturn(providerUrl); - ProviderConsumerRegTable.registerProvider(providerInvoker, registryUrl, providerUrl); + ApplicationModel.registerProviderInvoker(providerInvoker, registryUrl, providerUrl); Registry registry = mock(Registry.class); TestRegistryFactory.registry = registry; @@ -55,7 +54,7 @@ public void testExecute() throws Exception { Online online = new Online(); String output = online.execute(mock(CommandContext.class), new String[]{"org.apache.dubbo.BarService"}); assertThat(output, equalTo("OK")); - for (ProviderInvokerWrapper wrapper : getProviderInvoker("org.apache.dubbo.BarService")) { + for (ProviderInvokerWrapper wrapper : ApplicationModel.getProviderInvokers("org.apache.dubbo.BarService")) { assertTrue(wrapper.isReg()); } } diff --git a/dubbo-registry/dubbo-registry-api/pom.xml b/dubbo-registry/dubbo-registry-api/pom.xml index 44eb895b273..7ae8b752d2c 100644 --- a/dubbo-registry/dubbo-registry-api/pom.xml +++ b/dubbo-registry/dubbo-registry-api/pom.xml @@ -32,12 +32,12 @@ org.apache.dubbo - dubbo-cluster + dubbo-common ${project.parent.version} org.apache.dubbo - dubbo-configcenter-api + dubbo-cluster ${project.parent.version} @@ -64,7 +64,12 @@ org.apache.dubbo - dubbo-metadata + dubbo-metadata-api + ${project.parent.version} + + + org.apache.dubbo + dubbo-metadata-report-api ${project.parent.version} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java index bcdcfd29e66..cd501e6cee0 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java @@ -16,8 +16,19 @@ */ package org.apache.dubbo.registry.client; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.URLBuilder; +import org.apache.dubbo.metadata.MetadataService; + +import java.util.ArrayList; +import java.util.List; import java.util.Map; +import static java.lang.String.valueOf; +import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceURLsParams; +import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderHost; +import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderPort; + /** * The model class of an instance of a service, which is used for service registration and discovery. *

@@ -91,4 +102,37 @@ default boolean isHealthy() { * @return if equals , return true, or false */ boolean equals(Object another); + + /** + * Build the {@link URL urls} from {@link ServiceInstance#getMetadata() the metadata} of {@link ServiceInstance} + * + * @param serviceInstance {@link ServiceInstance} + * @return the not-null {@link List} + */ + static List toUrls(ServiceInstance serviceInstance) { + + Map> paramsMap = getMetadataServiceURLsParams(serviceInstance); + + List urls = new ArrayList<>(paramsMap.size()); + + for (Map.Entry> entry : paramsMap.entrySet()) { + + URLBuilder urlBuilder = new URLBuilder(); + String protocol = entry.getKey(); + Map urlParams = entry.getValue(); + String host = getProviderHost(urlParams); + Integer port = getProviderPort(urlParams); + urlBuilder.setHost(host) + .setPort(port) + .setProtocol(protocol) + .setPath(MetadataService.class.getName()); + + // add parameters + entry.getValue().forEach((name, value) -> urlBuilder.addParameter(name, valueOf(value))); + + urls.add(urlBuilder.build()); + } + + return urls; + } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java index 5c1cc8e9d11..56797235a3f 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java @@ -18,8 +18,8 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.compiler.support.ClassUtils; -import org.apache.dubbo.metadata.LocalMetadataService; import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.registry.client.ServiceInstance; import org.apache.dubbo.registry.client.ServiceInstanceMetadataCustomizer; @@ -47,8 +47,8 @@ protected String buildMetadataKey(ServiceInstance serviceInstance) { @Override protected String buildMetadataValue(ServiceInstance serviceInstance) { - LocalMetadataService localMetadataService = LocalMetadataService.getDefaultExtension(); - List exportedURLs = localMetadataService.getExportedURLs(); + WritableMetadataService writableMetadataService = WritableMetadataService.getDefaultExtension(); + List exportedURLs = writableMetadataService.getExportedURLs(); Object[] data = exportedURLs.stream() .map(URL::valueOf) // String to URL .map(URL::getServiceInterface) // get the service interface diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java index 97ba53c3404..b41873d45ca 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java @@ -17,8 +17,8 @@ package org.apache.dubbo.registry.client.metadata; import org.apache.dubbo.common.URL; -import org.apache.dubbo.metadata.LocalMetadataService; import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.registry.client.ServiceInstance; import org.apache.dubbo.registry.client.ServiceInstanceMetadataCustomizer; @@ -45,7 +45,7 @@ public String buildMetadataKey(ServiceInstance serviceInstance) { @Override public String buildMetadataValue(ServiceInstance serviceInstance) { - LocalMetadataService localMetadataService = LocalMetadataService.getDefaultExtension(); + WritableMetadataService writableMetadataService = WritableMetadataService.getDefaultExtension(); String serviceInterface = MetadataService.class.getName(); @@ -53,7 +53,7 @@ public String buildMetadataValue(ServiceInstance serviceInstance) { String version = MetadataService.VERSION; - List urls = localMetadataService.getExportedURLs(serviceInterface, group, version); + List urls = writableMetadataService.getExportedURLs(serviceInterface, group, version); return getMetadataServiceParameter(toURLs(urls)); } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java new file mode 100644 index 00000000000..58dca64ac10 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java @@ -0,0 +1,73 @@ +/* + * 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.proxy; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.extension.ExtensionLoader; +import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.registry.client.ServiceInstance; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Protocol; +import org.apache.dubbo.rpc.ProxyFactory; +import org.apache.dubbo.rpc.cluster.Cluster; +import org.apache.dubbo.rpc.cluster.directory.StaticDirectory; +import org.apache.dubbo.rpc.cluster.support.AvailableCluster; + +import java.lang.reflect.Proxy; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * The factory of {@link MetadataService}'s {@link Proxy} + * + * @since 2.7.3 + */ +public class DefaultMetadataServiceProxyFactory implements MetadataServiceProxyFactory { + + private final Map proxys = new HashMap<>(); + + private ProxyFactory proxyFactory; + + private Protocol protocol; + + private Cluster cluster = ExtensionLoader.getExtensionLoader(Cluster.class).getExtension(AvailableCluster.NAME); + + public void setProtocol(Protocol protocol) { + this.protocol = protocol; + } + + public void setProxyFactory(ProxyFactory proxyFactory) { + this.proxyFactory = proxyFactory; + } + + @Override + public MetadataService getProxy(ServiceInstance serviceInstance) { + return proxys.computeIfAbsent(serviceInstance.getId(), id -> createProxy(serviceInstance)); + } + + protected MetadataService createProxy(ServiceInstance serviceInstance) { + List urls = ServiceInstance.toUrls(serviceInstance); + List> invokers = urls.stream() + .map(url -> protocol.refer(MetadataService.class, url)) + .collect(Collectors.toList()); + + Invoker invoker = cluster.join(new StaticDirectory<>(invokers)); + return proxyFactory.getProxy(invoker); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java new file mode 100644 index 00000000000..9ec31dff55b --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java @@ -0,0 +1,55 @@ +/* + * 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.proxy; + +import org.apache.dubbo.common.extension.SPI; +import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.registry.client.ServiceInstance; + +import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader; + +/** + * A factory to create a {@link MetadataService} proxy + * + * @see ServiceInstance + * @see MetadataService + * @since 2.7.3 + */ +@SPI("local") +public interface MetadataServiceProxyFactory { + + /** + * Create a {@link MetadataService} proxy via the specified {@link ServiceInstance} + * + * @param serviceInstance the instance of {@link ServiceInstance} + * @return non-null + */ + MetadataService getProxy(ServiceInstance serviceInstance); + + /** + * Get the default extension of {@link MetadataServiceProxyFactory} + * + * @return non-null + */ + static MetadataServiceProxyFactory getDefaultExtension() { + return getExtensionLoader(MetadataServiceProxyFactory.class).getDefaultExtension(); + } + + static MetadataServiceProxyFactory getExtension(String name) { + return getExtensionLoader(MetadataServiceProxyFactory.class).getExtension(name); + } +} diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfigurationFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/RemoteMetadataServiceProxyFactory.java similarity index 61% rename from dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfigurationFactory.java rename to dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/RemoteMetadataServiceProxyFactory.java index 13482b77296..3544294fe58 100644 --- a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfigurationFactory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/RemoteMetadataServiceProxyFactory.java @@ -14,19 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.configcenter.mock; +package org.apache.dubbo.registry.client.metadata.proxy; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory; -import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.metadata.WritableMetadataService; +import org.apache.dubbo.registry.client.ServiceInstance; + +import static org.apache.dubbo.common.constants.CommonConstants.METADATA_REMOTE; /** * */ -public class MockDynamicConfigurationFactory extends AbstractDynamicConfigurationFactory { +public class RemoteMetadataServiceProxyFactory implements MetadataServiceProxyFactory { @Override - protected DynamicConfiguration createDynamicConfiguration(URL url) { - return new MockDynamicConfiguration(url); + public MetadataService getProxy(ServiceInstance serviceInstance) { + return WritableMetadataService.getExtension(METADATA_REMOTE); } + } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java index 5258d24c9f4..7a135a79680 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java @@ -16,14 +16,14 @@ */ package org.apache.dubbo.registry.integration; +import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; +import org.apache.dubbo.common.config.configcenter.ConfigChangeType; +import org.apache.dubbo.common.config.configcenter.ConfigurationListener; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigChangeType; -import org.apache.dubbo.configcenter.ConfigurationListener; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.rpc.cluster.Configurator; import org.apache.dubbo.rpc.cluster.configurator.parser.ConfigParser; diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index 2f3a83567a4..20759a562f8 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.Version; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -27,7 +28,6 @@ import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.common.utils.UrlUtils; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.remoting.Constants; @@ -604,6 +604,11 @@ public Class getInterface() { return serviceType; } + @Override + public List> getAllInvokers() { + return invokers; + } + @Override public URL getUrl() { return this.overrideDirectoryUrl; diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index 9afa7ab9fd9..a3943882fd3 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.config.ConfigurationUtils; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -26,13 +27,10 @@ import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.common.utils.UrlUtils; -import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryFactory; import org.apache.dubbo.registry.RegistryService; -import org.apache.dubbo.registry.support.ProviderConsumerRegTable; -import org.apache.dubbo.registry.support.ProviderInvokerWrapper; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; @@ -41,6 +39,7 @@ import org.apache.dubbo.rpc.cluster.Cluster; import org.apache.dubbo.rpc.cluster.Configurator; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.invoker.ProviderInvokerWrapper; import org.apache.dubbo.rpc.protocol.InvokerWrapper; import java.util.ArrayList; @@ -211,7 +210,7 @@ public Exporter export(final Invoker originInvoker) throws RpcExceptio // url to registry final Registry registry = getRegistry(originInvoker); final URL registeredProviderUrl = getRegisteredProviderUrl(providerUrl, registryUrl); - ProviderInvokerWrapper providerInvokerWrapper = ProviderConsumerRegTable.registerProvider(originInvoker, + ProviderInvokerWrapper providerInvokerWrapper = ApplicationModel.registerProviderInvoker(originInvoker, registryUrl, registeredProviderUrl); //to judge if we need to delay publish boolean register = registeredProviderUrl.getParameter("register", true); @@ -254,8 +253,8 @@ public void reExport(final Invoker originInvoker, URL newInvokerUrl) { final URL registeredProviderUrl = getRegisteredProviderUrl(newInvokerUrl, registryUrl); //decide if we need to re-publish - ProviderInvokerWrapper providerInvokerWrapper = ProviderConsumerRegTable.getProviderWrapper(registeredProviderUrl, originInvoker); - ProviderInvokerWrapper newProviderInvokerWrapper = ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, registeredProviderUrl); + ProviderInvokerWrapper providerInvokerWrapper = ApplicationModel.getProviderInvoker(registeredProviderUrl.getServiceKey(), originInvoker); + ProviderInvokerWrapper newProviderInvokerWrapper = ApplicationModel.registerProviderInvoker(originInvoker, registryUrl, registeredProviderUrl); /** * Only if the new url going to Registry is different with the previous one should we do unregister and register. */ @@ -412,7 +411,7 @@ private Invoker doRefer(Cluster cluster, Registry registry, Class type PROVIDERS_CATEGORY + "," + CONFIGURATORS_CATEGORY + "," + ROUTERS_CATEGORY)); Invoker invoker = cluster.join(directory); - ProviderConsumerRegTable.registerConsumer(invoker, url, subscribeUrl, directory); + ApplicationModel.registerConsumerInvoker(invoker, subscribeUrl.getServiceKey()); return invoker; } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ConsumerInvokerWrapper.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ConsumerInvokerWrapper.java deleted file mode 100644 index 141634de25b..00000000000 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ConsumerInvokerWrapper.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.registry.support; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.registry.integration.RegistryDirectory; -import org.apache.dubbo.rpc.Invocation; -import org.apache.dubbo.rpc.Invoker; -import org.apache.dubbo.rpc.Result; -import org.apache.dubbo.rpc.RpcException; - -/** - * @date 2017/11/23 - */ -public class ConsumerInvokerWrapper implements Invoker { - private Invoker invoker; - private URL originUrl; - private URL registryUrl; - private URL consumerUrl; - private RegistryDirectory registryDirectory; - - public ConsumerInvokerWrapper(Invoker invoker, URL registryUrl, URL consumerUrl, RegistryDirectory registryDirectory) { - this.invoker = invoker; - this.originUrl = URL.valueOf(invoker.getUrl().toFullString()); - this.registryUrl = URL.valueOf(registryUrl.toFullString()); - this.consumerUrl = consumerUrl; - this.registryDirectory = registryDirectory; - } - - @Override - public Class getInterface() { - return invoker.getInterface(); - } - - @Override - public URL getUrl() { - return invoker.getUrl(); - } - - @Override - public boolean isAvailable() { - return invoker.isAvailable(); - } - - @Override - public Result invoke(Invocation invocation) throws RpcException { - return invoker.invoke(invocation); - } - - @Override - public void destroy() { - invoker.destroy(); - } - - public URL getOriginUrl() { - return originUrl; - } - - public URL getRegistryUrl() { - return registryUrl; - } - - public Invoker getInvoker() { - return invoker; - } - - public URL getConsumerUrl() { - return consumerUrl; - } - - public RegistryDirectory getRegistryDirectory() { - return registryDirectory; - } -} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderConsumerRegTable.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderConsumerRegTable.java deleted file mode 100644 index 9af39888e21..00000000000 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderConsumerRegTable.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.registry.support; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.utils.ConcurrentHashSet; -import org.apache.dubbo.registry.integration.RegistryDirectory; -import org.apache.dubbo.rpc.Invoker; - -import java.util.Collections; -import java.util.Map; -import java.util.Objects; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * @date 2017/11/23 - */ -public class ProviderConsumerRegTable { - public static ConcurrentHashMap> providerInvokers = new ConcurrentHashMap<>(); - public static ConcurrentHashMap> consumerInvokers = new ConcurrentHashMap<>(); - - public static ProviderInvokerWrapper registerProvider(Invoker invoker, URL registryUrl, URL providerUrl) { - ProviderInvokerWrapper wrapperInvoker = new ProviderInvokerWrapper<>(invoker, registryUrl, providerUrl); - String serviceUniqueName = providerUrl.getServiceKey(); - ConcurrentMap invokers = providerInvokers.get(serviceUniqueName); - if (invokers == null) { - providerInvokers.putIfAbsent(serviceUniqueName, new ConcurrentHashMap<>()); - invokers = providerInvokers.get(serviceUniqueName); - } - invokers.put(invoker, wrapperInvoker); - return wrapperInvoker; - } - - /*public static ProviderInvokerWrapper removeProviderWrapper(Invoker invoker, URL providerUrl) { - String serviceUniqueName = providerUrl.getServiceKey(); - Set invokers = providerInvokers.get(serviceUniqueName); - if (invokers == null) { - return null; - } - return invokers.remove(new ProviderIndvokerWrapper(invoker, null, null)); - }*/ - - public static Set getProviderInvoker(String serviceUniqueName) { - ConcurrentMap invokers = providerInvokers.get(serviceUniqueName); - if (invokers == null) { - return Collections.emptySet(); - } - return new HashSet<>(invokers.values()); - } - - public static ProviderInvokerWrapper getProviderWrapper(URL registeredProviderUrl, Invoker invoker) { - String serviceUniqueName = registeredProviderUrl.getServiceKey(); - ConcurrentMap invokers = providerInvokers.get(serviceUniqueName); - if (invokers == null) { - return null; - } - - for (Map.Entry entry : invokers.entrySet()) { - if (entry.getKey() == invoker) { - return entry.getValue(); - } - } - - return null; - } - - public static void registerConsumer(Invoker invoker, URL registryUrl, URL consumerUrl, RegistryDirectory registryDirectory) { - ConsumerInvokerWrapper wrapperInvoker = new ConsumerInvokerWrapper(invoker, registryUrl, consumerUrl, registryDirectory); - String serviceUniqueName = consumerUrl.getServiceKey(); - Set invokers = consumerInvokers.get(serviceUniqueName); - if (invokers == null) { - consumerInvokers.putIfAbsent(serviceUniqueName, new ConcurrentHashSet()); - invokers = consumerInvokers.get(serviceUniqueName); - } - invokers.add(wrapperInvoker); - } - - public static Set getConsumerInvoker(String serviceUniqueName) { - Set invokers = consumerInvokers.get(serviceUniqueName); - return invokers == null ? Collections.emptySet() : invokers; - } - - public static boolean isRegistered(String serviceUniqueName) { - Set providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(serviceUniqueName); - return providerInvokerWrapperSet.stream().anyMatch(ProviderInvokerWrapper::isReg); - } - - public static int getConsumerAddressNum(String serviceUniqueName) { - Set providerInvokerWrapperSet = ProviderConsumerRegTable.getConsumerInvoker(serviceUniqueName); - return providerInvokerWrapperSet.stream() - .map(w -> w.getRegistryDirectory().getUrlInvokerMap()) - .filter(Objects::nonNull) - .mapToInt(Map::size).sum(); - } -} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java index 945df0d680a..3d1f613b14c 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java @@ -20,15 +20,15 @@ import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.metadata.LocalMetadataService; import org.apache.dubbo.metadata.MetadataService; import org.apache.dubbo.metadata.ServiceNameMapping; +import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.client.ServiceDiscovery; import org.apache.dubbo.registry.client.ServiceDiscoveryFactory; import org.apache.dubbo.registry.client.ServiceInstance; -import org.apache.dubbo.registry.client.metadata.MetadataServiceProxyFactory; +import org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory; import org.apache.dubbo.registry.client.selector.ServiceInstanceSelector; import java.util.ArrayList; @@ -50,6 +50,7 @@ import static java.util.stream.Stream.of; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.METADATA_DEFAULT; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; @@ -61,6 +62,7 @@ import static org.apache.dubbo.common.utils.CollectionUtils.isEmpty; import static org.apache.dubbo.common.utils.CollectionUtils.isNotEmpty; import static org.apache.dubbo.common.utils.StringUtils.isBlank; +import static org.apache.dubbo.metadata.support.Constants.METADATA_REPORT_KEY; import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getExportedServicesRevision; import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceURLsParams; import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderHost; @@ -87,18 +89,19 @@ public class ServiceOrientedRegistry extends FailbackRegistry { private final ServiceNameMapping serviceNameMapping; - private final LocalMetadataService localMetadataService; + private final WritableMetadataService writableMetadataService; private final MetadataServiceProxyFactory metadataServiceProxyFactory; - public ServiceOrientedRegistry(URL registryURL) { super(registryURL); this.serviceDiscovery = buildServiceDiscovery(registryURL); this.subscribedServices = buildSubscribedServices(registryURL); this.serviceNameMapping = ServiceNameMapping.getDefaultExtension(); - this.localMetadataService = LocalMetadataService.getDefaultExtension(); - this.metadataServiceProxyFactory = MetadataServiceProxyFactory.getDefaultExtension(); + + String metadata = registryURL.getParameter(METADATA_REPORT_KEY, METADATA_DEFAULT); + this.writableMetadataService = WritableMetadataService.getExtension(metadata); + this.metadataServiceProxyFactory = MetadataServiceProxyFactory.getExtension(metadata); } private Set buildSubscribedServices(URL url) { @@ -140,7 +143,7 @@ public void doRegister(URL url) { if (!shouldRegister(url)) { // Should Not Register return; } - if (localMetadataService.exportURL(url)) { + if (writableMetadataService.exportURL(url)) { if (logger.isInfoEnabled()) { logger.info(format("The URL[%s] registered successfully.", url.toString())); } @@ -156,7 +159,7 @@ public void doUnregister(URL url) { if (!shouldRegister(url)) { return; } - if (localMetadataService.unexportURL(url)) { + if (writableMetadataService.unexportURL(url)) { if (logger.isInfoEnabled()) { logger.info(format("The URL[%s] deregistered successfully.", url.toString())); } @@ -177,7 +180,7 @@ public void doSubscribe(URL url, NotifyListener listener) { @Override public void doUnsubscribe(URL url, NotifyListener listener) { - localMetadataService.unsubscribeURL(url); + writableMetadataService.unsubscribeURL(url); } @Override @@ -194,7 +197,7 @@ public void destroy() { protected void subscribeURLs(URL url, NotifyListener listener) { - localMetadataService.subscribeURL(url); + writableMetadataService.subscribeURL(url); Set serviceNames = getServices(url); @@ -397,7 +400,7 @@ protected List getProviderExportedURLs(URL subscribedURL, ServiceInstance p String protocol = subscribedURL.getParameter(PROTOCOL_KEY); try { - MetadataService metadataService = metadataServiceProxyFactory.createProxy(providerInstance); + MetadataService metadataService = metadataServiceProxyFactory.getProxy(providerInstance); List urls = metadataService.getExportedURLs(serviceInterface, group, version, protocol); exportedURLs = urls.stream().map(URL::valueOf).collect(Collectors.toList()); } catch (Throwable e) { diff --git a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory new file mode 100644 index 00000000000..d9283dec444 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory @@ -0,0 +1,2 @@ +local=org.apache.dubbo.registry.client.metadata.proxy.DefaultMetadataServiceProxyFactory +remote=org.apache.dubbo.registry.client.metadata.proxy.RemoteMetadataServiceProxyFactory \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java index bcbd846495e..73b88d48f6a 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java @@ -17,7 +17,7 @@ package org.apache.dubbo.registry.support; import org.apache.dubbo.common.URL; -import org.apache.dubbo.metadata.LocalMetadataService; +import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.registry.NotifyListener; import org.junit.jupiter.api.BeforeEach; @@ -66,7 +66,7 @@ public class ServiceOrientedRegistryTest { private static URL url2 = url.setProtocol("rest"); - private LocalMetadataService metadataService; + private WritableMetadataService metadataService; private ServiceOrientedRegistry registry; @@ -75,7 +75,7 @@ public class ServiceOrientedRegistryTest { @BeforeEach public void init() { registry = ServiceOrientedRegistry.create(registryURL); - metadataService = LocalMetadataService.getDefaultExtension(); + metadataService = WritableMetadataService.getDefaultExtension(); notifyListener = new MyNotifyListener(); } diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscoveryFactory.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscoveryFactory.java index 65ba64fc029..929b17ecaea 100644 --- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscoveryFactory.java +++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscoveryFactory.java @@ -19,10 +19,6 @@ import org.apache.dubbo.registry.client.ServiceDiscovery; import org.apache.dubbo.registry.client.ServiceDiscoveryFactory; -import com.alibaba.nacos.api.naming.NamingService; - -import static org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.createNamingService; - /** * Nacos {@link ServiceDiscoveryFactory} * diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java index 33dcc908e1b..2860a29dad6 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java @@ -16,10 +16,14 @@ */ package org.apache.dubbo.rpc.model; +import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.model.invoker.ProviderInvokerWrapper; import java.util.Collection; +import java.util.Collections; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -33,15 +37,14 @@ * adjust project structure in order to fully utilize the methods introduced here. */ public class ApplicationModel { - protected static final Logger LOGGER = LoggerFactory.getLogger(ApplicationModel.class); /** - * full qualified class name -> provided service + * serviceKey -> exported service */ private static final ConcurrentMap PROVIDED_SERVICES = new ConcurrentHashMap<>(); /** - * full qualified class name -> subscribe service + * serviceKey -> referred service */ private static final ConcurrentMap CONSUMED_SERVICES = new ConcurrentHashMap<>(); @@ -55,12 +58,12 @@ public static Collection allProviderModels() { return PROVIDED_SERVICES.values(); } - public static ProviderModel getProviderModel(String serviceName) { - return PROVIDED_SERVICES.get(serviceName); + public static ProviderModel getProviderModel(String serviceKey) { + return PROVIDED_SERVICES.get(serviceKey); } - public static ConsumerModel getConsumerModel(String serviceName) { - return CONSUMED_SERVICES.get(serviceName); + public static ConsumerModel getConsumerModel(String serviceKey) { + return CONSUMED_SERVICES.get(serviceKey); } public static void initConsumerModel(String serviceName, ConsumerModel consumerModel) { @@ -83,6 +86,39 @@ public static void setApplication(String application) { ApplicationModel.application = application; } + public static ProviderInvokerWrapper registerProviderInvoker(Invoker invoker, URL registryUrl, URL providerUrl) { + ProviderInvokerWrapper wrapperInvoker = new ProviderInvokerWrapper<>(invoker, registryUrl, providerUrl); + ProviderModel providerModel = getProviderModel(providerUrl.getServiceKey()); + providerModel.addInvoker(wrapperInvoker); + return wrapperInvoker; + } + + public static Collection getProviderInvokers(String serviceKey) { + ProviderModel providerModel = getProviderModel(serviceKey); + if (providerModel == null) { + return Collections.emptySet(); + } + return providerModel.getInvokers(); + } + + public static ProviderInvokerWrapper getProviderInvoker(String serviceKey, Invoker invoker) { + ProviderModel providerModel = getProviderModel(serviceKey); + return providerModel.getInvoker(invoker.getUrl().getProtocol()); + } + + public static boolean isRegistered(String serviceKey) { + return getProviderInvokers(serviceKey).stream().anyMatch(ProviderInvokerWrapper::isReg); + } + + public static void registerConsumerInvoker(Invoker invoker, String serviceKey) { + ConsumerModel consumerModel = getConsumerModel(serviceKey); + consumerModel.setInvoker(invoker); + } + + public static Invoker getConsumerInvoker(String serviceKey) { + return (Invoker) getConsumerModel(serviceKey).getInvoker(); + } + /** * For unit test */ diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java index 4c990a5088c..851cd062133 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.model; import org.apache.dubbo.common.utils.Assert; +import org.apache.dubbo.rpc.Invoker; import java.lang.reflect.Method; import java.util.ArrayList; @@ -29,34 +30,35 @@ * Consumer Model which is about subscribed services. */ public class ConsumerModel { - private final Object proxyObject; - private final String serviceName; + private final String serviceKey; private final Class serviceInterfaceClass; private final Map methodModels = new IdentityHashMap(); + private Object proxyObject; + private Invoker invoker; + /** * This constructor create an instance of ConsumerModel and passed objects should not be null. * If service name, service instance, proxy object,methods should not be null. If these are null * then this constructor will throw {@link IllegalArgumentException} - * @param serviceName Name of the service. + * @param serviceKey Name of the service. * @param serviceInterfaceClass Service interface class. * @param proxyObject Proxy object. * @param methods Methods of service class * @param attributes Attributes of methods. */ - public ConsumerModel(String serviceName + public ConsumerModel(String serviceKey , Class serviceInterfaceClass , Object proxyObject , Method[] methods , Map attributes) { - Assert.notEmptyString(serviceName, "Service name can't be null or blank"); + Assert.notEmptyString(serviceKey, "Service name can't be null or blank"); Assert.notNull(serviceInterfaceClass, "Service interface class can't null"); - Assert.notNull(proxyObject, "Proxy object can't be null"); Assert.notNull(methods, "Methods can't be null"); - this.serviceName = serviceName; + this.serviceKey = serviceKey; this.serviceInterfaceClass = serviceInterfaceClass; this.proxyObject = proxyObject; for (Method method : methods) { @@ -106,7 +108,19 @@ public Class getServiceInterfaceClass() { return serviceInterfaceClass; } - public String getServiceName() { - return serviceName; + public String getServiceKey() { + return serviceKey; + } + + public void setProxyObject(Object proxyObject) { + this.proxyObject = proxyObject; + } + + public Invoker getInvoker() { + return invoker; + } + + public void setInvoker(Invoker invoker) { + this.invoker = invoker; } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java index 6fb9bebd7ea..48d9ac76d4d 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java @@ -16,9 +16,13 @@ */ package org.apache.dubbo.rpc.model; +import org.apache.dubbo.rpc.model.invoker.ProviderInvokerWrapper; + import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -27,17 +31,20 @@ * ProviderModel which is about published services */ public class ProviderModel { - private final String serviceName; + private final String serviceKey; private final Object serviceInstance; private final Class serviceInterfaceClass; private final Map> methods = new HashMap>(); - public ProviderModel(String serviceName, Object serviceInstance, Class serviceInterfaceClass) { + private Map protocolInvokers = new HashMap<>(); + + + public ProviderModel(String serviceKey, Object serviceInstance, Class serviceInterfaceClass) { if (null == serviceInstance) { - throw new IllegalArgumentException("Service[" + serviceName + "]Target is NULL."); + throw new IllegalArgumentException("Service[" + serviceKey + "]Target is NULL."); } - this.serviceName = serviceName; + this.serviceKey = serviceKey; this.serviceInstance = serviceInstance; this.serviceInterfaceClass = serviceInterfaceClass; @@ -45,8 +52,8 @@ public ProviderModel(String serviceName, Object serviceInstance, Class servic } - public String getServiceName() { - return serviceName; + public String getServiceKey() { + return serviceKey; } public Class getServiceInterfaceClass() { @@ -89,8 +96,20 @@ private void initMethod() { methodModels = new ArrayList(1); methods.put(method.getName(), methodModels); } - methodModels.add(new ProviderMethodModel(method, serviceName)); + methodModels.add(new ProviderMethodModel(method, serviceKey)); } } + + public void addInvoker(ProviderInvokerWrapper invoker) { + protocolInvokers.put(invoker.getUrl().getProtocol(), invoker); + } + + public ProviderInvokerWrapper getInvoker(String protocol) { + return protocolInvokers.get(protocol); + } + + public Collection getInvokers() { + return Collections.unmodifiableCollection(protocolInvokers.values()); + } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/invoker/ProviderInvokerWrapper.java similarity index 95% rename from dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java rename to dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/invoker/ProviderInvokerWrapper.java index ce079b743e4..cc1958959db 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/invoker/ProviderInvokerWrapper.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.registry.support; +package org.apache.dubbo.rpc.model.invoker; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; @@ -32,7 +32,7 @@ public class ProviderInvokerWrapper implements Invoker { private URL providerUrl; private volatile boolean isReg; - public ProviderInvokerWrapper(Invoker invoker,URL registryUrl,URL providerUrl) { + public ProviderInvokerWrapper(Invoker invoker, URL registryUrl, URL providerUrl) { this.invoker = invoker; this.originUrl = URL.valueOf(invoker.getUrl().toFullString()); this.registryUrl = URL.valueOf(registryUrl.toFullString()); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/pom.xml b/dubbo-rpc/dubbo-rpc-dubbo/pom.xml index dc6cd2295f8..99fdf5a8b96 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/pom.xml +++ b/dubbo-rpc/dubbo-rpc-dubbo/pom.xml @@ -41,8 +41,8 @@ org.apache.dubbo - dubbo-config-api - ${project.version} + dubbo-cluster + ${project.parent.version} org.apache.dubbo @@ -59,11 +59,6 @@ - - org.apache.dubbo - dubbo-configcenter-api - ${project.parent.version} - org.apache.dubbo dubbo-remoting-netty4 diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java index 3998026b70b..de3a2a5e7c1 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java @@ -152,7 +152,7 @@ public String telnet(Channel channel, String message) { private boolean isServiceMatch(String service, ProviderModel provider) { - return provider.getServiceName().equalsIgnoreCase(service) + return provider.getServiceKey().equalsIgnoreCase(service) || provider.getServiceInterfaceClass().getSimpleName().equalsIgnoreCase(service) || provider.getServiceInterfaceClass().getName().equalsIgnoreCase(service) || StringUtils.isEmpty(service); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandler.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandler.java index 0eaf1a22d0a..9dd0a8a36b0 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandler.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandler.java @@ -22,6 +22,7 @@ import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.telnet.TelnetHandler; import org.apache.dubbo.remoting.telnet.support.Help; +import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ConsumerMethodModel; import org.apache.dubbo.rpc.model.ConsumerModel; @@ -30,9 +31,6 @@ import java.lang.reflect.Method; -import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.getConsumerAddressNum; -import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.isRegistered; - /** * ListTelnetHandler handler list services and its methods details. */ @@ -87,11 +85,11 @@ private void printAllProvidedServices(StringBuilder buf, boolean detail) { } for (ProviderModel provider : ApplicationModel.allProviderModels()) { - buf.append(provider.getServiceName()); + buf.append(provider.getServiceKey()); if (detail) { buf.append(" -> "); buf.append(" published: "); - buf.append(isRegistered(provider.getServiceName()) ? "Y" : "N"); + buf.append(ApplicationModel.isRegistered(provider.getServiceKey()) ? "Y" : "N"); } buf.append("\r\n"); } @@ -103,11 +101,11 @@ private void printAllReferredServices(StringBuilder buf, boolean detail) { } for (ConsumerModel consumer : ApplicationModel.allConsumerModels()) { - buf.append(consumer.getServiceName()); + buf.append(consumer.getServiceKey()); if (detail) { buf.append(" -> "); buf.append(" addresses: "); - buf.append(getConsumerAddressNum(consumer.getServiceName())); + buf.append(((AbstractClusterInvoker) consumer.getInvoker()).getDirectory().getAllInvokers().size()); } } } @@ -120,7 +118,7 @@ private void printSpecifiedService(String service, StringBuilder buf, boolean de private void printSpecifiedProvidedService(String service, StringBuilder buf, boolean detail) { for (ProviderModel provider : ApplicationModel.allProviderModels()) { if (isProviderMatched(service,provider)) { - buf.append(provider.getServiceName()).append(" (as provider):\r\n"); + buf.append(provider.getServiceKey()).append(" (as provider):\r\n"); for (ProviderMethodModel method : provider.getAllMethods()) { printMethod(method.getMethod(), buf, detail); } @@ -131,7 +129,7 @@ private void printSpecifiedProvidedService(String service, StringBuilder buf, bo private void printSpecifiedReferredService(String service, StringBuilder buf, boolean detail) { for (ConsumerModel consumer : ApplicationModel.allConsumerModels()) { if (isConsumerMatcher(service,consumer)) { - buf.append(consumer.getServiceName()).append(" (as consumer):\r\n"); + buf.append(consumer.getServiceKey()).append(" (as consumer):\r\n"); for (ConsumerMethodModel method : consumer.getAllMethods()) { printMethod(method.getMethod(), buf, detail); } @@ -149,13 +147,13 @@ private void printMethod(Method method, StringBuilder buf, boolean detail) { } private boolean isProviderMatched(String service, ProviderModel provider) { - return service.equalsIgnoreCase(provider.getServiceName()) + return service.equalsIgnoreCase(provider.getServiceKey()) || service.equalsIgnoreCase(provider.getServiceInterfaceClass().getName()) || service.equalsIgnoreCase(provider.getServiceInterfaceClass().getSimpleName()); } private boolean isConsumerMatcher(String service,ConsumerModel consumer) { - return service.equalsIgnoreCase(consumer.getServiceName()) + return service.equalsIgnoreCase(consumer.getServiceKey()) || service.equalsIgnoreCase(consumer.getServiceInterfaceClass().getName()) || service.equalsIgnoreCase(consumer.getServiceInterfaceClass().getSimpleName()); } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler b/dubbo-rpc/dubbo-rpc-dubbo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler index 99111639c26..ef32515fe7a 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler @@ -5,5 +5,4 @@ pwd=org.apache.dubbo.rpc.protocol.dubbo.telnet.CurrentTelnetHandler invoke=org.apache.dubbo.rpc.protocol.dubbo.telnet.InvokeTelnetHandler trace=org.apache.dubbo.rpc.protocol.dubbo.telnet.TraceTelnetHandler count=org.apache.dubbo.rpc.protocol.dubbo.telnet.CountTelnetHandler -select=org.apache.dubbo.rpc.protocol.dubbo.telnet.SelectTelnetHandler -shutdown=org.apache.dubbo.rpc.protocol.dubbo.telnet.ShutdownTelnetHandler \ No newline at end of file +select=org.apache.dubbo.rpc.protocol.dubbo.telnet.SelectTelnetHandler \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/FutureFilterTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/FutureFilterTest.java index 500a95eeacb..1a1b0fd4f11 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/FutureFilterTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/FutureFilterTest.java @@ -30,7 +30,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.apache.dubbo.config.Constants.ON_THROW_METHOD_KEY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -77,7 +76,7 @@ public void testSyncCallbackHasException() throws RpcException, Throwable { AppResponse result = new AppResponse(); result.setException(new RuntimeException()); given(invoker.invoke(invocation)).willReturn(result); - URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&" + ON_THROW_METHOD_KEY + "=echo"); + URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&onthrow.method=echo"); given(invoker.getUrl()).willReturn(url); eventFilter.invoke(invoker, invocation).recreate(); diff --git a/pom.xml b/pom.xml index 084674489c5..7bdde08179c 100644 --- a/pom.xml +++ b/pom.xml @@ -146,7 +146,6 @@ dubbo-bom dubbo-all dubbo-distribution - dubbo-metadata-report dubbo-configcenter dubbo-dependencies dubbo-event