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();
}
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);
}
Aggregations