private void populateNetworkForService(
     Service service, String launchConfigName, Map<String, Object> composeServiceData) {
   Object networkMode =
       composeServiceData.get(ServiceDiscoveryConfigItem.NETWORKMODE.getDockerName());
   if (networkMode != null) {
     if (networkMode.equals(DockerNetworkConstants.NETWORK_MODE_CONTAINER)) {
       Map<String, Object> serviceData =
           ServiceDiscoveryUtil.getLaunchConfigDataAsMap(service, launchConfigName);
       // network mode can be passed by container, or by service name, so check both
       // networkFromContainerId wins
       Integer targetContainerId =
           DataAccessor.fieldInteger(service, DockerInstanceConstants.DOCKER_CONTAINER);
       if (targetContainerId != null) {
         Instance instance =
             objectManager.loadResource(Instance.class, targetContainerId.longValue());
         String instanceName = ServiceDiscoveryUtil.getInstanceName(instance);
         composeServiceData.put(
             ServiceDiscoveryConfigItem.NETWORKMODE.getDockerName(),
             DockerNetworkConstants.NETWORK_MODE_CONTAINER + ":" + instanceName);
       } else {
         Object networkLaunchConfig =
             serviceData.get(ServiceDiscoveryConstants.FIELD_NETWORK_LAUNCH_CONFIG);
         if (networkLaunchConfig != null) {
           composeServiceData.put(
               ServiceDiscoveryConfigItem.NETWORKMODE.getDockerName(),
               DockerNetworkConstants.NETWORK_MODE_CONTAINER + ":" + networkLaunchConfig);
         }
       }
     } else if (networkMode.equals(DockerNetworkConstants.NETWORK_MODE_MANAGED)) {
       composeServiceData.remove(ServiceDiscoveryConfigItem.NETWORKMODE.getDockerName());
     }
   }
 }
  @Override
  @SuppressWarnings("unchecked")
  public void createLoadBalancerService(
      Service service, List<? extends Long> certIds, Long defaultCertId) {
    String lbName = getLoadBalancerName(service);
    // 1. create load balancer config
    Map<String, Object> lbConfigData =
        (Map<String, Object>)
            DataAccessor.field(
                service,
                ServiceDiscoveryConstants.FIELD_LOAD_BALANCER_CONFIG,
                jsonMapper,
                Map.class);

    if (lbConfigData == null) {
      lbConfigData = new HashMap<String, Object>();
    }

    LoadBalancerConfig lbConfig = createDefaultLoadBalancerConfig(lbName, lbConfigData, service);

    // 2. add listeners to the config based on the ports info
    Map<String, Object> launchConfigData =
        ServiceDiscoveryUtil.getLaunchConfigDataAsMap(service, null);
    createListeners(service, lbConfig, launchConfigData);

    // 3. create a load balancer
    createLoadBalancer(service, lbName, lbConfig, launchConfigData, certIds, defaultCertId);
  }
  @SuppressWarnings("unchecked")
  private void populateVolumesForService(
      Service service, String launchConfigName, Map<String, Object> composeServiceData) {
    List<String> namesCombined = new ArrayList<>();
    List<String> launchConfigNames = new ArrayList<>();
    Map<String, Object> launchConfigData =
        ServiceDiscoveryUtil.getLaunchConfigDataAsMap(service, launchConfigName);
    Object dataVolumesLaunchConfigs =
        launchConfigData.get(ServiceDiscoveryConstants.FIELD_DATA_VOLUMES_LAUNCH_CONFIG);

    if (dataVolumesLaunchConfigs != null) {
      launchConfigNames.addAll((List<String>) dataVolumesLaunchConfigs);
    }

    // 1. add launch config names
    namesCombined.addAll(launchConfigNames);

    // 2. add instance names if specified
    List<? extends Integer> instanceIds =
        (List<? extends Integer>) launchConfigData.get(DockerInstanceConstants.FIELD_VOLUMES_FROM);

    if (instanceIds != null) {
      for (Integer instanceId : instanceIds) {
        Instance instance =
            objectManager.findOne(Instance.class, INSTANCE.ID, instanceId, INSTANCE.REMOVED, null);
        String instanceName = ServiceDiscoveryUtil.getInstanceName(instance);
        if (instanceName != null) {
          namesCombined.add(instanceName);
        }
      }
    }

    if (!namesCombined.isEmpty()) {
      composeServiceData.put(ServiceDiscoveryConfigItem.VOLUMESFROM.getDockerName(), namesCombined);
    }
  }