mirror of
https://github.com/nasa/openmct.git
synced 2025-06-22 09:08:43 +00:00
[Staleness] API and Component Functionality (#6108)
* initial telemetry api updates for staleness support * modifying staleness to a subsription style * fixing variable name * debuggin * put the subscribe in the wrong place * stale class for object views * temp cyan border for testing * added staleness to swg, working on stacked plot staleness * WIP: stacked plot staleness * reverting, going a different route * staleness on stacked plots * plot legend staleness * remove debug code * staleness for alphanumerics * lad table and table set staleness * overlay plot staleness * remove debug code * hardened lad staleness functionality fixed plots without composition bug * adding staleness to gauges * renaming telemetry age check functionality so it does not conflict with new staleness functionality * couple one-off fixes here and there, and WIP for condition sets, moving to telemetry tables to facilitate styling of completed components * small fix on lad tables, added staleness functionality to tables * finishing up condition sets * some cleaning up * adding border to condition sets when an item is stale * fixing dub sub * addressing PR comment, moving repeated code to a function * robustified the SWG stalenes provider, little fixes here and there as far as cleaning up listeners and... whatnot * removing debug code * typo fixes * cleanin up debug code * created a simple stalenes mixin for more basic usage in components * more robustification, if a new staleness subscription happens, will now send the current staleness value if we have it, beefed up example stalenes swg provider * beefed up staleness mixin a bit to give it more use * copyright * cleanin up ladtable code * cleanin up ladtable code * cleaning up lad table sets * some minor updates * Closes #6109 - New staleness glyph and font CSS added. * Closes #6109 - Normalized staleness colors as theme constants. - New mixins for staleness application to view elements. - Applied staleness styling to all relevant view elements. - TODO: smoke-test in Show theme. * adding staleness utils helper, mixin and isStale functionalirty for telemtry api * Closes #6109 - Refined style for Snow theme. * need to have one domainObject per stalenes utility * making sure we handle domains correctly while dealing with staleness * couple fixes * moving abort controller logic to a spot where it makes more sense * added some more info for the StalenesProvider interface docs * returning undefinded for ifStale requests with no provider * debuggin * debuggin * missed "isStale" call in condtioncollections * removing debug code and using mixin unsubscribe in gauge * fixing tests * more targeted tree item click Co-authored-by: Charles Hacskaylo <charlesh88@gmail.com> Co-authored-by: Andrew Henry <akhenry@gmail.com> Co-authored-by: Scott Bell <scott@traclabs.com>
This commit is contained in:
@ -36,6 +36,7 @@ export default class TelemetryAPI {
|
||||
this.formatMapCache = new WeakMap();
|
||||
this.formatters = new Map();
|
||||
this.limitProviders = [];
|
||||
this.stalenessProviders = [];
|
||||
this.metadataCache = new WeakMap();
|
||||
this.metadataProviders = [new DefaultMetadataProvider(this.openmct)];
|
||||
this.noRequestProviderForAllObjects = false;
|
||||
@ -114,6 +115,10 @@ export default class TelemetryAPI {
|
||||
if (provider.supportsLimits) {
|
||||
this.limitProviders.unshift(provider);
|
||||
}
|
||||
|
||||
if (provider.supportsStaleness) {
|
||||
this.stalenessProviders.unshift(provider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,7 +130,7 @@ export default class TelemetryAPI {
|
||||
return provider.supportsSubscribe.apply(provider, args);
|
||||
}
|
||||
|
||||
return this.subscriptionProviders.filter(supportsDomainObject)[0];
|
||||
return this.subscriptionProviders.find(supportsDomainObject);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,25 +143,25 @@ export default class TelemetryAPI {
|
||||
return provider.supportsRequest.apply(provider, args);
|
||||
}
|
||||
|
||||
return this.requestProviders.filter(supportsDomainObject)[0];
|
||||
return this.requestProviders.find(supportsDomainObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
#findMetadataProvider(domainObject) {
|
||||
return this.metadataProviders.filter(function (p) {
|
||||
return p.supportsMetadata(domainObject);
|
||||
})[0];
|
||||
return this.metadataProviders.find((provider) => {
|
||||
return provider.supportsMetadata(domainObject);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
#findLimitEvaluator(domainObject) {
|
||||
return this.limitProviders.filter(function (p) {
|
||||
return p.supportsLimits(domainObject);
|
||||
})[0];
|
||||
return this.limitProviders.find((provider) => {
|
||||
return provider.supportsLimits(domainObject);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -351,6 +356,101 @@ export default class TelemetryAPI {
|
||||
}.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to staleness updates for a specific domain object.
|
||||
* The callback will be called whenever staleness changes.
|
||||
*
|
||||
* @method subscribeToStaleness
|
||||
* @memberof module:openmct.TelemetryAPI~StalenessProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the object
|
||||
* to watch for staleness updates
|
||||
* @param {Function} callback the callback to invoke with staleness data,
|
||||
* as it is received: ex.
|
||||
* {
|
||||
* isStale: <Boolean>,
|
||||
* timestamp: <timestamp>
|
||||
* }
|
||||
* @returns {Function} a function which may be called to terminate
|
||||
* the subscription to staleness updates
|
||||
*/
|
||||
subscribeToStaleness(domainObject, callback) {
|
||||
const provider = this.#findStalenessProvider(domainObject);
|
||||
|
||||
if (!this.stalenessSubscriberCache) {
|
||||
this.stalenessSubscriberCache = {};
|
||||
}
|
||||
|
||||
const keyString = objectUtils.makeKeyString(domainObject.identifier);
|
||||
let stalenessSubscriber = this.stalenessSubscriberCache[keyString];
|
||||
|
||||
if (!stalenessSubscriber) {
|
||||
stalenessSubscriber = this.stalenessSubscriberCache[keyString] = {
|
||||
callbacks: [callback]
|
||||
};
|
||||
if (provider) {
|
||||
stalenessSubscriber.unsubscribe = provider
|
||||
.subscribeToStaleness(domainObject, (stalenessResponse) => {
|
||||
stalenessSubscriber.callbacks.forEach((cb) => {
|
||||
cb(stalenessResponse);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
stalenessSubscriber.unsubscribe = () => {};
|
||||
}
|
||||
} else {
|
||||
stalenessSubscriber.callbacks.push(callback);
|
||||
}
|
||||
|
||||
return function unsubscribe() {
|
||||
stalenessSubscriber.callbacks = stalenessSubscriber.callbacks.filter((cb) => {
|
||||
return cb !== callback;
|
||||
});
|
||||
if (stalenessSubscriber.callbacks.length === 0) {
|
||||
stalenessSubscriber.unsubscribe();
|
||||
delete this.stalenessSubscriberCache[keyString];
|
||||
}
|
||||
}.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request telemetry staleness for a domain object.
|
||||
*
|
||||
* @method isStale
|
||||
* @memberof module:openmct.TelemetryAPI~StalenessProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the object
|
||||
* which has associated telemetry staleness
|
||||
* @returns {Promise.<StalenessResponseObject>} a promise for a StalenessResponseObject
|
||||
* or undefined if no provider exists
|
||||
*/
|
||||
async isStale(domainObject) {
|
||||
const provider = this.#findStalenessProvider(domainObject);
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
const abortController = new AbortController();
|
||||
const options = { signal: abortController.signal };
|
||||
this.requestAbortControllers.add(abortController);
|
||||
|
||||
try {
|
||||
const staleness = await provider.isStale(domainObject, options);
|
||||
|
||||
return staleness;
|
||||
} finally {
|
||||
this.requestAbortControllers.delete(abortController);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
#findStalenessProvider(domainObject) {
|
||||
return this.stalenessProviders.find((provider) => {
|
||||
return provider.supportsStaleness(domainObject);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get telemetry metadata for a given domain object. Returns a telemetry
|
||||
* metadata manager which provides methods for interrogating telemetry
|
||||
@ -661,6 +761,29 @@ export default class TelemetryAPI {
|
||||
* @memberof module:openmct.TelemetryAPI~
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides telemetry staleness data. To subscribe to telemetry stalenes,
|
||||
* new StalenessProvider implementations should be
|
||||
* [registered]{@link module:openmct.TelemetryAPI#addProvider}.
|
||||
*
|
||||
* @interface StalenessProvider
|
||||
* @property {function} supportsStaleness receieves a domainObject and
|
||||
* returns a boolean to indicate it will provide staleness
|
||||
* @property {function} subscribeToStaleness receieves a domainObject to
|
||||
* be subscribed to and a callback to invoke with a StalenessResponseObject
|
||||
* @property {function} isStale an asynchronous method called with a domainObject
|
||||
* and an options object which currently has an abort signal, ex.
|
||||
* { signal: <AbortController.signal> }
|
||||
* this method should return a current StalenessResponseObject
|
||||
* @memberof module:openmct.TelemetryAPI~
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} StalenessResponseObject
|
||||
* @property {Boolean} isStale boolean representing the staleness state
|
||||
* @property {Number} timestamp Unix timestamp in milliseconds
|
||||
*/
|
||||
|
||||
/**
|
||||
* An interface for retrieving telemetry data associated with a domain
|
||||
* object.
|
||||
|
Reference in New Issue
Block a user