Frank Kobzik has uploaded a new change for review.

Change subject: core: add graphics device to management classes
......................................................................

core: add graphics device to management classes

This patch adds graphics device to vm/template management (CRUD)
commands.

Change-Id: I39c84ce94cd3cb52286c52d765a389e69c9b0e62
Signed-off-by: Frantisek Kobzik <[email protected]>
Bug-Url: https://bugzilla.redhat.com/1033547
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmTemplateCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmPoolWithVmsParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
15 files changed, 328 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/67/28567/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
index de32b39..50c1703 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
@@ -39,6 +39,8 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.DiskInterface;
 import org.ovirt.engine.core.common.businessentities.DisplayType;
+import org.ovirt.engine.core.common.businessentities.GraphicsDevice;
+import org.ovirt.engine.core.common.businessentities.GraphicsType;
 import org.ovirt.engine.core.common.businessentities.ImageType;
 import org.ovirt.engine.core.common.businessentities.InstanceType;
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
@@ -356,6 +358,23 @@
         return validate(storageDomainValidator.hasSpaceForNewDisks(disksList));
     }
 
+    boolean checkNumberOfMonitors() {
+        boolean result = true;
+        int numOfMonitors = 
getParameters().getVmStaticData().getNumOfMonitors();
+
+        for (GraphicsType type : GraphicsType.values()) {
+            if (getParameters().shouldUpdateGraphicsDevice(type)) {
+                GraphicsDevice graphicsDevice = 
getParameters().getGraphicsDevice(type);
+                if (graphicsDevice == null) {
+                    return false;
+                }
+                result = result && VmHandler.isNumOfMonitorsLegal(type, 
numOfMonitors, getReturnValue().getCanDoActionMessages());
+            }
+        }
+
+        return result;
+    }
+
     protected boolean checkSingleQxlDisplay() {
         if (!getParameters().getVmStaticData().getSingleQxlPci()) {
             return true;
@@ -364,12 +383,6 @@
                         getParameters().getVm().getOs(),
                         getReturnValue().getCanDoActionMessages(),
                         getVdsGroup().getcompatibility_version()));
-    }
-
-    protected boolean checkNumberOfMonitors() {
-        return 
VmHandler.isNumOfMonitorsLegal(getParameters().getVmStaticData().getDefaultDisplayType(),
-                getParameters().getVmStaticData().getNumOfMonitors(),
-                getReturnValue().getCanDoActionMessages());
     }
 
     protected boolean hostToRunExist() {
@@ -510,6 +523,7 @@
         }
 
         // Check if the display type is supported
+        // todo os info follow up - also check graphics!
         if 
(!VmHandler.isDisplayTypeSupported(getParameters().getVmStaticData().getOsId(),
                 vmFromParams.getDefaultDisplayType(),
                 getReturnValue().getCanDoActionMessages(),
@@ -726,6 +740,7 @@
                     addActiveSnapshot();
                     addVmPermission();
                     addVmInit();
+                    addGraphicsDevice();
                     getCompensationContext().stateChanged();
                     return null;
                 }
@@ -751,6 +766,18 @@
             }
         } else {
             log.errorFormat("Failed to add vm . The reasons are: {0}", 
StringUtils.join(errorMessages, ','));
+        }
+    }
+
+    private void addGraphicsDevice() {
+        for (GraphicsType type : GraphicsType.values()) {
+            GraphicsDevice graphicsDevice = 
getParameters().getGraphicsDevice(type);
+            if (graphicsDevice == null) {
+                continue;
+            }
+
+            graphicsDevice.setVmId(getVmId());
+            getBackend().runInternalAction(VdcActionType.AddGraphicsDevice, 
new GraphicsParameters(graphicsDevice));
         }
     }
 
@@ -1285,6 +1312,7 @@
         }
 
         // Choose a proper default display type according to the cluster 
architecture
+        // todo os info follow up
         if (getParameters().getVmStaticData().getOsId() != 
OsRepository.AUTO_SELECT_OS &&
                 getParameters().getVmStaticData().getDefaultDisplayType() == 
null) {
             DisplayType defaultDisplayType =
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
index d1efa37..12f0a6e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
@@ -313,6 +313,7 @@
         }
 
         // Check if the display type is supported
+        // todo osinfo followup
         if 
(!VmHandler.isDisplayTypeSupported(getParameters().getMasterVm().getOsId(),
                 getParameters().getMasterVm().getDefaultDisplayType(),
                 getReturnValue().getCanDoActionMessages(),
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
index 21535b5..6eb3057 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
@@ -88,6 +88,7 @@
                 }
 
                 // Check if the display type is supported
+                // todo osinfo followup
                 if (!VmHandler.isDisplayTypeSupported(vm.getOs(),
                         vm.getDefaultDisplayType(),
                         getReturnValue().getCanDoActionMessages(),
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
index 1352db9..12387ca 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
@@ -421,6 +421,7 @@
         }
 
         // Check if the display type is supported
+        // todo osinfo followup
         if (!VmHandler.isDisplayTypeSupported(vmFromParams.getOs(),
                 vmFromParams.getDefaultDisplayType(),
                 getReturnValue().getCanDoActionMessages(),
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
index 397069a..ba8bfa8 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
@@ -31,6 +31,8 @@
 import org.ovirt.engine.core.common.businessentities.ActionGroup;
 import org.ovirt.engine.core.common.businessentities.Disk;
 import org.ovirt.engine.core.common.businessentities.DiskInterface;
+import org.ovirt.engine.core.common.businessentities.GraphicsDevice;
+import org.ovirt.engine.core.common.businessentities.GraphicsType;
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
 import org.ovirt.engine.core.common.businessentities.Snapshot;
 import org.ovirt.engine.core.common.businessentities.VM;
@@ -132,6 +134,7 @@
             updateVmPayload();
             VmDeviceUtils.updateVmDevices(getParameters(), oldVm);
             updateWatchdog();
+            updateGraphicsDevice();
         }
         VmHandler.updateVmInitToDB(getParameters().getVmStaticData());
 
@@ -237,6 +240,47 @@
             }
 
         }
+    }
+
+    private void updateGraphicsDevice() {
+        for (GraphicsType type : GraphicsType.values()) {
+            if (!getParameters().shouldUpdateGraphicsDevice(type)) {
+                continue;
+            }
+
+            GraphicsDevice vmGraphicsDevice = getGraphicsDevOfType(type);
+            if (vmGraphicsDevice == null) {
+                if (getParameters().getGraphicsDevice(type) != null) {
+                    getParameters().getGraphicsDevice(type).setVmId(getVmId());
+                    
getBackend().runInternalAction(VdcActionType.AddGraphicsDevice,
+                            new 
GraphicsParameters(getParameters().getGraphicsDevice(type)));
+                }
+            } else {
+                if (getParameters().getGraphicsDevice(type) == null) {
+                    
getBackend().runInternalAction(VdcActionType.RemoveGraphicsDevice,
+                            new GraphicsParameters(vmGraphicsDevice));
+                } else {
+                    getParameters().getGraphicsDevice(type).setVmId(getVmId());
+                    
getBackend().runInternalAction(VdcActionType.UpdateGraphicsDevice,
+                            new 
GraphicsParameters(getParameters().getGraphicsDevice(type)));
+                }
+            }
+        }
+    }
+
+    // first dev or null
+    private GraphicsDevice getGraphicsDevOfType(GraphicsType type) {
+        VdcQueryReturnValue query =
+                getBackend().runInternalQuery(VdcQueryType.GetGraphicsDevices, 
new IdQueryParameters(getParameters().getVmId()));
+        List<GraphicsDevice> graphicsDevices = query.getReturnValue();
+
+        for (GraphicsDevice dev : graphicsDevices) {
+            if (dev.getVmDeviceType() == type.getCorrespondingDeviceType()) {
+                return dev;
+            }
+        }
+
+        return null;
     }
 
     protected void updateVmPayload() {
@@ -389,10 +433,8 @@
         }
 
         // Check if number of monitors passed is legal
