-
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
469 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,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) |
Oops, something went wrong.