![]() |
Fledge
An open source edge computing platform for industrial users
|
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... | |
StorageAssetTrackingTuple * | 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. 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 ¤tToken, 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... | |
AssetTrackingTuple * | getAssetTrackingTuple (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... | |
AssetTrackingTable * | getDeprecatedAssetTrackingTuples () |
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) |
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.
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.
hostname | The hostname of the Fledge core micro service |
port | The port of the management service API listener in the Fledge core |
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.
service | Service name |
plugin | Plugin name |
asset | Asset name |
event | Event type |
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
code | The log code for the entry |
severity | The severity level |
message | The JSON message to log |
|
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'
string ManagementClient::addChildCategories | ( | const std::string & | parentCategory, |
const std::vector< std::string > & | children | ||
) |
Add child categories to a (parent) category.
parentCategory | The given category name |
children | Categories to add under parent |
std::exception |
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.
serviceName | The name of the service to send the request to |
operation | The type of operations; post, put, get or delete |
publicEndpoint | The URL inthe Fledge public API to be proxied |
privateEnpoint | The URL in the service API of the named service to which the reuests will be proxied. |
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.
service | Service name |
plugin | Plugin name |
asset | Asset name |
event | Event type |
deprecated | Deprecated or not |
datapoints | Datapoints type |
count | Count Type |
bool ManagementClient::clearAlert | ( | const std::string & | key | ) |
Clear an alert.
key | Alert key |
bool ManagementClient::deleteProxy | ( | const std::string & | serviceName | ) |
Delete the current proxy endpoitn for the named service.
Normally called prior to the service shutting down.
serviceName | THe name of the service to sto the proxying for |
ACL ManagementClient::getACL | ( | const std::string & | aclName | ) |
std::string ManagementClient::getAlertByKey | ( | const std::string & | key | ) |
Get an alert by specific key.
key | Key to get alert |
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.
serviceName | The serviceName to restrict data fetch |
assetName | The asset name that belongs to the service |
event | The associated event type |
std::vector< AssetTrackingTuple * > & ManagementClient::getAssetTrackingTuples | ( | const std::string | serviceName = "" | ) |
Get the asset tracking tuples for a service or all services.
serviceName | The serviceName to restrict data fetch If empty records for all services are fetched |
ConfigCategories ManagementClient::getCategories | ( | ) |
Get the set of all configuration categories from the core micro service.
ConfigCategory ManagementClient::getCategory | ( | const std::string & | categoryName | ) |
Return the content of the named category by calling the management API of the Fledge core.
categoryName | The name of the categpry to return |
exception | If the category does not exist or the result can not be parsed |
ConfigCategories ManagementClient::getChildCategories | ( | const std::string & | categoryName | ) |
Return child categories of a given category.
categoryName | The given category name |
std::exception |
AssetTrackingTable * ManagementClient::getDeprecatedAssetTrackingTuples | ( | ) |
Get the asset tracking tuples for all the deprecated assets.
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.
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.
service | A partially filled service record that will be completed |
bool ManagementClient::getServices | ( | std::vector< ServiceRecord *> & | services | ) |
Return all services registered with the Fledge core.
services | A vector of service records that will be populated |
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.
serviceName | The serviceName to restrict data fetch |
assetName | The asset name that belongs to the service |
event | The associated event type |
dp | The datapoints Type |
c | The count of datapoints |
std::vector< StorageAssetTrackingTuple * > & ManagementClient::getStorageAssetTrackingTuples | ( | const std::string | serviceName | ) |
Get the storage asset tracking tuples for a service or all services.
serviceName | The serviceName to restrict data fetch If empty records for all services are fetched |
bool ManagementClient::raiseAlert | ( | const std::string & | key, |
const std::string & | message, | ||
const std::string & | urgency = "normal" |
||
) |
Raise an alert.
key | Alert key |
message | Alert message |
urgency | Alert urgency |
bool ManagementClient::refreshBearerToken | ( | const std::string & | currentToken, |
std::string & | newToken | ||
) |
Refresh the JWT bearer token string.
currentToken | Current bearer token |
newToken | New issued bearer token being set |
bool ManagementClient::registerCategory | ( | const std::string & | categoryName | ) |
Register interest in a configuration category.
category | The name of the configuration category to register |
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.
category | The name of the category to register |
bool ManagementClient::registerService | ( | const ServiceRecord & | service | ) |
Register this service with the Fledge core.
service | The service record of this service |
bool ManagementClient::restartService | ( | ) |
Restart this service by sendign a request to the Fledge core.
string ManagementClient::setCategoryItemValue | ( | const std::string & | categoryName, |
const std::string & | itemName, | ||
const std::string & | itemValue | ||
) |
Set a category configuration item value.
categoryName | The given category name |
itemName | The given item name |
itemValue | The item value to set |
std::exception |
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.
category | The name of the configuration category to unregister |
bool ManagementClient::unregisterService | ( | ) |
Unregister this service with the Fledge core.
int ManagementClient::validateDatapoints | ( | std::string | dp1, |
std::string | dp2 | ||
) |
Compare the datapoints to be equal or not, they can be '"' enclosed.
dp1 | The datapoint to compare, enclosed in '"' |
dp2 | The datapoint to compare |
bool ManagementClient::verifyAccessBearerToken | ( | BearerToken & | token | ) |
Checks and validate the JWT bearer token object as reference.
request | The bearer token object |
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
bearerToken | The bearer token object |