Daniel Erez has uploaded a new change for review.

Change subject: core: DiskImagesValidator - validate images belong to same Disk
......................................................................

core: DiskImagesValidator - validate images belong to same Disk

DiskImagesValidator:
added a validation method for verifying that the specified
diskImages belong to the same image group.

Change-Id: I52c4a31cbe3d93f582b710910dd9cd1a51ab50b2
Signed-off-by: Daniel Erez <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskImagesValidator.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/DiskImagesValidatorTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
7 files changed, 40 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/26448/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskImagesValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskImagesValidator.java
index 7f823b9..c5ed627 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskImagesValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskImagesValidator.java
@@ -192,6 +192,21 @@
         return ValidationResult.VALID;
     }
 
+    public ValidationResult diskImagesBelongToSameImageGroup() {
+        Guid imageGroupId = null;
+        for (DiskImage diskImage : diskImages) {
+            if (imageGroupId == null || 
diskImage.getId().equals(imageGroupId)) {
+                imageGroupId = diskImage.getId();
+                continue;
+            }
+
+            return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_DISKS_SNAPSHOTS_DONT_BELONG_TO_SAME_DISK,
+                    String.format("diskalias %s", diskImage.getDiskAlias()));
+        }
+
+        return ValidationResult.VALID;
+    }
+
     private DbFacade getDbFacade() {
        return DbFacade.getInstance();
     }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/DiskImagesValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/DiskImagesValidatorTest.java
index df7051e..43a4837 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/DiskImagesValidatorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/DiskImagesValidatorTest.java
@@ -280,6 +280,24 @@
         verify(snapshotDao, 
never()).get(createdDevices.get(0).getSnapshotId());
     }
 
