Search in sources :

Example 66 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createCapacityResponse.

@Override
public List<CapacityResponse> createCapacityResponse(final List<? extends Capacity> result, final DecimalFormat format) {
    final List<CapacityResponse> capacityResponses = new ArrayList<>();
    for (final Capacity summedCapacity : result) {
        final CapacityResponse capacityResponse = new CapacityResponse();
        capacityResponse.setCapacityTotal(summedCapacity.getTotalCapacity());
        capacityResponse.setCapacityType(summedCapacity.getCapacityType());
        capacityResponse.setCapacityUsed(summedCapacity.getUsedCapacity());
        if (summedCapacity.getPodId() != null) {
            capacityResponse.setPodId(ApiDBUtils.findPodById(summedCapacity.getPodId()).getUuid());
            final HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId());
            if (pod != null) {
                capacityResponse.setPodId(pod.getUuid());
                capacityResponse.setPodName(pod.getName());
            }
        }
        if (summedCapacity.getClusterId() != null) {
            final ClusterVO cluster = ApiDBUtils.findClusterById(summedCapacity.getClusterId());
            if (cluster != null) {
                capacityResponse.setClusterId(cluster.getUuid());
                capacityResponse.setClusterName(cluster.getName());
                if (summedCapacity.getPodId() == null) {
                    final HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId());
                    capacityResponse.setPodId(pod.getUuid());
                    capacityResponse.setPodName(pod.getName());
                }
            }
        }
        final DataCenter zone = ApiDBUtils.findZoneById(summedCapacity.getDataCenterId());
        if (zone != null) {
            capacityResponse.setZoneId(zone.getUuid());
            capacityResponse.setZoneName(zone.getName());
        }
        if (summedCapacity.getUsedPercentage() != null) {
            capacityResponse.setPercentageAllocated(format.format(summedCapacity.getUsedPercentage() * 100f));
        } else if (summedCapacity.getTotalCapacity() != 0) {
            capacityResponse.setPercentageAllocated(format.format((float) summedCapacity.getUsedCapacity() / (float) summedCapacity.getTotalCapacity() * 100f));
        } else {
            capacityResponse.setPercentageAllocated(format.format(0L));
        }
        capacityResponse.setObjectName("capacity");
        capacityResponses.add(capacityResponse);
    }
    final List<VgpuTypesInfo> gpuCapacities;
    if (result.size() > 1 && (gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
        final HashMap<String, Long> vgpuVMs = ApiDBUtils.getVgpuVmsCount(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId());
        float capacityUsed = 0;
        long capacityMax = 0;
        for (final VgpuTypesInfo capacity : gpuCapacities) {
            if (vgpuVMs.containsKey(capacity.getGroupName().concat(capacity.getModelName()))) {
                capacityUsed += (float) vgpuVMs.get(capacity.getGroupName().concat(capacity.getModelName())) / capacity.getMaxVpuPerGpu();
            }
            if (capacity.getModelName().equals(GPU.GPUType.passthrough.toString())) {
                capacityMax += capacity.getMaxCapacity();
            }
        }
        final DataCenter zone = ApiDBUtils.findZoneById(result.get(0).getDataCenterId());
        final CapacityResponse capacityResponse = new CapacityResponse();
        if (zone != null) {
            capacityResponse.setZoneId(zone.getUuid());
            capacityResponse.setZoneName(zone.getName());
        }
        if (result.get(0).getPodId() != null) {
            final HostPodVO pod = ApiDBUtils.findPodById(result.get(0).getPodId());
            capacityResponse.setPodId(pod.getUuid());
            capacityResponse.setPodName(pod.getName());
        }
        if (result.get(0).getClusterId() != null) {
            final ClusterVO cluster = ApiDBUtils.findClusterById(result.get(0).getClusterId());
            capacityResponse.setClusterId(cluster.getUuid());
            capacityResponse.setClusterName(cluster.getName());
        }
        capacityResponse.setCapacityType(Capacity.CAPACITY_TYPE_GPU);
        capacityResponse.setCapacityUsed((long) Math.ceil(capacityUsed));
        capacityResponse.setCapacityTotal(capacityMax);
        if (capacityMax > 0) {
            capacityResponse.setPercentageAllocated(format.format(capacityUsed / capacityMax * 100f));
        } else {
            capacityResponse.setPercentageAllocated(format.format(0));
        }
        capacityResponse.setObjectName("capacity");
        capacityResponses.add(capacityResponse);
    }
    return capacityResponses;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) DataCenter(com.cloud.dc.DataCenter) CapacityResponse(com.cloud.api.response.CapacityResponse) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) Capacity(com.cloud.capacity.Capacity) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo)

Example 67 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class RecreateHostAllocator method allocateTo.

