configuration.cpp 5.39 KB
Newer Older
1
2
3
//================================================================================
// Name        : configuration.cpp
// 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

#include "configuration.h"

Alessio Netti's avatar
Alessio Netti committed
30
31
32
bool Configuration::readAdditionalValues(boost::property_tree::iptree::value_type &global) {
    // ----- READING ADDITIONAL GLOBAL SETTINGS -----
    if (boost::iequals(global.first, "mqttListenAddress")) {
Alessio Netti's avatar
Alessio Netti committed
33
34
        mqttListenHost = parseNetworkHost(global.second.data());
        mqttListenPort = parseNetworkPort(global.second.data());
35
        if(mqttListenPort=="") mqttListenPort = string(DEFAULT_LISTENPORT);
Alessio Netti's avatar
Alessio Netti committed
36
37
38
39
40
41
42
    } else if (boost::iequals(global.first, "cleaningInterval")) {
        cleaningInterval = stoul(global.second.data());
    } else if (boost::iequals(global.first, "messageThreads")) {
        messageThreads = stoul(global.second.data());
    } else if (boost::iequals(global.first, "messageSlots")) {
        messageSlots = stoul(global.second.data());
    } else {
43
44
        return false;
    }
Alessio Netti's avatar
Alessio Netti committed
45
46
    return true;
}
47

Alessio Netti's avatar
Alessio Netti committed
48
49
50
51
52
void Configuration::readAdditionalBlocks(boost::property_tree::iptree& cfg) {
    // ----- READING CASSANDRA SETTINGS -----
    if(cfg.find("cassandra") != cfg.not_found()) {
        BOOST_FOREACH(boost::property_tree::iptree::value_type & global, cfg.get_child("cassandra")) {
            if (boost::iequals(global.first, "address")) {
Alessio Netti's avatar
Alessio Netti committed
53
54
                cassandraSettings.host = parseNetworkHost(global.second.data());
                cassandraSettings.port = parseNetworkPort(global.second.data());
55
                if(cassandraSettings.port=="") cassandraSettings.port = string(DEFAULT_CASSANDRAPORT);
Alessio Netti's avatar
Alessio Netti committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
            } else if (boost::iequals(global.first, "username")) {
                cassandraSettings.username = global.second.data();
            } else if (boost::iequals(global.first, "password")) {
                cassandraSettings.password = global.second.data();
            } else if (boost::iequals(global.first, "ttl")) {
                cassandraSettings.ttl = stoul(global.second.data());
            } else if (boost::iequals(global.first, "numThreadsIo")) {
                cassandraSettings.numThreadsIo = stoul(global.second.data());
            } else if (boost::iequals(global.first, "queueSizeIo")) {
                cassandraSettings.queueSizeIo = stoul(global.second.data());
            } else if (boost::iequals(global.first, "coreConnPerHost")) {
                cassandraSettings.coreConnPerHost = stoul(global.second.data());
            } else if (boost::iequals(global.first, "debugLog")) {
                cassandraSettings.debugLog = to_bool(global.second.data());
            } else {
                LOG(warning) << "  Value \"" << global.first << "\" not recognized. Omitting";
72
            }
73
74
75
        }
    }
}
Alessio Netti's avatar
Alessio Netti committed
76

77
DCDB::PublicSensor Configuration::metadataToPublicSensor(const SensorMetadata& sm) {
Alessio Netti's avatar
Alessio Netti committed
78
    DCDB::PublicSensor ps;
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    if(sm.getPublicName())
        ps.name = *sm.getPublicName();
    if(sm.getIsVirtual())
        ps.is_virtual = *sm.getIsVirtual();
    if(sm.getPattern())
        ps.pattern = *sm.getPattern();
    if(sm.getUnit())
        ps.unit = *sm.getUnit();
    if(sm.getScale())
        ps.scaling_factor = *sm.getScale();
    if(sm.getTTL())
        ps.ttl = *sm.getTTL();
    if(sm.getInterval())
        ps.interval = *sm.getInterval();
    if(sm.getOperations())
        ps.operations = *sm.getOperations();
Alessio Netti's avatar
Alessio Netti committed
95
    uint64_t sensorMask = 0;
96
    if(sm.getIntegrable() && *sm.getIntegrable())
Alessio Netti's avatar
Alessio Netti committed
97
        sensorMask = sensorMask | INTEGRABLE;
98
    if(sm.getMonotonic() && *sm.getMonotonic())
Alessio Netti's avatar
Alessio Netti committed
99
        sensorMask = sensorMask | MONOTONIC;
100
    ps.sensor_mask = sensorMask;
Alessio Netti's avatar
Alessio Netti committed
101
102
    return ps;
}
103
104
105

SensorMetadata Configuration::publicSensorToMetadata(const DCDB::PublicSensor& ps) {
    SensorMetadata sm;
106
107
    sm.setPublicName(ps.name);
    sm.setIsVirtual(ps.is_virtual);
108
109
    
    // Stripping whitespace from the sensor pattern in the SID
110
111
112
    string stripPattern = ps.pattern;
    boost::algorithm::trim(stripPattern);
    sm.setPattern(stripPattern);
113
    
114
115
116
117
118
119
120
    sm.setUnit(ps.unit);
    sm.setScale(ps.scaling_factor);
    sm.setTTL(ps.ttl);
    sm.setInterval(ps.interval);
    sm.setOperations(ps.operations);
    sm.setIntegrable(ps.sensor_mask & INTEGRABLE);
    sm.setMonotonic(ps.sensor_mask & MONOTONIC);
121
122
    return sm;
}