-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathapi.py
More file actions
76 lines (62 loc) · 3.05 KB
/
api.py
File metadata and controls
76 lines (62 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# WARNING THIS FILE IS AUTOGENERATED
#
# Databricks CLI
# Copyright 2017 Databricks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"), except
# that the use of services to which certain application programming
# interfaces (each, an "API") connect requires that the user first obtain
# a license for the use of the APIs from Databricks, Inc. ("Databricks"),
# by creating an account at www.databricks.com and agreeing to either (a)
# the Community Edition Terms of Service, (b) the Databricks Terms of
# Service, or (c) another written agreement between Licensee and Databricks
# for the use of the APIs.
#
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys
from databricks_cli.sdk.service import ExecutionContextService
if sys.version_info > (3, 5):
from typing import Dict, Any # noqa
class ExecutionContext(object):
def __init__(self, api_client, cluster_id):
self.client = ExecutionContextService(api_client)
self.cluster_id = cluster_id
self.id = None
def __enter__(self):
if self.id is None:
self.id = self.client.create_context(cluster_id=self.cluster_id)["id"]
return self
def __exit__(self, _type, _value, _traceback):
self.client.delete_context(cluster_id=self.cluster_id, context_id=self.id)
self.id = None
class ExecutionContextApi(object):
def __init__(self, api_client):
self.client = ExecutionContextService(api_client)
def create_context(self, cluster_id, language="python"):
# type: (str, str, Dict[Any, Any]) -> Dict[Any, Any]
return self.client.create_context(cluster_id, language)
def get_context_status(self, cluster_id, context_id):
# type: (str, str, Dict[Any, Any]) -> Dict[Any, Any]
return self.client.get_context_status(cluster_id, context_id)
def delete_context(self, cluster_id, context_id):
# type: (str, str, Dict[Any, Any]) -> Any
return self.client.delete_context(cluster_id, context_id)
def execute_command(self, cluster_id, context_id, command, language="python"):
# type: (str, str, str, str, Dict[Any, Any]) -> Dict[Any, Any]
return self.client.execute_command(cluster_id, context_id, command, language)
def cancel_command(self, cluster_id, context_id, command_id):
# type: (str, str, str, Dict[Any, Any]) -> Dict[Any, Any]
return self.client.cancel_command(cluster_id, context_id, command_id)
def get_command_status(self, cluster_id, context_id, command_id):
# type: (str, str, str, Dict[Any, Any]) -> Dict[Any, Any]
return self.client.get_command_status(cluster_id, context_id, command_id)