use of com.vmware.photon.controller.model.adapters.vsphere.VsphereResourceCleanerService.ResourceCleanRequest in project photon-model by vmware.
the class VSphereIncrementalEnumerationService method garbageCollectUntouchedComputeResources.
private void garbageCollectUntouchedComputeResources(ComputeEnumerateResourceRequest request, Set<String> untouchedResources, TaskManager mgr) {
if (untouchedResources.isEmpty()) {
mgr.patchTask(TaskStage.FINISHED);
return;
}
if (!request.preserveMissing) {
// delete dependent resources without waiting for response
for (String resourceLink : untouchedResources) {
Operation.createDelete(PhotonModelUriUtils.createInventoryUri(getHost(), resourceLink)).sendWith(this);
}
mgr.patchTask(TaskStage.FINISHED);
return;
}
List<Operation> deleteOps = new ArrayList<>();
for (String resourceLink : untouchedResources) {
if (resourceLink.startsWith(ComputeService.FACTORY_LINK)) {
ResourceCleanRequest patch = new ResourceCleanRequest();
patch.resourceLink = resourceLink;
deleteOps.add(Operation.createPatch(this, VSphereUriPaths.RESOURCE_CLEANER).setBody(patch));
} else {
deleteOps.add(Operation.createDelete(PhotonModelUriUtils.createInventoryUri(getHost(), resourceLink)));
}
}
OperationJoin.create(deleteOps).setCompletion((os, es) -> mgr.patchTask(TaskStage.FINISHED)).sendWith(this);
}
use of com.vmware.photon.controller.model.adapters.vsphere.VsphereResourceCleanerService.ResourceCleanRequest in project photon-model by vmware.
the class VSphereVirtualMachineEnumerationHelper method deleteVM.
private static void deleteVM(EnumerationProgress enumerationProgress, VmOverlay vmOverlay, VSphereIncrementalEnumerationService service, ServiceDocument oldDocument) {
if (!enumerationProgress.getRequest().preserveMissing) {
Operation.createDelete(PhotonModelUriUtils.createInventoryUri(service.getHost(), oldDocument.documentSelfLink)).setCompletion((o, e) -> {
trackVm(enumerationProgress).handle(o, e);
}).sendWith(service);
} else {
ResourceCleanRequest patch = new ResourceCleanRequest();
patch.resourceLink = oldDocument.documentSelfLink;
Operation.createPatch(service, VSphereUriPaths.RESOURCE_CLEANER).setBody(patch).setCompletion((o, e) -> {
trackVm(enumerationProgress).handle(o, e);
}).sendWith(service);
}
}
Aggregations