3#include <SimoxUtility/algorithm/string/string_tools.h>
32 plugin->setMemoryName(memoryName);
36 data::AddSegmentsResult
40 bool addCoreSegmentOnUsage =
false;
44 data::AddSegmentsResult
68 { coreSegment.clear(); });
72 armem::query::data::Result
79 armem::query::data::Result
88 structure::data::GetServerStructureResult
96 dto::DirectlyStoreResult
103 dto::StartRecordResult
111 dto::StopRecordResult
118 dto::RecordStatusResult
134 return plugin->workingMemory;
140 return plugin->iceAdapter;
146 return plugin->longtermMemory;
150 armem::actions::GetActionsOutputSeq
152 const ::Ice::Current& )
157 armem::actions::GetActionsOutputSeq
164 armem::actions::ExecuteActionOutputSeq
166 const ::Ice::Current& )
171 armem::actions::ExecuteActionOutputSeq
178 armem::prediction::data::PredictionResultSeq
184 armem::prediction::data::EngineSupportMap
190 armem::prediction::data::PredictionResultSeq
192 const ::Ice::Current& )
197 armem::prediction::data::EngineSupportMap
214 const std::string& exportName,
215 const std::string& host,
217 bool overwritePrevStrategy,
218 const ::Ice::Current&)
222 std::shared_ptr<armem::server::ltm::persistence::RestPersistence> restPersistence =
223 std::make_shared<armem::server::ltm::persistence::RestPersistence>(
224 identifier, exportName, host, port);
231 ARMARX_INFO <<
"OverwritePrevStrategy=" << overwritePrevStrategy;
233 if (overwritePrevStrategy)
246 const std::string& exportName,
247 const std::string& exportPath,
248 bool overwritePrevStrategy,
249 const ::Ice::Current&)
253 std::shared_ptr<armem::server::ltm::persistence::DiskPersistence> diskPersistence =
254 std::make_shared<armem::server::ltm::persistence::DiskPersistence>(
255 identifier, exportName, std::filesystem::path(exportPath));
261 ARMARX_INFO <<
"OverwritePrevStrategy=" << overwritePrevStrategy;
263 if (overwritePrevStrategy)
276 const std::string& exportName,
277 bool overwritePrevStrategy,
278 const ::Ice::Current&)
299 const std::string& memoryName,
300 const std::vector<std::string>& coreSegmentNames,
301 bool addNonExistingCoreSegments,
302 int amountOfSnapshotsPerSegmentToLoad,
303 const ::Ice::Current&)
307 auto splitAtLastSlash =
308 [
this, &export_path](
const std::string& input) -> std::pair<std::string, std::string>
310 size_t lastSlash = input.rfind(
'/');
312 if (lastSlash == std::string::npos)
315 <<
"Could not load LTM into WM, as the given export_path does not contain '/', "
316 "which it needs to in order to split into directory_path and exportName. \n"
317 <<
"The path you have provided is: \n"
322 std::string first = input.substr(0, lastSlash);
323 std::string second = input.substr(lastSlash + 1);
327 return {first, second};
331 size_t secondLastSlash = input.rfind(
'/', lastSlash - 1);
332 if (secondLastSlash == std::string::npos)
334 ARMARX_ERROR <<
"The path you provided to load the LTM into the WM ends with a '/' "
335 "but does not contain any further '/'. "
336 <<
"Check if you provided the correct path. The path needs to consist "
337 "of a path to a directory, a '/' as a divider, and the name of the "
338 "export directory.\n"
339 <<
"You have given the following path: \n"
344 return {input.substr(0, secondLastSlash),
345 input.substr(secondLastSlash + 1, lastSlash - secondLastSlash - 1)};
348 auto [directory, exportName] = splitAtLastSlash(export_path);
349 if (directory ==
"" && exportName ==
"")
357 addNonExistingCoreSegments,
358 amountOfSnapshotsPerSegmentToLoad);
363 const std::string& exportName,
364 const std::string& memoryName,
365 const std::vector<std::string>& coreSegmentNames,
366 bool addNonExistingCoreSegments,
367 int amountOfSnapshotsPerSegmentToLoad)
376 if (addNonExistingCoreSegments)
379 <<
"You tried to set addNonExistingCoreSegments to true, this is not supported yet";
383 std::filesystem::path path(directory);
384 path.append(exportName);
385 path.append(memoryName);
388 if (not std::filesystem::is_directory(path))
390 ARMARX_WARNING <<
"You are trying to load data from a path which does not exist";
397 bool isSingleMemory =
false;
398 for (
auto i = std::filesystem::recursive_directory_iterator(path);
399 i != std::filesystem::recursive_directory_iterator();
407 <<
"You are trying to import a directory which does not contain memory data";
415 if (std::filesystem::is_regular_file(dir.path()) &&
416 simox::alg::starts_with(dir.path().filename(),
"data.aron"))
419 MemoryPersistenceStrategy::DEPTH_TO_DATA_FILES);
424 << armem::server::ltm::persistence::MemoryPersistenceStrategy::
434 <<
" and write it to the current WM"
436 <<
"Reason: the path you have given is not a single memory but contains "
437 "more than one memory";
441 ARMARX_DEBUG <<
"Now loading data from filesystem LTM...";
445 if (std::filesystem::is_directory(directory))
447 std::string defaultIdent =
"DefaultDisk";
448 ARMARX_INFO <<
"Path of the folder trying to import: " << path;
449 std::shared_ptr<armem::server::ltm::persistence::DiskPersistence> diskPersistence =
450 std::make_shared<armem::server::ltm::persistence::DiskPersistence>(
451 defaultIdent, exportName, path.parent_path().parent_path());
454 if (
ltm.getPersistenceStrategy())
456 ltm.getPersistenceStrategy()->addStrategy(diskPersistence);
460 std::shared_ptr<armem::server::ltm::persistence::RedundantPersistenceStrategy>
461 redundantPersistence = std::make_shared<
464 ltm.setPersistenceStrategy(redundantPersistence);
465 ltm.getPersistenceStrategy()->addStrategy(diskPersistence);
470 if (amountOfSnapshotsPerSegmentToLoad != -1)
472 ARMARX_INFO <<
"You specified amountOfSnapshotsPerSegmentToLoad = "
473 << std::to_string(amountOfSnapshotsPerSegmentToLoad);
474 if (coreSegmentNames.size() != 0)
476 std::list<std::string> lst(coreSegmentNames.begin(), coreSegmentNames.end());
477 ltm.loadLatestNReferences(amountOfSnapshotsPerSegmentToLoad,
memory, lst);
481 memory =
ltm.loadLatestNReferences(amountOfSnapshotsPerSegmentToLoad);
487 if (coreSegmentNames.size() != 0)
489 std::list<std::string> lst(coreSegmentNames.begin(), coreSegmentNames.end());
498 memoryData = std::move(
memory);
505 data::Commit iceCommit;
509 ARMARX_INFO <<
"Successfully loaded data from " << path
510 <<
" into the current working memory";
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
bool forEachCoreSegment(CoreSegmentFunctionT &&func)
Helps connecting a Memory server to the Ice interface.
server::wm::Memory * workingMemory
armem::structure::data::GetServerStructureResult getServerStructure()
dto::StartRecordResult startRecord(const dto::StartRecordInput &startRecordInput)
armem::CommitResult reloadFromLTMOnStartup()
Triggers a reload (.
armem::CommitResult reloadAllFromLTM()
Loads all core segments and their data from the LTM.
query::data::Result queryLTM(const armem::query::data::Input &input, bool storeIntoWM)
Query the LTMs of the memory server.
dto::StopRecordResult stopRecord()
query::data::Result query(const armem::query::data::Input &input)
prediction::data::PredictionResultSeq predict(prediction::data::PredictionRequestSeq requests)
dto::DirectlyStoreResult directlyStore(const dto::DirectlyStoreInput &directlStoreInput)
armem::CommitResult reloadPropertyDefinedCoreSegmentsFromLTM()
server::ltm::Memory * longtermMemory
dto::RecordStatusResult getRecordStatus()
data::CommitResult commitLocking(const data::Commit &commitIce, Time timeArrived)
prediction::data::EngineSupportMap getAvailableEngines()
data::AddSegmentsResult addSegments(const data::AddSegmentsInput &input, bool addCoreSegments=false)
A memory storing data on the hard drive and in mongodb (needs 'armarx memory start' to start the mong...
std::shared_ptr< persistence::RedundantPersistenceStrategy > getPersistenceStrategy() const
MemoryID getMemoryID() const
static const int DEPTH_TO_DATA_FILES
Basically the option to use multiple ltm sinks as source or target.
virtual void useDiskPersistenceStrategy(const std::string &identifier, const std::string &exportName, const std::string &exportPath, bool overwritePrevStrategy, const ::Ice::Current &) override
Use a disk persistence strategy for storing the wm as ltm Uses the disk as ltm sink.
server::ltm::Memory & longtermMemory()
virtual dto::StopRecordResult stopRecord(const Ice::Current &=Ice::emptyCurrent) override
virtual armem::query::data::Result query(const armem::query::data::Input &input, const Ice::Current &=Ice::emptyCurrent) override
void setMemoryName(const std::string &memoryName)
server::wm::Memory & workingMemory()
virtual data::CommitResult commit(const data::Commit &commit, const Ice::Current &=Ice::emptyCurrent) override
virtual armem::query::data::Result queryLTM(const armem::query::data::Input &input, bool storeIntoWM, const Ice::Current &=Ice::emptyCurrent) override
Queries only the LTMs of the memory server.
Plugin & memoryServerPlugin()
virtual void loadLTMintoWM(bool complete, const ::Ice::Current &) override
Loads the data of the LTMs into the WM.
virtual dto::RecordStatusResult getRecordStatus(const Ice::Current &=Ice::emptyCurrent) override
virtual armem::actions::ExecuteActionOutputSeq executeActions(const armem::actions::ExecuteActionInputSeq &inputs)
virtual data::AddSegmentsResult addSegments(const data::AddSegmentsInput &input, const Ice::Current &=Ice::emptyCurrent) override
bool loadExportIntoWM(const std::string &export_path, const std::string &memoryName, const std::vector< std::string > &coreSegmentName={}, bool addNonExistingCoreSegments=false, int amountOfSnapshotsPerSegmentToLoad=-1, const ::Ice::Current &=Ice::emptyCurrent) override
loads data from a specified LTM export into the currently running WM (needs to already have the CoreS...
virtual dto::StartRecordResult startRecord(const dto::StartRecordInput &startRecordInput, const Ice::Current &=Ice::emptyCurrent) override
MemoryToIceAdapter & iceAdapter()
virtual dto::DirectlyStoreResult directlyStore(const dto::DirectlyStoreInput &, const Ice::Current &=Ice::emptyCurrent) override
armem::CommitResult reloadFromLTM()
virtual void useMongoDbPersistenceStrategy(const std::string &identifier, const std::string &exportName, bool overwritePrevStrategy, const ::Ice::Current &) override
Use a mongodb persistence strategy for storing the wm as ltm Uses a mongodb as ltm sink.
virtual armem::actions::GetActionsOutputSeq getActions(const armem::actions::GetActionsInputSeq &inputs)
virtual void clearWorkingMemory(const Ice::Current &=Ice::emptyCurrent) override
Clears the working memory usings its clear feature.
virtual ~ReadWritePluginUser() override
virtual armem::structure::data::GetServerStructureResult getServerStructure(const Ice::Current &=Ice::emptyCurrent) override
virtual void useRestPersistenceStrategy(const std::string &identifier, const std::string &exportName, const std::string &host, int port, bool overwritePrevStrategy, const ::Ice::Current &) override
Use a rest persistence strategy for storing the wm as ltm Uses a rest server as ltm sink.
virtual armem::prediction::data::EngineSupportMap getAvailableEngines()
virtual armem::prediction::data::PredictionResultSeq predict(const armem::prediction::data::PredictionRequestSeq &requests)
Client-side working memory.
Brief description of class memory.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Commit toCommit(const ContainerT &container)
void toIce(data::MemoryID &ice, const MemoryID &id)