Skip to content
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

[FSTORE-1281] Add method to stop execution + type hinting login+get_feature_store #203

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/hopsworks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import annotations

import warnings
import logging
import os
import sys
import getpass
import tempfile
from pathlib import Path

from hopsworks.client.exceptions import RestAPIError, ProjectException
from hopsworks import version, constants, client
from hopsworks.connection import Connection
from hopsworks import project

# Needs to run before import of hsml and hsfs

Check failure on line 31 in python/hopsworks/__init__.py

View workflow job for this annotation

GitHub Actions / Lint and Stylecheck

Ruff (I001)

python/hopsworks/__init__.py:16:1: I001 Import block is un-sorted or un-formatted
warnings.filterwarnings(action="ignore", category=UserWarning, module=r".*psycopg2")

import hsml # noqa: F401, E402
import hsfs # noqa: F401, E402

__version__ = version.__version__

Check failure on line 37 in python/hopsworks/__init__.py

View workflow job for this annotation

GitHub Actions / Lint and Stylecheck

Ruff (I001)

python/hopsworks/__init__.py:34:1: I001 Import block is un-sorted or un-formatted

connection = Connection.connection

Expand Down Expand Up @@ -62,7 +64,7 @@
project: str = None,
api_key_value: str = None,
api_key_file: str = None,
):
) -> project.Project:
"""Connect to [Serverless Hopsworks](https://app.hopsworks.ai) by calling the `hopsworks.login()` function with no arguments.

```python
Expand Down
18 changes: 18 additions & 0 deletions python/hopsworks/core/execution_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,21 @@ def _delete(self, job_name, id):
id,
]
_client._send_request("DELETE", path_params)

def _stop(self, job_name: str, id: int) -> None:
_client = client.get_instance()
path_params = [
"project",
self._project_id,
"jobs",
job_name,
"executions",
id,
"status",
]
_client._send_request(
"PUT",
path_params=path_params,
data={"state": "stopped"},
headers={"Content-Type": "application/json"},
)
9 changes: 9 additions & 0 deletions python/hopsworks/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# limitations under the License.
#

import humps
import json
from hopsworks.engine import execution_engine
from hopsworks.core import execution_api
from hopsworks import constants, util


class Execution:

Check failure on line 24 in python/hopsworks/execution.py

View workflow job for this annotation

GitHub Actions / Lint and Stylecheck

Ruff (I001)

python/hopsworks/execution.py:17:1: I001 Import block is un-sorted or un-formatted
def __init__(
self,
id=None,
Expand Down Expand Up @@ -212,6 +212,15 @@
"""
self._execution_api._delete(self._job.name, self.id)

def stop(self):
"""Stop the execution
!!! danger "Potentially dangerous operation"
This operation stops the execution.
# Raises
`RestAPIError`.
"""
self._execution_api._stop(self.job_name, self.id)

def await_termination(self):
"""Wait until execution reaches terminal state
# Raises
Expand Down
5 changes: 3 additions & 2 deletions python/hopsworks/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import annotations

import humps
import json

from hopsworks import util, client, constants
from hopsworks.client.external import Client
from hopsworks.core import (
job_api,
git_api,
dataset_api,
kafka_api,
opensearch_api,
environment_api,
flink_cluster_api,
)

from hsfs import feature_store

class Project:

Check failure on line 34 in python/hopsworks/project.py

View workflow job for this annotation

GitHub Actions / Lint and Stylecheck

Ruff (I001)

python/hopsworks/project.py:16:1: I001 Import block is un-sorted or un-formatted
def __init__(
self,
archived=None,
Expand Down Expand Up @@ -101,7 +102,7 @@
"""Timestamp when the project was created"""
return self._created

def get_feature_store(self, name: str = None):
def get_feature_store(self, name: str = None) -> feature_store.FeatureStore:
robzor92 marked this conversation as resolved.
Show resolved Hide resolved
"""Connect to Project's Feature Store.

Defaulting to the project name of default feature store. To get a
Expand Down
Loading