Search in sources :

Example 36 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class VSphereResourcePoolEnumerationHelper method makeDescriptionFromChanges.

private static ComputeDescription makeDescriptionFromChanges(ResourcePoolOverlay rp, String selfLink, String ownerName) {
    ComputeDescription res = new ComputeDescription();
    res.name = rp.getNameOrNull();
    res.documentSelfLink = buildUriPath(ComputeDescriptionService.FACTORY_LINK, UriUtils.getLastPathSegment(selfLink));
    res.totalMemoryBytes = rp.getMemoryReservationBytes();
    return res;
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 37 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription 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 38 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class VSphereVirtualMachineEnumerationHelper method createNewVm.

static void createNewVm(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, VmOverlay vm) {
    ComputeDescription desc = makeDescriptionForVm(service, enumerationProgress, vm);
    desc.tenantLinks = enumerationProgress.getTenantLinks();
    Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeDescriptionService.FACTORY_LINK)).setBody(desc).sendWith(service);
    ComputeState state = makeVmFromResults(enumerationProgress, vm);
    state.descriptionLink = desc.documentSelfLink;
    state.tenantLinks = enumerationProgress.getTenantLinks();
    List<Operation> operations = new ArrayList<>();
    VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
        VsphereEnumerationHelper.populateTags(service, enumerationProgress, vm, state);
        state.networkInterfaceLinks = new ArrayList<>();
        Map<String, List<String>> nicToIPv4Addresses = vm.getMapNic2IpV4Addresses();
        for (VirtualEthernetCard nic : vm.getNics()) {
            VirtualDeviceBackingInfo backing = nic.getBacking();
            if (backing instanceof VirtualEthernetCardNetworkBackingInfo) {
                VirtualEthernetCardNetworkBackingInfo veth = (VirtualEthernetCardNetworkBackingInfo) backing;
                NetworkInterfaceState iface = new NetworkInterfaceState();
                iface.networkLink = enumerationProgress.getNetworkTracker().getSelfLink(veth.getNetwork());
                iface.name = nic.getDeviceInfo().getLabel();
                iface.documentSelfLink = buildUriPath(NetworkInterfaceService.FACTORY_LINK, service.getHost().nextUUID());
                iface.address = getPrimaryIPv4Address(nic, nicToIPv4Addresses);
                CustomProperties.of(iface).put(CustomProperties.DATACENTER_SELF_LINK, enumerationProgress.getDcLink());
                Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), NetworkInterfaceService.FACTORY_LINK)).setBody(iface).sendWith(service);
                state.networkInterfaceLinks.add(iface.documentSelfLink);
            } else if (backing instanceof VirtualEthernetCardDistributedVirtualPortBackingInfo) {
                VirtualEthernetCardDistributedVirtualPortBackingInfo veth = (VirtualEthernetCardDistributedVirtualPortBackingInfo) backing;
                String portgroupKey = veth.getPort().getPortgroupKey();
                Operation op = addNewInterfaceState(service, enumerationProgress, state, portgroupKey, InterfaceStateMode.INTERFACE_STATE_WITH_DISTRIBUTED_VIRTUAL_PORT, SubnetState.class, SubnetState.class, getPrimaryIPv4Address(nic, nicToIPv4Addresses));
                if (op != null) {
                    operations.add(op);
                }
            } else if (backing instanceof VirtualEthernetCardOpaqueNetworkBackingInfo) {
                VirtualEthernetCardOpaqueNetworkBackingInfo veth = (VirtualEthernetCardOpaqueNetworkBackingInfo) backing;
                String opaqueNetworkId = veth.getOpaqueNetworkId();
                Operation op = addNewInterfaceState(service, enumerationProgress, state, opaqueNetworkId, InterfaceStateMode.INTERFACE_STATE_WITH_OPAQUE_NETWORK, NetworkState.class, NetworkState.class, getPrimaryIPv4Address(nic, nicToIPv4Addresses));
                if (op != null) {
                    operations.add(op);
                }
            } else {
                // TODO add support for DVS
                service.logFine(() -> String.format("Will not add nic of type %s", backing.getClass().getName()));
            }
        }
        // Process all the disks attached to the VM
        List<VirtualDevice> disks = vm.getDisks();
        if (CollectionUtils.isNotEmpty(disks)) {
            state.diskLinks = new ArrayList<>(disks.size());
            for (VirtualDevice device : disks) {
                Operation vdOp = processVirtualDevice(service, null, device, enumerationProgress, state.diskLinks, VimUtils.convertMoRefToString(vm.getId()), null);
                if (vdOp != null) {
                    operations.add(vdOp);
                }
            }
        }
        service.logFine(() -> String.format("Found new VM %s", vm.getInstanceUuid()));
        if (operations.isEmpty()) {
            Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeService.FACTORY_LINK)).setBody(state).setCompletion(trackVm(enumerationProgress)).sendWith(service);
        } else {
            OperationJoin.create(operations).setCompletion((operationMap, exception) -> {
                Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeService.FACTORY_LINK)).setBody(state).setCompletion(updateVirtualDisksAndTrackVm(service, enumerationProgress, operationMap)).sendWith(service);
            }).sendWith(service);
        }
    });
}
Also used : ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) VirtualEthernetCardOpaqueNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardOpaqueNetworkBackingInfo) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) URI(java.net.URI) VirtualDevice(com.vmware.vim25.VirtualDevice) NsxProperties(com.vmware.photon.controller.model.adapters.vsphere.network.NsxProperties) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Collectors(java.util.stream.Collectors) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) ClientUtils.handleVirtualDiskUpdate(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.handleVirtualDiskUpdate) List(java.util.List) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) ClientUtils.handleVirtualDeviceUpdate(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.handleVirtualDeviceUpdate) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) DiskService(com.vmware.photon.controller.model.resources.DiskService) VirtualFloppy(com.vmware.vim25.VirtualFloppy) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceCleanRequest(com.vmware.photon.controller.model.adapters.vsphere.VsphereResourceCleanerService.ResourceCleanRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) VirtualEthernetCardDistributedVirtualPortBackingInfo(com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) VirtualEthernetCardNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo) ArrayList(java.util.ArrayList) VirtualCdrom(com.vmware.vim25.VirtualCdrom) ClientUtils.findMatchingDiskState(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingDiskState) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) 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) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TYPE_PORTGROUP(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames.TYPE_PORTGROUP) VirtualDisk(com.vmware.vim25.VirtualDisk) UriUtils.buildUriPath(com.vmware.xenon.common.UriUtils.buildUriPath) InterfaceStateMode(com.vmware.photon.controller.model.adapters.vsphere.VSphereIncrementalEnumerationService.InterfaceStateMode) ObjectUpdate(com.vmware.vim25.ObjectUpdate) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VirtualEthernetCardDistributedVirtualPortBackingInfo(com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo) VirtualEthernetCardNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo) VirtualEthernetCardOpaqueNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardOpaqueNetworkBackingInfo) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) ArrayList(java.util.ArrayList) VirtualDevice(com.vmware.vim25.VirtualDevice) Operation(com.vmware.xenon.common.Operation) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) List(java.util.List) ArrayList(java.util.ArrayList) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard)

