Search in sources :

Example 91 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class VSphereResourcePoolEnumerationHelper method makeResourcePoolFromResults.

private static ComputeState makeResourcePoolFromResults(EnumerationProgress enumerationProgress, ResourcePoolOverlay rp, String selfLink, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
    ComputeState state = new ComputeState();
    state.documentSelfLink = selfLink;
    state.name = rp.getName();
    state.id = rp.getId().getValue();
    state.type = ComputeType.VM_HOST;
    state.powerState = PowerState.ON;
    state.endpointLink = request.endpointLink;
    AdapterUtils.addToEndpointLinks(state, request.endpointLink);
    state.regionId = enumerationProgress.getRegionId();
    state.parentLink = enumerationProgress.getRequest().resourceLink();
    state.resourcePoolLink = request.resourcePoolLink;
    state.adapterManagementReference = request.adapterManagementReference;
    ManagedObjectReference owner = rp.getOwner();
    AbstractOverlay ov = enumerationProgress.getOverlay(owner);
    if (ov instanceof ComputeResourceOverlay) {
        ComputeResourceOverlay cr = (ComputeResourceOverlay) ov;
        state.groupLinks = VsphereEnumerationHelper.getConnectedDatastoresAndNetworks(enumerationProgress, cr.getDatastore(), cr.getNetwork(), client);
    } else if (ov instanceof HostSystemOverlay) {
        HostSystemOverlay cr = (HostSystemOverlay) ov;
        state.groupLinks = VsphereEnumerationHelper.getConnectedDatastoresAndNetworks(enumerationProgress, cr.getDatastore(), cr.getNetwork(), client);
    }
    CustomProperties.of(state).put(CustomProperties.MOREF, rp.getId()).put(CustomProperties.DATACENTER_SELF_LINK, enumerationProgress.getDcLink()).put(CustomProperties.TYPE, VimNames.TYPE_RESOURCE_POOL);
    VsphereEnumerationHelper.populateResourceStateWithAdditionalProps(state, enumerationProgress.getVcUuid());
    return state;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 92 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class VSphereResourcePoolEnumerationHelper method updateResourcePool.

private static void updateResourcePool(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, String ownerName, String selfLink, ResourcePoolOverlay rp, boolean fullUpdate, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ComputeState state;
    ComputeDescription desc;
    if (fullUpdate) {
        state = makeResourcePoolFromResults(enumerationProgress, rp, selfLink, client);
        state.name = rp.makeUserFriendlyName(ownerName);
        state.tenantLinks = enumerationProgress.getTenantLinks();
        state.resourcePoolLink = null;
        desc = makeDescriptionForResourcePool(enumerationProgress, rp, selfLink);
    } else {
        state = makeResourcePoolFromChanges(rp, selfLink, ownerName);
        desc = makeDescriptionFromChanges(rp, selfLink, ownerName);
    }
    state.descriptionLink = desc.documentSelfLink;
    service.logFine(() -> String.format("Refreshed ResourcePool %s", state.name));
    Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), selfLink)).setBody(state).setCompletion(trackResourcePool(enumerationProgress, rp)).sendWith(service);
    Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), desc.documentSelfLink)).setBody(desc).sendWith(service);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 93 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class VSphereResourcePoolEnumerationHelper method handleResourcePoolChanges.

