Tal Nisan has uploaded a new change for review.

Change subject: core: Add storage types to DiskImage entity
......................................................................

core: Add storage types to DiskImage entity

Currently DiskImage has a storageIds field that contains a list of the
storages it resides on. It makes sense also to add a storage types field
to avoid having to fetch the storage domain in order to know which storage
type the disk resides on.
This will be helpful when the storage pool storage type property will be
removed.

Change-Id: I8302972bb21fa076cd35fb308f5f660ca9200daa
Relates-To: https://bugzilla.redhat.com/1038053
Signed-off-by: Tal Nisan <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImage.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
M packaging/dbscripts/create_views.sql
3 files changed, 34 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/89/23589/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImage.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImage.java
index ced0447..3719d13 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImage.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImage.java
@@ -203,6 +203,7 @@
     }
 
     private ArrayList<Guid> storageIds;
+    private ArrayList<StorageType> storageTypes;
 
     public ArrayList<Guid> getStorageIds() {
         return storageIds;
@@ -212,6 +213,14 @@
         this.storageIds = storageIds;
     }
 
+    public ArrayList<StorageType> getStorageTypes() {
+        return storageTypes;
+    }
+
+    public void setStorageTypes(ArrayList<StorageType> storageTypes) {
+        this.storageTypes = storageTypes;
+    }
+
     public Guid getVmSnapshotId() {
         return getImage().getSnapshotId();
     }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
index e517b55..45e6236 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
@@ -11,6 +11,7 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.ImageStatus;
 import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum;
+import org.ovirt.engine.core.common.businessentities.StorageType;
 import org.ovirt.engine.core.common.businessentities.VolumeFormat;
 import org.ovirt.engine.core.common.businessentities.VolumeType;
 import org.ovirt.engine.core.compat.Guid;
@@ -151,6 +152,7 @@
                     .getTimestamp("lastModified")));
             entity.setAppList(rs.getString("app_list"));
             
entity.setStorageIds(GuidUtils.getGuidListFromString(rs.getString("storage_id")));
+            
entity.setStorageTypes(getStorageTypesList(rs.getString("storage_type")));
             entity.setStoragesNames(split(rs.getString("storage_name")));
             entity.setVmSnapshotId(getGuid(rs, "vm_snapshot_id"));
             entity.setVolumeType(VolumeType.forValue(rs
@@ -180,6 +182,24 @@
             return new DiskImage();
         }
 
+        private ArrayList<StorageType> getStorageTypesList(String 
storageTypesString) throws SQLException {
+            List<String> splitTypes = split(storageTypesString);
+            if (splitTypes == null) {
+                return null;
+            }
+
+            ArrayList<StorageType> types = new ArrayList<>(splitTypes.size());
+            for (String typeStr : splitTypes) {
+                try {
+                    types.add(StorageType.forValue(Integer.parseInt(typeStr)));
+                }
+                catch (NumberFormatException e) {
+                    throw new SQLException("Could not parse disk image storage 
domain type " + typeStr, e);
+                }
+            }
+            return types;
+        }
+
         /**
          * since quota can be null, we need to preserve null in the list
          *
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index 3aadaed..edb3425 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -38,6 +38,7 @@
     storage_domain_static_view.storage_name as storage_name,
     storage_domain_static_view.storage as storage_path,
        storage_domain_static_view.storage_pool_id as storage_pool_id,
+       storage_domain_static_view.storage_type as storage_type,
        images.creation_date as creation_date,
     images.size as size,
     images.it_guid as it_guid,
@@ -113,6 +114,7 @@
 SELECT images.image_guid as image_id,
           array_to_string(array_agg(storage_domain_static.storage), ',') as 
storage_path,
           array_to_string(array_agg(storage_domain_static.id), ',') storage_id,
+          array_to_string(array_agg(storage_domain_static.storage_type), ',') 
storage_type,
           array_to_string(array_agg(storage_domain_static.storage_name), ',') 
as storage_name,
           array_to_string(array_agg(COALESCE(CAST(quota.id as varchar), '')), 
',') as quota_id,
           array_to_string(array_agg(COALESCE(quota.quota_name, '')), ',') as 
quota_name
@@ -125,7 +127,7 @@
 CREATE OR REPLACE VIEW vm_images_view
 AS
 SELECT                storage_for_image_view.storage_id as storage_id, 
storage_for_image_view.storage_path as storage_path, 
storage_for_image_view.storage_name as storage_name,
-                                         
images_storage_domain_view.storage_pool_id as storage_pool_id, 
images_storage_domain_view.image_guid as image_guid,
+                                         storage_for_image_view.storage_type, 
images_storage_domain_view.storage_pool_id as storage_pool_id, 
images_storage_domain_view.image_guid as image_guid,
                       images_storage_domain_view.creation_date as 
creation_date, disk_image_dynamic.actual_size as actual_size, 
disk_image_dynamic.read_rate as read_rate,
                       disk_image_dynamic.read_latency_seconds as 
read_latency_seconds, disk_image_dynamic.write_latency_seconds as 
write_latency_seconds,
                       disk_image_dynamic.flush_latency_seconds as 
flush_latency_seconds, disk_image_dynamic.write_rate as write_rate,
@@ -166,6 +168,7 @@
            storage_for_image_view.storage_id as storage_id, -- Storage fields
            storage_for_image_view.storage_path as storage_path,
            storage_for_image_view.storage_name as storage_name,
+           storage_for_image_view.storage_type as storage_type,
            storage_pool_id,
            image_guid, -- Image fields
            creation_date,
@@ -208,6 +211,7 @@
            null AS storage_id, -- Storage domain fields
            null AS storage_path,
            null AS storage_name,
+           null AS storage_type,
            null AS storage_pool_id,
            null AS image_guid, -- Image fields
            null AS creation_date,


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

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

Reply via email to