Search in sources :

Example 1 with DiskInstanceRequest

use of com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest in project photon-model by vmware.

the class AWSDiskService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    DiskInstanceRequest request = op.getBody(DiskInstanceRequest.class);
    if (request.resourceReference == null) {
        op.fail(new IllegalArgumentException("Disk description cannot be empty"));
        return;
    }
    // initialize context
    AWSDiskContext ctx = new AWSDiskContext(this, request);
    op.complete();
    handleStages(ctx, AwsDiskStage.DISK_STATE);
}
Also used : DiskInstanceRequest(com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest)

Example 2 with DiskInstanceRequest

use of com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest in project photon-model by vmware.

the class ProvisionDiskTaskService method doSubStageDiskOperation.

private void doSubStageDiskOperation(ProvisionDiskTaskState updatedState, ProvisionDiskTaskState.SubStage nextStage, DiskInstanceRequest.DiskRequestType diskRequestType) {
    Operation.CompletionHandler c = (o, e) -> {
        if (e != null) {
            failTask(e);
            return;
        }
        DiskInstanceRequest cr = new DiskInstanceRequest();
        cr.resourceReference = createInventoryUri(this.getHost(), updatedState.diskLink);
        cr.requestType = diskRequestType;
        ServiceDocument subTask = o.getBody(ServiceDocument.class);
        cr.taskReference = UriUtils.buildUri(this.getHost(), subTask.documentSelfLink);
        cr.isMockRequest = updatedState.isMockRequest;
        sendHostServiceRequest(cr, updatedState.diskAdapterReference);
    };
    // after setting boot order and rebooting, we want the sub
    // task to patch us, the main task, to the "next" state
    createSubTask(c, nextStage, updatedState);
}
Also used : ProvisionDiskTaskState(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState) Operation(com.vmware.xenon.common.Operation) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) DiskInstanceRequest(com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Utils(com.vmware.xenon.common.Utils) UriPaths(com.vmware.photon.controller.model.UriPaths) SubStage(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState.SubStage) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) URI(java.net.URI) TaskService(com.vmware.xenon.services.common.TaskService) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Operation(com.vmware.xenon.common.Operation) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DiskInstanceRequest(com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest)

Example 3 with DiskInstanceRequest

use of com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest in project photon-model by vmware.

the class VSphereDiskService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    DiskInstanceRequest request = op.getBody(DiskInstanceRequest.class);
    try {
        validateInputRequest(request);
    } catch (Exception e) {
        op.fail(e);
        return;
    }
    op.setStatusCode(Operation.STATUS_CODE_CREATED);
    op.complete();
    TaskManager taskManager = new TaskManager(this, request.taskReference, request.resourceLink());
    DiskContext.populateContextThen(this, createInitialContext(taskManager, request, op), ctx -> {
        switch(request.requestType) {
            case CREATE:
                handleCreateDisk(ctx);
                break;
            case DELETE:
                handleDeleteDisk(ctx);
                break;
            default:
                Throwable error = new IllegalStateException("Unsupported requestType " + request.requestType);
                ctx.fail(error);
        }
    });
}
Also used : TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) DiskInstanceRequest(com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest)

Aggregations

DiskInstanceRequest (com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest)3 UriPaths (com.vmware.photon.controller.model.UriPaths)1 TaskManager (com.vmware.photon.controller.model.adapters.util.TaskManager)1 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)1 ProvisionDiskTaskState (com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState)1 SubStage (com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState.SubStage)1 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)1 Operation (com.vmware.xenon.common.Operation)1 CompletionHandler (com.vmware.xenon.common.Operation.CompletionHandler)1 ServiceDocument (com.vmware.xenon.common.ServiceDocument)1 TaskState (com.vmware.xenon.common.TaskState)1 TaskStage (com.vmware.xenon.common.TaskState.TaskStage)1 UriUtils (com.vmware.xenon.common.UriUtils)1 Utils (com.vmware.xenon.common.Utils)1 TaskService (com.vmware.xenon.services.common.TaskService)1 URI (java.net.URI)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1