Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
53c3e429
Commit
53c3e429
authored
Oct 21, 2019
by
Carla Guillen Carias
Browse files
Renaming...
parent
595348fb
Changes
6
Hide whitespace changes
Inline
Side-by-side
analytics/operators/persystsql/
PerSyst
DB.cpp
→
analytics/operators/persystsql/
Maria
DB.cpp
View file @
53c3e429
//================================================================================
// Name :
PerSyst
DB.cpp
// Name :
Maria
DB.cpp
// Author : Carla Guillen
// Contact : info@dcdb.it
// Copyright : Leibniz Supercomputing Centre
...
...
@@ -25,8 +25,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//================================================================================
#include
"PerSystDB.h"
#include
<string>
#include
<sstream>
#include
<iostream>
...
...
@@ -36,11 +34,11 @@
#include
<sys/types.h>
// uid_t
#include
<pwd.h>
// getpwuid
#include
"../../../common/include/timestamp.h"
#include
"PerSystDB.h"
#include
"boost/date_time/gregorian/gregorian.hpp"
#include
"boost/date_time/local_time/local_time.hpp"
#include
"boost/date_time/posix_time/posix_time.hpp"
#include
"MariaDB.h"
#include
"MariaDB.h"
...
...
@@ -64,10 +62,10 @@ public:
}
};
PerSystDB
*
PerSyst
DB
::
instance
=
nullptr
;
std
::
mutex
PerSyst
DB
::
mut
;
MariaDB
*
Maria
DB
::
instance
=
nullptr
;
std
::
mutex
Maria
DB
::
mut
;
void
PerSyst
DB
::
print_error
(){
void
Maria
DB
::
print_error
(){
LOG
(
error
)
<<
"Error("
<<
mysql_errno
(
_mysql
)
<<
") ["
<<
mysql_sqlstate
(
_mysql
)
<<
"]
\"
"
<<
mysql_error
(
_mysql
)
<<
"
\"
"
;
if
(
mysql_errno
(
_mysql
)
==
2006
){
mysql_close
(
_mysql
);
...
...
@@ -75,20 +73,20 @@ void PerSystDB::print_error(){
}
}
PerSystDB
::
PerSyst
DB
()
:
_mysql
(
NULL
),
_rotation
(
EVERY_MONTH
),
_every_x_days
(
0
),
_end_aggregate_timestamp
(
0
),
_initialized
(
false
)
{
MariaDB
::
Maria
DB
()
:
_mysql
(
NULL
),
_rotation
(
EVERY_MONTH
),
_every_x_days
(
0
),
_end_aggregate_timestamp
(
0
),
_initialized
(
false
)
{
}
PerSystDB
*
PerSyst
DB
::
getInstance
(){
MariaDB
*
Maria
DB
::
getInstance
(){
// no lock here
if
(
instance
)
return
instance
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
mut
);
if
(
instance
)
return
instance
;
return
instance
=
new
PerSyst
DB
();
return
instance
=
new
Maria
DB
();
}
bool
PerSyst
DB
::
initializeConnection
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
bool
Maria
DB
::
initializeConnection
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
const
std
::
string
&
password
,
const
std
::
string
&
database_name
,
Rotation_t
rotation
,
int
port
,
unsigned
int
every_x_days
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mut
);
...
...
@@ -104,7 +102,7 @@ bool PerSystDB::initializeConnection(const std::string & host, const std::string
return
true
;
}
bool
PerSyst
DB
::
finalizeConnection
(){
bool
Maria
DB
::
finalizeConnection
(){
std
::
lock_guard
<
std
::
mutex
>
lock
(
mut
);
if
(
_initialized
){
mysql_close
(
_mysql
);
...
...
@@ -115,11 +113,11 @@ bool PerSystDB::finalizeConnection(){
}
PerSystDB
::~
PerSyst
DB
(){
MariaDB
::~
Maria
DB
(){
}
bool
PerSyst
DB
::
getDBJobIDs
(
std
::
vector
<
std
::
string
>
&
job_id_strings
,
std
::
map
<
std
::
string
,
std
::
string
>&
job_id_map
)
{
bool
Maria
DB
::
getDBJobIDs
(
std
::
vector
<
std
::
string
>
&
job_id_strings
,
std
::
map
<
std
::
string
,
std
::
string
>&
job_id_map
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mut
);
std
::
vector
<
std
::
string
>
notfound
;
for
(
auto
&
job_id_str
:
job_id_strings
){
...
...
@@ -165,9 +163,9 @@ bool PerSystDB::getDBJobIDs(std::vector<std::string> & job_id_strings, std::map<
return
true
;
}
void
PerSyst
DB
::
addJobToCache
(
std
::
string
&
job_id_string
,
std
::
string
&
job_id_db
){
void
Maria
DB
::
addJobToCache
(
std
::
string
&
job_id_string
,
std
::
string
&
job_id_db
){
if
(
_jobCache
.
size
()
==
JOB_CACHE_MAX_SIZE
){
//remove one element before inserting
using
MyPairType
=
std
::
pair
<
std
::
string
,
PerSyst
DB
::
Job_info_t
>
;
using
MyPairType
=
std
::
pair
<
std
::
string
,
Maria
DB
::
Job_info_t
>
;
auto
smallest
=
std
::
min_element
(
_jobCache
.
begin
(),
_jobCache
.
end
(),
[](
const
MyPairType
&
l
,
const
MyPairType
&
r
)
->
bool
{
return
l
.
second
.
last_seen_timestamp
<
r
.
second
.
last_seen_timestamp
;});
_jobCache
.
erase
(
smallest
);
...
...
@@ -178,7 +176,7 @@ void PerSystDB::addJobToCache(std::string &job_id_string, std::string & job_id_d
_jobCache
[
job_id_string
]
=
ji
;
}
bool
PerSyst
DB
::
getCurrentSuffixAggregateTable
(
std
::
string
&
suffix
){
bool
Maria
DB
::
getCurrentSuffixAggregateTable
(
std
::
string
&
suffix
){
if
(
_end_aggregate_timestamp
){
auto
now_uts
=
getTimestamp
();
if
(
now_uts
<
_end_aggregate_timestamp
)
{
//suffix found, don't do anything
...
...
@@ -219,7 +217,7 @@ bool PerSystDB::getCurrentSuffixAggregateTable(std::string & suffix){
}
bool
PerSyst
DB
::
insertIntoJob
(
const
std
::
string
&
job_id_string
,
const
std
::
string
&
uid
,
int
&
job_id_db
,
const
std
::
string
&
suffix
){
bool
Maria
DB
::
insertIntoJob
(
const
std
::
string
&
job_id_string
,
const
std
::
string
&
uid
,
int
&
job_id_db
,
const
std
::
string
&
suffix
){
std
::
lock_guard
<
std
::
mutex
>
lock
(
mut
);
std
::
stringstream
build_insert
;
build_insert
<<
"INSERT INTO Accounting (job_id_string, user, aggregate_first_suffix, aggregate_last_suffix) VALUES (
\'
"
<<
job_id_string
<<
"
\'
,
\'
"
;
...
...
@@ -237,7 +235,7 @@ bool PerSystDB::insertIntoJob(const std::string& job_id_string, const std::strin
}
bool
PerSyst
DB
::
insertInAggregateTable
(
const
std
::
string
&
suffix
,
Aggregate_info_t
&
agg
){
bool
Maria
DB
::
insertInAggregateTable
(
const
std
::
string
&
suffix
,
Aggregate_info_t
&
agg
){
std
::
lock_guard
<
std
::
mutex
>
lock
(
mut
);
std
::
stringstream
build_insert
;
build_insert
<<
"INSERT INTO Aggregate_"
<<
suffix
<<
" VALUES ( FROM_UNIXTIME(
\'
"
<<
agg
.
timestamp
;
...
...
@@ -259,7 +257,7 @@ bool PerSystDB::insertInAggregateTable(const std::string& suffix, Aggregate_info
return
true
;
}
bool
PerSyst
DB
::
createNewAggregate
(
std
::
string
&
new_suffix
){
bool
Maria
DB
::
createNewAggregate
(
std
::
string
&
new_suffix
){
std
::
string
select
=
"SELECT suffix, end_timestamp FROM SuffixToAggregateTable ORDER BY end_timestamp DESC LIMIT 1"
;
if
(
mysql_real_query
(
_mysql
,
select
.
c_str
(),
select
.
size
())){
print_error
();
...
...
@@ -315,7 +313,7 @@ bool PerSystDB::createNewAggregate(std::string& new_suffix){
}
bool
PerSyst
DB
::
updateJobsLastSuffix
(
std
::
map
<
std
::
string
,
std
::
string
>&
job_map
,
std
::
string
&
suffix
){
bool
Maria
DB
::
updateJobsLastSuffix
(
std
::
map
<
std
::
string
,
std
::
string
>&
job_map
,
std
::
string
&
suffix
){
std
::
lock_guard
<
std
::
mutex
>
lock
(
mut
);
std
::
stringstream
build_update
;
build_update
<<
"UPDATE Accounting SET aggregate_last_suffix=
\'
"
<<
suffix
...
...
@@ -341,7 +339,7 @@ bool PerSystDB::updateJobsLastSuffix(std::map<std::string, std::string>& job_map
}
bool
PerSyst
DB
::
getTableSuffix
(
std
::
string
&
table_suffix
){
bool
Maria
DB
::
getTableSuffix
(
std
::
string
&
table_suffix
){
std
::
lock_guard
<
std
::
mutex
>
lock
(
mut
);
if
(
!
getCurrentSuffixAggregateTable
(
table_suffix
)
&&
!
createNewAggregate
(
table_suffix
))
{
...
...
@@ -350,7 +348,7 @@ bool PerSystDB::getTableSuffix(std::string & table_suffix){
return
true
;
}
void
PerSyst
DB
::
getNewDates
(
const
std
::
string
&
last_end_timestamp
,
std
::
string
&
begin_timestamp
,
std
::
string
&
end_timestamp
){
void
Maria
DB
::
getNewDates
(
const
std
::
string
&
last_end_timestamp
,
std
::
string
&
begin_timestamp
,
std
::
string
&
end_timestamp
){
begin_timestamp
=
last_end_timestamp
;
std
::
tm
tm
=
{
};
...
...
analytics/operators/persystsql/
PerSyst
DB.h
→
analytics/operators/persystsql/
Maria
DB.h
View file @
53c3e429
//================================================================================
// Name :
PerSyst
DB.h
// Name :
Maria
DB.h
// Author : Carla Guillen
// Contact : info@dcdb.it
// Copyright : Leibniz Supercomputing Centre
...
...
@@ -25,8 +25,8 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//================================================================================
#ifndef ANALYTICS_OPERATORS_PERSYSTSQL_
PERSYST
DB_H_
#define ANALYTICS_OPERATORS_PERSYSTSQL_
PERSYST
DB_H_
#ifndef ANALYTICS_OPERATORS_PERSYSTSQL_
MARIA
DB_H_
#define ANALYTICS_OPERATORS_PERSYSTSQL_
MARIA
DB_H_
#include
"mariadb/mysql.h"
#include
"../../../common/include/logging.h"
...
...
@@ -45,7 +45,7 @@ struct Aggregate_info_t {
float
severity_average
;
};
class
PerSyst
DB
{
class
Maria
DB
{
private:
struct
Job_info_t
{
...
...
@@ -60,8 +60,8 @@ public:
protected:
PerSyst
DB
();
virtual
~
PerSyst
DB
();
Maria
DB
();
virtual
~
Maria
DB
();
MYSQL
*
_mysql
;
Rotation_t
_rotation
;
...
...
@@ -70,7 +70,7 @@ protected:
std
::
string
_current_table_suffix
;
boost
::
log
::
sources
::
severity_logger
<
boost
::
log
::
trivial
::
severity_level
>
lg
;
static
PerSyst
DB
*
instance
;
static
Maria
DB
*
instance
;
static
std
::
mutex
mut
;
bool
_initialized
;
std
::
map
<
std
::
string
,
Job_info_t
>
_jobCache
;
...
...
@@ -133,9 +133,9 @@ public:
/**
* Singleton object. Get here your instance!
*/
static
PerSyst
DB
*
getInstance
();
static
Maria
DB
*
getInstance
();
};
#endif
/* ANALYTICS_OPERATORS_PERSYSTSQL_
PERSYST
DB_H_ */
#endif
/* ANALYTICS_OPERATORS_PERSYSTSQL_
MARIA
DB_H_ */
analytics/operators/persystsql/PerSystSqlConfigurator.cpp
View file @
53c3e429
...
...
@@ -40,9 +40,9 @@
PerSystSqlConfigurator
::
PerSystSqlConfigurator
()
:
JobOperatorConfiguratorTemplate
()
{
_operatorName
=
"persystsql"
;
_baseName
=
"sensor"
;
_rotation_map
[
"EVERY_YEAR"
]
=
PerSyst
DB
::
EVERY_YEAR
;
_rotation_map
[
"EVERY_MONTH"
]
=
PerSyst
DB
::
EVERY_MONTH
;
_rotation_map
[
"EVERY_XDAYS"
]
=
PerSyst
DB
::
EVERY_XDAYS
;
_rotation_map
[
"EVERY_YEAR"
]
=
Maria
DB
::
EVERY_YEAR
;
_rotation_map
[
"EVERY_MONTH"
]
=
Maria
DB
::
EVERY_MONTH
;
_rotation_map
[
"EVERY_XDAYS"
]
=
Maria
DB
::
EVERY_XDAYS
;
}
PerSystSqlConfigurator
::~
PerSystSqlConfigurator
()
{
...
...
@@ -74,7 +74,7 @@ void PerSystSqlConfigurator::operatorAttributes(PerSystSqlOperator& op, CFG_VAL
std
::
string
password
;
std
::
string
database_name
;
int
port
=
-
1
;
PerSyst
DB
::
Rotation_t
rotation
=
PerSyst
DB
::
EVERY_MONTH
;
Maria
DB
::
Rotation_t
rotation
=
Maria
DB
::
EVERY_MONTH
;
PerSystSqlOperator
::
Backend_t
backend
=
PerSystSqlOperator
::
DEFAULT
;
unsigned
int
every_x_days
=
0
;
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
config
)
{
...
...
analytics/operators/persystsql/PerSystSqlConfigurator.h
View file @
53c3e429
...
...
@@ -40,7 +40,7 @@ public:
PerSystSqlConfigurator
();
virtual
~
PerSystSqlConfigurator
();
private:
std
::
map
<
std
::
string
,
PerSyst
DB
::
Rotation_t
>
_rotation_map
;
std
::
map
<
std
::
string
,
Maria
DB
::
Rotation_t
>
_rotation_map
;
void
sensorBase
(
AggregatorSensorBase
&
s
,
CFG_VAL
config
)
override
;
void
operatorAttributes
(
PerSystSqlOperator
&
op
,
CFG_VAL
config
)
override
;
bool
unit
(
UnitTemplate
<
AggregatorSensorBase
>&
u
)
override
;
...
...
analytics/operators/persystsql/PerSystSqlOperator.cpp
View file @
53c3e429
...
...
@@ -52,7 +52,7 @@ PerSystSqlOperator::PerSystSqlOperator(const std::string& name) :
0
),
_severity_formula
(
NOFORMULA
),
_severity_threshold
(
0
),
_severity_exponent
(
0
),
_severity_max_memory
(
0
),
_go_back_ns
(
0
),
_backend
(
DEFAULT
),
_scaling_factor
(
1
),
_property_id
(
0
)
{
_persystdb
=
PerSyst
DB
::
getInstance
();
_persystdb
=
Maria
DB
::
getInstance
();
}
PerSystSqlOperator
::~
PerSystSqlOperator
()
{
...
...
analytics/operators/persystsql/PerSystSqlOperator.h
View file @
53c3e429
...
...
@@ -36,7 +36,7 @@
#include
"../../../common/include/logging.h"
#include
"../../includes/JobOperatorTemplate.h"
#include
"../aggregator/AggregatorSensorBase.h"
#include
"
PerSyst
DB.h"
#include
"
Maria
DB.h"
class
PerSystSqlOperator
:
public
JobOperatorTemplate
<
AggregatorSensorBase
>
{
...
...
@@ -101,7 +101,7 @@ public:
_backend
=
backend
;
}
void
setMariaDBConnection
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
const
std
::
string
&
password
,
const
std
::
string
&
database_name
,
int
port
,
PerSyst
DB
::
Rotation_t
rotation
,
unsigned
int
every_x_days
=
0
){
void
setMariaDBConnection
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
const
std
::
string
&
password
,
const
std
::
string
&
database_name
,
int
port
,
Maria
DB
::
Rotation_t
rotation
,
unsigned
int
every_x_days
=
0
){
_conn
.
host
=
host
;
_conn
.
user
=
user
;
_conn
.
password
=
password
;
...
...
@@ -134,13 +134,13 @@ private:
std
::
string
password
;
std
::
string
database_name
;
int
port
;
PerSyst
DB
::
Rotation_t
rotation
;
Maria
DB
::
Rotation_t
rotation
;
unsigned
int
every_x_days
;
};
MariaDB_conn_t
_conn
;
int
_property_id
;
PerSyst
DB
*
_persystdb
;
Maria
DB
*
_persystdb
;
const
int
SCALING_FACTOR_SEVERITY
=
1000000
;
protected:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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