-        if 
(!VmHandler.isNumOfMonitorsLegal(vmFromParams.getDefaultDisplayType(),
-                vmFromParams.getNumOfMonitors(),
-                getReturnValue().getCanDoActionMessages())) {
-            return false;
+        if (!checkNumberOfMonitors()) {
+            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_ILLEGAL_NUM_OF_MONITORS);
         }
 
         // Check PCI and IDE limits are ok
@@ -444,6 +486,7 @@
         }
 
         // Check if the display type is supported
+        // todo address this in os info follow up
         if (!VmHandler.isDisplayTypeSupported(vmFromParams.getOs(),
                 vmFromParams.getDefaultDisplayType(),
                 getReturnValue().getCanDoActionMessages(),
@@ -517,6 +560,24 @@
         return true;
     }
 
+    private boolean checkNumberOfMonitors() { // todo this is a perfect 
example of pure ugliness
+        List<VmDevice> currentVmGraphics= 
getVmDeviceDao().getVmDeviceByVmIdAndType(getVmId(), 
VmDeviceGeneralType.GRAPHICS);
+
+        boolean result = true;
+        int numOfMonitors = 
getParameters().getVmStaticData().getNumOfMonitors();
+
+        for (GraphicsType type : GraphicsType.values()) {
+            boolean resultVmHasGraphicsOfType = 
getParameters().shouldUpdateGraphicsDevice(type) && 
getParameters().getGraphicsDevice(type) != null;
+            for (VmDevice currentVmGraphic : currentVmGraphics) {
+                if (resultVmHasGraphicsOfType || 
type.getCorrespondingDeviceType().name().equalsIgnoreCase(currentVmGraphic.getDevice()))
 { // todo rewrite
+                    result = result && VmHandler.isNumOfMonitorsLegal(type, 
numOfMonitors, getReturnValue().getCanDoActionMessages());
+                }
+            }
+        }
+
+        return result;
+    }
+
     protected boolean isValidPciAndIdeLimit(VM vmFromParams) {
         List<Disk> allDisks = 
getDbFacade().getDiskDao().getAllForVm(getVmId());
         List<VmNic> interfaces = getVmNicDao().getAllForVm(getVmId());
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
index 090e442..7542aab 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
@@ -11,14 +11,20 @@
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.UpdateVmTemplateParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.ActionGroup;
 import org.ovirt.engine.core.common.businessentities.DiskImageBase;
+import org.ovirt.engine.core.common.businessentities.GraphicsDevice;
+import org.ovirt.engine.core.common.businessentities.GraphicsType;
 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.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.locks.LockingGroup;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.common.validation.group.UpdateEntity;
 import org.ovirt.engine.core.compat.Guid;
@@ -116,6 +122,7 @@
         }
 
         // Check if the display type is supported
+        // todo osinfo followup
         if (returnValue) {
             returnValue = 
VmHandler.isDisplayTypeSupported(getParameters().getVmTemplateData().getOsId(),
                     
getParameters().getVmTemplateData().getDefaultDisplayType(),
@@ -194,6 +201,7 @@
             updateOriginalTemplateNameOnDerivedVms();
             UpdateVmTemplate();
             updateWatchdog(getParameters().getVmTemplateData().getId());
+            updateGraphicsDevice();
             checkTrustedService();
             setSucceeded(true);
         }
@@ -316,4 +324,43 @@
         return super.isQuotaDependant();
     }
 
+    private void updateGraphicsDevice() {
+        for (GraphicsType type : GraphicsType.values()) {
+            if (!getParameters().shouldUpdateGraphicsDevice(type)) {
+                continue;
+            }
+
+            GraphicsDevice vmGraphicsDevice = getGraphicsDevOfType(type);
+            if (vmGraphicsDevice == null) {
+                if (getParameters().getGraphicsDevice(type) != null) {
+                    
getBackend().runInternalAction(VdcActionType.AddGraphicsDevice,
+                            new 
GraphicsParameters(getParameters().getGraphicsDevice(type)));
+                }
+            } else {
+                if (getParameters().getGraphicsDevice(type) == null) {
+                    
getBackend().runInternalAction(VdcActionType.RemoveGraphicsDevice,
+                            new GraphicsParameters(vmGraphicsDevice));
+                } else {
+                    
getBackend().runInternalAction(VdcActionType.UpdateGraphicsDevice,
+                            new 
GraphicsParameters(getParameters().getGraphicsDevice(type)));
+                }
+            }
+        }
+    }
+
+    // first dev or null
+    private GraphicsDevice getGraphicsDevOfType(GraphicsType type) {
+        VdcQueryReturnValue query =
+                getBackend().runInternalQuery(VdcQueryType.GetGraphicsDevices, 
new IdQueryParameters(getParameters().getVmTemplateId()));
+        List<GraphicsDevice> graphicsDevices = query.getReturnValue();
+
+        for (GraphicsDevice dev : graphicsDevices) {
+            if (dev.getVmDeviceType() == type.getCorrespondingDeviceType()) {
+                return dev;
+            }
+        }
+
+        return null;
+    }
+
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
index bb297ac..ba61903 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
@@ -26,6 +26,7 @@
 import org.ovirt.engine.core.common.businessentities.EditableField;
 import org.ovirt.engine.core.common.businessentities.EditableOnVm;
 import org.ovirt.engine.core.common.businessentities.EditableOnVmStatusField;
+import org.ovirt.engine.core.common.businessentities.GraphicsType;
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
 import org.ovirt.engine.core.common.businessentities.UsbPolicy;
@@ -551,25 +552,27 @@
     /**
      * Checks number of monitors validation according to VM and Display types.
      *
-     * @param displayType
-     *            Display type : Spice or Vnc
+     * @param graphicsType
+     *            Graphics type : Spice or Vnc
      * @param numOfMonitors
      *            Number of monitors
      * @param reasons
      *            Messages for CanDoAction().
      * @return
      */
-    public static boolean isNumOfMonitorsLegal(DisplayType displayType, int 
numOfMonitors, List<String> reasons) {
-        boolean legal = true;
-        if (displayType == DisplayType.vnc) {
+    public static boolean isNumOfMonitorsLegal(GraphicsType graphicsType, int 
numOfMonitors, List<String> reasons) {
+        boolean legal = false;
+
+        if (graphicsType == GraphicsType.VNC) {
             legal = (numOfMonitors <= 1);
-        }
-        else { // Spice
+        } else if (graphicsType == GraphicsType.SPICE) { // Spice
             legal = (numOfMonitors <= getMaxNumberOfMonitors());
         }
+
         if (!legal) {
             
reasons.add(VdcBllMessages.ACTION_TYPE_FAILED_ILLEGAL_NUM_OF_MONITORS.toString());
         }
+
         return legal;
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
index 40f05e3..d4f9f05 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
@@ -213,4 +213,5 @@
     protected boolean isCpuSharesValid(VM vmData) {
         return (vmData.getCpuShares() >= 0 && vmData.getCpuShares() <= 
MAXIMUM_CPU_SHARES);
     }
+
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmTemplateCommand.java
index 328dba9..c1a344c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmTemplateCommand.java
@@ -4,7 +4,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.validator.StorageDomainValidator;
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
index d49d558..d2e3fa6 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
@@ -410,15 +410,23 @@
             //  update devices boot order
             updateBootOrderInVmDeviceAndStoreToDB(vmBase);
 
-            int numOfMonitors = (vmBase.getDefaultDisplayType() == 
DisplayType.vnc) ? Math.max(1, vmBase.getNumOfMonitors()) :
-                vmBase.getSingleQxlPci() ? 1 : vmBase.getNumOfMonitors();
+            int numOfMonitors = getNumOfMonitors(vm);
+
             // create Video device. Multiple if display type is spice
+            // todo revisit (case spice+vnc)
             for (int i = 0; i < numOfMonitors; i++) {
                 addVideoDevice(vmBase);
             }
         }
     }
 
+    private static int getNumOfMonitors(VM vm) { // revisit, this is gonna be 
so wrong
+        int maxMonitorsSpice = vm.getSingleQxlPci() ? 1 : 
vm.getNumOfMonitors();
+        int maxMonitorsVnc = Math.max(1, vm.getNumOfMonitors());
+
+        return Math.min(maxMonitorsSpice, maxMonitorsVnc);
+    }
+
     private static void addSoundCard(VmBase vmBase) {
         addSoundCard(vmBase, ClusterUtils.getCompatibilityVersion(vmBase));
     }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
index 9902a70..16a4f59 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
@@ -30,6 +30,7 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.DiskInterface;
 import org.ovirt.engine.core.common.businessentities.DisplayType;
+import org.ovirt.engine.core.common.businessentities.GraphicsDevice;
 import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
@@ -240,6 +241,13 @@
         
assertCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_ILLEGAL_NUM_OF_MONITORS);
     }
 
