PerSystSqlConfigurator.cpp 6.35 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
    BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config)
    {
            if (boost::iequals(val.first, "operation")) {
                    std::string opName = val.second.data();
54
                    if (opName == "average"){
55
                            s.setOperation(AggregatorSensorBase::AVG);
56
                    } else if (opName == "deciles" || opName == "percentiles" || opName == "quantile"){
57
                            s.setOperation(AggregatorSensorBase::QTL);
58
                    } else if (opName == "observations" || opName == "numobs") {
59
                            s.setOperation(AggregatorSensorBase::OBS);
60
61
62
63
64
                    } else if (opName == "average_severity"){
                    	    s.setOperation(AggregatorSensorBase::AVG_SEV);
		    } else {
			LOG(error) << "PerSystSqlConfigurator operation " << opName << " not supported!" ; 
			}	
65
66
67
68
            }
    }
}

69
void PerSystSqlConfigurator::operatorAttributes(PerSystSqlOperator& op, CFG_VAL config) {
70
71
72
73
	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
74
75
76
77
		} 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")){
78
			double threshold = std::stod(val.second.data());
79
80
			op.setSeverityThreshold(threshold);
		} else if (boost::iequals(val.first, "severity_exponent")){
81
82
			double exponent =  std::stod(val.second.data());
			op.setSeverityExponent(exponent);
83
84
85
86
87
88
89
90
91
92
93
94
95
96
		} 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);
97
98
99
100
101
102
103
104
105
		} 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);
Carla Guillen's avatar
Carla Guillen committed
106
107
108
109
    		} else if(boost::iequals(val.first, "property_id")){
			auto property_id = std::stoi(val.second.data());
			op.setPropertyId(property_id);
		}
110
111
112
	}
}

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

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

131
132

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

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

157
	return JobOperatorConfiguratorTemplate::readUnits(op, protoInputs, protoOutputs, protoGlobalOutputs, inputMode);
158
}