use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class ResourceRemovalTaskService method deallocateIpAddressesForResources.
private void deallocateIpAddressesForResources(ResourceRemovalTaskState currentState, QueryTask queryTask, String subTaskLink) {
// handle empty pages
if (queryTask.results.documentCount == 0) {
sendSelfPatch(TaskState.TaskStage.FINISHED, SubStage.FINISHED, null);
return;
}
if (subTaskLink == null) {
createSubTaskForIpDeallocationCallbacks(currentState, queryTask, link -> deallocateIpAddressesForResources(currentState, queryTask, link));
return;
}
logFine("Starting ip deallocation of %d compute resources using sub task", queryTask.results.documentCount);
// for each compute resource link in the results, call ResourceIPDeallocationTaskService
for (String resourceLink : queryTask.results.documentLinks) {
ResourceIPDeallocationTaskState deallocateTask = new ResourceIPDeallocationTaskState();
deallocateTask.resourceLink = resourceLink;
deallocateTask.tenantLinks = currentState.tenantLinks;
deallocateTask.serviceTaskCallback = ServiceTaskCallback.create(UriUtils.buildPublicUri(getHost(), subTaskLink));
deallocateTask.serviceTaskCallback.onSuccessFinishTask();
// Similar to instance deletes - a failure for one network interface deallocate will fail the task
deallocateTask.serviceTaskCallback.onErrorFailTask();
this.sendRequest(Operation.createPost(this, ResourceIPDeallocationTaskService.FACTORY_LINK).setBody(deallocateTask).setCompletion((o, ex) -> {
if (ex != null) {
logSevere("Failure deallocating IPs for resource: [%s]: %s", resourceLink, ex);
ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.finish(resourceLink);
sendPatch(subTaskLink, subTaskPatchBody);
} else {
logFine("Sent deallocation IPs request for resource [%s]", resourceLink);
}
}));
}
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class ResourceRemovalTaskService method doInstanceDeletes.
private void doInstanceDeletes(ResourceRemovalTaskState currentState, QueryTask queryTask, String subTaskLink) {
// handle empty pages
if (queryTask.results.documentCount == 0) {
sendSelfPatch(currentState.taskInfo.stage, SubStage.DEALLOCATE_IP_ADDRESSES, s -> {
s.nextPageLink = null;
});
return;
}
if (subTaskLink == null) {
createSubTaskForDeleteCallbacks(currentState, queryTask, link -> doInstanceDeletes(currentState, queryTask, link));
return;
}
logFine(() -> String.format("Starting delete of %d compute resources using sub task %s", queryTask.results.documentLinks.size(), subTaskLink));
// a DELETE request to its associated instance service.
for (String resourceLink : queryTask.results.documentLinks) {
URI u = ComputeStateWithDescription.buildUri(UriUtils.buildUri(getHost(), resourceLink));
sendRequest(Operation.createGet(u).setCompletion((o, e) -> {
if (e != null) {
// we do not fail task if one delete failed ...
// send a FINISHED patch which is what a sub task
// would do. Since the
// current state
// is still at REMOVING_RESOURCES, we will just
// increment a counter
ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.fail(resourceLink, e);
sendPatch(subTaskLink, subTaskPatchBody);
return;
}
sendInstanceDelete(resourceLink, subTaskLink, o, currentState);
}));
}
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class AWSPowerServiceTest method changePowerState.
private void changePowerState(ComputeDescription cd, String computeLink, PowerState powerState) {
String taskLink = UUID.randomUUID().toString();
ComputePowerRequest powerRequest = new ComputePowerRequest();
powerRequest.isMockRequest = this.isMock;
powerRequest.powerState = powerState;
powerRequest.resourceReference = UriUtils.buildUri(this.host, computeLink);
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(cd.powerAdapterReference).setBody(powerRequest).setReferer("/boza").setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(powerOp);
ctx.await();
ComputeState compute = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeLink));
assertEquals(powerState, compute.powerState);
if (PowerState.OFF.equals(powerState)) {
assertTrue(compute.address.isEmpty());
}
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class TaskManager method createTaskPatch.
public Operation createTaskPatch(TaskStage stage) {
ResourceOperationResponse body = ResourceOperationResponse.finish(this.resourceLink);
body.taskInfo.stage = stage;
return Operation.createPatch(this.taskReference).setBody(body);
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class BaseVSphereAdapterTest method createSnapshotAndWaitFailure.
protected void createSnapshotAndWaitFailure(ComputeState vm) throws Throwable {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest snapshotRequest = getCreateSnapshotRequest(ResourceOperation.CREATE_SNAPSHOT.operation, vm.documentSelfLink, taskLink);
Operation createSnapshotOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterSnapshotService.SELF_LINK)).setBody(snapshotRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> Assert.assertNull(e));
TestContext ctx2 = this.host.testCreate(1);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Service.Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx2.completeIteration();
return true;
} else {
ctx2.completeIteration();
return false;
}
});
this.host.send(createSnapshotOp);
ctx2.await();
}
Aggregations