Search in sources :

Example 1 with SubscriberMetadataIdentifier

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

the class ZookeeperMetadataReportTest method testDoGetSubscribedURLs.

@Test
public void testDoGetSubscribedURLs() throws ExecutionException, InterruptedException {
    String interfaceName = "org.apache.dubbo.metadata.store.zookeeper.ZookeeperMetadataReport4TstService";
    String version = "1.0.0";
    String group = null;
    String application = "etc-metadata-report-consumer-test";
    String revision = "90980";
    String protocol = "xxx";
    URL url = generateURL(interfaceName, version, group, application);
    SubscriberMetadataIdentifier subscriberMetadataIdentifier = new SubscriberMetadataIdentifier(application, revision);
    Gson gson = new Gson();
    String r = gson.toJson(Arrays.asList(url));
    zookeeperMetadataReport.doSaveSubscriberData(subscriberMetadataIdentifier, r);
    String fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(subscriberMetadataIdentifier));
    Assertions.assertNotNull(fileContent);
    Assertions.assertEquals(fileContent, r);
}
Also used : SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) Gson(com.google.gson.Gson) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 2 with SubscriberMetadataIdentifier

use of org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier 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 3 with SubscriberMetadataIdentifier

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

the class RemoteMetadataServiceImpl method getMetadata.

public MetadataInfo getMetadata(ServiceInstance instance) {
    SubscriberMetadataIdentifier identifier = new SubscriberMetadataIdentifier(instance.getServiceName(), ServiceInstanceMetadataUtils.getExportedServicesRevision(instance));
    String registryCluster = instance.getExtendParams().get(REGISTRY_CLUSTER_KEY);
    MetadataReport metadataReport = getMetadataReports().get(registryCluster);
    if (metadataReport == null) {
        metadataReport = getMetadataReports().entrySet().iterator().next().getValue();
    }
    return metadataReport.getAppMetadata(identifier, instance.getExtendParams());
}
Also used : MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)

Example 4 with SubscriberMetadataIdentifier

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

the class RemoteMetadataServiceImpl method publishMetadata.

public void publishMetadata(String serviceName) {
    Map<String, MetadataInfo> metadataInfos = localMetadataService.getMetadataInfos();
    metadataInfos.forEach((registryCluster, metadataInfo) -> {
        if (!metadataInfo.hasReported()) {
            SubscriberMetadataIdentifier identifier = new SubscriberMetadataIdentifier(serviceName, metadataInfo.calAndGetRevision());
            metadataInfo.getExtendParams().put(REGISTRY_CLUSTER_KEY, registryCluster);
            MetadataReport metadataReport = getMetadataReports().get(registryCluster);
            if (metadataReport == null) {
                metadataReport = getMetadataReports().entrySet().iterator().next().getValue();
            }
            logger.info("Publishing metadata to " + metadataReport.getClass().getSimpleName());
            if (logger.isDebugEnabled()) {
                logger.debug(metadataInfo.toString());
            }
            metadataReport.publishAppMetadata(identifier, metadataInfo);
            metadataInfo.markReported();
        }
    });
}
Also used : MetadataInfo(org.apache.dubbo.metadata.MetadataInfo) MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)

Example 5 with SubscriberMetadataIdentifier

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

the class ZookeeperMetadataReportTest method testDoSaveSubscriberData.

@Test
public void testDoSaveSubscriberData() throws ExecutionException, InterruptedException {
    String interfaceName = "org.apache.dubbo.metadata.store.zookeeper.ZookeeperMetadataReport4TstService";
    String version = "1.0.0";
    String group = null;
    String application = "etc-metadata-report-consumer-test";
    String revision = "90980";
    String protocol = "xxx";
    URL url = generateURL(interfaceName, version, group, application);
    SubscriberMetadataIdentifier subscriberMetadataIdentifier = new SubscriberMetadataIdentifier(application, revision);
    Gson gson = new Gson();
    String r = gson.toJson(Arrays.asList(url));
    zookeeperMetadataReport.doSaveSubscriberData(subscriberMetadataIdentifier, r);
    String fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(subscriberMetadataIdentifier));
    Assertions.assertNotNull(fileContent);
    Assertions.assertEquals(fileContent, r);
}
Also used : SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) Gson(com.google.gson.Gson) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

SubscriberMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)8 URL (org.apache.dubbo.common.URL)6 Test (org.junit.jupiter.api.Test)6 Gson (com.google.gson.Gson)4 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)3 MetadataReport (org.apache.dubbo.metadata.report.MetadataReport)3 GetResponse (io.etcd.jetcd.kv.GetResponse)2 HashMap (java.util.HashMap)2 ServiceDefinition (org.apache.dubbo.metadata.definition.model.ServiceDefinition)2 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)2 ServiceMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier)2 HashSet (java.util.HashSet)1