Skip to content

Commit

Permalink
Merge pull request #859 from fledge-iot/2.0.1RC
Browse files Browse the repository at this point in the history
2.0.1RC
  • Loading branch information
Mohit04tomar authored Oct 27, 2022
2 parents fb94566 + c9c5bb0 commit a791263
Show file tree
Hide file tree
Showing 121 changed files with 4,703 additions and 769 deletions.
9 changes: 9 additions & 0 deletions C/common/config_category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,15 @@ bool ConfigCategory::setItemAttribute(const string& itemName,
case FILE_ATTR:
m_items[i]->m_file = value;
return true;
case MINIMUM_ATTR:
m_items[i]->m_minimum = value;
return true;
case MAXIMUM_ATTR:
m_items[i]->m_maximum = value;
return true;
case LENGTH_ATTR:
m_items[i]->m_length = value;
return true;
default:
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion C/common/include/config_category.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ class ConfigCategory {
ORDER_ATTR,
READONLY_ATTR,
MANDATORY_ATTR,
FILE_ATTR};
FILE_ATTR,
MINIMUM_ATTR,
MAXIMUM_ATTR,
LENGTH_ATTR};
std::string getItemAttribute(const std::string& itemName,
ItemAttribute itemAttribute) const;

Expand Down
19 changes: 18 additions & 1 deletion C/common/include/management_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ using HttpServer = SimpleWeb::Server<SimpleWeb::HTTP>;
using namespace rapidjson;

class AssetTrackingTuple;
class StorageAssetTrackingTuple;

/**
* The management client class used by services and tasks to communicate
Expand Down Expand Up @@ -60,10 +61,25 @@ class ManagementClient {
const std::vector<std::string>& children);
std::vector<AssetTrackingTuple*>&
getAssetTrackingTuples(const std::string serviceName = "");
std::vector<StorageAssetTrackingTuple*>&
getStorageAssetTrackingTuples(const std::string serviceName);

StorageAssetTrackingTuple* getStorageAssetTrackingTuple(const std::string& serviceName,
const std::string& assetName,
const std::string& event, const std::string & dp, const unsigned int& c);

bool addAssetTrackingTuple(const std::string& service,
const std::string& plugin,
const std::string& asset,
const std::string& event);

bool addStorageAssetTrackingTuple(const std::string& service,
const std::string& plugin,
const std::string& asset,
const std::string& event,
const bool& deprecated = false,
const std::string& datapoints = "",
const int& count = 0);
ConfigCategories getChildCategories(const std::string& categoryName);
HttpClient *getHttpClient();
bool addAuditEntry(const std::string& serviceName,
Expand Down Expand Up @@ -94,10 +110,11 @@ class ManagementClient {
std::vector<std::pair<std::string, std::string> > >& endpoints);
bool deleteProxy(const std::string& serviceName);
const std::string getUrlbase() { return m_urlbase.str(); }
ACL getACL(const std::string& aclName);
ACL getACL(const std::string& aclName);
AssetTrackingTuple* getAssetTrackingTuple(const std::string& serviceName,
const std::string& assetName,
const std::string& event);
int validateDatapoints(std::string dp1, std::string dp2);

private:
std::ostringstream m_urlbase;
Expand Down
3 changes: 2 additions & 1 deletion C/common/include/reading_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class JSONReading : public Reading {
unsigned long getId() const { return m_id; };

private:
void escapeCharacter(std::string& stringToEvaluate, std::string pattern);
Datapoint *datapoint(const std::string& name, const rapidjson::Value& json);
void escapeCharacter(std::string& stringToEvaluate, std::string pattern);
};

class ReadingSetException : public std::exception
Expand Down
127 changes: 127 additions & 0 deletions C/common/include/storage_asset_tracking.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#ifndef _STORAGE_ASSET_TRACKING_H
#define _STORAGE_ASSET_TRACKING_H
/*
* Fledge storage asset tracking related
*
* Copyright (c) 2022 Dianomic Systems
*
* Released under the Apache 2.0 Licence
*
* Author: Ashwini Sinha
*/
#include <logger.h>
#include <vector>
#include <sstream>
#include <unordered_set>
#include <asset_tracking.h>
#include <management_client.h>
#include <set>


