@Override public long count(Class<?> entityClass) { SimpleQuery<?> query = this.createQuery(entityClass); return query.count(); }
private long getUsedVolumeSnapshotNum(String accountUuid) { SimpleQuery<AccountResourceRefVO> queryVolumeSnapshotNum = dbf.createQuery(AccountResourceRefVO.class); queryVolumeSnapshotNum.add(AccountResourceRefVO_.accountUuid, Op.EQ, accountUuid); queryVolumeSnapshotNum.add(AccountResourceRefVO_.resourceType, Op.EQ, VolumeSnapshotVO.class.getSimpleName()); return queryVolumeSnapshotNum.count(); }
private boolean isNeedRemoveVip(PortForwardingRuleInventory inv) { SimpleQuery q = dbf.createQuery(PortForwardingRuleVO.class); q.add(PortForwardingRuleVO_.vipUuid, Op.EQ, inv.getVipUuid()); q.add(PortForwardingRuleVO_.vmNicUuid, Op.NOT_NULL); return q.count() == 1; }
private SessionInventory getSession(String accountUuid, String userUuid) { int maxLoginTimes = org.zstack.identity.IdentityGlobalConfig.MAX_CONCURRENT_SESSION.value(Integer.class); SimpleQuery<SessionVO> query = dbf.createQuery(SessionVO.class); query.add(SessionVO_.accountUuid, Op.EQ, accountUuid); query.add(SessionVO_.userUuid, Op.EQ, userUuid); long count = query.count(); if (count >= maxLoginTimes) { // please don't update the bellow code, ui used it String err = String.format("Login sessions hit limit of max allowed concurrent login sessions, max allowed: %s", maxLoginTimes); throw new BadCredentialsException(err); } int sessionTimeout = IdentityGlobalConfig.SESSION_TIMEOUT.value(Integer.class); SessionVO svo = new SessionVO(); svo.setUuid(Platform.getUuid()); svo.setAccountUuid(accountUuid); svo.setUserUuid(userUuid); long expiredTime = getCurrentSqlDate().getTime() + TimeUnit.SECONDS.toMillis(sessionTimeout); svo.setExpiredDate(new Timestamp(expiredTime)); svo = dbf.persistAndRefresh(svo); SessionInventory session = SessionInventory.valueOf(svo); sessions.put(session.getUuid(), session); return session; }
private SessionInventory getSession(String accountUuid, String userUuid) { int maxLoginTimes = org.zstack.identity.IdentityGlobalConfig.MAX_CONCURRENT_SESSION.value(Integer.class); SimpleQuery<SessionVO> query = dbf.createQuery(SessionVO.class); query.add(SessionVO_.accountUuid, SimpleQuery.Op.EQ, accountUuid); query.add(SessionVO_.userUuid, SimpleQuery.Op.EQ, userUuid); long count = query.count(); if (count >= maxLoginTimes) { String err = String.format("Login sessions hit limit of max allowed concurrent login sessions, max allowed: %s", maxLoginTimes); throw new BadCredentialsException(err); } int sessionTimeout = IdentityGlobalConfig.SESSION_TIMEOUT.value(Integer.class); SessionVO svo = new SessionVO(); svo.setUuid(Platform.getUuid()); svo.setAccountUuid(accountUuid); svo.setUserUuid(userUuid); long expiredTime = getCurrentSqlDate().getTime() + TimeUnit.SECONDS.toMillis(sessionTimeout); svo.setExpiredDate(new Timestamp(expiredTime)); svo = dbf.persistAndRefresh(svo); SessionInventory session = SessionInventory.valueOf(svo); return session; }
private List<Tuple> getDeletedImageManagedByUs() { int qun = 1000; SimpleQuery q = dbf.createQuery(ImageBackupStorageRefVO.class); q.add(ImageBackupStorageRefVO_.status, Op.EQ, ImageStatus.Deleted); long amount = q.count(); int times = (int) (amount / qun) + (amount % qun != 0 ? 1 : 0); int start = 0; List<Tuple> ret = new ArrayList<Tuple>(); for (int i = 0; i < times; i++) { q = dbf.createQuery(ImageBackupStorageRefVO.class); q.select(ImageBackupStorageRefVO_.imageUuid, ImageBackupStorageRefVO_.lastOpDate, ImageBackupStorageRefVO_.backupStorageUuid); q.add(ImageBackupStorageRefVO_.status, Op.EQ, ImageStatus.Deleted); q.setLimit(qun); q.setStart(start); List<Tuple> ts = q.listTuple(); start += qun; for (Tuple t : ts) { String imageUuid = t.get(0, String.class); if (!destMaker.isManagedByUs(imageUuid)) { continue; } ret.add(t); } } return ret; }
private boolean checkIfNeedBackupStorageToDownloadImage(HostAllocatorSpec spec, List<HostVO> candidates) { List<String> clusterUuids = CollectionUtils.transformToList(candidates, new Function<String, HostVO>() { @Override public String call(HostVO arg) { return arg.getClusterUuid(); } }); SimpleQuery<PrimaryStorageClusterRefVO> pq = dbf.createQuery(PrimaryStorageClusterRefVO.class); pq.select(PrimaryStorageClusterRefVO_.primaryStorageUuid); pq.add(PrimaryStorageClusterRefVO_.clusterUuid, Op.IN, clusterUuids); List<String> psUuids = pq.listValue(); if (psUuids.isEmpty()) { return true; } SimpleQuery<ImageCacheVO> cq = dbf.createQuery(ImageCacheVO.class); cq.add(ImageCacheVO_.imageUuid, Op.EQ, spec.getImage().getUuid()); cq.add(ImageCacheVO_.primaryStorageUuid, Op.IN, psUuids); cq.groupBy(ImageCacheVO_.primaryStorageUuid); long count = cq.count(); return count != psUuids.size(); }
SimpleQuery<UsedIpVO> q = dbf.createQuery(UsedIpVO.class); q.add(UsedIpVO_.ipRangeUuid, Op.EQ, rangeUuid); long count = q.count(); if (count == total) { logger.debug(String.format("ip range[uuid:%s] has no ip available, try next one", rangeUuid));
@Override public APIMessage intercept(APIMessage msg) throws ApiMessageInterceptionException { if (!CoreGlobalProperty.UNIT_TEST_ON) { if (msg instanceof APIAddSftpBackupStorageMsg) { APIAddSftpBackupStorageMsg amsg = (APIAddSftpBackupStorageMsg) msg; String url = amsg.getUrl(); if (!url.startsWith("/")) { ErrorCode err = argerr("invalid url[%s], the url must be an absolute path starting with '/'", amsg.getUrl()); throw new ApiMessageInterceptionException(err); } String hostname = amsg.getHostname(); SimpleQuery<SftpBackupStorageVO> query = dbf.createQuery(SftpBackupStorageVO.class); query.add(SftpBackupStorageVO_.hostname, Op.EQ, hostname); long count = query.count(); if (count != 0) { ErrorCode err = argerr("existing SimpleHttpBackupStorage with hostname[%s] found", hostname); throw new ApiMessageInterceptionException(err); } } } return msg; }
private List<Tuple> getDeletedVolumeManagedByUs() { int qun = 1000; SimpleQuery q = dbf.createQuery(VolumeVO.class); q.add(VolumeVO_.status, Op.EQ, VolumeStatus.Deleted); q.add(VolumeVO_.type, Op.EQ, VolumeType.Data); long amount = q.count(); int times = (int) (amount / qun) + (amount % qun != 0 ? 1 : 0); int start = 0; List<Tuple> ret = new ArrayList<Tuple>(); for (int i = 0; i < times; i++) { q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.uuid, VolumeVO_.lastOpDate); q.add(VolumeVO_.status, Op.EQ, VolumeStatus.Deleted); q.add(VolumeVO_.type, Op.EQ, VolumeType.Data); q.setLimit(qun); q.setStart(start); List<Tuple> lst = q.listTuple(); start += qun; for (Tuple t : lst) { String uuid = t.get(0, String.class); if (!destMaker.isManagedByUs(uuid)) { continue; } ret.add(t); } } return ret; }
q.add(VxlanNetworkVO_.vni, SimpleQuery.Op.GTE, s); q.add(VxlanNetworkVO_.vni, SimpleQuery.Op.LTE, e); long count = q.count(); if (count == total) { logger.debug(String.format("vni range[uuid:%s] has no vni available, try next one", rangeUuid));
@Override public boolean isIpRangeFull(IpRangeVO vo) { SimpleQuery<UsedIpVO> query = dbf.createQuery(UsedIpVO.class); query.add(UsedIpVO_.ipRangeUuid, Op.EQ, vo.getUuid()); long used = query.count(); if (vo.getIpVersion() == IPv6Constants.IPv4) { int total = NetworkUtils.getTotalIpInRange(vo.getStartIp(), vo.getEndIp()); return used >= total; } else { return IPv6NetworkUtils.isIpv6RangeFull(vo.getStartIp(), vo.getEndIp(), used); } }
q.add(JobQueueEntryVO_.jobQueueId, SimpleQuery.Op.EQ, qvo.getId()); q.orderBy(JobQueueEntryVO_.id, SimpleQuery.Od.ASC); long count = q.count(); if (count == 0) { logger.debug(String.format("[JobQueue Removed]: id:%s, no Pending or Processing job remaining in this queue, remove it", qvo.getId()));
rq.add(L2NetworkClusterRefVO_.clusterUuid, SimpleQuery.Op.EQ, msg.getClusterUuid()); rq.add(L2NetworkClusterRefVO_.l2NetworkUuid, SimpleQuery.Op.EQ, msg.getL2NetworkUuid()); long count = rq.count(); if (count != 0) { evt.setInventory(self.toInventory());
q.add(LocalStorageResourceRefVO_.resourceUuid, Op.IN, list(vm.getRootVolumeUuid(), volume.getUuid())); q.groupBy(LocalStorageResourceRefVO_.hostUuid); long count = q.count();