Search in sources :

Example 11 with ServiceStateCollectionUpdateRequest

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);
}
Also used : Collection(java.util.Collection) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest)

Example 12 with ServiceStateCollectionUpdateRequest

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);
    }
}
Also used : ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) MatchType(com.vmware.xenon.services.common.QueryTask.QueryTerm.MatchType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Utils(com.vmware.xenon.common.Utils) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) PbmProfile(com.vmware.pbm.PbmProfile) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) Stream(java.util.stream.Stream) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Operation(com.vmware.xenon.common.Operation) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)

Example 13 with ServiceStateCollectionUpdateRequest

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);
}
Also used : Collection(java.util.Collection) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Operation(com.vmware.xenon.common.Operation)

Aggregations

ServiceStateCollectionUpdateRequest (com.vmware.xenon.common.ServiceStateCollectionUpdateRequest)13 Collection (java.util.Collection)13 Operation (com.vmware.xenon.common.Operation)10 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)4 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)4 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)4 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)4 OperationJoin (com.vmware.xenon.common.OperationJoin)4 QueryTask (com.vmware.xenon.services.common.QueryTask)4 List (java.util.List)4 Map (java.util.Map)4 AdapterUtils.createPostOperation (com.vmware.photon.controller.model.adapters.util.AdapterUtils.createPostOperation)3 Utils (com.vmware.xenon.common.Utils)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)2 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)2 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)2