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+ from  typing  import  Dict , Any 
27+ 
28+ from  databricks_cli .sdk .service  import  ExecutionContextService 
29+ 
30+ 
31+ class  ExecutionContext (object ):
32+     def  __init__ (self , api_client , cluster_id ):
33+         self .client  =  ExecutionContextService (api_client )
34+         self .cluster_id  =  cluster_id 
35+         self .id  =  None 
36+ 
37+     def  __enter__ (self ):
38+         if  self .id  is  None :
39+             self .id  =  self .client .create_context (cluster_id = self .cluster_id )["id" ]
40+ 
41+         return  self 
42+ 
43+     def  __exit__ (self , _type , _value , _traceback ):
44+         self .client .delete_context (cluster_id = self .cluster_id , context_id = self .id )
45+         self .id  =  None 
46+ 
47+ 
48+ class  ExecutionContextApi (object ):
49+ 
50+     def  __init__ (self , api_client ):
51+         self .client  =  ExecutionContextService (api_client )
52+ 
53+     def  create_context (self , cluster_id , language = "python" ):
54+         # type: (str, str, Dict[Any, Any])  -> Dict[Any, Any] 
55+         return  self .client .create_context (cluster_id , language )
56+ 
57+     def  get_context_status (self , cluster_id , context_id ):
58+         # type: (str, str, Dict[Any, Any])  -> Dict[Any, Any] 
59+         return  self .client .get_context_status (cluster_id , context_id )
60+ 
61+     def  delete_context (self , cluster_id , context_id ):
62+         # type: (str, str, Dict[Any, Any]) -> Any 
63+         return  self .client .delete_context (cluster_id , context_id )
64+ 
65+     def  execute_command (self , cluster_id , context_id , command , language = "python" ):
66+         # type: (str, str, str, str, Dict[Any, Any]) -> Dict[Any, Any] 
67+         return  self .client .execute_command (cluster_id , context_id , command , language )
68+ 
69+     def  cancel_command (self , cluster_id , context_id , command_id ):
70+         # type: (str, str, str, Dict[Any, Any]) -> Dict[Any, Any] 
71+         return  self .client .cancel_command (cluster_id , context_id , command_id )
72+ 
73+     def  get_command_status (self , cluster_id , context_id , command_id ):
74+         # type: (str, str, str, Dict[Any, Any]) -> Dict[Any, Any] 
75+         return  self .client .get_command_status (cluster_id , context_id , command_id )
0 commit comments