Search in sources :

Example 1 with AffinityGroupJoinVO

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());
}
Also used : AffinityGroupResponse(org.apache.cloudstack.affinity.AffinityGroupResponse) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO)

Example 2 with AffinityGroupJoinVO

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);
}
Also used : AffinityGroupVMMapVO(org.apache.cloudstack.affinity.AffinityGroupVMMapVO) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) List(java.util.List) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO) Pair(com.cloud.utils.Pair)

Example 3 with AffinityGroupJoinVO

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());
}
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.utils.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)

Example 4 with AffinityGroupJoinVO

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<>();
    }
}
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 5 with AffinityGroupJoinVO

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());
}
Also used : AffinityGroupVMMapVO(com.cloud.affinity.AffinityGroupVMMapVO) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO) 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