Search in sources :

Example 16 with MetadataIdentifier

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

the class EtcdMetadataReportTest method storeConsumer.

private MetadataIdentifier storeConsumer(EtcdMetadataReport etcdMetadataReport, String interfaceName, String version, String group, String application) throws InterruptedException {
    MetadataIdentifier consumerIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application);
    Map<String, String> tmp = new HashMap<>();
    tmp.put("paramConsumerTest", "etcdConsumer");
    etcdMetadataReport.storeConsumerMetadata(consumerIdentifier, tmp);
    Thread.sleep(1000);
    return consumerIdentifier;
}
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) HashMap(java.util.HashMap)

Example 17 with MetadataIdentifier

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

the class EtcdMetadataReportTest method testStoreProvider.

@Test
public void testStoreProvider() throws Exception {
    String version = "1.0.0";
    String group = null;
    String application = "etcd-metdata-report-test";
    String r = etcdMetadataReport.getServiceDefinition(new MetadataIdentifier(TEST_SERVICE, version, group, "provider", application));
    Assertions.assertNull(r);
    MetadataIdentifier providerIdentifier = storeProvider(etcdMetadataReport, TEST_SERVICE, version, group, application);
    CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(providerIdentifier), StandardCharsets.UTF_8));
    String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
    Assertions.assertNotNull(fileContent);
    Gson gson = new Gson();
    FullServiceDefinition fullServiceDefinition = gson.fromJson(fileContent, FullServiceDefinition.class);
    Assertions.assertEquals(fullServiceDefinition.getParameters().get("paramTest"), "etcdTest");
    r = etcdMetadataReport.getServiceDefinition(new MetadataIdentifier(TEST_SERVICE, version, group, "provider", application));
    Assertions.assertNotNull(r);
}
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) Gson(com.google.gson.Gson) GetResponse(io.etcd.jetcd.kv.GetResponse) Test(org.junit.jupiter.api.Test)

Example 18 with MetadataIdentifier

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

the class FailoverMetadataReportTest method testReadWriteAllMetadataReport.

@Test
public void testReadWriteAllMetadataReport() {
    URL url = mockURL.addParameter("strategy", "all");
    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());
    MetadataIdentifier identifier = new MetadataIdentifier("helloService", null, null, null, "test");
    ServiceDefinition definition = new ServiceDefinition();
    definition.setCanonicalName("helloService");
    report.storeProviderMetadata(identifier, definition);
    Assertions.assertNotNull(report.getServiceDefinition(identifier));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertNotNull(holder.report.getServiceDefinition(identifier));
    }
    HashMap parameterMap = new HashMap();
    report.storeConsumerMetadata(identifier, parameterMap);
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertEquals(parameterMap, ((MockMetadataReport) holder.report).consumerMetadata.get(identifier));
    }
    SubscriberMetadataIdentifier subscribeIdentifier = new SubscriberMetadataIdentifier("test", "1.0");
    MetadataInfo metadataInfo = new MetadataInfo(subscribeIdentifier.getApplication(), subscribeIdentifier.getRevision(), null);
    report.publishAppMetadata(subscribeIdentifier, metadataInfo);
    Assertions.assertEquals(metadataInfo, report.getAppMetadata(subscribeIdentifier, null));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertEquals(metadataInfo, holder.report.getAppMetadata(subscribeIdentifier, null));
    }
    report.registerServiceAppMapping("helloService", "test", null);
    Set<String> appNames = report.getServiceAppMapping("helloService", null, null);
    Assertions.assertEquals(appNames, report.getServiceAppMapping("helloService", null, null));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertEquals(appNames, holder.report.getServiceAppMapping("helloService", null, null));
    }
    ServiceMetadataIdentifier serviceIdentifier = new ServiceMetadataIdentifier("helloService", null, null, null, "1.0", "dubbo");
    report.saveServiceMetadata(serviceIdentifier, url);
    Assertions.assertNotNull(report.getExportedURLs(serviceIdentifier));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertNotNull(holder.report.getExportedURLs(serviceIdentifier));
    }
    report.saveSubscribedData(subscribeIdentifier, new HashSet<>());
    Assertions.assertNotNull(report.getSubscribedURLs(subscribeIdentifier));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertNotNull(holder.report.getSubscribedURLs(subscribeIdentifier));
    }
}
Also used : 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) Test(org.junit.jupiter.api.Test)

