use of com.vmware.xenon.common.ServiceStateCollectionUpdateRequest in project photon-model by vmware.
the class VSphereComputeDiskManagementService method updateComputeDiskLinks.
/**
* Invoke PUT operation on compute to remove the disk link from the links.
*/
private Operation updateComputeDiskLinks(VSphereVMDiskContext ctx) {
Map<String, Collection<Object>> collectionToRemove = Collections.singletonMap(ComputeService.ComputeState.FIELD_NAME_DISK_LINKS, Collections.singletonList(ctx.diskState.documentSelfLink));
ServiceStateCollectionUpdateRequest updateDiskLinksRequest = ServiceStateCollectionUpdateRequest.create(null, collectionToRemove);
return Operation.createPatch(PhotonModelUriUtils.createInventoryUri(this.getHost(), ctx.computeDesc.documentSelfLink)).setBody(updateDiskLinksRequest);
}
use of com.vmware.xenon.common.ServiceStateCollectionUpdateRequest in project photon-model by vmware.
the class VsphereStoragePolicyEnumerationHelper method updateStorageDescription.
static void updateStorageDescription(VSphereIncrementalEnumerationService service, Stream<Operation> opStream, String spSelfLink, ServiceDocumentQueryResult result) {
List<Operation> patchOps = new ArrayList<>();
List<String> originalLinks = new ArrayList<>();
if (result.documentLinks != null) {
originalLinks.addAll(result.documentLinks);
}
opStream.forEach(op -> {
StorageDescription storageDescription = op.getBody(StorageDescription.class);
if (result.documentLinks != null && result.documentLinks.contains(storageDescription.documentSelfLink)) {
originalLinks.remove(storageDescription.documentSelfLink);
} else {
if (storageDescription.groupLinks == null) {
storageDescription.groupLinks = new HashSet<>();
}
storageDescription.groupLinks.add(spSelfLink);
patchOps.add(Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), storageDescription.documentSelfLink)).setBody(storageDescription));
}
});
// In this case, we need to update the datastore by removing the policy group link
if (!originalLinks.isEmpty()) {
originalLinks.stream().forEach(link -> {
Map<String, Collection<Object>> collectionsToRemove = Collections.singletonMap(ResourceState.FIELD_NAME_GROUP_LINKS, Collections.singletonList(spSelfLink));
ServiceStateCollectionUpdateRequest updateGroupLinksRequest = ServiceStateCollectionUpdateRequest.create(null, collectionsToRemove);
patchOps.add(Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), link)).setBody(updateGroupLinksRequest));
});
}
if (!patchOps.isEmpty()) {
OperationJoin.create(patchOps).setCompletion((ops, exs) -> {
if (exs != null) {
service.logFine(() -> String.format("Syncing Storage policy failed %s", Utils.toString(exs)));
}
}).sendWith(service);
}
}
use of com.vmware.xenon.common.ServiceStateCollectionUpdateRequest in project photon-model by vmware.
the class TagsUtil method updateResourceTagLinks.
/**
* Private method used to generate structure containing the tag states to add and tag states to
* remove to the specified resource state (specified by its document self link).
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private static DeferredResult<Void> updateResourceTagLinks(StatelessService service, Collection<String> tagLinksToDelete, Collection<String> tagLinksToAdd, String currentStateSelfLink) {
if (tagLinksToAdd != null && tagLinksToAdd.contains(null)) {
service.logSevere("Null tag link found for ResourceState: %s", currentStateSelfLink);
service.logSevere("Removing null tag link from tagLinksToAdd.");
tagLinksToAdd.remove(null);
}
// nothing to add/update
if (tagLinksToDelete.isEmpty() && tagLinksToAdd.isEmpty()) {
return DeferredResult.completed((Void) null);
}
// create patch operation to update tag links of the current resource state
Map<String, Collection<Object>> collectionsToRemoveMap = Collections.singletonMap(ComputeState.FIELD_NAME_TAG_LINKS, (Collection) tagLinksToDelete);
Map<String, Collection<Object>> collectionsToAddMap = Collections.singletonMap(ComputeState.FIELD_NAME_TAG_LINKS, (Collection) tagLinksToAdd);
ServiceStateCollectionUpdateRequest updateTagLinksRequest = ServiceStateCollectionUpdateRequest.create(collectionsToAddMap, collectionsToRemoveMap);
Operation updatePatch = Operation.createPatch(createInventoryUri(service.getHost(), currentStateSelfLink)).setBody(updateTagLinksRequest).setReferer(service.getUri());
return service.sendWithDeferredResult(updatePatch).thenApply(ignore -> (Void) null);
}
Aggregations