PerSystSqlConfigurator.cpp 6.53 KB
Newer Older
1
//================================================================================
2
// Name        : PerSystSqlConfigurator.cpp
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Author      : Carla Guillen
// Contact     : info@dcdb.it
// Copyright   : Leibniz Supercomputing Centre
// Description : Template implementing features to use Units in Operators.
//================================================================================

//================================================================================
// 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.
//
// 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.
//
// 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.
//================================================================================

28
29
#include "PerSystSqlConfigurator.h"

30
31
32
33
34
35
36
37
38
39
#include <boost/algorithm/string/predicate.hpp>
#include <boost/foreach.hpp>
#include <boost/property_tree/detail/ptree_implementation.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#include <string>
#include <vector>

#include "../../includes/OperatorConfiguratorTemplate.h"
#include "../../includes/UnitInterface.h"

40
PerSystSqlConfigurator::PerSystSqlConfigurator(): JobOperatorConfiguratorTemplate() {
41
42
43
44
45
	 _operatorName = "persystsql";
	 _baseName     = "sensor";

}

46
PerSystSqlConfigurator::~PerSystSqlConfigurator() {
47
48
}

49
void PerSystSqlConfigurator::sensorBase(AggregatorSensorBase& s, CFG_VAL config) {
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config)
    {
            if (boost::iequals(val.first, "operation")) {
                    std::string opName = val.second.data();
                    if (opName == "sum")
                            s.setOperation(AggregatorSensorBase::SUM);
                    else if (opName == "average")
                            s.setOperation(AggregatorSensorBase::AVG);
                    else if (opName == "maximum")
                            s.setOperation(AggregatorSensorBase::MAX);
                    else if (opName == "minimum")
                            s.setOperation(AggregatorSensorBase::MIN);
                    else if (opName == "std")
                            s.setOperation(AggregatorSensorBase::STD);
64
                    else if (opName == "deciles" || opName == "percentiles" || opName == "quantile")
65
66
67
                            s.setOperation(AggregatorSensorBase::QTL);
                    else if (opName == "observations")
                            s.setOperation(AggregatorSensorBase::OBS);
Carla Guillen Carias's avatar
Carla Guillen Carias committed
68
69
                    else if (opName == "average_severity")
                    		s.setOperation(AggregatorSensorBase::AVG_SEV);
70
71
72
73
            }
    }
}

74
void PerSystSqlConfigurator::operatorAttributes(PerSystSqlOperator& op, CFG_VAL config) {
75
76
77
78
	BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
		if (boost::iequals(val.first, "number_quantiles")) {
			unsigned int num_quantiles = std::stoul(val.second.data());
			op.setNumberOfEvenQuantiles(num_quantiles);
Carla Guillen's avatar
Carla Guillen committed
79
80
81
82
83
		} else if (boost::iequals(val.first, "go_back_ms")) {
			auto go_back_ms = std::stoi(val.second.data());
			op.setGoBackInMs(go_back_ms);
		} else if (boost::iequals(val.first, "severity_threshold")){
			auto threshold = std::stod(val.second.data());
84
85
			op.setSeverityThreshold(threshold);
		} else if (boost::iequals(val.first, "severity_exponent")){
Carla Guillen's avatar
Carla Guillen committed
86
			auto exponent =  std::stod(val.second.data());
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
			op.setSeverityThreshold(exponent);
		} else if (boost::iequals(val.first, "severity_formula")){
			std::string formula = val.second.data();
			if(formula == "formula1"){
				op.setSeverityFormula(PerSystSqlOperator::FORMULA1);
			} else if (formula == "formula2") {
				op.setSeverityFormula(PerSystSqlOperator::FORMULA2);
			} else if (formula == "formula3") {
				op.setSeverityFormula(PerSystSqlOperator::FORMULA3);
			} else if (formula == "memory_formula"){
				op.setSeverityFormula(PerSystSqlOperator::MEMORY_FORMULA);
			}
		} else if (boost::iequals(val.first, "severity_max_memory")){
			auto max_memory =  std::stof(val.second.data());
			op.setSeverityMaxMemory(max_memory);
102
103
104
105
106
107
108
109
110
111
		} else if (boost::iequals(val.first, "backend")) {
			if(val.second.data() == "cassandra") {
				op.setBackend(PerSystSqlOperator::CASSANDRA);
			} else if(val.second.data() == "mariadb") {
				op.setBackend(PerSystSqlOperator::MARIADB);
			}
		} else if(boost::iequals(val.first, "scaling_factor")){
			auto scaling_factor = std::stoull(val.second.data());
			op.setScalingFactor(scaling_factor);
    	}
112
113
114
	}
}

115
bool PerSystSqlConfigurator::unit(UnitTemplate<AggregatorSensorBase>& u) {
116
	if(!u.isTopUnit()) {
117
		LOG(error) << "    " << _operatorName << ": This operator type only supports hierarchical units!";
118
119
120
		return false;
	}
	if(u.getOutputs().empty()) {
121
		LOG(error) << "    " << _operatorName << ": At least one output sensor per unit must be defined!";
122
123
		return false;
	}
124
125
126
	return true;
}

127
bool PerSystSqlConfigurator::readUnits(PerSystSqlOperator& op,
128
		std::vector<shared_ptr<AggregatorSensorBase>>& protoInputs,
129
130
131
		std::vector<shared_ptr<AggregatorSensorBase>>& protoOutputs,
	    std::vector<shared_ptr<AggregatorSensorBase>>& protoGlobalOutputs,
	    inputMode_t inputMode) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
132

133
134

	int num_quantiles = op.getNumberOfEvenQuantiles();
135
	if(num_quantiles == 0){
Carla Guillen Carias's avatar
Carla Guillen Carias committed
136
137
		return false;
	}
138
	bool quantile_found = false;
Carla Guillen's avatar
Carla Guillen committed
139
	AggregatorSensorBase quantsensor("");
140
	for(auto &sensor: protoGlobalOutputs) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
141
		if(sensor->getOperation() == AggregatorSensorBase::QTL){
142
			quantile_found = true;
Carla Guillen Carias's avatar
Carla Guillen Carias committed
143
144
145
146
147
148
			quantsensor = *(sensor.get());
			sensor->setPercentile(0);
			auto topic = sensor->getMqtt();
			sensor->setMqtt(topic + "0");
			break;
		}
149
	}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
150

151
	for(int i = 1; i <= num_quantiles && quantile_found; ++i) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
152
153
		auto outputSensor = std::make_shared<AggregatorSensorBase>(quantsensor);
		outputSensor->setMqtt(outputSensor->getMqtt() + std::to_string(i));
154
155
		outputSensor->setOperation(AggregatorSensorBase::QTL);
		outputSensor->setPercentile(i);
156
		protoGlobalOutputs.push_back(outputSensor);
157
158
	}

159
	return JobOperatorConfiguratorTemplate::readUnits(op, protoInputs, protoOutputs, protoGlobalOutputs, inputMode);
160
}