 |
Fledge
An open source edge computing platform for industrial users
|
1 #ifndef _SOUTH_SERVICE_H
2 #define _SOUTH_SERVICE_H
14 #include <south_plugin.h>
15 #include <service_handler.h>
16 #include <config_category.h>
18 #include <filter_plugin.h>
19 #include <plugin_data.h>
20 #include <audit_logger.h>
21 #include <perfmonitors.h>
23 #define MAX_SLEEP 5 // Maximum number of seconds the service will sleep during a poll cycle
25 #define SERVICE_NAME "Fledge South"
35 #define SOUTH_THROTTLE_HIGH_PERCENT 50 // Percentage above buffer threshold where we throttle down
36 #define SOUTH_THROTTLE_LOW_PERCENT 10 // Percentage above buffer threshold where we throttle up
37 #define SOUTH_THROTTLE_PERCENT 10 // The percentage we throttle poll by
38 #define SOUTH_THROTTLE_DOWN_INTERVAL 10 // Interval between throttle down attmepts
39 #define SOUTH_THROTTLE_UP_INTERVAL 15 // Interval between throttle up attempts
45 #define DEBUG_ATTACHED 0x01
46 #define DEBUG_SUSPENDED 0x02
47 #define DEBUG_ISOLATED 0x04
60 const std::string& token =
"");
62 void start(std::string& coreAddress,
63 unsigned short corePort);
67 void configChange(
const std::string&,
const std::string&);
69 void configChildCreate(
const std::string&,
71 const std::string&){};
72 void configChildDelete(
const std::string&,
73 const std::string&){};
74 bool isRunning() {
return !m_shutdown; };
75 bool setPoint(
const std::string& name,
const std::string& value);
76 bool operation(
const std::string& name, std::vector<PLUGIN_PARAMETER *>& );
77 void setDryRun() { m_dryRun =
true; };
84 m_debugState = DEBUG_ATTACHED;
85 return m_ingest->attachDebugger();
92 m_ingest->detachDebugger();
93 suspendDebugger(
false);
94 isolateDebugger(
false);
97 void setDebuggerBuffer(
unsigned int size)
100 m_ingest->setDebuggerBuffer(size);
102 std::string getDebuggerBuffer()
105 return m_ingest->getDebuggerBuffer();
108 void suspendDebugger(
bool suspend)
110 suspendIngest(suspend);
112 m_debugState |= DEBUG_SUSPENDED;
114 m_debugState &= ~(
unsigned int)DEBUG_SUSPENDED;
116 void isolateDebugger(
bool isolate)
119 m_ingest->isolate(isolate);
121 m_debugState |= DEBUG_ISOLATED;
123 m_debugState &= ~(
unsigned int)DEBUG_ISOLATED;
125 void stepDebugger(
unsigned int steps)
127 std::lock_guard<std::mutex> guard(m_suspendMutex);
130 void replayDebugger()
133 m_ingest->replayDebugger();
136 bool debuggerAttached()
138 return m_debugState & DEBUG_ATTACHED;
143 return m_controlEnabled;
147 return m_debuggerEnabled;
153 int createTimerFd(
struct timeval rate);
155 std::string parent_name,
156 std::string current_name);
158 void processNumberList(
const ConfigCategory& cateogry,
const std::string& item, std::vector<unsigned long>& list);
159 void calculateTimerRate();
160 bool syncToNextPoll();
162 void checkPendingReconfigure();
164 void suspendIngest(
bool suspend)
166 std::lock_guard<std::mutex> guard(m_suspendMutex);
167 m_suspendIngest = suspend;
172 std::lock_guard<std::mutex> guard(m_suspendMutex);
173 return m_suspendIngest;
177 std::lock_guard<std::mutex> guard(m_suspendMutex);
178 if (m_suspendIngest && m_steps > 0)
185 void getResourceLimit();
187 std::thread *m_reconfThread;
188 std::deque<std::pair<std::string,std::string>> m_pendingNewConfig;
189 std::mutex m_pendingNewConfigMutex;
190 std::condition_variable m_cvNewReconf;
199 unsigned long m_readingsPerSec;
200 unsigned int m_threshold;
201 unsigned long m_timeout;
205 unsigned int m_highWater;
206 unsigned int m_lowWater;
207 struct timeval m_lastThrottle;
208 struct timeval m_desiredRate;
209 struct timeval m_currentRate;
211 const std::string m_token;
212 unsigned int m_repeatCnt;
214 std::string m_dataKey;
216 bool m_requestRestart;
217 std::string m_rateUnits;
218 enum { POLL_INTERVAL, POLL_FIXED, POLL_ON_DEMAND }
220 std::vector<unsigned long> m_hours;
221 std::vector<unsigned long> m_minutes;
222 std::vector<unsigned long> m_seconds;
223 std::string m_hoursStr;
224 std::string m_minutesStr;
225 std::string m_secondsStr;
226 std::condition_variable m_pollCV;
227 std::mutex m_pollMutex;
231 bool m_suspendIngest;
232 unsigned int m_steps;
233 std::mutex m_suspendMutex;
234 unsigned int m_debugState;
236 bool m_controlEnabled;
237 bool m_debuggerEnabled;
238 ServiceBufferingType m_serviceBufferingType;
239 unsigned int m_serviceBufferSize;
240 DiscardPolicy m_discardPolicy;
251 void asJSON(std::string &json)
const
255 json =
"\"debug\" : " + m_south->
debugState();
DefaultConfigCategory.
Definition: config_category.h:241
Definition: json_provider.h:14
virtual ~SouthService()
Destructor for south service.
Definition: south.cpp:280
The ingest class is used to ingest asset readings.
Definition: ingest.h:74
std::string debugState()
Return the state of the pipeline debugger.
Definition: south.cpp:1962
SouthService(const std::string &name, const std::string &token="")
Constructor for the south service.
Definition: south.cpp:247
void processConfigChange(const std::string &, const std::string &)
Configuration change notification.
Definition: south.cpp:1068
void stop()
Stop the storage service/.
Definition: south.cpp:917
The SouthService class.
Definition: south_service.h:57
void start(std::string &coreAddress, unsigned short corePort)
Start the south service.
Definition: south.cpp:305
void restart()
Restart request.
Definition: south.cpp:1052
Definition: config_category.h:56
void shutdown()
Shutdown request.
Definition: south.cpp:1031
Definition: plugin_data.h:15
bool setPoint(const std::string &name, const std::string &value)
Perform a setPoint operation on the south plugin.
Definition: south.cpp:1562
void configChange(const std::string &, const std::string &)
Configuration change notification using a separate thread.
Definition: south.cpp:1307
Class that represents a south plugin.
Definition: south_plugin.h:33
void handlePendingReconf()
Handle configuration change notification; called by reconf thread Waits for some reconf operation(s) ...
Definition: south.cpp:1265
Fledge Logger class used to log to syslog.
Definition: logger.h:42
A data provider class to return data in the south service ping response.
Definition: south_service.h:247
The AssetTracker class provides the asset tracking functionality.
Definition: asset_tracking.h:239
ServiceAuthHandler adds security to the base class ServiceHandler.
Definition: service_handler.h:35
A singleton class for access to the audit logger within services.
Definition: audit_logger.h:21
bool operation(const std::string &name, std::vector< PLUGIN_PARAMETER * > &)
Perform an operation on the south plugin.
Definition: south.cpp:1582