protected String getServiceVIP(Service service, String requestedVip) {
   if (service.getKind().equalsIgnoreCase(KIND.LOADBALANCERSERVICE.name())
       || service.getKind().equalsIgnoreCase(KIND.SERVICE.name())
       || service.getKind().equalsIgnoreCase(KIND.DNSSERVICE.name())) {
     Subnet vipSubnet = getServiceVipSubnet(service);
     PooledResourceOptions options = new PooledResourceOptions();
     if (requestedVip != null) {
       options.setRequestedItem(requestedVip);
     }
     PooledResource resource = poolManager.allocateOneResource(vipSubnet, service, options);
     if (resource != null) {
       return resource.getName();
     }
   }
   return null;
 }
 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;
 }
 private void addExtraComposeParameters(
     Service service, String launchConfigName, Map<String, Object> composeServiceData) {
   if (service.getKind().equalsIgnoreCase(ServiceDiscoveryConstants.KIND.DNSSERVICE.name())) {
     composeServiceData.put(
         ServiceDiscoveryConfigItem.IMAGE.getDockerName(), "rancher/dns-service");
   } else if (service
       .getKind()
       .equalsIgnoreCase(ServiceDiscoveryConstants.KIND.LOADBALANCERSERVICE.name())) {
     composeServiceData.put(
         ServiceDiscoveryConfigItem.IMAGE.getDockerName(), "rancher/load-balancer-service");
   } else if (service
       .getKind()
       .equalsIgnoreCase(ServiceDiscoveryConstants.KIND.EXTERNALSERVICE.name())) {
     composeServiceData.put(
         ServiceDiscoveryConfigItem.IMAGE.getDockerName(), "rancher/external-service");
   }
 }
  @Override
  public void addLoadBalancerServiceLink(Service service, LoadBalancerServiceLink serviceLink) {
    if (!service
        .getKind()
        .equalsIgnoreCase(ServiceDiscoveryConstants.KIND.LOADBALANCERSERVICE.name())) {
      return;
    }

    consumeMapDao.createServiceLink(service, serviceLink);
  }
  @SuppressWarnings("unchecked")
  protected void populateLoadBalancerServiceLabels(
      Service service, String launchConfigName, Map<String, Object> composeServiceData) {
    if (!service
        .getKind()
        .equalsIgnoreCase(ServiceDiscoveryConstants.KIND.LOADBALANCERSERVICE.name())) {
      return;
    }

    Map<String, String> labels = new HashMap<>();
    if (composeServiceData.get(InstanceConstants.FIELD_LABELS) != null) {
      labels.putAll(
          (HashMap<String, String>) composeServiceData.get(InstanceConstants.FIELD_LABELS));
    }
    // get all consumed services maps
    List<? extends ServiceConsumeMap> consumedServiceMaps =
        consumeMapDao.findConsumedServices(service.getId());
    // for each port, populate the label
    for (ServiceConsumeMap map : consumedServiceMaps) {
      Service consumedService =
          objectManager.loadResource(Service.class, map.getConsumedServiceId());
      List<String> ports =
          DataAccessor.fieldStringList(map, LoadBalancerConstants.FIELD_LB_TARGET_PORTS);
      String consumedServiceName = consumedService.getName();
      if (!service.getEnvironmentId().equals(consumedService.getEnvironmentId())) {
        Environment env =
            objectManager.loadResource(Environment.class, consumedService.getEnvironmentId());
        consumedServiceName = env.getName() + "/" + consumedServiceName;
      }
      String labelName = ServiceDiscoveryConstants.LABEL_LB_TARGET + consumedServiceName;
      StringBuilder bldr = new StringBuilder();
      for (String port : ports) {
        bldr.append(port).append(",");
      }
      if (bldr.length() > 0) {
        labels.put(labelName, bldr.toString().substring(0, bldr.length() - 1));
      }
    }

    if (!labels.isEmpty()) {
      composeServiceData.put(InstanceConstants.FIELD_LABELS, labels);
    }
  }
  @Override
  public void addToLoadBalancerService(Service lbSvc, ServiceExposeMap instanceToRegister) {
    if (!lbSvc
        .getKind()
        .equalsIgnoreCase(ServiceDiscoveryConstants.KIND.LOADBALANCERSERVICE.name())) {
      return;
    }

    if (!isActiveService(lbSvc)) {
      return;
    }

    if (!exposeMapDao.isActiveMap(instanceToRegister)) {
      return;
    }

    LoadBalancer lb =
        objectManager.findOne(
            LoadBalancer.class,
            LOAD_BALANCER.SERVICE_ID,
            lbSvc.getId(),
            LOAD_BALANCER.REMOVED,
            null);
    if (lb == null) {
      return;
    }

    ServiceConsumeMap map =
        consumeMapDao.findNonRemovedMap(lbSvc.getId(), instanceToRegister.getServiceId(), null);
    if (map == null) {
      return;
    }

    LoadBalancerTargetInput target =
        new LoadBalancerTargetInput(instanceToRegister, map, jsonMapper);
    lbService.addTargetToLoadBalancer(lb, target);
  }