--- /dev/null
+/*\r
+==================================================================================\r
+ Copyright (c) 2018-2019 AT&T Intellectual Property.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================================\r
+*/\r
+\r
+#include <kpi_db.hpp>\r
+\r
+// Destructor\r
+kpi_db_resp::~kpi_db_resp(void){\r
+ freeReplyObject(redis_reply);\r
+};\r
+\r
+// Push the data to the DB\r
+void kpi_db_resp::Rpush(redisContext *c, std::string key,std::string value){\r
+ redis_reply = (redisReply*)redisCommand(c, "RPUSH %s %s",key,value);\r
+}\r
+\r
+// Getting val corresponding to key\r
+void kpi_db_resp::Get(redisContext *c, std::string key){\r
+ redis_reply= (redisReply*)redisCommand(c, "GET %s",key);\r
+}\r
+\r
+// Delete the key and value pair from the DB\r
+void kpi_db_resp::Del(redisContext *c, std::string key){\r
+ redis_reply= (redisReply*)redisCommand(c, "DEL %s",key);\r
+}\r
+\r
+// Check whether the Key exists in the DB\r
+void kpi_db_resp::Exists(redisContext *c, std::string key){\r
+ redis_reply= (redisReply*)redisCommand(c, "EXISTS %s",key);\r
+}\r
+\r
+// Called whenever the KPI information is received from the RIC Indication message\r
+void kpi_db_resp::UpdateDB(redisContext* c,cucp_resource_helper *kpi_data){\r
+\r
+ if(kpi_data == NULL || c==NULL) {\r
+ mdclog_write(MDCLOG_INFO, "Reddis Context or KPI_DATA pointer NULL\n");\r
+ return;\r
+ }\r
+ std::string gnb_id(reinterpret_cast<char*>(kpi_data->gnbId));\r
+ Exists(c,gnb_id);\r
+ if(redis_reply->type==REDIS_REPLY_STATUS){\r
+ if(redis_reply->integer==1){\r
+ //Key already exists ---> delete the data and insert again\r
+ Del(c,gnb_id);\r
+ Rpush(c,gnb_id,std::to_string(kpi_data->cuCpResourceStatus.bhca));\r
+ Rpush(c,gnb_id,std::to_string(kpi_data->cuCpResourceStatus.numberOfUEs));\r
+ }\r
+ else{\r
+ //Key does not exists --> Simply insert\r
+ Rpush(c,gnb_id,std::to_string(kpi_data->cuCpResourceStatus.bhca));\r
+ Rpush(c,gnb_id,std::to_string(kpi_data->cuCpResourceStatus.numberOfUEs));\r
+ }\r
+ }\r
+ mdclog_write(MDCLOG_INFO, "GNB_ID : %s\n\tBHCA : %d\n\tUE_Count : %d",gnb_id, kpi_data->cuCpResourceStatus.bhca, kpi_data->cuCpResourceStatus.numberOfUEs);\r
+}
\ No newline at end of file