use of com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription 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.TargetDescription 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.TargetDescription 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;
}
use of com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method removeLoadBalancerTargets.
public void removeLoadBalancerTargets(AuthenticatedContext ac, CloudLoadBalancer loadBalancer, List<CloudResource> resourcesToRemove) {
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 instance ids to remove
Set<String> instancesToRemove = getInstanceIdsForGroups(resourcesToRemove, entry.getValue());
// Find target group ARN
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(loadBalancer.getType());
String targetGroupArn = getResourceArnByLogicalId(ac, AwsTargetGroup.getTargetGroupName(entry.getKey().getTrafficPort(), scheme), region);
// Deregister any instances that no longer exist
if (!instancesToRemove.isEmpty()) {
try {
List<TargetDescription> targetsToRemove = instancesToRemove.stream().map(instanceId -> new TargetDescription().withId(instanceId)).collect(Collectors.toList());
DeregisterTargetsResult deregisterTargetsResult = amazonElbClient.deregisterTargets(new DeregisterTargetsRequest().withTargetGroupArn(targetGroupArn).withTargets(targetsToRemove));
} catch (InvalidTargetException ignored) {
// no-op - we tried to remove a target that wasn't in the target group, which is fine
}
}
}
}
Aggregations