##// END OF EJS Templates
clean kernel manager
clean kernel manager

File last commit:

r13036:b067a89d
r13037:388f2e91
Show More
handlers.py
112 lines | 3.9 KiB | text/x-python | PythonLexer
Zachary Sailer
standard model changes
r13011 """Tornado handlers for the sessions web service.
Zachary Sailer
manual rebase - add sessions web service
r12985
Authors:
* Zach Sailer
"""
#-----------------------------------------------------------------------------
Zachary Sailer
standard model changes
r13011 # Copyright (C) 2013 The IPython Development Team
Zachary Sailer
manual rebase - add sessions web service
r12985 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from tornado import web
from zmq.utils import jsonapi
from IPython.utils.jsonutil import date_default
Zachary Sailer
rebase master- eliminate read-only
r13014 from ...base.handlers import IPythonHandler
Zachary Sailer
manual rebase - add sessions web service
r12985
#-----------------------------------------------------------------------------
# Session web service handlers
#-----------------------------------------------------------------------------
class SessionRootHandler(IPythonHandler):
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
rebase master- eliminate read-only
r13014 @web.authenticated
Zachary Sailer
manual rebase - add sessions web service
r12985 def get(self):
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 # Return a list of running sessions
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
nbm = self.notebook_manager
km = self.kernel_manager
sessions = sm.list_sessions()
self.finish(jsonapi.dumps(sessions))
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
manual rebase - add sessions web service
r12985 @web.authenticated
def post(self):
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 # Creates a new session
#(unless a session already exists for the named nb)
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
nbm = self.notebook_manager
km = self.kernel_manager
notebook_path = self.get_argument('notebook_path', default=None)
Zachary Sailer
session manager restructuring...
r13035 name, path = nbm.named_notebook_path(notebook_path)
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 # Check to see if session exists
Zachary Sailer
session manager restructuring...
r13035 if sm.session_exists(name=name, path=path):
model = sm.get_session(name=name, path=path)
kernel_id = model['kernel']['id']
km.start_kernel(kernel_id, cwd=nbm.notebook_dir)
else:
session_id = sm.get_session_id()
sm.save_session(session_id=session_id, name=name, path=path)
kernel_id = km.start_kernel(cwd=nbm.notebook_dir)
Zachary Sailer
manual rebase - add sessions web service
r12985 kernel = km.kernel_model(kernel_id, self.ws_url)
Zachary Sailer
session manager restructuring...
r13035 sm.update_session(session_id, kernel=kernel_id)
model = sm.get_session(id=session_id)
self.set_header('Location', '{0}kernels/{1}'.format(self.base_kernel_url, kernel_id))
Zachary Sailer
manual rebase - add sessions web service
r12985 self.finish(jsonapi.dumps(model))
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
manual rebase - add sessions web service
r12985 class SessionHandler(IPythonHandler):
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 SUPPORTED_METHODS = ('GET', 'PATCH', 'DELETE')
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
rebase master- eliminate read-only
r13014 @web.authenticated
Zachary Sailer
manual rebase - add sessions web service
r12985 def get(self, session_id):
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 # Returns the JSON model for a single session
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
Zachary Sailer
session manager restructuring...
r13035 model = sm.get_session(id=session_id)
Zachary Sailer
manual rebase - add sessions web service
r12985 self.finish(jsonapi.dumps(model))
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 @web.authenticated
def patch(self, session_id):
Zachary Sailer
session manager restructuring...
r13035 # Currently, this handler is strictly for renaming notebooks
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
nbm = self.notebook_manager
km = self.kernel_manager
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 notebook_path = self.request.body
Zachary Sailer
session manager restructuring...
r13035 name, path = nbm.named_notebook_path(notebook_path)
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 sm.update_session(session_id, name=name)
Zachary Sailer
session manager restructuring...
r13035 model = sm.get_session(id=session_id)
Zachary Sailer
fixed shutdown button refresh on dashboard
r12996 self.finish(jsonapi.dumps(model))
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
manual rebase - add sessions web service
r12985 @web.authenticated
def delete(self, session_id):
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 # Deletes the session with given session_id
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
nbm = self.notebook_manager
km = self.kernel_manager
Zachary Sailer
session manager restructuring...
r13035 session = sm.get_session(id=session_id)
sm.delete_session(session_id)
km.shutdown_kernel(session['kernel']['id'])
Zachary Sailer
fixed shutdown button refresh on dashboard
r12996 self.set_status(204)
self.finish()
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
manual rebase - add sessions web service
r12985
#-----------------------------------------------------------------------------
# URL to handler mappings
#-----------------------------------------------------------------------------
_session_id_regex = r"(?P<session_id>\w+-\w+-\w+-\w+-\w+)"
default_handlers = [
(r"api/sessions/%s" % _session_id_regex, SessionHandler),
(r"api/sessions", SessionRootHandler)
]