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 #1518 from foglamp/1.5.2RC
Browse files Browse the repository at this point in the history
1.5.2RC
  • Loading branch information
Singhal-Vaibhav authored Apr 9, 2019
2 parents 5ca3f94 + fd1857e commit e55a6cb
Show file tree
Hide file tree
Showing 356 changed files with 7,629 additions and 4,526 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ data/tmp

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

Expand Down
5 changes: 4 additions & 1 deletion C/common/config_category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ void ConfigCategory::removeItemsType(ConfigCategory::ItemType type)
{
if ((*it)->m_itemType == type)
{
delete *it;
m_items.erase(it);
}
else
Expand All @@ -323,7 +324,7 @@ void ConfigCategory::removeItems()
{
for (auto it = m_items.begin(); it != m_items.end(); )
{

delete *it;
m_items.erase(it);
}
}
Expand All @@ -340,6 +341,7 @@ void ConfigCategory::keepItemsType(ConfigCategory::ItemType type)
{
if ((*it)->m_itemType != type)
{
delete *it;
m_items.erase(it);
}
else
Expand Down Expand Up @@ -384,6 +386,7 @@ bool ConfigCategory::extractSubcategory(ConfigCategory &subCategories)
m_name.replace(m_name.find(pattern), pattern.length(), instanceName);

// Removes the element just processed
delete *it;
subCategories.m_items.erase(it);
extracted = true;
}
Expand Down
8 changes: 6 additions & 2 deletions C/common/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using namespace std;

// uncomment line below to get uSec level timestamps
//#define ADD_USEC_TS
// #define ADD_USEC_TS

inline long getCurrTimeUsec()
{
Expand Down Expand Up @@ -112,7 +112,11 @@ void Logger::error(const string& msg, ...)
va_list args;
va_start(args, msg);
string *fmt = format(msg, args);
syslog(LOG_ERR, "ERROR: %s", fmt->c_str());
#ifdef ADD_USEC_TS
syslog(LOG_ERR, "[.%06ld] ERROR: %s", getCurrTimeUsec(), fmt->c_str());
#else
syslog(LOG_ERR, "ERROR: %s", fmt->c_str());
#endif
delete fmt;
va_end(args);
}
Expand Down
1 change: 0 additions & 1 deletion C/common/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ FogLampProcess::FogLampProcess(int argc, char** argv) :
throw runtime_error(string("Error while parsing optional options: ") + e.what());
}


// Connection to FogLamp core microservice
m_client = new ManagementClient(m_core_mngt_host, m_core_mngt_port);

Expand Down
6 changes: 5 additions & 1 deletion C/plugins/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIR})
file(GLOB SOURCES *.cpp)

# Include header files
include_directories(include ../../common/include ../../services/common/include ../../thirdparty/Simple-Web-Server)
include_directories(include)
include_directories(../../common/include)
include_directories(../../services/common/include)
include_directories(../../thirdparty/Simple-Web-Server)
include_directories(../../thirdparty/rapidjson/include)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../../lib)

Expand Down
81 changes: 68 additions & 13 deletions C/plugins/common/include/omf.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@
#include <http_sender.h>
#include <zlib.h>

#define TYPE_ID_DEFAULT 1
#define FAKE_ASSET_KEY "_default_start_id_"
#define OMF_TYPE_STRING "string"
#define OMF_TYPE_INTEGER "integer"
#define OMF_TYPE_FLOAT "number"

/**
* Per asset dataTypes
*
* typeId is a prefix for OMF data Type messages
* types is a JSON string with datapoint names and types
* This class is used in a std::map where assetName is a key
*/
class OMFDataTypes
{
public:
long typeId;
std::string types;
};

/**
* The OMF class.
*/
Expand All @@ -32,7 +48,12 @@ class OMF
*/
OMF(HttpSender& sender,
const std::string& path,
const std::string& typeId,
const long typeId,
const std::string& producerToken);

OMF(HttpSender& sender,
const std::string& path,
std::map<std::string, OMFDataTypes>& types,
const std::string& producerToken);

// Destructor
Expand Down Expand Up @@ -81,8 +102,8 @@ class OMF
std::string compress_string(const std::string& str,
int compressionlevel = Z_DEFAULT_COMPRESSION);

// Return current value of type-id
const std::string& getTypeId() { return m_typeId; };
// Return current value of global type-id
const long getTypeId() const { return m_typeId; };

// Check DataTypeError
bool isDataTypeError(const char* message);
Expand All @@ -93,6 +114,11 @@ class OMF
// Removed mapped object types found in input data
void unsetMapObjectTypes(std::map<std::string, Reading*>& dataSuperSet) const;

void setStaticData(std::vector<std::pair<std::string, std::string>> *staticData)
{
m_staticData = staticData;
};

private:
/**
* Builds the HTTP header to send
Expand Down Expand Up @@ -134,24 +160,42 @@ class OMF
bool sendDataTypes(const Reading& row);

// Get saved dataType
static bool getCreatedTypes(const std::string& key);
bool getCreatedTypes(const std::string& key);

// Set saved dataType
static bool setCreatedTypes(const std::string& key);
bool setCreatedTypes(const std::string& key);

// Clear data types cache
static void clearCreatedTypes();
void clearCreatedTypes();

// Increment type-id value
void incrementTypeId();

// Handle data type errors
bool handleTypeErrors(const Reading& reading);

// Extract assetName from erro message
std::string getAssetNameFromError(const char* message);

// Get asset type-id from cached data
long getAssetTypeId(const std::string& assetName) const;

// Increment per asset type-id value
void incrementAssetTypeId(const std::string& assetName);

// Set global type-id as the maximum value of all per asset type-ids
void setTypeId();

// Set saved dataType
bool setCreatedTypes(const Reading& row);

// Remove cached data types enttry for given asset name
void clearCreatedTypes(const std::string& key);

private:
const std::string m_path;
std::string m_typeId;
const std::string m_producerToken;
const std::string m_path;
long m_typeId;
const std::string m_producerToken;

// Define the OMF format to use for each type
// the format will not be applied if the string is empty
Expand All @@ -170,9 +214,20 @@ class OMF
bool m_lastError;
bool m_changeTypeId;

// These errors are considered not blocking in the communication with the destination,
// the sending operation will proceed with the next block of data if one of these is encountered
std::vector<std::string> m_notBlockingErrors;
// These errors are considered not blocking in the communication
// with the destination, the sending operation will proceed
// with the next block of data if one of these is encountered
std::vector<std::string> m_notBlockingErrors;

// Data types cache[key] = (key_type_id, key data types)
std::map<std::string, OMFDataTypes>*
m_OMFDataTypes;
/**
* Static data to send to OMF
*/
std::vector<std::pair<std::string, std::string>>
*m_staticData;

};

/**
Expand All @@ -182,7 +237,7 @@ class OMF
class OMFData
{
public:
OMFData(const Reading& reading, const std::string& typeId);
OMFData(const Reading& reading, const long typeId);
const std::string& OMFdataVal() const;
private:
std::string m_value;
Expand Down
Loading

0 comments on commit e55a6cb

Please sign in to comment.