2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
2015-03-19 23:48:04 +00:00
|
|
|
|
|
|
|
define(
|
|
|
|
[],
|
|
|
|
function () {
|
|
|
|
|
|
|
|
// Set of connection states; changing among these states will be
|
|
|
|
// reflected in the indicator's appearance.
|
|
|
|
// CONNECTED: Everything nominal, expect to be able to read/write.
|
|
|
|
// DISCONNECTED: HTTP failed; maybe misconfigured, disconnected.
|
|
|
|
// PENDING: Still trying to connect, and haven't failed yet.
|
|
|
|
var CONNECTED = {
|
|
|
|
text: "Connected",
|
|
|
|
glyphClass: "ok",
|
|
|
|
description: "Connected to the domain object database."
|
|
|
|
},
|
|
|
|
DISCONNECTED = {
|
|
|
|
text: "Disconnected",
|
|
|
|
glyphClass: "err",
|
|
|
|
description: "Unable to connect to the domain object database."
|
|
|
|
},
|
|
|
|
PENDING = {
|
|
|
|
text: "Checking connection..."
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-08-24 16:04:03 +00:00
|
|
|
* Indicator for the current ElasticSearch connection. Polls
|
|
|
|
* ElasticSearch at a regular interval (defined by bundle constants)
|
|
|
|
* to ensure that the database is available.
|
2015-08-07 18:44:54 +00:00
|
|
|
* @constructor
|
|
|
|
* @memberof platform/persistence/elastic
|
2015-08-14 22:20:46 +00:00
|
|
|
* @implements {Indicator}
|
|
|
|
* @param $http Angular's $http service
|
|
|
|
* @param $interval Angular's $interval service
|
2015-08-24 16:04:03 +00:00
|
|
|
* @param {string} path the URL to poll for elasticsearch availability
|
2015-08-14 22:20:46 +00:00
|
|
|
* @param {number} interval the interval, in milliseconds, to poll at
|
2015-03-19 23:48:04 +00:00
|
|
|
*/
|
2015-08-14 22:20:46 +00:00
|
|
|
function ElasticIndicator($http, $interval, path, interval) {
|
2015-03-19 23:48:04 +00:00
|
|
|
// Track the current connection state
|
2015-08-14 22:20:46 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.state = PENDING;
|
2015-03-19 23:48:04 +00:00
|
|
|
|
2015-08-24 16:04:03 +00:00
|
|
|
// Callback if the HTTP request to ElasticSearch fails
|
2015-08-14 22:20:46 +00:00
|
|
|
function handleError() {
|
|
|
|
self.state = DISCONNECTED;
|
2015-03-19 23:48:04 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 18:46:40 +00:00
|
|
|
// Callback if the HTTP request succeeds.
|
2015-08-14 22:20:46 +00:00
|
|
|
function handleResponse() {
|
|
|
|
self.state = CONNECTED;
|
2015-03-19 23:48:04 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 16:04:03 +00:00
|
|
|
// Try to connect to ElasticSearch, and update the indicator.
|
2015-03-19 23:48:04 +00:00
|
|
|
function updateIndicator() {
|
2015-08-14 22:20:46 +00:00
|
|
|
$http.get(path).then(handleResponse, handleError);
|
2015-03-19 23:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the indicator initially, and start polling.
|
|
|
|
updateIndicator();
|
2015-12-03 21:29:54 +00:00
|
|
|
$interval(updateIndicator, interval, 0, false);
|
2015-03-19 23:48:04 +00:00
|
|
|
}
|
|
|
|
|
2015-08-14 22:20:46 +00:00
|
|
|
ElasticIndicator.prototype.getGlyph = function () {
|
|
|
|
return "D";
|
|
|
|
};
|
|
|
|
ElasticIndicator.prototype.getGlyphClass = function () {
|
|
|
|
return this.state.glyphClass;
|
|
|
|
};
|
|
|
|
ElasticIndicator.prototype.getText = function () {
|
|
|
|
return this.state.text;
|
|
|
|
};
|
|
|
|
ElasticIndicator.prototype.getDescription = function () {
|
|
|
|
return this.state.description;
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:46:40 +00:00
|
|
|
return ElasticIndicator;
|
2015-03-19 23:48:04 +00:00
|
|
|
}
|
2015-08-07 18:44:54 +00:00
|
|
|
);
|