Search in sources :

Example 6 with AffinityGroupJoinVO

use of com.cloud.api.query.vo.AffinityGroupJoinVO in project cosmic by MissionCriticalCloud.

the class ViewResponseHelper method createAffinityGroupResponses.

public static List<AffinityGroupResponse> createAffinityGroupResponses(final List<AffinityGroupJoinVO> groups) {
    final Hashtable<Long, AffinityGroupResponse> vrDataList = new Hashtable<>();
    for (final 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<>(vrDataList.values());
}
Also used : AffinityGroupResponse(com.cloud.affinity.AffinityGroupResponse) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO)

Example 7 with AffinityGroupJoinVO

use of com.cloud.api.query.vo.AffinityGroupJoinVO in project cloudstack by apache.

the class QueryManagerImpl method listDomainLevelAffinityGroups.

private Pair<List<AffinityGroupJoinVO>, Integer> 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 Pair<>(new ArrayList<AffinityGroupJoinVO>(), 0);
        }
        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 new Pair<>(vrs, count);
    } else {
        return new Pair<>(new ArrayList<AffinityGroupJoinVO>(), 0);
    }
}
Also used : ArrayList(java.util.ArrayList) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) AffinityGroupDomainMapVO(org.apache.cloudstack.affinity.AffinityGroupDomainMapVO) Pair(com.cloud.utils.Pair)

Example 8 with AffinityGroupJoinVO

use of com.cloud.api.query.vo.AffinityGroupJoinVO in project cloudstack by apache.

the class QueryManagerImpl method searchForAffinityGroupsInternal.

public Pair<List<AffinityGroupJoinVO>, Integer> searchForAffinityGroupsInternal(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();
    Account caller = CallContext.current().getCallingAccount();
    if (vmId != null) {
        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);
    }
    List<Long> permittedAccounts = new ArrayList<Long>();
    Ternary<Long, Boolean, ListProjectResourcesCriteria> ternary = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, affinityGroupId, accountName, projectId, permittedAccounts, ternary, listAll, false);
    domainId = ternary.first();
    isRecursive = ternary.second();
    ListProjectResourcesCriteria listProjectResourcesCriteria = ternary.third();
    Filter searchFilter = new Filter(AffinityGroupJoinVO.class, ID_FIELD, true, startIndex, pageSize);
    SearchCriteria<AffinityGroupJoinVO> sc = buildAffinityGroupSearchCriteria(domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
    Pair<List<AffinityGroupJoinVO>, Integer> uniqueGroupsPair = _affinityGroupJoinDao.searchAndCount(sc, searchFilter);
    // search group details by ids
    List<AffinityGroupJoinVO> affinityGroups = new ArrayList<AffinityGroupJoinVO>();
    Integer count = uniqueGroupsPair.second();
    if (count.intValue() != 0) {
        List<AffinityGroupJoinVO> uniqueGroups = uniqueGroupsPair.first();
        Long[] vrIds = new Long[uniqueGroups.size()];
        int i = 0;
        for (AffinityGroupJoinVO v : uniqueGroups) {
            vrIds[i++] = v.getId();
        }
        affinityGroups = _affinityGroupJoinDao.searchByIds(vrIds);
    }
    if (!permittedAccounts.isEmpty()) {
        // add domain level affinity groups
        if (domainId != null) {
            SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
            Pair<List<AffinityGroupJoinVO>, Integer> groupsPair = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId);
            affinityGroups.addAll(groupsPair.first());
            count += groupsPair.second();
        } else {
            for (Long permAcctId : permittedAccounts) {
                Account permittedAcct = _accountDao.findById(permAcctId);
                SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
                Pair<List<AffinityGroupJoinVO>, Integer> groupsPair = listDomainLevelAffinityGroups(scDomain, searchFilter, permittedAcct.getDomainId());
                affinityGroups.addAll(groupsPair.first());
                count += groupsPair.second();
            }
        }
    } else if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) {
        // list all domain level affinity groups for the domain admin case
        SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
        Pair<List<AffinityGroupJoinVO>, Integer> groupsPair = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId);
        affinityGroups.addAll(groupsPair.first());
        count += groupsPair.second();
    }
    return new Pair<List<AffinityGroupJoinVO>, Integer>(affinityGroups, count);
}
Also used : Account(com.cloud.user.Account) UserVmVO(com.cloud.vm.UserVmVO) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) SearchCriteria(com.cloud.utils.db.SearchCriteria) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Aggregations

AffinityGroupJoinVO (com.cloud.api.query.vo.AffinityGroupJoinVO)8 ArrayList (java.util.ArrayList)7 Pair (com.cloud.utils.Pair)5 List (java.util.List)5 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)3 Filter (com.cloud.utils.db.Filter)3 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)2 Account (com.cloud.user.Account)2 Ternary (com.cloud.utils.Ternary)2 SearchCriteria (com.cloud.utils.db.SearchCriteria)2 UserVmVO (com.cloud.vm.UserVmVO)2 Hashtable (java.util.Hashtable)2 AffinityGroupDomainMapVO (com.cloud.affinity.AffinityGroupDomainMapVO)1 AffinityGroupResponse (com.cloud.affinity.AffinityGroupResponse)1 AffinityGroupVMMapVO (com.cloud.affinity.AffinityGroupVMMapVO)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1 AffinityGroupDomainMapVO (org.apache.cloudstack.affinity.AffinityGroupDomainMapVO)1 AffinityGroupResponse (org.apache.cloudstack.affinity.AffinityGroupResponse)1 AffinityGroupVMMapVO (org.apache.cloudstack.affinity.AffinityGroupVMMapVO)1