Skip to content

Commit

Permalink
2.7.8 service introspection (#6337)
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

* Polish #6315 : Correct words

* Polish #6333 : [Refactor] Using mandatory implementation of Service Instance registration instead of the event

* Polish #6336 : [Refactor] org.apache.dubbo.metadata.ServiceNameMapping
  • Loading branch information
mercyblitz authored Jun 17, 2020
1 parent dd7b880 commit e65f81f
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.ServiceInstanceCustomizer;
import org.apache.dubbo.registry.support.AbstractRegistryFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;

Expand Down Expand Up @@ -1085,9 +1086,37 @@ private void registerServiceInstance() {

ServiceInstance serviceInstance = createServiceInstance(serviceName, host, port);

preRegisterServiceInstance(serviceInstance);

getServiceDiscoveries().forEach(serviceDiscovery -> serviceDiscovery.register(serviceInstance));
}

/**
* Pre-register {@link ServiceInstance the service instance}
*
* @param serviceInstance {@link ServiceInstance the service instance}
* @since 2.7.8
*/
private void preRegisterServiceInstance(ServiceInstance serviceInstance) {
customizeServiceInstance(serviceInstance);
}

/**
* Customize {@link ServiceInstance the service instance}
*
* @param serviceInstance {@link ServiceInstance the service instance}
* @since 2.7.8
*/
private void customizeServiceInstance(ServiceInstance serviceInstance) {
ExtensionLoader<ServiceInstanceCustomizer> loader =
ExtensionLoader.getExtensionLoader(ServiceInstanceCustomizer.class);
// FIXME, sort customizer before apply
loader.getSupportedExtensionInstances().forEach(customizer -> {
// customizes
customizer.customize(serviceInstance);
});
}

private URL selectMetadataServiceExportedURL() {

URL selectedURL = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import java.util.List;

import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.metadata.ServiceNameMapping.getDefaultExtension;

/**
Expand All @@ -45,11 +43,7 @@ public void onEvent(ServiceConfigExportedEvent event) {
ServiceConfig serviceConfig = event.getServiceConfig();
List<URL> exportedURLs = serviceConfig.getExportedUrls();
exportedURLs.forEach(url -> {
String serviceInterface = url.getServiceInterface();
String group = url.getParameter(GROUP_KEY);
String version = url.getParameter(VERSION_KEY);
String protocol = url.getProtocol();
serviceNameMapping.map(serviceInterface, group, version, protocol);
serviceNameMapping.map(url);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metadata;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
Expand All @@ -27,6 +28,8 @@

import static java.lang.String.valueOf;
import static java.util.Arrays.asList;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.utils.CollectionUtils.isNotEmpty;
import static org.apache.dubbo.common.utils.StringUtils.SLASH;
import static org.apache.dubbo.rpc.model.ApplicationModel.getName;
Expand All @@ -43,12 +46,18 @@ public class DynamicConfigurationServiceNameMapping implements ServiceNameMappin
private final Logger logger = LoggerFactory.getLogger(getClass());

@Override
public void map(String serviceInterface, String group, String version, String protocol) {
public void map(URL exportedURL) {

String serviceInterface = exportedURL.getServiceInterface();

if (IGNORED_SERVICE_INTERFACES.contains(serviceInterface)) {
return;
}

String group = exportedURL.getParameter(GROUP_KEY);
String version = exportedURL.getParameter(VERSION_KEY);
String protocol = exportedURL.getProtocol();

DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration();

// the Dubbo Service Key as group
Expand All @@ -66,10 +75,15 @@ public void map(String serviceInterface, String group, String version, String pr
}

@Override
public Set<String> get(String serviceInterface, String group, String version, String protocol) {
public Set<String> get(URL subscribedURL) {

DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration();

String serviceInterface = subscribedURL.getServiceInterface();
String group = subscribedURL.getParameter(GROUP_KEY);
String version = subscribedURL.getParameter(VERSION_KEY);
String protocol = subscribedURL.getProtocol();

Set<String> serviceNames = new LinkedHashSet<>();
execute(() -> {
Set<String> keys = dynamicConfiguration.getConfigKeys(buildGroup(serviceInterface, group, version, protocol));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metadata;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.SPI;

import java.util.Set;
Expand All @@ -37,8 +38,20 @@ public interface ServiceNameMapping {
* @param group the group of Dubbo service interface (optional)
* @param version the version of Dubbo service interface version (optional)
* @param protocol the protocol of Dubbo service interface exported (optional)
* @deprecated 2.7.8 This method will be removed since 3.0
*/
void map(String serviceInterface, String group, String version, String protocol);
@Deprecated
default void map(String serviceInterface, String group, String version, String protocol) {
throw new UnsupportedOperationException("This method has been deprecated and should not be invoked!");
}

/**
* Map the specified Dubbo service {@link URL} to current Dubbo service name
*
* @param exportedURL the {@link URL} that the Dubbo Provider exported
* @since 2.7.8
*/
void map(URL exportedURL);

/**
* Get the service names from the specified Dubbo service interface, group, version and protocol
Expand All @@ -47,10 +60,22 @@ public interface ServiceNameMapping {
* @param group the group of Dubbo service interface (optional)
* @param version the version of Dubbo service interface version (optional)
* @param protocol the protocol of Dubbo service interface exported (optional)
* @return
* @return non-null {@link Set}
* @deprecated 2.7.8 This method will be removed since 3.0
*/
Set<String> get(String serviceInterface, String group, String version, String protocol);
@Deprecated
default Set<String> get(String serviceInterface, String group, String version, String protocol) {
throw new UnsupportedOperationException("This method has been deprecated and should not be invoked!");
}

/**
* Get the service names from the subscribed Dubbo service {@link URL}
*
* @param subscribedURL the {@link URL} that the Dubbo consumer subscribed
* @return non-null {@link Set}
* @since 2.7.8
*/
Set<String> get(URL subscribedURL);

/**
* Get the default extension of {@link ServiceNameMapping}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metadata;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory;
import org.apache.dubbo.config.ApplicationConfig;
Expand All @@ -28,10 +29,13 @@
import java.util.TreeSet;

import static java.util.Arrays.asList;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;
import static org.apache.dubbo.metadata.DynamicConfigurationServiceNameMapping.buildGroup;
import static org.apache.dubbo.metadata.ServiceNameMapping.getDefaultExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* {@link DynamicConfigurationServiceNameMapping} Test
Expand Down Expand Up @@ -61,6 +65,17 @@ public void testBuildGroup() {
assertEquals("mapping/test", buildGroup("test", "default", "1.0.0", "dubbo"));
}

@Test
public void testAndGetOnFailed() {
assertThrows(UnsupportedOperationException.class, () -> {
serviceNameMapping.map(null, null, null, null);
});

assertThrows(UnsupportedOperationException.class, () -> {
serviceNameMapping.get(null, null, null, null);
});
}

@Test
public void testMapAndGet() {

Expand All @@ -74,14 +89,18 @@ public void testMapAndGet() {
String version = null;
String protocol = null;

serviceNameMapping.map(serviceInterface, group, version, protocol);
URL url = URL.valueOf("dubbo://127.0.0.1:20880").setServiceInterface(serviceInterface)
.addParameter(GROUP_KEY, group)
.addParameter(VERSION_KEY, version);

serviceNameMapping.map(url);

ApplicationModel.getConfigManager().removeConfig(new ApplicationConfig(serviceName));
ApplicationModel.getConfigManager().setApplication(new ApplicationConfig(serviceName2));

serviceNameMapping.map(serviceInterface, group, version, protocol);
serviceNameMapping.map(url);

Set<String> serviceNames = serviceNameMapping.get(serviceInterface, group, version, protocol);
Set<String> serviceNames = serviceNameMapping.get(url);

assertEquals(new TreeSet(asList(serviceName, serviceName2)), serviceNames);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
* Customize the {@link ServiceInstance} before registering to Registry.
*
* @since 2.7.5
* @deprecated 2.7.8 Current class will be removed since 3.0.0
*/
@Deprecated
public class CustomizableServiceInstanceListener implements EventListener<ServiceInstancePreRegisteredEvent> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ public static boolean isDubboServiceInstance(ServiceInstance serviceInstance) {
|| metadata.containsKey(METADATA_SERVICE_URLS_PROPERTY_NAME);
}

public static void setEndpoints(ServiceInstance serviceInstance, Map<String, Integer> protocolPortss) {
public static void setEndpoints(ServiceInstance serviceInstance, Map<String, Integer> protocolPorts) {
Map<String, String> metadata = serviceInstance.getMetadata();
List<Endpoint> endpoints = new ArrayList<>();
protocolPortss.forEach((k, v) -> {
protocolPorts.forEach((k, v) -> {
Endpoint endpoint = new Endpoint(v, k);
endpoints.add(endpoint);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
service-instance=org.apache.dubbo.registry.client.event.listener.CustomizableServiceInstanceListener
# "service-instance" has been deprecated since 2.7.8
# service-instance=org.apache.dubbo.registry.client.event.listener.CustomizableServiceInstanceListener

registry-logging=org.apache.dubbo.registry.client.event.listener.LoggingEventListener

# "publishing-remote-metadata" in introduced since 2.7.8
publishing-remote-metadata=org.apache.dubbo.registry.client.event.listener.PublishingRemoteMetadataListener

0 comments on commit e65f81f

Please sign in to comment.