com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingClient Java Examples
The following examples show how to use
com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmazonAwsClientFactory.java From primecloud-controller with GNU General Public License v2.0 | 6 votes |
/** * {@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; }
Example #2
Source File: SimpleAutoScalingService.java From sequenceiq-samples with Apache License 2.0 | 6 votes |
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); }
Example #3
Source File: BaragonServiceModule.java From Baragon with Apache License 2.0 | 6 votes |
@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; }
Example #4
Source File: FetchElasticLoadBalancersJob.java From fullstop with Apache License 2.0 | 5 votes |
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; } }
Example #5
Source File: ServerInstanceContext.java From chassis with Apache License 2.0 | 5 votes |
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(); }
Example #6
Source File: SimpleAutoScalingService.java From sequenceiq-samples with Apache License 2.0 | 5 votes |
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); }
Example #7
Source File: ClassicLoadBalancer.java From Baragon with Apache License 2.0 | 5 votes |
@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; }
Example #8
Source File: FetchElasticLoadBalancersJobTest.java From fullstop with Apache License 2.0 | 4 votes |
@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")); }
Example #9
Source File: AmazonElasticLoadBalancingClientFactory.java From sequenceiq-samples with Apache License 2.0 | 4 votes |
public AmazonElasticLoadBalancingClient createAmazonElasticLoadBalancingClient(AWSCredentials crendentials) { AmazonElasticLoadBalancingClient amazonEC2Client = new AmazonElasticLoadBalancingClient(new SimpleAWSCredentialsProvider(crendentials)); amazonEC2Client.setRegion(region); return amazonEC2Client; }
Example #10
Source File: ElbResource.java From Baragon with Apache License 2.0 | 4 votes |
@Inject public ElbResource(@Named(BaragonServiceModule.BARAGON_AWS_ELB_CLIENT_V1) AmazonElasticLoadBalancingClient elbClient, Optional<ElbConfiguration> config) { this.elbClient = elbClient; this.config = config; }