use of com.vmware.xenon.common.ServiceStateCollectionUpdateRequest in project photon-model by vmware.
the class AWSComputeDescriptionEnumerationAdapterService method updateComputeDescriptionOperation.
private Operation updateComputeDescriptionOperation(InstanceDescKey cd, AWSComputeDescriptionCreationServiceContext context) {
Map<String, Collection<Object>> collectionsToAddMap = Collections.singletonMap(ComputeDescription.FIELD_NAME_ENDPOINT_LINKS, Collections.singletonList(context.cdState.endpointLink));
ServiceStateCollectionUpdateRequest updateEndpointLinksRequest = ServiceStateCollectionUpdateRequest.create(collectionsToAddMap, null);
return Operation.createPatch(this.getHost(), context.localComputeDescriptionMap.get(cd).documentSelfLink).setReferer(this.getHost().getUri()).setBody(updateEndpointLinksRequest);
}
use of com.vmware.xenon.common.ServiceStateCollectionUpdateRequest in project photon-model by vmware.
the class AzureComputeDiskDay2Service method updateComputeState.
/**
* Update the diskLink of DiskState in ComputeState
*/
private DeferredResult<Operation> updateComputeState(AzureComputeDiskDay2Context context) {
Map<String, Collection<Object>> collectionsToModify = Collections.singletonMap(ComputeState.FIELD_NAME_DISK_LINKS, Collections.singletonList(context.diskState.documentSelfLink));
Map<String, Collection<Object>> collectionsToAdd = null;
Map<String, Collection<Object>> collectionsToRemove = null;
ComputeState computeState = context.computeState;
if (context.request.operation.equals(ResourceOperation.ATTACH_DISK.operation)) {
collectionsToAdd = collectionsToModify;
} else if (context.request.operation.equals(ResourceOperation.DETACH_DISK.operation)) {
collectionsToRemove = collectionsToModify;
}
ServiceStateCollectionUpdateRequest updateDiskLinksRequest = ServiceStateCollectionUpdateRequest.create(collectionsToAdd, collectionsToRemove);
Operation computeStateOp = Operation.createPatch(createInventoryUri(this.getHost(), computeState.documentSelfLink)).setBody(updateDiskLinksRequest).setReferer(this.getUri());
return this.sendWithDeferredResult(computeStateOp);
}
use of com.vmware.xenon.common.ServiceStateCollectionUpdateRequest in project photon-model by vmware.
the class PhotonModelUtils method createRemoveEndpointLinksOperation.
/**
* Utility method to create an operation to remove an endpointLink from the endpointLinks set of
* the resourceState and also update the endpointLink property of the specific resourceState
*/
public static <T extends ResourceState> Operation createRemoveEndpointLinksOperation(Service service, String endpointLink, T resource) {
if (resource.endpointLinks == null || !resource.endpointLinks.contains(endpointLink)) {
return null;
}
Map<String, Collection<Object>> endpointsToRemoveMap = Collections.singletonMap(EndpointService.EndpointState.FIELD_NAME_ENDPOINT_LINKS, Collections.singleton(endpointLink));
ServiceStateCollectionUpdateRequest serviceStateCollectionUpdateRequest = ServiceStateCollectionUpdateRequest.create(null, endpointsToRemoveMap);
return Operation.createPatch(createInventoryUri(service.getHost(), resource.documentSelfLink)).setReferer(service.getUri()).setBody(serviceStateCollectionUpdateRequest).setCompletion((updateOp, exception) -> {
if (exception != null) {
service.getHost().log(Level.WARNING, () -> String.format("PATCH " + "to instance service %s, failed: %s", updateOp.getUri(), exception.toString()));
return;
}
service.getHost().log(Level.FINE, () -> String.format("PATCH to " + "update endpointLink in endpointLinks " + "to instance service %s finished successfully", updateOp.getUri()));
String resourceEndpointLink = getEndpointLink(resource);
if (resourceEndpointLink != null) {
// if the endpoint being deleted is the endpointLink of the
// resourceState, then assign a new endpointLink
updateEndpointLink(service, endpointLink, resource.documentSelfLink, resourceEndpointLink, resource.endpointLinks);
}
});
}
use of com.vmware.xenon.common.ServiceStateCollectionUpdateRequest in project photon-model by vmware.
the class ResourceGroomerTaskService method deleteDisassociatePatchStaleDocuments.
/**
* Deletes documents that have no endpointLinks associated with them.
* Disassociate documents if they have invalid endpointLinks by sending a collection update
* patch.
*/
private void deleteDisassociatePatchStaleDocuments(EndpointResourceDeletionRequest task, SubStage next) {
if (task.documentsToBeDeletedLinks.isEmpty() && task.endpointLinksByDocumentsToBeDisassociated.isEmpty()) {
task.subStage = next;
sendSelfPatch(task);
return;
}
List<Operation> deletePatchOperations = new ArrayList<>();
task.documentsToBeDeletedLinks.stream().forEach(documentLink -> {
deletePatchOperations.add(Operation.createDelete(this.getHost(), documentLink).setReferer(this.getHost().getUri()));
});
task.endpointLinksByDocumentsToBeDisassociated.entrySet().stream().forEach(entry -> {
Map<String, Collection<Object>> itemsToRemove = Collections.singletonMap(ResourceState.FIELD_NAME_ENDPOINT_LINKS, new ArrayList<>(entry.getValue()));
ServiceStateCollectionUpdateRequest request = ServiceStateCollectionUpdateRequest.create(null, itemsToRemove);
deletePatchOperations.add(Operation.createPatch(this.getHost(), entry.getKey()).setBody(request).setReferer(this.getUri()));
logInfo("Removing endpointLinks: %s from resource: %s", entry.getValue(), entry.getKey());
});
task.endpointLinkToBePatchedByDocumentLinks.entrySet().stream().forEach(entry -> {
if (entry.getKey().startsWith(ResourceGroupService.FACTORY_LINK) || entry.getKey().startsWith(AuthCredentialsService.FACTORY_LINK)) {
deletePatchOperations.add(createResourceGroupEndpointLinkPatchOp(entry.getKey(), entry.getValue()));
} else {
deletePatchOperations.add(createEndpointLinkPatchOp(entry.getKey(), entry.getValue()));
}
logInfo("Changing endpointLink to %s from resource: %s", entry.getValue(), entry.getKey());
});
logInfo("Deleting stale documents that have invalid endpointLinks. [documentCount=%s]", task.documentsToBeDeletedLinks.size());
logInfo("Patching stale documents that have invalid endpointLinks list. [documentCount=%s]", task.endpointLinksByDocumentsToBeDisassociated.size());
logInfo("Patching stale documents that have invalid endpointLink. [documentCount=%s]", task.endpointLinkToBePatchedByDocumentLinks.size());
task.documentsDeletedCount += task.documentsToBeDeletedLinks.size();
task.endpointLinksPatchedCount += task.endpointLinksByDocumentsToBeDisassociated.size();
task.endpointLinkPatchedCount += task.endpointLinkToBePatchedByDocumentLinks.size();
OperationJoin.create(deletePatchOperations).setCompletion((o, e) -> {
if (e != null) {
task.failureMessage = e.values().iterator().next().getMessage();
task.subStage = SubStage.FAILED;
sendSelfFailurePatch(task, task.failureMessage);
return;
}
task.subStage = next;
sendSelfPatch(task);
}).sendWith(this, OPERATION_BATCH_SIZE);
}
use of com.vmware.xenon.common.ServiceStateCollectionUpdateRequest in project photon-model by vmware.
the class AWSUtils method updateComputeState.
/**
* Add or remove diskLink from ComputeState by sending a ServiceStateCollectionUpdateRequest.
*/
public static DeferredResult<Operation> updateComputeState(String computeStateLink, List<String> diskLinks, String operation, Service service) {
Map<String, Collection<Object>> collectionsToModify = Collections.singletonMap(ComputeService.ComputeState.FIELD_NAME_DISK_LINKS, new ArrayList<>(diskLinks));
Map<String, Collection<Object>> collectionsToAdd = null;
Map<String, Collection<Object>> collectionsToRemove = null;
if (operation.equals(ResourceOperation.ATTACH_DISK.operation)) {
collectionsToAdd = collectionsToModify;
} else {
// DETACH case
collectionsToRemove = collectionsToModify;
}
ServiceStateCollectionUpdateRequest updateDiskLinksRequest = ServiceStateCollectionUpdateRequest.create(collectionsToAdd, collectionsToRemove);
Operation computeStateOp = Operation.createPatch(createInventoryUri(service.getHost(), computeStateLink)).setBody(updateDiskLinksRequest).setReferer(service.getUri());
return service.sendWithDeferredResult(computeStateOp);
}
Aggregations