Java 类com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingClient 实例源码

项目:primecloud-controller    文件:AmazonAwsClientFactory.java   
/**
 * {@inheritDoc}
 */
@Override
public AmazonElasticLoadBalancing createElbClient(String awsAccessId, String awsSecretKey) {
    AWSCredentials credentials = new BasicAWSCredentials(awsAccessId, awsSecretKey);
    ClientConfiguration configuration = createConfiguration();

    AmazonElasticLoadBalancing client = new AmazonElasticLoadBalancingClient(credentials, configuration);

    if (host != null) {
        client.setEndpoint(AmazonElasticLoadBalancing.ENDPOINT_PREFIX + "." + host);
    }

    client = new ExceptionHandleAwsClientWrapper().wrap(client);

    return client;
}
项目:sequenceiq-samples    文件:SimpleAutoScalingService.java   
private RegisterInstancesWithLoadBalancerResult registerInstancesToLoadBalancer(AmazonElasticLoadBalancingClient client, AmazonEC2Client simpleClient,
                                                                                String lbName) {
    List<Instance> instances = new ArrayList<>();
    for (Reservation reservation : simpleClient.describeInstances().getReservations()) {
        instances.addAll(reservation.getInstances());
    }
    List<com.amazonaws.services.elasticloadbalancing.model.Instance> instanceId = new ArrayList<>();
    List<String> instanceIdString = new ArrayList<>();
    for (Instance instance : instances) {
        instanceId.add(new com.amazonaws.services.elasticloadbalancing.model.Instance(instance.getInstanceId()));
        instanceIdString.add(instance.getInstanceId());
    }
    RegisterInstancesWithLoadBalancerRequest register = new RegisterInstancesWithLoadBalancerRequest();
    register.setLoadBalancerName(lbName);
    register.setInstances(instanceId);
    return client.registerInstancesWithLoadBalancer(register);
}
项目:vertx-deploy-tools    文件:AwsAutoScalingDeployUtils.java   
public AwsAutoScalingDeployUtils(String region, DeployConfiguration activeConfiguration, Log log) {
    this.activeConfiguration = activeConfiguration;
    this.log = log;

    Region awsRegion = Region.getRegion(Regions.fromName(region));
    awsAsClient = new AmazonAutoScalingClient();
    awsAsClient.setRegion(awsRegion);

    awsElbClient = new AmazonElasticLoadBalancingClient();
    awsElbClient.setRegion(awsRegion);

    awsEc2Client = new AmazonEC2Client();
    awsEc2Client.setRegion(awsRegion);

    activeConfiguration.withAutoScalingGroup(matchAutoScalingGroupName(activeConfiguration.getAutoScalingGroupId()));

}
项目:Baragon    文件:BaragonServiceModule.java   
@Provides
@Named(BARAGON_AWS_ELB_CLIENT_V2)
public com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClient providesAwsElbClientV2(Optional<ElbConfiguration> configuration) {
  com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClient elbClient;
  if (configuration.isPresent() && configuration.get().getAwsAccessKeyId() != null && configuration.get().getAwsAccessKeySecret() != null) {
    elbClient = new com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClient(new BasicAWSCredentials(configuration.get().getAwsAccessKeyId(), configuration.get().getAwsAccessKeySecret()));
  } else {
    elbClient = new com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClient();
  }

  if (configuration.isPresent() && configuration.get().getAwsEndpoint().isPresent()) {
    elbClient.setEndpoint(configuration.get().getAwsEndpoint().get());
  }
  if (configuration.isPresent() && configuration.get().getAwsRegion().isPresent()) {
    elbClient.configureRegion(Regions.fromName(configuration.get().getAwsRegion().get()));
  }

  return elbClient;
}
项目:bluegreen-manager    文件:AwsClientFactory.java   
/**
 * Constructs an AmazonElasticLoadBalancingClient and sets the region.
 */
public AmazonElasticLoadBalancingClient makeRegionalElbClient()
{
  AWSCredentials credentials = new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey);
  AmazonElasticLoadBalancingClient elb = new AmazonElasticLoadBalancingClient(credentials);
  elb.setRegion(awsRegion);
  return elb;
}
项目:bluegreen-manager    文件:AwsClientFactoryTest.java   
/**
 * Tests that we can make an elb client.
 */
