use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState in project photon-model by vmware.
the class ProvisionDiskTaskService method validateDiskAndStart.
private void validateDiskAndStart(ProvisionDiskTaskState state, Operation startPost) {
URI diskUri = UriUtils.buildUri(getHost(), state.diskLink);
sendRequest(Operation.createGet(createInventoryUri(this.getHost(), diskUri)).setCompletion((o, e) -> {
if (e != null) {
logWarning(() -> String.format("Failure retrieving disk state (%s): %s", diskUri, e.toString()));
o.complete();
failTask(e);
return;
}
DiskState disk = o.getBody(DiskState.class);
state.diskAdapterReference = disk.diskAdapterReference;
startPost.complete();
if (disk.capacityMBytes < 0) {
failTask(new IllegalArgumentException("disk capacity is mandatory for a disk"));
return;
}
if (state.taskSubStage == ProvisionDiskTaskState.SubStage.CREATING_DISK && state.diskAdapterReference == null) {
failTask(new IllegalArgumentException("diskState does not have create service specified"));
return;
}
sendSelfPatch(TaskStage.STARTED, state.taskSubStage, null);
}));
}
use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState in project photon-model by vmware.
the class ProvisionDiskTaskService method handleStart.
@Override
public void handleStart(Operation startPost) {
try {
ProvisionDiskTaskState state = startPost.getBody(ProvisionDiskTaskState.class);
validateState(state);
validateDiskAndStart(state, startPost);
} catch (Throwable e) {
logSevere(e);
startPost.fail(e);
failTask(e);
}
}
use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState in project photon-model by vmware.
the class ProvisionDiskTaskService method handlePatch.
@Override
public void handlePatch(Operation patch) {
ProvisionDiskTaskState patchBody = patch.getBody(ProvisionDiskTaskState.class);
ProvisionDiskTaskState currentState = getState(patch);
// this validates and transitions the stage to the next state
if (validateStageTransition(patch, patchBody, currentState)) {
return;
}
handleStagePatch(patch, currentState);
}
use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState 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);
}
use of com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState in project photon-model by vmware.
the class ProvisionDiskTaskService method validateState.
public void validateState(ProvisionDiskTaskState state) {
if (state.diskLink == null) {
throw new IllegalArgumentException("diskReference 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() + ProvisionDiskTaskState.DEFAULT_EXPIRATION_MICROS;
}
}
Aggregations