Search in sources :

Example 11 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class VSphereVirtualMachineEnumerationHelper method handleVMChanges.

public static void handleVMChanges(VSphereIncrementalEnumerationService service, List<ObjectUpdate> resourcesUpdates, EnumerationProgress enumerationProgress, EnumerationClient client) {
    List<VmOverlay> vmOverlays = new ArrayList<>();
    for (ObjectUpdate objectUpdate : resourcesUpdates) {
        if (VimUtils.isVirtualMachine(objectUpdate.getObj())) {
            VmOverlay vm = new VmOverlay(objectUpdate);
            if (vm.getInstanceUuid() != null || !objectUpdate.getKind().equals(ObjectUpdateKind.ENTER)) {
                vmOverlays.add(vm);
            }
        }
    }
    for (VmOverlay vmOverlay : vmOverlays) {
        if (ObjectUpdateKind.ENTER == vmOverlay.getObjectUpdateKind()) {
            createNewVm(service, enumerationProgress, vmOverlay);
        } else {
            ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
            QueryTask task = queryForVm(enumerationProgress, request.resourceLink(), null, vmOverlay.getId());
            VsphereEnumerationHelper.withTaskResults(service, task, result -> {
                if (!result.documentLinks.isEmpty()) {
                    ComputeState oldDocument = VsphereEnumerationHelper.convertOnlyResultToDocument(result, ComputeState.class);
                    if (ObjectUpdateKind.MODIFY == vmOverlay.getObjectUpdateKind()) {
                        updateVm(service, oldDocument, enumerationProgress, vmOverlay, false);
                    } else {
                        deleteVM(enumerationProgress, vmOverlay, service, oldDocument);
                    }
                } else {
                    enumerationProgress.getVmTracker().arrive();
                }
            });
        }
    }
}
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) ArrayList(java.util.ArrayList) ObjectUpdate(com.vmware.vim25.ObjectUpdate)

Example 12 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class VSphereVirtualMachineEnumerationHelper method processFoundVm.

static void processFoundVm(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, VmOverlay vm) {
    long latestAcceptableModification = System.currentTimeMillis() - VM_FERMENTATION_PERIOD_MILLIS;
    ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
    QueryTask task = queryForVm(enumerationProgress, request.resourceLink(), vm.getInstanceUuid(), vm.getId());
    VsphereEnumerationHelper.withTaskResults(service, task, result -> {
        if (result.documentLinks.isEmpty()) {
            if (vm.getLastReconfigureMillis() < latestAcceptableModification) {
                // If vm is not settled down don't create a new resource
                createNewVm(service, enumerationProgress, vm);
            } else {
                enumerationProgress.getVmTracker().arrive();
            }
        } else {
            // always update state of a vm even if modified recently
            ComputeState oldDocument = VsphereEnumerationHelper.convertOnlyResultToDocument(result, ComputeState.class);
            updateVm(service, oldDocument, enumerationProgress, vm, true);
        }
    });
}
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 13 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class VsphereComputeResourceEnumerationHelper method handleComputeResourceChanges.

