本文整理汇总了Python中spark.job_server_api.get_spark_api函数的典型用法代码示例。如果您正苦于以下问题:Python get_spark_api函数的具体用法?Python get_spark_api怎么用?Python get_spark_api使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_spark_api函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_status
def check_status(self, notebook, snippet):
api = get_spark_api(self.user)
state = api.get_batch_status(snippet['result']['handle']['id'])
return {
'status': state,
}
示例2: create_session
def create_session(self, lang='scala', properties=None):
if not properties:
config = DefaultConfiguration.objects.get_configuration_for_user(app='spark', user=self.user)
if config is not None:
properties = config.properties_list
else:
properties = self.get_properties()
props = dict([(p['name'], p['value']) for p in properties]) if properties is not None else {}
props['kind'] = lang
api = get_spark_api(self.user)
response = api.create_session(**props)
status = api.get_session(response['id'])
count = 0
while status['state'] == 'starting' and count < 120:
status = api.get_session(response['id'])
count += 1
time.sleep(1)
if status['state'] != 'idle':
info = '\n'.join(status['log']) if status['log'] else 'timeout'
raise QueryError(_('The Spark session could not be created in the cluster: %s') % info)
return {
'type': lang,
'id': response['id'],
'properties': properties
}
示例3: create_session
def create_session(self, lang='scala', properties=None):
properties = dict([(p['name'], p['value']) for p in properties]) if properties is not None else {}
properties['kind'] = lang
api = get_spark_api(self.user)
response = api.create_session(**properties)
status = api.get_session(response['id'])
count = 0
while status['state'] == 'starting' and count < 120:
status = api.get_session(response['id'])
count += 1
time.sleep(1)
if status['state'] != 'idle':
info = '\n'.join(status['log']) if status['log'] else 'timeout'
raise QueryError(_('The Spark session could not be created in the cluster: %s') % info)
return {
'type': lang,
'id': response['id'],
'properties': []
}
示例4: create_session
def create_session(self, lang="scala", properties=None):
if properties is None:
settings = {
"executor_cores": 1, # Some props only in YARN mode
"executor_count": 1,
"executor_memory": "1G",
"driver_cores": 1,
"driver_memory": "1G",
}
api = get_spark_api(self.user)
print "TODO: we should use the settings %s for creating the new sessions" % settings
response = api.create_session(kind=lang)
status = api.get_session(response["id"])
count = 0
while status["state"] == "starting" and count < 120:
status = api.get_session(response["id"])
count += 1
time.sleep(1)
if status["state"] != "idle":
raise QueryError("\n".join(status["log"]))
return {"type": lang, "id": response["id"], "properties": settings}
示例5: close_statement
def close_statement(self, snippet):
api = get_spark_api(self.user)
session_id = snippet["result"]["handle"]["id"]
if session_id is not None:
api.close_batch(session_id)
return {"session": session_id, "status": 0}
else:
return {"status": -1} # skipped
示例6: download
def download(self, notebook, snippet, format):
try:
api = get_spark_api(self.user)
session = _get_snippet_session(notebook, snippet)
cell = snippet['result']['handle']['id']
return spark_download(api, session['id'], cell, format)
except Exception, e:
raise PopupException(e)
示例7: close
def close(self, notebook, snippet):
api = get_spark_api(self.user)
session = _get_snippet_session(notebook, snippet)
if session["id"] is not None:
api.close(session["id"])
return {"session": session["id"], "status": 0}
else:
return {"status": -1}
示例8: close_session
def close_session(self, session):
api = get_spark_api(self.user)
if session["id"] is not None:
try:
api.close(session["id"])
return {"session": session["id"], "status": 0}
except RestException, e:
if e.code == 404 or e.code == 500: # TODO remove the 500
raise SessionExpired(e)
示例9: close_session
def close_session(self, session):
api = get_spark_api(self.user)
if session['id'] is not None:
api.close(session['id'])
return {
'session': session['id'],
'status': 0
}
else:
return {'status': -1}
示例10: close
def close(self, notebook, snippet):
api = get_spark_api(self.user)
session = _get_snippet_session(notebook, snippet)
if session['id'] is not None:
api.close(session['id'])
return {
'session': session['id'],
'status': 'closed'
}
else:
return {'status': 'skipped'}
示例11: create_session
def create_session(self, lang="scala"):
api = get_spark_api(self.user)
response = api.create_session(kind=lang)
status = api.get_session(response["id"])
count = 0
while status["state"] == "starting" and count < 120:
status = api.get_session(response["id"])
count += 1
time.sleep(1)
return {"type": lang, "id": response["id"]}
示例12: fetch_result
def fetch_result(self, notebook, snippet, rows, start_over):
api = get_spark_api(self.user)
session = _get_snippet_session(notebook, snippet)
cell = snippet['result']['handle']['id']
try:
response = api.fetch_data(session['id'], cell)
except Exception, e:
message = force_unicode(str(e)).lower()
if 'session not found' in message:
raise SessionExpired(e)
else:
raise e
示例13: close_session
def close_session(self, session):
api = get_spark_api(self.user)
if session['id'] is not None:
try:
api.close(session['id'])
return {
'session': session['id'],
'status': 0
}
except RestException, e:
if e.code == 404 or e.code == 500: # TODO remove the 500
raise SessionExpired(e)
示例14: check_status
def check_status(self, notebook, snippet):
api = get_spark_api(self.user)
session = _get_snippet_session(notebook, snippet)
cell = snippet["result"]["handle"]["id"]
try:
response = api.fetch_data(session["id"], cell)
return {"status": response["state"]}
except Exception, e:
message = force_unicode(str(e)).lower()
if "session not found" in message:
raise SessionExpired(e)
else:
raise e
示例15: execute
def execute(self, notebook, snippet):
api = get_spark_api(self.user)
session = _get_snippet_session(notebook, snippet)
try:
response = api.submit_statement(session['id'], snippet['statement'])
return {
'id': response['id'],
'has_result_set': True,
}
except Exception, e:
message = force_unicode(str(e)).lower()
if 'session not found' in message or 'connection refused' in message or 'session is in state busy' in message:
raise SessionExpired(e)
else:
raise e