Example 19 with MetadataIdentifier

use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project incubator-dubbo-ops by apache.

the class ServiceTestController method methodDetail.

@RequestMapping(value = "/method", method = RequestMethod.GET)
public MethodMetadata methodDetail(@PathVariable String env, @RequestParam String application, @RequestParam String service, @RequestParam String method) {
    Map<String, String> info = ConvertUtil.serviceName2Map(service);
    MetadataIdentifier identifier = new MetadataIdentifier(info.get(Constants.INTERFACE_KEY), info.get(Constants.VERSION_KEY), info.get(Constants.GROUP_KEY), Constants.PROVIDER_SIDE, application);
    String metadata = providerService.getProviderMetaData(identifier);
    MethodMetadata methodMetadata = null;
    if (metadata != null) {
        Gson gson = new Gson();
        String release = providerService.findVersionInApplication(application);
        if (release.startsWith("2.")) {
            org.apache.dubbo.admin.model.domain.FullServiceDefinition serviceDefinition = gson.fromJson(metadata, org.apache.dubbo.admin.model.domain.FullServiceDefinition.class);
            List<org.apache.dubbo.admin.model.domain.MethodDefinition> methods = serviceDefinition.getMethods();
            if (methods != null) {
                for (org.apache.dubbo.admin.model.domain.MethodDefinition m : methods) {
                    if (ServiceTestUtil.sameMethod(m, method)) {
                        methodMetadata = ServiceTestUtil.generateMethodMeta(serviceDefinition, m);
                        break;
                    }
                }
            }
        } else {
            FullServiceDefinition serviceDefinition = gson.fromJson(metadata, FullServiceDefinition.class);
            List<MethodDefinition> methods = serviceDefinition.getMethods();
            if (methods != null) {
                for (MethodDefinition m : methods) {
                    if (ServiceTestV3Util.sameMethod(m, method)) {
                        methodMetadata = ServiceTestV3Util.generateMethodMeta(serviceDefinition, m);
                        break;
                    }
                }
            }
        }
    }
    return methodMetadata;
}
Also used : Gson(com.google.gson.Gson) MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) MethodDefinition(org.apache.dubbo.metadata.definition.model.MethodDefinition) MethodMetadata(org.apache.dubbo.admin.model.domain.MethodMetadata) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with MetadataIdentifier

use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project incubator-dubbo-ops by apache.

the class MetricsCollectController method addMetricsConfigToMap.

protected void addMetricsConfigToMap(Map<String, String> configMap, String ip) {
    List<Provider> providers = providerService.findByAddress(ip);
    if (providers.size() > 0) {
        Provider provider = providers.get(0);
        String service = provider.getService();
        MetadataIdentifier providerIdentifier = new MetadataIdentifier(Tool.getInterface(service), Tool.getVersion(service), Tool.getGroup(service), Constants.PROVIDER_SIDE, provider.getApplication());
        String metaData = providerService.getProviderMetaData(providerIdentifier);
        FullServiceDefinition providerServiceDefinition = new Gson().fromJson(metaData, FullServiceDefinition.class);
        Map<String, String> parameters = providerServiceDefinition.getParameters();
        configMap.put(parameters.get(Constants.METRICS_PORT), parameters.get(Constants.METRICS_PROTOCOL));
    } else {
        List<Consumer> consumers = consumerService.findByAddress(ip);
        if (consumers.size() > 0) {
            Consumer consumer = consumers.get(0);
            String service = consumer.getService();
            MetadataIdentifier consumerIdentifier = new MetadataIdentifier(Tool.getInterface(service), Tool.getVersion(service), Tool.getGroup(service), Constants.CONSUMER_SIDE, consumer.getApplication());
            String metaData = consumerService.getConsumerMetadata(consumerIdentifier);
            Map<String, String> consumerParameters = new Gson().fromJson(metaData, Map.class);
            configMap.put(consumerParameters.get(Constants.METRICS_PORT), consumerParameters.get(Constants.METRICS_PROTOCOL));
        }
    }
}
Also used : MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) Consumer(org.apache.dubbo.admin.model.domain.Consumer) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) Gson(com.google.gson.Gson) Provider(org.apache.dubbo.admin.model.domain.Provider)

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