use of com.amazonaws.AmazonServiceException in project openhab1-addons by openhab.
the class DynamoDBPersistenceService method query.
/**
* {@inheritDoc}
*/
@Override
public Iterable<HistoricItem> query(FilterCriteria filter) {
logger.debug("got a query");
if (!isProperlyConfigured) {
logger.warn("Configuration for dynamodb not yet loaded or broken. Not storing item.");
return Collections.emptyList();
}
if (!maybeConnectAndCheckConnection()) {
logger.warn("DynamoDB not connected. Not storing item.");
return Collections.emptyList();
}
String itemName = filter.getItemName();
Item item = getItemFromRegistry(itemName);
if (item == null) {
logger.warn("Could not get item {} from registry!", itemName);
return Collections.emptyList();
}
Class<DynamoDBItem<?>> dtoClass = AbstractDynamoDBItem.getDynamoItemClass(item.getClass());
String tableName = tableNameResolver.fromClass(dtoClass);
DynamoDBMapper mapper = getDBMapper(tableName);
logger.debug("item {} (class {}) will be tried to query using dto class {} from table {}", itemName, item.getClass(), dtoClass, tableName);
List<HistoricItem> historicItems = new ArrayList<HistoricItem>();
DynamoDBQueryExpression<DynamoDBItem<?>> queryExpression = createQueryExpression(dtoClass, filter);
@SuppressWarnings("rawtypes") final PaginatedQueryList<? extends DynamoDBItem> paginatedList;
try {
paginatedList = mapper.query(dtoClass, queryExpression);
} catch (AmazonServiceException e) {
logger.error("DynamoDB query raised unexpected exception: {}. Returning empty collection. " + "Status code 400 (resource not found) might occur if table was just created.", e.getMessage());
return Collections.emptyList();
}
for (int itemIndexOnPage = 0; itemIndexOnPage < filter.getPageSize(); itemIndexOnPage++) {
int itemIndex = filter.getPageNumber() * filter.getPageSize() + itemIndexOnPage;
DynamoDBItem<?> dynamoItem;
try {
dynamoItem = paginatedList.get(itemIndex);
} catch (IndexOutOfBoundsException e) {
logger.debug("Index {} is out-of-bounds", itemIndex);
break;
}
if (dynamoItem != null) {
HistoricItem historicItem = dynamoItem.asHistoricItem(item);
logger.trace("Dynamo item {} converted to historic item: {}", item, historicItem);
historicItems.add(historicItem);
}
}
return historicItems;
}
use of com.amazonaws.AmazonServiceException in project SimianArmy by Netflix.
the class VSphereClient method terminateInstance.
@Override
public /**
* reinstall the given instance. If it is powered down this will be ignored and the
* reinstall occurs the next time the machine is powered up.
*/
void terminateInstance(String instanceId) {
try {
connection.connect();
VirtualMachine virtualMachine = connection.getVirtualMachineById(instanceId);
this.terminationStrategy.terminate(virtualMachine);
} catch (RemoteException e) {
throw new AmazonServiceException("cannot destroy & recreate " + instanceId, e);
} finally {
connection.disconnect();
}
}
use of com.amazonaws.AmazonServiceException in project SimianArmy by Netflix.
the class AWSClient method detachVolume.
@Override
public void detachVolume(String instanceId, String volumeId, boolean force) {
Validate.notEmpty(instanceId);
LOGGER.info(String.format("Detach volumes from instance %s in region %s.", instanceId, region));
try {
DetachVolumeRequest detachVolumeRequest = new DetachVolumeRequest();
detachVolumeRequest.setForce(force);
detachVolumeRequest.setInstanceId(instanceId);
detachVolumeRequest.setVolumeId(volumeId);
ec2Client().detachVolume(detachVolumeRequest);
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
throw new NotFoundException("AWS instance " + instanceId + " not found", e);
}
throw e;
}
}
use of com.amazonaws.AmazonServiceException in project SimianArmy by Netflix.
the class AWSClient method setInstanceSecurityGroups.
/** {@inheritDoc} */
public void setInstanceSecurityGroups(String instanceId, List<String> groupIds) {
Validate.notEmpty(instanceId);
LOGGER.info(String.format("Removing all security groups from instance %s in region %s.", instanceId, region));
try {
ModifyInstanceAttributeRequest request = new ModifyInstanceAttributeRequest();
request.setInstanceId(instanceId);
request.setGroups(groupIds);
ec2Client().modifyInstanceAttribute(request);
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
throw new NotFoundException("AWS instance " + instanceId + " not found", e);
}
throw e;
}
}
use of com.amazonaws.AmazonServiceException in project SimianArmy by Netflix.
the class AWSClient method listAttachedVolumes.
@Override
public List<String> listAttachedVolumes(String instanceId, boolean includeRoot) {
Validate.notEmpty(instanceId);
LOGGER.info(String.format("Listing volumes attached to instance %s in region %s.", instanceId, region));
try {
List<String> volumeIds = new ArrayList<String>();
for (Instance instance : describeInstances(instanceId)) {
String rootDeviceName = instance.getRootDeviceName();
for (InstanceBlockDeviceMapping ibdm : instance.getBlockDeviceMappings()) {
EbsInstanceBlockDevice ebs = ibdm.getEbs();
if (ebs == null) {
continue;
}
String volumeId = ebs.getVolumeId();
if (Strings.isNullOrEmpty(volumeId)) {
continue;
}
if (!includeRoot && rootDeviceName != null && rootDeviceName.equals(ibdm.getDeviceName())) {
continue;
}
volumeIds.add(volumeId);
}
}
return volumeIds;
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
throw new NotFoundException("AWS instance " + instanceId + " not found", e);
}
throw e;
}
}
Aggregations