Example 39 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class VSphereVirtualMachineEnumerationHelper method makeDescriptionForVm.

static ComputeDescription makeDescriptionForVm(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, VmOverlay vm) {
    ComputeDescription res = new ComputeDescription();
    res.name = vm.getName();
    res.endpointLink = enumerationProgress.getRequest().endpointLink;
    AdapterUtils.addToEndpointLinks(res, enumerationProgress.getRequest().endpointLink);
    res.documentSelfLink = buildUriPath(ComputeDescriptionService.FACTORY_LINK, service.getHost().nextUUID());
    res.instanceAdapterReference = enumerationProgress.getParent().description.instanceAdapterReference;
    res.enumerationAdapterReference = enumerationProgress.getParent().description.enumerationAdapterReference;
    res.statsAdapterReference = enumerationProgress.getParent().description.statsAdapterReference;
    res.powerAdapterReference = enumerationProgress.getParent().description.powerAdapterReference;
    res.diskAdapterReference = enumerationProgress.getParent().description.diskAdapterReference;
    res.regionId = enumerationProgress.getRegionId();
    res.cpuCount = vm.getNumCpu();
    res.totalMemoryBytes = vm.getMemoryBytes();
    return res;
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 40 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class VsphereComputeResourceEnumerationHelper method createNewComputeResource.

private static void createNewComputeResource(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, ComputeResourceOverlay cr, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ComputeDescription desc = makeDescriptionForCluster(service, enumerationProgress, cr);
    desc.tenantLinks = enumerationProgress.getTenantLinks();
    Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeDescriptionService.FACTORY_LINK)).setBody(desc).sendWith(service);
    ComputeState state = makeComputeResourceFromResults(enumerationProgress, cr, client);
    state.tenantLinks = enumerationProgress.getTenantLinks();
    state.descriptionLink = desc.documentSelfLink;
    submitWorkToVSpherePool(service, () -> {
        VsphereEnumerationHelper.populateTags(service, enumerationProgress, cr, state);
        service.logFine(() -> String.format("Found new ComputeResource %s", cr.getId().getValue()));
        Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeService.FACTORY_LINK)).setBody(state).setCompletion(trackComputeResource(enumerationProgress, cr)).sendWith(service);
    });
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Aggregations

ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)78 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)39 Operation (com.vmware.xenon.common.Operation)21 ArrayList (java.util.ArrayList)21 QueryTask (com.vmware.xenon.services.common.QueryTask)17 Test (org.junit.Test)17 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)15 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)15 List (java.util.List)15 Utils (com.vmware.xenon.common.Utils)14 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)14 URI (java.net.URI)14 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)13 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)12 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)12 UriUtils (com.vmware.xenon.common.UriUtils)12 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)11 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)11