@Test
public void testMakeRegionalELBClient()
{
  AmazonElasticLoadBalancingClient elb = awsClientFactory.makeRegionalElbClient();
  assertEquals(ServiceAbbreviations.ElasticLoadbalancing, elb.getServiceName());
}
项目:fullstop    文件:FetchElasticLoadBalancersJob.java   
private Map<String, List<Tag>> getElbTags(AmazonElasticLoadBalancingClient elbClient, List<String> elbNames) {
    if (isEmpty(elbNames)) {
        return emptyMap();
    } else {
        final Map<String, List<Tag>> result = newHashMapWithExpectedSize(elbNames.size());
        // http://docs.aws.amazon.com/elasticloadbalancing/2012-06-01/APIReference/API_DescribeTags.html
        // describeTags expects a maximum of 20 load balancer names per call
        for (List<String> elbNamePartition : partition(elbNames, ELB_NAMES_MAX_SIZE)) {
            elbClient.describeTags(new DescribeTagsRequest().withLoadBalancerNames(elbNamePartition))
                    .getTagDescriptions()
                    .forEach(tagDescription -> result.put(tagDescription.getLoadBalancerName(), tagDescription.getTags()));
        }
        return result;
    }
}
项目:chassis    文件:ServerInstanceContext.java   
private ServerInstanceContext(){
    amazonElasticLoadBalancing = new AmazonElasticLoadBalancingClient();
    amazonEC2 = new AmazonEC2Client();

    ec2MetadataClient = new Ec2MetadataClient() {
        @Override
        public String getAvailabilityZone() {
            return EC2MetadataUtils.getAvailabilityZone();
        }

        @Override
        public String getInstanceId() {
            return EC2MetadataUtils.getInstanceId();
        }

        @Override
        public String getUserData() {
            return EC2MetadataUtils.getUserData();
        }

        @Override
        public String getPrivateIpAddress() {
            return EC2MetadataUtils.getPrivateIpAddress();
        }

        @Override
        public String getPublicIpAddress() {
            for (EC2MetadataUtils.NetworkInterface net : EC2MetadataUtils.getNetworkInterfaces()) {
                List<String> ips = net.getPublicIPv4s();
                if (ips != null && ips.size() > 0) {
                    return ips.get(0);
                }
            }
            return null;
        }
    };

    init();
}
项目:sequenceiq-samples    文件:SimpleAutoScalingService.java   
private CreateLoadBalancerResult createLoadBalancer(AmazonElasticLoadBalancingClient client, String name, String... zones) {
    CreateLoadBalancerRequest lbRequest = new CreateLoadBalancerRequest();
    lbRequest.setLoadBalancerName(name);
    lbRequest.withAvailabilityZones(zones);
    lbRequest.setListeners(Arrays.asList(new Listener("HTTP", 80, 80)));
    return client.createLoadBalancer(lbRequest);
}
项目:clouck    文件:ElbWrapperImpl.java   
private AmazonElasticLoadBalancing findClient(Account account, Region region) {
    // TODO: need to config client config parameter. ignore it for now.
    // TODO: need a cached version based on account and region as key
    AWSCredentials credential = new BasicAWSCredentials(account.getAccessKeyId(), account.getSecretAccessKey());
    AmazonElasticLoadBalancing elb = new AmazonElasticLoadBalancingClient(credential);
    elb.setRegion(com.amazonaws.regions.Region.getRegion(region.getRegions()));
    return elb;
}
项目:Baragon    文件:ClassicLoadBalancer.java   
@Inject
public ClassicLoadBalancer(Optional<ElbConfiguration> configuration,
                           BaragonExceptionNotifier exceptionNotifier,
                           BaragonLoadBalancerDatastore loadBalancerDatastore,
                           BaragonKnownAgentsDatastore knownAgentsDatastore,
                           @Named(BaragonServiceModule.BARAGON_AWS_ELB_CLIENT_V1) AmazonElasticLoadBalancingClient elbClient) {
  super(configuration, exceptionNotifier, loadBalancerDatastore, knownAgentsDatastore);
  this.elbClient = elbClient;
}
项目:bluegreen-manager    文件:ElbClient.java   
public ElbClient(AmazonElasticLoadBalancingClient awsElbClient)
{
  this.awsElbClient = awsElbClient;
}
项目:AWSConfig    文件:EC2UtilsImpl.java   
/**
 * Default constructor.
 */
public EC2UtilsImpl() {
    this.amazonEc2 = new AmazonEC2Client();
    this.amazonElasticLoadBalancing = new AmazonElasticLoadBalancingClient();
}
项目:AWSConfig    文件:EC2UtilsImpl.java   
/**
 * Parameterized constructor. Pass the AWS Region as parameter.
 * @param region 
 */
