Search in sources :

Example 1 with MetadataIdentifier

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

the class ConsulMetaDataCollectorTest method testGetConsumerMetaData.

@Test
public void testGetConsumerMetaData() {
    MetadataIdentifier identifier = buildIdentifier(false);
    Map<String, String> consumerParams = new HashMap<>();
    consumerParams.put("k1", "v1");
    consumerParams.put("k2", "1");
    consumerParams.put("k3", "true");
    String metadata = gson.toJson(consumerParams);
    consulMetaDataCollector.getClient().setKVValue(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), metadata);
    String consumerMetaData = consulMetaDataCollector.getConsumerMetaData(identifier);
    Map<String, String> retParams = gson.fromJson(consumerMetaData, new TypeToken<Map<String, String>>() {
    }.getType());
    Assert.assertEquals(consumerParams, retParams);
}
Also used : MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) HashMap(java.util.HashMap) TypeToken(com.google.gson.reflect.TypeToken) Test(org.junit.Test)

Example 2 with MetadataIdentifier

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

the class ServiceController method serviceDetail.

@RequestMapping(value = "/service/{service}", method = RequestMethod.GET)
public ServiceDetailDTO serviceDetail(@PathVariable String service, @PathVariable String env) {
    service = service.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
    String group = Tool.getGroup(service);
    String version = Tool.getVersion(service);
    String interfaze = Tool.getInterface(service);
    List<Provider> providers = providerService.findByService(service);
    List<Consumer> consumers = consumerService.findByService(service);
    String application = null;
    if (providers != null && providers.size() > 0) {
        application = providers.get(0).getApplication();
    }
    MetadataIdentifier identifier = new MetadataIdentifier(interfaze, version, group, Constants.PROVIDER_SIDE, application);
    String metadata = providerService.getProviderMetaData(identifier);
    ServiceDetailDTO serviceDetailDTO = new ServiceDetailDTO();
    serviceDetailDTO.setConsumers(consumers);
    serviceDetailDTO.setProviders(providers);
    if (metadata != null) {
        try {
            // for dubbo version under 2.7, this metadata will represent as IP address, like 10.0.0.1.
            // So the json conversion will fail.
            String release = providerService.findVersionInApplication(application);
            // serialization compatible 2.x version
            if (release.startsWith("2")) {
                org.apache.dubbo.admin.model.domain.FullServiceDefinition serviceDefinition = gson.fromJson(metadata, org.apache.dubbo.admin.model.domain.FullServiceDefinition.class);
                serviceDetailDTO.setMetadata(serviceDefinition);
            } else {
                FullServiceDefinition serviceDefinition = gson.fromJson(metadata, FullServiceDefinition.class);
                serviceDetailDTO.setMetadata(serviceDefinition);
            }
        } catch (JsonParseException e) {
            throw new VersionValidationException("dubbo 2.6 does not support metadata");
        }
    }
    serviceDetailDTO.setConsumers(consumers);
    serviceDetailDTO.setProviders(providers);
    serviceDetailDTO.setService(service);
    serviceDetailDTO.setApplication(application);
    return serviceDetailDTO;
}
Also used : VersionValidationException(org.apache.dubbo.admin.common.exception.VersionValidationException) JsonParseException(com.google.gson.JsonParseException) Provider(org.apache.dubbo.admin.model.domain.Provider) MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) Consumer(org.apache.dubbo.admin.model.domain.Consumer) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) ServiceDetailDTO(org.apache.dubbo.admin.model.dto.ServiceDetailDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with MetadataIdentifier

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

the class RedisMetadataReportTest method testStoreConsumer.

private void testStoreConsumer(RedisMetadataReport redisMetadataReport, String version, long moreTime) throws ClassNotFoundException {
    String interfaceName = "org.apache.dubbo.metadata.store.redis.RedisMetadata4TstService";
    String group = null;
    String application = "vic.redis.md";
    MetadataIdentifier consumerMetadataIdentifier = storeConsumer(redisMetadataReport, interfaceName, version, group, application);
    Jedis jedis = null;
    try {
        jedis = redisMetadataReport.pool.getResource();
        String keyTmp = consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
        String value = jedis.get(keyTmp);
        if (value == null) {
            Thread.sleep(moreTime);
            value = jedis.get(keyTmp);
        }
        Assertions.assertEquals(value, "{\"paramConsumerTest\":\"redisCm\"}");
    } catch (Throwable e) {
        throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
    } finally {
        if (jedis != null) {
            jedis.del(consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
        }
        redisMetadataReport.pool.close();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) RpcException(org.apache.dubbo.rpc.RpcException)

Example 4 with MetadataIdentifier

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

the class RedisMetadataReportTest method testStoreProvider.

private void testStoreProvider(RedisMetadataReport redisMetadataReport, String version, long moreTime) throws ClassNotFoundException {
    String interfaceName = "org.apache.dubbo.metadata.store.redis.RedisMetadata4TstService";
    String group = null;
    String application = "vic.redis.md";
    MetadataIdentifier providerMetadataIdentifier = storePrivider(redisMetadataReport, interfaceName, version, group, application);
    Jedis jedis = null;
    try {
        jedis = redisMetadataReport.pool.getResource();
        String keyTmp = providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
        String value = jedis.get(keyTmp);
        if (value == null) {
            Thread.sleep(moreTime);
            value = jedis.get(keyTmp);
        }
        Assertions.assertNotNull(value);
        Gson gson = new Gson();
        FullServiceDefinition fullServiceDefinition = gson.fromJson(value, FullServiceDefinition.class);
        Assertions.assertEquals(fullServiceDefinition.getParameters().get("paramTest"), "redisTest");
    } catch (Throwable e) {
        throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
    } finally {
        if (jedis != null) {
            jedis.del(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
        }
        redisMetadataReport.pool.close();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) RpcException(org.apache.dubbo.rpc.RpcException) Gson(com.google.gson.Gson)

Example 5 with MetadataIdentifier

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

the class ZookeeperMetadataReportTest method storeConsumer.

private MetadataIdentifier storeConsumer(MetadataReport zookeeperMetadataReport, String interfaceName, String version, String group, String application) throws ClassNotFoundException, InterruptedException {
    URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group));
    MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application);
    Class interfaceClass = Class.forName(interfaceName);
    Map<String, String> tmp = new HashMap<>();
    tmp.put("paramConsumerTest", "zkCm");
    zookeeperMetadataReport.storeConsumerMetadata(consumerMetadataIdentifier, tmp);
    Thread.sleep(2000);
    return consumerMetadataIdentifier;
}
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) HashMap(java.util.HashMap) 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