Skip to content

Commit

Permalink
2.7.8 service introspection update (#6308)
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
  • Loading branch information
mercyblitz committed Jun 11, 2020
1 parent b086a95 commit 2a0d015
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.dubbo.config.utils.ConfigValidationUtils;
import org.apache.dubbo.event.Event;
import org.apache.dubbo.event.EventDispatcher;
import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
Expand Down Expand Up @@ -62,20 +61,16 @@
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.CONSUMER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
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_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.PROXY_CLASS_REF;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;
import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY;
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.LOCAL_PROTOCOL;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
Expand Down Expand Up @@ -221,10 +216,6 @@ public synchronized void init() {
// appendParameters(map, consumer, Constants.DEFAULT_KEY);
AbstractConfig.appendParameters(map, consumer);
AbstractConfig.appendParameters(map, this);
MetadataReportConfig metadataReportConfig = getMetadataReportConfig();
if (metadataReportConfig != null && metadataReportConfig.isValid()) {
map.putIfAbsent(METADATA_KEY, REMOTE_METADATA_STORAGE_TYPE);
}
Map<String, AsyncMethodInfo> attributes = null;
if (CollectionUtils.isNotEmpty(getMethods())) {
attributes = new HashMap<>();
Expand Down Expand Up @@ -352,16 +343,6 @@ private T createProxy(Map<String, String> map) {
if (logger.isInfoEnabled()) {
logger.info("Refer dubbo service " + interfaceClass.getName() + " from url " + invoker.getUrl());
}
/**
* @since 2.7.0
* ServiceData Store
*/
String metadata = map.get(METADATA_KEY);
WritableMetadataService metadataService = WritableMetadataService.getExtension(metadata == null ? DEFAULT_METADATA_STORAGE_TYPE : metadata);
if (metadataService != null) {
URL consumerURL = new URL(CONSUMER_PROTOCOL, map.remove(REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map);
metadataService.publishServiceDefinition(consumerURL);
}
// create service proxy
return (T) PROXY_FACTORY.getProxy(invoker, ProtocolUtils.isGeneric(generic));
}
Expand Down Expand Up @@ -466,7 +447,7 @@ public void setBootstrap(DubboBootstrap bootstrap) {
}

private void postProcessConfig() {
List<ConfigPostProcessor> configPostProcessors =ExtensionLoader.getExtensionLoader(ConfigPostProcessor.class)
List<ConfigPostProcessor> configPostProcessors = ExtensionLoader.getExtensionLoader(ConfigPostProcessor.class)
.getActivateExtension(URL.valueOf("configPostProcessor://"), (String[]) null);
configPostProcessors.forEach(component -> component.postProcessReferConfig(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.dubbo.config.utils.ConfigValidationUtils;
import org.apache.dubbo.event.Event;
import org.apache.dubbo.event.EventDispatcher;
import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
Expand Down Expand Up @@ -68,16 +67,13 @@

import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
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_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.PROVIDER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.REGISTER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
Expand Down Expand Up @@ -344,10 +340,6 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
AbstractConfig.appendParameters(map, provider);
AbstractConfig.appendParameters(map, protocolConfig);
AbstractConfig.appendParameters(map, this);
MetadataReportConfig metadataReportConfig = getMetadataReportConfig();
if (metadataReportConfig != null && metadataReportConfig.isValid()) {
map.putIfAbsent(METADATA_KEY, REMOTE_METADATA_STORAGE_TYPE);
}
if (CollectionUtils.isNotEmpty(getMethods())) {
for (MethodConfig method : getMethods()) {
AbstractConfig.appendParameters(map, method, method.getName());
Expand Down Expand Up @@ -502,14 +494,6 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
Exporter<?> exporter = PROTOCOL.export(wrapperInvoker);
exporters.add(exporter);
}
/**
* @since 2.7.0
* ServiceData Store
*/
WritableMetadataService metadataService = WritableMetadataService.getExtension(url.getParameter(METADATA_KEY, DEFAULT_METADATA_STORAGE_TYPE));
if (metadataService != null) {
metadataService.publishServiceDefinition(url);
}
}
}
this.urls.add(url);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.config.event.listener;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.AbstractInterfaceConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.event.ReferenceConfigInitializedEvent;
import org.apache.dubbo.config.event.ServiceConfigExportedEvent;
import org.apache.dubbo.event.EventListener;
import org.apache.dubbo.event.GenericEventListener;
import org.apache.dubbo.metadata.WritableMetadataService;

import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.metadata.WritableMetadataService.getExtension;

/**
* An {@link EventListener} {@link WritableMetadataService#publishServiceDefinition(URL) publishs the service definition}
* when {@link ServiceConfigExportedEvent the event of the exported Dubbo service} and
* {@link ReferenceConfigInitializedEvent the event of the referenced Dubbo service} is raised.
*
* @see GenericEventListener
* @see ServiceConfigExportedEvent
* @see ReferenceConfigInitializedEvent
* @since 2.7.8
*/
public class PublishingServiceDefinitionListener extends GenericEventListener {

public void onEvent(ReferenceConfigInitializedEvent event) {
handleEvent(event.getReferenceConfig());
}

public void onEvent(ServiceConfigExportedEvent event) {
handleEvent(event.getServiceConfig());
}

private void handleEvent(AbstractInterfaceConfig config) {
String metadataType = getMetadataType(config);
for (URL exportedURL : config.getExportedUrls()) {
WritableMetadataService metadataService = getExtension(metadataType);
if (metadataService != null) {
metadataService.publishServiceDefinition(exportedURL);
}
}
}

private String getMetadataType(AbstractInterfaceConfig config) {
ApplicationConfig applicationConfig = config.getApplication();
String metadataType = applicationConfig.getMetadataType();
if (REMOTE_METADATA_STORAGE_TYPE.equals(metadataType)) {
MetadataReportConfig metadataReportConfig = config.getMetadataReportConfig();
if (metadataReportConfig == null || !metadataReportConfig.isValid()) {
metadataType = DEFAULT_METADATA_STORAGE_TYPE;
}
}
return metadataType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public static void validateAbstractInterfaceConfig(AbstractInterfaceConfig confi
checkExtension(ProxyFactory.class, PROXY_KEY, config.getProxy());
checkExtension(Cluster.class, CLUSTER_KEY, config.getCluster());
checkMultiExtension(Filter.class, FILE_KEY, config.getFilter());
checkMultiExtension(InvokerListener.class, LISTENER_KEY, config.getListener());
checkNameHasSymbol(LAYER_KEY, config.getLayer());

List<MethodConfig> methods = config.getMethods();
Expand All @@ -311,7 +312,7 @@ public static void validateServiceConfig(ServiceConfig config) {
checkName(TOKEN_KEY, config.getToken());
checkPathName(PATH_KEY, config.getPath());

checkMultiExtension(ExporterListener.class, LISTENER_KEY, config.getListener());
checkMultiExtension(ExporterListener.class, "listener", config.getListener());

validateAbstractInterfaceConfig(config);

Expand All @@ -336,7 +337,7 @@ public static void validateServiceConfig(ServiceConfig config) {
}

public static void validateReferenceConfig(ReferenceConfig config) {
checkMultiExtension(InvokerListener.class, LISTENER_KEY, config.getListener());
checkMultiExtension(InvokerListener.class, "listener", config.getListener());
checkKey(VERSION_KEY, config.getVersion());
checkKey(GROUP_KEY, config.getGroup());
checkName(CLIENT_KEY, config.getClient());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
service-mapping=org.apache.dubbo.config.event.listener.ServiceNameMappingListener
config-logging=org.apache.dubbo.config.event.listener.LoggingEventListener
config-logging=org.apache.dubbo.config.event.listener.LoggingEventListener
# since 2.7.8
publishing-service-definition=org.apache.dubbo.config.event.listener.PublishingServiceDefinitionListener
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import static java.lang.String.valueOf;
import static java.util.Arrays.asList;
import static org.apache.dubbo.common.utils.CollectionUtils.isNotEmpty;
import static org.apache.dubbo.common.utils.StringUtils.SLASH;
import static org.apache.dubbo.rpc.model.ApplicationModel.getName;

Expand Down Expand Up @@ -72,7 +73,9 @@ public Set<String> get(String serviceInterface, String group, String version, St
Set<String> serviceNames = new LinkedHashSet<>();
execute(() -> {
Set<String> keys = dynamicConfiguration.getConfigKeys(buildGroup(serviceInterface, group, version, protocol));
serviceNames.addAll(keys);
if (isNotEmpty(keys)) {
serviceNames.addAll(keys);
}
});
return Collections.unmodifiableSet(serviceNames);
}
Expand Down

0 comments on commit 2a0d015

Please sign in to comment.