public static void handleResourcePoolChanges(VSphereIncrementalEnumerationService service, List<ResourcePoolOverlay> resourcePools, EnumerationProgress enumerationProgress, EnumerationClient client) {
    ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
    enumerationProgress.expectResourcePoolCount(resourcePools.size());
    for (ResourcePoolOverlay resourcePool : resourcePools) {
        // no need to collect the root resource pool
        if (ObjectUpdateKind.ENTER.equals(resourcePool.getObjectUpdateKind()) && VimNames.TYPE_RESOURCE_POOL.equals(resourcePool.getParent().getType())) {
            String ownerMoRefId = resourcePool.getOwner().getValue();
            QueryTask task = queryForRPOwner(ownerMoRefId, enumerationProgress);
            String selfLink = buildStableResourcePoolLink(resourcePool.getId(), request.endpointLink);
            withTaskResults(service, task, result -> {
                try {
                    if (!result.documentLinks.isEmpty()) {
                        ComputeState ownerDocument = convertOnlyResultToDocument(result, ComputeState.class);
                        createNewResourcePool(service, enumerationProgress, ownerDocument.name, selfLink, resourcePool, client);
                    } else {
                        // This happens for the resource pools within Host. The owner is a ComputeResource and
                        // is not currently enumerated in photon
                        createNewResourcePool(service, enumerationProgress, null, selfLink, resourcePool, client);
                    }
                } catch (Exception e) {
                    enumerationProgress.getResourcePoolTracker().track();
                }
            });
        } else {
            String rpSelfLink = buildStableResourcePoolLink(resourcePool.getId(), request.endpointLink);
            Operation.createGet(PhotonModelUriUtils.createInventoryUri(service.getHost(), rpSelfLink)).setCompletion((o, e) -> {
                try {
                    if (e == null) {
                        ComputeState oldState = o.getBody(ComputeState.class);
                        String existingOwnerName = getOwnerNameFromResourcePoolName(oldState.name);
                        if (ObjectUpdateKind.MODIFY.equals(resourcePool.getObjectUpdateKind())) {
                            updateResourcePool(service, enumerationProgress, existingOwnerName, oldState.documentSelfLink, resourcePool, false, client);
                        } else {
                            Operation.createDelete(PhotonModelUriUtils.createInventoryUri(service.getHost(), rpSelfLink)).setCompletion(trackResourcePool(enumerationProgress, resourcePool)).sendWith(service);
                        }
                    } else {
                        enumerationProgress.getResourcePoolTracker().track();
                    }
                } catch (Exception ex) {
                    enumerationProgress.getResourcePoolTracker().track();
                }
            }).sendWith(service);
        }
    }
    try {
        enumerationProgress.getResourcePoolTracker().await();
    } catch (InterruptedException e) {
        service.logSevere("Interrupted during incremental enumeration for resource pools!", e);
    }
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) 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) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) List(java.util.List) UriUtils.buildUriPath(com.vmware.xenon.common.UriUtils.buildUriPath) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) 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) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException)

Example 94 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class BasePowerContext method updateComputeState.

/**
 * Updates the compute state with the new power state
 */
private DeferredResult<CONTEXT> updateComputeState(CONTEXT context) {
    ComputeState state = new ComputeState();
    state.powerState = context.request.powerState;
    Operation op = Operation.createPatch(context.request.resourceReference).setBody(state);
    return this.service.sendWithDeferredResult(op).thenApply(ignore -> context);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Operation(com.vmware.xenon.common.Operation)

Example 95 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class InstanceClient method createInstanceFromTemplate.

public ComputeState createInstanceFromTemplate(ManagedObjectReference template) throws Exception {
    ManagedObjectReference vm = cloneVm(template);
    if (vm == null) {
        // vm was created by someone else
        return null;
    }
    // store reference to created vm for further processing
    this.vm = vm;
    customizeAfterClone();
    ComputeState state = new ComputeState();
    state.resourcePoolLink = VimUtils.firstNonNull(this.ctx.child.resourcePoolLink, this.ctx.parent.resourcePoolLink);
    return state;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)214 Operation (com.vmware.xenon.common.Operation)93 ArrayList (java.util.ArrayList)63 QueryTask (com.vmware.xenon.services.common.QueryTask)58 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)57 HashMap (java.util.HashMap)54 List (java.util.List)51 Map (java.util.Map)50 Utils (com.vmware.xenon.common.Utils)45 Test (org.junit.Test)45 UriUtils (com.vmware.xenon.common.UriUtils)44 URI (java.net.URI)42 Collectors (java.util.stream.Collectors)42 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)40 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)40 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)40 StatelessService (com.vmware.xenon.common.StatelessService)40 Query (com.vmware.xenon.services.common.QueryTask.Query)40 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)38 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)36