ironic-ui/ironic_ui/static/dashboard/admin/ironic/node-error.service.js
Peter Piela 7971aea3d9 Consolidate node last_error processing
Consolidate last_error processing for the node-list and node-detail
views using a newly added node-error service. The service provides
a function checkNodeError that will compare the error condition
of a specified node with its last known value which is stored
in browser session persistent storage (as part of each check).
If a change in the node error condition has occurred the user
is notified using the toast service. The use of persistent storage
eliminates duplicate notifications that would otherwise be
generated from page transitions and service re-initializations.

The checkNodeError function is called whenever node information
is retrieved using the ironic service getNode/getNodes functions.

Change-Id: Iba7bdaaa78d51384b6b9d79d2d723b8e7607eb9a
2016-12-06 18:04:16 -05:00

81 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2016 Cray Inc.
*
* 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.
*/
(function () {
'use strict';
angular
.module('horizon.dashboard.admin.ironic')
.service('horizon.dashboard.admin.ironic.node-error.service',
nodeErrorService);
nodeErrorService.$inject = [
'horizon.framework.widgets.toast.service'
];
function nodeErrorService(toastService) {
// Node last_error cache indexed by node uuid
var lastError = sessionStorage.nodeErrorService
? angular.fromJson(sessionStorage.nodeErrorService) : {};
/**
* @description Get the error condition for a specified node
*
* @param {string} nodeUuid node uuid
* @return {string} Error condition
*/
this.getLastError = function(nodeUuid) {
return angular.isDefined(lastError[nodeUuid])
? lastError[nodeUuid] : null;
};
/**
* @description Store the error condition for a specified node
*
* @param {node} node node
* @return {void}
*/
function setLastError(node) {
lastError[node.uuid] = node.last_error;
// Store node error condition in browser session storage
// which provides persistence across page transitions.
sessionStorage.nodeErrorService = angular.toJson(lastError);
}
/**
* @description Notify the user of a change in error condition for
* specified node.
*
* @param {node} node node being checked
* @return {void}
*/
this.checkNodeError = function(node) {
if (node.last_error !== null &&
node.last_error !== "" &&
(!angular.isDefined(lastError[node.uuid]) ||
node.last_error !== lastError[node.uuid])) {
toastService.add(
'error',
"Detected change in error condition on node " +
node.name + ". " +
node.last_error);
}
// Update stored node error condition
setLastError(node);
};
}
})();