-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add execution context API #455
Draft
fjakobs
wants to merge
1
commit into
databricks:main
Choose a base branch
from
fabianjakobs:execution-context-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you reuse the basic structure for command/context APIs from Tunnel CLI, so that it won't break, once merged? :)
6c429d4
it's removed, so probably it has to be re-added
0296117