Search in sources :

Example 6 with DescribeInstancesRequest

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;
}
Also used : Function(com.google.common.base.Function) Reservation(com.amazonaws.services.ec2.model.Reservation) FluentIterable(com.google.common.collect.FluentIterable) Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) List(java.util.List) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 7 with DescribeInstancesRequest

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;
}
Also used : Instance(com.amazonaws.services.elasticloadbalancing.model.Instance) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) Reservation(com.amazonaws.services.ec2.model.Reservation) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)

Example 8 with DescribeInstancesRequest

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)));
}
Also used : StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 9 with DescribeInstancesRequest

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)));
}
Also used : StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 10 with DescribeInstancesRequest

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;
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Function(com.google.common.base.Function) Reservation(com.amazonaws.services.ec2.model.Reservation) AutoScalingData(io.druid.indexing.overlord.autoscaling.AutoScalingData) Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Aggregations

DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)74 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)49 Reservation (com.amazonaws.services.ec2.model.Reservation)47 Instance (com.amazonaws.services.ec2.model.Instance)42 ArrayList (java.util.ArrayList)40 Filter (com.amazonaws.services.ec2.model.Filter)29 List (java.util.List)28 Map (java.util.Map)18 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)17 Collectors (java.util.stream.Collectors)17 Tag (com.amazonaws.services.ec2.model.Tag)13 Inject (javax.inject.Inject)13 Set (java.util.Set)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 TerminateInstancesRequest (com.amazonaws.services.ec2.model.TerminateInstancesRequest)11 TerminateInstancesResult (com.amazonaws.services.ec2.model.TerminateInstancesResult)11 Collection (java.util.Collection)11 DescribeVolumesResult (com.amazonaws.services.ec2.model.DescribeVolumesResult)10 StopInstancesRequest (com.amazonaws.services.ec2.model.StopInstancesRequest)10