use of com.amazonaws.services.elasticloadbalancingv2.model.TargetHealthDescription in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method addLoadBalancerTargets.
public void addLoadBalancerTargets(AuthenticatedContext ac, CloudLoadBalancer loadBalancer, List<CloudResource> resourcesToAdd) {
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonElasticLoadBalancingClient amazonElbClient = awsClient.createElasticLoadBalancingClient(new AwsCredentialView(ac.getCloudCredential()), region);
for (Map.Entry<TargetGroupPortPair, Set<Group>> entry : loadBalancer.getPortToTargetGroupMapping().entrySet()) {
// Get a list of the new instances in the target groups
Set<String> updatedInstanceIds = getInstanceIdsForGroups(resourcesToAdd, entry.getValue());
// Find target group ARN
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(loadBalancer.getType());
String targetGroupArn = getResourceArnByLogicalId(ac, AwsTargetGroup.getTargetGroupName(entry.getKey().getTrafficPort(), scheme), region);
// Use ARN to fetch a list of current targets
DescribeTargetHealthResult targetHealthResult = amazonElbClient.describeTargetHealth(new DescribeTargetHealthRequest().withTargetGroupArn(targetGroupArn));
List<TargetDescription> targetDescriptions = targetHealthResult.getTargetHealthDescriptions().stream().map(TargetHealthDescription::getTarget).collect(Collectors.toList());
Set<String> alreadyRegisteredInstanceIds = targetDescriptions.stream().map(TargetDescription::getId).collect(Collectors.toSet());
// Remove any targets that have already been registered from the list being processed
updatedInstanceIds.removeAll(alreadyRegisteredInstanceIds);
// Register any new instances
if (!updatedInstanceIds.isEmpty()) {
List<TargetDescription> targetsToAdd = updatedInstanceIds.stream().map(instanceId -> new TargetDescription().withId(instanceId)).collect(Collectors.toList());
RegisterTargetsResult registerTargetsResult = amazonElbClient.registerTargets(new RegisterTargetsRequest().withTargetGroupArn(targetGroupArn).withTargets(targetsToAdd));
}
}
}
use of com.amazonaws.services.elasticloadbalancingv2.model.TargetHealthDescription in project datarouter by hotpads.
the class ElbService method getTargetEc2InstancesId.
public List<String> getTargetEc2InstancesId(String targetGroupArn) {
var request = new DescribeTargetHealthRequest().withTargetGroupArn(targetGroupArn);
int randomSleepMs = RandomTool.getRandomIntBetweenTwoNumbers(0, 3_000);
return RetryableTool.tryNTimesWithBackoffAndRandomInitialDelayUnchecked(() -> amazonElasticLoadBalancing.get().describeTargetHealth(request).getTargetHealthDescriptions().stream().map(TargetHealthDescription::getTarget).map(TargetDescription::getId).collect(Collectors.toList()), NUM_ATTEMPTS, randomSleepMs, true);
}
use of com.amazonaws.services.elasticloadbalancingv2.model.TargetHealthDescription in project gridgain by gridgain.
the class TcpDiscoveryAlbIpFinder method getRegisteredAddresses.
/**
* {@inheritDoc}
*/
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
initClients();
DescribeTargetHealthRequest req = new DescribeTargetHealthRequest().withTargetGroupArn(targetGrpARN);
List<TargetHealthDescription> desc = amazonELBClient.describeTargetHealth(req).getTargetHealthDescriptions();
// instance ips
List<String> instanceIps = new LinkedList<>();
// instance ids
List<String> instanceIds = new LinkedList<>();
// Fetch the ids of instances in the given ARN via target health
for (TargetHealthDescription targetHealthDesc : desc) {
TargetDescription target = targetHealthDesc.getTarget();
String targetId = target.getId();
// divide the target ids into ips and instance ids
if (isIPAddress(targetId))
instanceIps.add(targetId);
else
instanceIds.add(targetId);
}
DescribeInstancesRequest descInstReq = new DescribeInstancesRequest().withInstanceIds(instanceIds);
List<Reservation> reservations = amazonEC2Client.describeInstances(descInstReq).getReservations();
// Convert instance ids to instance ips
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
String ip = instance.getPrivateIpAddress();
instanceIps.add(ip);
}
}
List<InetSocketAddress> addrs = new LinkedList<>();
for (String ip : instanceIps) {
InetSocketAddress addr = new InetSocketAddress(ip, 0);
addrs.add(addr);
}
return addrs;
}
use of com.amazonaws.services.elasticloadbalancingv2.model.TargetHealthDescription in project ignite-extensions by apache.
the class TcpDiscoveryAlbIpFinder method getRegisteredAddresses.
/**
* {@inheritDoc}
*/
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
initClients();
DescribeTargetHealthRequest req = new DescribeTargetHealthRequest().withTargetGroupArn(targetGrpARN);
List<TargetHealthDescription> desc = amazonELBClient.describeTargetHealth(req).getTargetHealthDescriptions();
// instance ips
List<String> instanceIps = new LinkedList<>();
// instance ids
List<String> instanceIds = new LinkedList<>();
// Fetch the ids of instances in the given ARN via target health
for (TargetHealthDescription targetHealthDesc : desc) {
TargetDescription target = targetHealthDesc.getTarget();
String targetId = target.getId();
// divide the target ids into ips and instance ids
if (isIPAddress(targetId))
instanceIps.add(targetId);
else
instanceIds.add(targetId);
}
DescribeInstancesRequest descInstReq = new DescribeInstancesRequest().withInstanceIds(instanceIds);
List<Reservation> reservations = amazonEC2Client.describeInstances(descInstReq).getReservations();
// Convert instance ids to instance ips
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
String ip = instance.getPrivateIpAddress();
instanceIps.add(ip);
}
}
List<InetSocketAddress> addrs = new LinkedList<>();
for (String ip : instanceIps) {
InetSocketAddress addr = new InetSocketAddress(ip, 0);
addrs.add(addr);
}
return addrs;
}
Aggregations