Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

MQTTPusher.h 3.87 KB
Newer Older
1
2
3
//================================================================================
// Name        : MQTTPusher.h
// Author      : Michael Ott, Micha Mueller
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright   : Leibniz Supercomputing Centre
// Description : Collects values from the sensors and pushes them to the database.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2017-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.
//================================================================================
27
28
29
30

#ifndef MQTTPUSHER_H_
#define MQTTPUSHER_H_

31
#define DCDB_MAP "/DCDB_MAP/"
32
#define DCDB_MET "/DCDB_MAP/METADATA/"
33
#define PUSHER_IDLETIME 1000000000
34

35
#include <mosquitto.h>
36
#include <map>
37
#include "PluginManager.h"
38
#include "sensorbase.h"
39
#include "../analytics/OperatorManager.h"
40

Alessio Netti's avatar
Alessio Netti committed
41
42
enum msgCap_t {DISABLED = 1, ENABLED = 2, MINIMUM = 3};

Micha Mueller's avatar
Micha Mueller committed
43
/**
44
45
46
 * @brief Collects values from the sensors and pushes them to the database.
 *
 * @ingroup pusher
Micha Mueller's avatar
Micha Mueller committed
47
 */
48
49
class MQTTPusher {
public:
50
	MQTTPusher(int brokerPort, const std::string& brokerHost, const bool autoPublish, int qosLevel,
51
			   pusherPluginStorage_t& plugins, op_pluginVector_t& oPlugins, int maxNumberOfMessages, unsigned int maxInflightMsgNum, unsigned int maxQueuedMsgNum);
52
53
	virtual ~MQTTPusher();

54
55
56
57
58
59
60
	/**
	 * @brief MQTTPusher's main execution loop.
	 *
	 * @details If MQTTPusher is started this function runs indefinitely until
	 *          a call to stop(). Execution of the main loop can be halted and
	 *          continued with halt() and cont() respectively.
	 */
61
	void push();
62
63
64
65
66
67

	/**
	 * @brief
	 *
	 * @return
	 */
68
	bool sendMappings();
69

70
71
72
	/**
	 * @brief Start MQTTPusher's push loop.
	 */
73
74
75
76
	void start() {
		_keepRunning = true;
	}

77
78
79
	/**
	 * @brief Stop MQTTPusher's push loop and terminate its execution.
	 */
80
81
82
83
	void stop() {
		_keepRunning = false;
	}

84
85
86
87
88
89
90
91
92
93
94
95
96
97
	/**
	 * @brief Blocking call to pause MQTTPusher's push loop.
	 *
	 * @details Instructs MQTTPusher to pause its push loop and blocks until
	 *          MQTTPusher is actually paused or a timeout occurred. On a
	 *          timeout execution of MQTTPusher is continued.
	 *
	 * @param timeout Time in seconds to wait for MQTTPusher to finish its
	 *                current push cycle.
	 *
	 * @return True if MQTTPusher was succesfully paused, false if a timeout
	 *         occurred and MQTTPusher still runs.
	 */
	bool halt(unsigned short timeout = 5);
98

99
100
101
	/**
	 * @brief Continue MQTTPusher's push loop.
	 */
102
	void cont() {
Alessio Netti's avatar
Alessio Netti committed
103
		computeMsgRate();
104
105
106
		_doHalt = false;
	}

107
private:
108
	int sendReadings(SensorBase& s, reading_t* reads, std::size_t& totalCount);
Alessio Netti's avatar
Alessio Netti committed
109
	void computeMsgRate();
110

Alessio Netti's avatar
Alessio Netti committed
111
	int _qosLevel;
112
113
	int _brokerPort;
	std::string _brokerHost;
114
	bool _autoPublish;
115
	pusherPluginStorage_t& _plugins;
116
	op_pluginVector_t& _operatorPlugins;
117
118
	struct mosquitto* _mosq;
	bool _connected;
119
	bool _keepRunning;
Alessio Netti's avatar
Alessio Netti committed
120
	msgCap_t _msgCap;
121
122
	bool _doHalt;
	bool _halted;
Alessio Netti's avatar
Alessio Netti committed
123
	int _maxNumberOfMessages;
124
125
	unsigned int _maxInflightMsgNum;
	unsigned int _maxQueuedMsgNum;
126
127

	boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
128
129
130
};

#endif /* MQTTPUSHER_H_ */