From 80ac61075582c41e5a0e5e735a2a29bf58925311 Mon Sep 17 00:00:00 2001 From: amantri Date: Mon, 11 Dec 2023 11:45:19 -0500 Subject: [PATCH] Generare new uuid for the event of an alarm update When an update is recieved for the existing alarm, the event_log table rejects the insert request since the event is already present in the table so, this change creates a new uuid for the event by checking for the uuid in the event_log table, if exist, it raises a new event by generating a new uuid. Test Cases: PASS: Send an update for the existing alarm and verify a new event is created with different uuid PASS: Send multiple consecutive alarm updates and verify new events are raised for each update with unique uuid and timestamps. Closes bug: 2046374 Change-Id: I06fb43b35974ab81bd95979a7dfb3b3776aacd17 Signed-off-by: amantri --- fm-common/sources/fmDbAlarm.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/fm-common/sources/fmDbAlarm.cpp b/fm-common/sources/fmDbAlarm.cpp index 9daa11e6..d1c61833 100644 --- a/fm-common/sources/fmDbAlarm.cpp +++ b/fm-common/sources/fmDbAlarm.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2014-2018 Wind River Systems, Inc. +// Copyright (c) 2014-2023 Wind River Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -469,6 +469,20 @@ bool CFmDbAlarmOperation::get_all_history_alarms(CFmDBSession &sess, SFmAlarmDat bool CFmDbAlarmOperation::add_alarm_history(CFmDBSession &sess, SFmAlarmDataT &a, bool set){ + std::string sql; + std::string query; + + FM_DB_UT_NAME_VAL(query, FM_ALARM_COLUMN_UUID, a.uuid); + fm_db_util_build_sql_query((const char*)FM_EVENT_LOG_TABLE_NAME, query.c_str(), sql); + + fm_db_result_t result; + if (sess.query(sql.c_str(), result)){ + if (result.size() > 0){ + FM_DEBUG_LOG("Generate new uuid for the event of an updated alarm\n"); + fm_uuid_create(a.uuid); + } + } + if (set){ a.alarm_state = (a.alarm_state == FM_ALARM_STATE_CLEAR) ? FM_ALARM_STATE_SET : a.alarm_state; @@ -509,7 +523,6 @@ bool CFmDbAlarmOperation::add_alarm_history(CFmDBSession &sess, } int id =0; - std::string sql; if (false == fm_db_util_get_next_log_id(sess, id)) { return false;