public void destroyComputeInstance(InventoryItem inventoryItem) throws InvalidCredentialsException {
Preconditions.checkNotNull(inventoryItem, "inventoryItem cannot be null.");
Preconditions.checkArgument(inventoryItem.getType().equals(Constants.COMPUTE_INSTANCE_TYPE),
"Inventory item of type '" + inventoryItem.getType() + "' cannot be destroyed.");
AWSClient client = (AWSClient)getClient(inventoryItem.getConnection());
logger.debug("Terminating node: " + inventoryItem.getExternalId());
BasicDBObject payload = getInventoryItemPayload(inventoryItem);
String jcloudsNodeId = payload.getString("id");
NodeMetadata nodeMetadata = client.getEC2Instance(jcloudsNodeId);
if (nodeMetadata.getStatus().equals(NodeMetadata.Status.TERMINATED)) {
return;
}
EventId eventId;
if (client.destroyEC2Instance(jcloudsNodeId)) {
eventId = EventId.CLOUD_INVENTORY_ITEM_TERMINATE;
} else {
// TODO: Handle this issue but it can be a false positive if the time it takes surpasses the time we wait
eventId = EventId.CLOUD_INVENTORY_ITEM_TERMINATE_FAILURE;
}