Merge branch 'apache-3.0' into apache-3.1

This commit is contained in:
Albumen Kevin 2022-07-28 14:07:48 +08:00
commit 80561c1925
35 changed files with 477 additions and 88 deletions

View File

@ -192,6 +192,7 @@ public interface FilterChainBuilder {
public Result invoke(Invocation invocation) throws RpcException {
Result asyncResult = filterInvoker.invoke(invocation);
asyncResult.whenCompleteWithContext((r, t) -> {
RuntimeException filterRuntimeException = null;
for (int i = filters.size() - 1; i >= 0; i--) {
FILTER filter = filters.get(i);
try {
@ -218,14 +219,18 @@ public interface FilterChainBuilder {
listener.onError(t, filterInvoker, invocation);
}
}
} catch (Throwable filterThrowable) {
} catch (RuntimeException runtimeException) {
LOGGER.error(String.format("Exception occurred while executing the %s filter named %s.", i, filter.getClass().getSimpleName()));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Whole filter list is: %s", filters.stream().map(tmpFilter -> tmpFilter.getClass().getSimpleName()).collect(Collectors.toList())));
}
throw filterThrowable;
filterRuntimeException = runtimeException;
t = runtimeException;
}
}
if (filterRuntimeException != null) {
throw filterRuntimeException;
}
});
return asyncResult;

View File

