use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class AWSEndpointAdapterService method validateCredentials.
private DeferredResult<Void> validateCredentials(AmazonEC2AsyncClient client) {
AWSDeferredResultAsyncHandler<DescribeAvailabilityZonesRequest, DescribeAvailabilityZonesResult> asyncHandler = new AWSDeferredResultAsyncHandler<>(this, "Validate Credentials");
client.describeAvailabilityZonesAsync(asyncHandler);
return asyncHandler.toDeferredResult().handle((describeAvailabilityZonesResult, e) -> {
if (e instanceof AmazonServiceException) {
AmazonServiceException ase = (AmazonServiceException) e;
if (ase.getStatusCode() == STATUS_CODE_UNAUTHORIZED) {
throw new LocalizableValidationException(e, PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE, PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE);
}
}
return null;
});
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class AWSPowerService method powerOn.
private void powerOn(AmazonEC2AsyncClient client, ComputePowerRequest pr, DefaultAdapterContext c) {
OperationContext opContext = OperationContext.getOperationContext();
StartInstancesRequest request = new StartInstancesRequest();
request.withInstanceIds(c.child.id);
client.startInstancesAsync(request, new AsyncHandler<StartInstancesRequest, StartInstancesResult>() {
@Override
public void onSuccess(StartInstancesRequest request, StartInstancesResult result) {
AWSUtils.waitForTransitionCompletion(getHost(), result.getStartingInstances(), "running", client, (is, e) -> {
OperationContext.restoreOperationContext(opContext);
if (e != null) {
onError(e);
return;
}
updateComputeState(pr, c);
});
}
@Override
public void onError(Exception e) {
OperationContext.restoreOperationContext(opContext);
c.taskManager.patchTaskToFailure(e);
}
});
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class AWSResetService method startInstance.
private void startInstance(AmazonEC2AsyncClient client, DefaultAdapterContext c) {
StartInstancesRequest startRequest = new StartInstancesRequest();
startRequest.withInstanceIds(c.child.id);
client.startInstancesAsync(startRequest, new AWSAsyncHandler<StartInstancesRequest, StartInstancesResult>() {
@Override
protected void handleError(Exception e) {
c.taskManager.patchTaskToFailure(e);
}
@Override
protected void handleSuccess(StartInstancesRequest request, StartInstancesResult result) {
AWSUtils.waitForTransitionCompletion(getHost(), result.getStartingInstances(), "running", client, (is, e) -> {
if (e == null) {
c.taskManager.finishTask();
} else {
c.taskManager.patchTaskToFailure(e);
}
});
}
});
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class AWSUtils method setDeleteOnTerminateAttribute.
public static DeferredResult<DiskService.DiskState> setDeleteOnTerminateAttribute(AmazonEC2AsyncClient client, String instanceId, Map<String, Pair<String, Boolean>> deleteDiskMapByDeviceName, OperationContext opCtx) {
List<InstanceBlockDeviceMappingSpecification> instanceBlockDeviceMappingSpecificationList = deleteDiskMapByDeviceName.entrySet().stream().map(entry -> new InstanceBlockDeviceMappingSpecification().withDeviceName(entry.getKey()).withEbs(new EbsInstanceBlockDeviceSpecification().withDeleteOnTermination(entry.getValue().right).withVolumeId(entry.getValue().left))).collect(Collectors.toList());
DeferredResult<DiskService.DiskState> modifyInstanceAttrDr = new DeferredResult();
ModifyInstanceAttributeRequest modifyInstanceAttrReq = new ModifyInstanceAttributeRequest().withInstanceId(instanceId).withAttribute(InstanceAttributeName.BlockDeviceMapping).withBlockDeviceMappings(instanceBlockDeviceMappingSpecificationList);
AWSAsyncHandler<ModifyInstanceAttributeRequest, ModifyInstanceAttributeResult> modifyInstanceAttrHandler = new AWSAsyncHandler<ModifyInstanceAttributeRequest, ModifyInstanceAttributeResult>() {
@Override
protected void handleError(Exception exception) {
OperationContext.restoreOperationContext(opCtx);
modifyInstanceAttrDr.fail(exception);
}
@Override
protected void handleSuccess(ModifyInstanceAttributeRequest request, ModifyInstanceAttributeResult result) {
OperationContext.restoreOperationContext(opCtx);
modifyInstanceAttrDr.complete(new DiskService.DiskState());
}
};
client.modifyInstanceAttributeAsync(modifyInstanceAttrReq, modifyInstanceAttrHandler);
return modifyInstanceAttrDr;
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class AWSUtils method unTagResources.
/**
* Synchronous UnTagging of one or many AWS resources with the provided tags.
*/
public static void unTagResources(AmazonEC2AsyncClient client, Collection<Tag> tags, String... resourceIds) {
if (isAwsClientMock()) {
return;
}
DeleteTagsRequest req = new DeleteTagsRequest().withTags(tags).withResources(resourceIds);
client.deleteTags(req);
}
Aggregations