+    @Test
+    public void diskImagesBelongToSameImageGroup() {
+        Guid imageGroupId = Guid.newGuid();
+        disk1.setId(imageGroupId);
+        disk2.setId(imageGroupId);
+
+        assertThat(validator.diskImagesBelongToSameImageGroup(), isValid());
+    }
+
+    @Test
+    public void diskImagesDontBelongToSameImageGroup() {
+        disk1.setId(Guid.newGuid());
+        disk2.setId(Guid.newGuid());
+
+        assertThat(validator.diskImagesBelongToSameImageGroup(),
+                
failsWith(VdcBllMessages.ACTION_TYPE_FAILED_DISKS_SNAPSHOTS_DONT_BELONG_TO_SAME_DISK));
+    }
+
     private VmDevice createVmDeviceForDisk(DiskImage disk) {
         VmDevice device = new VmDevice();
         device.setId(new VmDeviceId(null, disk.getId()));
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 9ef0f6c..ff9a309 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -659,6 +659,7 @@
     VDS_CANNOT_MAINTENANCE_VM_HAS_PLUGGED_DISK_SNAPSHOT(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_OVF_DISK_NOT_SUPPORTED(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_DISK_NOT_IN_APPLICABLE_STATUS(ErrorType.CONFLICT),
+    
ACTION_TYPE_FAILED_DISKS_SNAPSHOTS_DONT_BELONG_TO_SAME_DISK(ErrorType.CONFLICT),
     
ACTION_TYPE_FAILED_VM_CANNOT_BE_HIGHLY_AVAILABLE_AND_PINNED_TO_HOST(ErrorType.CONFLICT),
     
ACTION_TYPE_FAILED_VM_CANNOT_BE_PINNED_TO_CPU_AND_MIGRATABLE(ErrorType.CONFLICT),
     
ACTION_TYPE_FAILED_VM_CANNOT_BE_PINNED_TO_CPU_WITH_UNDEFINED_HOST(ErrorType.BAD_PARAMETERS),
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 176433d..95cb7d3 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -12,6 +12,7 @@
 VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM=Cannot delete Template. Template is 
being used by the following VMs: ${vmsList}.
 VMT_CANNOT_REMOVE_BASE_WITH_VERSIONS=Cannot delete Base Template that has 
Template Versions, please first remove all Template Versions for this Template: 
${versionsList}.
 ACTION_TYPE_FAILED_DETECTED_DERIVED_DISKS=Cannot ${action} ${type}. The 
following Disk(s) are based on it: \n ${disksInfo}.
+ACTION_TYPE_FAILED_DISKS_SNAPSHOTS_DONT_BELONG_TO_SAME_DISK="Cannot ${action} 
${type}. The specified disks snapshots don't belong to the same Disk: 
${diskAlias}."
 VMT_CANNOT_REMOVE_DOMAINS_LIST_MISMATCH=Cannot delete Template. The Template 
does not exist on the following Storage Domains: ${domainsList}.\nEither verify 
that Template exists on all Storage Domains listed on the domains list,\nor do 
not send domains list in order to delete all instances of the Template from the 
system.
 ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's 
Image does not exist.
 ACTION_TYPE_FAILED_VM_SNAPSHOT_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's 
Snapshot does not exist.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index b5c1784..cf3ee9d 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -46,6 +46,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. The following Disk(s) are 
based on it: \n ${disksInfo}.")
     String ACTION_TYPE_FAILED_DETECTED_DERIVED_DISKS();
 
+    @DefaultStringValue("Cannot ${action} ${type}. The specified disks 
snapshots don't belong to the same Disk: ${diskAlias}.")
+    String ACTION_TYPE_FAILED_DISKS_SNAPSHOTS_DONT_BELONG_TO_SAME_DISK();
+
     @DefaultStringValue("Cannot delete Template. The Template does not exist 
on the following Storage Domains: ${domainsList}.\nEither verify that Template 
exists on all Storage Domains listed on the domains list,\nor do not send 
domains list in order to delete all instances of the Template from the system.")
     String VMT_CANNOT_REMOVE_DOMAINS_LIST_MISMATCH();
 
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index a2b07da..bcfbc55a 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -12,6 +12,7 @@
 VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM=Cannot delete Template. Template is 
being used by the following VMs: ${vmsList}.
 VMT_CANNOT_REMOVE_BASE_WITH_VERSIONS=Cannot delete Base Template that has 
Template Versions, please first remove all Template Versions for this Template: 
${versionsList}.
 ACTION_TYPE_FAILED_DETECTED_DERIVED_DISKS=Cannot ${action} ${type}. The 
following Disk(s) are based on it: \n ${disksInfo}.
+ACTION_TYPE_FAILED_DISKS_SNAPSHOTS_DONT_BELONG_TO_SAME_DISK="Cannot ${action} 
${type}. The specified disks snapshots don't belong to the same Disk: 
${diskAlias}."
 VMT_CANNOT_REMOVE_DOMAINS_LIST_MISMATCH=Cannot delete Template. The Template 
does not exist on the following Storage Domains: ${domainsList}.\nEither verify 
that Template exists on all Storage Domains listed on the domains list,\nor do 
not send domains list in order to delete all instances of the Template from the 
system.
 ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's 
Image does not exist.
 ACTION_TYPE_FAILED_VM_SNAPSHOT_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's 
Snapshot does not exist.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index be68147..2b92d46 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -12,6 +12,7 @@
 VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM=Cannot delete Template. Template is 
being used by the following VMs: ${vmsList}.
 VMT_CANNOT_REMOVE_BASE_WITH_VERSIONS=Cannot delete Base Template that has 
Template Versions, please first remove all Template Versions for this Template: 
${versionsList}.
 ACTION_TYPE_FAILED_DETECTED_DERIVED_DISKS=Cannot ${action} ${type}. The 
following Disk(s) are based on it: \n ${disksInfo}.
+ACTION_TYPE_FAILED_DISKS_SNAPSHOTS_DONT_BELONG_TO_SAME_DISK="Cannot ${action} 
${type}. The specified disks snapshots don't belong to the same Disk: 
${diskAlias}."
 VMT_CANNOT_REMOVE_DOMAINS_LIST_MISMATCH=Cannot delete Template. The Template 
does not exist on the following Storage Domains: ${domainsList}.\nEither verify 
that Template exists on all Storage Domains listed on the domains list,\nor do 
not send domains list in order to delete all instances of the Template from the 
system.
 ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's 
Image does not exist.
 ACTION_TYPE_FAILED_VM_SNAPSHOT_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's 
Snapshot does not exist.


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

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

Reply via email to