Search in sources :

Example 11 with TaskState

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

the class SshCommandTaskService method handleStart.

@Override
public void handleStart(Operation start) {
    if (!start.hasBody()) {
        start.fail(new IllegalArgumentException("body is required"));
        return;
    }
    SshCommandTaskState state = start.getBody(SshCommandTaskState.class);
    if (state.host == null) {
        start.fail(new IllegalArgumentException("host is required"));
        return;
    }
    if (state.authCredentialLink == null) {
        start.fail(new IllegalArgumentException("authCredentialLink is required"));
        return;
    }
    if (state.commands == null || state.commands.isEmpty()) {
        start.fail(new IllegalArgumentException("commands must be specified"));
        return;
    }
    if (this.executor == null) {
        start.fail(new IllegalArgumentException("executor must not be null"));
        return;
    }
    if (state.taskInfo == null) {
        state.taskInfo = new TaskState();
    }
    if (TaskState.isFinished(state.taskInfo)) {
        // task is in the finished state, just return.
        start.complete();
        return;
    }
    if (state.taskInfo.stage != null && state.taskInfo.stage != TaskStage.CREATED) {
        start.fail(new IllegalStateException("SshCommand cannot be restarted."));
        return;
    }
    state.taskInfo.stage = TaskStage.STARTED;
    if (state.documentExpirationTimeMicros == 0) {
        // always set expiration so we do not accumulate tasks.
        state.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + TimeUnit.SECONDS.toMicros(DEFAULT_EXPIRATION_SECONDS);
    }
    start.setBody(state).complete();
    getAuth(state);
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 12 with TaskState

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

the class TaskUtils method sendFailureSelfPatch.

/**
 * Send a failure patch to the specified service
 *
 * @param service
 *         service to send the patch to
 * @param e
 *         Exception
 */
private static void sendFailureSelfPatch(StatefulService service, Throwable e) {
    // It looks like Xenon can't handle correctly serializing abstract classes, so we have to
    // use a simple class which extend the abstract.
    StatefulTaskDocument body = new StatefulTaskDocument();
    body.taskInfo = new TaskState();
    body.taskInfo.stage = TaskStage.FAILED;
    body.taskInfo.failure = Utils.toServiceErrorResponse(e);
    service.logWarning(() -> String.format("Operation failed: %s", Utils.toString(e)));
    sendPatch(service, body);
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 13 with TaskState

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

the class TaskUtils method sendFailurePatch.

/**
 * Patch a service to failure
 *
 * @param service
 *         Service to patch
 * @param t
 *         Throwable object
 */
public static void sendFailurePatch(StatefulService service, TaskServiceState taskState, Throwable t) {
    TaskState state = new TaskState();
    state.stage = TaskStage.FAILED;
    state.failure = Utils.toServiceErrorResponse(t);
    service.logWarning(() -> String.format("Operation failed: %s", Utils.toString(t)));
    taskState.taskInfo = state;
    sendPatch(service, taskState);
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 14 with TaskState

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

the class EndpointRemovalTaskService method createPatchSubStageTask.

private EndpointRemovalTaskState createPatchSubStageTask(TaskState.TaskStage stage, SubStage subStage, Throwable e) {
    EndpointRemovalTaskState body = new EndpointRemovalTaskState();
    body.taskInfo = new TaskState();
    body.taskInfo.stage = stage;
    body.taskSubStage = subStage;
    if (e != null) {
        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)

Example 15 with TaskState

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

the class NicSecurityGroupsTaskService method sendSelfPatch.

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