Moti Asayag has uploaded a new change for review.

Change subject: core: Extend Vm[Static] to contain provider id
......................................................................

core: Extend Vm[Static] to contain provider id

In order to allow association of VMs as a content host
on Katello server, the vm entity should store the id
of the provider which represents the Katello server.

Change-Id: I6c09188dcde40cbb5904dc15274d597ceb9b8594
Bug-Url: https://bugzilla.redhat.com/1157377
Signed-off-by: Moti Asayag <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
M packaging/dbscripts/create_views.sql
A packaging/dbscripts/upgrade/03_06_1370_add_provider_id_to_vms.sql
M packaging/dbscripts/vms_sp.sql
8 files changed, 56 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/17/40717/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
index 53c45a5..0309749 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
@@ -6,13 +6,14 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import javax.validation.Valid;
 
 import org.codehaus.jackson.annotate.JsonIgnore;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.storage.Disk;
-import org.ovirt.engine.core.common.businessentities.storage.DiskStorageType;
 import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
+import org.ovirt.engine.core.common.businessentities.storage.DiskStorageType;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.locks.LockInfo;
@@ -1890,4 +1891,12 @@
     public void setGuestMemoryFree(Long guestMemoryFree) {
         vmDynamic.setGuestMemoryFree(guestMemoryFree);
     }
+
+    public Guid getProviderId() {
+        return vmStatic.getProviderId();
+    }
+
+    public void setProviderId(Guid providerId) {
+        vmStatic.setProviderId(providerId);
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
index 0f04626..80fcdbd 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
@@ -1,5 +1,7 @@
 package org.ovirt.engine.core.common.businessentities;
 
+import java.util.Objects;
+
 import javax.validation.constraints.Size;
 import javax.validation.groups.Default;
 
@@ -36,6 +38,8 @@
 
     @EditableField
     private boolean useLatestVersion;
+
+    private Guid providerId;
 
     public VmStatic() {
         setNumOfMonitors(1);
@@ -114,7 +118,7 @@
         result = prime * result + ((originalTemplateGuid == null) ? 0 : 
originalTemplateGuid.hashCode());
         result = prime * result + ((originalTemplateName == null) ? 0 : 
originalTemplateName.hashCode());
         result = prime * result + (useLatestVersion ? 1249 : 1259);
-
+        result = prime * result + Objects.hashCode(providerId);
         return result;
     }
 
@@ -139,7 +143,7 @@
                 && ObjectUtils.objectsEqual(originalTemplateGuid, 
other.originalTemplateGuid)
                 && ObjectUtils.objectsEqual(originalTemplateName, 
other.originalTemplateName)
                 && useLatestVersion == other.useLatestVersion
-         );
+                && Objects.equals(providerId, other.providerId));
     }
 
     public boolean isUseHostCpuFlags() {
@@ -198,4 +202,11 @@
         this.useLatestVersion = useLatestVersion;
     }
 
+    public Guid getProviderId() {
+        return providerId;
+    }
+
+    public void setProviderId(Guid providerId) {
+        this.providerId = providerId;
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
index 539ee37..9a52c9c 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
@@ -43,7 +43,8 @@
                 .addValue("original_template_name", 
vm.getOriginalTemplateName())
                 .addValue("original_template_id", vm.getOriginalTemplateGuid())
                 .addValue("template_version_number", vm.isUseLatestVersion() ?
-                        USE_LATEST_VERSION_NUMBER_INDICATOR : 
DONT_USE_LATEST_VERSION_NUMBER_INDICATOR);
+                        USE_LATEST_VERSION_NUMBER_INDICATOR : 
DONT_USE_LATEST_VERSION_NUMBER_INDICATOR)
+                .addValue("provider_id", vm.getProviderId());
     }
 
     @Override
@@ -197,7 +198,7 @@
             entity.setOriginalTemplateGuid(getGuid(rs, 
"original_template_id"));
             // if template_version_number is null it means use latest version
             entity.setUseLatestVersion(rs.getObject("template_version_number") 
== USE_LATEST_VERSION_NUMBER_INDICATOR);
-
+            entity.setProviderId(getGuid(rs, "provider_id"));
             return entity;
         }
     }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java
index 44ecac3..7df5aae 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java
@@ -34,6 +34,7 @@
     private static final Guid QUOTA_ID = new 
Guid("88296e00-0cad-4e5a-9291-008a7b7f4399");
     private static final Guid SMALL_ICON_ID = new 
Guid("38fc5e1a-f96b-339b-9894-def6f366daf5");
     private static final Guid LARGE_ICON_ID = new 
Guid("a3b954f0-31ff-3166-b7a1-28b23202b198");
+    private static final Guid EXISTING_PROVIDER_ID = new 
Guid("1115c1c6-cb15-4832-b2a4-023770607111");
     protected Logger log = LoggerFactory.getLogger(getClass());
     private static final String STATIC_VM_NAME = "rhel5-pool-50";
     private static final int NUM_OF_VM_STATIC_IN_FIXTURES = 3;
