-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add execution context and run command APIs
These are the still supported functionality from the REST API 1.2. https://docs.databricks.com/dev-tools/api/1.2/index.html
- Loading branch information
Showing
7 changed files
with
466 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# 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. | ||
# | ||
from typing import Dict, Any | ||
|
||
from databricks_cli.sdk.service import ExecutionContextService | ||
|
||
|
||
class ExecutionContext(object): | ||
def __init__(self, api_client, cluster_id) -> None: | ||
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) -> None: | ||
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) |
Oops, something went wrong.