Moab Web Services > Plugins > Plugin Developer's Guide > Individual Datastore

Individual Datastore

Each plugin has access to an individual, persistent datastore which may be used for a variety of reasons. The datastore is not designed to store Moab 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:

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 may 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 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)
	}
}

Related Topics 

© 2015 Adaptive Computing