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 #1454 from foglamp/1.5.1RC
Browse files Browse the repository at this point in the history
Merge 1.5.1 into master
  • Loading branch information
Singhal-Vaibhav authored Mar 13, 2019
2 parents 94e3fb0 + 9efb2b2 commit 5ca3f94
Show file tree
Hide file tree
Showing 287 changed files with 2,910 additions and 562 deletions.
21 changes: 21 additions & 0 deletions C/common/config_category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,26 @@ void ConfigCategory::addItem(const std::string& name, const std::string descript
m_items.push_back(new CategoryItem(name, description, def, value, options));
}

/**
* Set the display name of an item
*
* @param name The item name in the category
* @param displayName The display name to set
* @return true if the item was found
*/
bool ConfigCategory::setItemDisplayName(const std::string& name, const std::string& displayName)
{
for (unsigned int i = 0; i < m_items.size(); i++)
{
if (name.compare(m_items[i]->m_name) == 0)
{
m_items[i]->m_displayName = displayName;
return true;
}
}
return false;
}

/**
* Delete all the items from the configuration category having a specific type
*
Expand Down Expand Up @@ -777,6 +797,7 @@ ConfigCategory::CategoryItem::CategoryItem(const string& name,
const Value& item)
{
m_name = name;
m_itemType = UnknownType;
if (! item.IsObject())
{
throw new ConfigMalformed();
Expand Down
215 changes: 108 additions & 107 deletions C/common/filter_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,130 +86,131 @@ bool FilterPipeline::loadFilters(const string& categoryName)
Logger::getLogger()->info("FilterPipeline::loadFilters(): categoryName=%s, filters=%s", categoryName.c_str(), filter.c_str());
if (!filter.empty())
{
std::vector<pair<string, PLUGIN_HANDLE>> filterInfo;
std::vector<pair<string, PLUGIN_HANDLE>> filterInfo;

// Remove \" and leading/trailing "
// TODO: improve/change this
filter.erase(remove(filter.begin(), filter.end(), '\\' ), filter.end());
size_t i;
while (! (i = filter.find('"')) || (i = filter.rfind('"')) == static_cast<unsigned char>(filter.size() - 1))
{
filter.erase(i, 1);
}
// Remove \" and leading/trailing "
// TODO: improve/change this
filter.erase(remove(filter.begin(), filter.end(), '\\' ), filter.end());
size_t i;
while (! (i = filter.find('"')) || (i = filter.rfind('"')) == static_cast<unsigned char>(filter.size() - 1))
{
filter.erase(i, 1);
}

//Parse JSON object for filters
Document theFilters;
theFilters.Parse(filter.c_str());
// The "pipeline" property must be an array
if (theFilters.HasParseError() ||
!theFilters.HasMember(JSON_CONFIG_PIPELINE_ELEM) ||
!theFilters[JSON_CONFIG_PIPELINE_ELEM].IsArray())
{
string errMsg("loadFilters: can not parse JSON '");
errMsg += string(JSON_CONFIG_FILTER_ELEM) + "' property";
Logger::getLogger()->fatal(errMsg.c_str());
throw runtime_error(errMsg);
}
else
{
const Value& filterList = theFilters[JSON_CONFIG_PIPELINE_ELEM];
if (!filterList.Size())
//Parse JSON object for filters
Document theFilters;
theFilters.Parse(filter.c_str());
// The "pipeline" property must be an array
if (theFilters.HasParseError() ||
!theFilters.HasMember(JSON_CONFIG_PIPELINE_ELEM) ||
!theFilters[JSON_CONFIG_PIPELINE_ELEM].IsArray())
{
// Empty array, just return true
return true;
string errMsg("loadFilters: can not parse JSON '");
errMsg += string(JSON_CONFIG_FILTER_ELEM) + "' property";
Logger::getLogger()->fatal(errMsg.c_str());
throw runtime_error(errMsg);
}
else
{
const Value& filterList = theFilters[JSON_CONFIG_PIPELINE_ELEM];
if (!filterList.Size())
{
// Empty array, just return true
return true;
}

// Prepare printable list of filters
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
filterList.Accept(writer);
string printableList(buffer.GetString());
// Prepare printable list of filters
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
filterList.Accept(writer);
string printableList(buffer.GetString());

string logMsg("loadFilters: found filter(s) ");
logMsg += printableList + " for plugin '";
logMsg += categoryName + "'";
string logMsg("loadFilters: found filter(s) ");
logMsg += printableList + " for plugin '";
logMsg += categoryName + "'";

Logger::getLogger()->info(logMsg.c_str());
Logger::getLogger()->info(logMsg.c_str());

// Try loading all filter plugins: abort on any error
for (Value::ConstValueIterator itr = filterList.Begin(); itr != filterList.End(); ++itr)
{
// Get "plugin" item fromn filterCategoryName
string filterCategoryName = itr->GetString();
ConfigCategory filterDetails = mgtClient->getCategory(filterCategoryName);
if (!filterDetails.itemExists("plugin"))
{
string errMsg("loadFilters: 'plugin' item not found ");
errMsg += "in " + filterCategoryName + " category";
Logger::getLogger()->fatal(errMsg.c_str());
throw runtime_error(errMsg);
}
string filterName = filterDetails.getValue("plugin");
PLUGIN_HANDLE filterHandle;
// Load filter plugin only: we don't call any plugin method right now
filterHandle = loadFilterPlugin(filterName);
if (!filterHandle)
// Try loading all filter plugins: abort on any error
for (Value::ConstValueIterator itr = filterList.Begin(); itr != filterList.End(); ++itr)
{
string errMsg("Cannot load filter plugin '" + filterName + "'");
Logger::getLogger()->fatal(errMsg.c_str());
throw runtime_error(errMsg);
// Get "plugin" item fromn filterCategoryName
string filterCategoryName = itr->GetString();
ConfigCategory filterDetails = mgtClient->getCategory(filterCategoryName);
if (!filterDetails.itemExists("plugin"))
{
string errMsg("loadFilters: 'plugin' item not found ");
errMsg += "in " + filterCategoryName + " category";
Logger::getLogger()->fatal(errMsg.c_str());
throw runtime_error(errMsg);
}
string filterName = filterDetails.getValue("plugin");
PLUGIN_HANDLE filterHandle;
// Load filter plugin only: we don't call any plugin method right now
filterHandle = loadFilterPlugin(filterName);
if (!filterHandle)
{
string errMsg("Cannot load filter plugin '" + filterName + "'");
Logger::getLogger()->fatal(errMsg.c_str());
throw runtime_error(errMsg);
}
else
{
// Save filter handler: key is filterCategoryName
filterInfo.push_back(pair<string,PLUGIN_HANDLE>
(filterCategoryName, filterHandle));
}
}
else

// We have kept filter default config in the filterInfo map
// Handle configuration for each filter
PluginManager *pluginManager = PluginManager::getInstance();
for (vector<pair<string, PLUGIN_HANDLE>>::iterator itr = filterInfo.begin();
itr != filterInfo.end();
++itr)
{
// Save filter handler: key is filterCategoryName
filterInfo.push_back(pair<string,PLUGIN_HANDLE>
(filterCategoryName, filterHandle));
}
}
// Get plugin default configuration
string filterConfig = pluginManager->getInfo(itr->second)->config;

// We have kept filter default config in the filterInfo map
// Handle configuration for each filter
PluginManager *pluginManager = PluginManager::getInstance();
for (vector<pair<string, PLUGIN_HANDLE>>::iterator itr = filterInfo.begin();
itr != filterInfo.end();
++itr)
{
// Get plugin default configuration
string filterConfig = pluginManager->getInfo(itr->second)->config;
// Create/Update default filter category items
DefaultConfigCategory filterDefConfig(categoryName + "_" + itr->first, filterConfig);
string filterDescription = "Configuration of '" + itr->first;
filterDescription += "' filter for plugin '" + categoryName + "'";
filterDefConfig.setDescription(filterDescription);

// Update filter category items
DefaultConfigCategory filterDefConfig(itr->first, filterConfig);
string filterDescription = "Configuration of '" + itr->first;
filterDescription += "' filter for plugin '" + categoryName + "'";
filterDefConfig.setDescription(filterDescription);
if (!mgtClient->addCategory(filterDefConfig, true))
{
string errMsg("Cannot create/update '" + \
categoryName + "' filter category");
Logger::getLogger()->fatal(errMsg.c_str());
throw runtime_error(errMsg);
}
children.push_back(categoryName + "_" + itr->first);

if (!mgtClient->addCategory(filterDefConfig, true))
{
string errMsg("Cannot create/update '" + \
categoryName + "' filter category");
Logger::getLogger()->fatal(errMsg.c_str());
throw runtime_error(errMsg);
}
children.push_back(categoryName + "_" + itr->first);
// Instantiate the FilterPlugin class
// in order to call plugin entry points
FilterPlugin* currentFilter = new FilterPlugin(itr->first,
itr->second);

// Instantiate the FilterPlugin class
// in order to call plugin entry points
FilterPlugin* currentFilter = new FilterPlugin(itr->first,
itr->second);

// Add filter to filters vector
m_filters.push_back(currentFilter);
// Add filter to filters vector
m_filters.push_back(currentFilter);
}
}
}
}
/*
* Put all the new catregories in the Filter category parent
* Create an empty South category if one doesn't exist
*/
string parentName = categoryName + " Filters";
DefaultConfigCategory filterConfig(parentName, string("{}"));
filterConfig.setDescription("Filters for " + categoryName);
mgtClient->addCategory(filterConfig, true);
mgtClient->addChildCategories(parentName, children);
vector<string> children1;
children1.push_back(parentName);
mgtClient->addChildCategories(categoryName, children1);
return true;

