Search in sources :

Example 16 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class ProvisionComputeTaskService method sendSelfPatch.

private void sendSelfPatch(TaskStage newStage, ProvisionComputeTaskState.SubStage newSubStage, Throwable ex) {
    ProvisionComputeTaskState patchBody = new ProvisionComputeTaskState();
    patchBody.taskInfo = new TaskState();
    patchBody.taskInfo.stage = newStage;
    patchBody.taskSubStage = newSubStage;
    if (ex != null) {
        patchBody.taskInfo.failure = Utils.toServiceErrorResponse(ex);
    }
    Operation patch = Operation.createPatch(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 : Operation(com.vmware.xenon.common.Operation) TaskState(com.vmware.xenon.common.TaskState)

Example 17 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class ProvisionComputeTaskService method validateState.

public void validateState(ProvisionComputeTaskState state) {
    if (state.computeLink == null) {
        throw new IllegalArgumentException("computeReference 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() + ProvisionComputeTaskState.DEFAULT_EXPIRATION_MICROS;
    }
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 18 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class ProvisionLoadBalancerTaskService method sendSelfPatch.

private void sendSelfPatch(TaskState.TaskStage stage, Throwable e) {
    ProvisionLoadBalancerTaskState body = new ProvisionLoadBalancerTaskState();
    body.taskInfo = new TaskState();
    if (e == null) {
        body.taskInfo.stage = stage;
    } else {
        body.taskInfo.stage = TaskState.TaskStage.FAILED;
        body.taskInfo.failure = Utils.toServiceErrorResponse(e);
        logWarning(() -> String.format("Patching to failed: %s", Utils.toString(e)));
    }
    sendSelfPatch(body);
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 19 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class ProvisionLoadBalancerTaskService method handleStart.

@Override
public void handleStart(Operation start) {
    if (!start.hasBody()) {
        start.fail(new IllegalArgumentException("body is required"));
        return;
    }
    ProvisionLoadBalancerTaskState state = start.getBody(ProvisionLoadBalancerTaskState.class);
    try {
        state.validate();
    } catch (Exception e) {
        start.fail(e);
    }
    state.taskInfo = new TaskState();
    state.taskInfo.stage = TaskState.TaskStage.CREATED;
    state.taskSubStage = SubStage.CREATED;
    start.complete();
    // start the task
    sendSelfPatch(TaskState.TaskStage.CREATED, null);
}
Also used : TaskState(com.vmware.xenon.common.TaskState) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException)

Example 20 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class ProvisionSubnetTaskService method sendSelfPatch.

private void sendSelfPatch(TaskState.TaskStage stage, Throwable e) {
    ProvisionSubnetTaskState body = new ProvisionSubnetTaskState();
    body.taskInfo = new TaskState();
    if (e == null) {
        body.taskInfo.stage = stage;
    } else {
        body.taskInfo.stage = TaskState.TaskStage.FAILED;
        body.taskInfo.failure = Utils.toServiceErrorResponse(e);
        logWarning(() -> String.format("Patching to failed: %s", Utils.toString(e)));
    }
    sendSelfPatch(body);
}
Also used : ProvisionSubnetTaskState(com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState) ProvisionSubnetTaskState(com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState) TaskState(com.vmware.xenon.common.TaskState)

Aggregations

TaskState (com.vmware.xenon.common.TaskState)45 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)6 NicSecurityGroupsTaskState (com.vmware.photon.controller.model.tasks.NicSecurityGroupsTaskService.NicSecurityGroupsTaskState)5 ProvisionSubnetTaskState (com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState)5 Operation (com.vmware.xenon.common.Operation)5 ImageEnumerationTaskState (com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState)4 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)3 IPAddressAllocationTaskState (com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState)3 ProvisionSecurityGroupTaskState (com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState)3 SubTaskState (com.vmware.photon.controller.model.tasks.SubTaskService.SubTaskState)3 HashMap (java.util.HashMap)3 UriPaths (com.vmware.photon.controller.model.UriPaths)2 EndpointType (com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType)2 ProvisionDiskTaskState (com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState)2 ResourceIPDeallocationTaskState (com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState)2 PropertyUsageOption (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption)2 UriUtils (com.vmware.xenon.common.UriUtils)2 Utils (com.vmware.xenon.common.Utils)2 TaskService (com.vmware.xenon.services.common.TaskService)2 List (java.util.List)2