[API] Support dynamic telemetry metadata (#1941)

* [API] Support dynamic telemetry metadata

Add support for dynamic telemetry metadata via custom telemetry
metadata providers.  

The metadata provider API should be considered unstable in it's
current invocation.

* Perform deprecation checking at runtime
* SWG uses telemetry metadata provider
* Don't throw with no matched metadata provider
* Update API docs
* Add license header
* Combine metadata providers with general telemetry providers
* Replace `TelemetryAPI.canProvideTelemetry` with
`TelemetryAPI.isTelemetryObject`.  
* CanProvideTelemetry is deprecated
* Change SWG inputs to numberfield
This commit is contained in:
Pete Richards
2018-03-21 14:18:08 -07:00
committed by Andrew Henry
parent 00fb071fe2
commit 8db75bf41e
19 changed files with 689 additions and 324 deletions

View File

@ -3,7 +3,7 @@
* 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
* Open openmct 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.
@ -14,20 +14,22 @@
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* Open openmct 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.
*****************************************************************************/
/*global console*/
define([
'./TelemetryMetadataManager',
'./TelemetryValueFormatter',
'./DefaultMetadataProvider',
'../objects/object-utils',
'lodash'
], function (
TelemetryMetadataManager,
TelemetryValueFormatter,
DefaultMetadataProvider,
objectUtils,
_
) {
@ -122,7 +124,6 @@ define([
*/
/**
* An interface for retrieving telemetry data associated with a domain
* object.
@ -131,15 +132,29 @@ define([
* @augments module:openmct.TelemetryAPI~TelemetryProvider
* @memberof module:openmct
*/
function TelemetryAPI(MCT) {
this.MCT = MCT;
function TelemetryAPI(openmct) {
this.openmct = openmct;
this.requestProviders = [];
this.subscriptionProviders = [];
this.metadataProviders = [new DefaultMetadataProvider(this.openmct)];
this.limitProviders = [];
this.metadataCache = new WeakMap();
this.formatMapCache = new WeakMap();
this.valueFormatterCache = new WeakMap();
}
/**
* Return true if the given domainObject is a telemetry object. A telemetry
* object is any object which has telemetry metadata-- regardless of whether
* the telemetry object has an available telemetry provider.
*
* @param {module:openmct.DomainObject} domainObject
* @returns {boolean} true if the object is a telemetry object.
*/
TelemetryAPI.prototype.isTelemetryObject = function (domainObject) {
return !!this.findMetadataProvider(domainObject);
};
/**
* Check if this provider can supply telemetry data associated with
* this domain object.
@ -151,6 +166,11 @@ define([
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
*/
TelemetryAPI.prototype.canProvideTelemetry = function (domainObject) {
console.warn(
'DEPRECATION WARNING: openmct.telemetry.canProvideTelemetry ' +
'will not be supported in future versions of Open MCT. Please ' +
'use openmct.telemetry.isTelemetryObject instead.'
);
return !!this.findSubscriptionProvider(domainObject) ||
!!this.findRequestProvider(domainObject);
};
@ -170,6 +190,12 @@ define([
if (provider.supportsSubscribe) {
this.subscriptionProviders.unshift(provider);
}
if (provider.supportsMetadata) {
this.metadataProviders.unshift(provider);
}
if (provider.supportsLimits) {
this.limitProviders.unshift(provider);
}
};
/**
@ -196,18 +222,36 @@ define([
return this.requestProviders.filter(supportsDomainObject)[0];
};
/**
* @private
*/
TelemetryAPI.prototype.findMetadataProvider = function (domainObject) {
return this.metadataProviders.filter(function (p) {
return p.supportsMetadata(domainObject);
})[0];
};
/**
* @private
*/
TelemetryAPI.prototype.findLimitEvaluator = function (domainObject) {
return this.limitProviders.filter(function (p) {
return p.supportsLimits(domainObject);
})[0];
};
/**
* @private
*/
TelemetryAPI.prototype.standardizeRequestOptions = function (options) {
if (!options.hasOwnProperty('start')) {
options.start = this.MCT.time.bounds().start;
options.start = this.openmct.time.bounds().start;
}
if (!options.hasOwnProperty('end')) {
options.end = this.MCT.time.bounds().end;
options.end = this.openmct.time.bounds().end;
}
if (!options.hasOwnProperty('domain')) {
options.domain = this.MCT.time.timeSystem().key;
options.domain = this.openmct.time.timeSystem().key;
}
};
@ -300,12 +344,15 @@ define([
*/
TelemetryAPI.prototype.getMetadata = function (domainObject) {
if (!this.metadataCache.has(domainObject)) {
if (!this.typeService) {
this.typeService = this.MCT.$injector.get('typeService');
var metadataProvider = this.findMetadataProvider(domainObject);
if (!metadataProvider) {
return;
}
var metadata = metadataProvider.getMetadata(domainObject);
this.metadataCache.set(
domainObject,
new TelemetryMetadataManager(domainObject, this.typeService)
new TelemetryMetadataManager(metadata)
);
}
return this.metadataCache.get(domainObject);
@ -343,7 +390,7 @@ define([
TelemetryAPI.prototype.getValueFormatter = function (valueMetadata) {
if (!this.valueFormatterCache.has(valueMetadata)) {
if (!this.formatService) {
this.formatService = this.MCT.$injector.get('formatService');
this.formatService = this.openmct.$injector.get('formatService');
}
this.valueFormatterCache.set(
valueMetadata,
@ -375,7 +422,7 @@ define([
* @param {Format} format the
*/
TelemetryAPI.prototype.addFormat = function (format) {
this.MCT.legacyExtension('formats', {
this.openmct.legacyExtension('formats', {
key: format.key,
implementation: function () {
return format;
@ -385,7 +432,9 @@ define([
/**
* Get a limit evaluator for this domain object.
* Limit Evaluators help you evaluate limit and alarm status of individual telemetry datums for display purposes without having to interact directly with the Limit API.
* Limit Evaluators help you evaluate limit and alarm status of individual
* telemetry datums for display purposes without having to interact directly
* with the Limit API.
*
* This method is optional.
* If a provider does not implement this method, it is presumed
@ -397,8 +446,34 @@ define([
* @method limitEvaluator
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
*/
TelemetryAPI.prototype.limitEvaluator = function () {
return this.legacyProvider.limitEvaluator.apply(this.legacyProvider, arguments);
TelemetryAPI.prototype.limitEvaluator = function (domainObject) {
return this.getLimitEvaluator(domainObject);
};
/**
* Get a limit evaluator for this domain object.
* Limit Evaluators help you evaluate limit and alarm status of individual
* telemetry datums for display purposes without having to interact directly
* with the Limit API.
*
* This method is optional.
* If a provider does not implement this method, it is presumed
* that no limits are defined for this domain object's telemetry.
*
* @param {module:openmct.DomainObject} domainObject the domain
* object for which to evaluate limits
* @returns {module:openmct.TelemetryAPI~LimitEvaluator}
* @method limitEvaluator
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
*/
TelemetryAPI.prototype.getLimitEvaluator = function (domainObject) {
var provider = this.findLimitEvaluator(domainObject);
if (!provider) {
return {
evaluate: function () {}
};
}
return provider.getLimitEvaluator(domainObject);
};
return TelemetryAPI;