Search in sources :

Example 11 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class DeploymentPlanningManagerImpl method findPotentialDeploymentResources.

protected Pair<Host, Map<Volume, StoragePool>> findPotentialDeploymentResources(final List<Host> suitableHosts, final Map<Volume, List<StoragePool>> suitableVolumeStoragePools, final ExcludeList avoid, final DeploymentPlanner.PlannerResourceUsage resourceUsageRequired, List<Volume> readyAndReusedVolumes) {
    s_logger.debug("Trying to find a potenial host and associated storage pools from the suitable host/pool lists for this VM");
    boolean hostCanAccessPool = false;
    boolean haveEnoughSpace = false;
    if (readyAndReusedVolumes == null) {
        readyAndReusedVolumes = new ArrayList<>();
    }
    final Map<Volume, StoragePool> storage = new HashMap<>();
    final TreeSet<Volume> volumesOrderBySizeDesc = new TreeSet<>(new Comparator<Volume>() {

        @Override
        public int compare(final Volume v1, final Volume v2) {
            if (v1.getSize() < v2.getSize()) {
                return 1;
            } else {
                return -1;
            }
        }
    });
    volumesOrderBySizeDesc.addAll(suitableVolumeStoragePools.keySet());
    final boolean multipleVolume = volumesOrderBySizeDesc.size() > 1;
    for (final Host potentialHost : suitableHosts) {
        final Map<StoragePool, List<Volume>> volumeAllocationMap = new HashMap<>();
        for (final Volume vol : volumesOrderBySizeDesc) {
            haveEnoughSpace = false;
            s_logger.debug("Checking if host: " + potentialHost.getId() + " can access any suitable storage pool for volume: " + vol.getVolumeType());
            final List<StoragePool> volumePoolList = suitableVolumeStoragePools.get(vol);
            hostCanAccessPool = false;
            for (final StoragePool potentialSPool : volumePoolList) {
                if (!_storageMgr.storagePoolHasEnoughIops(Collections.singletonList(vol), potentialSPool)) {
                    continue;
                }
                if (hostCanAccessSPool(potentialHost, potentialSPool)) {
                    hostCanAccessPool = true;
                    if (multipleVolume && !readyAndReusedVolumes.contains(vol)) {
                        List<Volume> requestVolumes = null;
                        if (volumeAllocationMap.containsKey(potentialSPool)) {
                            requestVolumes = volumeAllocationMap.get(potentialSPool);
                        } else {
                            requestVolumes = new ArrayList<>();
                        }
                        requestVolumes.add(vol);
                        if (!_storageMgr.storagePoolHasEnoughSpace(requestVolumes, potentialSPool)) {
                            continue;
                        }
                        volumeAllocationMap.put(potentialSPool, requestVolumes);
                    }
                    storage.put(vol, potentialSPool);
                    haveEnoughSpace = true;
                    break;
                }
            }
            if (!hostCanAccessPool) {
                break;
            }
            if (!haveEnoughSpace) {
                s_logger.warn("insufficient capacity to allocate all volumes");
                break;
            }
        }
        if (hostCanAccessPool && haveEnoughSpace && checkIfHostFitsPlannerUsage(potentialHost.getId(), resourceUsageRequired)) {
            s_logger.debug("Found a potential host " + "id: " + potentialHost.getId() + " name: " + potentialHost.getName() + " and associated storage pools for this VM");
            return new Pair<>(potentialHost, storage);
        } else {
            avoid.addHost(potentialHost.getId());
        }
    }
    s_logger.debug("Could not find a potential host that has associated storage pools from the suitable host/pool lists for this VM");
    return null;
}
Also used : StoragePool(com.cloud.legacymodel.storage.StoragePool) HashMap(java.util.HashMap) Host(com.cloud.legacymodel.dc.Host) Volume(com.cloud.legacymodel.storage.Volume) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) Pair(com.cloud.legacymodel.utils.Pair)

Example 12 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class ConsoleProxyManagerImpl method isZoneReady.

public boolean isZoneReady(final Map<Long, ZoneHostInfo> zoneHostInfoMap, final long dataCenterId) {
    final ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId);
    if (zoneHostInfo != null && isZoneHostReady(zoneHostInfo)) {
        final VMTemplateVO template = this._templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
        if (template == null) {
            logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch console proxy vm");
            return false;
        }
        final TemplateDataStoreVO templateHostRef = this._vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dataCenterId, VMTemplateStatus.DOWNLOADED);
        if (templateHostRef != null) {
            boolean useLocalStorage = false;
            final Boolean useLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId);
            if (useLocal != null) {
                useLocalStorage = useLocal.booleanValue();
            }
            final List<Pair<Long, Integer>> l = this._consoleProxyDao.getDatacenterStoragePoolHostInfo(dataCenterId, useLocalStorage);
            if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
                return true;
            } else {
                logger.debug("Primary storage is not ready, wait until it is ready to launch console proxy");
            }
        } else {
            logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage.");
        }
    }
    return false;
}
Also used : ZoneHostInfo(com.cloud.consoleproxy.RunningHostInfoAgregator.ZoneHostInfo) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) Pair(com.cloud.legacymodel.utils.Pair)

