public static Collection<String> queryVmInGC(final String hostUuid, final Collection<String> vmUuids) { Collection<String> vmUuidsInGC = new HashSet<>(); List<String> gcNames = Q.New(GarbageCollectorVO.class).select(GarbageCollectorVO_.name) .eq(GarbageCollectorVO_.runnerClass, DeleteVmGC.class.getName()) .like(GarbageCollectorVO_.name, String.format("%%on-host-%s%%", hostUuid)) .notEq(GarbageCollectorVO_.status, GCStatus.Done).listValues(); if (gcNames != null && !gcNames.isEmpty()) { vmUuidsInGC = vmUuids.stream().filter(uuid -> gcNames.contains(String.format("gc-vm-%s-on-host-%s", uuid, hostUuid))).collect(Collectors.toSet()); } return vmUuidsInGC; } }
public SystemTagInventory updateUnique(String resourceUuid, String oldTag, String newTag) { String tagUuid = Q.New(SystemTagVO.class).eq(SystemTagVO_.resourceUuid, resourceUuid). eq(SystemTagVO_.resourceType, resourceClass.getSimpleName()).like(SystemTagVO_.tag, oldTag). select(SystemTagVO_.uuid).findValue(); if (tagUuid == null) { return null; } return tagMgr.updateSystemTag(tagUuid, newTag); }
public List<SystemTagInventory> getTagInventories(String resourceUuid) { return SystemTagInventory.valueOf(Q.New(SystemTagVO.class).eq(SystemTagVO_.resourceType, getResourceClass().getSimpleName()). eq(SystemTagVO_.resourceUuid, resourceUuid).like(SystemTagVO_.tag, useTagFormat()).list()); }
@Override public Long getTrashId(String storageUuid, String installPath) { DebugUtils.Assert(installPath != null, "installPath is not allowed null here"); List<JsonLabelVO> lables = Q.New(JsonLabelVO.class).eq(JsonLabelVO_.resourceUuid, storageUuid).like(JsonLabelVO_.labelValue, String.format("%%%s%%", installPath)).list(); if (!lables.isEmpty()) { for (JsonLabelVO lable: lables) { for (TrashType type: TrashType.values()) { if (!lable.getLabelKey().startsWith(type.name())) { // if lable key not starts with type, it may not be storage trash continue; } } StorageTrashSpec spec = JSONObjectUtil.toObject(lable.getLabelValue(), StorageTrashSpec.class); if (spec.getInstallPath().equals(installPath)) { return lable.getId(); } } } return null; }
@Override public Map<String, StorageTrashSpec> getTrashList(String storageUuid, List<TrashType> types) { Map<String, StorageTrashSpec> specs = new HashMap<>(); for (TrashType type: types) { List<JsonLabelVO> labels = Q.New(JsonLabelVO.class).eq(JsonLabelVO_.resourceUuid, storageUuid).like(JsonLabelVO_.labelKey, type.toString() + "-%").list(); labels.forEach(l -> { StorageTrashSpec spec = JSONObjectUtil.toObject(l.getLabelValue(), StorageTrashSpec.class); spec.setTrashId(l.getId()); spec.setCreateDate(l.getCreateDate()); if (spec.getTrashType() == null) { spec.setTrashType(type.toString()); } specs.put(l.getLabelKey(), spec); }); } return specs; }
.select(PrimaryStorageVO_.uuid) .eq(PrimaryStorageVO_.type, NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE) .like(PrimaryStorageVO_.url, String.format("%s:/%%", hostIp)) .limit(1) .findValue();
@Override protected void checkImageIfNeedToDownload(DownloadIsoToPrimaryStorageMsg msg){ logger.debug("check if image exist in disabled primary storage"); if(self.getState() != PrimaryStorageState.Disabled){ return ; } if( !Q.New(ImageCacheVO.class) .eq(ImageCacheVO_.primaryStorageUuid, self.getUuid()) .eq(ImageCacheVO_.imageUuid, msg.getIsoSpec().getInventory().getUuid()) .like(ImageCacheVO_.installUrl, String.format("%%hostUuid://%s%%", msg.getDestHostUuid())) .isExists()){ throw new OperationFailureException(operr( "cannot attach ISO to a primary storage[uuid:%s] which is disabled", self.getUuid())); } }