Maor Lipchuk has uploaded a new change for review. Change subject: core: Register all the OVF disks to Storage ......................................................................
core: Register all the OVF disks to Storage Register all the OVF disks in the Storage so the engine will not create new OVF disks. Change-Id: I9fc6666a64efa16968935cfceb10e19b8a4e2eef Bug-Url: https://bugzilla.redhat.com/?????? Signed-off-by: Maor Lipchuk <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AttachStorageDomainToPoolCommand.java 1 file changed, 79 insertions(+), 34 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/43/32743/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AttachStorageDomainToPoolCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AttachStorageDomainToPoolCommand.java index 2e3c33b..c4a6cef 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AttachStorageDomainToPoolCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AttachStorageDomainToPoolCommand.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -13,6 +14,7 @@ import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.FeatureSupported; import org.ovirt.engine.core.common.action.AttachStorageDomainToPoolParameters; +import org.ovirt.engine.core.common.action.RegisterDiskParameters; import org.ovirt.engine.core.common.action.StorageDomainPoolParametersBase; import org.ovirt.engine.core.common.action.StoragePoolWithStoragesParameter; import org.ovirt.engine.core.common.action.VdcActionType; @@ -196,8 +198,10 @@ new GetUnregisteredDisksQueryParameters(getParameters().getStorageDomainId(), getVds().getStoragePoolId())).getReturnValue(); - if (!unregisteredDisks.isEmpty()) { - Pair<DiskImage, Long> ovfDiskAndSize = getLatestOVFDisk(unregisteredDisks); + List<DiskImage> ovfStoreDiskImages = getAllOVFDisks(unregisteredDisks); + if (!ovfStoreDiskImages.isEmpty()) { + registerAllOvfDisks(ovfStoreDiskImages); + Pair<DiskImage, Long> ovfDiskAndSize = getLatestOVFDisk(ovfStoreDiskImages); DiskImage ovfDisk = ovfDiskAndSize.getFirst(); if (ovfDisk != null) { try { @@ -236,24 +240,33 @@ return ovfEntitiesFromTar; } - /** - * Returns the best match for OVF disk from all the disks. If no OVF disk was found, it returns null for disk and - * size 0. If there are OVF disks, we first match the updated ones, and from them we retrieve the one which was last - * updated. - * - * @param disks - * - A list of disks - * @return A Pair which contains the best OVF disk to retrieve data from and its size. - */ - private Pair<DiskImage, Long> getLatestOVFDisk(List<Disk> disks) { - Date foundOvfDiskUpdateDate = new Date(); - boolean isFoundOvfDiskUpdated = false; - Long size = 0L; - Disk ovfDisk = null; + private void registerAllOvfDisks(List<DiskImage> ovfStoreDiskImages) { + for (DiskImage ovfStoreDiskImage : ovfStoreDiskImages) { + ovfStoreDiskImage.setDiskAlias("OVF_STORE"); + ovfStoreDiskImage.setDiskDescription("OVF_STORE"); + ovfStoreDiskImage.setShareable(true); + RegisterDiskParameters registerDiskParams = new RegisterDiskParameters(ovfStoreDiskImage, getParameters().getStorageDomainId()); + String result = "succeeded"; + try { + if (!runInternalAction(VdcActionType.RegisterDisk, registerDiskParams, null).getSucceeded()) { + result = "failed"; + } + } catch (Exception e) { + result = "failed"; + log.error(e); + } + log.infoFormat("Register OVF_STORE disk id {0} for storage domain {1} has {2}", + ovfStoreDiskImage.getId(), + getParameters().getStorageDomainId(), + result); + } + } + + private List<DiskImage> getAllOVFDisks(List<Disk> disks) { + List<DiskImage> ovfDisks = new ArrayList<>(); for (Disk disk : disks) { - boolean isBetterOvfDiskFound = false; - // Check which disks are of OVF_STORE - String diskDecription = ((DiskImage) disk).getDescription(); + DiskImage ovfStoreDisk = (DiskImage) disk; + String diskDecription = ovfStoreDisk.getDescription(); if (diskDecription.contains(OvfInfoFileConstants.OvfStoreDescriptionLabel)) { Map<String, Object> diskDescriptionMap; try { @@ -263,28 +276,60 @@ continue; } - // The purpose of this check is to verify that it's an OVF store with data related to the Storage Domain. + // The purpose of this check is to verify that it's an OVF store with data related to the Storage + // Domain. if (!isDomainExistsInDiskDescription(diskDescriptionMap, getParameters().getStorageDomainId())) { log.warnFormat("The disk description does not contain the storage domain id {0}", getParameters().getStorageDomainId()); continue; } + ovfDisks.add(ovfStoreDisk); + } + } + return ovfDisks; + } - boolean isUpdated = Boolean.valueOf(diskDescriptionMap.get(OvfInfoFileConstants.IsUpdated).toString()); - Date date = getDateFromDiskDescription(diskDescriptionMap); + /** + * Returns the best match for OVF disk from all the disks. If no OVF disk was found, it returns null for disk and + * size 0. If there are OVF disks, we first match the updated ones, and from them we retrieve the one which was last + * updated. + * + * @param ovfStoreDiskImages + * - A list of OVF_STORE disks + * @return A Pair which contains the best OVF disk to retrieve data from and its size. + */ + private Pair<DiskImage, Long> getLatestOVFDisk(List<DiskImage> ovfStoreDiskImages) { + Date foundOvfDiskUpdateDate = new Date(); + boolean isFoundOvfDiskUpdated = false; + Long size = 0L; + Disk ovfDisk = null; + for (DiskImage ovfStoreDisk : ovfStoreDiskImages) { + boolean isBetterOvfDiskFound = false; - if (isFoundOvfDiskUpdated && !isUpdated) { - continue; - } - if ((isUpdated && !isFoundOvfDiskUpdated) || date.after(foundOvfDiskUpdateDate)) { - isBetterOvfDiskFound = true; - } - if (isBetterOvfDiskFound) { - isFoundOvfDiskUpdated = isUpdated; - foundOvfDiskUpdateDate = date; - ovfDisk = disk; - size = new Long(diskDescriptionMap.get(OvfInfoFileConstants.Size).toString()); - } + // Check which disks are of OVF_STORE + String diskDecription = ovfStoreDisk.getDescription(); + Map<String, Object> diskDescriptionMap; + try { + diskDescriptionMap = JsonHelper.jsonToMap(diskDecription); + } catch (IOException e) { + log.warnFormat("Exception while generating json containing ovf store info. Exception: {0}", e); + continue; + } + + boolean isUpdated = Boolean.valueOf(diskDescriptionMap.get(OvfInfoFileConstants.IsUpdated).toString()); + Date date = getDateFromDiskDescription(diskDescriptionMap); + + if (isFoundOvfDiskUpdated && !isUpdated) { + continue; + } + if ((isUpdated && !isFoundOvfDiskUpdated) || date.after(foundOvfDiskUpdateDate)) { + isBetterOvfDiskFound = true; + } + if (isBetterOvfDiskFound) { + isFoundOvfDiskUpdated = isUpdated; + foundOvfDiskUpdateDate = date; + ovfDisk = ovfStoreDisk; + size = new Long(diskDescriptionMap.get(OvfInfoFileConstants.Size).toString()); } } return new Pair<>((DiskImage)ovfDisk, size); -- To view, visit http://gerrit.ovirt.org/32743 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9fc6666a64efa16968935cfceb10e19b8a4e2eef Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Maor Lipchuk <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
