// 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/functions/LoadBalancerToLoadBalancerMetadata.java
// public class LoadBalancerToLoadBalancerMetadata implements Function<LoadBalancer, LoadBalancerMetadata> {
// 
//    @Resource
//    @Named(LoadBalancerConstants.LOADBALANCER_LOGGER)
//    protected Logger logger = Logger.NULL;
// 
//    protected final IAcsClient client;
//    protected final Map<String, LoadBalancerType> loadBalancerTypes;
// 
//    public LoadBalancerToLoadBalancerMetadata(
//          IAcsClient client,
//          Map<String, LoadBalancerType> loadBalancerTypes) {
//       this.client = client;
//       this.loadBalancerTypes = loadBalancerTypes;
//    }
// 
//    @Override
//    public LoadBalancerMetadata apply(LoadBalancer input) {
//       DescribeLoadBalancerAttributeRequest req = new DescribeLoadBalancerAttributeRequest();
//       req.setLoadBalancerId(input.getLoadBalancerId());
//       DescribeLoadBalancerAttributeResponse resp = null;
//       try {
//          resp = client.getAcsResponse(req);
//       } catch (Exception e) {
//          logger.warn(e.getMessage());
//       }
//       LocationBuilder location = new LocationBuilder()
//             .scope(LocationScope.REGION)
//             .id(resp.getRegionId())
//             .description(resp.getRegionId());
//       return new LoadBalancerMetadataImpl(
//             loadBalancerTypes.get(resp.getAddressType()),
//             input.getLoadBalancerId(),
//             input.getLoadBalancerName(),
//             input.getLoadBalancerId(),
//             location.build(),
//             null,
//             ImmutableMap.<String, String>builder().build(),
//             ImmutableSet.<String> builder().add(resp.getAddress()).build());
//    }
// }
// 
// Path: aliyun-slb/src/main/java/org/jclouds/aliyun/slb/loadbalancer/functions/RegionToLocation.java
// public class RegionToLocation implements Function<String, Location> {
// 
//    @Override
//    public Location apply(String input) {
//       LocationBuilder builder = new LocationBuilder();
//       builder.scope(LocationScope.REGION);
//       builder.id(input);
//       builder.description(input);
//       return builder.build();
//    }
// }


