// Path: aliyun-slb/src/main/java/org/jclouds/aliyun/slb/SLBApi.java
// public interface SLBApi extends Closeable {
// 
//    static final String DEFAULT_REGION = "cn-hangzhou";
// 
//    IAcsClient getAcsClient(String region);
// 
//    Set<String> getAvailableRegions();
// 
//    String encodeToId(String region, String id);
// 
//    String decodeToRegion(String id);
// 
//    String decodeToId(String id);
// }
// 
// Path: aliyun-slb/src/main/java/org/jclouds/aliyun/slb/loadbalancer/domain/SLBLoadBalancerProtocol.java
// public enum SLBLoadBalancerProtocol {
//    HTTP, HTTPS, TCP, UDP
// }


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.aliyun.slb.SLBApi;
import org.jclouds.aliyun.slb.loadbalancer.domain.SLBLoadBalancerProtocol;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.Location;
import org.jclouds.loadbalancer.LoadBalancerServiceAdapter;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.loadbalancer.strategy.LoadBalanceNodesStrategy;
import org.jclouds.logging.Logger;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.slb.model.v20140515.AddBackendServersRequest;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerHTTPListenerRequest;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerHTTPSListenerRequest;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerTCPListenerRequest;
import com.aliyuncs.slb.model.v20140515.StartLoadBalancerListenerRequest;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
package org.jclouds.aliyun.slb.loadbalancer.strategy;





public class SLBLoadBalanceNodesStrategy implements LoadBalanceNodesStrategy {

   @Resource
   @Named(LoadBalancerConstants.LOADBALANCER_LOGGER)
   protected Logger logger = Logger.NULL;

   protected final SLBApi api;
   protected final LoadBalancerServiceAdapter<LoadBalancerMetadata, Location> adapter;

   @Inject
   public SLBLoadBalanceNodesStrategy (
         LoadBalancerServiceAdapter<LoadBalancerMetadata, Location> adapter,
         SLBApi api) {
      this.adapter = adapter;
      this.api = api;
   }

   @Override
   public LoadBalancerMetadata createLoadBalancerInLocation(
         Location location,
         String name,
         String protocol,
         int loadBalancerPort,
         int instancePort,
         Iterable<? extends NodeMetadata> nodes) {
      IAcsClient client = api.getAcsClient(location.getId());
      LoadBalancerMetadata lbm = adapter
            .createLoadBalancerInLocation(location, name, protocol, loadBalancerPort, instancePort, nodes);
      String loadBalancerId = lbm.getId();
// Path: aliyun-slb/src/main/java/org/jclouds/aliyun/slb/SLBApi.java
// public interface SLBApi extends Closeable {
// 
//    static final String DEFAULT_REGION = "cn-hangzhou";
// 
//    IAcsClient getAcsClient(String region);
// 
//    Set<String> getAvailableRegions();
// 
//    String encodeToId(String region, String id);
// 
//    String decodeToRegion(String id);
// 
//    String decodeToId(String id);
// }
// 
// Path: aliyun-slb/src/main/java/org/jclouds/aliyun/slb/loadbalancer/domain/SLBLoadBalancerProtocol.java
// public enum SLBLoadBalancerProtocol {
//    HTTP, HTTPS, TCP, UDP
// }


// Path: aliyun-slb/src/main/java/org/jclouds/aliyun/slb/loadbalancer/strategy/SLBLoadBalanceNodesStrategy.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.aliyun.slb.SLBApi;
import org.jclouds.aliyun.slb.loadbalancer.domain.SLBLoadBalancerProtocol;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.Location;
import org.jclouds.loadbalancer.LoadBalancerServiceAdapter;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.loadbalancer.strategy.LoadBalanceNodesStrategy;
import org.jclouds.logging.Logger;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.slb.model.v20140515.AddBackendServersRequest;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerHTTPListenerRequest;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerHTTPSListenerRequest;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerTCPListenerRequest;
import com.aliyuncs.slb.model.v20140515.StartLoadBalancerListenerRequest;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

package org.jclouds.aliyun.slb.loadbalancer.strategy;





public class SLBLoadBalanceNodesStrategy implements LoadBalanceNodesStrategy {

   @Resource
   @Named(LoadBalancerConstants.LOADBALANCER_LOGGER)
   protected Logger logger = Logger.NULL;

   protected final SLBApi api;
   protected final LoadBalancerServiceAdapter<LoadBalancerMetadata, Location> adapter;

   @Inject
   public SLBLoadBalanceNodesStrategy (
         LoadBalancerServiceAdapter<LoadBalancerMetadata, Location> adapter,
         SLBApi api) {
      this.adapter = adapter;
      this.api = api;
   }

   @Override
   public LoadBalancerMetadata createLoadBalancerInLocation(
         Location location,
         String name,
         String protocol,
         int loadBalancerPort,
         int instancePort,
         Iterable<? extends NodeMetadata> nodes) {
      IAcsClient client = api.getAcsClient(location.getId());
      LoadBalancerMetadata lbm = adapter
            .createLoadBalancerInLocation(location, name, protocol, loadBalancerPort, instancePort, nodes);
      String loadBalancerId = lbm.getId();
      if (SLBLoadBalancerProtocol.HTTP.name().equalsIgnoreCase(protocol)) {