Martin Peřina has uploaded a new change for review.

Change subject: core: DB support for device custom properties
......................................................................

core: DB support for device custom properties

 - Adds custom_properties column to vm_device table.
 - Adds SupportCustomDeviceProperties to vdc_options to support only
   3.3+ versions
 - Adds CustomDeviceProperties to vdc_options to store properties

Change-Id: I67ed453706ac75cdc4356cc2d60913d8958c89ed
Signed-off-by: Martin Perina <mper...@redhat.com>
---
M backend/manager/dbscripts/create_views.sql
A backend/manager/dbscripts/upgrade/03_03_0100_add_device_custom_prop.sql
M backend/manager/dbscripts/vm_device_sp.sql
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.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/GetAllDisksByVmIdQueryTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
12 files changed, 74 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/09/14309/1

diff --git a/backend/manager/dbscripts/create_views.sql 
b/backend/manager/dbscripts/create_views.sql
index 30929d3..ebccfa2 100644
--- a/backend/manager/dbscripts/create_views.sql
+++ b/backend/manager/dbscripts/create_views.sql
@@ -1428,7 +1428,7 @@
 CREATE OR REPLACE VIEW vm_device_view
 AS
 SELECT device_id, vm_id, type, device, address, boot_order, spec_params,
-       is_managed, is_plugged, is_readonly, alias
+       is_managed, is_plugged, is_readonly, alias, custom_properties
   FROM vm_device;
 
 CREATE OR REPLACE VIEW vm_interface_ext_view
diff --git 
a/backend/manager/dbscripts/upgrade/03_03_0100_add_device_custom_prop.sql 
b/backend/manager/dbscripts/upgrade/03_03_0100_add_device_custom_prop.sql
new file mode 100644
index 0000000..bc02369
--- /dev/null
+++ b/backend/manager/dbscripts/upgrade/03_03_0100_add_device_custom_prop.sql
@@ -0,0 +1,9 @@
+select fn_db_add_column('vm_device', 'custom_properties', 'VARCHAR(4000)');
+select fn_db_add_config_value('SupportCustomDeviceProperties', 'false', '3.0');
+select fn_db_add_config_value('SupportCustomDeviceProperties', 'false', '3.1');
+select fn_db_add_config_value('SupportCustomDeviceProperties', 'false', '3.2');
+select fn_db_add_config_value('SupportCustomDeviceProperties', 'true', '3.3');
+select fn_db_add_config_value('CustomDeviceProperties', '', '3.0');
+select fn_db_add_config_value('CustomDeviceProperties', '', '3.1');
+select fn_db_add_config_value('CustomDeviceProperties', '', '3.2');
+select fn_db_add_config_value('CustomDeviceProperties', '', '3.3');
\ No newline at end of file
diff --git a/backend/manager/dbscripts/vm_device_sp.sql 
b/backend/manager/dbscripts/vm_device_sp.sql
index 0cfaf90..835e9a4 100644
--- a/backend/manager/dbscripts/vm_device_sp.sql
+++ b/backend/manager/dbscripts/vm_device_sp.sql
@@ -12,7 +12,8 @@
     v_is_managed boolean,
     v_is_plugged boolean,
     v_is_readonly boolean,
-    v_alias varchar(255))
+    v_alias varchar(255),
+    v_custom_properties varchar(4000))
 RETURNS VOID
 AS $procedure$
 BEGIN
@@ -27,7 +28,8 @@
         is_managed,
         is_plugged,
         is_readonly,
-        alias)
+        alias,
+        custom_properties)
     VALUES(
         v_device_id ,
         v_vm_id ,
@@ -39,7 +41,8 @@
         v_is_managed,
         v_is_plugged,
         v_is_readonly,
-        v_alias);
+        v_alias,
+        v_custom_properties);
 END; $procedure$
 LANGUAGE plpgsql;
 
@@ -54,7 +57,8 @@
     v_is_managed boolean,
     v_is_plugged boolean,
     v_is_readonly boolean,
