6.2.7
Individual Datastore
Each plugin has access to an individual, persistent datastore that can be used for a variety of reasons. The datastore is not designed to store Moab HPC Suite data such as nodes, jobs, or virtual machines, but custom, arbitrary data pertinent only to the individual plugin. This may include storing objects in a persistent cache, state information for currently running processes, or any other arbitrary data.
The individual datastore has the following properties:
- Data is persisted to the Mongo database and will be available even if the plugin or MWS is restarted.
- The data must be stored in groups of data called collections. These correspond directly to MongoDB collections.
- Each plugin can have an arbitrary number of collections.
- Collections are guaranteed not to collide if there are identically named collections between two plugin types or even two plugin instances.
- Each collection contains multiple objects or entries. These correspond directly to MongoDB documents.
- The values of entries can be any object that can be serialized to MongoDB: simple types (int or Integer), Maps, and Lists.
- A collection is automatically created whenever an entry is added to it, it does not need to be specifically initialized.
To utilize the datastore, the Plugin Datastore Service must be used. Operations are provided to add, query, and remove data from each collection.

Simple key/value storage is not currently provided with the datastore. It can easily be done, however, by storing data in the format of {name:"key", value:"value"} and then retrieving this entry later by querying on name equals "key."
Example
The example below demonstrates two web services (see 6.2.8 Exposing Web Services). The first adds multiple entries containing various types of data to an arbitrarily named collection. The second retrieves the data and returns it to the user.
package example import com.adaptc.mws.plugins.* class DatastorePlugin extends AbstractPlugin { IPluginDatastoreService pluginDatastoreService def storeData(Map params) { def collectionName = params.collectionName def data = [[boolVal:true], [stringVal:"String"], [intVal:1], [nullVal:null]] if (pluginDatastoreService.addData(collectionName, data)) log.info("Data successfully added") else log.info("There was an error adding the data") return [success:true] } def retrieveData(Map params) { def collectionName = params.collectionName return pluginDatastoreService.getCollection(collectionName) } }