+    private void mockGraphicsDevice() {
+        doReturn(vmDeviceDAO).when(command).getVmDeviceDao();
+        VmDevice graphicsDevice = new GraphicsDevice(VmDeviceType.SPICE);
+        graphicsDevice.setVmId(vm.getId());
+        when(vmDeviceDAO.getVmDeviceByVmIdAndType(vm.getId(), 
VmDeviceGeneralType.GRAPHICS)).thenReturn(Arrays.asList(graphicsDevice));
+    }
+
     @Test
     public void testUpdateFieldsQuotaEnforcementType() {
         vm.setQuotaEnforcementType(QuotaEnforcementTypeEnum.DISABLED);
@@ -336,6 +344,7 @@
         mockSameNameQuery(false);
         mockValidateCustomProperties();
         mockValidatePciAndIdeLimit();
+        mockGraphicsDevice();
     }
 
     private void assertCanDoActionMessage(VdcBllMessages msg) {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmPoolWithVmsParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmPoolWithVmsParameters.java
index 8b073fd..e1b04c2 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmPoolWithVmsParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmPoolWithVmsParameters.java
@@ -1,13 +1,18 @@
 package org.ovirt.engine.core.common.action;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
-
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 import javax.validation.Valid;
-
 import org.ovirt.engine.core.common.businessentities.DiskImage;
+import org.ovirt.engine.core.common.businessentities.GraphicsDevice;
+import org.ovirt.engine.core.common.businessentities.GraphicsType;
 import org.ovirt.engine.core.common.businessentities.VM;
-import org.ovirt.engine.core.common.businessentities.VmStatic;
 import org.ovirt.engine.core.common.businessentities.VmPool;
+import org.ovirt.engine.core.common.businessentities.VmStatic;
 import org.ovirt.engine.core.compat.Guid;
 
 public class AddVmPoolWithVmsParameters extends VmPoolOperationParameters {
@@ -21,6 +26,14 @@
     private Boolean soundDeviceEnabled;
     private Boolean consoleEnabled;
     private Boolean virtioScsiEnabled;
+    private Map<GraphicsType, GraphicsDevice> graphicsDevices;
+
+    /*
+     * This parameter is used to decide if to create graphics device or not. 
If it is null then:
+     *  - for add vm don't add graphics device,
+     *  - for update the current configuration will remain.
+     */
+    private Map<GraphicsType, Boolean> shouldUpdateGraphicsDevice;
 
     public AddVmPoolWithVmsParameters() {
     }
@@ -77,4 +90,34 @@
     public void setVirtioScsiEnabled(Boolean virtioScsiEnabled) {
         this.virtioScsiEnabled = virtioScsiEnabled;
     }
+
+    public Collection<GraphicsDevice> getGraphicsDevices() {
+        return Collections.unmodifiableCollection(graphicsDevices.values());
+    }
+
+    public GraphicsDevice getGraphicsDevice(GraphicsType type) {
+        return graphicsDevices.get(type);
+    }
+
+    public void setGraphicsDevice(GraphicsDevice dev) {
+        
graphicsDevices.put(GraphicsType.fromVmDeviceType(dev.getVmDeviceType()), dev);
+    }
+
+    public void setShouldUpdateGraphicsDevice(GraphicsType type, boolean 
shouldUpdate) {
+        this.shouldUpdateGraphicsDevice.put(type, shouldUpdate);
+    }
+
+    public boolean shouldUpdateGraphicsDevice(GraphicsType type) {
+        return Boolean.TRUE.equals(shouldUpdateGraphicsDevice.get(type));
+    }
+
+    public Set<GraphicsType> graphicsTypesToBeSet() {
+        HashSet<GraphicsType> graphicsTypes = new HashSet<GraphicsType>();
+
+        for (GraphicsType type : graphicsDevices.keySet()) {
+            graphicsTypes.add(type);
+        }
+
+        return graphicsTypes;
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
index 80a390b..3869312 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
@@ -1,10 +1,15 @@
 package org.ovirt.engine.core.common.action;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
-
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 import javax.validation.Valid;
-
 import org.ovirt.engine.core.common.businessentities.DiskImage;
+import org.ovirt.engine.core.common.businessentities.GraphicsDevice;
+import org.ovirt.engine.core.common.businessentities.GraphicsType;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmPayload;
 import org.ovirt.engine.core.common.businessentities.VmStatic;
@@ -27,6 +32,7 @@
     private VmWatchdog watchdog;
     private boolean copyTemplatePermissions;
     private boolean applyChangesLater;
+    private Map<GraphicsType, GraphicsDevice> graphicsDevices;
 
     /*
      * This parameter is needed at update to make sure that when we get a null 
watchdog from rest-api it is not meant to
@@ -53,18 +59,29 @@
      */
     private Boolean virtioScsiEnabled;
 
+    /*
+     * This parameter is used to decide if to create graphics device or not. 
If it is null then:
+     *  - for add vm don't add graphics device,
+     *  - for update the current configuration will remain.
+     */
+    private Map<GraphicsType, Boolean> shouldUpdateGraphicsDevice;
+
     public VmManagementParametersBase() {
-        privateStorageDomainId = Guid.Empty;
-        consoleEnabled = Boolean.FALSE;
-        balloonEnabled = true;
+        init();
     }
 
     public VmManagementParametersBase(VmStatic vmStatic) {
         super(vmStatic.getId());
         _vmStatic = vmStatic;
+        init();
+    }
+
+    private void init() {
         privateStorageDomainId = Guid.Empty;
         consoleEnabled = Boolean.FALSE;
         balloonEnabled = true;
+        graphicsDevices = new HashMap<GraphicsType, GraphicsDevice>();
+        shouldUpdateGraphicsDevice = new HashMap<GraphicsType, Boolean>();
     }
 
     public VmManagementParametersBase(VM vm) {
@@ -206,4 +223,35 @@
     public void setApplyChangesLater(boolean applyChangesLater) {
         this.applyChangesLater = applyChangesLater;
     }
+
+    public Collection<GraphicsDevice> getGraphicsDevices() {
+        return Collections.unmodifiableCollection(graphicsDevices.values());
+    }
+
+    public GraphicsDevice getGraphicsDevice(GraphicsType type) {
+        return graphicsDevices.get(type);
+    }
+
+    public void setGraphicsDevice(GraphicsDevice dev) {
+        
graphicsDevices.put(GraphicsType.fromVmDeviceType(dev.getVmDeviceType()), dev);
+    }
+
+    public void setShouldUpdateGraphicsDevice(GraphicsType type, boolean 
shouldUpdate) {
+        this.shouldUpdateGraphicsDevice.put(type, shouldUpdate);
+    }
+
+    public boolean shouldUpdateGraphicsDevice(GraphicsType type) {
+        return Boolean.TRUE.equals(shouldUpdateGraphicsDevice.get(type));
+    }
+
+    public Set<GraphicsType> graphicsTypesToBeSet() {
+        HashSet<GraphicsType> graphicsTypes = new HashSet<GraphicsType>();
+
+        for (GraphicsType type : graphicsDevices.keySet()) {
+            graphicsTypes.add(type);
+        }
+
+        return graphicsTypes;
+    }
+
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java
index 0a9bb9a..b2f1954 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java
@@ -1,8 +1,16 @@
 package org.ovirt.engine.core.common.action;
 
 import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 
+import java.util.Map;
+import java.util.Set;
+import org.ovirt.engine.core.common.businessentities.GraphicsDevice;
+import org.ovirt.engine.core.common.businessentities.GraphicsType;
 import org.ovirt.engine.core.common.businessentities.VmWatchdog;
 import org.ovirt.engine.core.compat.Guid;
 
@@ -15,12 +23,19 @@
     private VmWatchdog watchdog;
     private Boolean virtioScsiEnabled;
     private boolean balloonEnabled;
+    private Map<GraphicsType, GraphicsDevice> graphicsDevices;
 
     /*
      * see VmManagementParametersBase#updateWatchdog for details
      */
     private boolean updateWatchdog;
 
+    /*
+     * This parameter is used to decide if to create graphics device or not. 
If it is null then:
+     *  - for add vm don't add graphics device,
+     *  - for update the current configuration will remain.
+     */
+    private Map<GraphicsType, Boolean> shouldUpdateGraphicsDevice;
 
     public boolean getCheckDisksExists() {
         return privateCheckDisksExists;
@@ -32,6 +47,8 @@
 
     public VmTemplateParametersBase(Guid vmTemplateId) {
         this.vmTemplateId = vmTemplateId;
+        graphicsDevices = new HashMap<GraphicsType, GraphicsDevice>();
+        shouldUpdateGraphicsDevice = new HashMap<GraphicsType, Boolean>();
     }
 
     public Guid getVmTemplateId() {
@@ -49,7 +66,7 @@
     }
 
     public VmTemplateParametersBase() {
-        vmTemplateId = Guid.Empty;
+        this(Guid.Empty);
     }
 
     public void setRemoveTemplateFromDb(boolean removeTemplateFromDb) {
@@ -99,4 +116,35 @@
     public void setBalloonEnabled(boolean balloonEnabled) {
         this.balloonEnabled = balloonEnabled;
     }
+
+    public Collection<GraphicsDevice> getGraphicsDevices() {
+        return Collections.unmodifiableCollection(graphicsDevices.values());
+    }
+
+    public GraphicsDevice getGraphicsDevice(GraphicsType type) {
+        return graphicsDevices.get(type);
+    }
+
+    public void setGraphicsDevice(GraphicsDevice dev) {
+        
graphicsDevices.put(GraphicsType.fromVmDeviceType(dev.getVmDeviceType()), dev);
+    }
+
+    public void setShouldUpdateGraphicsDevice(GraphicsType type, boolean 
shouldUpdate) {
+        this.shouldUpdateGraphicsDevice.put(type, shouldUpdate);
+    }
+
+    public boolean shouldUpdateGraphicsDevice(GraphicsType type) {
+        return Boolean.TRUE.equals(shouldUpdateGraphicsDevice.get(type));
+    }
+
+    public Set<GraphicsType> graphicsTypesToBeSet() {
+        HashSet<GraphicsType> graphicsTypes = new HashSet<GraphicsType>();
+
+        for (GraphicsType type : graphicsDevices.keySet()) {
+            graphicsTypes.add(type);
+        }
+
+        return graphicsTypes;
+    }
+
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
index 117c6f7..03aa97f 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
@@ -2,6 +2,7 @@
 
 import org.ovirt.engine.core.common.utils.VmDeviceType;
 
+// todo - note  - now this is display type. because of os info, we don't 
change this now but in follow up
 public enum DisplayType {
     vnc(VmDeviceType.VGA),
     qxl(VmDeviceType.QXL);


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

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

Reply via email to