@Override
public List<Host> allocateTo(final VirtualMachineProfile vm, final DeploymentPlan plan, final Type type, final ExcludeList avoid, final int returnUpTo) {
    List<Host> hosts = super.allocateTo(vm, plan, type, avoid, returnUpTo);
    if (hosts != null && !hosts.isEmpty()) {
        return hosts;
    }
    s_logger.debug("First fit was unable to find a host");
    final VirtualMachine.Type vmType = vm.getType();
    if (vmType == VirtualMachine.Type.User) {
        s_logger.debug("vm is not a system vm so let's just return empty list");
        return new ArrayList<>();
    }
    final DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    final List<PodCluster> pcs = _resourceMgr.listByDataCenter(dc.getId());
    // basic network type for zone maps to direct untagged case
    if (dc.getNetworkType().equals(NetworkType.Basic)) {
        s_logger.debug("Direct Networking mode so we can only allow the host to be allocated in the same pod due to public ip address cannot change");
        final List<VolumeVO> vols = _volsDao.findByInstance(vm.getId());
        final VolumeVO vol = vols.get(0);
        final long podId = vol.getPodId();
        s_logger.debug("Pod id determined from volume " + vol.getId() + " is " + podId);
        final Iterator<PodCluster> it = pcs.iterator();
        while (it.hasNext()) {
            final PodCluster pc = it.next();
            if (pc.getPod().getId() != podId) {
                it.remove();
            }
        }
    }
    final Set<Pair<Long, Long>> avoidPcs = new HashSet<>();
    final Set<Long> hostIdsToAvoid = avoid.getHostsToAvoid();
    if (hostIdsToAvoid != null) {
        for (final Long hostId : hostIdsToAvoid) {
            final Host h = _hostDao.findById(hostId);
            if (h != null) {
                avoidPcs.add(new Pair<>(h.getPodId(), h.getClusterId()));
            }
        }
    }
    for (final Pair<Long, Long> pcId : avoidPcs) {
        s_logger.debug("Removing " + pcId + " from the list of available pods");
        pcs.remove(new PodCluster(new HostPodVO(pcId.first()), pcId.second() != null ? new ClusterVO(pcId.second()) : null));
    }
    for (final PodCluster p : pcs) {
        if (p.getPod().getAllocationState() != AllocationState.Enabled) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Pod name: " + p.getPod().getName() + ", podId: " + p.getPod().getId() + " is in " + p.getPod().getAllocationState().name() + " state, skipping this and trying other pods");
            }
            continue;
        }
        final Long clusterId = p.getCluster() == null ? null : p.getCluster().getId();
        if (p.getCluster() != null && p.getCluster().getAllocationState() != AllocationState.Enabled) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Cluster name: " + p.getCluster().getName() + ", clusterId: " + clusterId + " is in " + p.getCluster().getAllocationState().name() + " state, skipping this and trying other pod-clusters");
            }
            continue;
        }
        final DataCenterDeployment newPlan = new DataCenterDeployment(plan.getDataCenterId(), p.getPod().getId(), clusterId, null, null, null);
        hosts = super.allocateTo(vm, newPlan, type, avoid, returnUpTo);
        if (hosts != null && !hosts.isEmpty()) {
            return hosts;
        }
    }
    s_logger.debug("Unable to find any available pods at all!");
    return new ArrayList<>();
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host) HostPodVO(com.cloud.dc.HostPodVO) DataCenter(com.cloud.dc.DataCenter) VolumeVO(com.cloud.storage.VolumeVO) PodCluster(com.cloud.dc.PodCluster) VirtualMachine(com.cloud.vm.VirtualMachine) Pair(com.cloud.utils.Pair) HashSet(java.util.HashSet)

Example 68 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class FirstFitPlanner method orderClusters.

