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;
final UsageEventDetailsVO hiddenDetail = _usageEventDetailsDao.findDetail(event.getId(), "hidden");
final boolean isHidden = hiddenDetail != null && "true".equals(hiddenDetail.getValue());
UsageIPAddressVO ipAddressVO = new UsageIPAddressVO(id, event.getAccountId(), acct.getDomainId(), zoneId, ipAddress, isSourceNat, isSystem, event.getCreateDate(), null, isHidden);
_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);
}
}
}
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);
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);
}
use of com.cloud.utils.db.SearchCriteria in project cloudstack by apache.
the class HostDetailsDaoImpl method deleteDetails.
@Override
public void deleteDetails(long hostId) {
SearchCriteria sc = HostSearch.create();
sc.setParameters("hostId", hostId);
List<DetailVO> results = search(sc, null);
for (DetailVO result : results) {
remove(result.getId());
}
}
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);
}
});
}
Aggregations