public static void handleComputeResourceChanges(VSphereIncrementalEnumerationService service, List<ComputeResourceOverlay> computeResourceOverlays, EnumerationProgress ctx, EnumerationClient client) {
    ctx.expectComputeResourceCount(computeResourceOverlays.size());
    // process compute resource changes
    for (ComputeResourceOverlay cluster : computeResourceOverlays) {
        try {
            service.logInfo("Handling compute resource change %s", Utils.toJson(cluster));
            // TODO If a host is part of cluster then the host needs to be populated with cluster link.
            if (ObjectUpdateKind.ENTER == cluster.getObjectUpdateKind()) {
                // create a cluster object only for DRS enabled clusters
                if (cluster.isDrsEnabled()) {
                    service.logInfo("Creating new cluster for %s", Utils.toJson(cluster));
                    createNewComputeResource(service, ctx, cluster, client);
                }
            } else {
                // If an existing compute resource is modified or removed.
                ComputeEnumerateResourceRequest request = ctx.getRequest();
                QueryTask task = queryForCluster(ctx, request.resourceLink(), cluster.getId().getValue());
                withTaskResults(service, task, result -> {
                    service.logInfo("Queried for existing clusters for %s", Utils.toJson(cluster));
                    try {
                        if (!result.documentLinks.isEmpty()) {
                            ComputeState oldDocument = convertOnlyResultToDocument(result, ComputeState.class);
                            // check if the compute resource is modified.
                            if (ObjectUpdateKind.MODIFY.equals(cluster.getObjectUpdateKind())) {
                                service.logInfo("Updating existing cluster for %s", Utils.toJson(cluster));
                                updateCluster(service, oldDocument, ctx, cluster, client, false);
                            } else {
                                // Compute resource has been removed. remove the compute resource from photon model here
                                // Delete only compute state document as compute description can be shared among compute resources.
                                service.logInfo("Deleting existing cluster for %s", Utils.toJson(cluster));
                                Operation.createDelete(PhotonModelUriUtils.createInventoryUri(service.getHost(), oldDocument.documentSelfLink)).setCompletion((o, e) -> {
                                    trackComputeResource(ctx, cluster).handle(o, e);
                                }).sendWith(service);
                            }
                        } else {
                            ctx.getComputeResourceTracker().track();
                        }
                    } catch (Exception ex) {
                        service.logSevere("Error occurred while processing update of compute resource!", ex);
                        ctx.getComputeResourceTracker().track(cluster.getId(), ResourceTracker.ERROR);
                    }
                });
            }
        } catch (Exception e) {
            service.logSevere("Error occurred while processing update of compute resource!", e);
            ctx.getComputeResourceTracker().track(cluster.getId(), ResourceTracker.ERROR);
        }
    }
    // checkpoint compute resource
    try {
        ctx.getComputeResourceTracker().await();
    } catch (InterruptedException e) {
        service.logSevere("Interrupted during incremental enumeration for networks!", e);
    }
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) 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) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ArrayList(java.util.ArrayList) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) Utils(com.vmware.xenon.common.Utils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) TYPE_SERVER_DISK(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames.TYPE_SERVER_DISK) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) VsanHostConfigInfo(com.vmware.vim25.VsanHostConfigInfo) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) VsphereEnumerationHelper.getConnectedDatastoresAndNetworks(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.getConnectedDatastoresAndNetworks) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VsphereEnumerationHelper.updateLocalTags(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.updateLocalTags) List(java.util.List) VsphereEnumerationHelper.submitWorkToVSpherePool(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.submitWorkToVSpherePool) UriUtils.buildUriPath(com.vmware.xenon.common.UriUtils.buildUriPath) HostScsiDisk(com.vmware.vim25.HostScsiDisk) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) DiskService(com.vmware.photon.controller.model.resources.DiskService) Collections(java.util.Collections) 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 14 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest 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 15 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class VsphereDatastoreEnumerationHelper method createNewStorageDescription.

private static void createNewStorageDescription(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, DatastoreOverlay ds) {
    ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
    String regionId = enumerationProgress.getRegionId();
    StorageDescription desc = makeStorageFromResults(request, ds, regionId, enumerationProgress);
    desc.tenantLinks = enumerationProgress.getTenantLinks();
    service.logFine(() -> String.format("Found new Datastore %s", ds.getName()));
    VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
        VsphereEnumerationHelper.populateTags(service, enumerationProgress, ds, desc);
        Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), StorageDescriptionService.FACTORY_LINK)).setBody(desc).setCompletion((o, e) -> {
            trackDatastore(enumerationProgress, ds).handle(o, e);
            Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ResourceGroupService.FACTORY_LINK)).setBody(makeStorageGroup(ds, enumerationProgress)).sendWith(service);
            updateStorageStats(service, ds, o.getBody(ServiceDocument.class).documentSelfLink);
        }).sendWith(service);
    });
}
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) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceDocument(com.vmware.xenon.common.ServiceDocument) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)

Aggregations

ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)29 QueryTask (com.vmware.xenon.services.common.QueryTask)16 Operation (com.vmware.xenon.common.Operation)12 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)11 List (java.util.List)11 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)10 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)10 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)10 Utils (com.vmware.xenon.common.Utils)10 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)9 VsphereEnumerationHelper.convertOnlyResultToDocument (com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument)8 VsphereEnumerationHelper.withTaskResults (com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults)8 ObjectUpdateKind (com.vmware.vim25.ObjectUpdateKind)8 CompletionHandler (com.vmware.xenon.common.Operation.CompletionHandler)8 UriUtils (com.vmware.xenon.common.UriUtils)8 Map (java.util.Map)8 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)7 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)7 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)7 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)7