Liran Zelkha has uploaded a new change for review. Change subject: core: Add host# and vm# to cluster tab ......................................................................
core: Add host# and vm# to cluster tab In webadmin add an ability to see the count of VMs and Hosts for a cluster Change-Id: I9935c67db2a88960cd721aec4bfd71e70c9b4f57 Bug-Url: https://bugzilla.redhat.com/1084120 Signed-off-by: lzel...@redhat.com <lzel...@redhat.com> --- A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDSGroupHostsAndVMs.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java M packaging/dbscripts/vds_groups_sp.sql 5 files changed, 122 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/80/26980/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDSGroupHostsAndVMs.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDSGroupHostsAndVMs.java new file mode 100644 index 0000000..7dbc3ba --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDSGroupHostsAndVMs.java @@ -0,0 +1,39 @@ +package org.ovirt.engine.core.common.businessentities; + +import java.io.Serializable; + +import org.ovirt.engine.core.compat.Guid; + +public class VDSGroupHostsAndVMs extends IVdcQueryable implements Serializable { + + private static final long serialVersionUID = -5395392502656683858L; + + private Guid vdsGroupId; + private int hosts; + private int vms; + + public Guid getVdsGroupId() { + return vdsGroupId; + } + + public void setVdsGroupId(Guid vdsGroupId) { + this.vdsGroupId = vdsGroupId; + } + + public int getHosts() { + return hosts; + } + + public void setHosts(int hosts) { + this.hosts = hosts; + } + + public int getVms() { + return vms; + } + + public void setVms(int vms) { + this.vms = vms; + } + +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java index aa4870d..ed35272 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java @@ -1,9 +1,11 @@ package org.ovirt.engine.core.dao; import java.util.List; +import java.util.Map; import org.ovirt.engine.core.common.businessentities.ActionGroup; import org.ovirt.engine.core.common.businessentities.VDSGroup; +import org.ovirt.engine.core.common.businessentities.VDSGroupHostsAndVMs; import org.ovirt.engine.core.compat.Guid; /** @@ -183,4 +185,12 @@ * @return */ int getVmsCountByClusterId(Guid vdsGroupId); + + /** + * Retrieves the number of hosts and VMs in a list of clusters + * @param vdsGroups + * @return + */ + Map<Guid, VDSGroupHostsAndVMs> getHostsAndVmsForClusters(List<Guid> vdsGroups); + } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java index 05c57fd..c8bc65c 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java @@ -1,15 +1,26 @@ package org.ovirt.engine.core.dao; +import java.sql.Array; +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Types; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; + +import javax.management.RuntimeErrorException; import org.ovirt.engine.core.common.businessentities.ActionGroup; import org.ovirt.engine.core.common.businessentities.ArchitectureType; import org.ovirt.engine.core.common.businessentities.MigrateOnErrorOptions; import org.ovirt.engine.core.common.businessentities.SerialNumberPolicy; import org.ovirt.engine.core.common.businessentities.VDSGroup; +import org.ovirt.engine.core.common.businessentities.VDSGroupHostsAndVMs; import org.ovirt.engine.core.common.scheduling.OptimizationType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.Version; @@ -17,6 +28,7 @@ import org.ovirt.engine.core.utils.SerializationFactory; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor; /** * <code>VdsGroupDAODbFacadeImpl</code> provides an implementation of {@link VdsGroupDAO} that uses code previously @@ -213,6 +225,19 @@ return parameterSource; } + private final static class VDSGroupHostsAndVMsRowMapper implements RowMapper<VDSGroupHostsAndVMs> { + public static final RowMapper<VDSGroupHostsAndVMs> instance = new VDSGroupHostsAndVMsRowMapper(); + + @Override + public VDSGroupHostsAndVMs mapRow(ResultSet rs, int rowNum) throws SQLException { + VDSGroupHostsAndVMs entity = new VDSGroupHostsAndVMs(); + entity.setHosts(rs.getInt("hosts")); + entity.setVms(rs.getInt("vms")); + entity.setVdsGroupId(getGuid(rs, "vds_group_id")); + return entity; + } + + } private final static class VdsGroupRowMapper implements RowMapper<VDSGroup> { public static final RowMapper<VDSGroup> instance = new VdsGroupRowMapper(); @@ -277,4 +302,25 @@ getCustomMapSqlParameterSource() .addValue("cluster_policy_id", clusterPolicyId)); } + + @Override + public Map<Guid, VDSGroupHostsAndVMs> getHostsAndVmsForClusters(List<Guid> vdsGroups) { + Map<Guid, VDSGroupHostsAndVMs> result = new HashMap<>(); + + try { + Array groups = jdbcTemplate.getDataSource().getConnection().createArrayOf("uuid", vdsGroups.toArray()); + List<VDSGroupHostsAndVMs> dataList = getCallsHandler().executeReadList("GetHostsAndVmsForClusters", + VDSGroupHostsAndVMsRowMapper.instance, + getCustomMapSqlParameterSource() + .addValue("vds_group_ids", groups)); + + for (VDSGroupHostsAndVMs data : dataList) { + result.put(data.getVdsGroupId(), data); + } + + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } } diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java index 69d29ce..79e0833 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java @@ -10,12 +10,14 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.junit.Test; import org.ovirt.engine.core.common.businessentities.ArchitectureType; import org.ovirt.engine.core.common.businessentities.StoragePool; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSGroup; +import org.ovirt.engine.core.common.businessentities.VDSGroupHostsAndVMs; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.dao.scheduling.ClusterPolicyDao; @@ -461,4 +463,14 @@ // Non existing cluster, should return 0 assertEquals("Incorrect number of VMs in cluster", dao.getVmsCountByClusterId(Guid.newGuid()), 0); } + + @Test + public void testGetVmHostCount() { + Guid guid = Guid.createGuidFromString("b399944a-81ab-4ec5-8266-e19ba7c3c9d1"); + List<Guid> vdsGroups = new ArrayList<>(); + vdsGroups.add(guid); + Map<Guid, VDSGroupHostsAndVMs> data = dao.getHostsAndVmsForClusters(vdsGroups); + assertEquals("Incorrect number of VMs in cluster", data.get(guid).getVms(), 11); + assertEquals("Incorrect number of Hosts in cluster", data.get(guid).getHosts(), 1); + } } diff --git a/packaging/dbscripts/vds_groups_sp.sql b/packaging/dbscripts/vds_groups_sp.sql index 536f420..c38a974 100644 --- a/packaging/dbscripts/vds_groups_sp.sql +++ b/packaging/dbscripts/vds_groups_sp.sql @@ -268,3 +268,18 @@ WHERE vms.vds_group_id = v_vds_group_id AND vms.entity_type = 'VM'; END; $procedure$ LANGUAGE plpgsql; + +DROP TYPE IF EXISTS host_vm_cluster_rs CASCADE; +CREATE TYPE host_vm_cluster_rs AS (vds_group_id UUID,hosts bigint,vms bigint); + +Create or replace FUNCTION GetHostsAndVmsForClusters(v_vds_group_ids UUID[]) RETURNS SETOF host_vm_cluster_rs STABLE + AS $procedure$ +BEGIN + RETURN QUERY SELECT groups.vds_group_id,COUNT(DISTINCT vds.vds_id) as host_count,COUNT(vms.vm_guid) as vm_count + FROM vds_groups groups + LEFT JOIN vm_static vms on vms.vds_group_id = groups.vds_group_id + LEFT JOIN vds_static vds on vds.vds_group_id = groups.vds_group_id + WHERE groups.vds_group_id = ANY(v_vds_group_ids) + GROUP BY groups.vds_group_id; +END; $procedure$ +LANGUAGE plpgsql; -- To view, visit http://gerrit.ovirt.org/26980 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9935c67db2a88960cd721aec4bfd71e70c9b4f57 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liran Zelkha <lzel...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches