Search in sources :

Example 6 with Provider

use of org.apache.dubbo.admin.model.domain.Provider in project incubator-dubbo-ops by apache.

the class ProviderServiceImpl method convertProviders2DTO.

/**
 * Convert provider list to ServiceDTO list
 *
 * @param providers list of providers
 * @return ServiceDTO list of front page
 */
public Set<ServiceDTO> convertProviders2DTO(List<Provider> providers) {
    Set<ServiceDTO> result = new TreeSet<>();
    for (Provider provider : providers) {
        String app = provider.getApplication();
        String service = provider.getService();
        String group = Tool.getGroup(service);
        String version = Tool.getVersion(service);
        String interfaze = Tool.getInterface(service);
        ServiceDTO s = new ServiceDTO();
        s.setAppName(app);
        s.setService(interfaze);
        s.setGroup(group);
        s.setVersion(version);
        s.setRegistrySource(provider.getRegistrySource());
        result.add(s);
    }
    return result;
}
Also used : TreeSet(java.util.TreeSet) ServiceDTO(org.apache.dubbo.admin.model.dto.ServiceDTO) Provider(org.apache.dubbo.admin.model.domain.Provider)

Example 7 with Provider

use of org.apache.dubbo.admin.model.domain.Provider in project incubator-dubbo-ops by apache.

the class MetricsServiceImpl method getApplicationRelation.

@Override
public RelationDTO getApplicationRelation() {
    List<Consumer> consumerList = consumerService.findAll();
    List<Provider> providerList = providerService.findAll();
    int index = 0;
    // collect all service
    Set<String> serviceSet = new HashSet<>();
    // collect consumer's nodes map <application, node>
    Map<String, RelationDTO.Node> consumerNodeMap = new HashMap<>();
    // collect consumer's service and applications map <service, set<application>>
    Map<String, Set<String>> consumerServiceApplicationMap = new HashMap<>();
    for (Consumer consumer : consumerList) {
        String application = consumer.getApplication();
        if (!consumerNodeMap.keySet().contains(application)) {
            RelationDTO.Node node = new RelationDTO.Node(index, application, RelationDTO.CONSUMER_CATEGORIES.getIndex());
            consumerNodeMap.put(application, node);
            index++;
        }
        String service = consumer.getService();
        serviceSet.add(service);
        consumerServiceApplicationMap.computeIfAbsent(service, s -> new HashSet<>());
        consumerServiceApplicationMap.get(service).add(application);
    }
    // collect provider's nodes
    Map<String, RelationDTO.Node> providerNodeMap = new HashMap<>();
    // collect provider's service and applications map <service, set<application>>
    Map<String, Set<String>> providerServiceApplicationMap = new HashMap<>();
    for (Provider provider : providerList) {
        String application = provider.getApplication();
        if (!providerNodeMap.keySet().contains(application)) {
            RelationDTO.Node node = new RelationDTO.Node(index, application, RelationDTO.PROVIDER_CATEGORIES.getIndex());
            providerNodeMap.put(application, node);
            index++;
        }
        String service = provider.getService();
        serviceSet.add(service);
        providerServiceApplicationMap.computeIfAbsent(service, s -> new HashSet<>());
        providerServiceApplicationMap.get(service).add(application);
    }
    // merge provider's nodes and consumer's nodes
    Map<String, RelationDTO.Node> nodeMap = new HashMap<>(consumerNodeMap);
    for (Map.Entry<String, RelationDTO.Node> entry : providerNodeMap.entrySet()) {
        if (nodeMap.get(entry.getKey()) != null) {
            nodeMap.get(entry.getKey()).setCategory(RelationDTO.CONSUMER_AND_PROVIDER_CATEGORIES.getIndex());
        } else {
            nodeMap.put(entry.getKey(), entry.getValue());
        }
    }
    // build link by same service
    Set<RelationDTO.Link> linkSet = new HashSet<>();
    for (String service : serviceSet) {
        Set<String> consumerApplicationSet = consumerServiceApplicationMap.get(service);
        Set<String> providerApplicationSet = providerServiceApplicationMap.get(service);
        if (CollectionUtils.isNotEmpty(consumerApplicationSet) && CollectionUtils.isNotEmpty(providerApplicationSet)) {
            for (String providerApplication : providerApplicationSet) {
                for (String consumerApplication : consumerApplicationSet) {
                    if (nodeMap.get(consumerApplication) != null && nodeMap.get(providerApplication) != null) {
                        Integer consumerIndex = nodeMap.get(consumerApplication).getIndex();
                        Integer providerIndex = nodeMap.get(providerApplication).getIndex();
                        linkSet.add(new RelationDTO.Link(consumerIndex, providerIndex));
                    }
                }
            }
        }
    }
    // sort node by index
    List<RelationDTO.Node> nodeList = nodeMap.values().stream().sorted(Comparator.comparingInt(RelationDTO.Node::getIndex)).collect(Collectors.toList());
    return new RelationDTO(nodeList, new ArrayList<>(linkSet));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Provider(org.apache.dubbo.admin.model.domain.Provider) Consumer(org.apache.dubbo.admin.model.domain.Consumer) RelationDTO(org.apache.dubbo.admin.model.dto.RelationDTO) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

Provider (org.apache.dubbo.admin.model.domain.Provider)7 Consumer (org.apache.dubbo.admin.model.domain.Consumer)3 FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)2 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)2 Gson (com.google.gson.Gson)1 JsonParseException (com.google.gson.JsonParseException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 VersionValidationException (org.apache.dubbo.admin.common.exception.VersionValidationException)1 RelationDTO (org.apache.dubbo.admin.model.dto.RelationDTO)1 ServiceDTO (org.apache.dubbo.admin.model.dto.ServiceDTO)1 ServiceDetailDTO (org.apache.dubbo.admin.model.dto.ServiceDetailDTO)1 URL (org.apache.dubbo.common.URL)1 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)1