Search in sources :

Example 6 with TaskState

use of com.vmware.xenon.common.TaskState 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)

Example 7 with TaskState

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

the class ProvisionNetworkTaskService method handleStart.

@Override
public void handleStart(Operation start) {
    if (!start.hasBody()) {
        start.fail(new IllegalArgumentException("body is required"));
        return;
    }
    ProvisionNetworkTaskState state = start.getBody(ProvisionNetworkTaskState.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)

Example 8 with TaskState

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

the class ResourceAllocationTaskService method sendSelfPatch.

private void sendSelfPatch(TaskStage stage, SubStage subStage, Throwable e) {
    ResourceAllocationTaskState body = new ResourceAllocationTaskState();
    body.taskInfo = new TaskState();
    if (e == null) {
        body.taskInfo.stage = 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)));
    }
    sendSelfPatch(body);
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 9 with TaskState

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

the class ResourceRemovalTaskService method validateState.

public static void validateState(ResourceRemovalTaskState state) {
    if (state.resourceQuerySpec == null) {
        throw new IllegalArgumentException("resourceQuerySpec is required");
    }
    if (state.taskInfo == null || state.taskInfo.stage == null) {
        state.taskInfo = new TaskState();
        state.taskInfo.stage = TaskState.TaskStage.CREATED;
    }
    if (state.taskSubStage == null) {
        state.taskSubStage = SubStage.WAITING_FOR_QUERY_COMPLETION;
    }
    if (state.documentExpirationTimeMicros == 0) {
        state.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + DEFAULT_TIMEOUT_MICROS;
    }
}
Also used : ResourceIPDeallocationTaskState(com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState) TaskState(com.vmware.xenon.common.TaskState)

Example 10 with TaskState

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

the class ResourceRemovalTaskService method sendSelfPatch.

private void sendSelfPatch(TaskState.TaskStage stage, SubStage subStage, Consumer<ResourceRemovalTaskState> patchBodyConfigurator) {
    ResourceRemovalTaskState body = new ResourceRemovalTaskState();
    body.taskInfo = new TaskState();
    body.taskInfo.stage = stage;
    body.taskSubStage = subStage;
    if (patchBodyConfigurator != null) {
        patchBodyConfigurator.accept(body);
    }
    sendSelfPatch(body);
}
Also used : ResourceIPDeallocationTaskState(com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState) 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