Maor Lipchuk has uploaded a new change for review.

Change subject: core: Use the latest OVF_STORE files
......................................................................

core: Use the latest OVF_STORE files

Rotate over the OVF_STORE disks and retrieve the entities from the best
match of the OVF_STORE disk until succeeded.
Also register those disks as OVF_STORE disks, so it will be updated
every time there will be any change in the entities' OVF.

Change-Id: I8252281f295df49a28c3c131d9a98fef9af8f35e
Bug-Url: https://bugzilla.redhat.com/1138114
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, 47 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/03/33103/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 e441d2c..01d3a1e 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
@@ -22,6 +22,8 @@
 import org.ovirt.engine.core.common.businessentities.Disk;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.OvfEntityData;
+import org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo;
+import 
org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfoStatus;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatic;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
 import org.ovirt.engine.core.common.businessentities.StorageDomainType;
@@ -193,53 +195,65 @@
     }
 
     protected List<OvfEntityData> getEntitiesFromStorageOvfDisk() {
-        List<OvfEntityData> ovfEntitiesFromTar = Collections.emptyList();
-
-        // Initialize the list with all the ovfDisks in the specified Storage 
Domain.
-        List<DiskImage> ovfStoreDiskImages = getAllOVFDisks();
+        // Initialize a new ArrayList with all the ovfDisks in the specified 
Storage Domain,
+        // so the entities can be removed from the list every time we register 
the latest OVF disk and we can keep the
+        // ovfDisks cache list updated.
+        List<DiskImage> ovfStoreDiskImages = new ArrayList(getAllOVFDisks());
         if (!ovfStoreDiskImages.isEmpty()) {
-            Pair<DiskImage, Long> ovfDiskAndSize = 
getLatestOVFDisk(ovfStoreDiskImages);
-            DiskImage ovfDisk = ovfDiskAndSize.getFirst();
-            if (ovfDisk != null) {
-                try {
-                    VDSReturnValue retrievedByteData = 
runVdsCommand(VDSCommandType.RetrieveImageData,
-                            new ImageHttpAccessVDSCommandParameters(getVdsId(),
-                                    getParameters().getStoragePoolId(),
-                                    getParameters().getStorageDomainId(),
-                                    ovfDisk.getId(),
-                                    ovfDisk.getImage().getId(),
-                                    ovfDiskAndSize.getSecond()));
+            while (!ovfStoreDiskImages.isEmpty()) {
+                Pair<DiskImage, Long> ovfDiskAndSize = 
getLatestOVFDisk(ovfStoreDiskImages);
+                DiskImage ovfDisk = ovfDiskAndSize.getFirst();
+                if (ovfDisk != null) {
+                    try {
+                        VDSReturnValue retrievedByteData = 
runVdsCommand(VDSCommandType.RetrieveImageData,
+                                new 
ImageHttpAccessVDSCommandParameters(getVdsId(),
+                                        getParameters().getStoragePoolId(),
+                                        getParameters().getStorageDomainId(),
+                                        ovfDisk.getId(),
+                                        ovfDisk.getImage().getId(),
+                                        ovfDiskAndSize.getSecond()));
 
-                    if (retrievedByteData.getSucceeded()) {
-                        ovfEntitiesFromTar =
-                                OvfUtils.getOvfEntities((byte[]) 
retrievedByteData.getReturnValue(),
-                                        getParameters().getStorageDomainId());
-                    } else {
-                        log.errorFormat("Image data could not be retrieved for 
disk id {0} in storage domain id {1}",
+                        if (retrievedByteData.getSucceeded()) {
+                            return OvfUtils.getOvfEntities((byte[]) 
retrievedByteData.getReturnValue(),
+                                    getParameters().getStorageDomainId());
+                        } else {
+                            log.errorFormat("Image data could not be retrieved 
for disk id {0} in storage domain id {1}",
+                                    ovfDisk.getId(),
+                                    getParameters().getStorageDomainId());
+                        }
+                    } catch (RuntimeException e) {
+                        // We are catching RuntimeException, since the call 
for OvfUtils.getOvfEntities will throw
+                        // a RuntimeException if there is a problem to untar 
the file.
+                        log.errorFormat("Image data could not be retrieved for 
disk id {0} in storage domain id {1}. Error: {2}",
                                 ovfDisk.getId(),
-                                getParameters().getStorageDomainId());
-                        AuditLogDirector.log(this, 
AuditLogType.RETRIEVE_OVF_STORE_FAILED);
+                                getParameters().getStorageDomainId(),
+                                e);
                     }
-                } catch (RuntimeException e) {
-                    // We are catching RuntimeException, since the call for 
OvfUtils.getOvfEntities will throw
-                    // a RuntimeException if there is a problem to untar the 
file.
-                    log.errorFormat("Image data could not be retrieved for 
disk id {0} in storage domain id {1}. Error: {2}",
-                            ovfDisk.getId(),
-                            getParameters().getStorageDomainId(),
-                            e);
-                    AuditLogDirector.log(this, 
AuditLogType.RETRIEVE_OVF_STORE_FAILED);
+                    ovfStoreDiskImages.remove(ovfDisk);
                 }
             }
+            AuditLogDirector.log(this, AuditLogType.RETRIEVE_OVF_STORE_FAILED);
         } else {
             log.warnFormat("There are no OVF_STORE disks on storage domain id 
{0}",
                     getParameters().getStorageDomainId());
         }
-        return ovfEntitiesFromTar;
+        return Collections.emptyList();
     }
 
     /**
      * Register all the OVF_STORE disks as floating disks in the engine.
      */
+    private void addOvfStoreDiskToDomain(DiskImage ovfDisk) {
+        // Setting OVF_STORE disk to be outdated so it will be updated.
+        StorageDomainOvfInfo storageDomainOvfInfo =
+                new StorageDomainOvfInfo(getStorageDomainId(),
+                        null,
+                        ovfDisk.getId(),
+                        StorageDomainOvfInfoStatus.OUTDATED,
+                        null);
+        getDbFacade().getStorageDomainOvfInfoDao().save(storageDomainOvfInfo);
+    }
+
     private void registerAllOvfDisks(List<DiskImage> ovfStoreDiskImages) {
         for (DiskImage ovfStoreDiskImage : ovfStoreDiskImages) {
             
ovfStoreDiskImage.setDiskAlias(OvfInfoFileConstants.OvfStoreDescriptionLabel);
@@ -255,6 +269,7 @@
                     ovfStoreDiskImage.getId(),
                     getParameters().getStorageDomainId(),
                     result);
+            addOvfStoreDiskToDomain(ovfStoreDiskImage);
         }
     }
 


-- 
To view, visit http://gerrit.ovirt.org/33103
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8252281f295df49a28c3c131d9a98fef9af8f35e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Maor Lipchuk <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to