Example 13 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class ConsoleProxyManagerImpl method assignProxyFromRunningPool.

public ConsoleProxyVO assignProxyFromRunningPool(final long dataCenterId) {
    logger.trace("Assign console proxy from running pool for request from data center : " + dataCenterId);
    final ConsoleProxyAllocator allocator = getCurrentAllocator();
    assert (allocator != null);
    final List<ConsoleProxyVO> runningList = this._consoleProxyDao.getProxyListInStates(dataCenterId, State.Running);
    if (runningList != null && runningList.size() > 0) {
        final Iterator<ConsoleProxyVO> it = runningList.iterator();
        while (it.hasNext()) {
            final ConsoleProxyVO proxy = it.next();
            if (proxy.getActiveSession() >= this._capacityPerProxy) {
                it.remove();
            }
        }
        logger.trace("Running proxy pool size : " + runningList.size());
        for (final ConsoleProxyVO proxy : runningList) {
            logger.trace("Running proxy instance : " + proxy.getHostName());
        }
        final List<Pair<Long, Integer>> l = this._consoleProxyDao.getProxyLoadMatrix();
        final Map<Long, Integer> loadInfo = new HashMap<>();
        if (l != null) {
            for (final Pair<Long, Integer> p : l) {
                loadInfo.put(p.first(), p.second());
                logger.trace("Running proxy instance allocation load { proxy id : " + p.first() + ", load : " + p.second() + "}");
            }
        }
        final Long allocated = allocator.allocProxy(runningList, loadInfo, dataCenterId);
        if (allocated == null) {
            logger.debug("Unable to find a console proxy ");
            return null;
        }
        return this._consoleProxyDao.findById(allocated);
    } else {
        logger.trace("Empty running proxy pool for now in data center : " + dataCenterId);
    }
    return null;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) Pair(com.cloud.legacymodel.utils.Pair)

Example 14 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class DedicatedResourceManagerImpl method listDedicatedClusters.

@Override
public Pair<List<? extends DedicatedResourceVO>, Integer> listDedicatedClusters(final ListDedicatedClustersCmd cmd) {
    final Long clusterId = cmd.getClusterId();
    final Long domainId = cmd.getDomainId();
    final String accountName = cmd.getAccountName();
    Long accountId = null;
    final Long affinityGroupId = cmd.getAffinityGroupId();
    if (accountName != null) {
        if (domainId != null) {
            final Account account = _accountDao.findActiveAccount(accountName, domainId);
            if (account != null) {
                accountId = account.getId();
            }
        } else {
            throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName);
        }
    }
    final Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedClusters(clusterId, domainId, accountId, affinityGroupId);
    return new Pair<>(result.first(), result.second());
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) List(java.util.List) ArrayList(java.util.ArrayList) Pair(com.cloud.legacymodel.utils.Pair)

Example 15 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class NetworkServiceImpl method listTrafficTypes.

@Override
public Pair<List<? extends PhysicalNetworkTrafficType>, Integer> listTrafficTypes(final Long physicalNetworkId) {
    final PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
    if (network == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
        ex.addProxyObject(physicalNetworkId.toString(), "physicalNetworkId");
        throw ex;
    }
    final Pair<List<PhysicalNetworkTrafficTypeVO>, Integer> result = _pNTrafficTypeDao.listAndCountBy(physicalNetworkId);
    return new Pair<>(result.first(), result.second());
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.legacymodel.utils.Pair)

Aggregations

Pair (com.cloud.legacymodel.utils.Pair)139 ArrayList (java.util.ArrayList)87 List (java.util.List)64 Account (com.cloud.legacymodel.user.Account)49 Filter (com.cloud.utils.db.Filter)48 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)38 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)27 HashMap (java.util.HashMap)27 Ternary (com.cloud.legacymodel.utils.Ternary)23 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)22 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)20 SSHKeyPair (com.cloud.legacymodel.user.SSHKeyPair)16 TemplateFilter (com.cloud.legacymodel.storage.VirtualMachineTemplate.TemplateFilter)13 Map (java.util.Map)13 DB (com.cloud.utils.db.DB)11 DomainVO (com.cloud.domain.DomainVO)10 VolumeVO (com.cloud.storage.VolumeVO)10 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)9 Network (com.cloud.legacymodel.network.Network)9 ResourceTagVO (com.cloud.tags.ResourceTagVO)9