Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1420 from foglamp/1.5.0RC
Browse files Browse the repository at this point in the history
1.5.0 release
  • Loading branch information
praveen-garg authored Feb 22, 2019
2 parents dbd45f3 + 42ed54a commit 94e3fb0
Show file tree
Hide file tree
Showing 309 changed files with 20,410 additions and 3,605 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ data/tmp

# SQLite3 default db location and after migration
data/*.db
data/*.db-journal
scripts/extras/*.db

/etc/storage.json
/etc/certs/*
storage.json

*.cert
*.key
Expand Down Expand Up @@ -64,3 +66,9 @@ data/etc/backup_postgres_configuration_cache.json
# test
.pytest_cache
.coverage

# Async ingest pymodule
python/async_ingest.so*

# Python south plugins
python/foglamp/plugins/south/*
1 change: 1 addition & 0 deletions C/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib)
add_library(${PROJECT_NAME} SHARED ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${UUIDLIB})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})

set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 1)

# Install library
Expand Down
125 changes: 125 additions & 0 deletions C/common/asset_tracking.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* FogLAMP asset tracking related
*
* Copyright (c) 2019 Dianomic Systems
*
* Released under the Apache 2.0 Licence
*
* Author: Amandeep Singh Arora
*/

#include <logger.h>
#include <asset_tracking.h>

using namespace std;


AssetTracker *AssetTracker::instance = 0;

/**
* Get asset tracker singleton instance for the current south service
*
* @return Singleton asset tracker instance
*/
AssetTracker *AssetTracker::getAssetTracker()
{
return instance;
}

/**
* AssetTracker class constructor
*
* @param mgtClient Management client object for this south service
* @param service Service name
*/
AssetTracker::AssetTracker(ManagementClient *mgtClient, string service)
: m_mgtClient(mgtClient), m_service(service)
{
instance = this;
}

/**
* Fetch all asset tracking tuples from DB and populate local cache
*
* @param plugin Plugin name
* @param event Event name
*/
void AssetTracker::populateAssetTrackingCache(string /*plugin*/, string /*event*/)
{
try {
std::vector<AssetTrackingTuple*>& vec = m_mgtClient->getAssetTrackingTuples(m_service);
for (AssetTrackingTuple* & rec : vec)
{
assetTrackerTuplesCache.insert(rec);
//Logger::getLogger()->info("Added asset tracker tuple to cache: '%s'", rec->assetToString().c_str());
}
delete (&vec);
}
catch (...)
{
Logger::getLogger()->error("Failed to populate asset tracking tuples' cache");
return;
}
}


/**
* Check local cache for a given asset tracking tuple
*
* @param tuple Tuple to find in cache
* @return Returns whether tuple is present in cache
*/
bool AssetTracker::checkAssetTrackingCache(AssetTrackingTuple& tuple)
{
AssetTrackingTuple *ptr = &tuple;
std::unordered_set<AssetTrackingTuple*>::const_iterator it = assetTrackerTuplesCache.find(ptr);
if (it == assetTrackerTuplesCache.end())
{
return false;
}
else
return true;
}


/**
* Add asset tracking tuple via microservice management API and in cache
*
* @param tuple New tuple to add in DB and in cache
*/
void AssetTracker::addAssetTrackingTuple(AssetTrackingTuple& tuple)
{
std::unordered_set<AssetTrackingTuple*>::const_iterator it = assetTrackerTuplesCache.find(&tuple);
if (it == assetTrackerTuplesCache.end())
{
bool rv = m_mgtClient->addAssetTrackingTuple(tuple.m_serviceName, tuple.m_pluginName, tuple.m_assetName, tuple.m_eventName);
if (rv) // insert into cache only if DB operation succeeded
{
AssetTrackingTuple *ptr = new AssetTrackingTuple(tuple);
assetTrackerTuplesCache.insert(ptr);
Logger::getLogger()->info("addAssetTrackingTuple(): Added tuple to cache: '%s'", tuple.assetToString().c_str());
}
else
Logger::getLogger()->error("addAssetTrackingTuple(): Failed to insert asset tracking tuple into DB: '%s'", tuple.assetToString().c_str());
}
}

/**
* Add asset tracking tuple via microservice management API and in cache
*
* @param plugin Plugin name
* @param asset Asset name
* @param event Event name
*/
void AssetTracker::addAssetTrackingTuple(string plugin, string asset, string event)
{
// in case of "Filter" event, 'plugin' input argument is category name, so remove service name (prefix) & '_' from it
if (event == string("Filter"))
{
plugin.erase(plugin.begin(), plugin.begin() + m_service.length() + 1);
}

AssetTrackingTuple tuple(m_service, plugin, asset, event);
addAssetTrackingTuple(tuple);
}

Loading

0 comments on commit 94e3fb0

Please sign in to comment.