Search in sources :

Example 1 with ProvisionDiskTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState in project photon-model by vmware.

the class ProvisionDiskTaskService method validateDiskAndStart.

private void validateDiskAndStart(ProvisionDiskTaskState state, Operation startPost) {
    URI diskUri = UriUtils.buildUri(getHost(), state.diskLink);
    sendRequest(Operation.createGet(createInventoryUri(this.getHost(), diskUri)).setCompletion((o, e) -> {
        if (e != null) {
            logWarning(() -> String.format("Failure retrieving disk state (%s): %s", diskUri, e.toString()));
            o.complete();
            failTask(e);
            return;
        }
        DiskState disk = o.getBody(DiskState.class);
        state.diskAdapterReference = disk.diskAdapterReference;
        startPost.complete();
        if (disk.capacityMBytes < 0) {
            failTask(new IllegalArgumentException("disk capacity is mandatory for a disk"));
            return;
        }
        if (state.taskSubStage == ProvisionDiskTaskState.SubStage.CREATING_DISK && state.diskAdapterReference == null) {
            failTask(new IllegalArgumentException("diskState does not have create service specified"));
            return;
        }
        sendSelfPatch(TaskStage.STARTED, state.taskSubStage, null);
    }));
}
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) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) URI(java.net.URI)

Example 2 with ProvisionDiskTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState in project photon-model by vmware.

the class ProvisionDiskTaskService method handleStart.

@Override
public void handleStart(Operation startPost) {
    try {
        ProvisionDiskTaskState state = startPost.getBody(ProvisionDiskTaskState.class);
        validateState(state);
        validateDiskAndStart(state, startPost);
    } catch (Throwable e) {
        logSevere(e);
        startPost.fail(e);
        failTask(e);
    }
}
Also used : ProvisionDiskTaskState(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState)

Example 3 with ProvisionDiskTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState in project photon-model by vmware.

the class ProvisionDiskTaskService method handlePatch.

@Override
public void handlePatch(Operation patch) {
    ProvisionDiskTaskState patchBody = patch.getBody(ProvisionDiskTaskState.class);
    ProvisionDiskTaskState currentState = getState(patch);
    // this validates and transitions the stage to the next state
    if (validateStageTransition(patch, patchBody, currentState)) {
        return;
    }
    handleStagePatch(patch, currentState);
}
Also used : ProvisionDiskTaskState(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState)

Example 4 with ProvisionDiskTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState in project photon-model by vmware.

the class ProvisionDiskTaskService method sendSelfPatch.

private void sendSelfPatch(TaskStage newStage, ProvisionDiskTaskState.SubStage newSubStage, Throwable ex) {
    ProvisionDiskTaskState patchBody = new ProvisionDiskTaskState();
    patchBody.taskInfo = new TaskState();
    patchBody.taskInfo.stage = newStage;
    patchBody.taskSubStage = newSubStage;
    if (ex != null) {
        patchBody.taskInfo.failure = Utils.toServiceErrorResponse(ex);
    }
    Operation patch = Operation.createPatch(createInventoryUri(this.getHost(), getUri())).setBody(patchBody).setCompletion((o, e) -> {
        if (e != null) {
            logWarning(() -> String.format("Self patch failed: %s", com.vmware.xenon.common.Utils.toString(e)));
        }
    });
    sendRequest(patch);
}
Also used : ProvisionDiskTaskState(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState) Operation(com.vmware.xenon.common.Operation) ProvisionDiskTaskState(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState) TaskState(com.vmware.xenon.common.TaskState)

Example 5 with ProvisionDiskTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState in project photon-model by vmware.

the class ProvisionDiskTaskService method validateState.

public void validateState(ProvisionDiskTaskState state) {
    if (state.diskLink == null) {
        throw new IllegalArgumentException("diskReference is required");
    }
    state.taskInfo = new TaskState();
    state.taskInfo.stage = TaskStage.CREATED;
    if (state.taskSubStage == null) {
        throw new IllegalArgumentException("taskSubStage is required");
    }
    if (state.documentExpirationTimeMicros == 0) {
        state.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + ProvisionDiskTaskState.DEFAULT_EXPIRATION_MICROS;
    }
}
Also used : ProvisionDiskTaskState(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState) TaskState(com.vmware.xenon.common.TaskState)

Aggregations

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