Kanagaraj M has uploaded a new change for review. Change subject: gluster: update cluster 'comment' when new host found ......................................................................
gluster: update cluster 'comment' when new host found When a new host is added to an exiting cluster in the background using the gluster cli(gluster peer probe <host-name>), the sync job will check the list of hosts returned from the gluster with the list avaiable in the database. If there any new host which is not present in the database, Cluster's 'comment' field will be updated with the message "ACTION REQUIRED: Some new hosts found in the cluster". If the message is already present and there are no new hosts, the message will be cleared. Change-Id: I07c30ae9d7381a56edc753fdbfdb439465ffe6b7 Bug-Url: https://bugzilla.redhat.com/1025019 Signed-off-by: Kanagaraj M <kmayi...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.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, 85 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/20755/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.java index d528de9..61ff614 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.java @@ -56,6 +56,9 @@ private final Log log = LogFactory.getLog(GlusterSyncJob.class); private static final GlusterSyncJob instance = new GlusterSyncJob(); + private static final String ACTION_REQUIRED_NEW_SERVERS_FOUND_MSG = + "ACTION REQUIRED: Some new hosts are found in the cluster"; + private GlusterSyncJob() { } @@ -132,6 +135,7 @@ try { List<GlusterServerInfo> fetchedServers = fetchServers(cluster, upServer, existingServers); if (fetchedServers != null) { + updateNewServers(cluster, existingServers, fetchedServers); removeDetachedServers(existingServers, fetchedServers); } } catch(Exception e) { @@ -141,6 +145,49 @@ } } + private void updateNewServers(VDSGroup cluster, List<VDS> existingServers, List<GlusterServerInfo> fetchedServers) { + boolean serversAdded = hasNewServers(cluster, existingServers, fetchedServers); + String existingComment = cluster.getComment(); + String newComment = null; + if (serversAdded) { + if (!existingComment.contains(ACTION_REQUIRED_NEW_SERVERS_FOUND_MSG)) { + newComment = existingComment + ACTION_REQUIRED_NEW_SERVERS_FOUND_MSG; + } + } + else { + if (existingComment.length() > 0 && existingComment.contains(ACTION_REQUIRED_NEW_SERVERS_FOUND_MSG)) { + newComment = existingComment.replace(ACTION_REQUIRED_NEW_SERVERS_FOUND_MSG, ""); + } + } + + if (newComment != null) { + getClusterDao().updateComment(cluster.getId(), newComment); + } + } + + private boolean hasNewServers(VDSGroup cluster, List<VDS> existingServers, List<GlusterServerInfo> fetchedServers) { + if (GlusterFeatureSupported.glusterHostUuidSupported(cluster.getcompatibility_version())) { + for (GlusterServerInfo fetchedServer : fetchedServers) { + GlusterServer glusterServer = getGlusterServerDao().getByGlusterServerUuid(fetchedServer.getUuid()); + if (glusterServer == null || getVdsDao().get(glusterServer.getId()) == null) { + return true; + } + } + } + else { + for (GlusterServerInfo fetchedServer : fetchedServers) { + for (VDS existingServer: existingServers) { + List<String> vdsIps = getVdsIps(existingServer); + if (!fetchedServer.getHostnameOrIp().equals(existingServer.getHostName()) + && !vdsIps.contains(fetchedServer.getHostnameOrIp())) { + return true; + } + } + } + } + return false; + } + private void removeDetachedServers(List<VDS> existingServers, List<GlusterServerInfo> fetchedServers) { boolean serverRemoved = false; for (VDS server : existingServers) { 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 7e0e410..d194780 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 @@ -145,6 +145,15 @@ */ void setEmulatedMachine(Guid vdsGroupId, String emulatedMachine, boolean detectEmulatedMachine); + /** + * Sets the cluster's free text comment + * + * @param vdsGroupId + * @param comment + * - free text comment + */ + void updateComment(Guid vdsGroupId, String comment); + /** * Retries trusted cluster */ 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 11f03eb..725271a 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 @@ -138,6 +138,15 @@ getCallsHandler().executeModification("UpdateVdsGroupEmulatedMachine", parameterSource); } + @Override + public void updateComment(Guid vdsGroupId, String comment) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("vds_group_id", vdsGroupId) + .addValue("free_text_comment", comment); + + getCallsHandler().executeModification("UpdateVdsGroupComment", parameterSource); + } + public List<VDSGroup> getTrustedClusters() { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("trusted_service", true); 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 331baf9..e5555ad 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 @@ -350,6 +350,16 @@ } /** + * Test updating comment + */ + @Test + public void testUpdateComment() { + String comment = "This is a free text comment"; + dao.updateComment(existingVdsGroup.getId(), comment); + assertEquals(comment, dao.get(existingVdsGroup.getId()).getComment()); + } + + /** * Test the use of the special procedure to update emulated_machine */ @Test @@ -365,6 +375,7 @@ assertEquals(updatedValue, dao.get(existingVdsGroup.getId()).getEmulatedMachine()); } + /** * Test the use of the special procedure to update detect_emulated_machine */ diff --git a/packaging/dbscripts/vds_groups_sp.sql b/packaging/dbscripts/vds_groups_sp.sql index 7d47129..d2945f1 100644 --- a/packaging/dbscripts/vds_groups_sp.sql +++ b/packaging/dbscripts/vds_groups_sp.sql @@ -211,6 +211,15 @@ END; $procedure$ LANGUAGE plpgsql; +Create or replace FUNCTION UpdateVdsGroupComment(v_vds_group_id UUID, v_free_text_comment text) RETURNS VOID + AS $procedure$ +BEGIN + UPDATE vds_groups + SET free_text_comment = v_free_text_comment + WHERE vds_group_id = v_vds_group_id; +END; $procedure$ +LANGUAGE plpgsql; + Create or replace FUNCTION GetTrustedVdsGroups() RETURNS SETOF vds_groups_view STABLE AS $procedure$ BEGIN -- To view, visit http://gerrit.ovirt.org/20755 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I07c30ae9d7381a56edc753fdbfdb439465ffe6b7 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Kanagaraj M <kmayi...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches