Moti Asayag has uploaded a new change for review. Change subject: engine: Add SP for retrieving templates by vnic profile [WIP] ......................................................................
engine: Add SP for retrieving templates by vnic profile [WIP] The patch adds a stored-procedure for fetching all the templates which are using a given vnic profile. Change-Id: If143d7c23235c5aa56b1cb1f94f003eae7fe20a3 Signed-off-by: Moti Asayag <masa...@redhat.com> --- M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java M packaging/dbscripts/vm_templates_sp.sql 4 files changed, 41 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/70/16670/1 diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java index 98333ee..7167cfc 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java @@ -125,4 +125,13 @@ * @return the list of VmTemplates */ List<VmTemplate> getAllForNetwork(Guid networkId); + + /** + * Retrieves all VmTemplates that have a Network Interface that the given vnic profile is attached to. + * + * @param vnicProfileId + * the vm network interface profile id + * @return the list of VmTemplates + */ + List<VmTemplate> getAllForVnicProfile(Guid vnicProfileId); } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java index d78ed22..a66caba 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java @@ -202,6 +202,14 @@ .addValue("network_id", id)); } + @Override + public List<VmTemplate> getAllForVnicProfile(Guid vnicProfileId) { + return getCallsHandler().executeReadList("GetVmTemplatesByVnicProfileId", + VMTemplateRowMapper.instance, + getCustomMapSqlParameterSource() + .addValue("vnic_profile_id", vnicProfileId)); + } + private final static class VMTemplateRowMapper extends AbstractVmRowMapper<VmTemplate> { public static final VMTemplateRowMapper instance = new VMTemplateRowMapper(); diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java index 9447353..29690ab 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java @@ -288,6 +288,15 @@ assertEquals(existingTemplate, result.get(0)); } + /** + * Asserts that the correct template is returned for the given network id + */ + @Test + public void testGetAllVnicProfile() { + List<VmTemplate> result = dao.getAllForVnicProfile(FixturesTool.VM_NETWORK_INTERFACE_PROFILE); + assertEquals(existingTemplate, result.get(0)); + } + private static void assertGetResult(VmTemplate result) { assertNotNull(result); assertEquals(EXISTING_TEMPLATE_ID, result.getId()); diff --git a/packaging/dbscripts/vm_templates_sp.sql b/packaging/dbscripts/vm_templates_sp.sql index bd7f47f..89c66c9 100644 --- a/packaging/dbscripts/vm_templates_sp.sql +++ b/packaging/dbscripts/vm_templates_sp.sql @@ -405,3 +405,18 @@ END; $procedure$ LANGUAGE plpgsql; +Create or replace FUNCTION GetVmTemplatesByVnicProfileId(v_vnic_profile_id UUID) RETURNS SETOF vm_templates_view + AS $procedure$ +BEGIN + RETURN QUERY SELECT * + FROM vm_templates_view + WHERE EXISTS ( + SELECT 1 + FROM vm_interface + INNER JOIN vnic_profiles + ON vnic_profiles.id = vm_interface.vnic_profile_id + WHERE vm_interface.vnic_profile_id = v_vnic_profile_id + AND vm_interface.vmt_guid = vm_templates_view.vmt_guid); +END; $procedure$ +LANGUAGE plpgsql; + -- To view, visit http://gerrit.ovirt.org/16670 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If143d7c23235c5aa56b1cb1f94f003eae7fe20a3 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <masa...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches