Elasticsearch support for change to typeless API (#2941)

* added elasticsearch to bundlemap
This commit is contained in:
Joel McKinnon 2020-04-21 15:23:43 -07:00 committed by GitHub
parent 4a39ddf425
commit af93823b6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 19 deletions

View File

@ -43,9 +43,9 @@
openmct.legacyRegistry.enable.bind(openmct.legacyRegistry) openmct.legacyRegistry.enable.bind(openmct.legacyRegistry)
); );
openmct.install(openmct.plugins.LocalStorage());
openmct.install(openmct.plugins.Espresso()); openmct.install(openmct.plugins.Espresso());
openmct.install(openmct.plugins.MyItems()); openmct.install(openmct.plugins.MyItems());
openmct.install(openmct.plugins.LocalStorage());
openmct.install(openmct.plugins.Generator()); openmct.install(openmct.plugins.Generator());
openmct.install(openmct.plugins.ExampleImagery()); openmct.install(openmct.plugins.ExampleImagery());
openmct.install(openmct.plugins.UTCTimeSystem()); openmct.install(openmct.plugins.UTCTimeSystem());

View File

@ -71,7 +71,7 @@ define([
}, },
{ {
"key": "ELASTIC_PATH", "key": "ELASTIC_PATH",
"value": "mct/domain_object", "value": "mct/_doc",
"priority": "fallback" "priority": "fallback"
}, },
{ {

View File

@ -32,9 +32,9 @@ define(
// JSLint doesn't like underscore-prefixed properties, // JSLint doesn't like underscore-prefixed properties,
// so hide them here. // so hide them here.
var SRC = "_source", var SRC = "_source",
REV = "_version", CONFLICT = 409,
ID = "_id", SEQ_NO = "_seq_no",
CONFLICT = 409; PRIMARY_TERM = "_primary_term";
/** /**
* The ElasticPersistenceProvider reads and writes JSON documents * The ElasticPersistenceProvider reads and writes JSON documents
@ -104,7 +104,8 @@ define(
// Get a domain object model out of ElasticSearch's response // Get a domain object model out of ElasticSearch's response
ElasticPersistenceProvider.prototype.getModel = function (response) { ElasticPersistenceProvider.prototype.getModel = function (response) {
if (response && response[SRC]) { if (response && response[SRC]) {
this.revs[response[ID]] = response[REV]; this.revs[response[SEQ_NO]] = response[SEQ_NO];
this.revs[response[PRIMARY_TERM]] = response[PRIMARY_TERM];
return response[SRC]; return response[SRC];
} else { } else {
return undefined; return undefined;
@ -116,7 +117,8 @@ define(
// indicate that the request failed. // indicate that the request failed.
ElasticPersistenceProvider.prototype.checkResponse = function (response, key) { ElasticPersistenceProvider.prototype.checkResponse = function (response, key) {
if (response && !response.error) { if (response && !response.error) {
this.revs[key] = response[REV]; this.revs[SEQ_NO] = response[SEQ_NO];
this.revs[PRIMARY_TERM] = response[PRIMARY_TERM];
return response; return response;
} else { } else {
return this.handleError(response, key); return this.handleError(response, key);
@ -147,7 +149,7 @@ define(
function checkUpdate(response) { function checkUpdate(response) {
return self.checkResponse(response, key); return self.checkResponse(response, key);
} }
return this.put(key, value, { version: this.revs[key] }) return this.put(key, value)
.then(checkUpdate); .then(checkUpdate);
}; };

View File

@ -85,7 +85,7 @@ define(
it("allows object creation", function () { it("allows object creation", function () {
var model = { someKey: "some value" }; var model = { someKey: "some value" };
mockHttp.and.returnValue(mockPromise({ mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 1 } data: { "_id": "abc", "_seq_no": 1, "_primary_term": 1 }
})); }));
provider.createObject("testSpace", "abc", model).then(capture); provider.createObject("testSpace", "abc", model).then(capture);
expect(mockHttp).toHaveBeenCalledWith({ expect(mockHttp).toHaveBeenCalledWith({
@ -100,7 +100,7 @@ define(
it("allows object models to be read back", function () { it("allows object models to be read back", function () {
var model = { someKey: "some value" }; var model = { someKey: "some value" };
mockHttp.and.returnValue(mockPromise({ mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 1, "_source": model } data: { "_id": "abc", "_seq_no": 1, "_primary_term": 1, "_source": model }
})); }));
provider.readObject("testSpace", "abc").then(capture); provider.readObject("testSpace", "abc").then(capture);
expect(mockHttp).toHaveBeenCalledWith({ expect(mockHttp).toHaveBeenCalledWith({
@ -117,19 +117,19 @@ define(
// First do a read to populate rev tags... // First do a read to populate rev tags...
mockHttp.and.returnValue(mockPromise({ mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} } data: { "_id": "abc", "_source": {} }
})); }));
provider.readObject("testSpace", "abc"); provider.readObject("testSpace", "abc");
// Now perform an update // Now perform an update
mockHttp.and.returnValue(mockPromise({ mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 43, "_source": {} } data: { "_id": "abc", "_seq_no": 1, "_source": {} }
})); }));
provider.updateObject("testSpace", "abc", model).then(capture); provider.updateObject("testSpace", "abc", model).then(capture);
expect(mockHttp).toHaveBeenCalledWith({ expect(mockHttp).toHaveBeenCalledWith({
url: "/test/db/abc", url: "/test/db/abc",
method: "PUT", method: "PUT",
params: { version: 42 }, params: undefined,
data: model data: model
}); });
expect(capture.calls.mostRecent().args[0]).toBeTruthy(); expect(capture.calls.mostRecent().args[0]).toBeTruthy();
@ -138,13 +138,13 @@ define(
it("allows object deletion", function () { it("allows object deletion", function () {
// First do a read to populate rev tags... // First do a read to populate rev tags...
mockHttp.and.returnValue(mockPromise({ mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} } data: { "_id": "abc", "_source": {} }
})); }));
provider.readObject("testSpace", "abc"); provider.readObject("testSpace", "abc");
// Now perform an update // Now perform an update
mockHttp.and.returnValue(mockPromise({ mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} } data: { "_id": "abc", "_source": {} }
})); }));
provider.deleteObject("testSpace", "abc", {}).then(capture); provider.deleteObject("testSpace", "abc", {}).then(capture);
expect(mockHttp).toHaveBeenCalledWith({ expect(mockHttp).toHaveBeenCalledWith({
@ -167,13 +167,13 @@ define(
expect(capture).toHaveBeenCalledWith(undefined); expect(capture).toHaveBeenCalledWith(undefined);
}); });
it("handles rejection due to version", function () { it("handles rejection due to _seq_no", function () {
var model = { someKey: "some value" }, var model = { someKey: "some value" },
mockErrorCallback = jasmine.createSpy('error'); mockErrorCallback = jasmine.createSpy('error');
// First do a read to populate rev tags... // First do a read to populate rev tags...
mockHttp.and.returnValue(mockPromise({ mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} } data: { "_id": "abc", "_seq_no": 1, "_source": {} }
})); }));
provider.readObject("testSpace", "abc"); provider.readObject("testSpace", "abc");
@ -196,7 +196,7 @@ define(
// First do a read to populate rev tags... // First do a read to populate rev tags...
mockHttp.and.returnValue(mockPromise({ mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} } data: { "_id": "abc", "_seq_no": 1, "_source": {} }
})); }));
provider.readObject("testSpace", "abc"); provider.readObject("testSpace", "abc");

View File

@ -88,7 +88,8 @@ define([
var bundleMap = { var bundleMap = {
LocalStorage: 'platform/persistence/local', LocalStorage: 'platform/persistence/local',
MyItems: 'platform/features/my-items', MyItems: 'platform/features/my-items',
CouchDB: 'platform/persistence/couch' CouchDB: 'platform/persistence/couch',
Elasticsearch: 'platform/persistence/elastic'
}; };
var plugins = _.mapValues(bundleMap, function (bundleName, pluginName) { var plugins = _.mapValues(bundleMap, function (bundleName, pluginName) {