Search in sources :

Example 1 with MetadataReport

use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.

the class RemoteMetadataServiceImpl method publishProvider.

private void publishProvider(URL providerUrl) throws RpcException {
    // first add into the list
    // remove the individual param
    providerUrl = providerUrl.removeParameters(PID_KEY, TIMESTAMP_KEY, Constants.BIND_IP_KEY, Constants.BIND_PORT_KEY, TIMESTAMP_KEY);
    try {
        String interfaceName = providerUrl.getParameter(INTERFACE_KEY);
        if (StringUtils.isNotEmpty(interfaceName)) {
            Class interfaceClass = Class.forName(interfaceName);
            FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, providerUrl.getParameters());
            for (Map.Entry<String, MetadataReport> entry : getMetadataReports().entrySet()) {
                MetadataReport metadataReport = entry.getValue();
                metadataReport.storeProviderMetadata(new MetadataIdentifier(providerUrl.getServiceInterface(), providerUrl.getParameter(VERSION_KEY), providerUrl.getParameter(GROUP_KEY), PROVIDER_SIDE, providerUrl.getParameter(APPLICATION_KEY)), fullServiceDefinition);
            }
            return;
        }
        logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString());
    } catch (ClassNotFoundException e) {
        // ignore error
        logger.error("publishProvider getServiceDescriptor error. providerUrl: " + providerUrl.toFullString(), e);
    }
}
Also used : MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) Map(java.util.Map)

Example 2 with MetadataReport

use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.

the class MetadataServiceNameMapping method map.

@Override
public void map(URL url) {
    String serviceInterface = url.getServiceInterface();
    if (IGNORED_SERVICE_INTERFACES.contains(serviceInterface)) {
        return;
    }
    String registryCluster = getRegistryCluster(url);
    MetadataReport metadataReport = MetadataReportInstance.getMetadataReport(registryCluster);
    metadataReport.registerServiceAppMapping(ServiceNameMapping.buildGroup(serviceInterface), getName(), url);
}
Also used : MetadataReport(org.apache.dubbo.metadata.report.MetadataReport)

Example 3 with MetadataReport

use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.

the class MetadataServiceNameMapping method getAndListen.

