Generare new uuid for the event of an updated alarm

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.

Test Cases:
PASS: Send an update for the existing alarm and verify
      a new event is created with different uuid

Closes bug:

Change-Id: I06fb43b35974ab81bd95979a7dfb3b3776aacd17
Signed-off-by: amantri <ayyappa.mantri@windriver.com>
This commit is contained in:
amantri 2023-12-11 11:45:19 -05:00
parent f8716aa344
commit c93e2851d1
3 changed files with 16 additions and 2 deletions

View File

@ -469,6 +469,20 @@ bool CFmDbAlarmOperation::get_all_history_alarms(CFmDBSession &sess, SFmAlarmDat
bool CFmDbAlarmOperation::add_alarm_history(CFmDBSession &sess, bool CFmDbAlarmOperation::add_alarm_history(CFmDBSession &sess,
SFmAlarmDataT &a, bool set){ 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){ if (set){
a.alarm_state = (a.alarm_state == FM_ALARM_STATE_CLEAR) ? a.alarm_state = (a.alarm_state == FM_ALARM_STATE_CLEAR) ?
FM_ALARM_STATE_SET : a.alarm_state; FM_ALARM_STATE_SET : a.alarm_state;
@ -509,7 +523,6 @@ bool CFmDbAlarmOperation::add_alarm_history(CFmDBSession &sess,
} }
int id =0; int id =0;
std::string sql;
if (false == fm_db_util_get_next_log_id(sess, id)) { if (false == fm_db_util_get_next_log_id(sess, id)) {
return false; return false;

View File

@ -229,6 +229,7 @@ bool fm_db_util_build_sql_insert(const char* db_table,
sprintf(str,"$%lu::int,", ++i); sprintf(str,"$%lu::int,", ++i);
} else if ((it->first == FM_ALARM_COLUMN_CREATED_AT) || } else if ((it->first == FM_ALARM_COLUMN_CREATED_AT) ||
(it->first == FM_ALARM_COLUMN_TIMESTAMP)){ (it->first == FM_ALARM_COLUMN_TIMESTAMP)){
FM_INFO_LOG("insert ***(%s).... (%s)",it->first.c_str(), it->second.c_str());
params.param_values.push_back(it->second.c_str()); params.param_values.push_back(it->second.c_str());
params.param_lengths.push_back(strlen(it->second.c_str())); params.param_lengths.push_back(strlen(it->second.c_str()));
params.param_format.push_back(0); params.param_format.push_back(0);
@ -399,6 +400,7 @@ bool fm_db_util_build_sql_update(const char* db_table,
if ((it->first == FM_ALARM_COLUMN_UPDATED_AT) || if ((it->first == FM_ALARM_COLUMN_UPDATED_AT) ||
(it->first == FM_ALARM_COLUMN_TIMESTAMP)){ (it->first == FM_ALARM_COLUMN_TIMESTAMP)){
FM_INFO_LOG("update ***(%s).... (%s)",it->first.c_str(), it->second.c_str());
params.param_values.push_back(it->second.c_str()); params.param_values.push_back(it->second.c_str());
params.param_lengths.push_back(strlen(it->second.c_str())); params.param_lengths.push_back(strlen(it->second.c_str()));
params.param_format.push_back(0); params.param_format.push_back(0);

View File

@ -83,7 +83,6 @@ static PyObject * _fm_set(PyObject * self, PyObject *args) {
ERROR_LOG("Failed to convert string to alarm."); ERROR_LOG("Failed to convert string to alarm.");
Py_RETURN_NONE; Py_RETURN_NONE;
} }
rc = fm_set_fault(&alm_data, &tmp_uuid); rc = fm_set_fault(&alm_data, &tmp_uuid);
if (rc == FM_ERR_OK) { if (rc == FM_ERR_OK) {
return PyUnicode_FromString(&(tmp_uuid[0])); return PyUnicode_FromString(&(tmp_uuid[0]));