def apps(self, filters): tasks = Document2.objects.get_history( user=self.user).order_by('-last_modified')[:MAX_JOB_FETCH.get()] apps = [] for app in tasks: # Copied, Document class should have a get_history method (via method or inheritance) notebook = Notebook(document=app).get_data() is_notification_manager = False # Supposed SQL Editor query only right now if 'snippets' in notebook: statement = notebook[ 'description'] if is_notification_manager else _get_statement( notebook) history = { 'name': app.name, 'id': app.id, 'uuid': app.uuid, 'type': app.type, 'data': { 'statement': statement[:1001] if statement else '', 'lastExecuted': notebook['snippets'][0].get('lastExecuted', -1), 'status': notebook['snippets'][0]['status'], 'parentSavedQueryUuid': notebook.get('parentSavedQueryUuid', '') } if notebook['snippets'] else {}, 'absoluteUrl': app.get_absolute_url(), } api_status = self._api_status(history) if filters.get( 'states') and api_status.lower() not in filters['states']: continue apps.append({ 'id': 'history-%010d' % history['id'], 'name': history['data']['statement'], 'status': history['data']['status'], 'apiStatus': api_status, 'type': 'history-%s' % history['type'], 'user': self.user.username, 'progress': 50, 'queue': '', 'canWrite': True, 'duration': 1, 'submitted': history['data']['lastExecuted'] }) return {'apps': apps, 'total': len(tasks)}
def apps(self, filters): filter_params = { 'user': self.user, 'username': '', 'text': '', 'state': 'all', 'states': '' } filter_params.update(_extract_query_params(filters)) if filters.get('states'): filter_params['states'] = filters['states'] if 'time' in filters: filter_params['time_value'] = int(filters['time']['time_value']) filter_params['time_unit'] = filters['time']['time_unit'] filter_params['limit'] = MAX_JOB_FETCH.get() jobs = NativeYarnApi(self.user).get_jobs(**filter_params) apps = [ massage_job_for_json(job, user=self.user) for job in sorted(jobs, key=lambda job: job.jobId, reverse=True) ] return { 'apps': [{ 'id': app['id'], 'name': app['name'], 'type': app['applicationType'], 'status': app['status'], 'apiStatus': self._api_status(app['status']), 'user': app['user'], 'progress': app['progress'], 'queue': app['queueName'], 'duration': app['durationMs'], 'submitted': app['startTimeMs'], 'canWrite': app['canKill'], } for app in apps], 'total': len(apps) }
def apps(self, filters): filter_params = { 'user': self.user, 'username': '', 'text': '', 'state': 'all', 'states': '' } filter_params.update(_extract_query_params(filters)) if filters.get('states'): filter_params['states'] = filters['states'] if 'time' in filters: filter_params['time_value'] = int(filters['time']['time_value']) filter_params['time_unit'] = filters['time']['time_unit'] filter_params['limit'] = MAX_JOB_FETCH.get() jobs = NativeYarnApi(self.user).get_jobs(**filter_params) apps = [massage_job_for_json(job, user=self.user) for job in sorted(jobs, key=lambda job: job.jobId, reverse=True)] return { 'apps': [{ 'id': app['id'], 'name': app['name'], 'type': app['applicationType'], 'status': app['status'], 'apiStatus': self._api_status(app['status']), 'user': app['user'], 'progress': app['progress'], 'queue': app['queueName'], 'duration': app['durationMs'], 'submitted': app['startTimeMs'], 'canWrite': app['canKill'], } for app in apps], 'total': len(apps) }