@Override
public Set<String> getAndListen(URL url, MappingListener mappingListener) {
    String serviceInterface = url.getServiceInterface();
    String mappingKey = ServiceNameMapping.buildGroup(serviceInterface);
    Set<String> serviceNames = new LinkedHashSet<>();
    String registryCluster = getRegistryCluster(url);
    MetadataReport metadataReport = MetadataReportInstance.getMetadataReport(registryCluster);
    Set<String> apps = metadataReport.getServiceAppMapping(mappingKey, mappingListener, url);
    if (CollectionUtils.isNotEmpty(apps)) {
        serviceNames.addAll(apps);
    }
    return serviceNames;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MetadataReport(org.apache.dubbo.metadata.report.MetadataReport)

Example 4 with MetadataReport

use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.

the class FailoverMetadataReportTest method testLocalDataCenterMetadataReport.

@Test
public void testLocalDataCenterMetadataReport() {
    URL url = mockURL.addParameter("strategy", "local");
    FailoverMetadataReport report = getFailoverReport(url);
    Assertions.assertNotNull(report.getProxyReports(), "metadata reports should not be null.");
    Assertions.assertEquals(2, report.getProxyReports().size(), "expect 2 metadata report, actual " + report.getProxyReports().size());
    MetadataReport localReport = null, failoverReport = null;
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        if (holder.url.getBackupAddress().contains(url.getAddress())) {
            localReport = holder.report;
        } else {
            failoverReport = holder.report;
        }
    }
    Assertions.assertNotNull(localReport);
    Assertions.assertNotNull(failoverReport);
    MetadataIdentifier identifier = new MetadataIdentifier("helloService", null, null, null, "test");
    ServiceDefinition definition = new ServiceDefinition();
    definition.setCanonicalName("helloService");
    report.storeProviderMetadata(identifier, definition);
    // assert local metadata report write already.
    Assertions.assertNotNull(report.getServiceDefinition(identifier));
    Assertions.assertNotNull(localReport.getServiceDefinition(identifier));
    Assertions.assertNull(failoverReport.getServiceDefinition(identifier));
    HashMap parameterMap = new HashMap();
    report.storeConsumerMetadata(identifier, parameterMap);
    // assert local metadata report write already.
    Assertions.assertEquals(parameterMap, ((MockMetadataReport) localReport).consumerMetadata.get(identifier));
    Assertions.assertNotEquals(parameterMap, ((MockMetadataReport) failoverReport).consumerMetadata.get(identifier));
    SubscriberMetadataIdentifier subscribeIdentifier = new SubscriberMetadataIdentifier("test", "1.0");
    MetadataInfo metadataInfo = new MetadataInfo(subscribeIdentifier.getApplication(), subscribeIdentifier.getRevision(), null);
    report.publishAppMetadata(subscribeIdentifier, metadataInfo);
    // assert all metadata report write already.
    Assertions.assertEquals(metadataInfo, report.getAppMetadata(subscribeIdentifier, null));
    Assertions.assertEquals(metadataInfo, localReport.getAppMetadata(subscribeIdentifier, null));
    Assertions.assertNotEquals(metadataInfo, failoverReport.getAppMetadata(subscribeIdentifier, null));
    report.registerServiceAppMapping("helloService", "test", null);
    Set<String> appNames = report.getServiceAppMapping("helloService", null, null);
    // assert local metadata report write already.
    Assertions.assertEquals(appNames, report.getServiceAppMapping("helloService", null, null));
    Assertions.assertEquals(appNames, localReport.getServiceAppMapping("helloService", null, null));
    Assertions.assertNotEquals(appNames, failoverReport.getServiceAppMapping("helloService", null, null));
    ServiceMetadataIdentifier serviceIdentifier = new ServiceMetadataIdentifier("helloService", null, null, null, "1.0", "dubbo");
    report.saveServiceMetadata(serviceIdentifier, url);
    // assert local metadata report write already.
    Assertions.assertNotNull(report.getExportedURLs(serviceIdentifier));
    Assertions.assertNotNull(localReport.getExportedURLs(serviceIdentifier));
    Assertions.assertNull(failoverReport.getExportedURLs(serviceIdentifier));
    Set<String> urls = new HashSet<>();
    urls.add(url.toFullString());
    report.saveSubscribedData(subscribeIdentifier, urls);
    // assert local metadata report write already.
    Assertions.assertEquals(new ArrayList<>(urls), report.getSubscribedURLs(subscribeIdentifier));
    Assertions.assertEquals(new ArrayList<>(urls), localReport.getSubscribedURLs(subscribeIdentifier));
    Assertions.assertNotEquals(new ArrayList<>(urls), failoverReport.getSubscribedURLs(subscribeIdentifier));
}
Also used : MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) MetadataInfo(org.apache.dubbo.metadata.MetadataInfo) HashMap(java.util.HashMap) URL(org.apache.dubbo.common.URL) ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) ServiceDefinition(org.apache.dubbo.metadata.definition.model.ServiceDefinition) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with MetadataReport

use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.

the class FailoverMetadataReportTest method getFailoverReport.

protected FailoverMetadataReport getFailoverReport(URL url) {
    MetadataReportFactory reportFactory = reportLoader.getExtension(url.getProtocol());
    Assertions.assertTrue(reportFactory instanceof FailoverMetadataReportFactory, "expect " + FailoverMetadataReportFactory.class.getName() + " instance type, " + "actual " + reportFactory.getClass().getName() + " instance type");
    MetadataReport report = reportFactory.getMetadataReport(url);
    Assertions.assertTrue(report instanceof FailoverMetadataReport, "expect " + FailoverMetadataReport.class.getName() + " instance type, " + "actual " + report.getClass().getName() + " instance type");
    FailoverMetadataReport failover = (FailoverMetadataReport) report;
    return failover;
}
Also used : MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) MetadataReportFactory(org.apache.dubbo.metadata.report.MetadataReportFactory) AbstractMetadataReportFactory(org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory)

Aggregations

MetadataReport (org.apache.dubbo.metadata.report.MetadataReport)9 SubscriberMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)2 MetadataReportFactory (org.apache.dubbo.metadata.report.MetadataReportFactory)2 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)2 AbstractMetadataReportFactory (org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory)2 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 URL (org.apache.dubbo.common.URL)1 FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)1 ServiceDefinition (org.apache.dubbo.metadata.definition.model.ServiceDefinition)1 ServiceMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier)1 Test (org.junit.jupiter.api.Test)1