Ejemplo n.º 1
0
 protected List<ServiceInstanceData> populateTargetInstancesData(
     Map<Long, List<ServiceInstanceData>> servicesTargetInstances,
     Map<Long, List<ServiceDnsEntryData>> clientServiceIdToServiceData,
     Service targetService) {
   List<ServiceInstanceData> targetInstancesData = new ArrayList<>();
   if (targetService
       .getKind()
       .equalsIgnoreCase(ServiceDiscoveryConstants.KIND.DNSSERVICE.name())) {
     List<ServiceDnsEntryData> behindAlias =
         clientServiceIdToServiceData.get(targetService.getId());
     if (behindAlias != null) {
       for (ServiceDnsEntryData behindAliasEntry : behindAlias) {
         List<ServiceInstanceData> toAdd =
             servicesTargetInstances.get(behindAliasEntry.getTargetService().getId());
         if (toAdd != null) {
           targetInstancesData.addAll(toAdd);
         }
       }
     }
   } else {
     List<ServiceInstanceData> toAdd = servicesTargetInstances.get(targetService.getId());
     if (toAdd != null) {
       targetInstancesData.addAll(toAdd);
     }
   }
   return targetInstancesData;
 }
Ejemplo n.º 2
0
  protected List<DnsEntryData> convertToDnsEntryData(
      final boolean isVIPProvider,
      List<ServiceDnsEntryData> serviceDnsData,
      long accountId,
      long vnetId) {
    final Map<Long, IpAddress> instanceIdToHostIpMap =
        getInstanceWithHostNetworkingToIpMap(accountId);
    Map<Long, List<ServiceInstanceData>> servicesClientInstances =
        getServiceInstancesData(accountId, true, vnetId);
    Map<Long, List<ServiceInstanceData>> servicesTargetInstances =
        getServiceInstancesData(accountId, false, vnetId);
    Map<Long, List<ServiceDnsEntryData>> clientServiceIdToServiceData = new HashMap<>();
    for (ServiceDnsEntryData data : serviceDnsData) {
      Long clientServiceId = data.getClientService().getId();
      List<ServiceDnsEntryData> existingData = clientServiceIdToServiceData.get(clientServiceId);
      if (existingData == null) {
        existingData = new ArrayList<>();
      }
      existingData.add(data);
      clientServiceIdToServiceData.put(clientServiceId, existingData);
    }

    List<DnsEntryData> returnData = new ArrayList<>();

    for (ServiceDnsEntryData serviceData : serviceDnsData) {
      Service clientService = serviceData.getClientService();
      Map<String, Map<String, String>> resolve = new HashMap<>();
      Map<String, String> resolveCname = new HashMap<>();
      Service targetService = serviceData.getTargetService();
      List<ServiceInstanceData> targetInstancesData =
          populateTargetInstancesData(
              servicesTargetInstances, clientServiceIdToServiceData, targetService);

      for (ServiceInstanceData targetInstance : targetInstancesData) {
        populateResolveInfo(
            isVIPProvider,
            instanceIdToHostIpMap,
            serviceData,
            clientService,
            resolve,
            resolveCname,
            targetService,
            targetInstance);
      }

      if (servicesClientInstances.containsKey(clientService.getId())) {
        for (ServiceInstanceData clientInstance :
            servicesClientInstances.get(clientService.getId())) {
          DnsEntryData data = new DnsEntryData();
          String clientIp = getIpAddress(clientInstance, true, instanceIdToHostIpMap);
          data.setSourceIpAddress(clientIp);
          data.setResolveServicesAndContainers(resolve);
          data.setInstance(clientInstance.getInstance());
          data.setResolveCname(resolveCname);
          returnData.add(data);
        }
      }
    }
    return returnData;
  }