Sahina Bose has uploaded a new change for review. Change subject: engine: Sync geo-rep config information ......................................................................
engine: Sync geo-rep config information Added method to update database with CLI information for geo-replication configuration Change-Id: I0ee0bc7e916df3becfc99b701de8a0c9e95e2a4d Signed-off-by: Sahina Bose <sab...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJobTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDao.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoTest.java M packaging/dbscripts/gluster_georep_sp.sql 8 files changed, 160 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/09/37109/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java index bf478c2..7db1aad 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java @@ -14,6 +14,7 @@ import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.gluster.GeoRepSessionStatus; import org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSessionConfiguration; import org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSessionDetails; import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity; import org.ovirt.engine.core.common.constants.gluster.GlusterConstants; @@ -144,7 +145,6 @@ updateDiscoveredSessions(cluster, sessionsMap); } - private void updateDiscoveredSessions(VDSGroup cluster, Map<String, GlusterGeoRepSession> sessionsMap) { removeDeletedSessions(cluster.getId(), sessionsMap); @@ -185,7 +185,52 @@ getGeoRepDao().updateSession(session); } updateSessionDetailsInDB(session); + updateDiscoveredSessionConfig(cluster, session); } + } + + private void updateDiscoveredSessionConfig(VDSGroup cluster, GlusterGeoRepSession session) { + List<GlusterGeoRepSessionConfiguration> sessionConfigList = getSessionConfigFromCLI(cluster, session); + if (sessionConfigList == null) { + log.info("No configuration information returned from VDS for session '{}'", session.getSessionKey()); + return; + } + List<GlusterGeoRepSessionConfiguration> existingSessionConfigs = + getGeoRepDao().getGeoRepSessionConfig(session.getId()); + Map<String, GlusterGeoRepSessionConfiguration> existingKeyConfigMap = + prepareMapOfExistingConfigs(existingSessionConfigs); + for (GlusterGeoRepSessionConfiguration sessionConfig : sessionConfigList) { + //update sessionId for fetched object. + sessionConfig.setId(session.getId()); + // check if session config exists in db + if (!existingSessionConfigs.contains(sessionConfig)) { + if (existingKeyConfigMap.containsKey(sessionConfig.getKey())) { + getGeoRepDao().updateConfig(sessionConfig); + String oldValue = existingKeyConfigMap.get(sessionConfig.getKey()).getValue(); + logGeoRepMessage(AuditLogType.GEOREP_OPTION_CHANGED_FROM_CLI, + cluster.getId(), + getOptionChangedCustomVars(session, + sessionConfig.getKey(), + sessionConfig.getValue(), + oldValue)); + } else { + getGeoRepDao().saveConfig(sessionConfig); + logGeoRepMessage(AuditLogType.GEOREP_OPTION_SET_FROM_CLI, + cluster.getId(), + getOptionChangedCustomVars(session, sessionConfig.getKey(), sessionConfig.getValue(), null)); + } + } + } + } + + private Map<String, GlusterGeoRepSessionConfiguration> prepareMapOfExistingConfigs(List<GlusterGeoRepSessionConfiguration> existingConfigs) { + Map<String, GlusterGeoRepSessionConfiguration> keyConfigMap = new HashMap<>(); + if (existingConfigs != null) { + for (GlusterGeoRepSessionConfiguration config : existingConfigs) { + keyConfigMap.put(config.getKey(), config); + } + } + return keyConfigMap; } private void updateSlaveNodeAndVolumeId(GlusterGeoRepSession session) { @@ -240,6 +285,24 @@ put("geoRepSessionKey", session.getSessionKey()); } }); + } + + private void logGeoRepMessage(AuditLogType logType, Guid clusterId, final HashMap<String, String> customVars) { + logUtil.logAuditMessage(clusterId, null, null, + logType, customVars); + } + + private HashMap<String, String> getOptionChangedCustomVars(final GlusterGeoRepSession session, + String key, + String value, + String oldValue) { + HashMap<String, String> keyValMap = new HashMap<>(); + keyValMap.put(GlusterConstants.VOLUME_NAME, session.getMasterVolumeName()); + keyValMap.put("geoRepSessionKey", session.getSessionKey()); + keyValMap.put("key", key); + keyValMap.put("value", value); + keyValMap.put("oldValue", oldValue); + return keyValMap; } /** @@ -352,6 +415,31 @@ } } + private List<GlusterGeoRepSessionConfiguration> getSessionConfigFromCLI(VDSGroup cluster, + GlusterGeoRepSession session) { + VDS upServer = getClusterUtils().getRandomUpServer(cluster.getId()); + if (upServer == null) { + log.debug("No UP server found in cluster: {} for geo-rep monitoring", cluster.getName()); + return null; + } + try { + VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GetGlusterVolumeGeoRepConfigList, + new GlusterVolumeGeoRepSessionVDSParameters(upServer.getId(), + session.getMasterVolumeName(), session.getSlaveHostName(), session.getSlaveVolumeName())); + if (returnValue.getSucceeded()) { + return (List<GlusterGeoRepSessionConfiguration>) returnValue.getReturnValue(); + } else { + log.error("VDS error {}", returnValue.getVdsError().getMessage()); + log.debug("VDS error", returnValue.getVdsError()); + return null; + } + } catch (Exception e) { + log.error("Exception getting geo-rep status from vds {}", e.getMessage()); + log.debug("Exception", e); + return null; + } + } + private GlusterVolumeEntity getVolume(VDSGroup cluster, String masterVolumeName) { return getVolumeDao().getByName(cluster.getId(), masterVolumeName); } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJobTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJobTest.java index ee80831..3849f69 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJobTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJobTest.java @@ -23,6 +23,7 @@ import org.ovirt.engine.core.common.businessentities.gluster.GeoRepSessionStatus; import org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity; import org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSessionConfiguration; import org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSessionDetails; import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus; import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity; @@ -103,6 +104,20 @@ } @Test + public void testDiscoverGeoRepDataWithConfig() { + + doReturn(getSessionsVDSReturnVal(true, 2)).when(syncJob) + .runVdsCommand(eq(VDSCommandType.GetGlusterVolumeGeoRepStatus), + any(GlusterVolumeGeoRepSessionVDSParameters.class)); + doReturn(getSessionsConfigListVDSReturnVal(true)).when(syncJob) + .runVdsCommand(eq(VDSCommandType.GetGlusterVolumeGeoRepConfigList), + any(GlusterVolumeGeoRepSessionVDSParameters.class)); + syncJob.discoverGeoRepData(); + Mockito.verify(geoRepDao, times(2)).save(any(GlusterGeoRepSession.class)); + Mockito.verify(geoRepDao, times(2)).saveConfig(any(GlusterGeoRepSessionConfiguration.class)); + } + + @Test public void testDiscoverGeoRepDataWhenNoSessions() { doReturn(getSessionsVDSReturnVal(true, 0)).when(syncJob) @@ -163,6 +178,26 @@ return vdsRetValue; } + private Object getSessionsConfigListVDSReturnVal(boolean ret) { + VDSReturnValue vdsRetValue = new VDSReturnValue(); + vdsRetValue.setSucceeded(ret); + if (ret) { + vdsRetValue.setReturnValue(getSessionConfigList()); + } else { + vdsRetValue.setReturnValue(null); + } + return vdsRetValue; + } + + private List<GlusterGeoRepSessionConfiguration> getSessionConfigList() { + List<GlusterGeoRepSessionConfiguration> configList = new ArrayList<>(); + GlusterGeoRepSessionConfiguration config = new GlusterGeoRepSessionConfiguration(); + config.setKey("georep-crawl"); + config.setValue("hybrid"); + configList.add(config); + return configList; + } + private List<GlusterGeoRepSession> getSessions(int count, boolean populateVoId) { List<GlusterGeoRepSession> sessions = new ArrayList<GlusterGeoRepSession>(); for (int i = 0; i < count; i++) { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java index 618c06c..145e4ad 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java @@ -394,6 +394,8 @@ GEOREP_SESSION_STOP_FAILED(4102, AuditLogSeverity.ERROR), GEOREP_SESSION_DELETE(4103), GEOREP_SESSION_DELETE_FAILED(4104, AuditLogSeverity.ERROR), + GEOREP_OPTION_SET_FROM_CLI(4105, AuditLogSeverity.WARNING), + GEOREP_OPTION_CHANGED_FROM_CLI(4106, AuditLogSeverity.WARNING), USER_FORCE_SELECTED_SPM(159), USER_VDS_RESTART(41), diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDao.java index 7050b7c..9d945ed 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDao.java @@ -52,5 +52,7 @@ public List<GlusterGeoRepSessionConfiguration> getGeoRepSessionConfig(Guid sessionId); + public GlusterGeoRepSessionConfiguration getGeoRepSessionConfigByKey(Guid sessionId, String configKey); + public List<GlusterGeoRepSession> getAllSessions(); } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoDbFacadeImpl.java index 9942f56..573d98e 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoDbFacadeImpl.java @@ -145,6 +145,13 @@ } @Override + public GlusterGeoRepSessionConfiguration getGeoRepSessionConfigByKey(Guid sessionId, String configKey) { + // TODO Auto-generated method stub GetGlusterGeoRepSessionConfigByKey + return getCallsHandler().executeRead("GetGlusterGeoRepSessionConfigByKey", georepSessionConfigRowMapper, + createIdParameterMapper(sessionId).addValue("config_key", configKey)); + } + + @Override protected MapSqlParameterSource createFullParametersMapper( GlusterGeoRepSession geoRepSession) { return createIdParameterMapper(geoRepSession.getId()) @@ -253,6 +260,7 @@ }; } + @Override public List<GlusterGeoRepSession> getAllSessions() { return getCallsHandler().executeReadList("GetAllGlusterGeoRepSessions", georepSessionRowMapper, getCustomMapSqlParameterSource()); } diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties index 827abcc..0167784 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties @@ -822,6 +822,10 @@ GEOREP_SESSION_DELETE_FAILED=Failed to delete geo-replication session on volume ${glusterVolumeName} GEOREP_SESSION_STARTED=Geo-replication session on volume ${glusterVolumeName} has been started. GEOREP_SESSION_START_FAILED=Failed to start geo-replication session on volume ${glusterVolumeName} +GEOREP_OPTION_SET_FROM_CLI=Detected new option ${key}=${value} for geo-replication session ${geoRepSessionKey} on volume ${glusterVolumeName} of cluster ${VdsGroupName}, and added it to engine. +GEOREP_OPTION_CHANGED_FROM_CLI=Detected change in value of option ${key} from ${oldValue} to ${value} for geo-replication session on volume ${glusterVolumeName} of cluster ${VdsGroupName}, and updated it to engine. + + VDS_UNTRUSTED=Host ${VdsName} was set to non-operational. Host is not trusted by the attestation service. USER_ADDED_NETWORK_QOS=Network QoS ${QosName} was added. (User: ${UserName}) USER_FAILED_TO_ADD_NETWORK_QOS=Failed to add Network QoS ${QosName}. (User: ${UserName}) diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoTest.java index 51a5029..4bc3c42 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterGeoRepDaoTest.java @@ -18,6 +18,7 @@ public class GlusterGeoRepDaoTest extends BaseDAOTestCase { + private static final String GEOREP_CONFIG_CRAWL = "georep-crawl"; private static final Guid SESSION_ID = new Guid("4f4f751e-549b-4e7a-aff6-32d36856c125"); private static final Guid NONEXIST_SESSION_ID = new Guid("5e5e751e-549b-4e7a-aff6-32d36856c125"); @@ -55,7 +56,7 @@ private GlusterGeoRepSessionConfiguration getGlusterGeoRepSessionConfig() { GlusterGeoRepSessionConfiguration sessionConfig = new GlusterGeoRepSessionConfiguration(); sessionConfig.setId(FixturesTool.GLUSTER_GEOREP_SESSION_ID); - sessionConfig.setKey("georep-crawl"); + sessionConfig.setKey(GEOREP_CONFIG_CRAWL); sessionConfig.setValue("changelog"); return sessionConfig; } @@ -99,8 +100,12 @@ public void testSaveConfig() { GlusterGeoRepSessionConfiguration sessionConfig = getGlusterGeoRepSessionConfig(); dao.saveConfig(sessionConfig); - List<GlusterGeoRepSessionConfiguration> fetchedSessionConfig = dao.getGeoRepSessionConfig(FixturesTool.GLUSTER_GEOREP_SESSION_ID); - assertEquals(sessionConfig, fetchedSessionConfig.get(0)); + List<GlusterGeoRepSessionConfiguration> fetchedSessionConfigList = + dao.getGeoRepSessionConfig(FixturesTool.GLUSTER_GEOREP_SESSION_ID); + assertEquals(sessionConfig, fetchedSessionConfigList.get(0)); + GlusterGeoRepSessionConfiguration fetchedSessionConfig = + dao.getGeoRepSessionConfigByKey(FixturesTool.GLUSTER_GEOREP_SESSION_ID, GEOREP_CONFIG_CRAWL); + assertEquals(sessionConfig, fetchedSessionConfig); } @Test diff --git a/packaging/dbscripts/gluster_georep_sp.sql b/packaging/dbscripts/gluster_georep_sp.sql index d73d43e..47cb79d 100644 --- a/packaging/dbscripts/gluster_georep_sp.sql +++ b/packaging/dbscripts/gluster_georep_sp.sql @@ -209,6 +209,18 @@ END; $procedure$ LANGUAGE plpgsql; +Create or replace FUNCTION GetGlusterGeoRepSessionConfigByKey(v_session_id UUID, + v_config_key VARCHAR(50)) +RETURNS SETOF gluster_georep_config STABLE +AS $procedure$ +BEGIN + RETURN QUERY SELECT session_id, config_key, config_value, _update_date + FROM gluster_georep_config + WHERE session_id = v_session_id + AND config_key = v_config_key; +END; $procedure$ +LANGUAGE plpgsql; + Create or replace FUNCTION GetAllGlusterGeoRepSessions() RETURNS SETOF gluster_georep_sessions_view STABLE AS $procedure$ -- To view, visit http://gerrit.ovirt.org/37109 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0ee0bc7e916df3becfc99b701de8a0c9e95e2a4d 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