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.83 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 PUSHER_IDLETIME 1000000000
33

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

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

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

53
54
55
56
57
58
59
	/**
	 * @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.
	 */
60
	void push();
61
62
63
64
65
66

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

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

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

83
84
85
86
87
88
89
90
91
92
93
94
95
96
	/**
	 * @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);
97

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

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

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

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

#endif /* MQTTPUSHER_H_ */