Moti Asayag has uploaded a new change for review. Change subject: engine: Retrieve host interfaces by label ......................................................................
engine: Retrieve host interfaces by label The added stored-procedure allow to fetch the interfaces which are labelled with a given label in a specific cluster. Change-Id: Icbb3fa47f3c85d4d884a1f4cb4d1a7c04528eee9 Signed-off-by: Moti Asayag <[email protected]> --- M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/InterfaceDaoTest.java M backend/manager/modules/dal/src/test/resources/fixtures.xml M packaging/dbscripts/network_sp.sql 5 files changed, 70 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/56/22656/1 diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java index 03b72a8..a9b506d 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java @@ -136,4 +136,24 @@ * @return */ List<VdsNetworkInterface> getAllInterfacesWithIpAddress(Guid clusterId, String ipAddress); + + /** + * Retrieves all interfaces within a specific cluster + * + * @param clusterId + * the cluster where the hosts reside in + * @return + */ + List<VdsNetworkInterface> getAllInterfacesByClusterId(Guid clusterId); + + /** + * Retrieves all interfaces marked with a given label + * + * @param clusterId + * the cluster where the hosts reside in + * @param label + * the label to search for + * @return + */ + List<VdsNetworkInterface> getAllInterfacesByLabelForCluster(Guid clusterId, String label); } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java index 65703af..4f16b15 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java @@ -68,7 +68,7 @@ } /** - * Update the {@link VdsNetworkStatistics} in the DB using the given {@link SimpleJdbcCall}. + * Update the {@link VdsNetworkStatistics} in the DB * * @param callToUpdate * The call to use. @@ -182,6 +182,25 @@ getCustomMapSqlParameterSource().addValue("vds_interface_id", id)); } + @Override + public List<VdsNetworkInterface> getAllInterfacesByClusterId(Guid clusterId) { + return getCallsHandler().executeReadList("GetInterfacesByClusterId", + vdsNetworkInterfaceRowMapper, + getCustomMapSqlParameterSource().addValue("cluster_id", clusterId)); + } + + @Override + public List<VdsNetworkInterface> getAllInterfacesByLabelForCluster(Guid clusterId, String label) { + List<VdsNetworkInterface> labelledNics = new ArrayList<>(); + for (VdsNetworkInterface nic : getAllInterfacesByClusterId(clusterId)) { + if (nic.getLabels() != null && nic.getLabels().contains(label)) { + labelledNics.add(nic); + } + } + + return labelledNics; + } + private static final RowMapper<VdsNetworkInterface> vdsNetworkInterfaceRowMapper = new RowMapper<VdsNetworkInterface>() { @SuppressWarnings("unchecked") diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/InterfaceDaoTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/InterfaceDaoTest.java index 87b2da0..8e33805 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/InterfaceDaoTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/InterfaceDaoTest.java @@ -25,6 +25,7 @@ private static final String IP_ADDR = "10.35.110.10"; private static final Guid VDS_ID = new Guid("afce7a39-8e8c-4819-ba9c-796d316592e6"); private static final Guid CLUSTER_ID = new Guid("b399944a-81ab-4ec5-8266-e19ba7c3c9d1"); + private static final String LABEL = "abc"; private InterfaceDao dao; private VdsNetworkInterface existingVdsInterface; @@ -316,4 +317,18 @@ assertEquals(1, interfaces.size()); assertGetAllForVdsCorrectResult(interfaces); } + + @Test + public void testgetAllInterfacesByClusterId() { + List<VdsNetworkInterface> interfaces = dao.getAllInterfacesByClusterId(CLUSTER_ID); + assertNotNull(interfaces); + assertFalse(interfaces.isEmpty()); + } + + @Test + public void testGetAllInterfacesByLabelForCluster() { + List<VdsNetworkInterface> interfaces = dao.getAllInterfacesByLabelForCluster(CLUSTER_ID, LABEL); + assertNotNull(interfaces); + assertEquals(1, interfaces.size()); + } } diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml b/backend/manager/modules/dal/src/test/resources/fixtures.xml index 00c483a..73622a3 100644 --- a/backend/manager/modules/dal/src/test/resources/fixtures.xml +++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml @@ -4020,7 +4020,7 @@ <value>2010-11-12 10:12:41</value> <value>2010-11-12 15:57:01</value> <null /> - <null /> + <value>[ "aaa", "bbb", "abc" ]</value> </row> <row> <value>ba31682e-6ae7-4f9d-8c6f-04c93acca9dd</value> @@ -4041,7 +4041,7 @@ <value>2012-11-12 10:12:41</value> <value>2012-11-12 15:57:01</value> <null /> - <null /> + <value>[ "abc" ]</value> </row> <row> <value>ba31682e-6ae7-4f9d-8c6f-04c93acca9de</value> diff --git a/packaging/dbscripts/network_sp.sql b/packaging/dbscripts/network_sp.sql index 00a314d..f459b2a 100644 --- a/packaging/dbscripts/network_sp.sql +++ b/packaging/dbscripts/network_sp.sql @@ -435,6 +435,19 @@ LANGUAGE plpgsql; +Create or replace FUNCTION GetInterfacesByClusterId(v_cluster_id UUID) +RETURNS SETOF vds_interface_view STABLE + AS $procedure$ +BEGIN + RETURN QUERY SELECT vds_interface_view.* + FROM vds_interface_view + INNER JOIN vds_static + ON vds_interface_view.vds_id = vds_static.vds_id + WHERE vds_static.vds_group_id = v_cluster_id; +END; $procedure$ +LANGUAGE plpgsql; + + ---------------------------------------------------------------- -- [vm_interface] Table ---------------------------------------------------------------- -- To view, visit http://gerrit.ovirt.org/22656 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icbb3fa47f3c85d4d884a1f4cb4d1a7c04528eee9 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
