Search in sources :

Example 1 with AffinityGroupDomainMapVO

use of com.cloud.affinity.AffinityGroupDomainMapVO in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method listDomainLevelAffinityGroups.

private List<AffinityGroupJoinVO> listDomainLevelAffinityGroups(final SearchCriteria<AffinityGroupJoinVO> sc, final Filter searchFilter, final long domainId) {
    final List<Long> affinityGroupIds = new ArrayList<>();
    final Set<Long> allowedDomains = _domainMgr.getDomainParentIds(domainId);
    final List<AffinityGroupDomainMapVO> maps = _affinityGroupDomainMapDao.listByDomain(allowedDomains.toArray());
    for (final AffinityGroupDomainMapVO map : maps) {
        final boolean subdomainAccess = map.isSubdomainAccess();
        if (map.getDomainId() == domainId || subdomainAccess) {
            affinityGroupIds.add(map.getAffinityGroupId());
        }
    }
    if (!affinityGroupIds.isEmpty()) {
        final SearchCriteria<AffinityGroupJoinVO> domainSC = _affinityGroupJoinDao.createSearchCriteria();
        domainSC.addAnd("id", SearchCriteria.Op.IN, affinityGroupIds.toArray());
        domainSC.addAnd("aclType", SearchCriteria.Op.EQ, ACLType.Domain.toString());
        sc.addAnd("id", SearchCriteria.Op.SC, domainSC);
        final Pair<List<AffinityGroupJoinVO>, Integer> uniqueGroupsPair = _affinityGroupJoinDao.searchAndCount(sc, searchFilter);
        // search group by ids
        final Integer count = uniqueGroupsPair.second();
        if (count.intValue() == 0) {
            // empty result
            return new ArrayList<>();
        }
        final List<AffinityGroupJoinVO> uniqueGroups = uniqueGroupsPair.first();
        final Long[] vrIds = new Long[uniqueGroups.size()];
        int i = 0;
        for (final AffinityGroupJoinVO v : uniqueGroups) {
            vrIds[i++] = v.getId();
        }
        final List<AffinityGroupJoinVO> vrs = _affinityGroupJoinDao.searchByIds(vrIds);
        return vrs;
    } else {
        return new ArrayList<>();
    }
}
Also used : ArrayList(java.util.ArrayList) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) AffinityGroupDomainMapVO(com.cloud.affinity.AffinityGroupDomainMapVO)

Example 2 with AffinityGroupDomainMapVO

use of com.cloud.affinity.AffinityGroupDomainMapVO in project cosmic by MissionCriticalCloud.

the class DeploymentPlanningManagerImpl method checkForNonDedicatedResources.

