 |
Fledge
An open source edge computing platform for industrial users
|
1 #ifndef _ASSET_TRACKING_H
2 #define _ASSET_TRACKING_H
16 #include <unordered_set>
17 #include <management_client.h>
21 #include <condition_variable>
22 #include <storage_client.h>
24 #define MIN_ASSET_TRACKER_UPDATE 500 // The minimum interval for asset tracker updates
36 std::string &instanceName) = 0;
37 virtual std::string assetToString() = 0;
50 std::string assetToString()
53 o <<
"service:" << m_serviceName <<
54 ", plugin:" << m_pluginName <<
55 ", asset:" << m_assetName <<
56 ", event:" << m_eventName <<
57 ", deprecated:" << m_deprecated;
63 return ( x.m_serviceName==m_serviceName &&
64 x.m_pluginName==m_pluginName &&
65 x.m_assetName==m_assetName &&
66 x.m_eventName==m_eventName);
70 const std::string& plugin,
71 const std::string& asset,
72 const std::string& event,
73 const bool& deprecated =
false) :
74 m_serviceName(service),
78 m_deprecated(deprecated) {}
80 std::string &getAssetName() {
return m_assetName; };
81 std::string getPluginName() {
return m_pluginName;}
82 std::string getEventName() {
return m_eventName;}
83 std::string getServiceName() {
return m_serviceName;}
84 bool isDeprecated() {
return m_deprecated; };
85 void unDeprecate() { m_deprecated =
false; };
90 std::string &instanceName);
93 std::string m_serviceName;
94 std::string m_pluginName;
95 std::string m_assetName;
96 std::string m_eventName;
115 return (std::hash<std::string>()(t.m_serviceName + t.m_pluginName + t.m_assetName + t.m_eventName));
124 return (std::hash<std::string>()(t->m_serviceName + t->m_pluginName + t->m_assetName + t->m_eventName));
132 const std::string& plugin,
133 const std::string& asset,
134 const std::string& event,
135 const bool& deprecated =
false,
136 const std::string& datapoints =
"",
137 unsigned int c = 0) : m_datapoints(datapoints),
139 m_serviceName(service),
140 m_pluginName(plugin),
143 m_deprecated(deprecated)
148 return ( x.m_serviceName==m_serviceName &&
149 x.m_pluginName==m_pluginName &&
150 x.m_assetName==m_assetName &&
151 x.m_eventName==m_eventName);
153 std::string assetToString()
155 std::ostringstream o;
156 o <<
"service:" << m_serviceName <<
157 ", plugin:" << m_pluginName <<
158 ", asset:" << m_assetName <<
159 ", event:" << m_eventName <<
160 ", deprecated:" << m_deprecated <<
161 ", m_datapoints:" << m_datapoints <<
162 ", m_maxCount:" << m_maxCount;
166 bool isDeprecated() {
return m_deprecated; };
168 unsigned int getMaxCount() {
return m_maxCount; }
169 std::string getDataPoints() {
return m_datapoints; }
170 void unDeprecate() { m_deprecated =
false; };
171 void setDeprecate() { m_deprecated =
true; };
176 std::string &instanceName);
179 std::string m_datapoints;
180 unsigned int m_maxCount;
181 std::string m_serviceName;
182 std::string m_pluginName;
183 std::string m_assetName;
184 std::string m_eventName;
203 return (std::hash<std::string>()(t.m_serviceName +
215 return (std::hash<std::string>()(t->m_serviceName +
224 std::set<std::string>,
228 std::set<std::string>,
253 std::set<std::string>& dpSet,
254 bool addObj =
false);
258 getIngestService(
const std::string& asset)
260 return getService(
"Ingest", asset);
263 getEgressService(
const std::string& asset)
265 return getService(
"Egress", asset);
271 std::set<std::string>
273 bool tune(
unsigned long updateInterval);
277 getService(
const std::string& event,
const std::string& asset);
280 std::set<std::string>
281 getDataPointsSet(std::string strDatapoints);
282 bool getFledgeConfigInfo();
287 std::string m_service;
289 assetTrackerTuplesCache;
290 std::queue<TrackingTuple *> m_pending;
291 std::thread *m_thread;
293 std::condition_variable m_cv;
295 std::string m_fledgeName;
297 StorageAssetCacheMap storageAssetTrackerTuplesCache;
298 unsigned int m_updateInterval;
310 void remove(
const std::string& name);
313 std::map<std::string, AssetTrackingTuple *>
Definition: asset_tracking.h:102
A class to hold a set of asset tracking tuples that allows lookup by name.
Definition: asset_tracking.h:305
AssetTrackingTuple * findAssetTrackingCache(AssetTrackingTuple &tuple)
Lookup tuple in the asset tracker cache.
Definition: asset_tracking.cpp:180
void populateStorageAssetTrackingCache()
Fetch all storage asset tracking tuples from DB and populate local cache.
Definition: asset_tracking.cpp:438
void addStorageAssetTrackingTuple(StorageAssetTrackingTuple &tuple, std::set< std::string > &dpSet, bool addObj=false)
Add asset tracking tuple via microservice management API and in cache.
Definition: asset_tracking.cpp:700
void updateCache(std::set< std::string > dpSet, StorageAssetTrackingTuple *ptr)
Updates datapoints present in the arg dpSet in the cache.
Definition: asset_tracking.cpp:604
bool tune(unsigned long updateInterval)
Set the update interval for the asset tracker.
Definition: asset_tracking.cpp:349
InsertValues processData(bool storage, ManagementClient *mgtClient, bool &warned, std::string &instanceName)
Insert StorageAssetTrackingTuple data via Fledge core API or prepare InsertValues object for direct D...
Definition: asset_tracking.cpp:799
void remove(const std::string &name)
Remove an asset tracking tuple from the table.
Definition: asset_tracking.cpp:323
The AssetTrackingTuple class is used to represent an asset tracking tuple.
Definition: asset_tracking.h:47
InsertValues processData(bool storage_connected, ManagementClient *mgtClient, bool &warned, std::string &instanceName)
Insert AssetTrackingTuple data via Fledge core API or prepare InsertValues object for direct DB opera...
Definition: asset_tracking.cpp:754
StorageAssetTrackingTuple * findStorageAssetTrackingCache(StorageAssetTrackingTuple &tuple)
Check if a StorageAssetTrackingTuple is in cache.
Definition: asset_tracking.cpp:868
bool checkAssetTrackingCache(AssetTrackingTuple &tuple)
Check local cache for a given asset tracking tuple.
Definition: asset_tracking.cpp:162
void add(AssetTrackingTuple *tuple)
Add a tuple to an asset tracking table.
Definition: asset_tracking.cpp:299
static AssetTracker * getAssetTracker()
Get asset tracker singleton instance for the current south service.
Definition: asset_tracking.cpp:35
void workerThread()
The worker thread that will flush any pending asset tuples to the database.
Definition: asset_tracking.cpp:368
The management client class used by services and tasks to communicate with the management API of the ...
Definition: management_client.h:43
Definition: asset_tracking.h:190
~AssetTracker()
Destructor for the asset tracker.
Definition: asset_tracking.cpp:90
Definition: asset_tracking.h:129
void populateAssetTrackingCache(std::string plugin, std::string event)
Fetch all asset tracking tuples from DB and populate local cache.
Definition: asset_tracking.cpp:137
Client for accessing the storage service.
Definition: storage_client.h:43
bool getDeprecated(StorageAssetTrackingTuple *ptr)
This function takes a StorageAssetTrackingTuple pointer and searches for it in cache,...
Definition: asset_tracking.cpp:577
void addAssetTrackingTuple(AssetTrackingTuple &tuple)
Add asset tracking tuple via microservice management API and in cache.
Definition: asset_tracking.cpp:199
The AssetTracker class provides the asset tracking functionality.
Definition: asset_tracking.h:239
AssetTracker(ManagementClient *mgtClient, std::string service)
AssetTracker class constructor.
Definition: asset_tracking.cpp:46
Definition: asset_tracking.h:211
~AssetTrackingTable()
Destructor for asset tracking tuple table.
Definition: asset_tracking.cpp:286
Tracking abstract base class to be passed in the process data queue.
Definition: asset_tracking.h:29
std::set< std::string > * getStorageAssetTrackingCacheData(StorageAssetTrackingTuple *tuple)
Get stored value in the StorageAssetTrackingTuple cache for the given tuple.
Definition: asset_tracking.cpp:888
AssetTrackingTable()
Constructor for an asset tracking tuple table.
Definition: asset_tracking.cpp:279
AssetTrackingTuple * find(const std::string &name)
Find the named asset tuple and return a pointer to te asset.
Definition: asset_tracking.cpp:312