Search in sources :

Example 26 with SearchCriteria

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

the class LunDaoImpl method listLunsByVolId.

@Override
public List<LunVO> listLunsByVolId(Long volId) {
    Filter searchFilter = new Filter(LunVO.class, "id", Boolean.TRUE, Long.valueOf(0), Long.valueOf(10000));
    SearchCriteria sc = LunSearch.create();
    sc.setParameters("volumeId", volId);
    List<LunVO> lunList = listBy(sc, searchFilter);
    return lunList;
}
Also used : Filter(com.cloud.utils.db.Filter) LunVO(com.cloud.netapp.LunVO) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 27 with SearchCriteria

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

the class DeploymentPlanningManagerImpl method finalizeReservation.

@DB
@Override
public String finalizeReservation(final DeployDestination plannedDestination, final VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids, final DeploymentPlanner planner) throws InsufficientServerCapacityException, AffinityConflictException {
    final VirtualMachine vm = vmProfile.getVirtualMachine();
    final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
    return Transaction.execute(new TransactionCallback<String>() {

        @Override
        public String doInTransaction(TransactionStatus status) {
            boolean saveReservation = true;
            if (vmGroupCount > 0) {
                List<Long> groupIds = _affinityGroupVMMapDao.listAffinityGroupIdsByVmId(vm.getId());
                SearchCriteria<AffinityGroupVO> criteria = _affinityGroupDao.createSearchCriteria();
                criteria.addAnd("id", SearchCriteria.Op.IN, groupIds.toArray(new Object[groupIds.size()]));
                _affinityGroupDao.lockRows(criteria, null, true);
                for (AffinityGroupProcessor processor : _affinityProcessors) {
                    if (!processor.check(vmProfile, plannedDestination)) {
                        saveReservation = false;
                        break;
                    }
                }
            }
            if (saveReservation) {
                VMReservationVO vmReservation = new VMReservationVO(vm.getId(), plannedDestination.getDataCenter().getId(), plannedDestination.getPod().getId(), plannedDestination.getCluster().getId(), plannedDestination.getHost().getId());
                if (planner != null) {
                    vmReservation.setDeploymentPlanner(planner.getName());
                }
                Map<Long, Long> volumeReservationMap = new HashMap<Long, Long>();
                if (vm.getHypervisorType() != HypervisorType.BareMetal) {
                    for (Volume vo : plannedDestination.getStorageForDisks().keySet()) {
                        volumeReservationMap.put(vo.getId(), plannedDestination.getStorageForDisks().get(vo).getId());
                    }
                    vmReservation.setVolumeReservation(volumeReservationMap);
                }
                _reservationDao.persist(vmReservation);
                return vmReservation.getUuid();
            }
            return null;
        }
    });
}
Also used : TransactionStatus(com.cloud.utils.db.TransactionStatus) SearchCriteria(com.cloud.utils.db.SearchCriteria) VMReservationVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO) Volume(com.cloud.storage.Volume) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) AffinityGroupProcessor(org.apache.cloudstack.affinity.AffinityGroupProcessor) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine) DB(com.cloud.utils.db.DB)

Example 28 with SearchCriteria

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

the class AsyncJobManagerImpl method wakeupScan.

@DB
protected List<Long> wakeupScan() {
    final Date cutDate = DateUtil.currentGMTTime();
    SearchCriteria<Long> sc = JoinJobTimeSearch.create();
    sc.setParameters("beginTime", cutDate);
    sc.setParameters("endTime", cutDate);
    final List<Long> result = _joinMapDao.customSearch(sc, null);
    return Transaction.execute(new TransactionCallback<List<Long>>() {

        @Override
        public List<Long> doInTransaction(TransactionStatus status) {
            if (result.size() > 0) {
                Collections.sort(result);
                Long[] ids = result.toArray(new Long[result.size()]);
                AsyncJobVO job = _jobDao.createForUpdate();
                job.setPendingSignals(AsyncJob.Constants.SIGNAL_MASK_WAKEUP);
                SearchCriteria<AsyncJobVO> sc2 = JobIdsSearch.create("ids", ids);
                SearchCriteria<SyncQueueItemVO> queueItemsSC = QueueJobIdsSearch.create("contentIds", ids);
                _jobDao.update(job, sc2);
                SyncQueueItemVO item = _queueItemDao.createForUpdate();
                item.setLastProcessNumber(null);
                item.setLastProcessMsid(null);
                _queueItemDao.update(item, queueItemsSC);
            }
            return _joinMapDao.findJobsToWakeBetween(cutDate);
        }
    });
}
Also used : TransactionStatus(com.cloud.utils.db.TransactionStatus) List(java.util.List) Date(java.util.Date) SearchCriteria(com.cloud.utils.db.SearchCriteria) DB(com.cloud.utils.db.DB)

Example 29 with SearchCriteria

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

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 = _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);
        _usageIPAddressDao.persist(ipAddressVO);
    } else if (EventTypes.EVENT_NET_IP_RELEASE.equals(event.getType())) {
        SearchCriteria<UsageIPAddressVO> sc = _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 = _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());
            _usageIPAddressDao.update(ipAddressVO);
        }
    }
}
Also used : Account(com.cloud.user.Account) List(java.util.List) ArrayList(java.util.ArrayList) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 30 with SearchCriteria

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

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 = _accountDao.findByIdIncludingRemoved(event.getAccountId());
        String userName = event.getResourceName();
        UsageVPNUserVO vpnUser = new UsageVPNUserVO(zoneId, event.getAccountId(), acct.getDomainId(), userId, userName, event.getCreateDate(), null);
        _usageVPNUserDao.persist(vpnUser);
    } else if (EventTypes.EVENT_VPN_USER_REMOVE.equals(event.getType())) {
        SearchCriteria<UsageVPNUserVO> sc = _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 = _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());
            _usageVPNUserDao.update(vuVO);
        }
    }
}
Also used : Account(com.cloud.user.Account) List(java.util.List) ArrayList(java.util.ArrayList) SearchCriteria(com.cloud.utils.db.SearchCriteria)

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