PerSystSqlConfigurator.cpp 4.68 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
79
80
81
82
	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);
		}
	}
}

83
bool PerSystSqlConfigurator::unit(UnitTemplate<AggregatorSensorBase>& u) {
84
85
86
	return true;
}

87
bool PerSystSqlConfigurator::readUnits(PerSystSqlOperator& op,
88
89
		std::vector<shared_ptr<AggregatorSensorBase>>& protoInputs,
		std::vector<shared_ptr<AggregatorSensorBase>>& protoOutputs, inputMode_t inputMode) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
90

91
92

	int num_quantiles = op.getNumberOfEvenQuantiles();
93
	if(num_quantiles == 0){
Carla Guillen Carias's avatar
Carla Guillen Carias committed
94
95
		return false;
	}
96
	bool quantile_found = false;
Carla Guillen's avatar
Carla Guillen committed
97
	AggregatorSensorBase quantsensor("");
Carla Guillen Carias's avatar
Carla Guillen Carias committed
98
99
	for(auto &sensor: protoOutputs){
		if(sensor->getOperation() == AggregatorSensorBase::QTL){
100
			quantile_found = true;
Carla Guillen Carias's avatar
Carla Guillen Carias committed
101
102
103
104
105
106
			quantsensor = *(sensor.get());
			sensor->setPercentile(0);
			auto topic = sensor->getMqtt();
			sensor->setMqtt(topic + "0");
			break;
		}
107
	}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
108

109
	for(int i = 1; i <= num_quantiles && quantile_found; ++i){
Carla Guillen Carias's avatar
Carla Guillen Carias committed
110
111
		auto outputSensor = std::make_shared<AggregatorSensorBase>(quantsensor);
		outputSensor->setMqtt(outputSensor->getMqtt() + std::to_string(i));
112
113
114
115
116
		outputSensor->setOperation(AggregatorSensorBase::QTL);
		outputSensor->setPercentile(i);
		protoOutputs.push_back(outputSensor);
	}

Carla Guillen Carias's avatar
Carla Guillen Carias committed
117
	return JobOperatorConfiguratorTemplate::readUnits(op, protoInputs, protoOutputs, inputMode);
118
}