@Transactional(readOnly = true) private PrimaryStorageInventory findSMPByHostUuid(String clusterUuid) { List<PrimaryStorageVO> ret = SQL.New("select pri from PrimaryStorageVO pri, PrimaryStorageClusterRefVO ref" + " where pri.uuid = ref.primaryStorageUuid" + " and ref.clusterUuid = :cuuid" + " and pri.type = :ptype", PrimaryStorageVO.class) .param("cuuid", clusterUuid) .param("ptype", SMPConstants.SMP_TYPE) .limit(1) .list(); return ret.isEmpty() ? null : PrimaryStorageInventory.valueOf(ret.get(0)); }
@Override protected void scripts() { long count = sql("select count(bs) from BackupStorageVO bs", Long.class).find(); sql("select bs.uuid from BackupStorageVO bs", String.class).limit(1000).paginate(count, (List<String> bsUuids) -> { List<String> byUs = bsUuids.stream() .filter(bsUuid -> destMaker.isManagedByUs(bsUuid)) .collect(Collectors.toList()); track(byUs); }); } }.execute();
@Override protected void scripts() { long count = sql("select count(ps) from PrimaryStorageVO ps", Long.class).find(); sql("select ps.uuid from PrimaryStorageVO ps", String.class).limit(1000).paginate(count, (List<String> psUuids) -> { List<String> byUs = psUuids.stream() .filter(psUuid -> destMaker.isManagedByUs(psUuid)) .collect(Collectors.toList()); track(byUs); }); } }.execute();
@Override protected void scripts() { long count = sql("select count(h) from HostVO h", Long.class).find(); sql("select h.uuid from HostVO h", String.class).limit(1000).paginate(count, (List<String> hostUuids) -> { List<String> byUs = hostUuids.stream().filter(huuid -> { if (skipExisting) { return destMaker.isManagedByUs(huuid) && !trackers.containsKey(huuid); } else { return destMaker.isManagedByUs(huuid); } }).collect(Collectors.toList()); trackHost(byUs); }); } }.execute();
@Override @Deferred public boolean run() { // get current progress Tuple res = SQL.New("SELECT content, timeToDelete FROM TaskProgressVO" + " WHERE apiId = :apiId" + " ORDER BY CAST(content AS int) DESC", Tuple.class) .param("apiId", apiId) .limit(1) .find(); if (res != null && res.get(1) != null) { // FIXME: race condition here. return true; } int currentPercent = res == null ? 0 : new Double(res.get(0, String.class)).intValue(); Runnable cleanup = saveThreadContext(); Defer.defer(cleanup); ThreadContext.put(THREAD_CONTEXT_API, apiId); ThreadContext.put(THREAD_CONTEXT_TASK_NAME, taskName); if (endPercent <= currentPercent) { reportProgress(String.valueOf(endPercent)); return true; } else { reportProgress(String.valueOf(currentPercent + 1)); return false; } }