Search in sources :

Example 21 with SearchCriteria

use of com.cloud.utils.db.SearchCriteria in project cloudstack by apache.

the class VMSnapshotDaoImpl method listByAccountId.

public List<VMSnapshotVO> listByAccountId(Long accountId) {
    SearchCriteria sc = this.AllFieldsSearch.create();
    sc.setParameters("accountId", new Object[] { accountId });
    return listBy(sc, null);
}
Also used : SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 22 with SearchCriteria

use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.

the class UsageManagerImpl method createNetworkOfferingEvent.

private void createNetworkOfferingEvent(UsageEventVO event) {
    long zoneId = -1L;
    long vmId = event.getResourceId();
    long networkOfferingId = event.getOfferingId();
    if (EventTypes.EVENT_NETWORK_OFFERING_CREATE.equals(event.getType()) || EventTypes.EVENT_NETWORK_OFFERING_ASSIGN.equals(event.getType())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Creating networking offering: " + networkOfferingId + " for Vm: " + vmId + " for account: " + event.getAccountId());
        }
        zoneId = event.getZoneId();
        Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
        boolean isDefault = (event.getSize() == 1) ? true : false;
        UsageNetworkOfferingVO networkOffering = new UsageNetworkOfferingVO(zoneId, event.getAccountId(), acct.getDomainId(), vmId, networkOfferingId, isDefault, event.getCreateDate(), null);
        m_usageNetworkOfferingDao.persist(networkOffering);
    } else if (EventTypes.EVENT_NETWORK_OFFERING_DELETE.equals(event.getType()) || EventTypes.EVENT_NETWORK_OFFERING_REMOVE.equals(event.getType())) {
        SearchCriteria<UsageNetworkOfferingVO> sc = m_usageNetworkOfferingDao.createSearchCriteria();
        sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
        sc.addAnd("vmInstanceId", SearchCriteria.Op.EQ, vmId);
        sc.addAnd("networkOfferingId", SearchCriteria.Op.EQ, networkOfferingId);
        sc.addAnd("deleted", SearchCriteria.Op.NULL);
        List<UsageNetworkOfferingVO> noVOs = m_usageNetworkOfferingDao.search(sc, null);
        if (noVOs.size() > 1) {
            s_logger.warn("More that one usage entry for networking offering: " + networkOfferingId + " for Vm: " + vmId + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
        }
        for (UsageNetworkOfferingVO noVO : noVOs) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("deleting network offering: " + noVO.getNetworkOfferingId() + " from Vm: " + noVO.getVmInstanceId());
            }
            // there really shouldn't be more than one
            noVO.setDeleted(event.getCreateDate());
            m_usageNetworkOfferingDao.update(noVO);
        }
    }
}
Also used : Account(com.cloud.user.Account) List(java.util.List) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 23 with SearchCriteria

use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.

the class UsageManagerImpl method createVPNUserEvent.

private void createVPNUserEvent(UsageEventVO event) {
    long zoneId = 0L;
    long userId = event.getResourceId();
    if (EventTypes.EVENT_VPN_USER_ADD.equals(event.getType())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Creating VPN user: " + userId + " for account: " + event.getAccountId());
        }
        Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
        String userName = event.getResourceName();
        UsageVPNUserVO vpnUser = new UsageVPNUserVO(zoneId, event.getAccountId(), acct.getDomainId(), userId, userName, event.getCreateDate(), null);
        m_usageVPNUserDao.persist(vpnUser);
    } else if (EventTypes.EVENT_VPN_USER_REMOVE.equals(event.getType())) {
        SearchCriteria<UsageVPNUserVO> sc = m_usageVPNUserDao.createSearchCriteria();
        sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
        sc.addAnd("userId", SearchCriteria.Op.EQ, userId);
        sc.addAnd("deleted", SearchCriteria.Op.NULL);
        List<UsageVPNUserVO> vuVOs = m_usageVPNUserDao.search(sc, null);
        if (vuVOs.size() > 1) {
            s_logger.warn("More that one usage entry for vpn user: " + userId + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
        }
        for (UsageVPNUserVO vuVO : vuVOs) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("deleting vpn user: " + vuVO.getUserId());
            }
            // there really shouldn't be more than one
            vuVO.setDeleted(event.getCreateDate());
            m_usageVPNUserDao.update(vuVO);
        }
    }
}
Also used : Account(com.cloud.user.Account) List(java.util.List) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 24 with SearchCriteria

use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.

the class UsageManagerImpl method createIPHelperEvent.

private void createIPHelperEvent(UsageEventVO event) {
    String ipAddress = event.getResourceName();
    if (EventTypes.EVENT_NET_IP_ASSIGN.equals(event.getType())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("assigning ip address: " + ipAddress + " to account: " + event.getAccountId());
        }
        Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
        long zoneId = event.getZoneId();
        long id = event.getResourceId();
        long sourceNat = event.getSize();
        boolean isSourceNat = (sourceNat == 1) ? true : false;
        boolean isSystem = (event.getTemplateId() == null || event.getTemplateId() == 0) ? false : true;
        UsageIPAddressVO ipAddressVO = new UsageIPAddressVO(id, event.getAccountId(), acct.getDomainId(), zoneId, ipAddress, isSourceNat, isSystem, event.getCreateDate(), null);
        m_usageIPAddressDao.persist(ipAddressVO);
    } else if (EventTypes.EVENT_NET_IP_RELEASE.equals(event.getType())) {
        SearchCriteria<UsageIPAddressVO> sc = m_usageIPAddressDao.createSearchCriteria();
        sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
        sc.addAnd("address", SearchCriteria.Op.EQ, ipAddress);
        sc.addAnd("released", SearchCriteria.Op.NULL);
        List<UsageIPAddressVO> ipAddressVOs = m_usageIPAddressDao.search(sc, null);
        if (ipAddressVOs.size() > 1) {
            s_logger.warn("More that one usage entry for ip address: " + ipAddress + " assigned to account: " + event.getAccountId() + "; marking them all as released...");
        }
        for (UsageIPAddressVO ipAddressVO : ipAddressVOs) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("releasing ip address: " + ipAddressVO.getAddress() + " from account: " + ipAddressVO.getAccountId());
            }
            // there really shouldn't be more than one
            ipAddressVO.setReleased(event.getCreateDate());
            m_usageIPAddressDao.update(ipAddressVO);
        }
    }
}
Also used : Account(com.cloud.user.Account) List(java.util.List) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 25 with SearchCriteria

use of com.cloud.utils.db.SearchCriteria 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);
            affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId));
        } else {
            for (Long permAcctId : permittedAccounts) {
                Account permittedAcct = _accountDao.findById(permAcctId);
                SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), 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
        SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
        affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId));
    }
    return new Pair<List<AffinityGroupJoinVO>, Integer>(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.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

SearchCriteria (com.cloud.utils.db.SearchCriteria)33 List (java.util.List)25 Account (com.cloud.user.Account)17 ArrayList (java.util.ArrayList)16 TransactionStatus (com.cloud.utils.db.TransactionStatus)8 DB (com.cloud.utils.db.DB)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 Filter (com.cloud.utils.db.Filter)5 DomainVO (com.cloud.domain.DomainVO)4 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)3 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)3 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)3 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 Map (java.util.Map)3 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)2 DetailVO (com.cloud.host.DetailVO)2 HostVO (com.cloud.host.HostVO)2 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)2