/**
* The StorageAssetTrackingTuple class is used to represent ai storage asset
* tracking tuple. Hash function and '==' operator are defined for
* this class and pointer to this class that would be required
* to create an unordered_set of this class.
*/

class StorageAssetTrackingTuple : public AssetTrackingTuple {

public:
std::string m_datapoints;
unsigned int m_maxCount;

std::string assetToString()
{
std::ostringstream o;
o << AssetTrackingTuple::assetToString() << ", m_datapoints:" << m_datapoints << ", m_maxCount:" << m_maxCount;
return o.str();
}

unsigned int getMaxCount() { return m_maxCount; }
std::string getDataPoints() { return m_datapoints; }

StorageAssetTrackingTuple(const std::string& service,
const std::string& plugin,
const std::string& asset,
const std::string& event,
const bool& deprecated = false,
const std::string& datapoints = "",
unsigned int c = 0) :
AssetTrackingTuple(service, plugin, asset, event, deprecated), m_datapoints(datapoints), m_maxCount(c)
{}

private:
};

struct StorageAssetTrackingTuplePtrEqual {
bool operator()(StorageAssetTrackingTuple const* a, StorageAssetTrackingTuple const* b) const {
return *a == *b;
}
};

namespace std
{
template <>
struct hash<StorageAssetTrackingTuple>
{
size_t operator()(const StorageAssetTrackingTuple& t) const
{
return (std::hash<std::string>()(t.m_serviceName + t.m_pluginName + t.m_assetName + t.m_eventName));
}
};

template <>
struct hash<StorageAssetTrackingTuple*>
{
size_t operator()(StorageAssetTrackingTuple* t) const
{
return (std::hash<std::string>()(t->m_serviceName + t->m_pluginName + t->m_assetName + t->m_eventName));
}
};
}

class ManagementClient;

typedef std::unordered_multiset<StorageAssetTrackingTuple*, std::hash<StorageAssetTrackingTuple*>, StorageAssetTrackingTuplePtrEqual> StorageAssetCacheSet;

typedef std::unordered_multiset<StorageAssetTrackingTuple*, std::hash<StorageAssetTrackingTuple*>, StorageAssetTrackingTuplePtrEqual>::iterator StorageAssetCacheSetItr;

struct StorageAssetCacheSetItrCmp{

bool operator ()(StorageAssetCacheSetItr x, StorageAssetCacheSetItr y)
{
return x != y;
}

};
/**
* The StorageAssetTracker class provides the asset tracking functionality.
* There are methods to populate asset tracking cache from asset_tracker DB table,
* and methods to check/add asset tracking tuples to DB and to cache
*/
class StorageAssetTracker {

public:
StorageAssetTracker(ManagementClient *mgtClient, std::string m_service);
~StorageAssetTracker() {}
void populateStorageAssetTrackingCache();
StorageAssetTrackingTuple*
findStorageAssetTrackingCache(StorageAssetTrackingTuple& tuple);
void addStorageAssetTrackingTuple(StorageAssetTrackingTuple& tuple);
bool getFledgeConfigInfo();
static StorageAssetTracker *getStorageAssetTracker();
static void releaseStorageAssetTracker();
int compareDatapoints(const std::string& dp1, const std::string& dp2);

private:
static StorageAssetTracker *instance;
ManagementClient *m_mgtClient;
std::string m_fledgeService;
std::string m_service;
std::string m_event;

StorageAssetCacheSet storageAssetTrackerTuplesCache;
};

#endif
Loading

0 comments on commit a791263

Please sign in to comment.