@ -112,6 +112,7 @@ public class Environment extends LifecycleAdapter implements ApplicationExt {
* @deprecated only for ut
*/
@Deprecated
@DisableInject
public void setLocalMigrationRule(String localMigrationRule) {
this.localMigrationRule = localMigrationRule;
}

View File

@ -132,21 +132,25 @@ public class ModuleEnvironment extends Environment implements ModuleExt {
}
@Override
@DisableInject
public void setLocalMigrationRule(String localMigrationRule) {
applicationDelegate.setLocalMigrationRule(localMigrationRule);
}
@Override
@DisableInject
public void setExternalConfigMap(Map<String, String> externalConfiguration) {
applicationDelegate.setExternalConfigMap(externalConfiguration);
}
@Override
@DisableInject
public void setAppExternalConfigMap(Map<String, String> appExternalConfiguration) {
applicationDelegate.setAppExternalConfigMap(appExternalConfiguration);
}
@Override
@DisableInject
public void setAppConfigMap(Map<String, String> appConfiguration) {
applicationDelegate.setAppConfigMap(appConfiguration);
}

View File

@ -41,6 +41,7 @@ import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelAccessor;
import org.apache.dubbo.rpc.model.ScopeModelAware;
import java.io.BufferedReader;
import java.io.IOException;
@ -134,6 +135,8 @@ public class ExtensionLoader<T> {
private static SoftReference<Map<java.net.URL,List<String>>> urlListMapCache = new SoftReference<>(new ConcurrentHashMap<>());
private static List<String> ignoredInjectMethodsDesc = getIgnoredInjectMethodsDesc();
/**
* Record all unacceptable exceptions when using SPI
*/
@ -187,6 +190,13 @@ public class ExtensionLoader<T> {
return asList(strategies);
}
private static List<String> getIgnoredInjectMethodsDesc() {
List<String> ignoreInjectMethodsDesc = new ArrayList<>();
Arrays.stream(ScopeModelAware.class.getMethods()).map(ReflectUtils::getDesc).forEach(ignoreInjectMethodsDesc::add);
Arrays.stream(ExtensionAccessorAware.class.getMethods()).map(ReflectUtils::getDesc).forEach(ignoreInjectMethodsDesc::add);
return ignoreInjectMethodsDesc;
}
ExtensionLoader(Class<?> type, ExtensionDirector extensionDirector, ScopeModel scopeModel) {
this.type = type;
this.extensionDirector = extensionDirector;
@ -835,11 +845,23 @@ public class ExtensionLoader<T> {
continue;
}
/**
* Check {@link DisableInject} to see if we need auto injection for this property
* Check {@link DisableInject} to see if we need auto-injection for this property
*/
if (method.isAnnotationPresent(DisableInject.class)) {
continue;
}
// When spiXXX implements ScopeModelAware, ExtensionAccessorAware,
// the setXXX of ScopeModelAware and ExtensionAccessorAware does not need to be injected
if (method.getDeclaringClass() == ScopeModelAware.class) {
continue;
}
if (instance instanceof ScopeModelAware || instance instanceof ExtensionAccessorAware) {
if (ignoredInjectMethodsDesc.contains(ReflectUtils.getDesc(method))) {
continue;
}
}
Class<?> pt = method.getParameterTypes()[0];
if (ReflectUtils.isPrimitives(pt)) {
continue;

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.common.json;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
public interface JSON {
boolean isSupport();
@ -27,4 +28,25 @@ public interface JSON {
<T> List<T> toJavaList(String json, Class<T> clazz);
String toJson(Object obj);
List<?> getList(Map<String, ?> obj, String key);
List<Map<String, ?>> getListOfObjects(Map<String, ?> obj, String key);
List<String> getListOfStrings(Map<String, ?> obj, String key);
Map<String, ?> getObject(Map<String, ?> obj, String key);
Double getNumberAsDouble(Map<String, ?> obj, String key);
Integer getNumberAsInteger(Map<String, ?> obj, String key);
Long getNumberAsLong(Map<String, ?> obj, String key);
String getString(Map<String, ?> obj, String key);
List<Map<String, ?>> checkObjectList(List<?> rawList);
List<String> checkStringList(List<?> rawList);
}

View File

@ -0,0 +1,238 @@
/*
* 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.json.impl;
import org.apache.dubbo.common.json.JSON;
import java.util.List;
import java.util.Map;
public abstract class AbstractJSONImpl implements JSON {
@Override
public List<?> getList(Map<String, ?> obj, String key) {
assert obj != null;
assert key != null;
if (!obj.containsKey(key)) {
return null;
}
Object value = obj.get(key);
if (!(value instanceof List)) {
throw new ClassCastException(
String.format("value '%s' for key '%s' in '%s' is not List", value, key, obj));
}
return (List<?>) value;
}
/**
* Gets a list from an object for the given key, and verifies all entries are objects. If the key
* is not present, this returns null. If the value is not a List or an entry is not an object,
* throws an exception.
*/
@Override
public List<Map<String, ?>> getListOfObjects(Map<String, ?> obj, String key) {
assert obj != null;
List<?> list = getList(obj, key);
if (list == null) {
return null;
}
return checkObjectList(list);
}
/**
* Gets a list from an object for the given key, and verifies all entries are strings. If the key
* is not present, this returns null. If the value is not a List or an entry is not a string,
* throws an exception.
*/
@Override
public List<String> getListOfStrings(Map<String, ?> obj, String key) {
assert obj != null;
List<?> list = getList(obj, key);
if (list == null) {
return null;
}
return checkStringList(list);
}
/**
* Gets an object from an object for the given key. If the key is not present, this returns null.
* If the value is not a Map, throws an exception.
*/
@SuppressWarnings("unchecked")
@Override
public Map<String, ?> getObject(Map<String, ?> obj, String key) {
assert obj != null;
assert key != null;
if (!obj.containsKey(key)) {
return null;
}
Object value = obj.get(key);
if (!(value instanceof Map)) {
throw new ClassCastException(
String.format("value '%s' for key '%s' in '%s' is not object", value, key, obj));
}
return (Map<String, ?>) value;
}
/**
* Gets a number from an object for the given key. If the key is not present, this returns null.
* If the value does not represent a double, throws an exception.
*/
@Override
public Double getNumberAsDouble(Map<String, ?> obj, String key) {
assert obj != null;
assert key != null;
if (!obj.containsKey(key)) {
return null;
}
Object value = obj.get(key);
if (value instanceof Double) {
return (Double) value;
}
if (value instanceof String) {
try {
return Double.parseDouble((String) value);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
String.format("value '%s' for key '%s' is not a double", value, key));
}
}
throw new IllegalArgumentException(
String.format("value '%s' for key '%s' in '%s' is not a number", value, key, obj));
}
/**
* Gets a number from an object for the given key, casted to an integer. If the key is not
* present, this returns null. If the value does not represent an integer, throws an exception.
*/
@Override
public Integer getNumberAsInteger(Map<String, ?> obj, String key) {
assert obj != null;
assert key != null;
if (!obj.containsKey(key)) {
return null;
}
Object value = obj.get(key);
if (value instanceof Double) {
Double d = (Double) value;
int i = d.intValue();
if (i != d) {
throw new ClassCastException("Number expected to be integer: " + d);
}
return i;
}
if (value instanceof String) {
try {
return Integer.parseInt((String) value);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
String.format("value '%s' for key '%s' is not an integer", value, key));
}
}
throw new IllegalArgumentException(
String.format("value '%s' for key '%s' is not an integer", value, key));
}
/**
* Gets a number from an object for the given key, casted to an long. If the key is not
* present, this returns null. If the value does not represent a long integer, throws an
* exception.
*/
@Override
public Long getNumberAsLong(Map<String, ?> obj, String key) {
assert obj != null;
assert key != null;
if (!obj.containsKey(key)) {
return null;
}
Object value = obj.get(key);
if (value instanceof Double) {
Double d = (Double) value;
long l = d.longValue();
if (l != d) {
throw new ClassCastException("Number expected to be long: " + d);
}
return l;
}
if (value instanceof String) {
try {
return Long.parseLong((String) value);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
String.format("value '%s' for key '%s' is not a long integer", value, key));
}
}
throw new IllegalArgumentException(
String.format("value '%s' for key '%s' is not a long integer", value, key));
}
/**
* Gets a string from an object for the given key. If the key is not present, this returns null.
* If the value is not a String, throws an exception.
*/
@Override
public String getString(Map<String, ?> obj, String key) {
assert obj != null;
assert key != null;
if (!obj.containsKey(key)) {
return null;
}
Object value = obj.get(key);
if (!(value instanceof String)) {
throw new ClassCastException(
String.format("value '%s' for key '%s' in '%s' is not String", value, key, obj));
}
return (String) value;
}
/**
* Casts a list of unchecked JSON values to a list of checked objects in Java type.
* If the given list contains a value that is not a Map, throws an exception.
*/
@SuppressWarnings("unchecked")
@Override
public List<Map<String, ?>> checkObjectList(List<?> rawList) {
assert rawList != null;
for (int i = 0; i < rawList.size(); i++) {
if (!(rawList.get(i) instanceof Map)) {
throw new ClassCastException(
String.format("value %s for idx %d in %s is not object", rawList.get(i), i, rawList));
}
}
return (List<Map<String, ?>>) rawList;
}
/**
* Casts a list of unchecked JSON values to a list of String. If the given list
* contains a value that is not a String, throws an exception.
*/
@SuppressWarnings("unchecked")
@Override
public List<String> checkStringList(List<?> rawList) {
assert rawList != null;
for (int i = 0; i < rawList.size(); i++) {
if (!(rawList.get(i) instanceof String)) {
throw new ClassCastException(
String.format(
"value '%s' for idx %d in '%s' is not string", rawList.get(i), i, rawList));
}
}
return (List<String>) rawList;
}
}

View File

@ -16,13 +16,12 @@
*/
package org.apache.dubbo.common.json.impl;
import org.apache.dubbo.common.json.JSON;
import org.apache.dubbo.common.utils.ClassUtils;
import java.lang.reflect.Type;
import java.util.List;
public class FastJsonImpl implements JSON {
public class FastJsonImpl extends AbstractJSONImpl {
@Override
public boolean isSupport() {

View File

@ -16,7 +16,6 @@
*/
package org.apache.dubbo.common.json.impl;
import org.apache.dubbo.common.json.JSON;
import org.apache.dubbo.common.utils.ClassUtils;
import com.google.gson.Gson;
@ -25,7 +24,7 @@ import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.List;
public class GsonImpl implements JSON {
public class GsonImpl extends AbstractJSONImpl {
// weak reference of com.google.gson.Gson, prevent throw exception when init
private volatile Object gsonCache = null;

View File

@ -594,7 +594,7 @@ public abstract class AbstractConfig implements Serializable {
if (overrideAll || oldOne == null) {
Object newResult = getterMethod.invoke(newOne);
// if new one is non-null and new one is not equals old one
if (newResult != null && Objects.equals(newResult, oldOne)) {
if (newResult != null && !Objects.equals(newResult, oldOne)) {
method.invoke(this, newResult);
}
}

View File

@ -223,6 +223,13 @@ public abstract class AbstractConfigManager extends LifecycleAdapter {
return config;
}
protected <C extends AbstractConfig> boolean removeIfAbsent(C config, Map<String, C> configsMap) {
if(config.getId() != null) {
return configsMap.remove(config.getId(), config);
}
return configsMap.values().removeIf(c -> config == c);
}
protected boolean isUniqueConfig(AbstractConfig config) {
if (uniqueConfigTypes.contains(config.getClass())) {
return true;
@ -639,7 +646,7 @@ public abstract class AbstractConfigManager extends LifecycleAdapter {
/**
* In some scenario, we may nee to add and remove ServiceConfig or ReferenceConfig dynamically.
* In some scenario, we may need to add and remove ServiceConfig or ReferenceConfig dynamically.
*
* @param config the config instance to remove.
* @return
@ -651,7 +658,10 @@ public abstract class AbstractConfigManager extends LifecycleAdapter {
Map<String, AbstractConfig> configs = configsCache.get(getTagName(config.getClass()));
if (CollectionUtils.isNotEmptyMap(configs)) {
return configs.values().removeIf(c -> config == c);
// lock by config type
synchronized (configs) {
return removeIfAbsent(config, configs);
}
}
return false;
}

View File

@ -32,12 +32,12 @@ public enum ConfigMode {
OVERRIDE,
/**
* Override mode: accept last config, override previous config
* Override mode: accept last config, override previous config regardless of whether the attribute of previous config is absent or not
*/
OVERRIDE_ALL,
/**
* Override mode: accept last config, override previous config
* Override mode: accept last config, override previous config only when the attribute of previous config is absent
*/
OVERRIDE_IF_ABSENT,

View File

@ -16,6 +16,7 @@
*/
package org.apache.dubbo.config.context;
import org.apache.dubbo.common.context.ModuleExt;
import org.apache.dubbo.common.extension.DisableInject;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
@ -50,10 +51,12 @@ import static org.apache.dubbo.config.AbstractConfig.getTagName;
/**
* Manage configs of module
*/
public class ModuleConfigManager extends AbstractConfigManager {
public class ModuleConfigManager extends AbstractConfigManager implements ModuleExt {
private static final Logger logger = LoggerFactory.getLogger(ModuleConfigManager.class);
public static final String NAME = "moduleConfig";
private Map<String, AbstractInterfaceConfig> serviceConfigCache = new ConcurrentHashMap<>();
private final ConfigManager applicationConfigManager;
@ -199,6 +202,17 @@ public class ModuleConfigManager extends AbstractConfigManager {
return Optional.empty();
}
@Override
protected <C extends AbstractConfig> boolean removeIfAbsent(C config, Map<String, C> configsMap) {
if(super.removeIfAbsent(config, configsMap)) {
if (config instanceof ReferenceConfigBase || config instanceof ServiceConfigBase) {
removeInterfaceConfig((AbstractInterfaceConfig) config);
}
return true;
}
return false;
}
/**
* check duplicated ReferenceConfig/ServiceConfig
*
@ -247,6 +261,21 @@ public class ModuleConfigManager extends AbstractConfigManager {
return prevConfig;
}
private void removeInterfaceConfig(AbstractInterfaceConfig config) {
String uniqueServiceName;
Map<String, AbstractInterfaceConfig> configCache;
if (config instanceof ReferenceConfigBase) {
return;
} else if (config instanceof ServiceConfigBase) {
ServiceConfigBase serviceConfig = (ServiceConfigBase) config;
uniqueServiceName = serviceConfig.getUniqueServiceName();
configCache = serviceConfigCache;
} else {
throw new IllegalArgumentException("Illegal type of parameter 'config' : " + config.getClass().getName());
}
configCache.remove(uniqueServiceName, config);
}
@Override
public void loadConfigs() {
// load dubbo.providers.xxx

View File

@ -203,6 +203,9 @@ public class ApplicationModel extends ScopeModel {
LOGGER.info(getDesc() + " is created");
}
initialize();
Assert.notNull(getApplicationServiceRepository(), "ApplicationServiceRepository can not be null");
Assert.notNull(getApplicationConfigManager(), "ApplicationConfigManager can not be null");
Assert.assertTrue(getApplicationConfigManager().isInitialized(), "ApplicationConfigManager can not be initialized");
}
@Override

View File

@ -123,7 +123,6 @@ public class FrameworkModel extends ScopeModel {
// notify destroy and clean framework resources
// see org.apache.dubbo.config.deploy.FrameworkModelCleaner
notifyDestroy();
checkApplicationDestroy();
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is destroyed");

View File

@ -61,9 +61,9 @@ public class ModuleModel extends ScopeModel {
}
initialize();
Assert.notNull(serviceRepository, "ModuleServiceRepository can not be null");
Assert.notNull(moduleConfigManager, "ModuleConfigManager can not be null");
Assert.assertTrue(moduleConfigManager.isInitialized(), "ModuleConfigManager can not be initialized");
Assert.notNull(getServiceRepository(), "ModuleServiceRepository can not be null");
Assert.notNull(getConfigManager(), "ModuleConfigManager can not be null");
Assert.assertTrue(getConfigManager().isInitialized(), "ModuleConfigManager can not be initialized");
// notify application check state
ApplicationDeployer applicationDeployer = applicationModel.getDeployer();
@ -76,8 +76,6 @@ public class ModuleModel extends ScopeModel {
protected void initialize() {
super.initialize();
this.serviceRepository = new ModuleServiceRepository(this);
this.moduleConfigManager = new ModuleConfigManager(this);
this.moduleConfigManager.initialize();
initModuleExt();
@ -158,6 +156,10 @@ public class ModuleModel extends ScopeModel {
}
public ModuleConfigManager getConfigManager() {
if (moduleConfigManager == null) {
moduleConfigManager = (ModuleConfigManager) this.getExtensionLoader(ModuleExt.class)
.getExtension(ModuleConfigManager.NAME);
}
return moduleConfigManager;
}

View File

@ -263,7 +263,7 @@ public abstract class ScopeModel implements ExtensionAccessor {
}
/**
* @return the describe string of this scope model
* @return to describe string of this scope model
*/
public String getDesc() {
if (this.desc == null) {

View File

@ -1 +1,2 @@
moduleEnvironment=org.apache.dubbo.common.config.ModuleEnvironment
moduleConfig=org.apache.dubbo.config.context.ModuleConfigManager

View File

@ -37,10 +37,6 @@ public class ExtensionDirectorTest {
String testAppSrvName = "testAppSrv";
String testMdSrvName = "testMdSrv";
String testAppProviderName = "testAppProvider";
String testModuleProviderName = "testModuleProvider";
String testFrameworkProviderName = "testFrameworkProvider";
@Test
public void testInheritanceAndScope() {
@ -144,16 +140,16 @@ public class ExtensionDirectorTest {
@Test
public void testModelDataIsolation() {
//Model Tree
//frameworkModel1
// applicationModel11
// moduleModel111
// moduleModel112
// applicationModel12
// moduleModel121
//frameworkModel2
// applicationModel21
// moduleModel211
//Model Tree
//frameworkModel1
// applicationModel11
// moduleModel111
// moduleModel112
// applicationModel12
// moduleModel121
//frameworkModel2
// applicationModel21
// moduleModel211
FrameworkModel frameworkModel1 = new FrameworkModel();
ApplicationModel applicationModel11 = new ApplicationModel(frameworkModel1);

View File

@ -16,6 +16,7 @@
*/
package org.apache.dubbo.config.context;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.apache.dubbo.config.ConsumerConfig;
@ -306,6 +307,38 @@ public class ConfigManagerTest {
configManager.addConfig(applicationConfig1);
configManager.addConfig(applicationConfig2);
assertEquals(applicationConfig1, configManager.getApplicationOrElseThrow());
// test OVERRIDE_ALL mode
System.setProperty(DUBBO_CONFIG_MODE, ConfigMode.OVERRIDE_ALL.name());
ApplicationModel.reset();
configManager = ApplicationModel.defaultModel().getApplicationConfigManager();
Assertions.assertEquals(ConfigMode.OVERRIDE_ALL, configManager.getConfigMode());
ApplicationConfig applicationConfig11 = new ApplicationConfig("app11");
ApplicationConfig applicationConfig22 = new ApplicationConfig("app22");
applicationConfig11.setParameters(CollectionUtils.toStringMap("k1", "v1", "k2", "v2"));
applicationConfig22.setParameters(CollectionUtils.toStringMap("k1", "v11", "k2", "v22", "k3", "v3"));
configManager.addConfig(applicationConfig11);
configManager.addConfig(applicationConfig22);
assertEquals(applicationConfig11, configManager.getApplicationOrElseThrow());
assertEquals(applicationConfig11.getName(), "app22");
assertEquals(applicationConfig11.getParameters(), CollectionUtils.toStringMap("k1", "v11", "k2", "v22", "k3", "v3"));
// test OVERRIDE_IF_ABSENT mode
System.setProperty(DUBBO_CONFIG_MODE, ConfigMode.OVERRIDE_IF_ABSENT.name());
ApplicationModel.reset();
configManager = ApplicationModel.defaultModel().getApplicationConfigManager();
Assertions.assertEquals(ConfigMode.OVERRIDE_IF_ABSENT, configManager.getConfigMode());
ApplicationConfig applicationConfig33 = new ApplicationConfig("app33");
ApplicationConfig applicationConfig44 = new ApplicationConfig("app44");
applicationConfig33.setParameters(CollectionUtils.toStringMap("k1", "v1", "k2", "v2"));
applicationConfig44.setParameters(CollectionUtils.toStringMap("k1", "v11", "k2", "v22", "k3", "v3"));
configManager.addConfig(applicationConfig33);
configManager.addConfig(applicationConfig44);
assertEquals(applicationConfig33, configManager.getApplicationOrElseThrow());
assertEquals(applicationConfig33.getName(), "app33");
assertEquals(applicationConfig33.getParameters(), CollectionUtils.toStringMap("k1", "v1", "k2", "v2", "k3", "v3"));
} finally {
System.clearProperty(DUBBO_CONFIG_MODE);
}
@ -319,12 +352,25 @@ public class ConfigManagerTest {
Optional<RegistryConfig> registryConfigOptional = configManager.getConfig(RegistryConfig.class, registryConfig.getId());
Assertions.assertEquals(registryConfigOptional.get(), registryConfig);
ProtocolConfig protocolConfig = new ProtocolConfig("dubbo");
configManager.addProtocol(protocolConfig);
Optional<ProtocolConfig> protocolConfigOptional = configManager.getConfig(ProtocolConfig.class, protocolConfig.getName());
Assertions.assertEquals(protocolConfigOptional.get(), protocolConfig);
// test multi config has same name(dubbo)
ProtocolConfig protocolConfig2 = new ProtocolConfig("dubbo");
protocolConfig2.setPort(9103);
configManager.addProtocol(protocolConfig2);
try {
configManager.getConfig(ProtocolConfig.class, protocolConfig.getName());
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(e instanceof IllegalStateException);
Assertions.assertEquals(e.getMessage(), "Found more than one config by name: dubbo, instances: " +
"[<dubbo:protocol port=\"9103\" name=\"dubbo\" />, <dubbo:protocol name=\"dubbo\" />]. " +
"Please remove redundant configs or get config by id.");
}
ModuleConfig moduleConfig = new ModuleConfig();
moduleConfig.setId("moduleID_1");
moduleConfigManager.setModule(moduleConfig);

View File

@ -46,6 +46,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.METADATA_SERVICE
import static org.apache.dubbo.common.constants.CommonConstants.METADATA_SERVICE_PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
import static org.apache.dubbo.remoting.Constants.BIND_PORT_KEY;
/**
* Export metadata service
@ -123,8 +124,12 @@ public class ConfigurableMetadataServiceExporter {
// metadata service may export before normal service export, it.hasNext() will return false.
// so need use specified protocol port.
if (it.hasNext()) {
String addr = it.next().getAddress();
String rawPort = addr.substring(addr.indexOf(":") + 1);
ProtocolServer server = it.next();
String rawPort = server.getUrl().getParameter(BIND_PORT_KEY);
if (rawPort == null) {
String addr = server.getAddress();
rawPort = addr.substring(addr.indexOf(":") + 1);
}
protocolConfig.setPort(Integer.parseInt(rawPort));
} else {
Integer protocolPort = getProtocolConfig(specifiedProtocol).getPort();

View File

@ -427,9 +427,14 @@ public class ReferenceAnnotationBeanPostProcessor extends AbstractAnnotationBean
// the prev bean type is different, rename the new reference bean
int index = 2;
String newReferenceBeanName = null;
while (newReferenceBeanName == null || beanDefinitionRegistry.containsBeanDefinition(newReferenceBeanName)) {
while (newReferenceBeanName == null || beanDefinitionRegistry.containsBeanDefinition(newReferenceBeanName)
|| beanDefinitionRegistry.isAlias(newReferenceBeanName)) {
newReferenceBeanName = referenceBeanName + "#" + index;
index++;
// double check found same name and reference key
if (registeredReferenceBeanNames.contains(newReferenceBeanName)) {
return newReferenceBeanName;
}
}
newBeanDesc = newReferenceBeanName + "[" + referenceKey + "]";

View File

@ -16,7 +16,6 @@
*/
package org.apache.dubbo.config.spring.extension;
import org.apache.dubbo.common.context.Lifecycle;
import org.apache.dubbo.common.extension.ExtensionAccessor;
import org.apache.dubbo.common.extension.ExtensionInjector;
import org.apache.dubbo.common.extension.SPI;
@ -29,7 +28,7 @@ import java.util.Arrays;
/**
* SpringExtensionInjector
*/
public class SpringExtensionInjector implements ExtensionInjector, Lifecycle {
public class SpringExtensionInjector implements ExtensionInjector {
private ApplicationContext context;
@ -91,18 +90,5 @@ public class SpringExtensionInjector implements ExtensionInjector, Lifecycle {
Arrays.toString(beanNamesForType));
}
return beanFactory.getBean(beanNamesForType[0], type);
}
@Override
public void initialize() throws IllegalStateException {
}
@Override
public void start() throws IllegalStateException {
// no op
}
@Override
public void destroy() {
}
}

View File

@ -109,7 +109,7 @@
<plugin>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-native-plugin</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<executions>
<execution>
<phase>process-sources</phase>

View File

@ -105,7 +105,7 @@
<plugin>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-native-plugin</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<executions>
<execution>
<phase>process-sources</phase>

View File

@ -676,6 +676,7 @@ public class MetadataInfo implements Serializable {
this.params = params;
}
@Transient
public Map<String, String> getAllParams() {
if (consumerParams != null) {
Map<String, String> allParams = new HashMap<>((int) ((params.size() + consumerParams.size()) / 0.75f + 1));

View File

@ -57,7 +57,7 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>

View File

@ -19,9 +19,9 @@ package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.rpc.model.FrameworkModel;
@Cmd(name = "onlineApp", summary = "online app addresses", example = {
"onlineApp dubbo",
"onlineApp xx.xx.xxx.service"
@Cmd(name = "online", summary = "online app addresses", example = {
"online dubbo",
"online xx.xx.xxx.service"
})
public class Online extends BaseOnline {
public Online(FrameworkModel frameworkModel) {

View File

@ -67,7 +67,7 @@ public class TelnetHandlerAdapter extends ChannelHandlerAdapter implements Telne
} else {
buf.append("Command: ");
buf.append(command);
buf.append(" disabled");
buf.append(" disabled for security reasons, please enable support by listing the commands through 'telnet'");
}
} else {
buf.append("Unsupported command: ");
@ -86,7 +86,7 @@ public class TelnetHandlerAdapter extends ChannelHandlerAdapter implements Telne
private boolean commandEnabled(URL url, String command) {
String supportCommands = url.getParameter(TELNET_KEY);
if (StringUtils.isEmpty(supportCommands)) {
return true;
return false;
}
String[] commands = COMMA_SPLIT_PATTERN.split(supportCommands);
for (String c : commands) {

View File

@ -53,7 +53,7 @@ class TelnetHandlerAdapterTest {
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
message = "--no-prompt help";
expectedResult = "Command: help disabled\r\n";
expectedResult = "Command: help disabled for security reasons, please enable support by listing the commands through 'telnet'\r\n";
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
message = "--no-prompt";
@ -61,7 +61,7 @@ class TelnetHandlerAdapterTest {
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
message = "help";
expectedResult = "Command: help disabled\r\ndubbo>";
expectedResult = "Command: help disabled for security reasons, please enable support by listing the commands through 'telnet'\r\ndubbo>";
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
}
}

View File

@ -35,7 +35,7 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-actuator-compatible</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>
<!-- Spring Boot -->
@ -74,41 +74,41 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-autoconfigure</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>
<!-- Dubbo -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-config-spring</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-hessian2</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
@ -122,7 +122,7 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-dubbo</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

View File

@ -37,7 +37,7 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-autoconfigure-compatible</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>
<!-- Spring Boot dependencies -->
@ -64,20 +64,20 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-config-spring</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
@ -96,4 +96,4 @@
</dependency>
</dependencies>
</project>
</project>

View File

@ -66,33 +66,33 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-autoconfigure-compatible</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-config-spring</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-dubbo</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
@ -111,4 +111,4 @@
</dependency>
</dependencies>
</project>
</project>

View File

@ -67,21 +67,21 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-config-spring</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>
<!-- Test Dependencies -->
@ -99,4 +99,4 @@
</dependency>
</dependencies>
</project>
</project>

View File

@ -55,8 +55,8 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-autoconfigure</artifactId>
<version>${revision}</version>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
</project>

16
pom.xml
View File

@ -527,6 +527,22 @@
</plugins>
</build>
</profile>
<profile>
<id>jdk9-compile</id>
<activation>
<jdk>[1.9,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>