def get(self, job_id): """ # 查询这个job 的运行信息 Retrieve info about a running query job. """ job = QueryTask(job_id=job_id) return {'job': job.to_dict()}
def get(self, job_id): """ Retrieve info about a running query job. """ #print("@# JobResource ...",job_id) job = QueryTask(job_id=job_id) return {'job': job.to_dict()}
def post(self): params = request.get_json(force=True) data_source = models.DataSource.get_by_id_and_org(params.get('data_source_id'), self.current_org) if not has_access(data_source.groups, self.current_user, not_view_only): return {'job': {'status': 4, 'error': 'You do not have permission to run queries with this data source.'}}, 403 self.record_event({ 'action': 'execute_query', 'timestamp': int(time.time()), 'object_id': data_source.id, 'object_type': 'data_source', 'query': params['query'] }) max_age = int(params.get('max_age', -1)) if max_age == 0: query_result = None else: query_result = models.QueryResult.get_latest(data_source, params['query'], max_age) if query_result: return {'query_result': query_result.to_dict()} else: query_id = params.get('query_id', 'adhoc') job = QueryTask.add_task(params['query'], data_source, metadata={"Username": self.current_user.name, "Query ID": query_id}) return {'job': job.to_dict()}
def post(self): params = request.get_json(force=True) if settings.FEATURE_TABLES_PERMISSIONS: metadata = utils.SQLMetaData(params["query"]) if metadata.has_non_select_dml_statements or metadata.has_ddl_statements: return {"job": {"error": "Only SELECT statements are allowed"}} if len(metadata.used_tables - current_user.allowed_tables) > 0 and "*" not in current_user.allowed_tables: logging.warning( "Permission denied for user %s to table %s", self.current_user.name, metadata.used_tables ) return {"job": {"error": "Access denied for table(s): %s" % (metadata.used_tables)}} models.ActivityLog( user=self.current_user, type=models.ActivityLog.QUERY_EXECUTION, activity=params["query"] ).save() max_age = int(params.get("max_age", -1)) if max_age == 0: query_result = None else: query_result = models.QueryResult.get_latest(params["data_source_id"], params["query"], max_age) if query_result: return {"query_result": query_result.to_dict()} else: data_source = models.DataSource.get_by_id(params["data_source_id"]) query_id = params.get("query_id", "adhoc") job = QueryTask.add_task( params["query"], data_source, metadata={"Username": self.current_user.name, "Query ID": query_id} ) return {"job": job.to_dict()}
def run_query(data_source, parameter_values, query_text, query_id, max_age=0): query_parameters = set(collect_query_parameters(query_text)) missing_params = set(query_parameters) - set(parameter_values.keys()) if missing_params: return { 'job': { 'status': 4, 'error': 'Missing parameter value for: {}'.format( ", ".join(missing_params)) } }, 400 if query_parameters: query_text = pystache.render(query_text, parameter_values) if max_age == 0: query_result = None else: query_result = models.QueryResult.get_latest(data_source, query_text, max_age) if query_result: return {'query_result': query_result.to_dict()} else: job = QueryTask.add_task(query_text, data_source, metadata={ "Username": current_user.name, "Query ID": query_id }) return {'job': job.to_dict()}
def get(self, job_id, data_source_id): job = QueryTask(job_id=job_id) job._async_result._get_task_meta() data_source = models.DataSource.get_by_id_and_org( data_source_id, self.current_org) reserved_tasks = [ task for task in parse_tasks(celery.control.inspect().reserved(), 'reserved') if task['queue'] == data_source.queue_name ] tasks = reserved_tasks + get_waiting_in_queue(data_source.queue_name) return {'queue_name': data_source.queue_name, 'num_tasks': len(tasks)}
def post(self): params = request.get_json(force=True) if settings.FEATURE_TABLES_PERMISSIONS: metadata = utils.SQLMetaData(params['query']) if metadata.has_non_select_dml_statements or metadata.has_ddl_statements: return {'job': {'error': 'Only SELECT statements are allowed'}} if len(metadata.used_tables - current_user.allowed_tables ) > 0 and '*' not in current_user.allowed_tables: logging.warning('Permission denied for user %s to table %s', self.current_user.name, metadata.used_tables) return { 'job': { 'error': 'Access denied for table(s): %s' % (metadata.used_tables) } } models.ActivityLog(user=self.current_user, type=models.ActivityLog.QUERY_EXECUTION, activity=params['query']).save() max_age = int(params.get('max_age', -1)) if max_age == 0: query_result = None else: query_result = models.QueryResult.get_latest( params['data_source_id'], params['query'], max_age) if query_result: return {'query_result': query_result.to_dict()} else: data_source = models.DataSource.get_by_id(params['data_source_id']) query_id = params.get('query_id', 'adhoc') job = QueryTask.add_task(params['query'], data_source, metadata={ "Username": self.current_user.name, "Query ID": query_id }) return {'job': job.to_dict()}
def post(self): params = request.json if settings.FEATURE_TABLES_PERMISSIONS: metadata = utils.SQLMetaData(params['query']) if metadata.has_non_select_dml_statements or metadata.has_ddl_statements: return { 'job': { 'error': 'Only SELECT statements are allowed' } } if len(metadata.used_tables - current_user.allowed_tables) > 0 and '*' not in current_user.allowed_tables: logging.warning('Permission denied for user %s to table %s', self.current_user.name, metadata.used_tables) return { 'job': { 'error': 'Access denied for table(s): %s' % (metadata.used_tables) } } models.ActivityLog( user=self.current_user, type=models.ActivityLog.QUERY_EXECUTION, activity=params['query'] ).save() max_age = int(params['max_age']) if max_age == 0: query_result = None else: query_result = models.QueryResult.get_latest(params['data_source_id'], params['query'], max_age) if query_result: return {'query_result': query_result.to_dict()} else: data_source = models.DataSource.get_by_id(params['data_source_id']) query_id = params.get('query_id', 'adhoc') job = QueryTask.add_task(params['query'], data_source, metadata={"Username": self.current_user.name, "Query ID": query_id}) return {'job': job.to_dict()}
def run_query(data_source, parameter_values, query_text, query_id, max_age=0): query_parameters = set(collect_query_parameters(query_text)) missing_params = set(query_parameters) - set(parameter_values.keys()) if missing_params: return {'job': {'status': 4, 'error': 'Missing parameter value for: {}'.format(", ".join(missing_params))}}, 400 if query_parameters: query_text = pystache.render(query_text, parameter_values) if max_age == 0: query_result = None else: query_result = models.QueryResult.get_latest(data_source, query_text, max_age) if query_result: return {'query_result': query_result.to_dict()} else: job = QueryTask.add_task(query_text, data_source, metadata={"Username": current_user.name, "Query ID": query_id}) return {'job': job.to_dict()}
def delete(self, job_id): """ Cancel a query job in progress. """ job = QueryTask(job_id=job_id) job.cancel()
def delete(self, job_id): job = QueryTask(job_id=job_id) job.cancel()
def get(self, job_id): # TODO: if finished, include the query result job = QueryTask(job_id=job_id) return {'job': job.to_dict()}
def get(self, job_id): """ Retrieve info about a running query job. """ job = QueryTask(job_id=job_id) return {'job': job.to_dict()}
def get(self, job_id): job = QueryTask(job_id=job_id) return {'job': job.to_dict()}
def get(self, job_id, query_id=None): """ Retrieve info about a running query job. """ job = QueryTask(job_id=job_id) return {'job': job.to_dict()}
def get_job(job_id): """ Retrieve info about a running query job. """ job = QueryTask(job_id=job_id) return json_response({'job': job.to_dict()})