mirror of
https://github.com/nasa/openmct.git
synced 2025-06-26 03:00:13 +00:00
Compare commits
8 Commits
test-form-
...
couchdb-pe
Author | SHA1 | Date | |
---|---|---|---|
8258f21f7b | |||
44bfcf33ef | |||
669415d362 | |||
8601ec441f | |||
9a57a20404 | |||
1a3bff9813 | |||
baa5f21640 | |||
af9dceee3c |
@ -43,7 +43,9 @@
|
|||||||
openmct.legacyRegistry.enable.bind(openmct.legacyRegistry)
|
openmct.legacyRegistry.enable.bind(openmct.legacyRegistry)
|
||||||
);
|
);
|
||||||
|
|
||||||
openmct.install(openmct.plugins.LocalStorage());
|
//openmct.install(openmct.plugins.LocalStorage());
|
||||||
|
//Change 'vipersim' to whatever your local db is named
|
||||||
|
openmct.install(openmct.plugins.CouchDB('http://localhost:5984/vipersim'));
|
||||||
openmct.install(openmct.plugins.Espresso());
|
openmct.install(openmct.plugins.Espresso());
|
||||||
openmct.install(openmct.plugins.MyItems());
|
openmct.install(openmct.plugins.MyItems());
|
||||||
openmct.install(openmct.plugins.Generator());
|
openmct.install(openmct.plugins.Generator());
|
||||||
|
@ -35,7 +35,8 @@ define([
|
|||||||
'./services/LegacyObjectAPIInterceptor',
|
'./services/LegacyObjectAPIInterceptor',
|
||||||
'./views/installLegacyViews',
|
'./views/installLegacyViews',
|
||||||
'./policies/LegacyCompositionPolicyAdapter',
|
'./policies/LegacyCompositionPolicyAdapter',
|
||||||
'./actions/LegacyActionAdapter'
|
'./actions/LegacyActionAdapter',
|
||||||
|
'./services/LegacyPersistenceAdapter'
|
||||||
], function (
|
], function (
|
||||||
ActionDialogDecorator,
|
ActionDialogDecorator,
|
||||||
AdapterCapability,
|
AdapterCapability,
|
||||||
@ -51,7 +52,8 @@ define([
|
|||||||
LegacyObjectAPIInterceptor,
|
LegacyObjectAPIInterceptor,
|
||||||
installLegacyViews,
|
installLegacyViews,
|
||||||
legacyCompositionPolicyAdapter,
|
legacyCompositionPolicyAdapter,
|
||||||
LegacyActionAdapter
|
LegacyActionAdapter,
|
||||||
|
LegacyPersistenceAdapter
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
name: 'src/adapter',
|
name: 'src/adapter',
|
||||||
@ -114,6 +116,13 @@ define([
|
|||||||
"instantiate",
|
"instantiate",
|
||||||
"topic"
|
"topic"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provides: "persistenceService",
|
||||||
|
type: "provider",
|
||||||
|
priority: "fallback",
|
||||||
|
implementation: LegacyPersistenceAdapter.default,
|
||||||
|
depends: ["openmct"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
policies: [
|
policies: [
|
||||||
|
28
src/adapter/services/LegacyPersistenceAdapter.js
Normal file
28
src/adapter/services/LegacyPersistenceAdapter.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import objectUtils from 'objectUtils';
|
||||||
|
|
||||||
|
function LegacyPersistenceProvider(openmct) {
|
||||||
|
this.openmct = openmct;
|
||||||
|
}
|
||||||
|
|
||||||
|
LegacyPersistenceProvider.prototype.listObjects = function () {
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
LegacyPersistenceProvider.prototype.listSpaces = function () {
|
||||||
|
return Promise.resolve(Object.keys(this.openmct.objects.providers));
|
||||||
|
}
|
||||||
|
|
||||||
|
LegacyPersistenceProvider.prototype.updateObject = function (legacyDomainObject) {
|
||||||
|
return this.openmct.objects.save(legacyDomainObject.useCapability('adapter'));
|
||||||
|
}
|
||||||
|
|
||||||
|
LegacyPersistenceProvider.prototype.updateObject = function (legacyDomainObject) {
|
||||||
|
return this.openmct.objects.save(legacyDomainObject.useCapability('adapter'));
|
||||||
|
}
|
||||||
|
|
||||||
|
LegacyPersistenceProvider.prototype.readObject = function (keystring) {
|
||||||
|
let identifier = objectUtils.parseKeyString(keystring);
|
||||||
|
return this.openmct.legacyObject(this.openmct.objects.get(identifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LegacyPersistenceProvider;
|
53
src/plugins/persistence/couch/CouchDocument.js
Normal file
53
src/plugins/persistence/couch/CouchDocument.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT, Copyright (c) 2014-2018, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 separate
|
||||||
|
* metadata field which contains a subset of information found
|
||||||
|
* in the model itself (to support search optimization with
|
||||||
|
* CouchDB views.)
|
||||||
|
* @memberof platform/persistence/couch
|
||||||
|
* @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 document as
|
||||||
|
* deleted (see CouchDB docs for _deleted)
|
||||||
|
*/
|
||||||
|
export default 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
|
||||||
|
};
|
||||||
|
}
|
65
src/plugins/persistence/couch/CouchObjectProvider.js
Normal file
65
src/plugins/persistence/couch/CouchObjectProvider.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import CouchDocument from "./CouchDocument";
|
||||||
|
|
||||||
|
const REV = "_rev";
|
||||||
|
const ID = "_id";
|
||||||
|
|
||||||
|
export default class CouchObjectProvider {
|
||||||
|
constructor(openmct, url, namespace) {
|
||||||
|
this.openmct = openmct;
|
||||||
|
this.url = url;
|
||||||
|
this.namespace = namespace; this.namespace = namespace; this.namespace = namespace;
|
||||||
|
this.revs = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
request(subPath, method, value) {
|
||||||
|
console.log(subPath, method, value);
|
||||||
|
return fetch(this.url + '/' + subPath, {
|
||||||
|
method: method,
|
||||||
|
body: value
|
||||||
|
}).then(response => response.json())
|
||||||
|
.then(function (response) {
|
||||||
|
return response;
|
||||||
|
}, function () {
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the response to a create/update/delete request;
|
||||||
|
// track the rev if it's valid, otherwise return false to
|
||||||
|
// indicate that the request failed.
|
||||||
|
checkResponse(response) {
|
||||||
|
if (response && response.ok) {
|
||||||
|
this.revs[response.id] = response.rev;
|
||||||
|
return response.ok;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getModel(response) {
|
||||||
|
if (response && response.model) {
|
||||||
|
let key = response[ID];
|
||||||
|
this.revs[key] = response[REV];
|
||||||
|
let object = response.model;
|
||||||
|
object.identifier = {
|
||||||
|
namespace: this.namespace,
|
||||||
|
key: key
|
||||||
|
};
|
||||||
|
return object;
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get(identifier) {
|
||||||
|
return this.request(identifier.key, "GET").then(this.getModel.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
create(model) {
|
||||||
|
return this.request(model.identifier, "PUT", new CouchDocument(model.identifier.key, model)).then(this.checkResponse.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
update(model) {
|
||||||
|
return this.request(model.identifier, "PUT", model).then(this.checkResponse.bind(this));
|
||||||
|
}
|
||||||
|
}
|
8
src/plugins/persistence/couch/plugin.js
Normal file
8
src/plugins/persistence/couch/plugin.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import CouchObjectProvider from './CouchObjectProvider';
|
||||||
|
const NAMESPACE = '';
|
||||||
|
|
||||||
|
export default function CouchPlugin(config) {
|
||||||
|
return function install(openmct) {
|
||||||
|
openmct.objects.addProvider(NAMESPACE, new CouchObjectProvider(openmct, config, NAMESPACE));
|
||||||
|
}
|
||||||
|
}
|
77
src/plugins/persistence/couch/pluginSpec.js
Normal file
77
src/plugins/persistence/couch/pluginSpec.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT, Copyright (c) 2014-2020, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
import CouchPlugin from './plugin.js';
|
||||||
|
import {
|
||||||
|
createOpenMct,
|
||||||
|
resetApplicationState
|
||||||
|
} from 'utils/testing';
|
||||||
|
|
||||||
|
fdescribe("the plugin", () => {
|
||||||
|
let openmct;
|
||||||
|
let element;
|
||||||
|
let child;
|
||||||
|
let provider;
|
||||||
|
let testSpace = "testSpace";
|
||||||
|
let testPath = "/test/db";
|
||||||
|
let mockDomainObject = { identifier: {namespace: '', key: "some-value"} };
|
||||||
|
|
||||||
|
beforeEach((done) => {
|
||||||
|
openmct = createOpenMct(false);
|
||||||
|
openmct.install(new CouchPlugin(testSpace, testPath));
|
||||||
|
|
||||||
|
element = document.createElement('div');
|
||||||
|
child = document.createElement('div');
|
||||||
|
element.appendChild(child);
|
||||||
|
|
||||||
|
openmct.on('start', done);
|
||||||
|
openmct.startHeadless();
|
||||||
|
|
||||||
|
provider = openmct.objects.getProvider(mockDomainObject.identifier);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('registers a provider for objects', () => {
|
||||||
|
expect(provider).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gets an object', () => {
|
||||||
|
openmct.objects.get(mockDomainObject.identifier).then((result) => {
|
||||||
|
expect(provider.get).toHaveBeenCalled();
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates an object', () => {
|
||||||
|
openmct.objects.save(mockDomainObject).then((result) => {
|
||||||
|
expect(provider.create).toHaveBeenCalled();
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('updates an object', () => {
|
||||||
|
openmct.objects.save(mockDomainObject).then((result) => {
|
||||||
|
openmct.objects.save(mockDomainObject).then((updatedResult) => {
|
||||||
|
expect(provider.update).toHaveBeenCalled();
|
||||||
|
expect(updatedResult).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -54,7 +54,8 @@ define([
|
|||||||
'./themes/snow',
|
'./themes/snow',
|
||||||
'./URLTimeSettingsSynchronizer/plugin',
|
'./URLTimeSettingsSynchronizer/plugin',
|
||||||
'./notificationIndicator/plugin',
|
'./notificationIndicator/plugin',
|
||||||
'./newFolderAction/plugin'
|
'./newFolderAction/plugin',
|
||||||
|
'./persistence/couch/plugin'
|
||||||
], function (
|
], function (
|
||||||
_,
|
_,
|
||||||
UTCTimeSystem,
|
UTCTimeSystem,
|
||||||
@ -89,12 +90,12 @@ define([
|
|||||||
Snow,
|
Snow,
|
||||||
URLTimeSettingsSynchronizer,
|
URLTimeSettingsSynchronizer,
|
||||||
NotificationIndicator,
|
NotificationIndicator,
|
||||||
NewFolderAction
|
NewFolderAction,
|
||||||
|
CouchDBPlugin
|
||||||
) {
|
) {
|
||||||
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',
|
|
||||||
Elasticsearch: 'platform/persistence/elastic'
|
Elasticsearch: 'platform/persistence/elastic'
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -126,27 +127,7 @@ define([
|
|||||||
|
|
||||||
plugins.Conductor = TimeConductorPlugin.default;
|
plugins.Conductor = TimeConductorPlugin.default;
|
||||||
|
|
||||||
plugins.CouchDB = function (url) {
|
plugins.CouchDB = CouchDBPlugin.default;
|
||||||
return function (openmct) {
|
|
||||||
if (url) {
|
|
||||||
var bundleName = "config/couch";
|
|
||||||
openmct.legacyRegistry.register(bundleName, {
|
|
||||||
"extensions": {
|
|
||||||
"constants": [
|
|
||||||
{
|
|
||||||
"key": "COUCHDB_PATH",
|
|
||||||
"value": url,
|
|
||||||
"priority": "mandatory"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
openmct.legacyRegistry.enable(bundleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
openmct.legacyRegistry.enable(bundleMap.CouchDB);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
plugins.Elasticsearch = function (url) {
|
plugins.Elasticsearch = function (url) {
|
||||||
return function (openmct) {
|
return function (openmct) {
|
||||||
|
Reference in New Issue
Block a user