Shubhendu Tripathi has uploaded a new change for review.

Change subject: engine: Query to get list of cluster with nodes
......................................................................

engine: Query to get list of cluster with nodes

Introduced a BLL query to get the list of clusters which
have nodes attached with.

Change-Id: I5c06388ec88436518ce2e8bd3855d64ba66400b7
Bug-Url: https://bugzilla.redhat.com/1202391
Signed-off-by: Shubhendu Tripathi <[email protected]>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllClustersHavingHostsQuery.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.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
6 files changed, 56 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/69/40869/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllClustersHavingHostsQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllClustersHavingHostsQuery.java
new file mode 100644
index 0000000..69d4f54
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllClustersHavingHostsQuery.java
@@ -0,0 +1,20 @@
+package org.ovirt.engine.core.bll;
+
+import javax.inject.Inject;
+
+import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
+import org.ovirt.engine.core.dao.VdsGroupDAO;
+
+public class GetAllClustersHavingHostsQuery<P extends VdcQueryParametersBase> 
extends QueriesCommandBase<P> {
+    @Inject
+    private VdsGroupDAO clusterDao;
+
+    public GetAllClustersHavingHostsQuery(P parameters) {
+        super(parameters);
+    }
+
+    @Override
+    protected void executeQueryCommand() {
+        setReturnValue(clusterDao.getClustersHavingHosts());
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
index d133f3d..e4062fa 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
@@ -239,6 +239,7 @@
     GetDataCentersWithPermittedActionOnClusters(VdcQueryAuthType.User),
     GetClustersWithPermittedAction(VdcQueryAuthType.User),
     GetVmTemplatesWithPermittedAction(VdcQueryAuthType.User),
+    GetAllClustersHavingHosts,
 
     // Storage
     GetStorageDomainById(VdcQueryAuthType.User),
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 b376f56..221c573 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
@@ -157,6 +157,13 @@
     List<VDSGroup> getClustersWithPermittedAction(Guid userId, ActionGroup 
actionGroup);
 
     /**
+     * Retrieves clusters having valid hosts added to them
+     *
+     * @return list of clusters
+     */
+    List<VDSGroup> getClustersHavingHosts();
+
+    /**
      * Sets the cluster's emulated machine value
      * @param vdsGroupId
      * @param emulatedMachine
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 a5db0d4..5c559ce 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
@@ -169,6 +169,15 @@
     }
 
     @Override
+    public List<VDSGroup> getClustersHavingHosts() {
+        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource();
+
+        return getCallsHandler().executeReadList("GetClustersHavingHosts",
+                VdsGroupRowMapper.instance,
+                parameterSource);
+    }
+
+    @Override
     public void setEmulatedMachine(Guid vdsGroupId, String emulatedMachine, 
boolean detectEmulatedMachine) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
                 .addValue("vds_group_id", vdsGroupId)
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 dbe2d75..cf3dc9d 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
@@ -1,10 +1,12 @@
 package org.ovirt.engine.core.dao;
 
+import static org.hamcrest.Matchers.hasSize;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
@@ -479,4 +481,11 @@
         assertEquals(1, vdsGroups.size());
         assertEquals(FixturesTool.GLUSTER_CLUSTER_ID, 
vdsGroups.get(0).getId());
     }
+
+    @Test
+    public void testGetClustersHavingHosts() {
+        List<VDSGroup> clusters = ((VdsGroupDAODbFacadeImpl) 
dao).getClustersHavingHosts();
+        assertNotNull(clusters);
+        assertThat(clusters, hasSize(4));
+    }
 }
diff --git a/packaging/dbscripts/vds_groups_sp.sql 
b/packaging/dbscripts/vds_groups_sp.sql
index c8994a3..e8363bb 100644
--- a/packaging/dbscripts/vds_groups_sp.sql
+++ b/packaging/dbscripts/vds_groups_sp.sql
@@ -248,6 +248,16 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+-- This SP returns all clusters which have valid hosts attached to them
+Create or replace FUNCTION GetClustersHavingHosts() RETURNS SETOF 
vds_groups_view STABLE
+    AS $procedure$
+BEGIN
+    RETURN QUERY SELECT vds_groups_view.*
+    FROM vds_groups_view
+    WHERE EXISTS (SELECT 1 from vds_static WHERE vds_group_id = 
vds_groups_view.vds_group_id);
+END; $procedure$
+LANGUAGE plpgsql;
+
 --This SP updates the vds_group emulated machine and the detection mode
 Create or replace FUNCTION UpdateVdsGroupEmulatedMachine(v_vds_group_id UUID, 
v_emulated_machine varchar(40), v_detect_emulated_machine BOOLEAN) RETURNS VOID
    AS $procedure$


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c06388ec88436518ce2e8bd3855d64ba66400b7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5-gluster
Gerrit-Owner: Shubhendu Tripathi <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to