1 #ifndef _STORAGE_CLIENT_H 2 #define _STORAGE_CLIENT_H 12 #include <client_http.hpp> 14 #include <reading_set.h> 15 #include <resultset.h> 16 #include <purge_result.h> 19 #include <json_properties.h> 20 #include <expression.h> 21 #include <update_modifier.h> 27 using HttpClient = SimpleWeb::Client<SimpleWeb::HTTP>;
29 #define STREAM_BLK_SIZE 100 // Readings to send per write call to a stream 30 #define STREAM_THRESHOLD 25 // Switch to streamed mode above this number of readings per second 33 #define SC_INITIAL_BACKOFF 100 34 #define SC_MAX_BACKOFF 1000 36 #define DEFAULT_SCHEMA "fledge" 46 StorageClient(
const std::string& hostname,
const unsigned short port);
51 int insertTable(
const std::string& schema,
const std::string& tableName,
const InsertValues& values);
52 int insertTable(
const std::string& schema,
const std::string& tableName,
53 const std::vector<InsertValues>& values);
54 int insertTable(
const std::string& tableName,
const std::vector<InsertValues>& values);
58 int updateTable(
const std::string& schema,
const std::string& tableName,
const InsertValues& values,
60 int updateTable(
const std::string& schema,
const std::string& tableName,
const JSONProperties& json,
62 int updateTable(
const std::string& schema,
const std::string& tableName,
const InsertValues& values,
64 int updateTable(
const std::string& schema,
const std::string& tableName,
const ExpressionValues& values,
66 int updateTable(
const std::string& schema,
const std::string& tableName,
67 std::vector<std::pair<ExpressionValues *, Where *>>& updates,
const UpdateModifier *modifier = NULL);
68 int updateTable(
const std::string& schema,
const std::string& tableName,
const InsertValues& values,
70 int deleteTable(
const std::string& schema,
const std::string& tableName,
const Query& query);
71 int insertTable(
const std::string& tableName,
const InsertValues& values);
78 int updateTable(
const std::string& tableName, std::vector<std::pair<ExpressionValues *, Where *>>& updates,
82 int updateTable(
const std::string& schema,
const std::string& tableName,
83 std::vector<std::pair<InsertValue*, Where* > > &updates,
const UpdateModifier *modifier);
85 int updateTable(
const std::string& tableName, std::vector<std::pair<InsertValue*, Where*> >& updates,
98 const std::string& callbackUrl);
100 const std::string& callbackUrl);
102 std::vector<std::string> keyValues,
const std::string& operation,
const std::string& callbackUrl);
104 std::vector<std::string> keyValues,
const std::string& operation,
const std::string& callbackUrl);
110 void handleUnexpectedResponse(
const char *operation,
111 const std::string& table,
112 const std::string& responseCode,
113 const std::string& payload);
114 void handleUnexpectedResponse(
const char *operation,
115 const std::string& responseCode,
116 const std::string& payload);
117 void handleException(
const std::exception& ex,
const char *operation, ...);
118 HttpClient *getHttpClient(
void);
120 bool streamReadings(
const std::vector<Reading *> & readings);
122 std::ostringstream m_urlbase;
124 std::map<std::thread::id, HttpClient *> m_client_map;
125 std::map<std::thread::id, std::atomic<int>> m_seqnum_map;
130 uint32_t m_readingBlock;
131 std::string m_lastException;
Fledge Logger class used to log to syslog.
Definition: logger.h:26
ReadingSet * readingQueryToReadings(const Query &query)
Perform a generic query against the readings data, returning ReadingSet object.
Definition: storage_client.cpp:302
~StorageClient()
Destructor for storage client.
Definition: storage_client.cpp:75
ResultSet * readingQuery(const Query &query)
Perform a generic query against the readings data.
Definition: storage_client.cpp:267
PurgeResult readingPurgeBySize(unsigned long size, unsigned long sent, bool purgeUnsent)
Purge the readings by size.
Definition: storage_client.cpp:409
Update modifier.
Definition: update_modifier.h:18
bool registerAssetNotification(const std::string &assetName, const std::string &callbackUrl)
Register interest for a Reading asset name.
Definition: storage_client.cpp:1216
Class that defines JSON properties for update.
Definition: json_properties.h:53
bool registerTableNotification(const std::string &tableName, const std::string &key, std::vector< std::string > keyValues, const std::string &operation, const std::string &callbackUrl)
Register interest for a table.
Definition: storage_client.cpp:1300
bool readingAppend(Reading &reading)
Append a single reading.
Definition: storage_client.cpp:145
Storage layer query container.
Definition: query.h:25
The management client class used by services and tasks to communicate with the management API of the ...
Definition: management_client.h:43
Result set.
Definition: resultset.h:32
bool unregisterTableNotification(const std::string &tableName, const std::string &key, std::vector< std::string > keyValues, const std::string &operation, const std::string &callbackUrl)
Unregister interest for a table name.
Definition: storage_client.cpp:1356
StorageClient(HttpClient *client)
Storage Client constructor stores the provided HttpClient into the map.
Definition: storage_client.cpp:61
An asset reading represented as a class.
Definition: reading.h:33
Reading set class.
Definition: reading_set.h:26
ReadingSet * queryTableToReadings(const std::string &tableName, const Query &query)
Query a table and return a ReadingSet pointer.
Definition: storage_client.cpp:518
bool createSchema(const std::string &)
Function to create Storage Schema.
Definition: storage_client.cpp:1752
Client for accessing the storage service.
Definition: storage_client.h:43
ResultSet * queryTable(const std::string &schema, const std::string &tablename, const Query &query)
Query a table.
Definition: storage_client.cpp:482
PurgeResult readingPurgeByAsset(const std::string &asset)
Purge the readings by asset name.
Definition: storage_client.cpp:439
bool deleteHttpClient()
Delete HttpClient object for current thread.
Definition: storage_client.cpp:90
Definition: expression.h:68
PurgeResult readingPurgeByAge(unsigned long age, unsigned long sent, bool purgeUnsent)
Purge the readings by age.
Definition: storage_client.cpp:376
int deleteTable(const std::string &schema, const std::string &tableName, const Query &query)
Delete from a table.
Definition: storage_client.cpp:1122
bool unregisterAssetNotification(const std::string &assetName, const std::string &callbackUrl)
Unregister interest for a Reading asset name.
Definition: storage_client.cpp:1258
Definition: purge_result.h:22
ReadingSet * readingFetch(const unsigned long readingId, const unsigned long count)
Retrieve a set of readings for sending on the northbound interface of Fledge.
Definition: storage_client.cpp:338
Where clause in a selection of records.
Definition: where.h:31