/** * Filter out LUNs that are already a part of storage domains exist in the system. * * @param luns the LUNs list * @return the filtered LUNs list */ protected List<LUNs> filterLUNsThatBelongToExistingStorageDomains(List<LUNs> luns) { List<StorageDomain> existingStorageDomains = getStorageDomainDao().getAll(); final List<Guid> existingStorageDomainIDs = Entities.getIds(existingStorageDomains); return luns.stream() .filter(lun -> !existingStorageDomainIDs.contains(lun.getStorageDomainId())) .collect(Collectors.toList()); }
/** * Create StorageDomain objects according to the specified VG-IDs list. * * @param vgIDs the VG-IDs list * @return storage domains list */ @SuppressWarnings("unchecked") protected List<StorageDomain> getStorageDomainsByVolumeGroupIds(List<String> vgIDs) { List<StorageDomain> storageDomains = new ArrayList<>(); // Get existing PhysicalVolumes. List<String> existingLunIds = Entities.getIds(getLunDao().getAll()); for (String vgID : vgIDs) { VDSReturnValue returnValue; try { returnValue = executeGetVGInfo(new GetVGInfoVDSCommandParameters(getParameters().getVdsId(), vgID)); } catch (RuntimeException e) { log.error("Could not get info for VG ID: '{}': {}", vgID, e.getMessage()); log.debug("Exception", e); continue; } ArrayList<LUNs> luns = (ArrayList<LUNs>) returnValue.getReturnValue(); List<String> lunIdsOnStorage = Entities.getIds(luns); if (CollectionUtils.containsAny(lunIdsOnStorage, existingLunIds)) { log.info("There are existing luns in the system which are part of VG id '{}'", vgID); continue; } // Get storage domain ID by a representative LUN LUNs lun = luns.get(0); Guid storageDomainId = lun.getStorageDomainId(); // Get storage domain using GetStorageDomainInfo StorageDomain storageDomain = getStorageDomainById(storageDomainId); if (storageDomain != null) { storageDomains.add(storageDomain); } } return storageDomains; }