-    v_alias varchar(255))
+    v_alias varchar(255),
+    v_custom_properties varchar(4000))
 RETURNS VOID
 AS $procedure$
 BEGIN
@@ -69,6 +73,7 @@
            is_plugged = v_is_plugged,
            is_readonly = v_is_readonly,
            alias = v_alias,
+           custom_properties = v_custom_properties,
            _update_date = current_timestamp
     WHERE  device_id = v_device_id and vm_id = v_vm_id;
 END; $procedure$
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
index d04edf6..51879ca 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
@@ -138,7 +138,8 @@
                 true,
                 getParameters().isPlugUnPlug(),
                 false,
-                "");
+                "",
+                null);
     }
 
     protected void updateBootOrderInVmDevice() {
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 908b937..3ac2633 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
@@ -357,7 +357,8 @@
                     true,
                     is_plugged,
                     isReadOnly,
-                    "");
+                    "",
+                    null);
         dao.save(managedDevice);
         // If we add Disk/Interface/CD/Floppy, we have to recalculate boot 
order
         if (type.equals(VmDeviceType.DISK) || 
type.equals(VmDeviceType.INTERFACE )) {
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetAllDisksByVmIdQueryTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetAllDisksByVmIdQueryTest.java
index df008e0..4c36ff4 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetAllDisksByVmIdQueryTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetAllDisksByVmIdQueryTest.java
@@ -102,7 +102,8 @@
                 true,
                 true,
                 true,
-                "");
+                "",
+                null);
     }
 
     private DiskImage createDiskImage() {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java
index c687ead..c557116 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java
@@ -71,6 +71,11 @@
      */
     private String alias = "";
 
+    /**
+     * Custom properties
+     */
+    private String customProperties;
+
     public VmDevice() {
     }
 
@@ -80,7 +85,8 @@
             boolean isManaged,
             Boolean isPlugged,
             boolean isReadOnly,
-            String alias) {
+            String alias,
+            String customProperties) {
         super();
         this.id = id;
         this.type = type;
@@ -92,6 +98,7 @@
         this.isPlugged = isPlugged;
         this.isReadOnly = isReadOnly;
         this.alias = alias;
+        this.customProperties = customProperties;
     }
 
     @Override
@@ -197,6 +204,14 @@
         this.alias = alias;
     }
 
+    public String getCustomProperties() {
+        return customProperties;
+    }
+
+    public void setCustomProperties(String customProperties) {
+        this.customProperties = customProperties;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -211,6 +226,7 @@
         result = prime * result + (isPlugged ? 1231 : 1237);
         result = prime * result + (isReadOnly ? 1231 : 1237);
         result = prime * result + alias.hashCode();
+        result = prime * result + (customProperties == null ? 0 : 
customProperties.hashCode());
         return result;
     }
 
@@ -235,7 +251,8 @@
                 && isManaged == other.isManaged
                 && isPlugged == other.isPlugged
                 && isReadOnly == other.isReadOnly
-                && alias.equals(other.alias));
+                && alias.equals(other.alias)
+                && ObjectUtils.objectsEqual(customProperties, 
other.customProperties));
     }
 
     @Override
@@ -263,6 +280,8 @@
         sb.append(getIsReadOnly());
         sb.append(", deviceAlias=");
         sb.append(getAlias());
+        sb.append(", customProperties=");
+        sb.append(getCustomProperties());
         sb.append("}");
         return sb.toString();
     }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
index 20346a2..b743df9 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
@@ -1356,6 +1356,14 @@
     @DefaultValueAttribute("false")
     MigrationNetworkEnabled(502),
 