public EC2UtilsImpl(Regions region) {
    this.amazonEc2 = new AmazonEC2Client();
    this.amazonElasticLoadBalancing = new AmazonElasticLoadBalancingClient();
}
项目:fullstop    文件:FetchElasticLoadBalancersJobTest.java   
@Before
public void setUp() throws Exception {
    this.violationSinkMock = mock(ViolationSink.class);
    this.clientProviderMock = mock(ClientProvider.class);
    this.accountIdSupplierMock = mock(AccountIdSupplier.class);
    this.jobsPropertiesMock = mock(JobsProperties.class);
    this.portsChecker = mock(PortsChecker.class);
    this.securityGroupsChecker = mock(SecurityGroupsChecker.class);
    this.mockAwsELBClient = mock(AmazonElasticLoadBalancingClient.class);
    this.mockAwsApplications = mock(AwsApplications.class);
    this.mockViolationService = mock(ViolationService.class);
    this.fetchTaupageYamlMock = mock(FetchTaupageYaml.class);
    this.mockAmiDetailsProvider = mock(AmiDetailsProvider.class);
    this.mockEC2InstanceProvider = mock(EC2InstanceProvider.class);

    final Listener listener = new Listener("HTTPS", 80, 80);

    final ListenerDescription listenerDescription = new ListenerDescription();
    listenerDescription.setListener(listener);

    final ArrayList<LoadBalancerDescription> elbs = newArrayList();
    final ArrayList<TagDescription> tagDescriptions = newArrayList();

    final LoadBalancerDescription publicELB = new LoadBalancerDescription();
    publicELB.setScheme("internet-facing");
    publicELB.setListenerDescriptions(newArrayList(listenerDescription));
    publicELB.setCanonicalHostedZoneName("test.com");
    publicELB.setInstances(asList(new Instance("i1"), new Instance("i2")));
    publicELB.setLoadBalancerName("publicELB");
    elbs.add(publicELB);
    tagDescriptions.add(
            new TagDescription()
                    .withLoadBalancerName("publicELB")
                    .withTags(newArrayList(
                            new Tag().withKey("someTag").withValue("someValue"))));

    final LoadBalancerDescription privateELB = new LoadBalancerDescription();
    privateELB.setScheme("internal");
    privateELB.setCanonicalHostedZoneName("internal.org");
    privateELB.setLoadBalancerName("privateELB");
    elbs.add(privateELB);

    for (int i = 1; i <= 20; i++) {
        final String loadBalancerName = "kubeELB" + i;
        final LoadBalancerDescription kubeELB = new LoadBalancerDescription();
        kubeELB.setScheme("internet-facing");
        kubeELB.setCanonicalHostedZoneName("test" + i + ".com");
        kubeELB.setLoadBalancerName(loadBalancerName);
        elbs.add(kubeELB);

        tagDescriptions.add(
                new TagDescription()
                        .withLoadBalancerName(loadBalancerName)
                        .withTags(newArrayList(
                                new Tag().withKey("someTag").withValue("someValue"),
                                new Tag().withKey("kubernetes.io/cluster/").withValue("owned"))));
    }

    mockDescribeELBResult = new DescribeLoadBalancersResult();
    mockDescribeELBResult.setLoadBalancerDescriptions(elbs);

    mockDescribeTagsResult = new DescribeTagsResult();
    mockDescribeTagsResult.setTagDescriptions(tagDescriptions);

    regions.add(REGION1);

    when(clientProviderMock.getClient(any(), any(String.class), any(Region.class))).thenReturn(mockAwsELBClient);

    when(mockEC2InstanceProvider.getById(anyString(), any(Region.class), anyString()))
            .thenReturn(Optional.of(new com.amazonaws.services.ec2.model.Instance().withInstanceId("foo").withImageId("bar")));
    when(mockAmiDetailsProvider.getAmiDetails(anyString(), any(Region.class), anyString()))
            .thenReturn(ImmutableMap.of("ami_id", "bar"));
}
项目:gravity    文件:AwsAutomationAction.java   
public AmazonElasticLoadBalancingClient getLoadBalanceClient() {
    return loadBalanceClient;
}
项目:gravity    文件:AwsAutomationAction.java   
public void setLoadBalanceClient(AmazonElasticLoadBalancingClient loadBalanceClient) {
    this.loadBalanceClient = loadBalanceClient;
}
项目:sequenceiq-samples    文件:AmazonElasticLoadBalancingClientFactory.java   
public AmazonElasticLoadBalancingClient createAmazonElasticLoadBalancingClient(AWSCredentials crendentials) {
    AmazonElasticLoadBalancingClient amazonEC2Client = new AmazonElasticLoadBalancingClient(new SimpleAWSCredentialsProvider(crendentials));
    amazonEC2Client.setRegion(region);
    return amazonEC2Client;
}
项目:Baragon    文件:ElbResource.java   
@Inject
public ElbResource(@Named(BaragonServiceModule.BARAGON_AWS_ELB_CLIENT_V1) AmazonElasticLoadBalancingClient elbClient,
                   Optional<ElbConfiguration> config) {
  this.elbClient = elbClient;
  this.config = config;
}