-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into mct7343-tests
- Loading branch information
Showing
14 changed files
with
805 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 65 additions & 25 deletions
90
src/providers/fault-mgmt-providers/fault-action-provider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,100 @@ | ||
import { FAULT_MANAGEMENT_ALARMS, FAULT_MANAGEMENT_DEFAULT_SHELVE_DURATION } from './fault-mgmt-constants.js'; | ||
import { FAULT_MGMT_ALARMS, FAULT_MGMT_ACTIONS } from './fault-mgmt-constants.js'; | ||
|
||
export default class FaultActionProvider { | ||
constructor(url, instance, processor = 'realtime') { | ||
constructor(url, instance, processor) { | ||
this.url = url; | ||
this.instance = instance; | ||
this.processor = processor; | ||
} | ||
|
||
acknowledgeFault(fault, { comment = '' } = {}) { | ||
const payload = { | ||
comment, | ||
state: 'acknowledged' | ||
comment | ||
}; | ||
const options = this._getOptions(payload); | ||
const url = this._getUrl(fault); | ||
const options = this.#getOptions(payload); | ||
const url = this.#getUrl(fault, FAULT_MGMT_ACTIONS.ACKNOWLEDGE); | ||
|
||
return this._sendRequest(url, options); | ||
return this.#sendRequest(url, options); | ||
} | ||
|
||
shelveFault(fault, { shelved = true, comment = '', shelveDuration = FAULT_MANAGEMENT_DEFAULT_SHELVE_DURATION } = {}) { | ||
let payload = {}; | ||
/** | ||
* Shelves or unshelves a fault. | ||
* @param {FaultModel} fault the fault to perform the action on | ||
* @param {Object} options the options to perform the action with | ||
* @param {boolean} options.shelved whether to shelve or unshelve the fault | ||
* @param {string} options.comment the comment to add to the fault | ||
* @param {number} options.shelveDuration the duration to shelve the fault for | ||
* @returns {Promise<Response>} the response from the server | ||
*/ | ||
shelveFault(fault, { shelved = true, comment = '', shelveDuration } = {}) { | ||
const payload = {}; | ||
const action = shelved ? FAULT_MGMT_ACTIONS.SHELVE : FAULT_MGMT_ACTIONS.UNSHELVE; | ||
|
||
if (shelved) { | ||
payload.comment = comment; | ||
payload.shelveDuration = shelveDuration; | ||
payload.state = 'shelved'; | ||
} else { | ||
payload.state = 'unshelved'; | ||
} | ||
|
||
const options = this._getOptions(payload); | ||
let url = this._getUrl(fault); | ||
const options = this.#getOptions(payload); | ||
const url = this.#getUrl(fault, action); | ||
|
||
return this._sendRequest(url, options); | ||
return this.#sendRequest(url, options); | ||
} | ||
|
||
_getOptions(payload) { | ||
/** | ||
* @typedef {Object} ShelveDuration | ||
* @property {string} name - The name of the shelve duration | ||
* @property {number|null} value - The value of the shelve duration in milliseconds, or null for indefinite | ||
*/ | ||
|
||
/** | ||
* @returns {ShelveDuration[]} the list of shelve durations | ||
*/ | ||
getShelveDurations() { | ||
return [ | ||
{ | ||
name: '5 Minutes', | ||
value: 300000 | ||
}, | ||
{ | ||
name: '10 Minutes', | ||
value: 600000 | ||
}, | ||
{ | ||
name: '15 Minutes', | ||
value: 900000 | ||
}, | ||
{ | ||
name: 'Indefinite', | ||
value: null | ||
} | ||
]; | ||
} | ||
|
||
#getOptions(payload) { | ||
return { | ||
body: JSON.stringify(payload), | ||
// credentials: 'same-origin', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
method: 'PATCH', | ||
method: 'POST', | ||
mode: 'cors' | ||
}; | ||
} | ||
|
||
_getUrl(fault) { | ||
let url = `${this.url}api/processors/${this.instance}/${this.processor}/${FAULT_MANAGEMENT_ALARMS}`; | ||
url += `${fault.namespace}/${fault.name}`; | ||
url += `/${fault.seqNum}`; | ||
|
||
return url; | ||
/** | ||
* @param {FaultModel} fault the fault to perform the action on | ||
* @param {'acknowledge' | 'shelve' | 'unshelve' | 'clear'} action the action to perform on the fault | ||
* @returns {string} the URL to perform the action on the fault | ||
*/ | ||
#getUrl(fault, action) { | ||
return `${this.url}api/processors/${this.instance}/${this.processor}/${FAULT_MGMT_ALARMS}` | ||
+ `${fault.namespace}/${fault.name}/${fault.seqNum}:${action}`; | ||
} | ||
|
||
_sendRequest(url, options) { | ||
#sendRequest(url, options) { | ||
return fetch(url, options); | ||
} | ||
} | ||
|
||
/** @typedef {import('./utils.js').FaultModel} FaultModel */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export const FAULT_MANAGEMENT_ALARMS = 'alarms'; | ||
export const FAULT_MANAGEMENT_TYPE = 'faultManagement'; | ||
export const FAULT_MANAGEMENT_DEFAULT_SHELVE_DURATION = 90000; | ||
export const FAULT_MGMT_ALARMS = 'alarms'; | ||
export const FAULT_MGMT_TYPE = 'faultManagement'; | ||
export const DEFAULT_SHELVE_DURATION = 90000; | ||
export const FAULT_MGMT_ACTIONS = Object.freeze({ | ||
SHELVE: 'shelve', | ||
UNSHELVE: 'unshelve', | ||
ACKNOWLEDGE: 'acknowledge', | ||
CLEAR: 'clear' | ||
}); |
23 changes: 17 additions & 6 deletions
23
src/providers/fault-mgmt-providers/historical-fault-provider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
import { FAULT_MANAGEMENT_ALARMS, FAULT_MANAGEMENT_TYPE } from './fault-mgmt-constants.js'; | ||
import { FAULT_MGMT_ALARMS, FAULT_MGMT_TYPE } from './fault-mgmt-constants.js'; | ||
import { convertDataToFaultModel } from './utils.js'; | ||
|
||
export default class HistoricalFaultProvider { | ||
constructor(faultModelConverter, url, instance, processor = 'realtime') { | ||
this.faultModelConverter = faultModelConverter; | ||
constructor(url, instance, processor) { | ||
this.url = url; | ||
this.instance = instance; | ||
this.processor = processor; | ||
} | ||
|
||
/** | ||
* @param {import('openmct').DomainObject} domainObject | ||
* @returns {boolean} | ||
*/ | ||
supportsRequest(domainObject) { | ||
return domainObject.type === FAULT_MANAGEMENT_TYPE; | ||
return domainObject.type === FAULT_MGMT_TYPE; | ||
} | ||
|
||
/** | ||
* @returns {Promise<FaultModel[]>} | ||
*/ | ||
async request() { | ||
let url = `${this.url}api/processors/${this.instance}/${this.processor}/${FAULT_MANAGEMENT_ALARMS}`; | ||
const url = `${this.url}api/processors/${this.instance}/${this.processor}/${FAULT_MGMT_ALARMS}`; | ||
|
||
const res = await fetch(url); | ||
const faultsData = await res.json(); | ||
|
||
return faultsData.alarms?.map(this.faultModelConverter); | ||
return faultsData.alarms?.map(convertDataToFaultModel); | ||
} | ||
} | ||
|
||
/** | ||
* @typedef {import('./utils.js').FaultModel} FaultModel | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.