use of com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState 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);
}
}));
}
}
Aggregations