@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);
    }
  }
  private void populateLinksForService(
      Service service,
      Collection<Long> servicesToExportIds,
      Map<String, Object> composeServiceData) {
    List<String> serviceLinksWithNames = new ArrayList<>();
    List<String> externalLinksServices = new ArrayList<>();
    List<? extends ServiceConsumeMap> consumedServiceMaps =
        consumeMapDao.findConsumedServices(service.getId());
    for (ServiceConsumeMap consumedServiceMap : consumedServiceMaps) {
      Service consumedService =
          objectManager.findOne(
              Service.class, SERVICE.ID, consumedServiceMap.getConsumedServiceId());

      String linkName =
          consumedService.getName()
              + ":"
              + (consumedServiceMap.getName() != null
                  ? consumedServiceMap.getName()
                  : consumedService.getName());
      if (servicesToExportIds.contains(consumedServiceMap.getConsumedServiceId())) {
        serviceLinksWithNames.add(linkName);
      } else if (!consumedService.getEnvironmentId().equals(service.getEnvironmentId())) {
        Environment externalEnvironment =
            objectManager.loadResource(Environment.class, consumedService.getEnvironmentId());
        externalLinksServices.add(externalEnvironment.getName() + "/" + linkName);
      }
    }
    if (!serviceLinksWithNames.isEmpty()) {
      composeServiceData.put(
          ServiceDiscoveryConfigItem.LINKS.getDockerName(), serviceLinksWithNames);
    }

    if (!externalLinksServices.isEmpty()) {
      composeServiceData.put(
          ServiceDiscoveryConfigItem.EXTERNALLINKS.getDockerName(), externalLinksServices);
    }
  }