Remaining works of config-api refactor (#13045)

* * Move Configurator & Factory to common

* * Move ServiceNameMapping & MappingListener & MappingChangedEvent to common
* Add ServiceNameMappingUtils

* * Move ClusterUtils to common

* * Add ClusterInvokerFactory

* * Move InterfaceConfigValidator & MethodConfigValidator to cluster
* Move ConfigCenterConfigValidator to configcenter-api

* * Move DefaultMetricsServiceExporter to metrics-default

* * Move Lifecycles

* * Fix a part cyclic dependencies problem

* * Move ApplicationPostOfflineLifecycle to dubbo-registry

* * Fix a part cycle dependencies problem

* * Fix ut about MetadataReportInstance & Move Prometheus ut to metrics
* Move ClusterInvokerFactory to rpc-api

* * Update config-api pom

* * Add license

* * Fix module version of metadata-api

* * Move some MetadataService API to registry-api

* Add interface ApplicationMetadataUpdater to reduce the depedencies of  dubbo-metadata on dubbo-registry

* Temporary remove some tests that caused cyclic reference

* Temporary remove some tests that caused cyclic reference

* Add license

* Add test-config module for test

* Add license

* Fix pom

* Tests fix

* Pom fix

* Fix a bean registry problem

* Move config-test to dubbo-config

* Fix pom

* Add removed test

* Add removed test

* Remove application.yaml

* Fix version

* Fix codestyle

* Fix spi file

* Fix dependencies of dubbo-demo-native

* Fix dependencies of dubbo-demo-native

* Fix dependencies of dubbo-demo-native

* Fix dependencies of dubbo-demo-native

* Fix dependencies of dubbo-demo-native

* Fix dependencies of dubbo-demo-native

* Fix dependencies of dubbo-rpc

* Fix dependencies of dubbo-rpc-rest

* Fix dependencies of dubbo-rpc-rest

* Fix dependencies of dubbo-rpc-rest

* Fix dependencies of dubbo-rpc-rest

* Fix spi file of ApplicationDeployListener

* Fix test about exporter count

* Fix test about exporter count

* Update pom

* Add test msg

* Change MetadataUpdater init process

* Change MetadataUpdater init process

* Change MetadataUpdater init process

* Change MetadataUpdater init process

* Fix dependencies of dubbo-rpc-rest

* Using lifecycle instead of ApplicationDeployListener

* Update doc

* Update log

* Fix pom of dubbo-config-spring & dubbo-plugin-security & dubbo-rpc-rest

* Add scope for ApplicationLifecycle

* Fix pom of dubbo-config-spring

* Fix ut of rpc-rest(PR#13087)

* Fix bug of DefaultClusterInvokerFactory

* Fix bug of DefaultClusterInvokerFactory

* Fix bug of DefaultClusterInvokerFactory

* Fix bug of ServiceInstanceCustomizer

* Add dubbo-config-test to ignore list

* Code style & bug fix

* Remove unused import

* Add zookeeper-curator for test

* Test zookeeper version

* Test zookeeper version

* Test fix zookeeper

* Remove unnecessary modification

* Add test props

* Remove unused dependencies

* Code style fix

* Remove unnecessary dependencies & Code style fix

* Fix dependencies

* Update pom.xml

* Add dubbo-config-test as ignored

* Refactor ClusterInvokerFactory

* Refactor ClusterInvokerFactory

* Refactor ClusterInvokerFactory
This commit is contained in:
namelessssssssssss 2023-10-03 22:40:12 +08:00 committed by GitHub
parent 9eb83d16bb
commit f020f3e3d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
257 changed files with 1115 additions and 305 deletions

View File

@ -30,6 +30,7 @@ dubbo-config
dubbo-config-api
dubbo-config-spring
dubbo-config-spring6
dubbo-config-test
dubbo-configcenter
dubbo-configcenter-api
dubbo-configcenter-file

View File

@ -24,6 +24,8 @@ import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_CLUSTER;
/**
* Cluster. (SPI, Singleton, ThreadSafe)
* <p>
@ -31,11 +33,9 @@ import org.apache.dubbo.rpc.model.ScopeModelUtil;
* <a href="http://en.wikipedia.org/wiki/Fault-tolerant_system">Fault-Tolerant</a>
*
*/
@SPI(Cluster.DEFAULT)
@SPI(DEFAULT_CLUSTER)
public interface Cluster {
String DEFAULT = "failover";
/**
* Merge the directory invokers to a virtual invoker.
*
@ -53,7 +53,7 @@ public interface Cluster {
static Cluster getCluster(ScopeModel scopeModel, String name, boolean wrap) {
if (StringUtils.isEmpty(name)) {
name = Cluster.DEFAULT;
name = DEFAULT_CLUSTER;
}
return ScopeModelUtil.getApplicationModel(scopeModel).getExtensionLoader(Cluster.class).getExtension(name, wrap);
}

View File

@ -17,6 +17,8 @@
package org.apache.dubbo.rpc.cluster;
import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
import org.apache.dubbo.rpc.cluster.factory.DefaultClusterInvokerFactory;
import org.apache.dubbo.rpc.cluster.factory.StaticDirectoryStrategy;
import org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher;
import org.apache.dubbo.rpc.cluster.support.ClusterUtils;
import org.apache.dubbo.rpc.model.ApplicationModel;
@ -25,10 +27,13 @@ import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ScopeModelInitializer;
public class ClusterScopeModelInitializer implements ScopeModelInitializer {
@Override
public void initializeFrameworkModel(FrameworkModel frameworkModel) {
ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory();
beanFactory.registerBean(RouterSnapshotSwitcher.class);
beanFactory.registerBean(StaticDirectoryStrategy.class);
beanFactory.registerBean(DefaultClusterInvokerFactory.class);
}
@Override

View File

@ -0,0 +1,56 @@
/*
* 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.rpc.cluster.factory;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.cluster.ClusterInvokerFactory;
import org.apache.dubbo.rpc.cluster.Directory;
import org.apache.dubbo.rpc.model.ScopeModel;
import java.util.List;
import static org.apache.dubbo.rpc.cluster.Cluster.getCluster;
public class DefaultClusterInvokerFactory implements ClusterInvokerFactory {
private final List<DirectoryStrategy> strategies;
public DefaultClusterInvokerFactory(ScopeModel scopeModel) {
this.strategies = scopeModel.getBeanFactory().getBeansOfType(DirectoryStrategy.class);
}
/**
* Build an Invoker with StaticDirectory.
*
* @param config config
* @return ClusterInvoker
*/
@Override
public Invoker<?> getInvoker(ClusterInvokerConfig config) {
Directory<?> directory = null;
for (DirectoryStrategy strategy : strategies) {
if (strategy.name().equals(config.getDirectoryName())) {
directory = strategy.createDirectory(config);
break;
}
}
return getCluster(config.getScopeModel(), config.getClusterName(), config.isWrappedCluster())
.join(directory,config.isWrappedInvoker());
}
}

View File

@ -0,0 +1,27 @@
/*
* 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.rpc.cluster.factory;
import org.apache.dubbo.rpc.cluster.ClusterInvokerFactory;
import org.apache.dubbo.rpc.cluster.Directory;
public interface DirectoryStrategy {
ClusterInvokerFactory.DirectoryNames name();
<T> Directory<T> createDirectory(ClusterInvokerFactory.ClusterInvokerConfig clusterInvokerConfig);
}

View File

@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.cluster.factory;
import org.apache.dubbo.rpc.cluster.ClusterInvokerFactory;
import org.apache.dubbo.rpc.cluster.Directory;
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
public class StaticDirectoryStrategy implements DirectoryStrategy {
@Override
public ClusterInvokerFactory.DirectoryNames name() {
return ClusterInvokerFactory.DirectoryNames.STATIC;
}
@Override
public <T> Directory<T> createDirectory(ClusterInvokerFactory.ClusterInvokerConfig clusterInvokerConfig) {
return new StaticDirectory(clusterInvokerConfig.getServiceUrl(),clusterInvokerConfig.getInvokersToJoin());
}
}

View File

@ -23,8 +23,6 @@ import org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster;
public class ZoneAwareCluster extends AbstractCluster {
public final static String NAME = "zone-aware";
@Override
protected <T> AbstractClusterInvoker<T> doJoin(Directory<T> directory) throws RpcException {
return new ZoneAwareClusterInvoker<T>(directory);

View File

@ -49,6 +49,7 @@ import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
import static org.apache.dubbo.rpc.Constants.SCOPE_KEY;
import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_CLUSTER;
import static org.apache.dubbo.rpc.cluster.Constants.PEER_KEY;
/**
@ -291,7 +292,7 @@ public class ScopeClusterInvoker<T> implements ClusterInvoker<T>, ExporterChange
Invoker<?> invoker = protocolSPI.refer(getInterface(), consumerUrl);
List<Invoker<?>> invokers = new ArrayList<>();
invokers.add(invoker);
injvmInvoker = Cluster.getCluster(url.getScopeModel(), Cluster.DEFAULT, false).join(new StaticDirectory(url, invokers), true);
injvmInvoker = Cluster.getCluster(url.getScopeModel(), DEFAULT_CLUSTER, false).join(new StaticDirectory(url, invokers), true);
}
}
}

View File

@ -0,0 +1,2 @@
interface=org.apache.dubbo.config.validator.InterfaceConfigValidator
method=org.apache.dubbo.config.validator.MethodConfigValidator

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.config.deploy.lifecycle.application;
import org.apache.dubbo.common.deploy.ApplicationDeployListener;
import org.apache.dubbo.common.deploy.DeployState;
import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
import org.apache.dubbo.config.deploy.context.ApplicationContext;
import org.apache.dubbo.config.deploy.lifecycle.Lifecycle;
@ -29,10 +30,10 @@ import org.apache.dubbo.rpc.model.ModuleModel;
* Used in an application Lifecycle managing procedure, and dubbo packages
* can implement this interface to define what to do when application status changes.
* <p>
* Note: If you want to auto registry some extensions to BeanFactory, use {@link ApplicationDeployListener} instead.
* Note: If you want to auto registry some extensions to BeanFactory that shared in an application, consider use {@link ApplicationDeployListener}.
* <br>
*/
@SPI
@SPI(scope = ExtensionScope.APPLICATION)
public interface ApplicationLifecycle extends Lifecycle<ApplicationContext> {
/**

View File

@ -87,7 +87,7 @@ public class ApplicationLifecycleManager{
lifecycles.forEach(applicationLifecycle -> {
if(applicationLifecycle.needInitialize()) {
beanFactory.registerBean(applicationLifecycle);
sequence.append(applicationLifecycle.getClass().getSimpleName()).append("->");
sequence.append(applicationLifecycle.getClass().getSimpleName()).append("-> ");
}
});
sequence.append(" [END]");

View File

@ -17,20 +17,13 @@
package org.apache.dubbo.metadata;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RegistryConstants;
import org.apache.dubbo.common.extension.SPI;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;
import org.apache.dubbo.rpc.service.Destroyable;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import static java.util.Collections.emptySet;
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
import static org.apache.dubbo.common.extension.ExtensionScope.APPLICATION;
/**
@ -59,46 +52,6 @@ public interface ServiceNameMapping extends Destroyable {
return ScopeModelUtil.getApplicationModel(scopeModel).getDefaultExtension(ServiceNameMapping.class);
}
static String buildMappingKey(URL url) {
return buildGroup(url.getServiceInterface());
}
static String buildGroup(String serviceInterface) {
//the issue : https://github.com/apache/dubbo/issues/4671
// return DEFAULT_MAPPING_GROUP + SLASH + serviceInterface;
return serviceInterface;
}
static String toStringKeys(Set<String> serviceNames) {
if (CollectionUtils.isEmpty(serviceNames)) {
return "";
}
StringBuilder builder = new StringBuilder();
for (String n : serviceNames) {
builder.append(n);
builder.append(COMMA_SEPARATOR);
}
builder.deleteCharAt(builder.length() - 1);
return builder.toString();
}
static Set<String> getAppNames(String content) {
if (StringUtils.isBlank(content)) {
return emptySet();
}
return new TreeSet<>(Arrays.asList(content.split(COMMA_SEPARATOR)));
}
static Set<String> getMappingByUrl(URL consumerURL) {
String providedBy = consumerURL.getParameter(RegistryConstants.PROVIDED_BY);
if(StringUtils.isBlank(providedBy)) {
return null;
}
return AbstractServiceNameMapping.parseServices(providedBy);
}
/**
* Get the latest mapping result from remote center and register listener at the same time to get notified once mapping changes.
*

View File

@ -0,0 +1,30 @@
/*
* 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;
import org.apache.dubbo.rpc.model.ApplicationModel;
/**
* Provides a way to access ServiceInstanceMetadataUtils without importing registry-api.
*/
public interface ApplicationMetadataUpdater {
/**
* Refresh service metadata of an application.
*/
void refreshMetadataAndInstance(ApplicationModel applicationModel);
}

View File

@ -139,4 +139,8 @@ public interface Constants {
String RULE_VERSION_V27 = "v2.7";
String RULE_VERSION_V30 = "v3.0";
String ZONE_AWARE_CLUSTER_NAME = "zone-aware";
String DEFAULT_CLUSTER = "failover";
}

View File

@ -30,53 +30,6 @@
<skip_maven_deploy>false</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-default</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-registry</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-metadata</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-config-center</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-tracing</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
@ -85,7 +38,8 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-api</artifactId>
<!--TODO: swap to metrics-event-->
<artifactId>dubbo-metrics-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
@ -113,13 +67,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-rest</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty4</artifactId>
@ -141,20 +88,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-multicast</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-zookeeper</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
@ -171,53 +104,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-zookeeper</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-redis</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-configcenter-zookeeper</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-configcenter-nacos</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-filter-cache</artifactId>
@ -259,6 +145,5 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -35,13 +35,11 @@ import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.config.utils.ConfigValidationUtils;
import org.apache.dubbo.metadata.MetadataPublisher;
import org.apache.dubbo.rpc.cluster.ClusterInvokerFactory;
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.ClusterUtils;
import org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareCluster;
import org.apache.dubbo.rpc.model.AsyncMethodInfo;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.DubboStub;
@ -99,8 +97,10 @@ import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL;
import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_CLUSTER;
import static org.apache.dubbo.rpc.cluster.Constants.PEER_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.ZONE_AWARE_CLUSTER_NAME;
/**
* Please avoid using this class for any new application,
@ -615,6 +615,7 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private void createInvoker() {
ClusterInvokerFactory clusterInvokerFactory = getScopeModel().getBeanFactory().getBean(ClusterInvokerFactory.class);
if (urls.size() == 1) {
URL curUrl = urls.get(0);
invoker = protocolSPI.refer(interfaceClass, curUrl);
@ -623,7 +624,9 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
!curUrl.getParameter(UNLOAD_CLUSTER_RELATED, false)) {
List<Invoker<?>> invokers = new ArrayList<>();
invokers.add(invoker);
invoker = Cluster.getCluster(getScopeModel(), Cluster.DEFAULT).join(new StaticDirectory(curUrl, invokers), true);
invoker = clusterInvokerFactory.getInvoker(
new ClusterInvokerFactory.ClusterInvokerConfig(getScopeModel(),DEFAULT_CLUSTER,curUrl,invokers,true,true)
);
}
} else {
List<Invoker<?>> invokers = new ArrayList<>();
@ -642,18 +645,22 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
if (registryUrl != null) {
// registry url is available
// for multi-subscription scenario, use 'zone-aware' policy by default
String cluster = registryUrl.getParameter(CLUSTER_KEY, ZoneAwareCluster.NAME);
String cluster = registryUrl.getParameter(CLUSTER_KEY, ZONE_AWARE_CLUSTER_NAME);
// The invoker wrap sequence would be: ZoneAwareClusterInvoker(StaticDirectory) -> FailoverClusterInvoker
// (RegistryDirectory, routing happens here) -> Invoker
invoker = Cluster.getCluster(registryUrl.getScopeModel(), cluster, false).join(new StaticDirectory(registryUrl, invokers), false);
invoker = clusterInvokerFactory.getInvoker(
new ClusterInvokerFactory.ClusterInvokerConfig(registryUrl.getScopeModel(), cluster, registryUrl, invokers)
);
} else {
// not a registry url, must be direct invoke.
if (CollectionUtils.isEmpty(invokers)) {
throw new IllegalArgumentException("invokers == null");
}
URL curUrl = invokers.get(0).getUrl();
String cluster = curUrl.getParameter(CLUSTER_KEY, Cluster.DEFAULT);
invoker = Cluster.getCluster(getScopeModel(), cluster).join(new StaticDirectory(curUrl, invokers), true);
String cluster = curUrl.getParameter(CLUSTER_KEY, DEFAULT_CLUSTER);
invoker = clusterInvokerFactory.getInvoker(
new ClusterInvokerFactory.ClusterInvokerConfig(getScopeModel(), cluster, curUrl, invokers, true, true)
);
}
}
}

View File

@ -559,6 +559,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
String [] methods = Optional.ofNullable(url.getParameter(METHODS_KEY)).map(i->i.split(",")).orElse( new String[]{});
Arrays.stream(methods).forEach( method-> {
RpcInvocation invocation = new RpcInvocation(url.getServiceKey(),url.getServiceModel(),method,interfaceName, url.getProtocolServiceKey(), null, null,null,null,null,null);
//TODO: this event depends on too much outer API.
MetricsEventBus.publish(MetricsInitEvent.toMetricsInitEvent(application.getApplicationModel(),invocation));
});
}

View File

@ -34,6 +34,7 @@ import java.util.concurrent.ExecutorService;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_METRICS_COLLECTOR_EXCEPTION;
import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMETHEUS;
//TODO: move to metrics-default
/**
* Export metrics service
*/

View File

@ -1 +0,0 @@
exporter=org.apache.dubbo.config.metadata.ExporterDeployListener

View File

@ -1,7 +1,5 @@
config-center=org.apache.dubbo.config.validator.ConfigCenterConfigValidator
consumer=org.apache.dubbo.config.validator.ConsumerConfigValidator
interface=org.apache.dubbo.config.validator.InterfaceConfigValidator
method=org.apache.dubbo.config.validator.MethodConfigValidator
provider=org.apache.dubbo.config.validator.ProviderConfigValidator
reference=org.apache.dubbo.config.validator.ReferenceConfigValidator
service=org.apache.dubbo.config.validator.ServiceConfigValidator

View File

@ -1,6 +1,5 @@
config-pre-handle=org.apache.dubbo.config.deploy.lifecycle.application.ApplicationConfigPreHandleLifecycle
config-post-handle=org.apache.dubbo.config.deploy.lifecycle.application.ApplicationConfigPostHandleLifecycle
module-initialize=org.apache.dubbo.config.deploy.lifecycle.application.ModuleInitializeLifecycle
post-offline=org.apache.dubbo.config.deploy.lifecycle.application.ApplicationPostOfflineLifecycle
app-prepare=org.apache.dubbo.config.deploy.lifecycle.application.ApplicationPrepareLifecycle
validator-registry=org.apache.dubbo.config.deploy.lifecycle.application.ValidatorRegistryDeployListener

View File

@ -1 +0,0 @@
metadata-url=org.apache.dubbo.config.metadata.MetadataServiceURLParamsMetadataCustomizer

View File

@ -19,8 +19,6 @@ package org.apache.dubbo.config;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.validator.ConsumerConfigValidator;
import org.apache.dubbo.config.validator.InterfaceConfigValidator;
import org.apache.dubbo.config.validator.MethodConfigValidator;
import org.apache.dubbo.config.validator.ProviderConfigValidator;
import org.apache.dubbo.config.validator.ReferenceConfigValidator;
import org.apache.dubbo.config.validator.ServiceConfigValidator;
@ -48,19 +46,15 @@ public class ConfigValidatorExistTest {
validateFacade = new ConfigValidateFacade(applicationModel);
Assertions.assertNotNull(validateFacade);
Assertions.assertTrue(validateFacade.getValidators().size() >= 7);
Assertions.assertTrue(validateFacade.getValidators().size() >= 4);
try(
MockedStatic<ConsumerConfigValidator> configValidatorMockedStatic = Mockito.mockStatic(ConsumerConfigValidator.class);
MockedStatic<InterfaceConfigValidator> interfaceConfigValidatorMockedStatic = Mockito.mockStatic(InterfaceConfigValidator.class);
MockedStatic<MethodConfigValidator> methodConfigValidatorMockedStatic = Mockito.mockStatic(MethodConfigValidator.class);
MockedStatic<ProviderConfigValidator> providerConfigValidatorMockedStatic = Mockito.mockStatic(ProviderConfigValidator.class);
MockedStatic<ReferenceConfigValidator> referenceConfigValidatorMockedStatic = Mockito.mockStatic(ReferenceConfigValidator.class);
MockedStatic<ServiceConfigValidator> serviceConfigValidatorMockedStatic = Mockito.mockStatic(ServiceConfigValidator.class);
MockedStatic<ConsumerConfigValidator> configValidatorMockedStatic = Mockito.mockStatic(ConsumerConfigValidator.class);
MockedStatic<ProviderConfigValidator> providerConfigValidatorMockedStatic = Mockito.mockStatic(ProviderConfigValidator.class);
MockedStatic<ReferenceConfigValidator> referenceConfigValidatorMockedStatic = Mockito.mockStatic(ReferenceConfigValidator.class);
MockedStatic<ServiceConfigValidator> serviceConfigValidatorMockedStatic = Mockito.mockStatic(ServiceConfigValidator.class);
){
configValidatorMockedStatic.when(()-> ConsumerConfigValidator.validateConsumerConfig(any())).thenCallRealMethod();
interfaceConfigValidatorMockedStatic.when(()-> InterfaceConfigValidator.validateAbstractInterfaceConfig(any())).thenCallRealMethod();
methodConfigValidatorMockedStatic.when(()-> MethodConfigValidator.validateMethodConfig(any())).thenCallRealMethod();
providerConfigValidatorMockedStatic.when(()-> ProviderConfigValidator.validateProviderConfig(any())).thenCallRealMethod();
referenceConfigValidatorMockedStatic.when(()-> ReferenceConfigValidator.validateReferenceConfig(any())).thenCallRealMethod();
serviceConfigValidatorMockedStatic.when(()->ServiceConfigValidator.validateServiceConfig(any())).thenCallRealMethod();
@ -77,8 +71,6 @@ public class ConfigValidatorExistTest {
triggerValidate(new ServiceConfig<>());
configValidatorMockedStatic.verify(()-> ConsumerConfigValidator.validateConsumerConfig(any()),atLeastOnce());
interfaceConfigValidatorMockedStatic.verify(()-> InterfaceConfigValidator.validateAbstractInterfaceConfig(any()),atLeastOnce());
methodConfigValidatorMockedStatic.verify(()->MethodConfigValidator.validateMethodConfig(any()),atLeastOnce());
providerConfigValidatorMockedStatic.verify(()->ProviderConfigValidator.validateProviderConfig(any()),atLeastOnce());
referenceConfigValidatorMockedStatic.verify(()->ReferenceConfigValidator.validateReferenceConfig(any()),atLeastOnce());
serviceConfigValidatorMockedStatic.verify(()-> ServiceConfigValidator.validateServiceConfig(any()),atLeastOnce());

View File

@ -31,7 +31,6 @@
<!-- Uncomment spring_version property to check Spring 4.x compatibility -->
<!-- <spring_version>4.3.30.RELEASE</spring_version> -->
</properties>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
@ -254,6 +253,7 @@
<artifactId>curator-x-discovery</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
@ -278,6 +278,12 @@
<artifactId>nacos-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-test-common</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -294,7 +300,6 @@
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>

View File

@ -70,6 +70,12 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-test-common</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -0,0 +1,279 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-config</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dubbo-config-test</artifactId>
<properties>
<skip_maven_deploy>false</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-config-api</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-api</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-api</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-api</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-default</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-registry</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-metadata</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-config-center</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-tracing</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-monitor-api</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-api</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-api</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-injvm</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-dubbo</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-triple</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-rest</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-hessian2</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-fastjson2</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-multicast</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-zookeeper</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-zookeeper</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-redis</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-configcenter-zookeeper</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-configcenter-nacos</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-filter-cache</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-filter-validation</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-plugin-router-condition</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-plugin-router-tag</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-test-common</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -37,7 +37,6 @@ import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder;
import org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareClusterInvoker;
//import org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker;
import org.apache.dubbo.rpc.cluster.support.wrapper.ScopeClusterInvoker;
import org.apache.dubbo.rpc.listener.ListenerInvokerWrapper;
import org.apache.dubbo.rpc.model.ApplicationModel;

View File

@ -31,8 +31,8 @@ import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.SysProps;
import org.apache.dubbo.config.api.DemoService;
import org.apache.dubbo.config.deploy.DefaultApplicationDeployer;
import org.apache.dubbo.config.metadata.ConfigurableMetadataServiceExporter;
import org.apache.dubbo.config.metadata.ExporterDeployListener;
import org.apache.dubbo.metadata.deploy.ConfigurableMetadataServiceExporter;
import org.apache.dubbo.metadata.deploy.ExporterDeployListener;
import org.apache.dubbo.config.provider.impl.DemoServiceImpl;
import org.apache.dubbo.config.utils.ConfigValidationUtils;
import org.apache.dubbo.config.validator.ApplicationConfigValidator;
@ -295,11 +295,11 @@ class DubboBootstrapTest {
Exception exception = null;
try {
DubboBootstrap.getInstance()
.application(applicationConfig)
.registry(registryConfig)
.protocol(new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1))
.service(service)
.start();
.application(applicationConfig)
.registry(registryConfig)
.protocol(new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1))
.service(service)
.start();
} catch (Exception e) {
exception = e;
DubboBootstrap.reset();
@ -367,5 +367,4 @@ class DubboBootstrapTest {
public static class InterfaceConfig extends AbstractInterfaceConfig {
}
}
}

View File

@ -19,7 +19,6 @@ package org.apache.dubbo.config.bootstrap.builders;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Some files were not shown because too many files have changed in this diff Show More