All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jclouds.aliyun.slb.loadbalancer.functions.LoadBalancerToLoadBalancerMetadata Maven / Gradle / Ivy

The newest version!
package org.jclouds.aliyun.slb.loadbalancer.functions;

import java.util.Map;

import javax.annotation.Resource;
import javax.inject.Named;

import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
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.DescribeLoadBalancerAttributeRequest;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancerAttributeResponse;
import com.aliyuncs.slb.model.v20140515.DescribeLoadBalancersResponse.LoadBalancer;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

public class LoadBalancerToLoadBalancerMetadata implements Function {

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

   protected final IAcsClient client;
   protected final Map loadBalancerTypes;

   public LoadBalancerToLoadBalancerMetadata(
         IAcsClient client,
         Map 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.builder().build(),
            ImmutableSet. builder().add(resp.getAddress()).build());
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy