use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class AzurePowerServiceTest method triggerPowerChange.
private void triggerPowerChange(PowerState powerState, URI powerAdapterReference) {
String taskLink = UUID.randomUUID().toString();
ComputePowerRequest powerRequest = new ComputePowerRequest();
powerRequest.isMockRequest = this.isMock;
powerRequest.powerState = powerState;
powerRequest.resourceReference = UriUtils.buildUri(this.host, this.vmState.documentSelfLink);
powerRequest.taskReference = UriUtils.buildUri(this.host, taskLink);
TestContext ctx = this.host.testCreate(2);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else if (TaskState.isFinished(response.taskInfo)) {
ctx.completeIteration();
}
return true;
});
Operation powerOp = Operation.createPatch(powerAdapterReference).setBody(powerRequest).setReferer("/tests").setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(powerOp);
ctx.await();
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class AzureLifecycleOperationServiceTest method triggerRestart.
private void triggerRestart() {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = this.isMock;
request.operation = ResourceOperation.RESTART.operation;
request.resourceReference = UriUtils.buildUri(this.host, this.vmState.documentSelfLink);
request.taskReference = UriUtils.buildUri(this.host, taskLink);
TestContext ctx = this.host.testCreate(2);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else if (TaskState.isFinished(response.taskInfo)) {
ctx.completeIteration();
}
return true;
});
Operation restartOp = Operation.createPatch(UriUtils.buildUri(this.host, AzureLifecycleOperationService.SELF_LINK)).setBody(request).setReferer("/tests").setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(restartOp);
ctx.await();
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class AzureLifecycleOperationServiceTest method triggerSuspend.
private void triggerSuspend() {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = this.isMock;
request.operation = ResourceOperation.SUSPEND.operation;
request.resourceReference = UriUtils.buildUri(this.host, this.vmState.documentSelfLink);
request.taskReference = UriUtils.buildUri(this.host, taskLink);
TestContext ctx = this.host.testCreate(2);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else if (TaskState.isFinished(response.taskInfo)) {
ctx.completeIteration();
}
return true;
});
Operation restartOp = Operation.createPatch(UriUtils.buildUri(this.host, AzureLifecycleOperationService.SELF_LINK)).setBody(request).setReferer("/tests2").setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(restartOp);
ctx.await();
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class TaskManager method createFailurePatch.
private Operation createFailurePatch(String msg, Throwable failure) {
ResourceOperationResponse body = ResourceOperationResponse.fail(this.resourceLink, failure);
body.failureMessage = failure.getClass().getName() + ": " + msg;
return Operation.createPatch(this.taskReference).setBody(body);
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class SubTaskService method handlePatch.
@Override
public void handlePatch(Operation patch) {
SubTaskState<E> patchBody = getBody(patch);
SubTaskState<E> currentState = getState(patch);
if (patchBody.taskInfo == null || patchBody.taskInfo.stage == null) {
String error = "taskInfo, taskInfo.stage are required";
logWarning(error);
patch.fail(new IllegalArgumentException(error));
return;
}
if (currentState.completionsRemaining == 0) {
// don't do anything, we are done
patch.complete();
return;
}
if (patchBody.taskInfo.stage == TaskStage.FAILED || patchBody.taskInfo.stage == TaskStage.CANCELLED) {
currentState.failCount++;
currentState.completionsRemaining--;
if (ResourceOperationResponse.KIND.equals(patchBody.documentKind)) {
ResourceOperationResponse r = patch.getBody(ResourceOperationResponse.class);
currentState.failures.add(r);
}
} else if (patchBody.taskInfo.stage == TaskStage.FINISHED) {
currentState.completionsRemaining--;
currentState.finishedCount++;
if (ResourceOperationResponse.KIND.equals(patchBody.documentKind)) {
ResourceOperationResponse r = patch.getBody(ResourceOperationResponse.class);
currentState.completed.add(r);
}
} else if (patchBody.taskInfo.stage == TaskStage.STARTED) {
// don't decrement completions remaining.
} else {
logFine(() -> String.format("ignoring patch from %s", patch.getReferer()));
// ignore status updates from boot/power services
patch.complete();
return;
}
// any operation on state before a operation is completed, is guaranteed
// to be atomic
// (service is synchronized)
logFine(() -> String.format("Remaining %d", currentState.completionsRemaining));
boolean isFinished = currentState.completionsRemaining == 0;
patch.complete();
if (!isFinished) {
return;
}
ServiceTaskCallbackResponse<E> parentPatchBody = currentState.serviceTaskCallback.getFinishedResponse();
if (currentState.failCount > 0) {
double failedRatio = (double) currentState.failCount / (double) (currentState.finishedCount + currentState.failCount + currentState.completionsRemaining);
if (currentState.errorThreshold == 0 || failedRatio > currentState.errorThreshold) {
logWarning(() -> String.format("Notifying parent of task failure: %s (%s)", Utils.toJsonHtml(patchBody.failureMessage), patchBody.taskInfo.stage));
parentPatchBody = currentState.serviceTaskCallback.getFailedResponse(patchBody.taskInfo.failure);
}
}
parentPatchBody.completed = currentState.completed;
parentPatchBody.failures = currentState.failures;
currentState.serviceTaskCallback.sendResponse(this, parentPatchBody);
// we are a one shot task, self DELETE
sendRequest(Operation.createDelete(this, getSelfLink()));
}
Aggregations