Maor Lipchuk has uploaded a new change for review.

Change subject: core: Introduce volume classification
......................................................................

core: Introduce volume classification

Introduce new column in images table of volume_classification.
volume_classification is a column which determines if the image is a
volume or a snapshot.
It should be mainly used for Cinder, since a previewed snapshot in
Cinder is acctually a new Volume in Cinder and this indication is needed
once the disk is being deleted.

Change-Id: Ia1f37abcc4c5a99076138d7dfb0ffe72f68aef50
Bug-Url: https://bugzilla.redhat.com/1185826
Signed-off-by: Maor Lipchuk <mlipc...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddCinderDiskCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/DiskImage.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/Image.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/ImageDaoTest.java
M packaging/dbscripts/create_views.sql
M packaging/dbscripts/images_sp.sql
A packaging/dbscripts/upgrade/03_06_1480_add_column_volume_classification.sql
9 files changed, 55 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/42055/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
index 18c6fc6..1bb23de 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
@@ -313,7 +313,10 @@
 
             boolean oldTopIsActive = topImage.getImage().isActive();
             topImage.getImage().setActive(baseImage.getImage().isActive());
+            topImage.getImage().setVolumeClassification(
+                    
ImagesHandler.getVolumeClassificationForImage(baseImage.getImage().isActive()));
             baseImage.getImage().setActive(oldTopIsActive);
+            
topImage.getImage().setVolumeClassification(ImagesHandler.getVolumeClassificationForImage(oldTopIsActive));
 
             topImage.setImageStatus(ImageStatus.OK);
             getBaseDiskDao().update(topImage);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddCinderDiskCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddCinderDiskCommand.java
index 7cd6ed6..6e6df44 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddCinderDiskCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddCinderDiskCommand.java
@@ -10,6 +10,7 @@
 import org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic;
 import org.ovirt.engine.core.common.businessentities.storage.ImageStatus;
 import 
org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap;
+import 
org.ovirt.engine.core.common.businessentities.storage.VolumeClassification;
 import org.ovirt.engine.core.common.businessentities.storage.VolumeFormat;
 import org.ovirt.engine.core.common.businessentities.storage.VolumeType;
 import org.ovirt.engine.core.common.utils.Pair;
@@ -45,6 +46,7 @@
 
         cinderDisk.setId(Guid.createGuidFromString(volumeId));
         cinderDisk.setImageId(Guid.createGuidFromString(volumeId));
+        cinderDisk.setVolumeClassification(VolumeClassification.Volume);
         addCinderDiskToDB(cinderDisk);
 
         getParameters().setDiskInfo(cinderDisk);
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/DiskImage.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/DiskImage.java
index 43e6adf..794d1e9 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/DiskImage.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/DiskImage.java
@@ -90,6 +90,14 @@
         getImage().setActive(active);
     }
 
+    public VolumeClassification getVolumeClassification() {
+        return getImage().getVolumeClassification();
+    }
+
+    public void setVolumeClassification(VolumeClassification 
volumeClassification) {
+        getImage().setVolumeClassification(volumeClassification);
+    }
+
     @Override
     public Date getCreationDate() {
         return getImage().getCreationDate();
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/Image.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/Image.java
index 7b6e63f..9a515b4 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/Image.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/Image.java
@@ -18,6 +18,8 @@
 
     private boolean active;
 
+    private VolumeClassification volumeClassification;
+
     private Date creationDate;
 
     private Date lastModified;
@@ -150,6 +152,20 @@
         this.volumeFormat = volumeFormat;
     }
 
+    public VolumeClassification getVolumeClassification() {
+        if (volumeClassification == null) {
+            if (active) {
+                return VolumeClassification.Volume;
+            }
+            return VolumeClassification.Snapshot;
+        }
+        return volumeClassification;
+    }
+
+    public void setVolumeClassification(VolumeClassification 
volumeClassification) {
+        this.volumeClassification = volumeClassification;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
index 86829a6..959f09e 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
@@ -9,6 +9,7 @@
 
 import org.ovirt.engine.core.common.businessentities.storage.Image;
 import org.ovirt.engine.core.common.businessentities.storage.ImageStatus;
+import 
org.ovirt.engine.core.common.businessentities.storage.VolumeClassification;
 import org.ovirt.engine.core.common.businessentities.storage.VolumeFormat;
 import org.ovirt.engine.core.common.businessentities.storage.VolumeType;
 import org.ovirt.engine.core.compat.Guid;
@@ -62,7 +63,8 @@
                 .addValue("volume_type", entity.getVolumeType())
                 .addValue("volume_format", entity.getVolumeFormat())
                 .addValue("image_group_id", entity.getDiskId())
-                .addValue("active", entity.isActive());
+                .addValue("active", entity.isActive())
+                .addValue("volume_classification", 
entity.getVolumeClassification().getValue());
     }
 
     @Override
@@ -97,6 +99,7 @@
             
entity.setVolumeFormat(VolumeFormat.forValue(rs.getInt("volume_format")));
             entity.setDiskId(getGuidDefaultEmpty(rs, "image_group_id"));
             entity.setActive((Boolean) rs.getObject("active"));
