def system(request): # single Livy session LOGGER.debug("checking for active Livy session") livy_session = LivySession.get_active_session() # if session found, refresh if isinstance(livy_session, LivySession): # refresh livy_session.refresh_from_livy() # create and append to list livy_sessions = [livy_session] elif isinstance(livy_session, QuerySet): # loop and refresh for session in livy_session: session.refresh_from_livy() # set as list livy_sessions = livy_session else: livy_sessions = livy_session # get status of background jobs if not hasattr(settings, 'COMBINE_DEPLOYMENT') or settings.COMBINE_DEPLOYMENT != 'docker': try: supervisor = SupervisorRPCClient() bgtasks_proc = supervisor.check_process('celery') except: LOGGER.debug('supervisor might be down?') bgtasks_proc = None else: bgtasks_proc = None # get celery worker status active_tasks = celery_app.control.inspect().active() if active_tasks is None: celery_status = 'stopped' else: if len(next(iter(active_tasks.values()))) == 0: celery_status = 'idle' elif len(next(iter(active_tasks.values()))) > 0: celery_status = 'busy' else: celery_status = 'unknown' # return return render(request, 'core/system.html', { 'livy_session': livy_session, 'livy_sessions': livy_sessions, 'celery_status': celery_status, 'bgtasks_proc': bgtasks_proc, 'breadcrumbs': breadcrumb_parser(request) })
def livy_session(request): ''' Make Livy session information available to all views ''' # get active livy session lv = LivySession.get_active_session() return {'LIVY_SESSION': lv}
def livy_session(request): ''' Make Livy session information available to all views ''' # get active livy session lv = LivySession.get_active_session() if lv: if type(lv) == LivySession: # refresh single session lv.refresh_from_livy() elif type(lv) == QuerySet: # multiple Combine LivySession founds, loop through for s in lv: s.refresh_from_livy() else: pass return {'LIVY_SESSION': lv}
def livy_session_start(request): LOGGER.debug('Checking for pre-existing livy sessions') # get active livy sessions active_ls = LivySession.get_active_session() # none found if not active_ls: LOGGER.debug('active livy session not found, starting') livy_session = LivySession() livy_session.start_session() elif isinstance(active_ls, LivySession) and request.GET.get('restart') == 'true': LOGGER.debug( 'single, active session found, and restart flag passed, restarting') # restart active_ls.restart_session() # redirect return redirect('system')
def system_bg_status(request): """ View to return status on: - Livy session - celery worker """ # get livy status livy_session = LivySession.get_active_session() if livy_session: if isinstance(livy_session, LivySession): # refresh single session livy_session.refresh_from_livy() # set status livy_status = livy_session.status else: livy_status = 'stopped' # get celery worker status active_tasks = celery_app.control.inspect().active() # if None, assume celery app stopeed if active_tasks is None: celery_status = 'stopped' # else, determine if idle, busy, or unknown state else: if len(next(iter(active_tasks.values()))) == 0: celery_status = 'idle' elif len(next(iter(active_tasks.values()))) > 0: celery_status = 'busy' else: celery_status = 'unknown' # return json return JsonResponse({ 'celery_status': celery_status, 'livy_status': livy_status })