/*
* Put all the new catregories in the Filter category parent
* Create an empty South category if one doesn't exist
*/
string parentName = categoryName + " Filters";
DefaultConfigCategory filterConfig(parentName, string("{}"));
filterConfig.setDescription("Filters for " + categoryName);
mgtClient->addCategory(filterConfig, true);
mgtClient->addChildCategories(parentName, children);
vector<string> children1;
children1.push_back(parentName);
mgtClient->addChildCategories(categoryName, children1);
return true;
}
catch (ConfigItemNotFound* e)
{
Expand Down
3 changes: 2 additions & 1 deletion C/common/include/config_category.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ConfigCategories {

class ConfigCategory {
public:
enum ItemType { StringItem, EnumerationItem, JsonItem, BoolItem, NumberItem, DoubleItem, ScriptItem, CategoryType};
enum ItemType { UnknownType, StringItem, EnumerationItem, JsonItem, BoolItem, NumberItem, DoubleItem, ScriptItem, CategoryType};

ConfigCategory(const std::string& name, const std::string& json);
ConfigCategory() {};
Expand All @@ -74,6 +74,7 @@ class ConfigCategory {
std::string getDescription() const { return m_description; };
unsigned int getCount() const { return m_items.size(); };
bool itemExists(const std::string& name) const;
bool setItemDisplayName(const std::string& name, const std::string& displayName);
std::string getValue(const std::string& name) const;
std::string getType(const std::string& name) const;
std::string getDescription(const std::string& name) const;
Expand Down
54 changes: 54 additions & 0 deletions C/common/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,59 @@
#include <logger.h>
#include <process.h>
#include <service_record.h>
#include <signal.h>
#include <dlfcn.h>
#include <execinfo.h>
#include <cxxabi.h>


#define LOG_SERVICE_NAME "FogLAMP Process"

using namespace std;

/**
* Signal handler to log stack traces on fatal signals
*/
static void handler(int sig)
{
Logger *logger = Logger::getLogger();
void *array[20];
char buf[1024];
int size;

// get void*'s for all entries on the stack
size = backtrace(array, 20);

// print out all the frames to stderr
logger->fatal("Signal %d (%s) trapped:\n", sig, strsignal(sig));
char **messages = backtrace_symbols(array, size);
for (int i = 0; i < size; i++)
{
Dl_info info;
if (dladdr(array[i], &info) && info.dli_sname)
{
char *demangled = NULL;
int status = -1;
if (info.dli_sname[0] == '_')
demangled = abi::__cxa_demangle(info.dli_sname, NULL, 0, &status);
snprintf(buf, sizeof(buf), "%-3d %*p %s + %zd---------",
i, int(2 + sizeof(void*) * 2), array[i],
status == 0 ? demangled :
info.dli_sname == 0 ? messages[i] : info.dli_sname,
(char *)array[i] - (char *)info.dli_saddr);
free(demangled);
}
else
{
snprintf(buf, sizeof(buf), "%-3d %*p %s---------",
i, int(2 + sizeof(void*) * 2), array[i], messages[i]);
}
logger->fatal("(%d) %s", i, buf);
}
free(messages);
exit(1);
}

// Destructor
FogLampProcess::~FogLampProcess()
{
Expand All @@ -34,6 +82,12 @@ FogLampProcess::FogLampProcess(int argc, char** argv) :
m_argc(argc),
m_arg_vals((const char**) argv)
{
signal(SIGSEGV, handler);
signal(SIGILL, handler);
signal(SIGBUS, handler);
signal(SIGFPE, handler);
signal(SIGABRT, handler);

string myName = LOG_SERVICE_NAME;
m_logger = new Logger(myName);

Expand Down
Loading

0 comments on commit 5ca3f94

Please sign in to comment.