RestPersistence Class Reference

Persistence strategy that uses a rest server as its data sink. More...

#include <RobotAPI/libraries/armem/server/ltm/persistence/rest/RestPersistence.h>

+ Inheritance diagram for RestPersistence:

Public Member Functions

bool checkConnection ()
 Checks if the server is up. More...
 
bool containsContainer (const armarx::armem::MemoryID &id, std::string key) override
 
bool containsItem (const armarx::armem::MemoryID &id, std::string key) override
 
void createPropertyDefinitions (PropertyDefinitionsPtr &defs, const std::string &prefix) override
 
std::vector< std::string > getContainerKeys (const armarx::armem::MemoryID &id) override
 Returns keys that allow use to move a step further in the hierarchy (e.g. More...
 
std::vector< std::string > getItemKeys (const armarx::armem::MemoryID &id) override
 Keys of the actual items containing data stored for the memory id. More...
 
 RestPersistence ()
 
 RestPersistence (const std::string &identifier, const std::string &exportName)
 
 RestPersistence (const std::string &identifier, const std::string &exportName, const std::string &host, int port, bool disableIfNotAvailable=false)
 
std::vector< unsigned char > retrieveItem (const armarx::armem::MemoryID &id, std::string key) override
 Retrieve the actual data of an item stored for the memory id. More...
 
void storeItem (const armarx::armem::MemoryID &id, std::string key, std::vector< unsigned char > &data) override
 Stores an item containing actual data for the current memory id. More...
 
- Public Member Functions inherited from MemoryPersistenceStrategy
virtual void disable ()
 
virtual void enable ()
 
std::string getExportName ()
 
std::string getIdentifier ()
 
virtual bool isEnabled ()
 
 MemoryPersistenceStrategy ()
 
 MemoryPersistenceStrategy (const std::string &identifier, const std::string &exportName, bool enabled=true)
 
std::vector< unsigned char > retrieveItem (const armarx::armem::MemoryID &memoryId, ItemIdentifier itemIdentifier)
 
virtual ItemResult retrieveItemWithOrigin (const armarx::armem::MemoryID &id, std::string &key)
 Retrieves the actual data but also appends the origin which is in this case the strategy identifier. More...
 
virtual void setExportName (const std::string &exportName)
 
void setIdentifier (const std::string &identifier)
 
void storeItem (const armarx::armem::MemoryID &memoryId, ItemIdentifier itemIdentifer, std::vector< unsigned char > &data)
 
virtual ~MemoryPersistenceStrategy ()=default
 

Static Public Attributes

const static std::string DEFAULT_HOST = "localhost"
 
const static int DEFAULT_PORT = 8080
 
- Static Public Attributes inherited from MemoryPersistenceStrategy
static const constexpr char * DATA_FILENAME = "data.aron"
 
static const int DEPTH_TO_DATA_FILES = 7
 
static const constexpr char * MEMORY_EXPORT_SUFFIX = "_"
 
static const constexpr char * METADATA_FILENAME = "metadata.aron"
 
static const constexpr char * TYPE_FILENAME = "type.aron"
 

Additional Inherited Members

- Protected Attributes inherited from MemoryPersistenceStrategy
bool enabled_ = true
 If false, the strategy is not writing or reading anything. More...
 
std::string exportName_
 Name of the specific memory export where our items should be stored. More...
 
std::string identifier_
 Name of the strategy. More...
 

Detailed Description

Persistence strategy that uses a rest server as its data sink.

How the data is stored on the rest server is up to the server.

The structure of rest endpoints are very similar to a directory structure.

General endpoint: /endpoint GET: /endpoint?containers: return all container keys of the endpoint GET: /endpoint?container=key: check if a container with key exists (true = Status Code 200, false = Status Code 404) GET: /endpoint?items: return all item keys of the endpoint GET: /endpoint?item=key: return Status Code 200 with item data OR Status Code 404 if the item is not inside of the container PUT: /endpoint?item: store item data (data = http body content) DELETE: /endpoint?item=key: removes item with key, return Status Code 200 on success and Status Code 404 if item not found DELETE: /endpoint?container=key: removes container with key, return Status Code 200 on success and Status Code 404 if container not found

NOTE: DELETE-methods are implemented, but the curren memory system does not use it in general.

Available endpoints: /ltm/:exportName -> memories /ltm/:exportName/:memoryName -> core segments /ltm/:exportName/:memoryName/:coreSegmentName -> provider segments /ltm/:exportName/:memoryName/:coreSegmentName/:providerSegmentName -> entities /ltm/:exportName/:memoryName/:coreSegmentName/:providerSegmentName/:entityName -> entity snapshots /ltm/:exportName/:memoryName/:coreSegmentName/:providerSegmentName/:entityName/:timestamp -> entity instances /ltm/:exportName/:memoryName/:coreSegmentName/:providerSegmentName/:entityName/:timestamp/:instanceIndex -> entity instance (here you will definitely find some items)

Definition at line 51 of file RestPersistence.h.

Constructor & Destructor Documentation

◆ RestPersistence() [1/3]

RestPersistence ( )
inline

Definition at line 54 of file RestPersistence.h.

◆ RestPersistence() [2/3]

RestPersistence ( const std::string &  identifier,
const std::string &  exportName 
)
inline

Definition at line 56 of file RestPersistence.h.

◆ RestPersistence() [3/3]

RestPersistence ( const std::string &  identifier,
const std::string &  exportName,
const std::string &  host,
int  port,
bool  disableIfNotAvailable = false 
)
inline
Parameters
identifierbasically a unique name for the strategy (important if you use different strategies
See also
RedundantPersistenceStrategy)
Parameters
exportNameidentifier for the exported memory where any items are written. Changes http endpoints.
idmemory id, gives us the hierarchy depth to store some items for it (e.g. a core segment)
hostrest server address (e.g. localhost or a specific ip or a domain)
portnetwork port where the rest server runs

Definition at line 65 of file RestPersistence.h.

+ Here is the call graph for this function:

Member Function Documentation

◆ checkConnection()

bool checkConnection ( )

Checks if the server is up.

Definition at line 92 of file RestPersistence.cpp.

+ Here is the caller graph for this function:

◆ containsContainer()

bool containsContainer ( const armarx::armem::MemoryID id,
std::string  key 
)
overridevirtual

Implements MemoryPersistenceStrategy.

Definition at line 33 of file RestPersistence.cpp.

◆ containsItem()

bool containsItem ( const armarx::armem::MemoryID id,
std::string  key 
)
overridevirtual

Implements MemoryPersistenceStrategy.

Definition at line 45 of file RestPersistence.cpp.

+ Here is the caller graph for this function:

◆ createPropertyDefinitions()

void createPropertyDefinitions ( PropertyDefinitionsPtr defs,
const std::string &  prefix 
)
overridevirtual

Implements MemoryPersistenceStrategy.

Definition at line 86 of file RestPersistence.cpp.

◆ getContainerKeys()

std::vector< std::string > getContainerKeys ( const armarx::armem::MemoryID id)
overridevirtual

Returns keys that allow use to move a step further in the hierarchy (e.g.

if our memory id ends in a core segment it gives us the provider segment keys).

Implements MemoryPersistenceStrategy.

Definition at line 9 of file RestPersistence.cpp.

◆ getItemKeys()

std::vector< std::string > getItemKeys ( const armarx::armem::MemoryID id)
overridevirtual

Keys of the actual items containing data stored for the memory id.

Implements MemoryPersistenceStrategy.

Definition at line 21 of file RestPersistence.cpp.

◆ retrieveItem()

std::vector< unsigned char > retrieveItem ( const armarx::armem::MemoryID id,
std::string  key 
)
overridevirtual

Retrieve the actual data of an item stored for the memory id.

Returns
stored data

Implements MemoryPersistenceStrategy.

Definition at line 69 of file RestPersistence.cpp.

+ Here is the call graph for this function:

◆ storeItem()

void storeItem ( const armarx::armem::MemoryID id,
std::string  key,
std::vector< unsigned char > &  data 
)
overridevirtual

Stores an item containing actual data for the current memory id.

How it is stored depends on the implementation of a concrete strategy (e.g. on disk in a specific directory).

Parameters
keyunique identifier of our item for the specific id (e.g. filename). Note the keys can be equal for different id levels. So you might find the same key on the core segment level as well as on the entity level.
dataactual data written to the persistent item

Implements MemoryPersistenceStrategy.

Definition at line 57 of file RestPersistence.cpp.

Member Data Documentation

◆ DEFAULT_HOST

const std::string DEFAULT_HOST = "localhost"
static

Definition at line 77 of file RestPersistence.h.

◆ DEFAULT_PORT

const static int DEFAULT_PORT = 8080
static

Definition at line 78 of file RestPersistence.h.


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