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

FOGL-2547 Make static data take values from configuration #1503

Merged
merged 5 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions C/plugins/common/include/omf.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,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 @@ -217,6 +222,12 @@ class OMF
// 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 Down
25 changes: 19 additions & 6 deletions C/plugins/common/omf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,15 @@ const std::string OMF::createTypeData(const Reading& reading) const

// Add the Static data part

string tData("[{ \"type\": \"object\", \"properties\": { "
"\"Company\": {\"type\": \"string\"}, \"Location\": {\"type\": \"string\"}, "
"\"Name\": { \"type\": \"string\", \"isindex\": true } }, "
"\"classification\": \"static\", \"id\": \"");
string tData("[{ \"type\": \"object\", \"properties\": { ");
for (auto it = m_staticData->cbegin(); it != m_staticData->cend(); ++it)
{
tData.append("\"");
tData.append(it->first.c_str());
tData.append("\": {\"type\": \"string\"},");
}
tData.append("\"Name\": { \"type\": \"string\", \"isindex\": true } }, "
"\"classification\": \"static\", \"id\": \"");

// Add type_id + '_' + asset_name + '_typename_sensor'
OMF::setAssetTypeTag(reading.getAssetName(),
Expand Down Expand Up @@ -913,8 +918,16 @@ const std::string OMF::createStaticData(const Reading& reading) const
"typename_sensor",
sData);

sData.append("\", \"values\": [{\"Location\": \"Palo Alto\", "
"\"Company\": \"Dianomic\", \"Name\": \"");
sData.append("\", \"values\": [{");
for (auto it = m_staticData->cbegin(); it != m_staticData->cend(); ++it)
{
sData.append("\"");
sData.append(it->first.c_str());
sData.append("\": \"");
sData.append(it->second.c_str());
sData.append("\", ");
}
sData.append(" \"Name\": \"");

// Add asset_name
sData.append(reading.getAssetName());
Expand Down
29 changes: 29 additions & 0 deletions C/plugins/north/PI_Server_V2/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ typedef struct
string producerToken; // PI Server connector token
string formatNumber; // OMF protocol Number format
string formatInteger; // OMF protocol Integer format
vector<pair<string, string>>
staticData; // Static data
// Errors considered not blocking in the communication with the PI Server
std::vector<std::string>
notBlockingErrors;
Expand Down Expand Up @@ -186,6 +188,8 @@ PLUGIN_HANDLE plugin_init(ConfigCategory* configData)
string formatNumber = configData->getValue("formatNumber");
string formatInteger = configData->getValue("formatInteger");



/**
* Extract host, port, path from URL
*/
Expand Down Expand Up @@ -227,6 +231,30 @@ PLUGIN_HANDLE plugin_init(ConfigCategory* configData)
JSONStringToVectorString(connInfo->notBlockingErrors ,
configData->getValue("notBlockingErrors"),
std::string("errors400"));
/**
* Add static data
* Split the string up into each pair
*/
string staticData = configData->getValue("StaticData");
size_t pos = 0;
size_t start = 0;
do {
pos = staticData.find(",", start);
string item = staticData.substr(start, pos);
start = pos + 1;
size_t pos2 = 0;
if ((pos2 = item.find(":")) != string::npos)
{
string name = item.substr(0, pos2);
while (name[0] == ' ')
name = name.substr(1);
string value = item.substr(pos2 + 1);
while (value[0] == ' ')
value = value.substr(1);
pair<string, string> sData = make_pair(name, value);
connInfo->staticData.push_back(sData);
}
} while (pos != string::npos);

#if VERBOSE_LOG
// Log plugin configuration
Expand Down Expand Up @@ -333,6 +361,7 @@ uint32_t plugin_send(const PLUGIN_HANDLE handle,
connInfo->omf->setFormatType(OMF_TYPE_INTEGER,
connInfo->formatInteger);

connInfo->omf->setStaticData(&connInfo->staticData);
connInfo->omf->setNotBlockingErrors(connInfo->notBlockingErrors);

// Send data
Expand Down