Fledge
An open source edge computing platform for industrial users
ManagementClient Class Reference

The management client class used by services and tasks to communicate with the management API of the Fledge core microservice. More...

#include <management_client.h>

Public Member Functions

 ManagementClient (const std::string &hostname, const unsigned short port)
 Management Client constructor. More...
 
 ~ManagementClient ()
 Destructor for management client.
 
bool registerService (const ServiceRecord &service)
 Register this service with the Fledge core. More...
 
bool unregisterService ()
 Unregister this service with the Fledge core. More...
 
bool restartService ()
 Restart this service by sendign a request to the Fledge core. More...
 
bool getService (ServiceRecord &service)
 Get the specified service. More...
 
bool getServices (std::vector< ServiceRecord *> &services)
 Return all services registered with the Fledge core. More...
 
bool getServices (std::vector< ServiceRecord *> &services, const std::string &type)
 
bool registerCategory (const std::string &categoryName)
 Register interest in a configuration category. More...
 
bool registerCategoryChild (const std::string &categoryName)
 Register interest in a configuration category. More...
 
bool unregisterCategory (const std::string &categoryName)
 Unregister interest in a configuration category. More...
 
ConfigCategories getCategories ()
 Get the set of all configuration categories from the core micro service. More...
 
ConfigCategory getCategory (const std::string &categoryName)
 Return the content of the named category by calling the management API of the Fledge core. More...
 
std::string setCategoryItemValue (const std::string &categoryName, const std::string &itemName, const std::string &itemValue)
 Set a category configuration item value. More...
 
std::string addChildCategories (const std::string &parentCategory, const std::vector< std::string > &children)
 Add child categories to a (parent) category. More...
 
std::vector< AssetTrackingTuple * > & getAssetTrackingTuples (const std::string serviceName="")
 Get the asset tracking tuples for a service or all services. More...
 
std::vector< StorageAssetTrackingTuple * > & getStorageAssetTrackingTuples (const std::string serviceName)
 Get the storage asset tracking tuples for a service or all services. More...
 
StorageAssetTrackingTuplegetStorageAssetTrackingTuple (const std::string &serviceName, const std::string &assetName, const std::string &event, const std::string &dp, const unsigned int &c)
 Get the asset tracking tuple for a service and asset name. More...
 
bool addAssetTrackingTuple (const std::string &service, const std::string &plugin, const std::string &asset, const std::string &event)
 Add a new asset tracking tuple. More...
 
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)
 Add a new asset tracking tuple. More...
 
ConfigCategories getChildCategories (const std::string &categoryName)
 Return child categories of a given category. More...
 
HttpClient * getHttpClient ()
 Creates a HttpClient object for each thread it stores/retrieves the reference to the HttpClient and the associated thread id in a map. More...
 
bool addAuditEntry (const std::string &serviceName, const std::string &severity, const std::string &details)
 Add an Audit Entry. More...
 
std::string & getRegistrationBearerToken ()
 
void setNewBearerToken (const std::string &bearerToken)
 
bool verifyBearerToken (BearerToken &token)
 Checks and validate the JWT bearer token string. More...
 
bool verifyAccessBearerToken (BearerToken &bToken)
 Checks and validate the JWT bearer token object as reference. More...
 
bool verifyAccessBearerToken (std::shared_ptr< HttpServer::Request > request)
 
bool refreshBearerToken (const std::string &currentToken, std::string &newToken)
 Refresh the JWT bearer token string. More...
 
std::string & getBearerToken ()
 
bool addProxy (const std::string &serviceName, const std::string &operation, const std::string &publicEnpoint, const std::string &privateEndpoint)
 Request that the core proxy a URL to the service. More...
 
bool addProxy (const std::string &serviceName, const std::map< std::string, std::vector< std::pair< std::string, std::string > > > &endpoints)
 
bool deleteProxy (const std::string &serviceName)
 Delete the current proxy endpoitn for the named service. More...
 
const std::string getUrlbase ()
 
ACL getACL (const std::string &aclName)
 Return the content of the named ACL by calling the management API of the Fledge core. More...
 
AssetTrackingTuplegetAssetTrackingTuple (const std::string &serviceName, const std::string &assetName, const std::string &event)
 Get the asset tracking tuple for a service and asset name. More...
 
int validateDatapoints (std::string dp1, std::string dp2)
 Compare the datapoints to be equal or not, they can be '"' enclosed. More...
 
AssetTrackingTablegetDeprecatedAssetTrackingTuples ()
 Get the asset tracking tuples for all the deprecated assets. More...
 
std::string getAlertByKey (const std::string &key)
 Get an alert by specific key. More...
 
bool raiseAlert (const std::string &key, const std::string &message, const std::string &urgency="normal")
 Raise an alert. More...
 
bool clearAlert (const std::string &key)
 Clear an alert. More...
 
template<class T >
bool addCategory (const T &t, bool keepOriginalItems=false)
 

Detailed Description

The management client class used by services and tasks to communicate with the management API of the Fledge core microservice.

The class encapsulates the management REST API and provides methods for accessing each of those APIs.

Constructor & Destructor Documentation

