Search in sources :

Example 1 with LaunchSpecification

use of com.amazonaws.services.ec2.model.LaunchSpecification in project aws-sdk-android by aws-amplify.

the class EC2RequestHandler method afterResponse.

@Override
public void afterResponse(Request<?> request, Object response, TimingInfo timingInfo) {
    /*
         * For backwards compatibility, we preserve the existing List<String> of
         * security group names by explicitly populating it from the full list
         * of security group info.
         */
    if (response instanceof DescribeSpotInstanceRequestsResult) {
        DescribeSpotInstanceRequestsResult result = (DescribeSpotInstanceRequestsResult) response;
        for (SpotInstanceRequest spotInstanceRequest : result.getSpotInstanceRequests()) {
            LaunchSpecification launchSpecification = spotInstanceRequest.getLaunchSpecification();
            populateLaunchSpecificationSecurityGroupNames(launchSpecification);
        }
    } else if (response instanceof RequestSpotInstancesResult) {
        RequestSpotInstancesResult result = (RequestSpotInstancesResult) response;
        for (SpotInstanceRequest spotInstanceRequest : result.getSpotInstanceRequests()) {
            LaunchSpecification launchSpecification = spotInstanceRequest.getLaunchSpecification();
            populateLaunchSpecificationSecurityGroupNames(launchSpecification);
        }
    } else if (response instanceof DescribeInstancesResult) {
        DescribeInstancesResult result = (DescribeInstancesResult) response;
        for (Reservation reservation : result.getReservations()) {
            populateReservationSecurityGroupNames(reservation);
        }
    } else if (response instanceof RunInstancesResult) {
        RunInstancesResult result = (RunInstancesResult) response;
        populateReservationSecurityGroupNames(result.getReservation());
    }
}
Also used : DescribeSpotInstanceRequestsResult(com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) LaunchSpecification(com.amazonaws.services.ec2.model.LaunchSpecification) RequestSpotInstancesResult(com.amazonaws.services.ec2.model.RequestSpotInstancesResult) SpotInstanceRequest(com.amazonaws.services.ec2.model.SpotInstanceRequest)

Example 2 with LaunchSpecification

use of com.amazonaws.services.ec2.model.LaunchSpecification in project aws-sdk-android by aws-amplify.

the class EC2RequestHandler method populateLaunchSpecificationSecurityGroupNames.

private void populateLaunchSpecificationSecurityGroupNames(LaunchSpecification launchSpecification) {
    List<String> groupNames = new ArrayList<String>();
    for (GroupIdentifier group : launchSpecification.getAllSecurityGroups()) {
        groupNames.add(group.getGroupName());
    }
    launchSpecification.setSecurityGroups(groupNames);
}
Also used : ArrayList(java.util.ArrayList) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier)

Example 3 with LaunchSpecification

use of com.amazonaws.services.ec2.model.LaunchSpecification in project gocd-ecs-elastic-agent by gocd.

the class SpotRequestMatcher method matches.

public boolean matches(EC2Config ec2Config, SpotInstanceRequest spotInstanceRequest) {
    if (spotInstanceRequest == null) {
        return false;
    }
    LaunchSpecification launchSpecification = spotInstanceRequest.getLaunchSpecification();
    final Platform platform = platformFor(spotInstanceRequest);
    if (platform != ec2Config.getPlatform()) {
        return false;
    }
    if (!StringUtils.equals(launchSpecification.getImageId(), ec2Config.getAmi())) {
        return false;
    }
    if (!StringUtils.equals(ec2Config.getInstanceType(), launchSpecification.getInstanceType())) {
        return false;
    }
    if (notMatching(ec2Config.getSubnetIds(), launchSpecification.getSubnetId())) {
        return false;
    }
    if (notMatching(ec2Config.getSecurityGroups(), getInstanceSecurityGroups(launchSpecification))) {
        return false;
    }
    return ec2Config.runAsSpotInstance();
}
Also used : Platform(com.thoughtworks.gocd.elasticagent.ecs.domain.Platform) LaunchSpecification(com.amazonaws.services.ec2.model.LaunchSpecification)

Aggregations

LaunchSpecification (com.amazonaws.services.ec2.model.LaunchSpecification)2 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 DescribeSpotInstanceRequestsResult (com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult)1 GroupIdentifier (com.amazonaws.services.ec2.model.GroupIdentifier)1 RequestSpotInstancesResult (com.amazonaws.services.ec2.model.RequestSpotInstancesResult)1 Reservation (com.amazonaws.services.ec2.model.Reservation)1 RunInstancesResult (com.amazonaws.services.ec2.model.RunInstancesResult)1 SpotInstanceRequest (com.amazonaws.services.ec2.model.SpotInstanceRequest)1 Platform (com.thoughtworks.gocd.elasticagent.ecs.domain.Platform)1 ArrayList (java.util.ArrayList)1