configuration.h 3.94 KB
Newer Older
1
2
3
//================================================================================
// Name        : configuration.h
// Author      : Alessio Netti
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
5
6
7
8
9
10
11
12
13
14
15
16
// Copyright   : Leibniz Supercomputing Centre
// Description : Class responsible for reading collectagent specific configuration.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2018-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
17
//
18
19
20
21
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
22
//
23
24
25
26
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================
27
28
29
30
31
32

#ifndef CONFIGURATION_H_
#define CONFIGURATION_H_

#include <string>
#include <unistd.h>
33
#include <boost/algorithm/string/trim.hpp>
34
35
#include <boost/regex.hpp>

36

Alessio Netti's avatar
Logging    
Alessio Netti committed
37
#include "logging.h"
Alessio Netti's avatar
Alessio Netti committed
38
#include "globalconfiguration.h"
Alessio Netti's avatar
Alessio Netti committed
39
40
#include "metadatastore.h"
#include <dcdb/sensorconfig.h>
41

42
43
44
45
#define DEFAULT_LISTENHOST "localhost"
#define DEFAULT_LISTENPORT "1883"
#define DEFAULT_RESTAPIHOST "0.0.0.0"
#define DEFAULT_RESTAPIPORT "8080"
46

Alessio Netti's avatar
Alessio Netti committed
47
using namespace std;
48

49
50
51
52
53
/**
 * Wrapper class for Cassandra-specific settings
 *
 * @ingroup ca
 */
Alessio Netti's avatar
Alessio Netti committed
54
55
56
class cassandra_t {
public:
    cassandra_t() {}
57
58
    std::string host = string(DEFAULT_CASSANDRAHOST);
    std::string port = string(DEFAULT_CASSANDRAPORT);
Alessio Netti's avatar
Alessio Netti committed
59
60
    std::string username = "";
    std::string password = "";
61
    uint32_t ttl = DEFAULT_CASSANDRATTL;
Alessio Netti's avatar
Alessio Netti committed
62
63
64
65
66
    uint32_t numThreadsIo = 1;
    uint32_t queueSizeIo = 4096;
    uint32_t coreConnPerHost = 1;
    bool debugLog = false;
};
67

68
class influx_measurement_t {
69
public:
70
71
    influx_measurement_t() {}
    std::string           mqttPart;
72
73
74
    std::string           tag;
    boost::regex          tagRegex;
    std::string           tagSubstitution;
75
76
77
    std::set<std::string> fields;
};

78
79
80
81
82
83
84
85

class influx_t {
public:
    influx_t() {}
    std::string           mqttPrefix;
    std::map<std::string, influx_measurement_t> measurements;
};

86
/**
87
88
89
 * @brief Class responsible for reading collect agent specific configuration.
 *
 * @ingroup ca
90
 */
Alessio Netti's avatar
Alessio Netti committed
91
class Configuration : public GlobalConfiguration {
92
93

public:
Alessio Netti's avatar
Alessio Netti committed
94
    
95
    /**
Alessio Netti's avatar
Alessio Netti committed
96
     * @brief               Create new Configuration. Sets global config file to read from to cfgFile.
Alessio Netti's avatar
Alessio Netti committed
97
     * 
98
     * @param cfgFilePath	Path to where all config-files are located
Alessio Netti's avatar
Alessio Netti committed
99
     * @param cfgFileName   Name of the file containing the config
100
     */
Alessio Netti's avatar
Alessio Netti committed
101
    Configuration(const std::string& cfgFilePath, const std::string& cfgFileName) : GlobalConfiguration(cfgFilePath, cfgFileName) {
102
103
        restAPISettings.port = string(DEFAULT_RESTAPIPORT);
        restAPISettings.host = string(DEFAULT_RESTAPIHOST);
Alessio Netti's avatar
Alessio Netti committed
104
105
106
107
108
109
    }
    Configuration() {}
    
    virtual ~Configuration() {}
    
    // Additional configuration parameters to be parsed within the global block
110
111
    std::string mqttListenHost = string(DEFAULT_LISTENHOST);
    std::string mqttListenPort = string(DEFAULT_LISTENPORT);
Alessio Netti's avatar
Alessio Netti committed
112
113
114
115
    uint64_t cleaningInterval = 86400;
    uint64_t messageThreads = 128;
    uint64_t messageSlots = 16;
    cassandra_t cassandraSettings;
116
    influx_t influxSettings;
Alessio Netti's avatar
Alessio Netti committed
117
118
119
120
    
protected:
    void readAdditionalBlocks(boost::property_tree::iptree& cfg) override;
    bool readAdditionalValues(boost::property_tree::iptree::value_type &global) override;
121
122
123
124
};

#endif /* CONFIGURATION_H_ */