Search in sources :

Example 1 with FullServiceDefinition

use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition 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 2 with FullServiceDefinition

use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition in project dubbo by alibaba.

the class ProtobufTypeBuilderTest method testProtobufBuilder.

@Test
public void testProtobufBuilder() {
    // TEST Pb Service metaData builder
    FullServiceDefinition serviceDefinition = ServiceDefinitionBuilder.buildFullDefinition(ServiceInterface.class);
    MethodDefinition methodDefinition = serviceDefinition.getMethods().get(0);
    String parameterName = methodDefinition.getParameterTypes()[0];
    TypeDefinition typeDefinition = null;
    for (TypeDefinition type : serviceDefinition.getTypes()) {
        if (parameterName.equals(type.getType())) {
            typeDefinition = type;
            break;
        }
    }
    Map<String, TypeDefinition> propertiesMap = typeDefinition.getProperties();
    assertThat(propertiesMap.size(), is(11));
    assertThat(propertiesMap.containsKey("money"), is(true));
    assertThat(propertiesMap.get("money").getType(), equalTo("double"));
    assertThat(propertiesMap.containsKey("cash"), is(true));
    assertThat(propertiesMap.get("cash").getType(), equalTo("float"));
    assertThat(propertiesMap.containsKey("age"), is(true));
    assertThat(propertiesMap.get("age").getType(), equalTo("int"));
    assertThat(propertiesMap.containsKey("num"), is(true));
    assertThat(propertiesMap.get("num").getType(), equalTo("long"));
    assertThat(propertiesMap.containsKey("sex"), is(true));
    assertThat(propertiesMap.get("sex").getType(), equalTo("boolean"));
    assertThat(propertiesMap.containsKey("name"), is(true));
    assertThat(propertiesMap.get("name").getType(), equalTo("java.lang.String"));
    assertThat(propertiesMap.containsKey("msg"), is(true));
    assertThat(propertiesMap.get("msg").getType(), equalTo("com.google.protobuf.ByteString"));
    assertThat(propertiesMap.containsKey("phone"), is(true));
    assertThat(propertiesMap.get("phone").getType(), equalTo("java.util.List<org.apache.dubbo.metadata.definition.protobuf.model.GooglePB$PhoneNumber>"));
    assertThat(propertiesMap.containsKey("doubleMap"), is(true));
    assertThat(propertiesMap.get("doubleMap").getType(), equalTo("java.util.Map<java.lang.String,org.apache.dubbo.metadata.definition.protobuf.model.GooglePB$PhoneNumber>"));
    assertThat(propertiesMap.get("bytesList").getType(), equalTo("java.util.List<com.google.protobuf.ByteString>"));
    assertThat(propertiesMap.get("bytesMap").getType(), equalTo("java.util.Map<java.lang.String,com.google.protobuf.ByteString>"));
}
Also used : FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) MethodDefinition(org.apache.dubbo.metadata.definition.model.MethodDefinition) TypeDefinition(org.apache.dubbo.metadata.definition.model.TypeDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with FullServiceDefinition

use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition 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 4 with FullServiceDefinition

use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition 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 5 with FullServiceDefinition

use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition 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)

Aggregations

FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)16 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)11 Gson (com.google.gson.Gson)5 SubscriberMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)5 Test (org.junit.jupiter.api.Test)5 URL (org.apache.dubbo.common.URL)4 MethodDefinition (org.apache.dubbo.metadata.definition.model.MethodDefinition)4 ServiceMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Consumer (org.apache.dubbo.admin.model.domain.Consumer)2 Provider (org.apache.dubbo.admin.model.domain.Provider)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonParseException (com.google.gson.JsonParseException)1 GetResponse (io.etcd.jetcd.kv.GetResponse)1 VersionValidationException (org.apache.dubbo.admin.common.exception.VersionValidationException)1 MethodMetadata (org.apache.dubbo.admin.model.domain.MethodMetadata)1 ServiceDetailDTO (org.apache.dubbo.admin.model.dto.ServiceDetailDTO)1 TypeDefinition (org.apache.dubbo.metadata.definition.model.TypeDefinition)1 MetadataReport (org.apache.dubbo.metadata.report.MetadataReport)1