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

The Storage API class - this class is responsible for the registration of all API entry points in the storage API and the dispatch of those API calls to the internals of the storage service and the storage plugin itself. More...

#include <storage_api.h>

Public Member Functions

 StorageApi (const unsigned short port, const unsigned int threads, const unsigned int workerPoolSize)
 Construct the singleton Storage API.
 
 ~StorageApi ()
 Destructor for the storage API class. More...
 
void initResources ()
 Initialise the API entry points for the common data resource and the readings resource.
 
void setPlugin (StoragePlugin *)
 Connect with the storage plugin.
 
void setReadingPlugin (StoragePlugin *)
 Connect with the storage plugin.
 
void start ()
 Start the HTTP server.
 
void startServer ()
 
void wait ()
 Wait for the HTTP server to shutdown.
 
void stopServer ()
 
unsigned short getListenerPort ()
 Return the current listener port.
 
void commonInsert (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform an insert into a table of the data provided in the payload. More...
 
void commonSimpleQuery (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform a simple query on the table using the query parameters as conditions TODO make this work for multiple column queries. More...
 
void commonQuery (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform query on a table using the JSON encoded query in the payload. More...
 
void commonUpdate (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform an update on a table of the data provided in the payload. More...
 
void commonDelete (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform a delete on a table using the condition encoded in the JSON payload. More...
 
void defaultResource (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Handle a bad URL endpoint call.
 
void readingAppend (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform an append operation on the readings. More...
 
void readingFetch (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Fetch a block of readings. More...
 
void readingQuery (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform a query on a set of readings. More...
 
void readingPurge (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Purge the readings. More...
 
void readingRegister (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Register interest in readings for an asset.
 
void readingUnregister (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Unregister interest in readings for an asset.
 
void tableRegister (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Register interest in readings for an asset.
 
void tableUnregister (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Unregister interest in readings for an asset.
 
void createTableSnapshot (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Create a table snapshot.
 
void loadTableSnapshot (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Load a table snapshot.
 
void deleteTableSnapshot (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Delete a table snapshot.
 
void getTableSnapshots (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Get list of a table snapshots.
 
void createStorageStream (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Create a stream for high speed storage ingestion. More...
 
bool readingStream (ReadingStream **readings, bool commit)
 Append the readings that have arrived via a stream to the storage plugin. More...
 
void createStorageSchema (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform an create table and create index for schema provided in the payload. More...
 
void storageTableInsert (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform an insert table operation. More...
 
void storageTableUpdate (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform an update on a table of the data provided in the payload. More...
 
void storageTableDelete (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform a delete on a table using the condition encoded in the JSON payload. More...
 
void storageTableSimpleQuery (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform a simple query on the table using the query parameters as conditions TODO make this work for multiple column queries. More...
 
void storageTableQuery (shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request)
 Perform query on a table using the JSON encoded query in the payload. More...
 
void printList ()
 
bool createSchema (const std::string &schema)
 
void setTimeout (long timeout)
 
StoragePlugingetStoragePlugin ()
 
StoragePerformanceMonitorgetPerformanceMonitor ()
 
void worker ()
 The worker thread.
 
void queue (StorageOperation::Operations op, shared_ptr< HttpServer::Request > request, shared_ptr< HttpServer::Response > response)
 Append a request to the readings request queue. More...
 

Static Public Member Functions

static StorageApigetInstance ()
 Return the singleton instance of the StorageAPI class.
 

Public Attributes

std::atomic< int > m_workers_count
 

Detailed Description

The Storage API class - this class is responsible for the registration of all API entry points in the storage API and the dispatch of those API calls to the internals of the storage service and the storage plugin itself.

Constructor & Destructor Documentation

◆ ~StorageApi()

StorageApi::~StorageApi ( )

Destructor for the storage API class.

There is only ever one StorageApi class in existance and it lives for the entire duration of the storage service, so this is really for completeness rather than any pracitical use.

Member Function Documentation

◆ commonDelete()

void StorageApi::commonDelete ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform a delete on a table using the condition encoded in the JSON payload.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ commonInsert()

void StorageApi::commonInsert ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform an insert into a table of the data provided in the payload.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ commonQuery()

void StorageApi::commonQuery ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform query on a table using the JSON encoded query in the payload.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ commonSimpleQuery()

void StorageApi::commonSimpleQuery ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform a simple query on the table using the query parameters as conditions TODO make this work for multiple column queries.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ commonUpdate()

void StorageApi::commonUpdate ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform an update on a table of the data provided in the payload.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ createStorageSchema()

void StorageApi::createStorageSchema ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform an create table and create index for schema provided in the payload.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ createStorageStream()

void StorageApi::createStorageStream ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Create a stream for high speed storage ingestion.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ queue()

void StorageApi::queue ( StorageOperation::Operations  op,
shared_ptr< HttpServer::Request >  request,
shared_ptr< HttpServer::Response >  response 
)

Append a request to the readings request queue.

If the queue is starting to get long delay the return as a primitive way to throttle incoming requests

Parameters
opThe operation to perform
requestThe HTTP request
responseThe HTTP response

◆ readingAppend()

void StorageApi::readingAppend ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform an append operation on the readings.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ readingFetch()

void StorageApi::readingFetch ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Fetch a block of readings.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ readingPurge()

void StorageApi::readingPurge ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Purge the readings.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

Handle PluginNotImplementedException exception here

Return HTTP code 400 with message from storage plugin

Handle general exception

◆ readingQuery()

void StorageApi::readingQuery ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform a query on a set of readings.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ readingStream()

bool StorageApi::readingStream ( ReadingStream **  readings,
bool  commit 
)

Append the readings that have arrived via a stream to the storage plugin.

Parameters
readingsA Null terminated array of points to ReadingStream structures
commitA flag to commit the readings block

◆ storageTableDelete()

void StorageApi::storageTableDelete ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform a delete on a table using the condition encoded in the JSON payload.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ storageTableInsert()

void StorageApi::storageTableInsert ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform an insert table operation.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ storageTableQuery()

void StorageApi::storageTableQuery ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform query on a table using the JSON encoded query in the payload.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ storageTableSimpleQuery()

void StorageApi::storageTableSimpleQuery ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform a simple query on the table using the query parameters as conditions TODO make this work for multiple column queries.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

◆ storageTableUpdate()

void StorageApi::storageTableUpdate ( shared_ptr< HttpServer::Response >  response,
shared_ptr< HttpServer::Request >  request 
)

Perform an update on a table of the data provided in the payload.

Parameters
responseThe response stream to send the response on
requestThe HTTP request

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