Commit a75853e6 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Cleanup

parent aad95109
......@@ -39,8 +39,9 @@ cassandra_db::cassandra_db() : database_wrapper<cassandra_db>() {
cassandra_db::~cassandra_db() {}
bool cassandra_db::initialize() {
Logger::udr_app().debug("Initialize from CassandraDB");
return true;
Logger::udr_app().debug("Initialize CassandraDB");
Logger::udr_app().debug("CassandraDB is not supported!");
return false;
}
bool cassandra_db::close_connection() {
......@@ -54,6 +55,7 @@ bool cassandra_db::insert_authentication_subscription(
bool cassandra_db::query_authentication_subscription(
const std::string& id, nlohmann::json& json_data) {
Logger::udr_app().debug("CassandraDB is not supported!");
return true;
}
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "database_wrapper.hpp"
#include "logger.hpp"
using namespace oai::udr::app;
/*
//------------------------------------------------------------------------------
template <class DerivedT> database_wrapper<DerivedT>::database_wrapper():
database_wrapper_abstraction() {
//db_type = DB_TYPE_UNKNOWN;
}
//------------------------------------------------------------------------------
template <class DerivedT> database_wrapper<DerivedT>::~database_wrapper() {}
*/
/*
template <class DerivedT> bool database_wrapper<DerivedT>:: initialize() {
Logger::udr_app().debug("initialize from database_wrapper");
auto derived = static_cast<DerivedT*>(this);
//return derived->initialize();
return true;
}
*/
/*
template <class DerivedT> bool database_wrapper<DerivedT>:: close_connection() {
return true;
}
*/
/*
template<class DerivedT>
bool database_wrapper<DerivedT>::insert_authentication_subscription(
const std::string& id, const nlohmann::json& json_data) {
Logger::udr_app().debug(
"insert_authentication_subscription from database_wrapper");
auto derived = static_cast<DerivedT*>(this);
return derived->insert_authentication_subscription(id, json_data);
return true;
}
template<class DerivedT>
bool database_wrapper<DerivedT>::query_authentication_subscription(
const std::string& id, nlohmann::json& json_data) {
return true;
}
template<class DerivedT>
bool database_wrapper<DerivedT>::update_authentication_subscription(
const std::string& id, const nlohmann::json& json_data) {
return true;
}
template<class DerivedT>
bool database_wrapper<DerivedT>::delete_authentication_subscription(
const std::string& id) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::create_amf_context_3gpp(
const std::string& ue_id, const nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::query_amf_context_3gpp(
const std::string& ue_id, nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::database_wrapper::insert_authentication_status(
const std::string& ue_id, const nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::database_wrapper::delete_authentication_status(
const std::string& ue_id) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::database_wrapper::query_authentication_status(
const std::string& ue_id, nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::database_wrapper::query_sdm_subscription(
const std::string& ue_id, const std::string& subs_id,
nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::database_wrapper::delete_sdm_subscription(
const std::string& ue_id, const std::string& subs_id) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::update_sdm_subscription(
const std::string& ue_id, const std::string& subs_id,
nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::create_sdm_subscriptions(
const std::string& ue_id, nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::query_sdm_subscriptions(
const std::string& ue_id, nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::query_sm_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data, oai::udr::model::Snssai, std::string dnn) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::insert_smf_context_non_3gpp(
const std::string& ue_id, const int32_t& pdu_session_id,
nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::delete_smf_context(
const std::string& ue_id, const int32_t& pdu_session_id) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::query_smf_registration(
const std::string& ue_id, const int32_t& pdu_session_id,
nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::query_smf_reg_list(
const std::string& ue_id, nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
template<class DerivedT>
bool database_wrapper<DerivedT>::query_smf_select_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data) {
return true;
}
*/
This diff is collapsed.
......@@ -21,6 +21,11 @@
#ifndef DATABASE_WRAPPER_ABSTRACTION_HPP
#define DATABASE_WRAPPER_ABSTRACTION_HPP
#include "udr.h"
#include "Snssai.h"
#include "logger.hpp"
#include <nlohmann/json.hpp>
namespace oai::udr::app {
......@@ -29,7 +34,221 @@ class database_wrapper_abstraction {
database_wrapper_abstraction(){};
virtual ~database_wrapper_abstraction(){};
// virtual std::unique_ptr<database_wrapper_abstraction> clone() const = 0;
/*
* Initialize the DB and establish the connection between UDR and the DB
* @param void
* @return true if successful, otherwise return false
*/
virtual bool initialize() = 0;
/*
* Close the connection established to the DB
* @param void
* @return true if successful, otherwise return false
*/
virtual bool close_connection() = 0;
/*
* Insert a new item to the DB for the Authentication Subscription
* @param [const std::string&] id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool insert_authentication_subscription(
const std::string& id, const nlohmann::json& json_data) = 0;
/*
* Query an item from the DB for the Authentication Subscription
* @param [const std::string&] id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool query_authentication_subscription(
const std::string& id, nlohmann::json& json_data) = 0;
/*
* Update an item from the DB for the Authentication Subscription
* @param [const std::string&] id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool update_authentication_subscription(
const std::string& id, const nlohmann::json& json_data) = 0;
/*
* Delete an item from the DB for the Authentication Subscription
* @param [const std::string&] id: UE Identity
* @return true if successful, otherwise return false
*/
virtual bool delete_authentication_subscription(const std::string& id) = 0;
/*
* Query an item from the DB for AccessandMobilitySubscriptionData
* @param [const std::string&] ue_id: UE Identity
* @param [const std::string& ] serving_plmn_id: Serving PLMN ID
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data) = 0;
/*
* Insert an item into DB for AMF3GPPAccessRegistration Context
* @param [const std::string&] ue_id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool create_amf_context_3gpp(
const std::string& ue_id, const nlohmann::json& json_data) = 0;
/*
* Query for an item from the DB for AMF3GPPAccessRegistration
* @param [const std::string&] ue_id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @param [long code] code: HTTP response code
* @return true if successful, otherwise return false
*/
virtual bool query_amf_context_3gpp(
const std::string& ue_id, nlohmann::json& json_data) = 0;
/*
* Insert a new item into the DB for AuthenticationStatus
* @param [const std::string&] ue_id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool insert_authentication_status(
const std::string& ue_id, const nlohmann::json& json_data) = 0;
/*
* Delete an item from the DB for AuthenticationStatus
* @param [const std::string&] ue_id: UE Identity
* @return true if successful, otherwise return false
*/
virtual bool delete_authentication_status(const std::string& ue_id) = 0;
/*
* Query for an item from the DB for AuthenticationStatus
* @param [const std::string&] ue_id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool query_authentication_status(
const std::string& ue_id, nlohmann::json& json_data) = 0;
/*
* Query an item from the DB for SDMSubscription
* @param [const std::string&] ue_id: UE Identity
* @param [const std::string&] subs_id: subscription ID
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool query_sdm_subscription(
const std::string& ue_id, const std::string& subs_id,
nlohmann::json& json_data) = 0;
/*
* Delete an item from the DB for SDMSubscription
* @param [const std::string&] ue_id: UE Identity
* @param [const std::string&] subs_id: subscription ID
* @return true if successful, otherwise return false
*/
virtual bool delete_sdm_subscription(
const std::string& ue_id, const std::string& subs_id) = 0;
/*
* Update an item from the DB for SDMSubscription
* @param [const std::string&] ue_id: UE Identity
* @param [const std::string&] subs_id: subscription ID
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool update_sdm_subscription(
const std::string& ue_id, const std::string& subs_id,
nlohmann::json& json_data) = 0;
/*
* Insert a new item into the DB for SDMSubscriptions
* @param [const std::string&] ue_id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool create_sdm_subscriptions(
const std::string& ue_id, nlohmann::json& json_data) = 0;
/*
* Query an item from the DB for SDMSubscriptions
* @param [const std::string&] ue_id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool query_sdm_subscriptions(
const std::string& ue_id, nlohmann::json& json_data) = 0;
/*
* Query an item from the DB for SessionManagementSubscription
* @param [const std::string&] ue_id: UE Identity
* @param [const std::string&] serving_plmn_id: Serving PLMN ID
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool query_sm_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data, oai::udr::model::Snssai snssai = {},
std::string dnn = {}) = 0;
/*
* Insert an item into the DB for SMFRegistration
* @param [const std::string&] ue_id: UE Identity
* @param [const int32_t&] pdu_session_id: PDU Session ID
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool insert_smf_context_non_3gpp(
const std::string& ue_id, const int32_t& pdu_session_id,
nlohmann::json& json_data) = 0;
/*
* Delete an item from the DB for SMFRegistration
* @param [const std::string&] ue_id: UE Identity
* @param [const int32_t&] pdu_session_id: PDU Session ID
* @return true if successful, otherwise return false
*/
virtual bool delete_smf_context(
const std::string& ue_id, const int32_t& pdu_session_id) = 0;
/*
* Query an item from the DB SMFRegistration
* @param [const std::string&] ue_id: UE Identity
* @param [const int32_t&] pdu_session_id: PDU Session ID
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool query_smf_registration(
const std::string& ue_id, const int32_t& pdu_session_id,
nlohmann::json& json_data) = 0;
/*
* Query an item from the DB for a request to retrieve
* SMFRegistrationsCollection (SMFRegistrationsCollectionApiImpl)
* @param [const std::string&] ue_id: UE Identity
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool query_smf_reg_list(
const std::string& ue_id, nlohmann::json& json_data) = 0;
/*
* Query an item from the DB for SMFSelectionSubscription
* @param [const std::string&] ue_id: UE Identity
* @param [const std::string&] serving_plmn_id: Serving PLMN ID
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool query_smf_select_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data) = 0;
};
} // namespace oai::udr::app
......
......@@ -31,15 +31,13 @@ using namespace oai::udr::config;
extern udr_config udr_cfg;
//------------------------------------------------------------------------------
mysql_db::mysql_db() : database_wrapper<mysql_db>() {
// initialize();
}
mysql_db::mysql_db() : database_wrapper<mysql_db>() {}
//------------------------------------------------------------------------------
mysql_db::~mysql_db() {}
bool mysql_db::initialize() {
Logger::udr_app().debug("Initialize from MySQL DB");
Logger::udr_app().debug("Initialize MySQL DB");
if (!mysql_init(&mysql_connector)) {
Logger::udr_app().error("Cannot initialize MySQL");
throw std::runtime_error("Cannot initialize MySQL");
......
......@@ -55,12 +55,23 @@ udr_app::udr_app(const std::string& config_file, udr_event& ev)
: event_sub(ev) {
Logger::udr_app().startup("Starting...");
if (udr_cfg.db_type == DB_TYPE_MYSQL) {
db_connector = std::make_shared<mysql_db>();
} else {
// Use the appropriate DB connector
if (udr_cfg.db_type == DB_TYPE_CASSANDRA) {
db_connector = std::make_shared<cassandra_db>();
} else {
db_connector = std::make_shared<mysql_db>();
}
if (!db_connector->initialize()) {
Logger::udr_app().error("Error when initializing a connection with DB");
return;
}
db_connector->initialize();
// TEST
std::string ue_id;
nlohmann::json response_data;
long code;
handle_read_authentication_subscription(ue_id, response_data, code);
/*
if (!mysql_init(&mysql)) {
Logger::udr_app().error("Cannot initialize MySQL");
......@@ -1050,20 +1061,13 @@ void udr_app::handle_read_authentication_subscription(
const std::string& ue_id, nlohmann::json& response_data, long& code) {
Logger::udr_server().info("Handle Read Authentication Subscription");
// obj->accessDerivedField();
if (udr_cfg.db_type == DB_TYPE_MYSQL) {
if (std::dynamic_pointer_cast<mysql_db>(db_connector)
->query_authentication_subscription(ue_id, response_data)) {
if (db_connector->query_authentication_subscription(ue_id, response_data)) {
code = HTTP_STATUS_CODE_200_OK;
Logger::udr_server().info(
"AuthenticationSubscription GET: %s", response_data.dump().c_str());
} else {
code = HTTP_STATUS_CODE_404_NOT_FOUND; // TODO
}
} else {
}
return;
/*
......
......@@ -42,7 +42,7 @@ namespace oai::udr::config {
udr_config::udr_config() : mysql(), instance(), udr_name(), pid_dir(), nudr() {
nudr_http2_port = 8080;
nudr.api_version = "v1";
db_type = DB_TYPE_CASSANDRA;
db_type = DB_TYPE_MYSQL;
}
//------------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment