use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class VSphereHostSystemEnumerationHelper method processFoundHostSystem.
/**
* Process all the host system retrieved from the endpoint.
*/
public static void processFoundHostSystem(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, HostSystemOverlay hs, EnumerationClient client) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
QueryTask task = queryForHostSystem(enumerationProgress, request.resourceLink(), hs.getId().getValue());
withTaskResults(service, task, result -> {
try {
if (result.documentLinks.isEmpty()) {
createNewHostSystem(service, enumerationProgress, hs, client);
} else {
ComputeState oldDocument = convertOnlyResultToDocument(result, ComputeState.class);
updateHostSystem(service, oldDocument, enumerationProgress, hs, true, client);
}
} catch (Exception e) {
service.logSevere("Error occurred while processing host system!", e);
enumerationProgress.getHostSystemTracker().track();
}
});
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class VsphereDatastoreEnumerationHelper method handleDatastoreChanges.
/**
* Handles changes to datastores. Changes to name, capacity and free space are handled.
* new datastore addition and existing datastore deletion is handled.
*
* @param service the vsphere incremental service
* @param datastores the list of datastore overlays
* @param enumerationProgress the context of enumeration
*/
public static void handleDatastoreChanges(VSphereIncrementalEnumerationService service, List<DatastoreOverlay> datastores, EnumerationProgress enumerationProgress) {
enumerationProgress.expectDatastoreCount(datastores.size());
for (DatastoreOverlay datastore : datastores) {
// check if its a new datastore
if (ObjectUpdateKind.ENTER == datastore.getObjectUpdateKind()) {
createNewStorageDescription(service, enumerationProgress, datastore);
} else {
// "name" may not necessarily present in the object update. so passed as "null"
QueryTask task = queryForStorage(enumerationProgress, null, VimUtils.convertMoRefToString(datastore.getId()), null);
withTaskResults(service, task, result -> {
if (!result.documentLinks.isEmpty()) {
// Object is either modified or deleted
StorageDescriptionService.StorageDescription oldDocument = convertOnlyResultToDocument(result, StorageDescriptionService.StorageDescription.class);
// if the data store is modified
if (ObjectUpdateKind.MODIFY == datastore.getObjectUpdateKind()) {
// Handle the property changes here
updateStorageDescription(service, oldDocument, enumerationProgress, datastore, false);
} else {
// if it's not modified, it should've been deleted in the vCenter.
// So, delete the document from photon store
Operation.createDelete(PhotonModelUriUtils.createInventoryUri(service.getHost(), oldDocument.documentSelfLink)).setCompletion((o, e) -> {
enumerationProgress.getDatastoreTracker().track();
}).sendWith(service);
}
} else {
enumerationProgress.getDatastoreTracker().track();
}
});
}
}
try {
enumerationProgress.getDatastoreTracker().await();
} catch (InterruptedException e) {
service.logSevere("Interrupted during incremental enumeration for networks!", e);
}
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class VsphereDatastoreEnumerationHelper method processFoundDatastore.
public static void processFoundDatastore(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, DatastoreOverlay ds) {
QueryTask task = queryForStorage(enumerationProgress, ds.getName(), VimUtils.convertMoRefToString(ds.getId()), null);
withTaskResults(service, task, result -> {
if (result.documentLinks.isEmpty()) {
createNewStorageDescription(service, enumerationProgress, ds);
} else {
StorageDescription oldDocument = convertOnlyResultToDocument(result, StorageDescription.class);
updateStorageDescription(service, oldDocument, enumerationProgress, ds, true);
}
});
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class VsphereDatacenterEnumerationHelper method processDatacenterInfo.
static void processDatacenterInfo(VSphereIncrementalEnumerationService service, Element element, EnumerationProgress ctx) {
QueryTask task = queryForDatacenter(ctx, element.object.getValue());
withTaskResults(service, task, (ServiceDocumentQueryResult result) -> {
if (result.documentLinks.isEmpty()) {
createDatacenter(service, ctx, element);
} else {
ResourceGroupService.ResourceGroupState oldDocument = convertOnlyResultToDocument(result, ResourceGroupService.ResourceGroupState.class);
updateDatacenter(service, ctx, element, oldDocument);
}
});
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class VsphereStoragePolicyEnumerationHelper method updateDataStoreWithStoragePolicyGroup.
static void updateDataStoreWithStoragePolicyGroup(VSphereIncrementalEnumerationService service, EnumerationProgress ctx, StoragePolicyOverlay sp, String selfLink) {
List<Operation> getOps = new ArrayList<>();
sp.getDatastoreIds().stream().forEach(id -> {
if (null != ctx.getDatastoreTracker()) {
String dataStoreLink = ctx.getDatastoreTracker().getSelfLink(id, VimNames.TYPE_DATASTORE);
if (dataStoreLink != null && !ResourceTracker.ERROR.equals(dataStoreLink)) {
getOps.add(Operation.createGet(PhotonModelUriUtils.createInventoryUri(service.getHost(), dataStoreLink)));
}
} else {
ManagedObjectReference dataStoreMoref = new ManagedObjectReference();
dataStoreMoref.setType(VimNames.TYPE_DATASTORE);
dataStoreMoref.setValue(id);
QueryTask task = VsphereDatastoreEnumerationHelper.queryForStorage(ctx, null, VimUtils.convertMoRefToString(dataStoreMoref), selfLink);
VsphereEnumerationHelper.withTaskResults(service, task, result -> {
List<Operation> getOperations = new ArrayList<>();
if (result.documentLinks.size() > 0) {
for (String documentSelfLink : result.documentLinks) {
getOperations.add(Operation.createGet(PhotonModelUriUtils.createInventoryUri(service.getHost(), documentSelfLink)));
}
// TODO : Refactor this to avoid extra call to fetch datastores
updateDS(service, ctx, selfLink, getOperations);
}
});
}
});
updateDS(service, ctx, selfLink, getOps);
}
Aggregations