@Override
public List<Long> orderClusters(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid) throws InsufficientServerCapacityException {
    final VirtualMachine vm = vmProfile.getVirtualMachine();
    final Zone zone = zoneRepository.findOne(vm.getDataCenterId());
    // check if datacenter is in avoid set
    if (avoid.shouldAvoid(zone)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("DataCenter id = '" + zone.getId() + "' provided is in avoid set, DeploymentPlanner cannot allocate the VM, returning.");
        }
        return null;
    }
    List<Long> clusterList = new ArrayList<>();
    if (plan.getClusterId() != null) {
        final Long clusterIdSpecified = plan.getClusterId();
        s_logger.debug("Searching resources only under specified Cluster: " + clusterIdSpecified);
        final ClusterVO cluster = clusterDao.findById(plan.getClusterId());
        if (cluster != null) {
            if (avoid.shouldAvoid(cluster)) {
                s_logger.debug("The specified cluster is in avoid set, returning.");
            } else {
                clusterList.add(clusterIdSpecified);
                removeClustersCrossingThreshold(clusterList, avoid, vmProfile, plan);
            }
        } else {
            s_logger.debug("The specified cluster cannot be found, returning.");
            avoid.addCluster(plan.getClusterId());
            return null;
        }
    } else if (plan.getPodId() != null) {
        // consider clusters under this pod only
        final Long podIdSpecified = plan.getPodId();
        s_logger.debug("Searching resources only under specified Pod: " + podIdSpecified);
        final HostPodVO pod = podDao.findById(podIdSpecified);
        if (pod != null) {
            if (avoid.shouldAvoid(pod)) {
                s_logger.debug("The specified pod is in avoid set, returning.");
            } else {
                clusterList = scanClustersForDestinationInZoneOrPod(podIdSpecified, false, vmProfile, plan, avoid);
                if (clusterList == null) {
                    avoid.addPod(plan.getPodId());
                }
            }
        } else {
            s_logger.debug("The specified Pod cannot be found, returning.");
            avoid.addPod(plan.getPodId());
            return null;
        }
    } else {
        s_logger.debug("Searching all possible resources under this Zone: " + plan.getDataCenterId());
        final boolean applyAllocationAtPods = Boolean.parseBoolean(configDao.getValue(Config.ApplyAllocationAlgorithmToPods.key()));
        if (applyAllocationAtPods) {
            // start scan at all pods under this zone.
            clusterList = scanPodsForDestination(vmProfile, plan, avoid);
        } else {
            // start scan at clusters under this zone.
            clusterList = scanClustersForDestinationInZoneOrPod(plan.getDataCenterId(), true, vmProfile, plan, avoid);
        }
    }
    if (clusterList != null && !clusterList.isEmpty()) {
        final ServiceOffering offering = vmProfile.getServiceOffering();
        // In case of non-GPU VMs, protect GPU enabled Hosts and prefer VM deployment on non-GPU Hosts.
        if ((serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString()) == null) && !(hostGpuGroupsDao.listHostIds().isEmpty())) {
            final int requiredCpu = offering.getCpu();
            final long requiredRam = offering.getRamSize() * 1024L * 1024L;
            reorderClustersBasedOnImplicitTags(clusterList, requiredCpu, requiredRam);
        }
    }
    return clusterList;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ServiceOffering(com.cloud.offering.ServiceOffering) Zone(com.cloud.db.model.Zone) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 69 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class LibvirtServerDiscoverer method createHostVOForConnectedAgent.

@Override
public HostVO createHostVOForConnectedAgent(final HostVO host, final StartupCommand[] cmd) {
    final StartupCommand firstCmd = cmd[0];
    if (!(firstCmd instanceof StartupRoutingCommand)) {
        return null;
    }
    final StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
    if (ssCmd.getHypervisorType() != getHypervisorType()) {
        return null;
    }
    /* KVM requires host are the same in cluster */
    final ClusterVO clusterVO = _clusterDao.findById(host.getClusterId());
    if (clusterVO == null) {
        s_logger.debug("cannot find cluster: " + host.getClusterId());
        throw new IllegalArgumentException("cannot add host, due to can't find cluster: " + host.getClusterId());
    }
    final List<HostVO> hostsInCluster = _resourceMgr.listAllHostsInCluster(clusterVO.getId());
    if (!hostsInCluster.isEmpty()) {
        final HostVO oneHost = hostsInCluster.get(0);
        _hostDao.loadDetails(oneHost);
        final String hostOsInCluster = oneHost.getDetail("Host.OS");
        final String hostOs = ssCmd.getHostDetails().get("Host.OS");
        if (!hostOsInCluster.equalsIgnoreCase(hostOs)) {
            throw new IllegalArgumentException("Can't add host: " + firstCmd.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster," + "in which there are " + hostOsInCluster + " hosts added");
        }
    }
    _hostDao.loadDetails(host);
    return _resourceMgr.fillRoutingHostVO(host, ssCmd, getHypervisorType(), host.getDetails(), null);
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) ClusterVO(com.cloud.dc.ClusterVO) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) HostVO(com.cloud.host.HostVO)

Example 70 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method searchForClusters.

@Override
public List<? extends Cluster> searchForClusters(long zoneId, final Long startIndex, final Long pageSizeVal, final String hypervisorType) {
    final Filter searchFilter = new Filter(ClusterVO.class, "id", true, startIndex, pageSizeVal);
    final SearchCriteria<ClusterVO> sc = _clusterDao.createSearchCriteria();
    zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
    sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
    sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisorType);
    return _clusterDao.search(sc, searchFilter);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Filter(com.cloud.utils.db.Filter)

Aggregations

ClusterVO (com.cloud.dc.ClusterVO)151 HostVO (com.cloud.host.HostVO)72 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)66 ArrayList (java.util.ArrayList)55 HostPodVO (com.cloud.dc.HostPodVO)46 DataCenterVO (com.cloud.dc.DataCenterVO)38 ConfigurationException (javax.naming.ConfigurationException)37 HashMap (java.util.HashMap)28 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)24 Map (java.util.Map)24 DiscoveryException (com.cloud.exception.DiscoveryException)21 DB (com.cloud.utils.db.DB)21 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)20 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 Account (com.cloud.user.Account)17 List (java.util.List)17 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)17 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)16 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)15 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)14