2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

sensorconfig_internal.h 4.48 KB
Newer Older
1
2
//================================================================================
// Name        : sensorconfig_internal.h
3
// Author      : Axel Auweter, Daniele Tafani
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
5
// Copyright   : Leibniz Supercomputing Centre
Michael Ott's avatar
Michael Ott committed
6
// Description : Internal Interface for configuring libdcdb public sensors.
7
8
9
10
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
11
// Copyright (C) 2011-2019 Leibniz Supercomputing Centre
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; 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
27
28

#include <list>
Axel Auweter's avatar
Axel Auweter committed
29
#include <string>
30
#include <unordered_map>
31
#include <functional>
32
33
#include <unistd.h>
#include <sys/stat.h>
Axel Auweter's avatar
Axel Auweter committed
34
35

#include "cassandra.h"
Axel Auweter's avatar
Axel Auweter committed
36

37
38
39
#include "dcdb/connection.h"
#include "dcdb/timestamp.h"
#include "dcdb/sensorid.h"
Axel Auweter's avatar
Axel Auweter committed
40

41
#include "dcdb/sensorconfig.h"
42
#include "dcdb/libconfig.h"
Axel Auweter's avatar
Axel Auweter committed
43

44
45
46
47
#ifndef DCDB_SENSORCONFIG_INTERNAL_H
#define DCDB_SENSORCONFIG_INTERNAL_H

namespace DCDB {
Axel Auweter's avatar
Axel Auweter committed
48
49
50
51

class SensorConfigImpl
{
protected:
52
  Connection* connection;
53
  CassSession* session;
Axel Auweter's avatar
Axel Auweter committed
54

55
  typedef std::unordered_map<std::string, PublicSensor> SensorMap_t;
56
  SensorMap_t sensorMapByName;
57
  std::list<std::string> sensorList;
58
59
  std::string _clusterName;
  bool _useCache;
60
  std::string _sensorCacheFile;
61

Axel Auweter's avatar
Axel Auweter committed
62
  bool validateSensorPattern(const char* sensorPattern);
63
  bool validateSensorPublicName(std::string publicName);
64
  int acquireCacheLock(const bool write);
65
  int releaseCacheLock(const int fd);
Axel Auweter's avatar
Axel Auweter committed
66
67

public:
68
  SCError loadCache();
Axel Auweter's avatar
Axel Auweter committed
69
  SCError publishSensor(std::string publicName, std::string sensorPattern);
70
  SCError publishSensor(const PublicSensor& sensor);
71
  SCError publishSensor(const SensorMetadata& sensor);
72
  SCError publishVirtualSensor(std::string publicName, std::string vSensorExpression, std::string vSensorId, TimeStamp tZero, uint64_t interval);
73
  SCError unPublishSensor(std::string publicName);
74
  SCError unPublishSensorsByWildcard(std::string wildcard);
75
  SCError getPublicSensorNames(std::list<std::string>& publicSensors);
76
  SCError getPublicSensorsVerbose(std::list<PublicSensor>& publicSensors);
77
  
78
  SCError getPublicSensorByName(PublicSensor& sensor, const char* publicName);
79
80
  SCError getPublicSensorsByWildcard(std::list<PublicSensor>& sensors, const char* wildcard);
    
81
82
  SCError isVirtual(bool& isVirtual, std::string publicName);

83
84
  SCError setSensorScalingFactor(std::string publicName, double scalingFactor);
  SCError setSensorUnit(std::string publicName, std::string unit);
85
  SCError setSensorMask(std::string publicName, uint64_t mask);
86
  SCError setOperations(std::string publicName, std::set<std::string> operations);
87
  SCError clearOperations(std::string publicName);
88
  SCError clearOperationsByWildcard(std::string wildcard);
89
90
  SCError setTimeToLive(std::string publicName, uint64_t ttl);
  SCError setSensorInterval(std::string publicName, uint64_t interval);
91

92
93
94
  SCError setVirtualSensorExpression(std::string publicName, std::string expression);
  SCError setVirtualSensorTZero(std::string publicName, TimeStamp tZero);

95
96
97
  SCError getPublishedSensorsWritetime(uint64_t &ts);
  SCError setPublishedSensorsWritetime(const uint64_t &ts);

98
  SCError getClusterName(std::string &name);
99
100
101
102
103
104
  SCError isSensorCacheValid(const bool names, bool& isValid, uint64_t& entries);
  SCError findSensorCachePath();
  SCError saveNamesToFile(const std::list<std::string>& publicSensors);
  SCError saveMetadataToFile(const std::list<PublicSensor>& publicSensors);
  SCError loadNamesFromFile(std::list<std::string>& publicSensors);
  SCError loadMetadataFromFile(std::list<PublicSensor>& publicSensors);
105
  
106
  SensorConfigImpl(Connection* conn);
Axel Auweter's avatar
Axel Auweter committed
107
108
109
  virtual ~SensorConfigImpl();
};

110
111
112
} /* End of namespace DCDB */

#endif /* DCDB_SENSORCONFIG_INTERNAL_H */