use of com.cloud.api.query.vo.AffinityGroupJoinVO in project cloudstack by apache.
the class ViewResponseHelper method createAffinityGroupResponses.
public static List<AffinityGroupResponse> createAffinityGroupResponses(List<AffinityGroupJoinVO> groups) {
Hashtable<Long, AffinityGroupResponse> vrDataList = new Hashtable<Long, AffinityGroupResponse>();
for (AffinityGroupJoinVO vr : groups) {
AffinityGroupResponse vrData = vrDataList.get(vr.getId());
if (vrData == null) {
// first time encountering this AffinityGroup
vrData = ApiDBUtils.newAffinityGroupResponse(vr);
} else {
// update vms
vrData = ApiDBUtils.fillAffinityGroupDetails(vrData, vr);
}
vrDataList.put(vr.getId(), vrData);
}
return new ArrayList<AffinityGroupResponse>(vrDataList.values());
}
use of com.cloud.api.query.vo.AffinityGroupJoinVO in project cloudstack by apache.
the class QueryManagerImpl method listAffinityGroupsByVM.
private Pair<List<AffinityGroupJoinVO>, Integer> listAffinityGroupsByVM(long vmId, long pageInd, long pageSize) {
Filter sf = new Filter(SecurityGroupVMMapVO.class, null, true, pageInd, pageSize);
Pair<List<AffinityGroupVMMapVO>, Integer> agVmMappingPair = _affinityGroupVMMapDao.listByInstanceId(vmId, sf);
Integer count = agVmMappingPair.second();
if (count.intValue() == 0) {
// handle empty result cases
return new Pair<List<AffinityGroupJoinVO>, Integer>(new ArrayList<AffinityGroupJoinVO>(), count);
}
List<AffinityGroupVMMapVO> agVmMappings = agVmMappingPair.first();
Long[] agIds = new Long[agVmMappings.size()];
int i = 0;
for (AffinityGroupVMMapVO agVm : agVmMappings) {
agIds[i++] = agVm.getAffinityGroupId();
}
List<AffinityGroupJoinVO> ags = _affinityGroupJoinDao.searchByIds(agIds);
return new Pair<List<AffinityGroupJoinVO>, Integer>(ags, count);
}
use of com.cloud.api.query.vo.AffinityGroupJoinVO in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method searchForAffinityGroupsInternal.
public Pair<List<AffinityGroupJoinVO>, Integer> searchForAffinityGroupsInternal(final ListAffinityGroupsCmd cmd) {
final Long affinityGroupId = cmd.getId();
final String affinityGroupName = cmd.getAffinityGroupName();
final String affinityGroupType = cmd.getAffinityGroupType();
final Long vmId = cmd.getVirtualMachineId();
final String accountName = cmd.getAccountName();
Long domainId = cmd.getDomainId();
final Long projectId = cmd.getProjectId();
Boolean isRecursive = cmd.isRecursive();
final Boolean listAll = cmd.listAll();
final Long startIndex = cmd.getStartIndex();
final Long pageSize = cmd.getPageSizeVal();
final String keyword = cmd.getKeyword();
final Account caller = CallContext.current().getCallingAccount();
if (vmId != null) {
final UserVmVO userVM = _userVmDao.findById(vmId);
if (userVM == null) {
throw new InvalidParameterValueException("Unable to list affinity groups for virtual machine instance " + vmId + "; instance not found.");
}
_accountMgr.checkAccess(caller, null, true, userVM);
return listAffinityGroupsByVM(vmId.longValue(), startIndex, pageSize);
}
final List<Long> permittedAccounts = new ArrayList<>();
final Ternary<Long, Boolean, ListProjectResourcesCriteria> ternary = new Ternary<>(domainId, isRecursive, null);
_accountMgr.buildACLSearchParameters(caller, affinityGroupId, accountName, projectId, permittedAccounts, ternary, listAll, false);
domainId = ternary.first();
isRecursive = ternary.second();
final ListProjectResourcesCriteria listProjectResourcesCriteria = ternary.third();
final Filter searchFilter = new Filter(AffinityGroupJoinVO.class, ID_FIELD, true, startIndex, pageSize);
final SearchCriteria<AffinityGroupJoinVO> sc = buildAffinityGroupSearchCriteria(domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
final Pair<List<AffinityGroupJoinVO>, Integer> uniqueGroupsPair = _affinityGroupJoinDao.searchAndCount(sc, searchFilter);
// search group details by ids
List<AffinityGroupJoinVO> affinityGroups = new ArrayList<>();
final Integer count = uniqueGroupsPair.second();
if (count.intValue() != 0) {
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();
}
affinityGroups = _affinityGroupJoinDao.searchByIds(vrIds);
}
if (!permittedAccounts.isEmpty()) {
// add domain level affinity groups
if (domainId != null) {
final SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId));
} else {
for (final Long permAcctId : permittedAccounts) {
final Account permittedAcct = _accountDao.findById(permAcctId);
final SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, permittedAcct.getDomainId()));
}
}
} else if (permittedAccounts.isEmpty() && domainId != null && isRecursive) {
// list all domain level affinity groups for the domain admin case
final SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId));
}
return new Pair<>(affinityGroups, affinityGroups.size());
}
use of com.cloud.api.query.vo.AffinityGroupJoinVO 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<>();
}
}
use of com.cloud.api.query.vo.AffinityGroupJoinVO 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());
}
Aggregations