Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #126 - Gracefully fail when database connection can't be made for playback #127

Merged
merged 2 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions ait/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,31 @@ class Playback(object):
A Playback manages the state for the playback component.
playback.dbconn: connection to database
playback.query: time query map of {timestamp: list of (uid, data)} from database
playback.on: true if gui is currently in playback mode
playback.on: True if gui is currently in playback mode. Real-time telemetry will not
be sent to the frontend during this.
Copy link
Contributor

@aywaldron aywaldron Aug 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is stopping real-time telem during playback the intended functionality, or something to change in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's intended. If we're playing back telemetry from a historical query we cut off the real time stream to the clients so the older data can be replayed.

playback.enabled: True if historical data playback is enabled. This will be False
if a database connection cannot be made or if data playback is disabled for
some other reason.
"""

def __init__(self):
"""Creates a new Playback"""
self._db_connect()
self.enabled = False
self.query = {}
self.on = False
self.dbconn = None

self._db_connect()

if self.dbconn:
self.enabled = True

def _db_connect(self):
"""Connect to database"""

# Get datastore from config
plugins = ait.config.get('server.plugins')
datastore = ''
datastore = None
other_args = {}
for i in range(len(plugins)):
if plugins[i]['plugin']['name'] == 'ait.core.server.plugin.DataArchive':
Expand All @@ -152,11 +162,21 @@ def _db_connect(self):
other_args.pop('outputs', None)
other_args.pop('datastore', None)
break
mod, cls = datastore.rsplit('.', 1)

# Connect to database
self.dbconn = getattr(importlib.import_module(mod), cls)()
self.dbconn.connect(**other_args)
if datastore:
mod, cls = datastore.rsplit('.', 1)

# Connect to database
self.dbconn = getattr(importlib.import_module(mod), cls)()
self.dbconn.connect(**other_args)
else:
msg = (
'[GUI Playback Configuration]'
'Unable to locate DataArchive plugin configuration for '
'historical data queries. Historical telemetry playback '
'will be disabled in monitoring UI and server endpoints.'
)
log.warn(msg)

def reset(self):
"""Reset fields"""
Expand Down Expand Up @@ -1047,6 +1067,9 @@ def handle():
global playback
ranges = []

if not playback.enabled:
return json.dumps([])

# Loop through each packet from database
packets = list(playback.dbconn.query('SHOW MEASUREMENTS').get_points())
for i in range(len(packets)):
Expand Down Expand Up @@ -1076,6 +1099,10 @@ def handle():
def handle():
"""Set playback query with packet name, start time, and end time from form"""
global playback

if not playback.enabled:
return HttpResponse(status=404, body='Historic data playback is disabled')

tlm_dict = tlm.getDefaultDict()

# Get values from form
Expand Down
17 changes: 13 additions & 4 deletions ait/gui/static/js/ait/gui/Playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,20 @@ const Playback = {
// Display time ranges available
let range = m('div', {class: 'form-group'}, [
m('label', 'Time ranges available'),
this._range.map(function(i) {
return m('div', i[0] + ': ' + i[1] + ' to ' + i[2])
})
m('div', {'class': 'alert alert-warning'},
'No time ranges found. Is your database connection configured?'
)
])

if (this._range.length > 0) {
range = m('div', {class: 'form-group'}, [
m('label', 'Time ranges available'),
this._range.map(function(i) {
return m('div', i[0] + ': ' + i[1] + ' to ' + i[2])
})
])
}

// Packet select drop down menu
let packets = m('div', {class: 'form-group col-xs-3'}, [
m('label', 'Telemetry packet:'),
Expand Down Expand Up @@ -277,4 +286,4 @@ const Playback = {


export default Playback
export { Playback }
export { Playback }