本文整理汇总了Python中notebook.connectors.base.get_api函数的典型用法代码示例。如果您正苦于以下问题:Python get_api函数的具体用法?Python get_api怎么用?Python get_api使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_api函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_logs
def get_logs(request):
response = {"status": -1}
notebook = json.loads(request.POST.get("notebook", "{}"))
snippet = json.loads(request.POST.get("snippet", "{}"))
startFrom = request.POST.get("from")
startFrom = int(startFrom) if startFrom else None
size = request.POST.get("size")
size = int(size) if size else None
db = get_api(request, snippet)
full_log = str(request.POST.get("full_log", ""))
logs = db.get_log(notebook, snippet, startFrom=startFrom, size=size)
full_log += logs
jobs = db.get_jobs(notebook, snippet, full_log)
response["logs"] = logs.strip()
response["progress"] = (
db.progress(snippet, full_log) if snippet["status"] != "available" and snippet["status"] != "success" else 100
)
response["jobs"] = jobs
response["isFullLogs"] = snippet.get("interface") == "oozie"
response["status"] = 0
return JsonResponse(response)
开发者ID:fangxingli,项目名称:hue,代码行数:29,代码来源:api.py
示例2: check_status
def check_status(request):
response = {'status': -1}
notebook = json.loads(request.POST.get('notebook', '{}'))
snippet = json.loads(request.POST.get('snippet', '{}'))
try:
response['query_status'] = get_api(request, snippet).check_status(notebook, snippet)
response['status'] = 0
except SessionExpired:
response['status'] = 'expired'
raise
except QueryExpired:
response['status'] = 'expired'
raise
finally:
if response['status'] == 0 and snippet['status'] != response['query_status']:
status = response['query_status']['status']
elif response['status'] == 'expired':
status = 'expired'
else:
status = 'failed'
if notebook['type'].startswith('query'):
nb_doc = Document2.objects.get(id=notebook['id'])
nb_doc.can_write_or_exception(request.user)
nb = Notebook(document=nb_doc).get_data()
nb['snippets'][0]['status'] = status
nb_doc.update_data(nb)
nb_doc.save()
return JsonResponse(response)
开发者ID:kevinhjk,项目名称:hue,代码行数:31,代码来源:api.py
示例3: get_logs
def get_logs(request):
response = {"status": -1}
notebook = json.loads(request.POST.get("notebook", "{}"))
snippet = json.loads(request.POST.get("snippet", "{}"))
startFrom = request.POST.get("from")
startFrom = int(startFrom) if startFrom else None
size = request.POST.get("size")
size = int(size) if size else None
db = get_api(request.user, snippet, request.fs, request.jt)
logs = db.get_log(notebook, snippet, startFrom=startFrom, size=size)
jobs = json.loads(request.POST.get("jobs", "[]"))
# Get any new jobs from current logs snippet
new_jobs = db.get_jobs(notebook, snippet, logs)
# Append new jobs to known jobs and get the unique set
if new_jobs:
all_jobs = jobs + new_jobs
jobs = dict((job["name"], job) for job in all_jobs).values()
response["logs"] = logs
response["progress"] = (
db.progress(snippet, logs) if snippet["status"] != "available" and snippet["status"] != "success" else 100
)
response["jobs"] = jobs
response["status"] = 0
return JsonResponse(response)
开发者ID:shobull,项目名称:hue,代码行数:34,代码来源:api.py
示例4: execute
def execute(request):
response = {'status': -1}
notebook = json.loads(request.POST.get('notebook', '{}'))
snippet = json.loads(request.POST.get('snippet', '{}'))
try:
response['handle'] = get_api(request, snippet).execute(notebook, snippet)
finally:
if notebook['type'].startswith('query-'):
_snippet = [s for s in notebook['snippets'] if s['id'] == snippet['id']][0]
if 'handle' in response: # No failure
_snippet['result']['handle'] = response['handle']
else:
_snippet['status'] = 'failed'
history = _historify(notebook, request.user)
response['history_id'] = history.id
response['history_uuid'] = history.uuid
if notebook['isSaved']: # Keep track of history of saved queries
response['history_parent_uuid'] = history.dependencies.filter(type__startswith='query-').latest('last_modified').uuid
# Materialize and HTML escape results
if response['handle'].get('sync') and response['handle']['result'].get('data'):
response['handle']['result']['data'] = escape_rows(response['handle']['result']['data'])
response['status'] = 0
return JsonResponse(response)
开发者ID:kevinhjk,项目名称:hue,代码行数:28,代码来源:api.py
示例5: get_logs
def get_logs(request):
response = {'status': -1}
notebook = json.loads(request.POST.get('notebook', '{}'))
snippet = json.loads(request.POST.get('snippet', '{}'))
startFrom = request.POST.get('from')
startFrom = int(startFrom) if startFrom else None
size = request.POST.get('size')
size = int(size) if size else None
db = get_api(request, snippet)
logs = db.get_log(notebook, snippet, startFrom=startFrom, size=size)
jobs = json.loads(request.POST.get('jobs', '[]'))
# Get any new jobs from current logs snippet
new_jobs = db.get_jobs(notebook, snippet, logs)
# Append new jobs to known jobs and get the unique set
if new_jobs:
all_jobs = jobs + new_jobs
jobs = dict((job['name'], job) for job in all_jobs).values()
# Retrieve full log for job progress parsing
full_log = request.POST.get('full_log', logs)
response['logs'] = logs
response['progress'] = db.progress(snippet, full_log) if snippet['status'] != 'available' and snippet['status'] != 'success' else 100
response['jobs'] = jobs
response['status'] = 0
return JsonResponse(response)
开发者ID:heshunwq,项目名称:hue,代码行数:35,代码来源:api.py
示例6: execute_and_watch
def execute_and_watch(request):
notebook_id = request.GET.get('editor', request.GET.get('notebook'))
snippet_id = int(request.GET['snippet'])
action = request.GET['action']
destination = request.GET['destination']
notebook = Notebook(document=Document2.objects.get(id=notebook_id)).get_data()
snippet = notebook['snippets'][snippet_id]
editor_type = snippet['type']
api = get_api(request, snippet)
if action == 'save_as_table':
sql, success_url = api.export_data_as_table(notebook, snippet, destination)
editor = make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready-execute')
elif action == 'insert_as_query':
sql, success_url = api.export_large_data_to_hdfs(notebook, snippet, destination)
editor = make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready-execute')
else:
raise PopupException(_('Action %s is unknown') % action)
return render('editor.mako', request, {
'notebooks_json': json.dumps([editor.get_data()]),
'options_json': json.dumps({
'languages': [{"name": "%s SQL" % editor_type.title(), "type": editor_type}],
'mode': 'editor',
'success_url': success_url
}),
'editor_type': editor_type,
})
开发者ID:277800076,项目名称:hue,代码行数:30,代码来源:views.py
示例7: export_result
def export_result(request):
response = {'status': -1, 'message': _('Exporting result failed.')}
# Passed by check_document_access_permission but unused by APIs
notebook = json.loads(request.POST.get('notebook', '{}'))
snippet = json.loads(request.POST.get('snippet', '{}'))
data_format = json.loads(request.POST.get('format', 'hdfs-file'))
destination = json.loads(request.POST.get('destination', ''))
overwrite = json.loads(request.POST.get('overwrite', False))
api = get_api(request, snippet)
if data_format == 'hdfs-file':
if overwrite and request.fs.exists(destination):
if request.fs.isfile(destination):
request.fs.do_as_user(request.user.username, request.fs.rmtree, destination)
else:
raise ValidationError(_("The target path is a directory"))
response['watch_url'] = api.export_data_as_hdfs_file(snippet, destination, overwrite)
response['status'] = 0
elif data_format == 'hive-table':
notebook_id = notebook['id'] or request.GET.get('editor', request.GET.get('notebook'))
response['watch_url'] = reverse('notebook:execute_and_watch') + '?action=save_as_table¬ebook=' + str(notebook_id) + '&snippet=0&destination=' + destination
response['status'] = 0
elif data_format == 'hdfs-directory':
notebook_id = notebook['id'] or request.GET.get('editor', request.GET.get('notebook'))
response['watch_url'] = reverse('notebook:execute_and_watch') + '?action=insert_as_query¬ebook=' + str(notebook_id) + '&snippet=0&destination=' + destination
response['status'] = 0
return JsonResponse(response)
开发者ID:heshunwq,项目名称:hue,代码行数:30,代码来源:api.py
示例8: execute
def execute(request):
response = {'status': -1}
notebook = json.loads(request.POST.get('notebook', '{}'))
snippet = json.loads(request.POST.get('snippet', '{}'))
try:
response['handle'] = get_api(request, snippet).execute(notebook, snippet)
finally:
if notebook['type'].startswith('query-'):
_snippet = [s for s in notebook['snippets'] if s['id'] == snippet['id']][0]
if 'handle' in response: # No failure
_snippet['result']['handle'] = response['handle']
_snippet['result']['statements_count'] = response['handle']['statements_count']
else:
_snippet['status'] = 'failed'
history = _historify(notebook, request.user)
response['history_id'] = history.id
response['history_uuid'] = history.uuid
# Materialize and HTML escape results
if response['handle'].get('sync') and response['handle']['result'].get('data'):
response['handle']['result']['data'] = escape_rows(response['handle']['result']['data'])
response['status'] = 0
return JsonResponse(response)
开发者ID:OSUser,项目名称:hue,代码行数:27,代码来源:api.py
示例9: guess_field_types
def guess_field_types(request):
file_format = json.loads(request.POST.get('fileFormat', '{}'))
if file_format['inputFormat'] == 'file':
indexer = Indexer(request.user, request.fs)
stream = request.fs.open(file_format["path"])
_convert_format(file_format["format"], inverse=True)
format_ = indexer.guess_field_types({
"file": {
"stream": stream,
"name": file_format['path']
},
"format": file_format['format']
})
elif file_format['inputFormat'] == 'table':
sample = get_api(request, {'type': 'hive'}).get_sample_data({'type': 'hive'}, database=file_format['databaseName'], table=file_format['tableName'])
db = dbms.get(request.user)
table_metadata = db.get_table(database=file_format['databaseName'], table_name=file_format['tableName'])
format_ = {
"sample": sample['rows'][:4],
"columns": [
Field(col.name, HiveFormat.FIELD_TYPE_TRANSLATE.get(col.type, 'string')).to_dict()
for col in table_metadata.cols
]
}
elif file_format['inputFormat'] == 'query':
#TODO get schema from explain query
pass
return JsonResponse(format_)
开发者ID:CaeserNieh,项目名称:hue,代码行数:32,代码来源:api3.py
示例10: dt_logout
def dt_logout(request, next_page=None):
"""Log out the user"""
username = request.user.get_username()
request.audit = {
'username': username,
'operation': 'USER_LOGOUT',
'operationText': 'Logged out user: %s' % username
}
# Close Impala session on logout
session_app = "impala"
if request.user.has_hue_permission(action='access', app=session_app):
session = {"type":session_app,"sourceMethod":"dt_logout"}
try:
get_api(request, session).close_session(session)
except Exception, e:
LOG.warn("Error closing Impala session: %s" % e)
开发者ID:cloudera,项目名称:hue,代码行数:17,代码来源:views.py
示例11: close_session
def close_session(request):
response = {'status': -1}
session = json.loads(request.POST.get('session', '{}'))
response['session'] = get_api(request, {'type': session['type']}).close_session(session=session)
response['status'] = 0
return JsonResponse(response)
开发者ID:heshunwq,项目名称:hue,代码行数:9,代码来源:api.py
示例12: close_session
def close_session(request):
response = {"status": -1}
session = json.loads(request.POST.get("session", "{}"))
response["session"] = get_api(request, {"type": session["type"]}).close_session(session=session)
response["status"] = 0
return JsonResponse(response)
开发者ID:fangxingli,项目名称:hue,代码行数:9,代码来源:api.py
示例13: explain
def explain(request):
response = {'status': -1}
notebook = json.loads(request.POST.get('notebook', '{}'))
snippet = json.loads(request.POST.get('snippet', '{}'))
response = get_api(request, snippet).explain(notebook, snippet)
return JsonResponse(response)
开发者ID:heshunwq,项目名称:hue,代码行数:9,代码来源:api.py
示例14: explain
def explain(request):
response = {"status": -1}
notebook = json.loads(request.POST.get("notebook", "{}"))
snippet = json.loads(request.POST.get("snippet", "{}"))
response = get_api(request, snippet).explain(notebook, snippet)
return JsonResponse(response)
开发者ID:fangxingli,项目名称:hue,代码行数:9,代码来源:api.py
示例15: check_status
def check_status(request):
response = {"status": -1}
notebook = json.loads(request.POST.get("notebook", "{}"))
snippet = json.loads(request.POST.get("snippet", "{}"))
response["query_status"] = get_api(request.user, snippet, request.fs, request.jt).check_status(notebook, snippet)
response["status"] = 0
return JsonResponse(response)
开发者ID:shobull,项目名称:hue,代码行数:10,代码来源:api.py
示例16: fetch_result_metadata
def fetch_result_metadata(request):
response = {"status": -1}
notebook = json.loads(request.POST.get("notebook", "{}"))
snippet = json.loads(request.POST.get("snippet", "{}"))
response["result"] = get_api(request.user, snippet, request.fs, request.jt).fetch_result_metadata(notebook, snippet)
response["status"] = 0
return JsonResponse(response)
开发者ID:shobull,项目名称:hue,代码行数:10,代码来源:api.py
示例17: cancel_statement
def cancel_statement(request):
response = {'status': -1}
notebook = json.loads(request.POST.get('notebook', '{}'))
snippet = json.loads(request.POST.get('snippet', '{}'))
response['result'] = get_api(request, snippet).cancel(notebook, snippet)
response['status'] = 0
return JsonResponse(response)
开发者ID:heshunwq,项目名称:hue,代码行数:10,代码来源:api.py
示例18: fetch_result_metadata
def fetch_result_metadata(request):
response = {'status': -1}
notebook = json.loads(request.POST.get('notebook', '{}'))
snippet = json.loads(request.POST.get('snippet', '{}'))
response['result'] = get_api(request, snippet).fetch_result_metadata(notebook, snippet)
response['status'] = 0
return JsonResponse(response)
开发者ID:heshunwq,项目名称:hue,代码行数:10,代码来源:api.py
示例19: cancel_statement
def cancel_statement(request):
response = {"status": -1}
notebook = json.loads(request.POST.get("notebook", "{}"))
snippet = json.loads(request.POST.get("snippet", "{}"))
response["result"] = get_api(request.user, snippet, request.fs, request.jt).cancel(notebook, snippet)
response["status"] = 0
return JsonResponse(response)
开发者ID:shobull,项目名称:hue,代码行数:10,代码来源:api.py
示例20: check_status
def check_status(request):
response = {'status': -1}
notebook = json.loads(request.POST.get('notebook', '{}'))
snippet = json.loads(request.POST.get('snippet', '{}'))
response['query_status'] = get_api(request, snippet).check_status(notebook, snippet)
response['status'] = 0
return JsonResponse(response)
开发者ID:bmannava-invn,项目名称:hue,代码行数:10,代码来源:api.py
注:本文中的notebook.connectors.base.get_api函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论