use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project druid by druid-io.
the class EC2AutoScaler method idToIpLookup.
@Override
public List<String> idToIpLookup(List<String> nodeIds) {
final List<String> retVal = FluentIterable.from(Lists.partition(nodeIds, MAX_AWS_FILTER_VALUES)).transformAndConcat(new Function<List<String>, Iterable<Reservation>>() {
@Override
public Iterable<Reservation> apply(List<String> input) {
return amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("instance-id", input))).getReservations();
}
}).transformAndConcat(new Function<Reservation, Iterable<Instance>>() {
@Override
public Iterable<Instance> apply(Reservation reservation) {
return reservation.getInstances();
}
}).transform(new Function<Instance, String>() {
@Override
public String apply(Instance instance) {
return instance.getPrivateIpAddress();
}
}).toList();
log.debug("Performing lookup: %s --> %s", nodeIds, retVal);
return retVal;
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project ignite-extensions by apache.
the class TcpDiscoveryElbIpFinder method getRegisteredAddresses.
/**
* {@inheritDoc}
*/
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
initClients();
List<String> instanceIds = new ArrayList<>();
DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest().withLoadBalancerNames(loadBalancerName);
List<LoadBalancerDescription> descs = amazonELBClient.describeLoadBalancers(req).getLoadBalancerDescriptions();
for (LoadBalancerDescription desc : descs) {
for (Instance instance : desc.getInstances()) instanceIds.add(instance.getInstanceId());
}
DescribeInstancesRequest instReq = new DescribeInstancesRequest().withInstanceIds(instanceIds);
List<Reservation> reservations = amazonEC2Client.describeInstances(instReq).getReservations();
List<InetSocketAddress> addrs = new ArrayList<>();
for (Reservation reservation : reservations) {
List<com.amazonaws.services.ec2.model.Instance> instances = reservation.getInstances();
for (com.amazonaws.services.ec2.model.Instance instance : instances) addrs.add(new InetSocketAddress(instance.getPrivateIpAddress(), 0));
}
return addrs;
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project cloud-pipeline by epam.
the class EC2Helper method stopInstance.
public void stopInstance(String instanceId, String awsRegion) {
AmazonEC2 client = getEC2Client(awsRegion);
StopInstancesRequest stopInstancesRequest = new StopInstancesRequest().withInstanceIds(instanceId);
client.stopInstances(stopInstancesRequest);
Waiter<DescribeInstancesRequest> waiter = client.waiters().instanceStopped();
waiter.run(new WaiterParameters<>(new DescribeInstancesRequest().withInstanceIds(instanceId)));
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project cloud-pipeline by epam.
the class EC2Helper method startInstance.
public void startInstance(String instanceId, String awsRegion) {
AmazonEC2 client = getEC2Client(awsRegion);
StartInstancesRequest startInstancesRequest = new StartInstancesRequest().withInstanceIds(instanceId);
client.startInstances(startInstancesRequest);
Waiter<DescribeInstancesRequest> waiter = client.waiters().instanceRunning();
waiter.run(new WaiterParameters<>(new DescribeInstancesRequest().withInstanceIds(instanceId)));
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project druid by druid-io.
the class EC2AutoScaler method terminate.
@Override
public AutoScalingData terminate(List<String> ips) {
if (ips.isEmpty()) {
return new AutoScalingData(Lists.<String>newArrayList());
}
DescribeInstancesResult result = amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("private-ip-address", ips)));
List<Instance> instances = Lists.newArrayList();
for (Reservation reservation : result.getReservations()) {
instances.addAll(reservation.getInstances());
}
try {
return terminateWithIds(Lists.transform(instances, new Function<Instance, String>() {
@Override
public String apply(Instance input) {
return input.getInstanceId();
}
}));
} catch (Exception e) {
log.error(e, "Unable to terminate any instances.");
}
return null;
}
Aggregations