Skip to content

Commit

Permalink
2.7.8 service introspection (#6317)
Browse files Browse the repository at this point in the history
* Polish #6296 : Adding the new methods into MetadataReport to manipulate the exported URLs for service introspection

* Polish #6296 : Adding the new methods into MetadataReport to manipulate the exported URLs for service introspection

* Polish #6171 : [Feature] Introducing the composite implementation of MetadataService

* Revert "fix wrong check of InvokerListener when export a service (fix issue_6269) (#6271)"

This reverts commit 91989ca.

* Revert "fix wrong check of InvokerListener when export a service (fix issue_6269) (#6271)"

This reverts commit 91989ca.

* Revert the MetadataReport

* Polish #6305 : [Refactor] ServiceConfig and ReferenceConfig publish the ServiceDefinition based on the Dubbo Event

* Polish #6198 : [Issue] Fixing NacosDynamicConfiguration#publishConfig bug

* Polish #6310 : Refactoring MetadataReport's methods

* Polish #6198 : [Issue] Fixing NacosDynamicConfiguration#publishConfig bug

* Polish #6198 : [Issue] Fixing NacosDynamicConfiguration#publishConfig bug

* Polish #6315 : [Refactor] Refactoring the implementation of MetadataReport based on The Config-Center infrastructure

Deprecated List :

- NacosMetadataReport
- ZookeeperMetadataReport

* Polish #6315 : Refactoring by TreePathDynamicConfiguration

* Polish #6315 : Refactoring ConsulDynamicConfiguration by TreePathDynamicConfiguration

* Polish #6315 : Reset the config base path to be "metadata" for ConfigCenterBasedMetadataReportFactory

* Polish #6315 : Bugfix

* Polish #6315 : Bugfix
  • Loading branch information
mercyblitz committed Jun 12, 2020
1 parent 2a0d015 commit dd7b880
Show file tree
Hide file tree
Showing 36 changed files with 1,432 additions and 755 deletions.
20 changes: 20 additions & 0 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Expand Up @@ -35,10 +35,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;

import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
Expand Down Expand Up @@ -566,6 +568,24 @@ public Map<String, String> getParameters() {
return parameters;
}

/**
* Get the parameters to be selected(filtered)
*
* @param nameToSelect the {@link Predicate} to select the parameter name
* @return non-null {@link Map}
* @since 2.7.8
*/
public Map<String, String> getParameters(Predicate<String> nameToSelect) {
Map<String, String> selectedParameters = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : getParameters().entrySet()) {
String name = entry.getKey();
if (nameToSelect.test(name)) {
selectedParameters.put(name, entry.getValue());
}
}
return Collections.unmodifiableMap(selectedParameters);
}

public Map<String, Map<String, String>> getMethodParameters() {
return methodParameters;
}
Expand Down
Expand Up @@ -20,13 +20,17 @@
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 java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;

/**
* The abstract implementation of {@link DynamicConfiguration}
*
Expand All @@ -47,6 +51,20 @@ public abstract class AbstractDynamicConfiguration implements DynamicConfigurati
*/
public static final String THREAD_POOL_KEEP_ALIVE_TIME_PARAM_NAME = PARAM_NAME_PREFIX + "thread-pool.keep-alive-time";

/**
* The parameter name of group for config-center
*
* @since 2.7.8
*/
public static final String GROUP_PARAM_NAME = PARAM_NAME_PREFIX + GROUP_KEY;

/**
* The parameter name of timeout for config-center
*
* @since 2.7.8
*/
public static final String TIMEOUT_PARAM_NAME = PARAM_NAME_PREFIX + TIMEOUT_KEY;

public static final int DEFAULT_THREAD_POOL_SIZE = 1;

/**
Expand All @@ -64,28 +82,31 @@ public abstract class AbstractDynamicConfiguration implements DynamicConfigurati
*/
private final ThreadPoolExecutor workersThreadPool;

public AbstractDynamicConfiguration() {
this(DEFAULT_THREAD_POOL_PREFIX, DEFAULT_THREAD_POOL_SIZE, DEFAULT_THREAD_POOL_KEEP_ALIVE_TIME);
}
private final String group;

