use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class ProvisionComputeTaskService method sendSelfPatch.
private void sendSelfPatch(TaskStage newStage, ProvisionComputeTaskState.SubStage newSubStage, Throwable ex) {
ProvisionComputeTaskState patchBody = new ProvisionComputeTaskState();
patchBody.taskInfo = new TaskState();
patchBody.taskInfo.stage = newStage;
patchBody.taskSubStage = newSubStage;
if (ex != null) {
patchBody.taskInfo.failure = Utils.toServiceErrorResponse(ex);
}
Operation patch = Operation.createPatch(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);
}
use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class ProvisionComputeTaskService method validateState.
public void validateState(ProvisionComputeTaskState state) {
if (state.computeLink == null) {
throw new IllegalArgumentException("computeReference 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() + ProvisionComputeTaskState.DEFAULT_EXPIRATION_MICROS;
}
}
use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class ProvisionLoadBalancerTaskService method sendSelfPatch.
private void sendSelfPatch(TaskState.TaskStage stage, Throwable e) {
ProvisionLoadBalancerTaskState body = new ProvisionLoadBalancerTaskState();
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);
}
use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class ProvisionLoadBalancerTaskService method handleStart.
@Override
public void handleStart(Operation start) {
if (!start.hasBody()) {
start.fail(new IllegalArgumentException("body is required"));
return;
}
ProvisionLoadBalancerTaskState state = start.getBody(ProvisionLoadBalancerTaskState.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);
}
use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class ProvisionSubnetTaskService method sendSelfPatch.
private void sendSelfPatch(TaskState.TaskStage stage, Throwable e) {
ProvisionSubnetTaskState body = new ProvisionSubnetTaskState();
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);
}
Aggregations