import static com.google.common.collect.Iterables.transform;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.aliyun.slb.SLBApi;
import org.jclouds.aliyun.slb.loadbalancer.functions.LoadBalancerToLoadBalancerMetadata;
import org.jclouds.aliyun.slb.loadbalancer.functions.RegionToLocation;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.loadbalancer.LoadBalancerServiceAdapter;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.domain.LoadBalancerType;
import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl;
import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.logging.Logger;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerRequest;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerResponse;
import com.aliyuncs.slb.model.v20140515.DeleteLoadBalancerRequest;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancerAttributeRequest;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancerAttributeResponse;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancersRequest;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancersResponse.LoadBalancer;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
               location.build(),
               null,
               ImmutableMap.<String, String>builder().build(),
               ImmutableSet.<String> builder().add(resp.getAddress()).build());
      } catch (Exception e) {
         logger.warn(e.getMessage());
      }
      return lbm;
   }

   @Override
   public void destroyLoadBalancer(String id) {
      IAcsClient client = api.getAcsClient(SLBApi.DEFAULT_REGION);
      DeleteLoadBalancerRequest req = new DeleteLoadBalancerRequest();
      req.setLoadBalancerId(id);
      try {
         client.getAcsResponse(req);
      } catch (Exception e) {
         logger.warn(e.getMessage());
      }
   }

   @Override
   public Iterable<LoadBalancerMetadata> listLoadBalancers() {
      Builder<LoadBalancerMetadata> builder = ImmutableSet.builder();
      for (String region : api.getAvailableRegions()) {
         IAcsClient client = api.getAcsClient(region);
         DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest();
         try {
            List<LoadBalancer> list = client.getAcsResponse(req).getLoadBalancers();
// 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/functions/LoadBalancerToLoadBalancerMetadata.java
// public class LoadBalancerToLoadBalancerMetadata implements Function<LoadBalancer, LoadBalancerMetadata> {
// 
//    @Resource
//    @Named(LoadBalancerConstants.LOADBALANCER_LOGGER)
//    protected Logger logger = Logger.NULL;
// 
//    protected final IAcsClient client;
//    protected final Map<String, LoadBalancerType> loadBalancerTypes;
// 
//    public LoadBalancerToLoadBalancerMetadata(
//          IAcsClient client,
//          Map<String, LoadBalancerType> loadBalancerTypes) {
//       this.client = client;
//       this.loadBalancerTypes = loadBalancerTypes;
//    }
// 
//    @Override
//    public LoadBalancerMetadata apply(LoadBalancer input) {
//       DescribeLoadBalancerAttributeRequest req = new DescribeLoadBalancerAttributeRequest();
//       req.setLoadBalancerId(input.getLoadBalancerId());
//       DescribeLoadBalancerAttributeResponse resp = null;
//       try {
//          resp = client.getAcsResponse(req);
//       } catch (Exception e) {
//          logger.warn(e.getMessage());
//       }
//       LocationBuilder location = new LocationBuilder()
//             .scope(LocationScope.REGION)
//             .id(resp.getRegionId())
//             .description(resp.getRegionId());
//       return new LoadBalancerMetadataImpl(
//             loadBalancerTypes.get(resp.getAddressType()),
//             input.getLoadBalancerId(),
//             input.getLoadBalancerName(),
//             input.getLoadBalancerId(),
//             location.build(),
//             null,
//             ImmutableMap.<String, String>builder().build(),
//             ImmutableSet.<String> builder().add(resp.getAddress()).build());
//    }
// }
// 
// Path: aliyun-slb/src/main/java/org/jclouds/aliyun/slb/loadbalancer/functions/RegionToLocation.java
// public class RegionToLocation implements Function<String, Location> {
// 
//    @Override
//    public Location apply(String input) {
//       LocationBuilder builder = new LocationBuilder();
//       builder.scope(LocationScope.REGION);
//       builder.id(input);
//       builder.description(input);
//       return builder.build();
//    }
// }


// Path: aliyun-slb/src/main/java/org/jclouds/aliyun/slb/loadbalancer/SLBLoadBalancerServiceAdapter.java
import static com.google.common.collect.Iterables.transform;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.aliyun.slb.SLBApi;
import org.jclouds.aliyun.slb.loadbalancer.functions.LoadBalancerToLoadBalancerMetadata;
import org.jclouds.aliyun.slb.loadbalancer.functions.RegionToLocation;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.loadbalancer.LoadBalancerServiceAdapter;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.domain.LoadBalancerType;
import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl;
import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.logging.Logger;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerRequest;
import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerResponse;
import com.aliyuncs.slb.model.v20140515.DeleteLoadBalancerRequest;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancerAttributeRequest;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancerAttributeResponse;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancersRequest;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancersResponse.LoadBalancer;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;

               location.build(),
               null,
               ImmutableMap.<String, String>builder().build(),
               ImmutableSet.<String> builder().add(resp.getAddress()).build());
      } catch (Exception e) {
         logger.warn(e.getMessage());
      }
      return lbm;
   }

   @Override
   public void destroyLoadBalancer(String id) {
      IAcsClient client = api.getAcsClient(SLBApi.DEFAULT_REGION);
      DeleteLoadBalancerRequest req = new DeleteLoadBalancerRequest();
      req.setLoadBalancerId(id);
      try {
         client.getAcsResponse(req);
      } catch (Exception e) {
         logger.warn(e.getMessage());
      }
   }

   @Override
   public Iterable<LoadBalancerMetadata> listLoadBalancers() {
      Builder<LoadBalancerMetadata> builder = ImmutableSet.builder();
      for (String region : api.getAvailableRegions()) {
         IAcsClient client = api.getAcsClient(region);
         DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest();
         try {
            List<LoadBalancer> list = client.getAcsResponse(req).getLoadBalancers();
            builder.addAll(transform(list, new LoadBalancerToLoadBalancerMetadata(client, loadBalancerTypes)));