◆ ManagementClient()

ManagementClient::ManagementClient ( const std::string &  hostname,
const unsigned short  port 
)

Management Client constructor.

Creates a class used to send management API requests from a micro service to the Fledge core service.

The parameters required here are passed to new services and tasks using the –address= and –port= arguments when the service is started.

Parameters
hostnameThe hostname of the Fledge core micro service
portThe port of the management service API listener in the Fledge core

Member Function Documentation

◆ addAssetTrackingTuple()

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

Add a new asset tracking tuple.

Parameters
serviceService name
pluginPlugin name
assetAsset name
eventEvent type
Returns
whether operation was successful

◆ addAuditEntry()

bool ManagementClient::addAuditEntry ( const std::string &  code,
const std::string &  severity,
const std::string &  message 
)

Add an Audit Entry.

Called when an auditable event occurs to regsiter that event.

Fledge API call example :

curl -X POST -d '{"source":"LMTR", "severity":"WARNING", "details":{"message":"Engine oil pressure low"}}' http://localhost:8081/fledge/audit

Parameters
codeThe log code for the entry
severityThe severity level
messageThe JSON message to log

◆ addCategory()

template<class T >
bool ManagementClient::addCategory ( const T &  t,
bool  keepOriginalItems = false 
)
inline

Note: At the time being the keep_original_items is added into payload and configuration manager in the Fledge handles it.

In the near future keep_original_items will be passed as URL modifier, i.e: 'URL?keep_original_items=true'

◆ addChildCategories()

string ManagementClient::addChildCategories ( const std::string &  parentCategory,
const std::vector< std::string > &  children 
)

Add child categories to a (parent) category.

Parameters
parentCategoryThe given category name
childrenCategories to add under parent
Returns
JSON string with current child categories
Exceptions
std::exception

◆ addProxy()

bool ManagementClient::addProxy ( const std::string &  serviceName,
const std::string &  operation,
const std::string &  publicEndpoint,
const std::string &  privateEndpoint 
)

Request that the core proxy a URL to the service.

URL's in the public Fledge API will be forwarded to the service API of the named service.

Parameters
serviceNameThe name of the service to send the request to
operationThe type of operations; post, put, get or delete
publicEndpointThe URL inthe Fledge public API to be proxied
privateEnpointThe URL in the service API of the named service to which the reuests will be proxied.
Returns
bool True if the proxy request was accepted

◆ addStorageAssetTrackingTuple()

bool ManagementClient::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 
)

Add a new asset tracking tuple.

Parameters
serviceService name
pluginPlugin name
assetAsset name
eventEvent type
deprecatedDeprecated or not
datapointsDatapoints type
countCount Type
Returns
whether operation was successful

◆ clearAlert()

bool ManagementClient::clearAlert ( const std::string &  key)

Clear an alert.

Parameters
keyAlert key
Returns
whether operation was successful

◆ deleteProxy()

bool ManagementClient::deleteProxy ( const std::string &  serviceName)

Delete the current proxy endpoitn for the named service.

Normally called prior to the service shutting down.

Parameters
serviceNameTHe name of the service to sto the proxying for
Returns
bool True if the request succeeded

◆ getACL()

ACL ManagementClient::getACL ( const std::string &  aclName)

Return the content of the named ACL by calling the management API of the Fledge core.

Parameters
aclNameThe name of the ACL to return
Returns
ACL The ACL class
Exceptions
exceptionIf the ACL does not exist or the JSON result can not be parsed

◆ getAlertByKey()

std::string ManagementClient::getAlertByKey ( const std::string &  key)

Get an alert by specific key.

Parameters
keyKey to get alert
Returns
string Alert

◆ getAssetTrackingTuple()

AssetTrackingTuple * ManagementClient::getAssetTrackingTuple ( const std::string &  serviceName,
const std::string &  assetName,
const std::string &  event 
)

Get the asset tracking tuple for a service and asset name.

Parameters
serviceNameThe serviceName to restrict data fetch
assetNameThe asset name that belongs to the service
eventThe associated event type
Returns
A vector of pointers to AssetTrackingTuple objects allocated on heap

◆ getAssetTrackingTuples()

std::vector< AssetTrackingTuple * > & ManagementClient::getAssetTrackingTuples ( const std::string  serviceName = "")

Get the asset tracking tuples for a service or all services.

Parameters
serviceNameThe serviceName to restrict data fetch If empty records for all services are fetched
Returns
A vector of pointers to AssetTrackingTuple objects allocated on heap

◆ getCategories()

ConfigCategories ManagementClient::getCategories ( )

Get the set of all configuration categories from the core micro service.

Returns
ConfigCategories The set of all confguration categories

◆ getCategory()

ConfigCategory ManagementClient::getCategory ( const std::string &  categoryName)

Return the content of the named category by calling the management API of the Fledge core.

Parameters
categoryNameThe name of the categpry to return
Returns
ConfigCategory The configuration category
Exceptions
exceptionIf the category does not exist or the result can not be parsed

◆ getChildCategories()

ConfigCategories ManagementClient::getChildCategories ( const std::string &  categoryName)

Return child categories of a given category.

