10 std::vector<std::string>
17 return std::vector<std::string>();
20 return getRestContainers(
id);
23 std::vector<std::string>
30 return std::vector<std::string>();
33 return getRestItems(
id);
46 return restContainsContainer(
id, key);
59 return restContainsItem(
id, key);
65 std::vector<unsigned char>&
data)
74 writeItemToRest(
id, key,
data);
77 std::vector<unsigned char>
84 return std::vector<unsigned char>();
89 return readItemFromRest(
id, key);
92 return std::vector<unsigned char>();
97 const std::string& prefix)
99 defs->optional(host_, prefix +
"host");
100 defs->optional(port_, prefix +
"port");
106 std::string path =
"/ltm";
108 auto res = client_->Get(path);
113 <<
", port=" << port_;
119 <<
", port=" << port_;
125 RestPersistence::resetClient()
132 client_ = std::make_shared<httplib::Client>(host_, port_);
138 std::string path = buildPath(
id);
139 std::string query =
"item=" + key;
140 std::string url = path +
"?" + query;
142 ARMARX_DEBUG <<
"GET request: Read data from MemoryX-REST server: item=" << key
145 auto res = client_->Get(url);
151 ARMARX_DEBUG <<
"GET request successful: REST-LTM contain item with key=" << key;
158 ARMARX_DEBUG <<
"GET request successful: REST-LTM does not contain item with key="
166 ARMARX_DEBUG <<
"GET request failed. Status: " << res->status;
171 ARMARX_DEBUG <<
"GET request failed. No connection could be established to the "
172 "MemoryX-REST server at host="
173 << host_ <<
", port=" << port_;
182 std::string path = buildPath(
id);
183 std::string query =
"container=" + key;
184 std::string url = path +
"?" + query;
186 ARMARX_DEBUG <<
"GET request: Read data from MemoryX-REST server: container=" << key
189 auto res = client_->Get(url);
195 ARMARX_DEBUG <<
"GET request successful: REST-LTM contain container with key=" << key;
202 ARMARX_DEBUG <<
"GET request successful: REST-LTM does not contain container with key="
210 ARMARX_DEBUG <<
"GET request failed. Status: " << res->status;
215 ARMARX_DEBUG <<
"GET request failed. No connection could be established to the "
216 "MemoryX-REST server at host="
217 << host_ <<
", port=" << port_;
223 std::vector<std::string>
226 std::string path = buildPath(
id);
227 std::string query =
"items";
228 std::string url = path +
"?" + query;
230 ARMARX_DEBUG <<
"GET request: Get items from MemoryX-REST server: url=" << url;
232 auto res = client_->Get(url);
234 std::vector<std::string> item_keys;
242 nlohmann::json json_response = nlohmann::json::parse(res->body);
244 if (json_response.contains(
"keys") && json_response[
"keys"].is_array())
246 item_keys = json_response[
"keys"].get<std::vector<std::string>>();
249 catch (
const std::exception& e)
251 ARMARX_DEBUG <<
"GET request: Error parsing JSON: " << e.what();
256 ARMARX_DEBUG <<
"GET request failed. status=" << res->status <<
", url=" << url;
260 ARMARX_DEBUG <<
"GET request failed. No connection could be established to the "
261 "MemoryX-REST server at host="
262 << host_ <<
", port=" << port_;
268 std::vector<std::string>
271 std::string path = buildPath(
id);
272 std::string query =
"containers";
273 std::string url = path +
"?" + query;
275 ARMARX_DEBUG <<
"GET request: Get containers from MemoryX-REST server: url=" << url;
277 auto res = client_->Get(url);
279 std::vector<std::string> item_keys;
287 nlohmann::json json_response = nlohmann::json::parse(res->body);
289 if (json_response.contains(
"keys") && json_response[
"keys"].is_array())
291 item_keys = json_response[
"keys"].get<std::vector<std::string>>();
294 catch (
const std::exception& e)
296 ARMARX_ERROR <<
"GET request: Error parsing JSON: " << e.what();
301 ARMARX_DEBUG <<
"GET request failed. status=" << res->status <<
", url=" << url;
305 ARMARX_DEBUG <<
"GET request failed. No connection could be established to the "
306 "MemoryX-REST server at host="
307 << host_ <<
", port=" << port_;
313 std::vector<unsigned char>
316 std::string path = buildPath(
id);
317 std::string query =
"item=" + key;
318 std::string url = path +
"?" + query;
320 ARMARX_DEBUG <<
"GET request: Read data from MemoryX-REST server: key=" << key
323 auto res = client_->Get(url);
325 std::vector<unsigned char>
data;
331 data = std::vector<unsigned char>(res->body.begin(), res->body.end());
335 ARMARX_DEBUG <<
"GET request failed: REST-LTM does not contain any item with key="
340 ARMARX_DEBUG <<
"GET request failed. status=" << res->status <<
", key=" << key
345 ARMARX_DEBUG <<
"GET request failed. No connection could be established to the "
346 "MemoryX-REST server at host="
347 << host_ <<
", port=" << port_;
356 const std::vector<unsigned char>&
data)
358 std::string path = buildPath(
id);
359 std::string query =
"item=" + key;
360 std::string url = path +
"?" + query;
362 ARMARX_DEBUG <<
"PUT request: Write data to MemoryX-REST server: key=" << key
365 std::string body(
data.begin(),
data.end());
367 auto res = client_->Put(url, body,
"application/json");
375 ARMARX_DEBUG <<
"PUT request failed. status=" << res->status <<
", key=" << key
380 ARMARX_DEBUG <<
"PUT request failed. No connection could be established to the "
381 "MemoryX-REST server at host="
382 << host_ <<
", port=" << port_;
389 nlohmann::json& jsonData)
391 std::string str_data = jsonData.dump();
392 std::vector<unsigned char>
data(str_data.begin(), str_data.end());
401 const std::vector<unsigned char>&
data)
403 std::string path = buildPath(
id);
404 std::string mime_type = getMimeType(type);
405 std::string query =
"?item=" + key;
407 std::string body(
data.begin(),
data.end());
409 auto res = client_->Put(path + query, body, mime_type);
418 ARMARX_DEBUG <<
"Request failed. Error: " << res.error();
425 std::string path = buildPath(
id);
426 std::string query =
"item=" + key;
427 std::string url = path +
"?" + query;
429 ARMARX_DEBUG <<
"DELETE request: Remove item from MemoryX-REST server: key=" << key
433 auto res = client_->Delete(url);
437 ARMARX_DEBUG <<
"DELETE request successful: " << res->body;
441 ARMARX_DEBUG <<
"DELETE request failed. REST-LTM does not contain any item with key="
446 ARMARX_DEBUG <<
"DELETE request failed. Status: " << res->status;
450 ARMARX_DEBUG <<
"DELETE request failed. No connection could be established to the "
451 "MemoryX-REST server at host="
452 << host_ <<
", port=" << port_;
457 RestPersistence::setPort(
int port)
464 RestPersistence::getPort()
const
470 RestPersistence::setHost(std::string& host)
477 RestPersistence::getHost()
487 if (
id.hasMemoryName())
491 if (
id.hasCoreSegmentName())
496 if (
id.hasProviderSegmentName())
499 id.providerSegmentName);
501 if (
id.hasEntityName())
505 if (
id.hasTimestamp())
507 url +=
"/" +
id.timestampStr();
509 if (
id.hasInstanceIndex())
511 url +=
"/" +
id.instanceIndexStr();
518 RestPersistence::getMimeType(
DataType type)
521 std::string mime_type;
525 mime_type =
"application/json";
529 mime_type =
"image/png";