Omer Frenkel has uploaded a new change for review.

Change subject: core,webadmin: add isVm and isTemplate methods to VmEntityType
......................................................................

core,webadmin: add isVm and isTemplate methods to VmEntityType

Since now there are more types for VmEntityType (like instance type),
code that check for these types need to be updated.

Since the new entities are just types of templates,
and looking fwd we might add more like these,
looks like caller only want to know if this is a vm or a template.

So I added methods for easier reference,
and changed all references to specific types to the right method.

Change-Id: I6fc92031ab0afd08ab309a8ef6fd71a3fddb2204
Signed-off-by: Omer Frenkel <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmEntityType.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
5 files changed, 42 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/98/21598/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
index 74d7210..574707b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
@@ -28,7 +28,6 @@
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
-import org.ovirt.engine.core.common.businessentities.VmEntityType;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.locks.LockingGroup;
@@ -126,12 +125,12 @@
      */
     protected boolean checkOperationIsCorrect() {
         if (getParameters().getOperation() == ImageOperation.Copy
-                && getImage().getVmEntityType() != VmEntityType.TEMPLATE) {
+                && !getImage().getVmEntityType().isTemplateType()) {
             return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_DISK_IS_NOT_TEMPLATE_DISK);
         }
 
         if (getParameters().getOperation() == ImageOperation.Move
-                && getImage().getVmEntityType() == VmEntityType.TEMPLATE) {
+                && !getImage().getVmEntityType().isVmType()) {
             return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_DISK_IS_NOT_VM_DISK);
         }
         return true;
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
index 6da39d8..9909f0f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
@@ -36,11 +36,10 @@
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
-import org.ovirt.engine.core.common.businessentities.VmEntityType;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.VmTemplateStatus;
-import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.TransactionScopeOption;
@@ -84,7 +83,7 @@
     }
 
     private boolean validateAllVmsForDiskAreDown() {
-        if (getDisk().getVmEntityType() == VmEntityType.VM) {
+        if (getDisk().getVmEntityType().isVmType()) {
             for (VM vm : getVmsForDiskId()) {
                 if (vm.getStatus() != VMStatus.Down) {
                     VmDevice vmDevice = getVmDeviceDAO().get(new 
VmDeviceId(getDisk().getId(), vm.getId()));
@@ -113,7 +112,7 @@
     private boolean canRemoveDiskBasedOnImageStorageCheck() {
         boolean retValue = true;
         DiskImage diskImage = getDiskImage();
-        if (diskImage.getVmEntityType() == VmEntityType.TEMPLATE) {
+        if (diskImage.getVmEntityType().isTemplateType()) {
             // Temporary fix until re factoring vm_images_view and 
image_storage_domain_view
             
diskImage.setStorageIds(getDiskImageDao().get(diskImage.getImageId()).getStorageIds());
         } else if ((getParameters().getStorageDomainId() == null) || 
(Guid.Empty.equals(getParameters().getStorageDomainId()))) {
@@ -136,9 +135,9 @@
             
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_OBJECT_LOCKED);
         }
         if (retValue) {
-            if (getDisk().getVmEntityType() == VmEntityType.VM) {
+            if (getDisk().getVmEntityType().isVmType()) {
                 retValue = canRemoveVmImageDisk();
-            } else if (getDisk().getVmEntityType() == VmEntityType.TEMPLATE) {
+            } else if (getDisk().getVmEntityType().isTemplateType()) {
                 retValue = canRemoveTemplateDisk();
             }
         }
@@ -358,16 +357,17 @@
             return null;
         }
 
-        switch (getDisk().getVmEntityType()) {
-        case VM:
+        if (getDisk().getVmEntityType().isVmType()) {
             return createSharedLocksForVmDisk();
-        case TEMPLATE:
-            return createSharedLocksForTemplateDisk();
-        default:
-            log.warnFormat("No shared locks are taken while removing disk of 
entity: {0}",
-                    getDisk().getVmEntityType());
-            return null;
         }
+
+        if (getDisk().getVmEntityType().isTemplateType()) {
+            return createSharedLocksForTemplateDisk();
+        }
+
+        log.warnFormat("No shared locks are taken while removing disk of 
entity: {0}",
+                getDisk().getVmEntityType());
+        return null;
     }
 
     private Map<String, Pair<String, String>> createSharedLocksForVmDisk() {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmEntityType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmEntityType.java
index 0b5adeb..c67cd2b 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmEntityType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmEntityType.java
@@ -9,4 +9,22 @@
     TEMPLATE,
     INSTANCE_TYPE,
     IMAGE_TYPE;
+
+    /**
+     * Check if entity type is of a VM
+     * @return true if entity type is of a VM
+     */
+    public boolean isVmType() {
+        return this == VM;
+    }
+
+    /**
+     * Check if entity type is of a Template
+     * @return true if entity type is of a Template
+     */
+    public boolean isTemplateType() {
+        return this == TEMPLATE ||
+                this == INSTANCE_TYPE ||
+                this == IMAGE_TYPE;
+    }
 }
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
index ce9d09a..5f48840 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
@@ -8,7 +8,6 @@
 import org.ovirt.engine.core.common.businessentities.DiskInterface;
 import org.ovirt.engine.core.common.businessentities.ImageStatus;
 import org.ovirt.engine.core.common.businessentities.LunDisk;
-import org.ovirt.engine.core.common.businessentities.VmEntityType;
 import org.ovirt.engine.core.common.businessentities.VolumeType;
 import org.ovirt.engine.core.common.utils.SizeConverter;
 import org.ovirt.engine.ui.common.CommonApplicationConstants;
@@ -26,10 +25,10 @@
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.DiskModel;
 
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.resources.client.ImageResource;
 import com.google.gwt.cell.client.FieldUpdater;
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.resources.client.ImageResource;
 
 public class DisksViewColumns {
     private static final CommonApplicationResources resources = 
GWT.create(CommonApplicationResources.class);
@@ -127,8 +126,8 @@
         @Override
         public ImageResource getValue(Disk object) {
             setEnumTitle(object.getVmEntityType());
-            return object.getVmEntityType() == VmEntityType.VM ? 
resources.vmsImage() :
-                    object.getVmEntityType() == VmEntityType.TEMPLATE ? 
resources.templatesImage() : null;
+            return object.getVmEntityType().isVmType() ? resources.vmsImage() :
+                    object.getVmEntityType().isTemplateType() ? 
resources.templatesImage() : null;
         }
     };
 
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 5460ffa..1666da1 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,7 +13,6 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.ImageStatus;
 import org.ovirt.engine.core.common.businessentities.Quota;
-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;
@@ -249,8 +248,8 @@
         {
             Disk disk = (Disk) getSelectedItem();
 
-            diskVmListModel.setIsAvailable(disk.getVmEntityType() != 
VmEntityType.TEMPLATE);
-            diskTemplateListModel.setIsAvailable(disk.getVmEntityType() == 
VmEntityType.TEMPLATE);
+            diskVmListModel.setIsAvailable(disk.getVmEntityType().isVmType());
+            
diskTemplateListModel.setIsAvailable(disk.getVmEntityType().isTemplateType());
             diskStorageListModel.setIsAvailable(disk.getDiskStorageType() == 
DiskStorageType.IMAGE);
         }
     }
@@ -543,7 +542,7 @@
                 return;
             }
 
-            if (disk.getVmEntityType() == VmEntityType.TEMPLATE) {
+            if (disk.getVmEntityType().isTemplateType()) {
                 isMoveAllowed = false;
             }
             else {
@@ -566,7 +565,7 @@
 
         for (Disk disk : disks)
         {
-            boolean isTemplateDisk = disk.getVmEntityType() == 
VmEntityType.TEMPLATE;
+            boolean isTemplateDisk = disk.getVmEntityType().isTemplateType();
             boolean isImageLocked = disk.getDiskStorageType() == 
DiskStorageType.IMAGE
                     && ((DiskImage) disk).getImageStatus() == 
ImageStatus.LOCKED;
 


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

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

Reply via email to