mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 07:16:39 +00:00
[Time Controller] Decorate telemetry service
Decorate telemetry service instead of capability service to enforce time conductor bounds. WTD-1515.
This commit is contained in:
parent
2229e868ce
commit
62962e119e
@ -9,8 +9,8 @@
|
||||
"components": [
|
||||
{
|
||||
"type": "decorator",
|
||||
"provides": "capabilityService",
|
||||
"implementation": "ConductorCapabilityDecorator.js",
|
||||
"provides": "telemetryService",
|
||||
"implementation": "ConductorTelemetryDecorator.js",
|
||||
"depends": [ "conductorService" ]
|
||||
}
|
||||
],
|
||||
|
@ -1,81 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web 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 Web 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 define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Wrapper for the `telemetry` capability which adds start/end
|
||||
* times to all requests based on the current state of a time
|
||||
* conductor.
|
||||
*
|
||||
* @constructor
|
||||
* @memberof platform/features/conductor
|
||||
* @augments {platform/telemetry.TelemetryCapability}
|
||||
* @param {platform/features/conductor.TimeConductor} timeConductor
|
||||
* the time conductor which controls these queries
|
||||
* @param {platform/telemetry.TelemetryCapability} telemetryCapability
|
||||
* the wrapped capability
|
||||
*/
|
||||
function ConductorTelemetryCapability(timeConductor, telemetryCapability) {
|
||||
this.timeConductor = timeConductor;
|
||||
this.wrappedCapability = telemetryCapability;
|
||||
}
|
||||
|
||||
ConductorTelemetryCapability.prototype.amendRequest = function (request) {
|
||||
request = request || {};
|
||||
|
||||
// This isn't really the right check, but it happens to distinguish
|
||||
// plots (which want to query for the full set of data for easy
|
||||
// panning) from views like fixed position, which only want the
|
||||
// single latest data point.
|
||||
if (request.size !== undefined) {
|
||||
request.start = this.timeConductor.displayStart();
|
||||
request.end = this.timeConductor.displayEnd();
|
||||
} else {
|
||||
request.start = this.timeConductor.queryStart();
|
||||
request.end = this.timeConductor.queryEnd();
|
||||
}
|
||||
|
||||
return request;
|
||||
};
|
||||
|
||||
ConductorTelemetryCapability.prototype.getMetadata = function () {
|
||||
return this.wrappedCapability.getMetadata();
|
||||
};
|
||||
|
||||
ConductorTelemetryCapability.prototype.requestData = function (request) {
|
||||
request = this.amendRequest(request);
|
||||
return this.wrappedCapability.requestData(request);
|
||||
};
|
||||
|
||||
ConductorTelemetryCapability.prototype.subscribe = function (callback, request) {
|
||||
request = this.amendRequest(request);
|
||||
return this.wrappedCapability.subscribe(callback, request);
|
||||
};
|
||||
|
||||
return ConductorTelemetryCapability;
|
||||
}
|
||||
);
|
@ -22,43 +22,51 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
['./ConductorTelemetryCapability'],
|
||||
function (ConductorTelemetryCapability) {
|
||||
[],
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Decorates the `capabilityService` such that any exposed `telemetry`
|
||||
* capabilities have their requests mediated by the time conductor.
|
||||
* Decorates the `telemetryService` such that requests are
|
||||
* mediated by the time conductor.
|
||||
*
|
||||
* @constructor
|
||||
* @memberof platform/features/conductor
|
||||
* @implements {CapabilityService}
|
||||
* @implements {TelemetryService}
|
||||
* @param {platform/features/conductor.ConductorService} conductorServe
|
||||
* the service which exposes the global time conductor
|
||||
* @param {CapabilityService} capabilityService the decorated service
|
||||
* @param {TelemetryService} telemetryService the decorated service
|
||||
*/
|
||||
function ConductorCapabilityDecorator(conductorService, capabilityService) {
|
||||
function ConductorTelemetryDecorator(conductorService, telemetryService) {
|
||||
this.conductorService = conductorService;
|
||||
this.capabilityService = capabilityService;
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
ConductorCapabilityDecorator.prototype.getCapabilities = function (model) {
|
||||
var capabilities = this.capabilityService.getCapabilities(model),
|
||||
TelemetryCapability = capabilities.telemetry,
|
||||
conductorService = this.conductorService;
|
||||
ConductorTelemetryDecorator.prototype.amendRequests = function (requests) {
|
||||
var conductor = this.conductorService.getConductor(),
|
||||
start = conductor.displayStart(),
|
||||
end = conductor.displayEnd();
|
||||
|
||||
if (TelemetryCapability) {
|
||||
capabilities.telemetry = function (domainObject) {
|
||||
return new ConductorTelemetryCapability(
|
||||
conductorService.getConductor(),
|
||||
new TelemetryCapability(domainObject)
|
||||
);
|
||||
};
|
||||
function amendRequest(request) {
|
||||
request = request || {};
|
||||
request.start = start;
|
||||
request.end = end;
|
||||
return request;
|
||||
}
|
||||
|
||||
return capabilities;
|
||||
return (requests || []).map(amendRequest);
|
||||
};
|
||||
|
||||
return ConductorCapabilityDecorator;
|
||||
ConductorTelemetryDecorator.prototype.requestTelemetry = function (requests) {
|
||||
return this.telemetryService
|
||||
.requestTelemetry(this.amendRequests(requests));
|
||||
};
|
||||
|
||||
ConductorTelemetryDecorator.prototype.subscribe = function (callback, requests) {
|
||||
return this.telemetryService
|
||||
.subscribe(callback, this.amendRequests(requests));
|
||||
};
|
||||
|
||||
return ConductorTelemetryDecorator;
|
||||
}
|
||||
);
|
@ -1,101 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web 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 Web 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 define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
/**
|
||||
* EventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/23/2015.
|
||||
*/
|
||||
define(
|
||||
["../src/ConductorCapabilityDecorator"],
|
||||
function (ConductorCapabilityDecorator) {
|
||||
"use strict";
|
||||
|
||||
describe("ConductorCapabilityDecorator", function () {
|
||||
var mockCapabilityService,
|
||||
mockConductorService,
|
||||
testModel,
|
||||
testCapabilities,
|
||||
decorator;
|
||||
|
||||
function instantiate(Constructor) {
|
||||
return new Constructor();
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
testCapabilities = {
|
||||
telemetry: jasmine.createSpy('Telemetry'),
|
||||
other: jasmine.createSpy('Other')
|
||||
};
|
||||
|
||||
mockCapabilityService = jasmine.createSpyObj(
|
||||
'capabilityService',
|
||||
[ 'getCapabilities' ]
|
||||
);
|
||||
mockConductorService = jasmine.createSpyObj(
|
||||
'conductorService',
|
||||
[ 'getConductor' ]
|
||||
);
|
||||
testModel = { someKey: "some value" };
|
||||
|
||||
mockCapabilityService.getCapabilities.andCallFake(function () {
|
||||
// Wrap with object.create so we can still
|
||||
// reliably expect properties of testCapabilities itself
|
||||
return Object.create(testCapabilities);
|
||||
});
|
||||
|
||||
decorator = new ConductorCapabilityDecorator(
|
||||
mockConductorService,
|
||||
mockCapabilityService
|
||||
);
|
||||
});
|
||||
|
||||
it("delegates to the decorated capability service", function () {
|
||||
expect(mockCapabilityService.getCapabilities).not.toHaveBeenCalled();
|
||||
decorator.getCapabilities(testModel);
|
||||
expect(mockCapabilityService.getCapabilities).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("wraps the 'telemetry' capability of objects", function () {
|
||||
var capabilities = decorator.getCapabilities(testModel);
|
||||
expect(capabilities.telemetry)
|
||||
.not.toBe(testCapabilities.telemetry);
|
||||
|
||||
// Should wrap - verify by invocation
|
||||
expect(testCapabilities.telemetry).not.toHaveBeenCalled();
|
||||
instantiate(capabilities.telemetry);
|
||||
expect(testCapabilities.telemetry).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not wrap other capabilities", function () {
|
||||
var capabilities = decorator.getCapabilities(testModel);
|
||||
expect(capabilities.other)
|
||||
.toBe(testCapabilities.other);
|
||||
});
|
||||
|
||||
it("gets a time conductor from the conductorService", function () {
|
||||
expect(mockConductorService.getConductor).not.toHaveBeenCalled();
|
||||
instantiate(decorator.getCapabilities(testModel).telemetry);
|
||||
expect(mockConductorService.getConductor).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
@ -1,105 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web 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 Web 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 define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
/**
|
||||
* EventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/23/2015.
|
||||
*/
|
||||
define(
|
||||
["../src/ConductorTelemetryCapability"],
|
||||
function (ConductorTelemetryCapability) {
|
||||
"use strict";
|
||||
|
||||
describe("ConductorTelemetryCapability", function () {
|
||||
var mockConductor,
|
||||
mockTelemetryCapability,
|
||||
mockUnsubscribe,
|
||||
testMetadata,
|
||||
testStartTime,
|
||||
testEndTime,
|
||||
conductorTelemetryCapability;
|
||||
|
||||
beforeEach(function () {
|
||||
mockConductor = jasmine.createSpyObj(
|
||||
'timeConductor',
|
||||
[
|
||||
'queryStart',
|
||||
'queryEnd',
|
||||
'displayStart',
|
||||
'displayEnd'
|
||||
]
|
||||
);
|
||||
mockTelemetryCapability = jasmine.createSpyObj(
|
||||
'telemetry',
|
||||
[ 'getMetadata', 'requestData', 'subscribe' ]
|
||||
);
|
||||
mockUnsubscribe = jasmine.createSpy('unsubscribe');
|
||||
|
||||
testStartTime = 42;
|
||||
testEndTime = 12321;
|
||||
testMetadata = { someKey: 'some value' };
|
||||
mockTelemetryCapability.getMetadata.andReturn(testMetadata);
|
||||
mockTelemetryCapability.subscribe.andReturn(mockUnsubscribe);
|
||||
mockConductor.queryStart.andReturn(testStartTime);
|
||||
mockConductor.queryEnd.andReturn(testEndTime);
|
||||
|
||||
conductorTelemetryCapability = new ConductorTelemetryCapability(
|
||||
mockConductor,
|
||||
mockTelemetryCapability
|
||||
);
|
||||
});
|
||||
|
||||
it("simply delegates getMetadata calls", function () {
|
||||
expect(conductorTelemetryCapability.getMetadata())
|
||||
.toBe(testMetadata);
|
||||
});
|
||||
|
||||
it("adds start/end times to requests", function () {
|
||||
conductorTelemetryCapability
|
||||
.requestData({ someKey: "some value" });
|
||||
expect(mockTelemetryCapability.requestData).toHaveBeenCalledWith({
|
||||
someKey: "some value",
|
||||
start: testStartTime,
|
||||
end: testEndTime
|
||||
});
|
||||
});
|
||||
|
||||
it("adds start/end times to subscribe calls", function () {
|
||||
var mockCallback = jasmine.createSpy('callback'),
|
||||
testRequest = { someKey: "some value" };
|
||||
expect(conductorTelemetryCapability.subscribe(
|
||||
mockCallback,
|
||||
testRequest
|
||||
)).toBe(mockUnsubscribe);
|
||||
expect(mockTelemetryCapability.subscribe).toHaveBeenCalledWith(
|
||||
mockCallback,
|
||||
{
|
||||
someKey: "some value",
|
||||
start: testStartTime,
|
||||
end: testEndTime
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -1,7 +1,5 @@
|
||||
[
|
||||
"ConductorCapabilityDecorator",
|
||||
"ConductorRepresenter",
|
||||
"ConductorService",
|
||||
"ConductorTelemetryCapability",
|
||||
"TimeConductor"
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user