mirror of
https://github.com/nasa/openmct.git
synced 2025-04-11 21:31:06 +00:00
[Persistence] Update Elastic persistence
Update ElasticSearch persistence provider to use ElasticSearch's API, WTD-1033.
This commit is contained in:
parent
37310443e6
commit
f2f9b8bbee
@ -13,7 +13,7 @@
|
||||
"platform/features/scrolling",
|
||||
"platform/forms",
|
||||
"platform/persistence/cache",
|
||||
"platform/persistence/couch",
|
||||
"platform/persistence/elastic",
|
||||
|
||||
"example/generator"
|
||||
]
|
||||
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -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;
|
||||
}
|
||||
);
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user