+    @TypeConverterAttribute(Boolean.class)
+    @DefaultValueAttribute("false")
+    SupportCustomDeviceProperties(503),
+
+    @TypeConverterAttribute(String.class)
+    @DefaultValueAttribute("")
+    CustomDeviceProperties(504),
+
     Invalid(65535);
 
     private int intValue;
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
index 7c5c78d..dcd39ba 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
@@ -48,7 +48,8 @@
                 .addValue("is_managed", entity.getIsManaged())
                 .addValue("is_plugged", entity.getIsPlugged())
                 .addValue("is_readonly", entity.getIsReadOnly())
-                .addValue("alias", entity.getAlias());
+                .addValue("alias", entity.getAlias())
+                .addValue("custom_properties", entity.getCustomProperties());
     }
 
     @Override
@@ -149,6 +150,7 @@
             vmDevice.setIsPlugged(rs.getBoolean("is_plugged"));
             vmDevice.setIsReadOnly(rs.getBoolean("is_readonly"));
             vmDevice.setAlias(rs.getString("alias"));
+            vmDevice.setCustomProperties(rs.getString("custom_properties"));
             return vmDevice;
         }
     }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
index 7e04af3..69a2bdb 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
@@ -45,7 +45,7 @@
                 "type:'drive', controller:'0', bus:'0', unit:'1'",
                 2,
                 new HashMap<String, Object>(),
-                true, false, false, "alias");
+                true, false, false, "alias", "prop1=value1");
     }
 
     @Override
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
index f874db5..2a6ff2b 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
@@ -1213,7 +1213,8 @@
                     false,
                     true,
                     false,
-                    alias);
+                    alias,
+                    null);
             newVmDevices.add(newDevice);
             log.debugFormat("New device was marked for adding to VM {0} 
Devices : {1}", vmId, newDevice);
         }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
index 102d17b..6286681 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
@@ -120,7 +120,8 @@
                             true,
                             true,
                             true,
-                            "");
+                            "",
+                            null);
             struct = new HashMap<String, Object>();
             addCdDetails(vmDevice, struct);
             addDevice(struct, vmDevice, "");
@@ -137,7 +138,8 @@
                             true,
                             true,
                             true,
-                            "");
+                            "",
+                            null);
             struct = new HashMap<String, Object>();
             addCdDetails(vmDevice, struct);
             addDevice(struct, vmDevice, vm.getCdPath());
@@ -177,7 +179,8 @@
                             true,
                             true,
                             true,
-                            "");
+                            "",
+                            null);
             Map<String, Object> struct = new HashMap<String, Object>();
             addCdDetails(vmDevice, struct);
             addDevice(struct, vmDevice, "");
@@ -194,7 +197,8 @@
                             true,
                             true,
                             true,
-                            "");
+                            "",
+                            null);
             Map<String, Object> struct = new HashMap<String, Object>();
             addFloppyDetails(vmDevice, struct);
             addDevice(struct, vmDevice, vm.getFloppyPath());
@@ -433,7 +437,8 @@
                         true,
                         true,
                         true,
-                        "");
+                        "",
+                        null);
         Map<String, Object> struct = new HashMap<String, Object>();
         addFloppyDetails(vmDevice, struct);
         addDevice(struct, vmDevice, vm.getFloppyPath());
@@ -621,7 +626,8 @@
                             true,
                             true,
                             true,
-                            "");
+                            "",
+                            null);
             addMemBalloonDevice(vmDevice);
         } else {
             // get vm device for this Balloon from DB
@@ -660,9 +666,9 @@
         Set<Entry<String, Object>> values = specParams.entrySet();
         for (Entry<String, Object> currEntry : values) {
             if (currEntry.getValue() instanceof String) {
-                struct.put(currEntry.getKey(), (String) currEntry.getValue());
+                struct.put(currEntry.getKey(), currEntry.getValue());
             } else if (currEntry.getValue() instanceof Map) {
-                struct.put(currEntry.getKey(), (Map) currEntry.getValue());
+                struct.put(currEntry.getKey(), currEntry.getValue());
             }
         }
     }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I67ed453706ac75cdc4356cc2d60913d8958c89ed
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Peřina <mper...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to