Commit 53c3e429 authored by Carla Guillen Carias's avatar Carla Guillen Carias
Browse files

Renaming...

parent 595348fb
//================================================================================
// Name : PerSystDB.cpp
// Name : MariaDB.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 * PerSystDB::instance = nullptr;
std::mutex PerSystDB::mut;
MariaDB * MariaDB::instance = nullptr;
std::mutex MariaDB::mut;
void PerSystDB::print_error(){
void MariaDB::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::PerSystDB(): _mysql(NULL), _rotation(EVERY_MONTH), _every_x_days(0), _end_aggregate_timestamp(0), _initialized(false) {
MariaDB::MariaDB(): _mysql(NULL), _rotation(EVERY_MONTH), _every_x_days(0), _end_aggregate_timestamp(0), _initialized(false) {
}
PerSystDB * PerSystDB::getInstance(){
MariaDB * MariaDB::getInstance(){
// no lock here
if (instance) return instance;
std::lock_guard<std::mutex> lock(mut);
if (instance) return instance;
return instance = new PerSystDB();
return instance = new MariaDB();
}
bool PerSystDB::initializeConnection(const std::string & host, const std::string & user,
bool MariaDB::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 PerSystDB::finalizeConnection(){
bool MariaDB::finalizeConnection(){
std::lock_guard<std::mutex> lock(mut);
if(_initialized){
mysql_close(_mysql);
......@@ -115,11 +113,11 @@ bool PerSystDB::finalizeConnection(){
}
PerSystDB::~PerSystDB(){
MariaDB::~MariaDB(){
}
bool PerSystDB::getDBJobIDs(std::vector<std::string> & job_id_strings, std::map<std::string, std::string>& job_id_map) {
bool MariaDB::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 PerSystDB::addJobToCache(std::string &job_id_string, std::string & job_id_db){
void MariaDB::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, PerSystDB::Job_info_t>;
using MyPairType = std::pair<std::string, MariaDB::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 PerSystDB::getCurrentSuffixAggregateTable(std::string & suffix){
bool MariaDB::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 PerSystDB::insertIntoJob(const std::string& job_id_string, const std::string& uid, int & job_id_db, const std::string & suffix){
bool MariaDB::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 PerSystDB::insertInAggregateTable(const std::string& suffix, Aggregate_info_t & agg){
bool MariaDB::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 PerSystDB::createNewAggregate(std::string& new_suffix){
bool MariaDB::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 PerSystDB::updateJobsLastSuffix(std::map<std::string, std::string>& job_map, std::string & suffix){
bool MariaDB::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 PerSystDB::getTableSuffix(std::string & table_suffix){
bool MariaDB::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 PerSystDB::getNewDates(const std::string& last_end_timestamp, std::string & begin_timestamp, std::string & end_timestamp){
void MariaDB::getNewDates(const std::string& last_end_timestamp, std::string & begin_timestamp, std::string & end_timestamp){
begin_timestamp = last_end_timestamp;
std::tm tm = { };
......
//================================================================================
// Name : PerSystDB.h
// Name : MariaDB.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_PERSYSTDB_H_
#define ANALYTICS_OPERATORS_PERSYSTSQL_PERSYSTDB_H_
#ifndef ANALYTICS_OPERATORS_PERSYSTSQL_MARIADB_H_
#define ANALYTICS_OPERATORS_PERSYSTSQL_MARIADB_H_
#include "mariadb/mysql.h"
#include "../../../common/include/logging.h"
......@@ -45,7 +45,7 @@ struct Aggregate_info_t {
float severity_average;
};
class PerSystDB {
class MariaDB {
private:
struct Job_info_t {
......@@ -60,8 +60,8 @@ public:
protected:
PerSystDB();
virtual ~PerSystDB();
MariaDB();
virtual ~MariaDB();
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 PerSystDB * instance;
static MariaDB * 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 PerSystDB * getInstance();
static MariaDB * getInstance();
};
#endif /* ANALYTICS_OPERATORS_PERSYSTSQL_PERSYSTDB_H_ */
#endif /* ANALYTICS_OPERATORS_PERSYSTSQL_MARIADB_H_ */
......@@ -40,9 +40,9 @@
PerSystSqlConfigurator::PerSystSqlConfigurator(): JobOperatorConfiguratorTemplate() {
_operatorName = "persystsql";
_baseName = "sensor";
_rotation_map["EVERY_YEAR"] = PerSystDB::EVERY_YEAR;
_rotation_map["EVERY_MONTH"] = PerSystDB::EVERY_MONTH;
_rotation_map["EVERY_XDAYS"] = PerSystDB::EVERY_XDAYS;
_rotation_map["EVERY_YEAR"] = MariaDB::EVERY_YEAR;
_rotation_map["EVERY_MONTH"] = MariaDB::EVERY_MONTH;
_rotation_map["EVERY_XDAYS"] = MariaDB::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;
PerSystDB::Rotation_t rotation = PerSystDB::EVERY_MONTH;
MariaDB::Rotation_t rotation = MariaDB::EVERY_MONTH;
PerSystSqlOperator::Backend_t backend = PerSystSqlOperator::DEFAULT;
unsigned int every_x_days = 0;
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
......
......@@ -40,7 +40,7 @@ public:
PerSystSqlConfigurator();
virtual ~PerSystSqlConfigurator();
private:
std::map<std::string, PerSystDB::Rotation_t> _rotation_map;
std::map<std::string, MariaDB::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;
......
......@@ -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 = PerSystDB::getInstance();
_persystdb = MariaDB::getInstance();
}
PerSystSqlOperator::~PerSystSqlOperator() {
......
......@@ -36,7 +36,7 @@
#include "../../../common/include/logging.h"
#include "../../includes/JobOperatorTemplate.h"
#include "../aggregator/AggregatorSensorBase.h"
#include "PerSystDB.h"
#include "MariaDB.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, PerSystDB::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, MariaDB::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;
PerSystDB::Rotation_t rotation;
MariaDB::Rotation_t rotation;
unsigned int every_x_days;
};
MariaDB_conn_t _conn;
int _property_id;
PerSystDB *_persystdb;
MariaDB *_persystdb;
const int SCALING_FACTOR_SEVERITY=1000000;
protected:
......
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