Search in sources :

Example 41 with TaskState

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

the class ResourceIPDeallocationTaskService method initializeState.

/**
 * Customize the initialization logic (set the task with default values) that's part of initial
 * {@code POST} creating the task service.
 *
 * @see #handleStart(Operation)
 */
@Override
protected void initializeState(ResourceIPDeallocationTaskState startState, Operation startOp) {
    if (startState.taskInfo == null || startState.taskInfo.stage == null) {
        startState.taskInfo = new TaskState();
        startState.taskInfo.stage = TaskState.TaskStage.CREATED;
    }
    startState.taskSubStage = ResourceIPDeallocationTaskState.SubStage.CREATED;
}
Also used : TaskState(com.vmware.xenon.common.TaskState) IPAddressAllocationTaskState(com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState)

Example 42 with TaskState

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

the class ResourceIPDeallocationTaskService method proceedTo.

private void proceedTo(ResourceIPDeallocationTaskState.SubStage nextSubstage, Consumer<ResourceIPDeallocationTaskState> patchBodyConfigurator) {
    ResourceIPDeallocationTaskState state = new ResourceIPDeallocationTaskState();
    state.taskInfo = new TaskState();
    state.taskSubStage = nextSubstage;
    sendSelfPatch(state, TaskState.TaskStage.STARTED, patchBodyConfigurator);
}
Also used : TaskState(com.vmware.xenon.common.TaskState) IPAddressAllocationTaskState(com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState)

Example 43 with TaskState

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

the class EndpointAllocationTaskService method createUpdateSubStageTask.

private EndpointAllocationTaskState createUpdateSubStageTask(TaskStage stage, SubStage subStage, Throwable e) {
    EndpointAllocationTaskState body = new EndpointAllocationTaskState();
    body.taskInfo = new TaskState();
    if (e == null) {
        body.taskInfo.stage = stage == null ? TaskStage.STARTED : stage;
        body.taskSubStage = subStage;
    } else {
        body.taskInfo.stage = TaskStage.FAILED;
        body.taskInfo.failure = Utils.toServiceErrorResponse(e);
        logWarning(() -> String.format("Patching to failed: %s", Utils.toString(e)));
    }
    return body;
}
Also used : TaskState(com.vmware.xenon.common.TaskState) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState)

Example 44 with TaskState

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

the class ProvisionNetworkTaskService method sendSelfPatch.

private void sendSelfPatch(TaskState.TaskStage stage, Throwable e) {
    ProvisionNetworkTaskState body = new ProvisionNetworkTaskState();
    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 45 with TaskState

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

the class NicSecurityGroupsTaskService method handleStart.

@Override
public void handleStart(Operation start) {
    if (!start.hasBody()) {
        start.fail(new IllegalArgumentException("body is required"));
        return;
    }
    NicSecurityGroupsTaskState state = start.getBody(NicSecurityGroupsTaskState.class);
    try {
        Utils.validateState(getStateDescription(), state);
    } catch (Exception e) {
        start.fail(e);
        return;
    }
    validateSecurityGroupsEndpoint(state).whenComplete((ignore, e) -> {
        if (e != null) {
            start.fail(e);
            return;
        }
        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 : NicSecurityGroupsTaskState(com.vmware.photon.controller.model.tasks.NicSecurityGroupsTaskService.NicSecurityGroupsTaskState) NicSecurityGroupsTaskState(com.vmware.photon.controller.model.tasks.NicSecurityGroupsTaskService.NicSecurityGroupsTaskState) 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