Tomas Jelinek has uploaded a new change for review.

Change subject: webadmin: Allow creation of new disks as copy of any existing 
disk
......................................................................

webadmin: Allow creation of new disks as copy of any existing disk

Allowed to make a copy of a VM disk

Change-Id: I9c11478216a11d12208365ebdc69b9665766f6ba
Bug-Url: https://bugzilla.redhat.com/1132066
Signed-off-by: Tomas Jelinek <[email protected]>
---
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/CopyDiskModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/MoveDiskModel.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, 68 insertions(+), 47 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/38335/1

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 44e7962..f4ba564 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
@@ -697,9 +697,6 @@
     @DefaultStringValue("The specified Template doesn't exist in the current 
Data Center.")
     String ACTION_TYPE_FAILED_TEMPLATE_NOT_EXISTS_IN_CURRENT_DC();
 
-    @DefaultStringValue("Cannot ${action} ${type}. One of the Template Images 
already exists.")
-    String ACTION_TYPE_FAILED_IMAGE_ALREADY_EXISTS();
-
     @DefaultStringValue("Cannot ${action} ${type}. A Template with the same 
identifier already exists.")
     String ACTION_TYPE_FAILED_TEMPLATE_GUID_ALREADY_EXISTS();
 
@@ -2805,9 +2802,6 @@
 
     @DefaultStringValue("Cannot ${action} ${type}. ${diskAlias} is shareable, 
which Gluster domains do not support.")
     String ACTION_TYPE_FAILED_CANT_MOVE_SHAREABLE_DISK_TO_GLUSTERFS();
-
-    @DefaultStringValue("Cannot ${action} ${type}. The selected disk is not a 
template disk. Only template disks can be copied.")
-    String ACTION_TYPE_FAILED_DISK_IS_NOT_TEMPLATE_DISK();
 
     @DefaultStringValue("Cannot ${action} ${type}. The source and target 
storage domains are the same.")
     String ACTION_TYPE_FAILED_SOURCE_AND_TARGET_SAME();
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
index 2d47001..e436e10 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
@@ -13,6 +13,7 @@
 import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.ImageStatus;
+import org.ovirt.engine.core.common.businessentities.VmEntityType;
 import org.ovirt.engine.core.common.interfaces.SearchType;
 import org.ovirt.engine.core.common.mode.ApplicationMode;
 import org.ovirt.engine.core.common.queries.SearchParameters;
@@ -521,7 +522,6 @@
     }
 
     private void updateCopyAndMoveCommandAvailability(List<Disk> disks) {
-        boolean isCopyAllowed = true;
         boolean isMoveAllowed = true;
 
         if (disks == null || disks.isEmpty() || 
disks.get(0).getDiskStorageType() != DiskStorageType.IMAGE) {
@@ -532,7 +532,7 @@
         Guid datacenterId = ((DiskImage) disks.get(0)).getStoragePoolId();
 
         for (Disk disk : disks) {
-            if ((!isCopyAllowed && !isMoveAllowed) || 
disk.getDiskStorageType() != DiskStorageType.IMAGE) {
+            if (disk.getDiskStorageType() != DiskStorageType.IMAGE) {
                 disableMoveAndCopyCommands();
                 return;
             }
@@ -542,16 +542,13 @@
                 disableMoveAndCopyCommands();
                 return;
             }
-
-            if (disk.getVmEntityType() != null && 
disk.getVmEntityType().isTemplateType()) {
+            VmEntityType vmEntityType = disk.getVmEntityType();
+            if (vmEntityType != null && vmEntityType.isTemplateType()) {
                 isMoveAllowed = false;
-            }
-            else {
-                isCopyAllowed = false;
             }
         }
 
-        getCopyCommand().setIsExecutionAllowed(isCopyAllowed);
+        getCopyCommand().setIsExecutionAllowed(true);
         getMoveCommand().setIsExecutionAllowed(isMoveAllowed);
     }
 
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
index 09c8889..d287edb 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
@@ -32,7 +32,9 @@
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.DiskModel;
+import org.ovirt.engine.ui.uicommonweb.validation.I18NNameValidation;
 import org.ovirt.engine.ui.uicommonweb.validation.IValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation;
 import org.ovirt.engine.ui.uicommonweb.validation.SelectedQuotaValidation;
 import org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult;
 import org.ovirt.engine.ui.uicompat.IFrontendMultipleQueryAsyncCallback;
@@ -230,26 +232,7 @@
         ArrayList<StorageDomain> destinationDomains = new ArrayList<>();
         for (StorageDomain sd : activeStorageDomains) {
             // Storage domain destination should not be a domain which the 
disk is attached to.
-            if (sourceActiveStorageDomains.contains(sd)) {
-                continue;
-            }
-
-            // Destination should be in the same pool as the disk.
-            boolean connectedToSamePool = 
sd.getStoragePoolId().equals(diskImage.getStoragePoolId());
-            if (!connectedToSamePool) {
-                continue;
-            }
-
-            boolean hasSameSubType = sd.getStorageType().getStorageSubtype() 
== diskImage.getStorageTypes().get(0).getStorageSubtype();
-            if (shouldFilterBySourceType && !hasSameSubType) {
-                continue;
-            }
-
-            if (!isDomainValidForDiskTemplate(templateDisk, sd)) {
-                continue;
-            }
-
-            if (!isDiskValidForStorage(diskImage, sd)) {
+            if (!allowedStorageDomain(sourceActiveStorageDomains, 
shouldFilterBySourceType, diskImage, templateDisk, sd)) {
                 continue;
             }
 
@@ -258,6 +241,28 @@
         }
 
         return destinationDomains;
+    }
+
+    protected boolean allowedStorageDomain(ArrayList<StorageDomain> 
sourceActiveStorageDomains, boolean shouldFilterBySourceType, DiskImage 
diskImage, DiskModel templateDisk, StorageDomain sd) {
+        // Destination should be in the same pool as the disk.
+        boolean connectedToSamePool = 
sd.getStoragePoolId().equals(diskImage.getStoragePoolId());
+        if (!connectedToSamePool) {
+            return false;
+        }
+
+        boolean hasSameSubType = sd.getStorageType().getStorageSubtype() == 
diskImage.getStorageTypes().get(0).getStorageSubtype();
+        if (shouldFilterBySourceType && !hasSameSubType) {
+            return false;
+        }
+
+        if (!isDomainValidForDiskTemplate(templateDisk, sd)) {
+            return false;
+        }
+
+        if (!isDiskValidForStorage(diskImage, sd)) {
+            return false;
+        }
+        return true;
     }
 
     private boolean isDomainValidForDiskTemplate(DiskModel templateDisk, 
StorageDomain sd) {
@@ -324,7 +329,7 @@
         return null;
     }
 
-    protected void onExecute() {
+    protected final void onExecute() {
         if (this.getProgress() != null)
         {
             return;
@@ -334,6 +339,10 @@
             return;
         }
 
+        doExecute();
+    }
+
+    protected void doExecute() {
         startProgress(null);
     }
 
@@ -349,6 +358,7 @@
             DiskImage disk = (DiskImage) diskModel.getDisk();
             DiskProfile diskProfile = 
diskModel.getDiskProfile().getSelectedItem();
             disk.setDiskProfileId(diskProfile != null ? diskProfile.getId() : 
null);
+            disk.setDiskAlias(diskModel.getAlias().getEntity());
             if (diskModel.getQuota().getSelectedItem() != null) {
                 
disk.setQuotaId(diskModel.getQuota().getSelectedItem().getId());
             }
@@ -375,6 +385,7 @@
         MoveOrCopyImageGroupParameters params = 
createParameters(sourceStorageDomainGuid, destStorageDomainGuid, disk);
         params.setQuotaId(disk.getQuotaId());
         params.setDiskProfileId(disk.getDiskProfileId());
+        params.setNewAlias(disk.getDiskAlias());
 
         parameters.add(params);
     }
@@ -392,15 +403,23 @@
     }
 
     public boolean validate() {
+        boolean quotaValidated = true;
+
         if (getQuotaEnforcementType() == QuotaEnforcementTypeEnum.DISABLED
                 || getQuotaEnforcementType() == 
QuotaEnforcementTypeEnum.SOFT_ENFORCEMENT) {
-            return true;
+            quotaValidated = false;
         }
 
         boolean isValid = true;
         for (DiskModel diskModel : getDisks()) {
-            diskModel.getQuota().validateSelectedItem(new IValidation[] { new 
SelectedQuotaValidation() });
-            isValid &= diskModel.getQuota().getIsValid();
+            if (quotaValidated) {
+                diskModel.getQuota().validateSelectedItem(new IValidation[] { 
new SelectedQuotaValidation() });
+                isValid &= diskModel.getQuota().getIsValid();
+            }
+
+            diskModel.getAlias().validateEntity(new IValidation[] { new 
NotEmptyValidation(), new I18NNameValidation() });
+            isValid &= diskModel.getAlias().getIsValid();
+
         }
 
         return isValid;
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/CopyDiskModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/CopyDiskModel.java
index 756a62d..676f40d 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/CopyDiskModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/CopyDiskModel.java
@@ -31,6 +31,7 @@
 
     @Override
     public void init(ArrayList<DiskImage> disksImages) {
+        setIsAliasChangable(true);
         setDiskImages(disksImages);
 
         AsyncDataProvider.getInstance().getDiskList(new AsyncQuery(this, new 
INewAsyncCallback() {
@@ -87,15 +88,17 @@
     protected MoveOrCopyImageGroupParameters createParameters(Guid 
sourceStorageDomainGuid,
             Guid destStorageDomainGuid,
             DiskImage disk) {
-        return new MoveOrCopyImageGroupParameters(disk.getImageId(),
+        MoveOrCopyImageGroupParameters moveOrCopyImageGroupParameters = new 
MoveOrCopyImageGroupParameters(disk.getImageId(),
                 sourceStorageDomainGuid,
                 destStorageDomainGuid,
                 ImageOperation.Copy);
+        moveOrCopyImageGroupParameters.setImageGroupID(disk.getId());
+        return moveOrCopyImageGroupParameters;
     }
 
     @Override
-    protected void onExecute() {
-        super.onExecute();
+    protected void doExecute() {
+        super.doExecute();
 
         ArrayList<VdcActionParametersBase> parameters = getParameters();
         if (parameters.isEmpty()) {
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/MoveDiskModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/MoveDiskModel.java
index d3629da..3665678 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/MoveDiskModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/MoveDiskModel.java
@@ -165,8 +165,8 @@
     }
 
     @Override
-    protected void onExecute() {
-        super.onExecute();
+    protected void doExecute() {
+        super.doExecute();
 
         ArrayList<VdcActionParametersBase> parameters = getParameters();
         if (parameters.isEmpty()) {
@@ -184,4 +184,16 @@
                     }
                 }, this);
     }
+
+    @Override
+    protected boolean allowedStorageDomain(ArrayList<StorageDomain> 
sourceActiveStorageDomains, boolean shouldFilterBySourceType, DiskImage 
diskImage, DiskModel templateDisk, StorageDomain sd) {
+        // can not move to the same storage domain
+        if (sourceActiveStorageDomains.contains(sd)) {
+            return false;
+        }
+
+        return super.allowedStorageDomain(sourceActiveStorageDomains, 
shouldFilterBySourceType, diskImage, templateDisk, sd);
+    }
+
+
 }
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 2e07cba..5dd17af 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
@@ -239,7 +239,6 @@
 ACTION_TYPE_FAILED_IMAGE_TYPE_DOES_NOT_EXIST=Cannot ${action} ${type}. The 
relevant Image Type doesn't exist.
 ACTION_TYPE_FAILED_TEMPLATE_IS_DISABLED=Cannot ${action} ${type}. The Template 
is disabled, please try to enable the template first and try again.
 ACTION_TYPE_FAILED_TEMPLATE_NOT_EXISTS_IN_CURRENT_DC=The specified Template 
doesn't exist in the current Data Center.
-ACTION_TYPE_FAILED_IMAGE_ALREADY_EXISTS=Cannot ${action} ${type}. One of the 
Template Images already exists.
 ACTION_TYPE_FAILED_TEMPLATE_GUID_ALREADY_EXISTS=Cannot ${action} ${type}. A 
Template with the same identifier already exists.
 ACTION_TYPE_FAILED_CANDIDATE_ALREADY_EXISTS=Cannot ${action} ${type}. The 
export candidate already exists in the specified path.\n\
 - Use the 'Force Override' option to override the existing file.
@@ -967,7 +966,6 @@
 ACTION_TYPE_FAILED_NO_DISKS_SPECIFIED=Cannot ${action} ${type}. No disks have 
been specified.
 ACTION_TYPE_FAILED_CANT_MOVE_SHAREABLE_DISK_TO_GLUSTERFS=Cannot ${action} 
${type}. ${diskAlias} is shareable, which Gluster domains do not support.
 ACTION_TYPE_FAILED_DISK_IS_NOT_VM_DISK=Cannot ${action} ${type}. The following 
disk(s) are not attached to any VM: ${diskAliases}.
-ACTION_TYPE_FAILED_DISK_IS_NOT_TEMPLATE_DISK=Cannot ${action} ${type}. The 
selected disk is not a template disk. Only template disks can be copied.
 ACTION_TYPE_FAILED_SOURCE_AND_TARGET_SAME=Cannot ${action} ${type}. The source 
and target storage domains are the same.
 ACTION_TYPE_FAILED_CANNOT_MOVE_TEMPLATE_DISK=Cannot ${action} ${type}. 
Template disks cannot be moved.
 ACTION_TYPE_FAILED_BASE_TEMPLATE_DOES_NOT_EXIST=Cannot ${action} ${type}. Base 
Template does not exist for this Template Version.
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 82fccad..d7caf47 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
@@ -253,7 +253,6 @@
 ACTION_TYPE_FAILED_IMAGE_TYPE_DOES_NOT_EXIST=Cannot ${action} ${type}. The 
relevant Image Type doesn't exist.
 ACTION_TYPE_FAILED_TEMPLATE_IS_DISABLED=Cannot ${action} ${type}. The Template 
is disabled, please try to enable the template first and try again.
 ACTION_TYPE_FAILED_TEMPLATE_NOT_EXISTS_IN_CURRENT_DC=The specified Template 
doesn't exist in the current Data Center.
-ACTION_TYPE_FAILED_IMAGE_ALREADY_EXISTS=Cannot ${action} ${type}. One of the 
Template Images already exists.
 ACTION_TYPE_FAILED_TEMPLATE_GUID_ALREADY_EXISTS=Cannot ${action} ${type}. A 
Template with the same identifier already exists.
 ACTION_TYPE_FAILED_CANDIDATE_ALREADY_EXISTS=Cannot ${action} ${type}. The 
export candidate already exists in the specified path.\n\
 - Use the 'Force Override' option to override the existing file.
@@ -1036,7 +1035,6 @@
 ACTION_TYPE_FAILED_NO_DISKS_SPECIFIED=Cannot ${action} ${type}. No disks have 
been specified.
 ACTION_TYPE_FAILED_CANT_MOVE_SHAREABLE_DISK_TO_GLUSTERFS=Cannot ${action} 
${type}. ${diskAlias} is shareable, which Gluster domains do not support.
 ACTION_TYPE_FAILED_DISK_IS_NOT_VM_DISK=Cannot ${action} ${type}. The following 
disk(s) are not attached to any VM: ${diskAliases}.
-ACTION_TYPE_FAILED_DISK_IS_NOT_TEMPLATE_DISK=Cannot ${action} ${type}. The 
selected disk is not a template disk. Only template disks can be copied.
 ACTION_TYPE_FAILED_SOURCE_AND_TARGET_SAME=Cannot ${action} ${type}. The source 
and target storage domains are the same.
 ACTION_TYPE_FAILED_CANNOT_MOVE_TEMPLATE_DISK=Cannot ${action} ${type}. 
Template disks cannot be moved.
 ACTION_TYPE_FAILED_BASE_TEMPLATE_DOES_NOT_EXIST=Cannot ${action} ${type}. Base 
Template does not exist for this Template Version.


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

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

Reply via email to