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