Kanagaraj M has uploaded a new change for review.

Change subject: engine: get Up server by cluster query
......................................................................

engine: get Up server by cluster query

The query can be called by providing the clusterId, and
it will return a VDS which is UP status in the cluster.

Change-Id: I1699ae4895cce1bfbac01ff59b634b8c99432e42
Signed-off-by: Kanagaraj M <[email protected]>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsInUpStatusByVdsGroupIdQuery.java
A 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetVdsInUpStatusByVdsGroupIdQueryTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
3 files changed, 101 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/14/11914/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsInUpStatusByVdsGroupIdQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsInUpStatusByVdsGroupIdQuery.java
new file mode 100644
index 0000000..15bb1cf
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsInUpStatusByVdsGroupIdQuery.java
@@ -0,0 +1,19 @@
+package org.ovirt.engine.core.bll;
+
+import org.ovirt.engine.core.bll.utils.ClusterUtils;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+
+public class GetVdsInUpStatusByVdsGroupIdQuery<P extends IdQueryParameters> 
extends QueriesCommandBase<P> {
+    public GetVdsInUpStatusByVdsGroupIdQuery(P parameters) {
+        super(parameters);
+    }
+
+    protected ClusterUtils getClusterUtils() {
+        return ClusterUtils.getInstance();
+    }
+
+    @Override
+    protected void executeQueryCommand() {
+        
getQueryReturnValue().setReturnValue(getClusterUtils().getUpServer(getParameters().getId()));
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetVdsInUpStatusByVdsGroupIdQueryTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetVdsInUpStatusByVdsGroupIdQueryTest.java
new file mode 100644
index 0000000..0ff31de
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetVdsInUpStatusByVdsGroupIdQueryTest.java
@@ -0,0 +1,81 @@
+package org.ovirt.engine.core.bll;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.ovirt.engine.core.bll.utils.ClusterUtils;
+import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.VDSStatus;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.VdsDAO;
+
+/**
+ * A test case for {@link GetVdsInUpStatusByVdsGroupIdQuery}.
+ */
+public class GetVdsInUpStatusByVdsGroupIdQueryTest extends 
AbstractQueryTest<IdQueryParameters, 
GetVdsInUpStatusByVdsGroupIdQuery<IdQueryParameters>> {
+
+    private List<VDS> vdsList;
+    private Guid CLUSTER_ID = new Guid("b399944a-81ab-4ec5-8266-e19ba7c3c9d1");
+    private IdQueryParameters parameters;
+
+    ClusterUtils clusterUtils;
+    VdsDAO vdsDao;
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        setupExpectations();
+        setupMock();
+    }
+
+    private void setupExpectations() {
+        vdsList = new ArrayList<VDS>();
+        vdsList.add(getVds("vds1", VDSStatus.Up));
+        vdsList.add(getVds("vds2", VDSStatus.Up));
+        vdsList.add(getVds("vds3", VDSStatus.Up));
+    }
+
+    private void setupMock() {
+        vdsDao = mock(VdsDAO.class);
+
+        clusterUtils = spy(ClusterUtils.getInstance());
+        doReturn(clusterUtils).when(getQuery()).getClusterUtils();
+
+        doReturn(vdsDao).when(clusterUtils).getVdsDao();
+        doReturn(vdsList).when(vdsDao).getAllForVdsGroupWithStatus(CLUSTER_ID,
+                VDSStatus.Up);
+
+        parameters = new IdQueryParameters(CLUSTER_ID);
+        doReturn(parameters).when(getQuery()).getParameters();
+    }
+
+    private VDS getVds(String name, VDSStatus status) {
+        VDS vds = new VDS();
+        vds.setId(new Guid());
+        vds.setvds_name(name);
+        vds.setvds_group_id(CLUSTER_ID);
+        vds.setstatus(status);
+        return vds;
+    }
+
+    @Test
+    public void testExecuteQueryCommnad() {
+        getQuery().executeQueryCommand();
+        VDS actual = (VDS) getQuery().getQueryReturnValue().getReturnValue();
+
+        assertNotNull(actual);
+        assertEquals("wrong VDS", VDSStatus.Up, actual.getstatus());
+        assertTrue("wrong VDS", vdsList.contains(actual));
+    }
+}
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 261dea5..734f6b1 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
@@ -24,6 +24,7 @@
     GetVdsByHost,
     GetVdsByName,
     GetVdsByType,
+    GetVdsInUpStatusByVdsGroupId,
     GetVdsFenceStatus,
     GetNewVdsFenceStatus,
     CanFenceVds,


--
To view, visit http://gerrit.ovirt.org/11914
To unsubscribe, visit http://gerrit.ovirt.org/settings

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

Reply via email to