+            
entity.setVolumeClassification(VolumeClassification.forValue(rs.getInt("volume_classification")));
             return entity;
         }
     }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/ImageDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/ImageDaoTest.java
index 384be6f..56a0774 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/ImageDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/ImageDaoTest.java
@@ -10,6 +10,7 @@
 import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
 import org.ovirt.engine.core.common.businessentities.storage.Image;
 import org.ovirt.engine.core.common.businessentities.storage.ImageStatus;
+import 
org.ovirt.engine.core.common.businessentities.storage.VolumeClassification;
 import org.ovirt.engine.core.common.businessentities.storage.VolumeFormat;
 import org.ovirt.engine.core.common.businessentities.storage.VolumeType;
 import org.ovirt.engine.core.compat.Guid;
@@ -62,6 +63,7 @@
 
         newImage = new Image();
         newImage.setActive(true);
+        newImage.setVolumeClassification(VolumeClassification.Volume);
         newImage.setTemplateImageId(EXISTING_IMAGE_DISK_TEMPLATE_ID);
         newImage.setSnapshotId(EXISTING_SNAPSHOT_ID);
         newImage.setId(Guid.newGuid());
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index 07f729a..67185ad 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -68,6 +68,7 @@
     images.imageStatus AS imageStatus,
     images.image_group_id AS image_group_id,
     images.active,
+    images.volume_classification,
     vms_for_disk_view.entity_type AS entity_type,
     array_to_string ( vms_for_disk_view.array_vm_names,
         ',' ) AS vm_names,
@@ -224,6 +225,7 @@
     images_storage_domain_view.volume_type AS volume_type,
     images_storage_domain_view.image_group_id AS image_group_id,
     images_storage_domain_view.active AS active,
+    images_storage_domain_view.volume_classification AS volume_classification,
     images_storage_domain_view.volume_format AS volume_format,
     images_storage_domain_view.disk_interface AS disk_interface,
     images_storage_domain_view.boot AS boot,
@@ -301,6 +303,7 @@
             app_list,
             vm_snapshot_id,
             active,
+            volume_classification,
             entity_type,
             number_of_vms,
             vm_names,
@@ -352,6 +355,7 @@
             app_list,
             vm_snapshot_id,
             active,
+            volume_classification,
             entity_type,
             number_of_vms,
             vm_names,
@@ -392,6 +396,7 @@
             NULL AS app_list,
             NULL AS vm_snapshot_id,
             NULL AS active,
+            NULL AS volume_classification,
             vms_for_disk_view.entity_type,
             COALESCE ( array_upper ( vms_for_disk_view.array_vm_names,
                     1 )
diff --git a/packaging/dbscripts/images_sp.sql 
b/packaging/dbscripts/images_sp.sql
index 4e319fd..ba7d9c9 100644
--- a/packaging/dbscripts/images_sp.sql
+++ b/packaging/dbscripts/images_sp.sql
@@ -19,7 +19,8 @@
     v_volume_type INTEGER,
     v_volume_format INTEGER,
     v_image_group_id UUID ,
-    v_active BOOLEAN)
+    v_active BOOLEAN ,
+    v_volume_classification SMALLINT)
 RETURNS VOID
 AS $procedure$
 BEGIN
@@ -35,7 +36,8 @@
         volume_type,
         image_group_id,
         volume_format,
-        active)
+        active,
+        volume_classification)
     VALUES(
         v_creation_date,
         v_image_guid,
@@ -48,7 +50,8 @@
         v_volume_type,
         v_image_group_id,
         v_volume_format,
-        v_active);
+        v_active,
+        v_volume_classification);
 END; $procedure$
 LANGUAGE plpgsql;
 
@@ -128,7 +131,8 @@
     v_volume_type INTEGER,
     v_volume_format INTEGER,
     v_image_group_id UUID ,
-    v_active BOOLEAN)
+    v_active BOOLEAN ,
+    v_volume_classification SMALLINT)
 RETURNS VOID
 AS $procedure$
 BEGIN
@@ -144,6 +148,7 @@
            image_group_id = v_image_group_id,
            volume_format = v_volume_format,
            active = v_active,
+           volume_classification = v_volume_classification,
            _update_date = LOCALTIMESTAMP
     WHERE  image_guid = v_image_guid;
 END; $procedure$
diff --git 
a/packaging/dbscripts/upgrade/03_06_1480_add_column_volume_classification.sql 
b/packaging/dbscripts/upgrade/03_06_1480_add_column_volume_classification.sql
new file mode 100644
index 0000000..ba27caa
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_06_1480_add_column_volume_classification.sql
@@ -0,0 +1,6 @@
+SELECT fn_db_add_column('images', 'volume_classification', 'SMALLINT');
+
+update images set volume_classification = 0 where active;
+update images set volume_classification = 1 where active = false;
+
+


-- 
To view, visit https://gerrit.ovirt.org/42055
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia1f37abcc4c5a99076138d7dfb0ffe72f68aef50
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Maor Lipchuk <mlipc...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to