private Bucket getHostManagedByUs() { int qun = 10000; long amount = dbf.count(HostVO.class); int times = (int) (amount / qun) + (amount % qun != 0 ? 1 : 0); List<String> connected = new ArrayList<String>(); List<String> disconnected = new ArrayList<String>(); int start = 0; for (int i = 0; i < times; i++) { SimpleQuery<HostVO> q = dbf.createQuery(HostVO.class); q.select(HostVO_.uuid, HostVO_.status); q.setLimit(qun); q.setStart(start); List<Tuple> lst = q.listTuple(); start += qun; for (Tuple t : lst) { String huuid = t.get(0, String.class); if (!destMaker.isManagedByUs(huuid)) { continue; } HostStatus state = t.get(1, HostStatus.class); if (state == HostStatus.Connected) { connected.add(huuid); } else { // for Disconnected and Connecting, treat as Disconnected disconnected.add(huuid); } } } return Bucket.newBucket(connected, disconnected); }
private List<String> getHostManagedByUs() { int qun = 10000; long amount = dbf.count(HostVO.class); int times = (int) (amount / qun) + (amount % qun != 0 ? 1 : 0); List<String> hostUuids = new ArrayList<String>(); int start = 0; for (int i = 0; i < times; i++) { SimpleQuery<KVMHostVO> q = dbf.createQuery(KVMHostVO.class); q.select(HostVO_.uuid); // disconnected host will be handled by HostManager q.add(HostVO_.status, SimpleQuery.Op.EQ, HostStatus.Connected); q.setLimit(qun); q.setStart(start); List<String> lst = q.listValue(); start += qun; for (String huuid : lst) { if (!destMaker.isManagedByUs(huuid)) { continue; } hostUuids.add(huuid); } } return hostUuids; }
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 List<HostVO> allocate(String hypervisorType) { SimpleQuery<HostVO> query = dbf.createQuery(HostVO.class); query.add(HostVO_.state, Op.EQ, HostState.Enabled); query.add(HostVO_.status, Op.EQ, HostStatus.Connected); if (hypervisorType != null) { query.add(HostVO_.hypervisorType, Op.EQ, hypervisorType); } if (usePagination()) { query.setStart(paginationInfo.getOffset()); query.setLimit(paginationInfo.getLimit()); } return query.list(); }
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; }