query.h 3.28 KB
Newer Older
Axel Auweter's avatar
Axel Auweter committed
1
2
//================================================================================
// Name        : query.h
3
// Author      : Axel Auweter, Daniele Tafani
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
Axel Auweter's avatar
Axel Auweter committed
5
6
7
8
9
10
// Copyright   : Leibniz Supercomputing Centre
// Description : Header of query class of dcdbquery
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
11
// Copyright (C) 2011-2019 Leibniz Supercomputing Centre
Axel Auweter's avatar
Axel Auweter committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
// 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.
//================================================================================

Axel Auweter's avatar
Axel Auweter committed
28
29
30

#include <list>
#include <string>
31
#include <map>
Axel Auweter's avatar
Axel Auweter committed
32

Axel Auweter's avatar
Axel Auweter committed
33
#include "dcdb/connection.h"
Axel Auweter's avatar
Axel Auweter committed
34
#include "dcdb/timestamp.h"
Axel Auweter's avatar
Axel Auweter committed
35
#include "dcdb/sensorid.h"
Axel Auweter's avatar
Axel Auweter committed
36
#include "dcdb/sensordatastore.h"
Axel Auweter's avatar
Axel Auweter committed
37
#include "dcdb/sensorconfig.h"
Axel Auweter's avatar
Axel Auweter committed
38
#include "dcdb/unitconv.h"
39
#include "dcdb/virtualsensor.h"
40
#include "dcdb/sensor.h"
Axel Auweter's avatar
Axel Auweter committed
41
42
43
44
45
46

#ifndef QUERY_H
#define QUERY_H

class DCDBQuery
{
47

48
49
50
51
52
53
typedef enum {
    DCDB_OP_NONE,
    DCDB_OP_DELTA,
    DCDB_OP_DELTAT,
    DCDB_OP_DERIVATIVE,
    DCDB_OP_INTEGRAL,
54
    DCDB_OP_RATE,
55
    DCDB_OP_WINTERMUTE,
56
57
58
59
    DCDB_OP_UNKNOWN,
} DCDB_OP_TYPE;
    
typedef struct queryConfig {
60
    double scalingFactor;
61
62
    DCDB::Unit unit;
    DCDB_OP_TYPE operation;
63
    DCDB::QueryAggregate aggregate;
64
    std::string wintermuteOp;
65
} queryConfig_t;
66
typedef std::multimap<DCDB::PublicSensor, queryConfig_t> queryMap_t;
67
68
69
70
71
72

typedef enum {
    CONVERT_OK,
    CONVERT_ERR,
} CONVERT_RESULT;
    
73
74
75
76
77
78
79
80
81
private:
    void genOutput(std::list<DCDB::SensorDataStoreReading> &results, queryMap_t::iterator start, queryMap_t::iterator stop);
    void setInterval(DCDB::TimeStamp start, DCDB::TimeStamp end);
    void parseSensorSpecification(const std::string sensor, std::string& sensorName, queryConfig_t& queryCfg);
    void prepareQuery(std::list<std::string> sensors);
    void prepareQuery(std::list<std::string> sensors, std::list<std::string> prefixes);
    void execute();


82
  DCDB::Connection* connection;
Axel Auweter's avatar
Axel Auweter committed
83
84
85
  bool useLocalTime;
  bool useRawOutput;

86
    queryMap_t queries;
87
88
    double baseScalingFactor;
    DCDB::Unit baseUnit;
89
90
    DCDB::TimeStamp start_ts;
    DCDB::TimeStamp end_ts;
91

Axel Auweter's avatar
Axel Auweter committed
92
public:
Axel Auweter's avatar
Axel Auweter committed
93
94
95
96
  void setLocalTimeEnabled(bool enable);
  bool getLocalTimeEnabled();
  void setRawOutputEnabled(bool enable);
  bool getRawOutputEnabled();
97

98
99
100
101
  int connect(const char* hostname);
  void disconnect();
  void doQuery(std::list<std::string> sensors, DCDB::TimeStamp start, DCDB::TimeStamp end);
  void dojobQuery(std::list<std::string> sensors, std::string jobId);
102

Axel Auweter's avatar
Axel Auweter committed
103

Axel Auweter's avatar
Axel Auweter committed
104
  DCDBQuery();
Axel Auweter's avatar
Axel Auweter committed
105
  virtual ~DCDBQuery() {};
Axel Auweter's avatar
Axel Auweter committed
106
107
108
109
110

};


#endif /* QUERY_H */