Parameters
categoryNameThe given category name
Returns
JSON string with current child categories
Exceptions
std::exception

◆ getDeprecatedAssetTrackingTuples()

AssetTrackingTable * ManagementClient::getDeprecatedAssetTrackingTuples ( )

Get the asset tracking tuples for all the deprecated assets.

Returns
A vector of pointers to AssetTrackingTuple objects allocated on heap

◆ getHttpClient()

HttpClient * ManagementClient::getHttpClient ( )

Creates a HttpClient object for each thread it stores/retrieves the reference to the HttpClient and the associated thread id in a map.

Returns
HttpClient The HTTP client connection to the core

◆ getService()

bool ManagementClient::getService ( ServiceRecord service)

Get the specified service.

Supplied with a service record that must either have the name or the type fields populated. The call will populate the other fields of the service record.

Note, if multiple service records match then only the first will be returned.

Parameters
serviceA partially filled service record that will be completed
Returns
bool Return true if the service record was found

◆ getServices()

bool ManagementClient::getServices ( std::vector< ServiceRecord *> &  services)

Return all services registered with the Fledge core.

Parameters
servicesA vector of service records that will be populated
Returns
bool True if the vecgtor was populated

◆ getStorageAssetTrackingTuple()

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

Get the asset tracking tuple for a service and asset name.

Parameters
serviceNameThe serviceName to restrict data fetch
assetNameThe asset name that belongs to the service
eventThe associated event type
dpThe datapoints Type
cThe count of datapoints
Returns
A pointer to AssetTrackingTuple objects allocated on heap

◆ getStorageAssetTrackingTuples()

std::vector< StorageAssetTrackingTuple * > & ManagementClient::getStorageAssetTrackingTuples ( const std::string  serviceName)

Get the storage asset tracking tuples for a service or all services.

Parameters
serviceNameThe serviceName to restrict data fetch If empty records for all services are fetched
Returns
A vector of pointers to AssetTrackingTuple objects allocated on heap

◆ raiseAlert()

bool ManagementClient::raiseAlert ( const std::string &  key,
const std::string &  message,
const std::string &  urgency = "normal" 
)

Raise an alert.

Parameters
keyAlert key
messageAlert message
urgencyAlert urgency
Returns
whether operation was successful

◆ refreshBearerToken()

bool ManagementClient::refreshBearerToken ( const std::string &  currentToken,
std::string &  newToken 
)

Refresh the JWT bearer token string.

Parameters
currentTokenCurrent bearer token
newTokenNew issued bearer token being set
Returns
True on success, false otherwise

◆ registerCategory()

bool ManagementClient::registerCategory ( const std::string &  categoryName)

Register interest in a configuration category.

Parameters
categoryThe name of the configuration category to register
Returns
bool True if the configuration category has been registered

◆ registerCategoryChild()

bool ManagementClient::registerCategoryChild ( const std::string &  categoryName)

Register interest in a configuration category.

The service will be called with the updated configuration category whenever an item in the category is added, removed or changed.

Parameters
categoryThe name of the category to register
Returns
bool True if the registration was succesful

◆ registerService()

bool ManagementClient::registerService ( const ServiceRecord service)

Register this service with the Fledge core.

Parameters
serviceThe service record of this service
Returns
bool True if the service registration was sucessful

◆ restartService()

bool ManagementClient::restartService ( )

Restart this service by sendign a request to the Fledge core.

Returns
bool True if the service successfully requested restart

◆ setCategoryItemValue()

string ManagementClient::setCategoryItemValue ( const std::string &  categoryName,
const std::string &  itemName,
const std::string &  itemValue 
)

Set a category configuration item value.

Parameters
categoryNameThe given category name
itemNameThe given item name
itemValueThe item value to set
Returns
JSON string of the updated category item
Exceptions
std::exception

◆ unregisterCategory()

bool ManagementClient::unregisterCategory ( const std::string &  categoryName)

Unregister interest in a configuration category.

The service will no longer be called when the configuration category is changed.

Parameters
categoryThe name of the configuration category to unregister
Returns
bool True if the configuration category is unregistered

◆ unregisterService()

bool ManagementClient::unregisterService ( )

Unregister this service with the Fledge core.

Returns
bool True if the service successfully unregistered

◆ validateDatapoints()

int ManagementClient::validateDatapoints ( std::string  dp1,
std::string  dp2 
)

Compare the datapoints to be equal or not, they can be '"' enclosed.

Parameters
dp1The datapoint to compare, enclosed in '"'
dp2The datapoint to compare
Returns
int integer depicting result of comparison, 0 on equal

◆ verifyAccessBearerToken()

bool ManagementClient::verifyAccessBearerToken ( BearerToken token)

Checks and validate the JWT bearer token object as reference.

Parameters
requestThe bearer token object
Returns
True on success, false otherwise

◆ verifyBearerToken()

bool ManagementClient::verifyBearerToken ( BearerToken bearerToken)

Checks and validate the JWT bearer token string.

Input token internal data will be set with new values or cached ones

Parameters
bearerTokenThe bearer token object
Returns
True on success, false otherwise

The documentation for this class was generated from the following files: