Search in sources :

Example 31 with Reservation

use of software.amazon.awssdk.services.ec2.model.Reservation in project camel by apache.

the class AmazonEC2ClientMock method describeInstances.

@Override
public DescribeInstancesResult describeInstances(DescribeInstancesRequest describeInstancesRequest) {
    DescribeInstancesResult result = new DescribeInstancesResult();
    if (describeInstancesRequest.getInstanceIds().isEmpty()) {
        Collection<Reservation> list = new ArrayList<Reservation>();
        Reservation res = new Reservation();
        res.setOwnerId("1");
        res.setRequesterId("user-test");
        res.setReservationId("res-1");
        Collection<Instance> instances = new ArrayList();
        Instance ins = new Instance();
        ins.setImageId("id-1");
        ins.setInstanceType(InstanceType.T2Micro);
        ins.setInstanceId("instance-1");
        instances.add(ins);
        Instance ins1 = new Instance();
        ins1.setImageId("id-2");
        ins1.setInstanceType(InstanceType.T2Micro);
        ins1.setInstanceId("instance-2");
        instances.add(ins1);
        res.setInstances(instances);
        list.add(res);
        result.setReservations(list);
    } else {
        if (describeInstancesRequest.getInstanceIds().contains("instance-1")) {
            Collection<Reservation> list = new ArrayList<Reservation>();
            Reservation res = new Reservation();
            res.setOwnerId("1");
            res.setRequesterId("user-test");
            res.setReservationId("res-1");
            Collection<Instance> instances = new ArrayList();
            Instance ins = new Instance();
            ins.setImageId("id-1");
            ins.setInstanceType(InstanceType.T2Micro);
            ins.setInstanceId("instance-1");
            instances.add(ins);
            res.setInstances(instances);
            list.add(res);
            result.setReservations(list);
        }
    }
    return result;
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList)

Example 32 with Reservation

use of software.amazon.awssdk.services.ec2.model.Reservation in project camel by apache.

the class AmazonEC2ClientMock method runInstances.

@Override
public RunInstancesResult runInstances(RunInstancesRequest runInstancesRequest) {
    RunInstancesResult result = new RunInstancesResult();
    if (runInstancesRequest.getImageId().equals("test-1")) {
        Reservation res = new Reservation();
        res.setOwnerId("1");
        res.setRequesterId("user-test");
        res.setReservationId("res-1");
        Collection<Instance> instances = new ArrayList();
        Instance ins = new Instance();
        ins.setImageId(runInstancesRequest.getImageId());
        ins.setInstanceType(runInstancesRequest.getInstanceType());
        ins.setInstanceId("instance-1");
        if (runInstancesRequest.getSecurityGroups() != null) {
            if (runInstancesRequest.getSecurityGroups().contains("secgroup-1") && runInstancesRequest.getSecurityGroups().contains("secgroup-2")) {
                GroupIdentifier id1 = new GroupIdentifier();
                id1.setGroupId("id-1");
                id1.setGroupName("secgroup-1");
                GroupIdentifier id2 = new GroupIdentifier();
                id2.setGroupId("id-2");
                id2.setGroupName("secgroup-2");
                Collection secGroups = new ArrayList<GroupIdentifier>();
                secGroups.add(id1);
                secGroups.add(id2);
                ins.setSecurityGroups(secGroups);
            } else if (ObjectHelper.isNotEmpty(runInstancesRequest.getKeyName())) {
                if (ObjectHelper.isNotEmpty(runInstancesRequest.getKeyName().contains("keypair-1"))) {
                    GroupIdentifier id1 = new GroupIdentifier();
                    id1.setGroupId("id-3");
                    id1.setGroupName("secgroup-3");
                    GroupIdentifier id2 = new GroupIdentifier();
                    id2.setGroupId("id-4");
                    id2.setGroupName("secgroup-4");
                    Collection secGroups = new ArrayList<GroupIdentifier>();
                    secGroups.add(id1);
                    secGroups.add(id2);
                    ins.setSecurityGroups(secGroups);
                }
            }
        }
        instances.add(ins);
        res.setInstances(instances);
        result.setReservation(res);
    } else {
        throw new AmazonServiceException("The image-id doesn't exists");
    }
    return result;
}
Also used : Reservation(com.amazonaws.services.ec2.model.Reservation) Instance(com.amazonaws.services.ec2.model.Instance) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier)

Example 33 with Reservation

use of software.amazon.awssdk.services.ec2.model.Reservation in project ignite 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 34 with Reservation

use of software.amazon.awssdk.services.ec2.model.Reservation in project photon-model by vmware.

the class AWSRemoteCleanup method deleteStaleAwsEc2instances.

/**
 * Delete stale AWS EC2 Instances.
 */
@Test
public void deleteStaleAwsEc2instances() {
    AmazonEC2 usEastEc2Client = this.ec2Clients.get(US_EAST_1_TAG);
    List<String> instanceIdsToBeDeleted = new ArrayList<>();
    DescribeInstancesResult instancesResult = usEastEc2Client.describeInstances();
    List<Reservation> reservations = instancesResult.getReservations();
    for (Reservation reservation : reservations) {
        List<Instance> instances = reservation.getInstances();
        for (Instance instance : instances) {
            long instanceLaunchTimeMicros = TimeUnit.MILLISECONDS.toMicros(instance.getLaunchTime().getTime());
            long timeDifference = Utils.getNowMicrosUtc() - instanceLaunchTimeMicros;
            if (timeDifference > TimeUnit.HOURS.toMicros(1) && shouldDelete(instance)) {
                this.host.log(Level.INFO, "Marking %s instance for deletion", instance.getInstanceId());
                instanceIdsToBeDeleted.add(instance.getInstanceId());
            }
        }
    }
    triggerEC2Deletion(instanceIdsToBeDeleted, usEastEc2Client);
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) Test(org.junit.Test)

Example 35 with Reservation

use of software.amazon.awssdk.services.ec2.model.Reservation in project airavata by apache.

the class AmazonUtil method loadInstances.

/**
 * Load instances
 *
 * @return list of instances
 */
public static List<Instance> loadInstances() {
    List<Instance> resultList = new ArrayList<Instance>();
    DescribeInstancesResult describeInstancesResult = getEC2Client().describeInstances();
    List<Reservation> reservations = describeInstancesResult.getReservations();
    for (Iterator<Reservation> iterator = reservations.iterator(); iterator.hasNext(); ) {
        Reservation reservation = iterator.next();
        for (Instance instance : reservation.getInstances()) {
            resultList.add(instance);
        }
    }
    return resultList;
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList)

Aggregations

Reservation (com.amazonaws.services.ec2.model.Reservation)39 Instance (com.amazonaws.services.ec2.model.Instance)35 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)23 ArrayList (java.util.ArrayList)21 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)16 Filter (com.amazonaws.services.ec2.model.Filter)11 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 Test (org.junit.Test)8 Tag (com.amazonaws.services.ec2.model.Tag)7 Function (com.google.common.base.Function)6 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)6 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)6 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)5 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)5 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)5 CreateTagsRequest (com.amazonaws.services.ec2.model.CreateTagsRequest)5 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)5 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)5 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)5 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)5