private void terminateSpotRequest() throws AmazonServiceException { if (spotRequestId == null) return; com.amazonaws.services.ec2.AmazonEC2 client = AmazonEC2.connect(); List<String> spotInstanceRequestIds = new ArrayList<String>(); spotInstanceRequestIds.add(spotRequestId); CancelSpotInstanceRequestsRequest cancelRequest = new CancelSpotInstanceRequestsRequest( spotInstanceRequestIds); client.cancelSpotInstanceRequests(cancelRequest); }
public void shutdownInstances() { AmazonEC2 ec2 = new AmazonEC2Client(getAwsCredentials()); ec2.setEndpoint(getOrCry("ec2endpoint")); try { // cancel spot request, so no new instances will be launched DescribeSpotInstanceRequestsRequest describeRequest = new DescribeSpotInstanceRequestsRequest(); DescribeSpotInstanceRequestsResult describeResult = ec2 .describeSpotInstanceRequests(describeRequest); List<SpotInstanceRequest> describeResponses = describeResult .getSpotInstanceRequests(); List<String> spotRequestIds = new ArrayList<String>(); List<String> instanceIds = new ArrayList<String>(); for (SpotInstanceRequest describeResponse : describeResponses) { spotRequestIds.add(describeResponse.getSpotInstanceRequestId()); if ("active".equals(describeResponse.getState())) { instanceIds.add(describeResponse.getInstanceId()); } } ec2.cancelSpotInstanceRequests(new CancelSpotInstanceRequestsRequest() .withSpotInstanceRequestIds(spotRequestIds)); log.info("Cancelled spot request"); if (instanceIds.size() > 0) { ec2.terminateInstances(new TerminateInstancesRequest( instanceIds)); log.info("Shut down " + instanceIds.size() + " instances"); } } catch (Exception e) { log.warn("Failed to shutdown instances - ", e); } }
@Override public CancelSpotInstanceRequestsResult call() throws AmazonClientException { CancelSpotInstanceRequestsRequest request = new CancelSpotInstanceRequestsRequest() .withSpotInstanceRequestIds(this.spotRequestIds); CancelSpotInstanceRequestsResult result = getClient().getApi().cancelSpotInstanceRequests(request); awaitCancellation(this.spotRequestIds); return result; }
@Override public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) { @SuppressWarnings("unchecked") List<String> requests = (List<String>) execution.getVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS); checkNotNull(requests, "process variable '{}' not found", ProcessVariables.SPOT_INSTANCE_REQUEST_IDS); if (requests.size() > 0) { client.cancelSpotInstanceRequests(new CancelSpotInstanceRequestsRequest() .withSpotInstanceRequestIds(requests)); } }
@Override public CancelSpotInstanceRequestsResult cancelSpotInstanceRequests(CancelSpotInstanceRequestsRequest cancelSpotInstanceRequestsRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
public void cancelSpotInstanceOffers(String... spotInstanceOfferIds) { ec2_.cancelSpotInstanceRequests(new CancelSpotInstanceRequestsRequest().withSpotInstanceRequestIds(spotInstanceOfferIds)); }