List of usage examples for com.amazonaws.services.ec2.model CancelSpotInstanceRequestsResult getCancelledSpotInstanceRequests
public java.util.List<CancelledSpotInstanceRequest> getCancelledSpotInstanceRequests()
One or more Spot Instance requests.
From source file:n3phele.factory.ec2.VirtualServerResource.java
License:Open Source License
private void cancelSpotVMRequest(VirtualServer item) throws Exception { String spotId = item.getSpotId(); try {//w w w . j a va 2s.c o m if (spotId != null && spotId.length() > 0) { AmazonEC2Client client = null; client = getEC2Client(item.getAccessKey(), item.getEncryptedKey(), item.getLocation()); try { if (item.getInstanceId() == null || item.getInstanceId().length() == 0) { DescribeSpotInstanceRequestsResult update = client.describeSpotInstanceRequests( new DescribeSpotInstanceRequestsRequest().withSpotInstanceRequestIds(spotId)); String instanceId = update.getSpotInstanceRequests().get(0).getInstanceId(); item.setInstanceId(instanceId); update(item); } } catch (Exception e) { log.log(Level.WARNING, "Spot request " + spotId + " update failed ", e); } CancelSpotInstanceRequestsRequest request = new CancelSpotInstanceRequestsRequest() .withSpotInstanceRequestIds(spotId); CancelSpotInstanceRequestsResult result = client.cancelSpotInstanceRequests(request); log.info("Cancel spot request " + spotId + " status " + result.getCancelledSpotInstanceRequests().get(0).getState().toString()); } } catch (Exception e) { log.log(Level.SEVERE, "Cleanup delete of spot instance " + spotId, e); throw e; } }