Search in sources :

Example 1 with AttachVolumeResult

use of com.amazonaws.services.ec2.model.AttachVolumeResult in project photon-model by vmware.

the class AWSComputeDiskDay2Service method performAttachOperation.

private DeferredResult<DiskContext> performAttachOperation(DiskContext context) {
    DeferredResult<DiskContext> dr = new DeferredResult<>();
    try {
        if (context.request.isMockRequest) {
            updateComputeAndDiskState(dr, context, null);
            return dr;
        }
        String instanceId = context.computeState.id;
        if (instanceId == null || !instanceId.startsWith(AWS_INSTANCE_ID_PREFIX)) {
            return logAndGetFailedDr(context, "compute id cannot be empty");
        }
        String diskId = context.diskState.id;
        if (diskId == null || !diskId.startsWith(AWS_VOLUME_ID_PREFIX)) {
            return logAndGetFailedDr(context, "disk id cannot be empty");
        }
        String deviceName = getAvailableDeviceName(context, instanceId);
        if (deviceName == null) {
            return logAndGetFailedDr(context, "No device name is available for attaching new disk");
        }
        context.diskState.customProperties.put(DEVICE_NAME, deviceName);
        AttachVolumeRequest attachVolumeRequest = new AttachVolumeRequest().withInstanceId(instanceId).withVolumeId(diskId).withDevice(deviceName);
        AWSAsyncHandler<AttachVolumeRequest, AttachVolumeResult> attachDiskHandler = new AWSAttachDiskHandler(dr, context);
        context.amazonEC2Client.attachVolumeAsync(attachVolumeRequest, attachDiskHandler);
    } catch (Exception e) {
        context.error = e;
        return DeferredResult.completed(context);
    }
    return dr;
}
Also used : AttachVolumeRequest(com.amazonaws.services.ec2.model.AttachVolumeRequest) AttachVolumeResult(com.amazonaws.services.ec2.model.AttachVolumeResult) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

AttachVolumeRequest (com.amazonaws.services.ec2.model.AttachVolumeRequest)1 AttachVolumeResult (com.amazonaws.services.ec2.model.AttachVolumeResult)1 DeferredResult (com.vmware.xenon.common.DeferredResult)1