/** * {@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; }
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); }
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())); }
@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; }
/** * 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; }
/** * Tests that we can make an elb client. */ @Test public void testMakeRegionalELBClient() { AmazonElasticLoadBalancingClient elb = awsClientFactory.makeRegionalElbClient(); assertEquals(ServiceAbbreviations.ElasticLoadbalancing, elb.getServiceName()); }
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; } }
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(); }
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); }
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; }
@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; }
public ElbClient(AmazonElasticLoadBalancingClient awsElbClient) { this.awsElbClient = awsElbClient; }
/** * Default constructor. */ public EC2UtilsImpl() { this.amazonEc2 = new AmazonEC2Client(); this.amazonElasticLoadBalancing = new AmazonElasticLoadBalancingClient(); }
/** * Parameterized constructor. Pass the AWS Region as parameter. * @param region */ public EC2UtilsImpl(Regions region) { this.amazonEc2 = new AmazonEC2Client(); this.amazonElasticLoadBalancing = new AmazonElasticLoadBalancingClient(); }
@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")); }
public AmazonElasticLoadBalancingClient getLoadBalanceClient() { return loadBalanceClient; }
public void setLoadBalanceClient(AmazonElasticLoadBalancingClient loadBalanceClient) { this.loadBalanceClient = loadBalanceClient; }
public AmazonElasticLoadBalancingClient createAmazonElasticLoadBalancingClient(AWSCredentials crendentials) { AmazonElasticLoadBalancingClient amazonEC2Client = new AmazonElasticLoadBalancingClient(new SimpleAWSCredentialsProvider(crendentials)); amazonEC2Client.setRegion(region); return amazonEC2Client; }
@Inject public ElbResource(@Named(BaragonServiceModule.BARAGON_AWS_ELB_CLIENT_V1) AmazonElasticLoadBalancingClient elbClient, Optional<ElbConfiguration> config) { this.elbClient = elbClient; this.config = config; }