Search in sources :

Example 6 with MetadataIdentifier

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

the class ZookeeperMetadataReportTest method testStoreProvider.

@Test
public void testStoreProvider() throws ClassNotFoundException, InterruptedException {
    String interfaceName = "org.apache.dubbo.metadata.store.zookeeper.ZookeeperMetadataReport4TstService";
    String version = "1.0.0.zk.md";
    String group = null;
    String application = "vic.zk.md";
    MetadataIdentifier providerMetadataIdentifier = storePrivider(zookeeperMetadataReport, interfaceName, version, group, application);
    String fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
    fileContent = waitSeconds(fileContent, 3500, zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
    Assertions.assertNotNull(fileContent);
    deletePath(providerMetadataIdentifier, zookeeperMetadataReport);
    fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
    fileContent = waitSeconds(fileContent, 1000, zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
    Assertions.assertNull(fileContent);
    providerMetadataIdentifier = storePrivider(zookeeperMetadataReport, interfaceName, version, group, application);
    fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
    fileContent = waitSeconds(fileContent, 3500, zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
    Assertions.assertNotNull(fileContent);
    Gson gson = new Gson();
    FullServiceDefinition fullServiceDefinition = gson.fromJson(fileContent, FullServiceDefinition.class);
    Assertions.assertEquals(fullServiceDefinition.getParameters().get("paramTest"), "zkTest");
}
Also used : ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) Gson(com.google.gson.Gson) Test(org.junit.jupiter.api.Test)

Example 7 with MetadataIdentifier

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

the class ZookeeperMetadataReportTest method storePrivider.

private MetadataIdentifier storePrivider(MetadataReport zookeeperMetadataReport, String interfaceName, String version, String group, String application) throws ClassNotFoundException, InterruptedException {
    URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?paramTest=zkTest&version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group));
    MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
    Class interfaceClass = Class.forName(interfaceName);
    FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
    zookeeperMetadataReport.storeProviderMetadata(providerMetadataIdentifier, fullServiceDefinition);
    Thread.sleep(2000);
    return providerMetadataIdentifier;
}
Also used : ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) URL(org.apache.dubbo.common.URL)

Example 8 with MetadataIdentifier

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

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

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

the class EtcdMetadataReportTest method storeProvider.

private MetadataIdentifier storeProvider(EtcdMetadataReport etcdMetadataReport, String interfaceName, String version, String group, String application) throws ClassNotFoundException, InterruptedException {
    URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?paramTest=etcdTest&version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group));
    MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
    Class interfaceClass = Class.forName(interfaceName);
    FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
    etcdMetadataReport.storeProviderMetadata(providerMetadataIdentifier, fullServiceDefinition);
    Thread.sleep(1000);
    return providerMetadataIdentifier;
}
Also used : MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) URL(org.apache.dubbo.common.URL)

Aggregations

MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)22 SubscriberMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)12 FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)11 ServiceMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier)10 URL (org.apache.dubbo.common.URL)8 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)6 Gson (com.google.gson.Gson)5 GetResponse (io.etcd.jetcd.kv.GetResponse)2 Consumer (org.apache.dubbo.admin.model.domain.Consumer)2 Provider (org.apache.dubbo.admin.model.domain.Provider)2 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)2 MethodDefinition (org.apache.dubbo.metadata.definition.model.MethodDefinition)2 ServiceDefinition (org.apache.dubbo.metadata.definition.model.ServiceDefinition)2 MetadataReport (org.apache.dubbo.metadata.report.MetadataReport)2 RpcException (org.apache.dubbo.rpc.RpcException)2 Test (org.junit.Test)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Jedis (redis.clients.jedis.Jedis)2 JsonParseException (com.google.gson.JsonParseException)1