Search in sources :

Example 1 with AffinityGroupVMMapVO

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

the class QueryManagerImpl method listAffinityGroupsByVM.

private Pair<List<AffinityGroupJoinVO>, Integer> listAffinityGroupsByVM(final long vmId, final long pageInd, final long pageSize) {
    final List<AffinityGroupVMMapVO> agVmMappings = _affinityGroupVMMapDao.listByInstanceId(vmId);
    final Long[] agIds = new Long[agVmMappings.size()];
    int i = 0;
    for (final AffinityGroupVMMapVO agVm : agVmMappings) {
        agIds[i++] = agVm.getAffinityGroupId();
    }
    final List<AffinityGroupJoinVO> ags = _affinityGroupJoinDao.searchByIds(agIds);
    return new Pair<>(ags, ags.size());
}
Also used : AffinityGroupVMMapVO(com.cloud.affinity.AffinityGroupVMMapVO) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO) Pair(com.cloud.utils.Pair)

Example 2 with AffinityGroupVMMapVO

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

the class AffinityGroupVMMapDaoImpl method updateMap.

@Override
public void updateMap(final Long vmId, final List<Long> affinityGroupIds) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    final SearchCriteria<AffinityGroupVMMapVO> sc = createSearchCriteria();
    sc.addAnd("instanceId", SearchCriteria.Op.EQ, vmId);
    expunge(sc);
    for (final Long groupId : affinityGroupIds) {
        final AffinityGroupVMMapVO vo = new AffinityGroupVMMapVO(groupId, vmId);
        persist(vo);
    }
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) AffinityGroupVMMapVO(com.cloud.affinity.AffinityGroupVMMapVO)

Example 3 with AffinityGroupVMMapVO

use of com.cloud.affinity.AffinityGroupVMMapVO 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

AffinityGroupVMMapVO (com.cloud.affinity.AffinityGroupVMMapVO)3 AffinityGroupDomainMapVO (com.cloud.affinity.AffinityGroupDomainMapVO)1 AffinityGroupJoinVO (com.cloud.api.query.vo.AffinityGroupJoinVO)1 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)1 Pair (com.cloud.utils.Pair)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 VirtualMachine (com.cloud.vm.VirtualMachine)1 ArrayList (java.util.ArrayList)1