private void checkForNonDedicatedResources(final VirtualMachineProfile vmProfile, final Zone zone, final ExcludeList avoids) {
    boolean isExplicit = false;
    final VirtualMachine vm = vmProfile.getVirtualMachine();
    // check if zone is dedicated. if yes check if vm owner has access to it.
    final DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(zone.getId());
    if (dedicatedZone != null && !_accountMgr.isRootAdmin(vmProfile.getOwner().getId())) {
        final long accountDomainId = vmProfile.getOwner().getDomainId();
        final long accountId = vmProfile.getOwner().getAccountId();
        // account will be to use explicit dedication affinity group.
        if (dedicatedZone.getAccountId() != null) {
            if (dedicatedZone.getAccountId().equals(accountId)) {
                return;
            } else {
                throw new CloudRuntimeException("Failed to deploy VM, Zone " + zone.getName() + " not available for the user account " + vmProfile.getOwner());
            }
        }
        // domain level dedication group
        if (!_affinityGroupService.isAffinityGroupAvailableInDomain(dedicatedZone.getAffinityGroupId(), accountDomainId)) {
            throw new CloudRuntimeException("Failed to deploy VM, Zone " + zone.getName() + " not available for the user domain " + vmProfile.getOwner());
        }
    }
    // check affinity group of type Explicit dedication exists. If No put
    // dedicated pod/cluster/host in avoid list
    final List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), "ExplicitDedication");
    if (vmGroupMappings != null && !vmGroupMappings.isEmpty()) {
        isExplicit = true;
    }
    final List<Long> allPodsInDc = _podDao.listAllPods(zone.getId());
    final List<Long> allDedicatedPods = _dedicatedDao.listAllPods();
    allPodsInDc.retainAll(allDedicatedPods);
    final List<Long> allClustersInDc = _clusterDao.listAllCusters(zone.getId());
    final List<Long> allDedicatedClusters = _dedicatedDao.listAllClusters();
    allClustersInDc.retainAll(allDedicatedClusters);
    final List<Long> allHostsInDc = _hostDao.listAllHosts(zone.getId());
    final List<Long> allDedicatedHosts = _dedicatedDao.listAllHosts();
    allHostsInDc.retainAll(allDedicatedHosts);
    // Only when the type is instance VM and not explicitly dedicated.
    if (vm.getType() == VirtualMachine.Type.User && !isExplicit) {
        // add explicitly dedicated resources in avoidList
        avoids.addPodList(allPodsInDc);
        avoids.addClusterList(allClustersInDc);
        avoids.addHostList(allHostsInDc);
    }
    // No need to check the isExplicit. As both the cases are handled.
    if (vm.getType() == VirtualMachine.Type.DomainRouter) {
        final long vmAccountId = vm.getAccountId();
        final long vmDomainId = vm.getDomainId();
        // Lists all explicitly dedicated resources from vm account ID or domain ID.
        final List<Long> allPodsFromDedicatedID = new ArrayList<>();
        final List<Long> allClustersFromDedicatedID = new ArrayList<>();
        final List<Long> allHostsFromDedicatedID = new ArrayList<>();
        // Whether the dedicated resources belong to Domain or not. If not, it may belongs to Account or no dedication.
        final List<AffinityGroupDomainMapVO> domainGroupMappings = _affinityGroupDomainMapDao.listByDomain(vmDomainId);
        // For temporary storage and indexing.
        List<DedicatedResourceVO> tempStorage;
        if (domainGroupMappings == null || domainGroupMappings.isEmpty()) {
            // The dedicated resource belongs to VM Account ID.
            tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, vmAccountId, null).first();
            for (final DedicatedResourceVO vo : tempStorage) {
                allPodsFromDedicatedID.add(vo.getPodId());
            }
            tempStorage.clear();
            tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, vmAccountId, null).first();
            for (final DedicatedResourceVO vo : tempStorage) {
                allClustersFromDedicatedID.add(vo.getClusterId());
            }
            tempStorage.clear();
            tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, vmAccountId, null).first();
            for (final DedicatedResourceVO vo : tempStorage) {
                allHostsFromDedicatedID.add(vo.getHostId());
            }
            // Remove the dedicated ones from main list
            allPodsInDc.removeAll(allPodsFromDedicatedID);
            allClustersInDc.removeAll(allClustersFromDedicatedID);
            allHostsInDc.removeAll(allHostsFromDedicatedID);
        } else {
            // The dedicated resource belongs to VM Domain ID or No dedication.
            tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, null, null).first();
            for (final DedicatedResourceVO vo : tempStorage) {
                allPodsFromDedicatedID.add(vo.getPodId());
            }
            tempStorage.clear();
            tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, null, null).first();
            for (final DedicatedResourceVO vo : tempStorage) {
                allClustersFromDedicatedID.add(vo.getClusterId());
            }
            tempStorage.clear();
            tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, null, null).first();
            for (final DedicatedResourceVO vo : tempStorage) {
                allHostsFromDedicatedID.add(vo.getHostId());
            }
            // Remove the dedicated ones from main list
            allPodsInDc.removeAll(allPodsFromDedicatedID);
            allClustersInDc.removeAll(allClustersFromDedicatedID);
            allHostsInDc.removeAll(allHostsFromDedicatedID);
        }
        // Add in avoid list or no addition if no dedication
        avoids.addPodList(allPodsInDc);
        avoids.addClusterList(allClustersInDc);
        avoids.addHostList(allHostsInDc);
    }
}
Also used : AffinityGroupVMMapVO(com.cloud.affinity.AffinityGroupVMMapVO) ArrayList(java.util.ArrayList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) AffinityGroupDomainMapVO(com.cloud.affinity.AffinityGroupDomainMapVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

AffinityGroupDomainMapVO (com.cloud.affinity.AffinityGroupDomainMapVO)2 ArrayList (java.util.ArrayList)2 AffinityGroupVMMapVO (com.cloud.affinity.AffinityGroupVMMapVO)1 AffinityGroupJoinVO (com.cloud.api.query.vo.AffinityGroupJoinVO)1 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 VirtualMachine (com.cloud.vm.VirtualMachine)1 List (java.util.List)1