Sahina Bose has uploaded a new change for review.

Change subject: engine: Remove gluster hooks from db when no servers in cluster
......................................................................

engine: Remove gluster hooks from db when no servers in cluster

If the host being removed is the last server in the cluster
clean up the entries for gluster hooks as well.

Change-Id: Ib4f99798cb4d0ebe70045c20286939f54d6b1fcc
Bug-Url: https://bugzilla.redhat.com/986171
Signed-off-by: Sahina Bose <sab...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoTest.java
M packaging/dbscripts/gluster_hooks_sp.sql
5 files changed, 39 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/29/21529/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java
index cbca662..74db518 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java
@@ -52,11 +52,14 @@
         }
 
         /**
-         * If the removing server is the last server in the cluster and the 
force action is true, then clear the gluster
-         * volumes from the database
+         * If the removing server is the last server in the cluster , then 
clear the gluster
+         * volumes and hooks from the database
+         * if not force, host remove would have failed if there were volumes, 
so safe to
+         * clean up volumes in DB.
          */
-        if (!clusterHasMultipleHosts() && getParameters().isForceAction()) {
+        if (!clusterHasMultipleHosts()) {
             removeGlusterVolumesFromDb();
+            removeGlusterHooksFromDb();
         }
 
         TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
@@ -192,6 +195,10 @@
         getGlusterVolumeDao().removeByClusterId(getVdsGroupId());
     }
 
+    private void removeGlusterHooksFromDb() {
+        getGlusterHooksDao().removeAllInCluster(getVdsGroupId());
+    }
+
     public ClusterUtils getClusterUtils() {
         return ClusterUtils.getInstance();
     }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDao.java
index b280098..b518982 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDao.java
@@ -73,4 +73,6 @@
 
     public void removeGlusterServerHook(Guid hookId, Guid serverId);
 
+    public void removeAllInCluster(Guid clusterId);
+
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
index e341368..2558f8b 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
@@ -307,4 +307,11 @@
         // TODO: Implement this
         throw new NotImplementedException("Unsupported operation");
     }
+
+    @Override
+    public void removeAllInCluster(Guid clusterId) {
+        getCallsHandler().executeModification("DeleteAllGlusterHooks",
+                getCustomMapSqlParameterSource()
+                .addValue("cluster_id", clusterId));
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoTest.java
index 85711f7..d629b67 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoTest.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.dao.gluster;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -141,6 +142,16 @@
         assertTrue(hooks.isEmpty());
     }
 
+    @Test
+    public void testRemoveAllInCluster() {
+        List<GlusterHookEntity> originalHookList = 
dao.getByClusterId(FixturesTool.GLUSTER_CLUSTER_ID);
+        assertFalse(originalHookList.isEmpty());
+        dao.removeAllInCluster(FixturesTool.GLUSTER_CLUSTER_ID);
+        List<GlusterHookEntity> hooks = 
dao.getByClusterId(FixturesTool.GLUSTER_CLUSTER_ID);
+        assertNotNull(hooks);
+        assertTrue(hooks.isEmpty());
+    }
+
     public void testRemoveAllButOne() {
         GlusterHookEntity newHook = getGlusterHook();
         newHook.setId(FixturesTool.NEW_HOOK_ID);
diff --git a/packaging/dbscripts/gluster_hooks_sp.sql 
b/packaging/dbscripts/gluster_hooks_sp.sql
index 4840c1b..8956186 100644
--- a/packaging/dbscripts/gluster_hooks_sp.sql
+++ b/packaging/dbscripts/gluster_hooks_sp.sql
@@ -123,6 +123,15 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+Create or replace FUNCTION DeleteAllGlusterHooks(v_cluster_id UUID)
+RETURNS VOID
+AS $procedure$
+BEGIN
+    DELETE FROM gluster_hooks
+    WHERE cluster_id = v_cluster_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
 
 Create or replace FUNCTION DeleteGlusterHooksByIds(v_ids TEXT)
 RETURNS VOID


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib4f99798cb4d0ebe70045c20286939f54d6b1fcc
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Sahina Bose <sab...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to