Search in sources :

Example 11 with ProvisionSubnetTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState in project photon-model by vmware.

the class ProvisionSubnetTaskService method handlePatch.

@Override
public void handlePatch(Operation patch) {
    if (!patch.hasBody()) {
        patch.fail(new IllegalArgumentException("body is required"));
        return;
    }
    ProvisionSubnetTaskState currentState = getState(patch);
    ProvisionSubnetTaskState patchState = patch.getBody(ProvisionSubnetTaskState.class);
    if (TaskState.isFailed(patchState.taskInfo)) {
        currentState.taskInfo = patchState.taskInfo;
    }
    switch(patchState.taskInfo.stage) {
        case CREATED:
            currentState.taskSubStage = nextStage(currentState);
            handleSubStages(currentState);
            logInfo(() -> String.format("%s %s on %s started", "Subnet", currentState.requestType.toString(), currentState.subnetLink));
            break;
        case STARTED:
            currentState.taskInfo.stage = TaskState.TaskStage.STARTED;
            break;
        case FINISHED:
            SubStage nextStage = nextStage(currentState);
            if (nextStage == SubStage.FINISHED) {
                currentState.taskInfo.stage = TaskState.TaskStage.FINISHED;
                logInfo(() -> "Task is complete");
                ServiceTaskCallback.sendResponse(currentState.serviceTaskCallback, this, currentState);
            } else {
                sendSelfPatch(TaskState.TaskStage.CREATED, null);
            }
            break;
        case FAILED:
            logWarning(() -> String.format("Task failed with %s", Utils.toJsonHtml(currentState.taskInfo.failure)));
            ServiceTaskCallback.sendResponse(currentState.serviceTaskCallback, this, currentState);
            break;
        case CANCELLED:
            break;
        default:
            break;
    }
    patch.complete();
}
Also used : ProvisionSubnetTaskState(com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState)

Example 12 with ProvisionSubnetTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState in project photon-model by vmware.

the class ProvisionSubnetTaskService method handleStart.

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

ProvisionSubnetTaskState (com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState)12 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)4 Test (org.junit.Test)3 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)2 TaskState (com.vmware.xenon.common.TaskState)2 InstanceRequestType (com.vmware.photon.controller.model.adapterapi.SubnetInstanceRequest.InstanceRequestType)1 DvsNetworkService (com.vmware.photon.controller.model.adapters.vsphere.network.DvsNetworkService)1 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)1 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)1 NetworkService (com.vmware.photon.controller.model.resources.NetworkService)1 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)1 SubnetService (com.vmware.photon.controller.model.resources.SubnetService)1 ProvisionSubnetTaskService (com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService)1 TaskOption (com.vmware.photon.controller.model.tasks.TaskOption)1 TestUtils (com.vmware.photon.controller.model.tasks.TestUtils)1 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)1 Operation (com.vmware.xenon.common.Operation)1 ServiceDocument (com.vmware.xenon.common.ServiceDocument)1