Search in sources :

Example 1 with TaskState

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

the class IPAddressAllocationTaskService method failTask.

private void failTask(Throwable e, String messageFormat, Object... args) {
    String message = String.format(messageFormat, args);
    logWarning(() -> message);
    IPAddressAllocationTaskState body = new IPAddressAllocationTaskState();
    body.taskInfo = new TaskState();
    body.taskInfo.stage = TaskState.TaskStage.FAILED;
    body.taskInfo.failure = Utils.toServiceErrorResponse(e);
    sendSelfPatch(body);
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 2 with TaskState

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

the class IPAddressAllocationTaskService 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(IPAddressAllocationTaskState startState, Operation startOp) {
    if (startState.taskInfo == null || startState.taskInfo.stage == null) {
        startState.taskInfo = new TaskState();
        startState.taskInfo.stage = TaskState.TaskStage.CREATED;
    }
    startState.taskSubStage = IPAddressAllocationTaskState.SubStage.CREATED;
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 3 with TaskState

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

the class IPAddressAllocationTaskService method proceedTo.

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

Example 4 with TaskState

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

the class ImageEnumerationTaskService 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(ImageEnumerationTaskState startState, Operation startOp) {
    if (startState.options == null) {
        startState.options = EnumSet.noneOf(TaskOption.class);
    }
    if (startState.taskInfo == null || startState.taskInfo.stage == null) {
        startState.taskInfo = new TaskState();
        startState.taskInfo.stage = TaskState.TaskStage.CREATED;
    }
    if (startState.documentExpirationTimeMicros <= 0) {
        setExpiration(startState, DEFAULT_EXPIRATION_MINUTES, TimeUnit.MINUTES);
    }
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 5 with TaskState

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

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