private final long timeout;

public AbstractDynamicConfiguration(URL url) {
this(getThreadPoolPrefixName(url), getThreadPoolSize(url), getThreadPoolKeepAliveTime(url));
this(getThreadPoolPrefixName(url), getThreadPoolSize(url), getThreadPoolKeepAliveTime(url), getGroup(url),
getTimeout(url));
}

public AbstractDynamicConfiguration(String threadPoolPrefixName,
int threadPoolSize,
long keepAliveTime) {
long keepAliveTime,
String group,
long timeout) {
this.workersThreadPool = initWorkersThreadPool(threadPoolPrefixName, threadPoolSize, keepAliveTime);
this.group = group;
this.timeout = timeout;
}

@Override
public void addListener(String key, String group, ConfigurationListener listener) {

}

@Override
public void removeListener(String key, String group, ConfigurationListener listener) {

}

@Override
Expand All @@ -107,6 +128,29 @@ public final void close() throws Exception {
}
}

@Override
public boolean removeConfig(String key, String group) {
return execute(() -> doRemoveConfig(key, group), -1L);
}

/**
* @return the default group
* @since 2.7.8
*/
@Override
public String getDefaultGroup() {
return getGroup();
}

/**
* @return the default timeout
* @since 2.7.8
*/
@Override
public long getDefaultTimeout() {
return getTimeout();
}

/**
* Get the content of configuration in the specified key and group
*
Expand All @@ -124,6 +168,17 @@ public final void close() throws Exception {
*/
protected abstract void doClose() throws Exception;

/**
* Remove the config in the specified key and group
*
* @param key the key
* @param group the group
* @return If successful, return <code>true</code>, or <code>false</code>
* @throws Exception
* @since 2.7.8
*/
protected abstract boolean doRemoveConfig(String key, String group) throws Exception;

/**
* Executes the {@link Runnable} with the specified timeout
*
Expand Down Expand Up @@ -216,4 +271,36 @@ protected static long getParameter(URL url, String name, long defaultValue) {
}
return defaultValue;
}


protected String getGroup() {
return group;
}

protected long getTimeout() {
return timeout;
}

/**
* Get the group from {@link URL the specified connection URL}
*
* @param url {@link URL the specified connection URL}
* @return non-null
* @since 2.7.8
*/
protected static String getGroup(URL url) {
String group = getParameter(url, GROUP_PARAM_NAME, null);
return StringUtils.isBlank(group) ? getParameter(url, GROUP_KEY, DEFAULT_GROUP) : group;
}

