use of org.apache.cloudstack.affinity.AffinityGroupDomainMapVO in project cloudstack by apache.
the class DeploymentPlanningManagerImpl method checkForNonDedicatedResources.
private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, DataCenter dc, ExcludeList avoids) {
boolean isExplicit = false;
VirtualMachine vm = vmProfile.getVirtualMachine();
// check if zone is dedicated. if yes check if vm owner has access to it.
DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(dc.getId());
if (dedicatedZone != null && !_accountMgr.isRootAdmin(vmProfile.getOwner().getId())) {
long accountDomainId = vmProfile.getOwner().getDomainId();
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 " + dc.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 " + dc.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
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), "ExplicitDedication");
if (vmGroupMappings != null && !vmGroupMappings.isEmpty()) {
isExplicit = true;
}
List<Long> allPodsInDc = _podDao.listAllPods(dc.getId());
List<Long> allDedicatedPods = _dedicatedDao.listAllPods();
allPodsInDc.retainAll(allDedicatedPods);
List<Long> allClustersInDc = _clusterDao.listAllClusters(dc.getId());
List<Long> allDedicatedClusters = _dedicatedDao.listAllClusters();
allClustersInDc.retainAll(allDedicatedClusters);
List<Long> allHostsInDc = _hostDao.listAllHosts(dc.getId());
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) {
long vmAccountId = vm.getAccountId();
long vmDomainId = vm.getDomainId();
//Lists all explicitly dedicated resources from vm account ID or domain ID.
List<Long> allPodsFromDedicatedID = new ArrayList<Long>();
List<Long> allClustersFromDedicatedID = new ArrayList<Long>();
List<Long> allHostsFromDedicatedID = new ArrayList<Long>();
//Whether the dedicated resources belong to Domain or not. If not, it may belongs to Account or no dedication.
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 (DedicatedResourceVO vo : tempStorage) {
allPodsFromDedicatedID.add(vo.getPodId());
}
tempStorage.clear();
tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, vmAccountId, null).first();
for (DedicatedResourceVO vo : tempStorage) {
allClustersFromDedicatedID.add(vo.getClusterId());
}
tempStorage.clear();
tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, vmAccountId, null).first();
for (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 (DedicatedResourceVO vo : tempStorage) {
allPodsFromDedicatedID.add(vo.getPodId());
}
tempStorage.clear();
tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, null, null).first();
for (DedicatedResourceVO vo : tempStorage) {
allClustersFromDedicatedID.add(vo.getClusterId());
}
tempStorage.clear();
tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, null, null).first();
for (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);
}
}
use of org.apache.cloudstack.affinity.AffinityGroupDomainMapVO in project cloudstack by apache.
the class QueryManagerImpl method listDomainLevelAffinityGroups.
private List<AffinityGroupJoinVO> listDomainLevelAffinityGroups(SearchCriteria<AffinityGroupJoinVO> sc, Filter searchFilter, long domainId) {
List<Long> affinityGroupIds = new ArrayList<Long>();
Set<Long> allowedDomains = _domainMgr.getDomainParentIds(domainId);
List<AffinityGroupDomainMapVO> maps = _affinityGroupDomainMapDao.listByDomain(allowedDomains.toArray());
for (AffinityGroupDomainMapVO map : maps) {
boolean subdomainAccess = map.isSubdomainAccess();
if (map.getDomainId() == domainId || subdomainAccess) {
affinityGroupIds.add(map.getAffinityGroupId());
}
}
if (!affinityGroupIds.isEmpty()) {
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);
Pair<List<AffinityGroupJoinVO>, Integer> uniqueGroupsPair = _affinityGroupJoinDao.searchAndCount(sc, searchFilter);
// search group by ids
Integer count = uniqueGroupsPair.second();
if (count.intValue() == 0) {
// empty result
return new ArrayList<AffinityGroupJoinVO>();
}
List<AffinityGroupJoinVO> uniqueGroups = uniqueGroupsPair.first();
Long[] vrIds = new Long[uniqueGroups.size()];
int i = 0;
for (AffinityGroupJoinVO v : uniqueGroups) {
vrIds[i++] = v.getId();
}
List<AffinityGroupJoinVO> vrs = _affinityGroupJoinDao.searchByIds(vrIds);
return vrs;
} else {
return new ArrayList<AffinityGroupJoinVO>();
}
}
Aggregations