PersistentModelMap

Document ID : KB000048513
Last Modified Date : 14/02/2018
Show Technical Document Details

LISA provides a convenient mechanism to store arbitrary key/value pairs in its reporting database. The Registry provides a java API and it is also exposed as a RESTful service by the LISA console.

Maps are accessed by namespace and key. Values must be Strings. If you need to store complex objects then you are responsible for serialization using libraries such as XStream.

There are 4 basic APIS which are declared in PersistentMap and are implemented by TestRegistry


 	public interface PersistentMap { 

 	/** 	
 	* This method gets a value from the specified namespace cast as a string. 	
 	* 	
 	* @param namespace the namespace to get the value from. 	
 	* @param key the key to the desired value. 	
 	* @return the value known by the key or {@code null}. 	
 	*/ 	
 	public String getMapValue(final String namespace, final String key) throws RemoteException; 

 	/** 	
 	* This method puts a value into the specified namespace. 	
 	* 	
 	* @param namespace the namespace to put the value in. 	
 	* @param key the key to make the value known by. 	
 	* @param value the value to associate with the key. 	
 	* @return the previous value for the key or {@code null}. 	
 	*/ 	
 	public String putMapValue(final String namespace, final String key, final String value) throws RemoteException; 

 	/** 	
 	* This method removes a value from the specified namespace. 	
 	* 	
 	* @param namespace the namespace to remove the key from. 	
 	* @param key the key to the value to remove. 	
 	* @return the value known by the key or {@code null}. 	
 	*/ 	
 	public String removeMapValue(final String namespace, final String key) throws RemoteException; 

 	/** 	
 	* This method returns all key/value pairs in a given namespace. 	
 	* 	
 	* @param namespace the namespace to use 	
 	* @return the key/value pairs registered to the namespace or {@code null}. 	
 	*/ 	
 	public Map<String, String> getAllMapValues(final String namespace) throws RemoteException; 	
 	} 

In java code:

com.itko.lisa.coordinator.TestRegistry tr = com.itko.lisa.test.Environment.getTestRegistry();

tr.putMapValue("MyNamespace", "key1", "value1");

Example usage (REST)

GET http://localhost:1505/lisa-invoke/persistentMap/namespace/key

GET http://localhost:1505/lisa-invoke/persistentMap/namespace (equivalent to getAll)

PUT http://localhost:1505/lisa-invoke/persistentMap/namespace/key/value

POST http://localhost:1505/lisa-invoke/persistentMap/namespace/key (value is requestBody)

DELETE http://localhost:1505/lisa-invoke/persistentMap/namespace/key

Data expiry

key/value pairs are deleted by the registry when they expire. The relevant lisa properties and the default values are as follows:

lisa.persistent.map.delete=true // whether to expire the data at all

lisa.persistent.map.delete.cycle=10m // check for expired entries every ten minutes

lisa.persistent.map.delete.age=30d // delete entries older than 30 days.

The timestamps on key/value pairs are updated whenever an entry is added, updated or retrieved.

See attached sample test case PersistentModelMap.tst

File Attachments:
TEC603962.zip