/**
* Get the timeout from {@link URL the specified connection URL}
*
* @param url {@link URL the specified connection URL}
* @return non-null
* @since 2.7.8
*/
protected static long getTimeout(URL url) {
return getParameter(url, TIMEOUT_PARAM_NAME, -1L);
}
}
Expand Up @@ -232,4 +232,14 @@ static DynamicConfiguration getDynamicConfiguration(URL connectionURL) {
static String getRuleKey(URL url) {
return url.getColonSeparatedKey();
}

/**
* @param key the key to represent a configuration
* @param group the group where the key belongs to
* @return <code>true</code> if success, or <code>false</code>
* @since 2.7.8
*/
default boolean removeConfig(String key, String group) {
return true;
}
}
@@ -0,0 +1,171 @@
/*
* 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;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.file.FileSystemDynamicConfiguration;
import org.apache.dubbo.common.utils.PathUtils;
import org.apache.dubbo.common.utils.StringUtils;

import java.util.Collection;
import java.util.SortedSet;
import java.util.TreeSet;

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.constants.CommonConstants.PATH_SEPARATOR;
import static org.apache.dubbo.common.utils.CollectionUtils.isEmpty;
import static org.apache.dubbo.common.utils.PathUtils.buildPath;

/**
* An abstract implementation of {@link DynamicConfiguration} is like "tree-structure" path :
* <ul>
* <li>{@link FileSystemDynamicConfiguration "file"}</li>
* <li>{@link org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfiguration "zookeeper"}</li>
* <li>{@link org.apache.dubbo.configcenter.consul.ConsulDynamicConfiguration "consul"}</li>
* </ul>
*
* @see DynamicConfiguration
* @see AbstractDynamicConfiguration
* @since 2.7.8
*/
public abstract class TreePathDynamicConfiguration extends AbstractDynamicConfiguration {

/**
* The parameter name of URL for the config base path
*/
public static final String CONFIG_BASE_PATH_PARAM_NAME = PARAM_NAME_PREFIX + "base-path";

/**
* The default value of parameter of URL for the config base path
*/
public static final String DEFAULT_CONFIG_BASE_PATH = "/config";

private final String rootPath;

public TreePathDynamicConfiguration(URL url) {
super(url);
this.rootPath = getRootPath(url);
}

public TreePathDynamicConfiguration(String rootPath,
String threadPoolPrefixName,
int threadPoolSize,
long keepAliveTime,
String group,
long timeout) {
super(threadPoolPrefixName, threadPoolSize, keepAliveTime, group, timeout);
this.rootPath = rootPath;
}

@Override
protected final String doGetConfig(String key, String group) throws Exception {
String pathKey = buildPathKey(group, key);
return doGetConfig(pathKey);
}

@Override
public final boolean publishConfig(String key, String group, String content) {
String pathKey = buildPathKey(group, key);
return execute(() -> doPublishConfig(pathKey, content), getDefaultTimeout());
}

@Override
protected final boolean doRemoveConfig(String key, String group) throws Exception {
String pathKey = buildPathKey(group, key);
return doRemoveConfig(pathKey);
}

@Override
public final void addListener(String key, String group, ConfigurationListener listener) {
String pathKey = buildPathKey(group, key);
doAddListener(pathKey, listener);
}

@Override
public final void removeListener(String key, String group, ConfigurationListener listener) {
String pathKey = buildPathKey(group, key);
doRemoveListener(pathKey, listener);
}

@Override
public final SortedSet<String> getConfigKeys(String group) throws UnsupportedOperationException {
String groupPath = buildGroupPath(group);
Collection<String> configKeys = doGetConfigKeys(groupPath);
return isEmpty(configKeys) ? emptySortedSet() : unmodifiableSortedSet(new TreeSet<>(configKeys));
}

protected abstract boolean doPublishConfig(String pathKey, String content) throws Exception;

protected abstract String doGetConfig(String pathKey) throws Exception;

protected abstract boolean doRemoveConfig(String pathKey) throws Exception;

protected abstract Collection<String> doGetConfigKeys(String groupPath);

protected abstract void doAddListener(String pathKey, ConfigurationListener listener);

protected abstract void doRemoveListener(String pathKey, ConfigurationListener listener);

protected String buildGroupPath(String group) {
return buildPath(rootPath, group);
}

protected String buildPathKey(String group, String key) {
return buildPath(buildGroupPath(group), key);
}

/**
* Get the root path from the specified {@link URL connection URl}
*
* @param url the specified {@link URL connection URl}
* @return non-null
*/
protected String getRootPath(URL url) {
String rootPath = PATH_SEPARATOR + getConfigNamespace(url) + getConfigBasePath(url);
rootPath = PathUtils.normalize(rootPath);
if (rootPath.endsWith(PATH_SEPARATOR)) {
rootPath = rootPath.substring(0, rootPath.length() - 1);
}
return rootPath;
}

/**
* Get the namespace from the specified {@link URL connection URl}
*
* @param url the specified {@link URL connection URl}
* @return non-null
*/
protected String getConfigNamespace(URL url) {
return url.getParameter(CONFIG_NAMESPACE_KEY, DEFAULT_GROUP);
}

/**
* Get the config base path from the specified {@link URL connection URl}
*
* @param url the specified {@link URL connection URl}
* @return non-null
*/
protected String getConfigBasePath(URL url) {
String configBasePath = url.getParameter(CONFIG_BASE_PATH_PARAM_NAME, DEFAULT_CONFIG_BASE_PATH);
if (StringUtils.isNotEmpty(configBasePath) && !configBasePath.startsWith(PATH_SEPARATOR)) {
configBasePath = PATH_SEPARATOR + configBasePath;
}
return configBasePath;
}
}

0 comments on commit dd7b880

Please sign in to comment.