Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-UDR
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-UDR
Commits
e3ae3afc
Commit
e3ae3afc
authored
Jun 20, 2022
by
Tien Thinh NGUYEN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DB Connection Manager
parent
e5d5d7a6
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
189 additions
and
3 deletions
+189
-3
src/common/udr.h
src/common/udr.h
+4
-2
src/udr_app/db_connection_manager.cpp
src/udr_app/db_connection_manager.cpp
+73
-0
src/udr_app/db_connection_manager.hpp
src/udr_app/db_connection_manager.hpp
+70
-0
src/udr_app/udr_app.cpp
src/udr_app/udr_app.cpp
+14
-1
src/udr_app/udr_event.cpp
src/udr_app/udr_event.cpp
+10
-0
src/udr_app/udr_event.hpp
src/udr_app/udr_event.hpp
+12
-0
src/udr_app/udr_event_sig.hpp
src/udr_app/udr_event_sig.hpp
+6
-0
No files found.
src/common/udr.h
View file @
e3ae3afc
...
...
@@ -27,6 +27,8 @@
#define HEART_BEAT_TIMER 10
#define DB_CONNECTION_TIMER 1000
#define _unused(x) ((void) (x))
#define NNRF_NFM_BASE "/nnrf-nfm/"
...
...
@@ -78,7 +80,7 @@ typedef enum db_type_s {
DB_TYPE_CASSANDRA
=
2
}
db_type_t
;
static
const
std
::
vector
<
std
::
string
>
db_type_e2str
=
{
"Unknown"
,
"MySQL"
,
"Cassandra"
};
static
const
std
::
vector
<
std
::
string
>
db_type_e2str
=
{
"Unknown"
,
"MySQL"
,
"Cassandra"
};
#endif
src/udr_app/db_connection_manager.cpp
0 → 100644
View file @
e3ae3afc
/*
* 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
*/
/*! \file db_connection_manager.cpp
\brief
\author Tien-Thinh NGUYEN
\company Eurecom
\date 2022
\email:
*/
#include "db_connection_manager.hpp"
#include "logger.hpp"
#include "udr.h"
#include "udr_app.hpp"
using
namespace
oai
::
udr
::
config
;
using
namespace
oai
::
udr
::
app
;
using
json
=
nlohmann
::
json
;
extern
udr_config
udr_cfg
;
//------------------------------------------------------------------------------
db_connection_manager
::
db_connection_manager
(
udr_event
&
ev
)
:
m_event_sub
(
ev
)
{}
//---------------------------------------------------------------------------------------------
void
db_connection_manager
::
start_event_connection_initialization
(
std
::
shared_ptr
<
database_wrapper_abstraction
>&
db_connector
)
{
// get current time
uint64_t
ms
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
system_clock
::
now
().
time_since_epoch
())
.
count
();
struct
itimerspec
its
;
its
.
it_value
.
tv_sec
=
DB_CONNECTION_TIMER
;
// seconds
its
.
it_value
.
tv_nsec
=
0
;
// 100 * 1000 * 1000; //100ms
const
uint64_t
interval
=
its
.
it_value
.
tv_sec
*
1000
+
its
.
it_value
.
tv_nsec
/
1000000
;
// convert sec, nsec to msec
db_connection
=
m_event_sub
.
subscribe_task_db_connection_reset
(
boost
::
bind
(
&
udr_nrf
::
trigger_connection_reset_procedure
,
this
,
_1
,
_2
),
db_connector
,
interval
,
ms
+
interval
);
}
//---------------------------------------------------------------------------------------------
void
db_connection_manager
::
trigger_connection_reset_procedure
(
std
::
shared_ptr
<
database_wrapper_abstraction
>&
db_connector
,
uint64_t
ms
)
{
_unused
(
ms
);
// Close the current connection
db_connector
.
close_connection
();
// and start a new one
db_connector
.
initialize
();
}
src/udr_app/db_connection_manager.hpp
0 → 100644
View file @
e3ae3afc
/*
* 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
*/
/*! \file db_connection_manager.hpp
\author Tien-Thinh NGUYEN
\company Eurecom
\date 2022
\email:
*/
#ifndef FILE_DB_CONNECTION_MANAGER_SEEN
#define FILE_DB_CONNECTION_MANAGER_SEEN
#include "database_wrapper_abstraction.hpp"
#include "udr_event.hpp"
namespace
oai
{
namespace
udr
{
namespace
app
{
class
db_connection_manager
{
private:
public:
db_connection_manager
(
udr_event
&
ev
);
db_connection_manager
(
db_connection_manager
const
&
)
=
delete
;
void
operator
=
(
db_connection_manager
const
&
)
=
delete
;
/*
* Start event connection initialization procedure
* @param [void]
* @return void
*/
void
start_event_connection_initialization
(
std
::
shared_ptr
<
database_wrapper_abstraction
>&
db_connector
);
/*
* Trigger connection reset procedure (NF Heartbeat)
* @param [void]
* @return void
*/
void
trigger_connection_reset_procedure
(
uint64_t
ms
,
std
::
shared_ptr
<
database_wrapper_abstraction
>&
db_connector
);
private:
udr_event
&
m_event_sub
;
bs2
::
connection
task_connection
;
bs2
::
connection
db_connection
;
};
}
// namespace app
}
// namespace udr
}
// namespace oai
#endif
/* FILE_DB_CONNECTION_MANAGER_SEEN */
src/udr_app/udr_app.cpp
View file @
e3ae3afc
...
...
@@ -37,6 +37,7 @@
#include "mysql_db.hpp"
#include "udr_config.hpp"
#include "udr_nrf.hpp"
#include "db_connection_manager.hpp"
using
namespace
oai
::
udr
::
app
;
using
namespace
oai
::
udr
::
model
;
...
...
@@ -45,6 +46,7 @@ using namespace oai::udr::config;
extern
udr_app
*
udr_app_inst
;
extern
udr_config
udr_cfg
;
udr_nrf
*
udr_nrf_inst
=
nullptr
;
db_connection_manager
*
db_connection_manager_inst
=
nullptr
;
//------------------------------------------------------------------------------
udr_app
::
udr_app
(
const
std
::
string
&
config_file
,
udr_event
&
ev
)
...
...
@@ -73,12 +75,23 @@ udr_app::udr_app(const std::string& config_file, udr_event& ev)
throw
;
}
}
// DB Connection Manager
try
{
db_connection_manager_inst
=
new
db_connection_manager
(
ev
);
Logger
::
udr_app
().
info
(
"DB Connection Task Created "
);
}
catch
(
std
::
exception
&
e
)
{
Logger
::
udr_app
().
error
(
"Cannot create DB Connection Task: %s"
,
e
.
what
());
throw
;
}
Logger
::
udr_app
().
startup
(
"Started"
);
}
//------------------------------------------------------------------------------
udr_app
::~
udr_app
()
{
Logger
::
udr_app
().
debug
(
"Delete UDR APP instance..."
);
// Close DB connection
db_connector
->
close_connection
();
}
//------------------------------------------------------------------------------
...
...
src/udr_app/udr_event.cpp
View file @
e3ae3afc
...
...
@@ -42,3 +42,13 @@ bs2::connection udr_event::subscribe_task_nf_heartbeat(
};
return
task_tick
.
connect
(
f
);
}
bs2
::
connection
udr_event
::
subscribe_task_db_connection_reset
(
const
db_connection_sig_t
::
slot_type
&
sig
,
std
::
shared_ptr
<
database_wrapper_abstraction
>&
db_connector
,
uint64_t
period
,
uint64_t
start
)
{
auto
f
=
[
db_connector
,
period
,
start
,
sig
](
uint64_t
t
)
{
if
(
t
>=
start
&&
(
t
-
start
)
%
period
==
0
)
sig
(
db_connector
,
t
);
};
return
db_connection_sig
.
connect
(
f
);
}
src/udr_app/udr_event.hpp
View file @
e3ae3afc
...
...
@@ -66,8 +66,20 @@ class udr_event {
bs2
::
connection
subscribe_task_nf_heartbeat
(
const
task_sig_t
::
slot_type
&
sig
,
uint64_t
period
,
uint64_t
start
=
0
);
/*
* Subscribe to the task db connection reset event
* @param [const db_connection_sig_t::slot_type &] sig
* @param [uint64_t] period: interval between two events
* @param [uint64_t] start:
* @return void
*/
bs2
::
connection
subscribe_task_db_connection_reset
(
const
db_connection_sig_t
::
slot_type
&
sig
,
uint64_t
period
,
uint64_t
start
=
0
);
private:
task_sig_t
task_tick
;
db_connection_sig_t
db_connection_sig
;
};
}
// namespace oai::udr::app
#endif
src/udr_app/udr_event_sig.hpp
View file @
e3ae3afc
...
...
@@ -33,6 +33,8 @@
#include <boost/signals2.hpp>
#include <string>
#include "database_wrapper_abstraction.hpp"
namespace
bs2
=
boost
::
signals2
;
namespace
oai
::
udr
::
app
{
...
...
@@ -41,5 +43,9 @@ typedef bs2::signal_type<
void
(
uint64_t
),
bs2
::
keywords
::
mutex_type
<
bs2
::
dummy_mutex
>>::
type
task_sig_t
;
typedef
bs2
::
signal_type
<
void
(
uint64_t
,
std
::
shared_ptr
<
database_wrapper_abstraction
>&
),
bs2
::
keywords
::
mutex_type
<
bs2
::
dummy_mutex
>>::
type
db_connection_sig_t
;
}
// namespace oai::udr::app
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment