diff --git a/bundles.json b/bundles.json index 31aedf69bb..ed42240882 100644 --- a/bundles.json +++ b/bundles.json @@ -13,7 +13,7 @@ "platform/features/scrolling", "platform/forms", "platform/persistence/cache", - "platform/persistence/couch", + "platform/persistence/elastic", "example/generator" ] diff --git a/platform/persistence/elastic/bundle.json b/platform/persistence/elastic/bundle.json index 011c46b666..046e7f53d2 100644 --- a/platform/persistence/elastic/bundle.json +++ b/platform/persistence/elastic/bundle.json @@ -6,8 +6,8 @@ { "provides": "persistenceService", "type": "provider", - "implementation": "CouchPersistenceProvider.js", - "depends": [ "$http", "$q", "PERSISTENCE_SPACE", "COUCHDB_PATH" ] + "implementation": "ElasticPersistenceProvider.js", + "depends": [ "$http", "$q", "PERSISTENCE_SPACE", "ELASTIC_ROOT", "ELASTIC_PATH" ] } ], "constants": [ @@ -16,22 +16,26 @@ "value": "mct" }, { - "key": "COUCHDB_PATH", - "value": "/couch/openmct" + "key": "ELASTIC_ROOT", + "value": "http://localhost:9200" }, { - "key": "COUCHDB_INDICATOR_INTERVAL", + "key": "ELASTIC_PATH", + "value": "mct/domain_object" + }, + { + "key": "ELASTIC_INDICATOR_INTERVAL", "value": 15000 } ], "indicators": [ { - "implementation": "CouchIndicator.js", + "implementation": "ElasticIndicator.js", "depends": [ "$http", "$interval", - "COUCHDB_PATH", - "COUCHDB_INDICATOR_INTERVAL" + "ELASTIC_ROOT", + "ELASTIC_INDICATOR_INTERVAL" ] } ] diff --git a/platform/persistence/elastic/src/CouchDocument.js b/platform/persistence/elastic/src/CouchDocument.js deleted file mode 100644 index c24f6e2b99..0000000000 --- a/platform/persistence/elastic/src/CouchDocument.js +++ /dev/null @@ -1,41 +0,0 @@ -/*global define*/ - -define( - [], - function () { - "use strict"; - - /** - * A CouchDocument describes domain object model in a format - * which is easily read-written to CouchDB. This includes - * Couch's _id and _rev fields, as well as a sseparate - * metadata field which contains a subset of information found - * in the model itself (to support search optimization with - * CouchDB views.) - * @constructor - * @param {string} id the id under which to store this mode - * @param {object} model the model to store - * @param {string} rev the revision to include (or undefined, - * if no revision should be noted for couch) - * @param {boolean} whether or not to mark this documnet as - * deleted (see CouchDB docs for _deleted) - */ - function CouchDocument(id, model, rev, markDeleted) { - return { - "_id": id, - "_rev": rev, - "_deleted": markDeleted, - "metadata": { - "category": "domain object", - "type": model.type, - "owner": "admin", - "name": model.name, - "created": Date.now() - }, - "model": model - }; - } - - return CouchDocument; - } -); \ No newline at end of file diff --git a/platform/persistence/elastic/src/ElasticPersistenceProvider.js b/platform/persistence/elastic/src/ElasticPersistenceProvider.js index 13a511cd74..8f0277af3f 100644 --- a/platform/persistence/elastic/src/ElasticPersistenceProvider.js +++ b/platform/persistence/elastic/src/ElasticPersistenceProvider.js @@ -1,37 +1,39 @@ /*global define*/ define( - ["./CouchDocument"], - function (CouchDocument) { + [], + function () { 'use strict'; - // JSLint doesn't like dangling _'s, but CouchDB uses these, so - // hide this behind variables. - var REV = "_rev", + // JSLint doesn't like underscore-prefixed properties, + // so hide them here. + var SRC = "_source", + REV = "_version", ID = "_id"; /** - * The CouchPersistenceProvider reads and writes JSON documents - * (more specifically, domain object models) to/from a CouchDB + * The ElasticPersistenceProvider reads and writes JSON documents + * (more specifically, domain object models) to/from an ElasticSearch * instance. * @constructor */ - function ElasticPersistenceProvider($http, $q, SPACE, PATH) { + function ElasticPersistenceProvider($http, $q, SPACE, ROOT, PATH) { var spaces = [ SPACE ], revs = {}; // Convert a subpath to a full path, suitable to pass // to $http. function url(subpath) { - return PATH + '/' + subpath; + return ROOT + '/' + PATH + '/' + subpath; } // Issue a request using $http; get back the plain JS object // from the expected JSON response - function request(subpath, method, value) { + function request(subpath, method, value, params) { return $http({ method: method, url: url(subpath), + params: params, data: value }).then(function (response) { return response.data; @@ -44,8 +46,11 @@ define( function get(subpath) { return request(subpath, "GET"); } - function put(subpath, value) { - return request(subpath, "PUT", value); + function put(subpath, value, params) { + return request(subpath, "PUT", value, params); + } + function del(subpath) { + return request(subpath, "DELETE"); } // Pull out a list of document IDs from CouchDB's @@ -56,9 +61,9 @@ define( // Get a domain object model out of CouchDB's response function getModel(response) { - if (response && response.model) { + if (response && response[SRC]) { revs[response[ID]] = response[REV]; - return response.model; + return response[SRC]; } else { return undefined; } @@ -108,8 +113,7 @@ define( * operation */ createObject: function (space, key, value) { - return put(key, new CouchDocument(key, value)) - .then(checkResponse); + return put(key, value).then(checkResponse); }, /** @@ -135,7 +139,7 @@ define( * operation */ updateObject: function (space, key, value) { - return put(key, new CouchDocument(key, value, revs[key])) + return put(key, value, { version: revs[key] }) .then(checkResponse); }, /** @@ -150,8 +154,7 @@ define( * operation */ deleteObject: function (space, key, value) { - return put(key, new CouchDocument(key, value, revs[key], true)) - .then(checkResponse); + return del(key).then(checkResponse); } };