Search in sources :

Example 71 with QueryTask

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();
        }
    });
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)

Example 72 with QueryTask

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);
    }
}
Also used : STORAGE_USED_BYTES(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_USED_BYTES) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) ServiceDocument(com.vmware.xenon.common.ServiceDocument) HashMap(java.util.HashMap) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) CUSTOM_PROP_STORAGE_SHARED(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_PROP_STORAGE_SHARED) Utils(com.vmware.xenon.common.Utils) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) StatsUtil(com.vmware.photon.controller.model.tasks.monitoring.StatsUtil) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) SingleResourceStatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService) TimeUnit(java.util.concurrent.TimeUnit) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) STORAGE_AVAILABLE_BYTES(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_AVAILABLE_BYTES) List(java.util.List) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) UriUtils(com.vmware.xenon.common.UriUtils) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) QueryTask(com.vmware.xenon.services.common.QueryTask) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService)

Example 73 with QueryTask

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);
        }
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)

Example 74 with QueryTask

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);
        }
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 75 with QueryTask

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);
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

QueryTask (com.vmware.xenon.services.common.QueryTask)147 Query (com.vmware.xenon.services.common.QueryTask.Query)62 Operation (com.vmware.xenon.common.Operation)61 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)39 ArrayList (java.util.ArrayList)26 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)20 List (java.util.List)20 ResourceMetrics (com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)19 UriUtils (com.vmware.xenon.common.UriUtils)18 Utils (com.vmware.xenon.common.Utils)17 HashSet (java.util.HashSet)16 HashMap (java.util.HashMap)14 QueryOption (com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption)12 TimeUnit (java.util.concurrent.TimeUnit)12 ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)11 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)11 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)11 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)11 URI (java.net.URI)11 Set (java.util.Set)11