@@ -172,12 +173,15 @@
 
     @Test
     public void testUpdate() {
+        assertEquals(existingVmStatic.getProviderId(), EXISTING_PROVIDER_ID);
         existingVmStatic.setDescription("updated");
         existingVmStatic.setCpuProfileId(FixturesTool.CPU_PROFILE_2);
+        existingVmStatic.setProviderId(null);
         dao.update(existingVmStatic);
         VmStatic result = dao.get(EXISTING_VM_ID);
         assertNotNull(result);
         assertEquals(existingVmStatic, result);
+        assertNull(result.getProviderId());
     }
 
     @Test
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index 0708b8a..d6b725a 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -2160,6 +2160,7 @@
         <column>custom_cpu_name</column>
         <column>small_icon_id</column>
         <column>large_icon_id</column>
+        <column>provider_id</column>
         <!-- Templates -->
         <row>
             <value>00000000-0000-0000-0000-000000000000</value>
@@ -2226,6 +2227,7 @@
             <null />
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b79</value>
@@ -2292,6 +2294,7 @@
             <value>cpu1</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b80</value>
@@ -2358,6 +2361,7 @@
             <value>Penryn</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b81</value>
@@ -2424,6 +2428,7 @@
             <null />
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <value>1115c1c6-cb15-4832-b2a4-023770607111</value>
         </row>
          <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
@@ -2490,6 +2495,7 @@
             <value>Penryn</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <value>1115c1c6-cb15-4832-b2a4-023770607111</value>
         </row>
          <row>
             <value>99408929-82cf-4dc7-a532-9d998063fa95</value>
@@ -2556,6 +2562,7 @@
             <value>Penryn</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
          <row>
             <value>5849b030-626e-47cb-ad90-3ce782d831b3</value>
@@ -2622,6 +2629,7 @@
             <value>Penryn</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b83</value>
@@ -2688,6 +2696,7 @@
             <null />
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
 
         <!-- VMS -->
@@ -2756,6 +2765,7 @@
             <null />
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4355</value>
@@ -2822,6 +2832,7 @@
             <value>Penryn</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <value>1115c1c6-cb15-4832-b2a4-023770607111</value>
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4356</value>
@@ -2888,6 +2899,7 @@
             <null />
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4357</value>
@@ -2954,6 +2966,7 @@
             <value>Penryn</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4359</value>
@@ -3020,6 +3033,7 @@
             <value></value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4360</value>
@@ -3086,6 +3100,7 @@
             <value>Penryn</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f5001</value>
@@ -3152,6 +3167,7 @@
             <value></value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f5002</value>
@@ -3218,6 +3234,7 @@
             <value>Penryn</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f5003</value>
@@ -3284,6 +3301,7 @@
             <value>Penryn</value>
             <value>38fc5e1a-f96b-339b-9894-def6f366daf5</value>
             <value>a3b954f0-31ff-3166-b7a1-28b23202b198</value>
+            <null />
         </row>
     </table>
 
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index d9324dd..e3b5cd8 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -1098,7 +1098,8 @@
        vm_dynamic.guest_mem_cached as guest_mem_cached,
        vm_dynamic.guest_mem_free as guest_mem_free,
     vm_static.small_icon_id as small_icon_id,
-    vm_static.large_icon_id as large_icon_id
+    vm_static.large_icon_id as large_icon_id,
+    vm_static.provider_id as provider_id
 FROM
     vm_static
 INNER JOIN vm_dynamic ON vm_static.vm_guid = vm_dynamic.vm_guid
diff --git a/packaging/dbscripts/upgrade/03_06_1370_add_provider_id_to_vms.sql 
b/packaging/dbscripts/upgrade/03_06_1370_add_provider_id_to_vms.sql
new file mode 100644
index 0000000..da6f126
--- /dev/null
+++ b/packaging/dbscripts/upgrade/03_06_1370_add_provider_id_to_vms.sql
@@ -0,0 +1,2 @@
+select fn_db_add_column('vm_static', 'provider_id', 'UUID');
+ALTER TABLE vm_static ADD CONSTRAINT fk_vm_static_provider_id FOREIGN KEY 
(provider_id) REFERENCES providers(id) ON DELETE SET NULL;
diff --git a/packaging/dbscripts/vms_sp.sql b/packaging/dbscripts/vms_sp.sql
index 3bd57c2..c63daf2 100644
--- a/packaging/dbscripts/vms_sp.sql
+++ b/packaging/dbscripts/vms_sp.sql
@@ -849,7 +849,8 @@
 v_custom_emulated_machine VARCHAR(40),
 v_custom_cpu_name VARCHAR(40),
 v_small_icon_id UUID,
-v_large_icon_id UUID)
+v_large_icon_id UUID,
+v_provider_id UUID)
 
 RETURNS VOID
 
@@ -889,7 +890,8 @@
       custom_emulated_machine = v_custom_emulated_machine,
       custom_cpu_name = v_custom_cpu_name,
       small_icon_id = v_small_icon_id,
-      large_icon_id = v_large_icon_id
+      large_icon_id = v_large_icon_id,
+      provider_id = v_provider_id
       WHERE vm_guid = v_vm_guid
       AND   entity_type = 'VM';
 END; $procedure$


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

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

Reply via email to