Search in sources :

Example 1 with DescribeSpotInstanceRequestsRequest

use of com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsRequest in project cloudbreak by hortonworks.

the class ASGroupStatusCheckerTask method checkForSpotRequest.

private void checkForSpotRequest(Activity activity, AmazonEC2 amazonEC2Client) {
    if (WAIT_FOR_SPOT_INSTANCES_STATUS_CODE.equals(activity.getStatusCode())) {
        Pattern pattern = Pattern.compile(SPOT_ID_PATTERN);
        Matcher matcher = pattern.matcher(activity.getStatusMessage());
        if (matcher.find()) {
            String spotId = matcher.group(0);
            DescribeSpotInstanceRequestsResult spotResult = amazonEC2Client.describeSpotInstanceRequests(new DescribeSpotInstanceRequestsRequest().withSpotInstanceRequestIds(spotId));
            Optional<SpotInstanceRequest> request = spotResult.getSpotInstanceRequests().stream().findFirst();
            if (request.isPresent()) {
                if (LOW_SPOT_PRICE_STATUS_CODE.equals(request.get().getStatus().getCode())) {
                    throw new CloudConnectorException(request.get().getStatus().getMessage());
                }
            }
        }
    }
}
Also used : DescribeSpotInstanceRequestsResult(com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DescribeSpotInstanceRequestsRequest(com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsRequest) SpotInstanceRequest(com.amazonaws.services.ec2.model.SpotInstanceRequest)

Aggregations

DescribeSpotInstanceRequestsRequest (com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsRequest)1 DescribeSpotInstanceRequestsResult (com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult)1 SpotInstanceRequest (com.amazonaws.services.ec2.model.SpotInstanceRequest)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1