Search in sources :

Example 1 with VersionValidationException

use of org.apache.dubbo.admin.common.exception.VersionValidationException 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)

Aggregations

JsonParseException (com.google.gson.JsonParseException)1 VersionValidationException (org.apache.dubbo.admin.common.exception.VersionValidationException)1 Consumer (org.apache.dubbo.admin.model.domain.Consumer)1 Provider (org.apache.dubbo.admin.model.domain.Provider)1 ServiceDetailDTO (org.apache.dubbo.admin.model.dto.ServiceDetailDTO)1 FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)1 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1