-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Re-adding bindings to resource manager (#325)
- Loading branch information
Showing
8 changed files
with
163 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from __future__ import annotations | ||
|
||
from datetime import datetime | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from firebolt.model.V1 import FireboltBaseModel | ||
|
||
|
||
class BindingKey(BaseModel): | ||
account_id: str | ||
database_id: str | ||
engine_id: str | ||
|
||
|
||
class Binding(FireboltBaseModel): | ||
"""A binding between an engine and a database.""" | ||
|
||
binding_key: BindingKey = Field(alias="id") | ||
is_default_engine: bool = Field(alias="engine_is_default") | ||
|
||
# optional | ||
current_status: Optional[str] | ||
health_status: Optional[str] | ||
create_time: Optional[datetime] | ||
create_actor: Optional[str] | ||
last_update_time: Optional[datetime] | ||
last_update_actor: Optional[str] | ||
desired_status: Optional[str] | ||
|
||
@property | ||
def database_id(self) -> str: | ||
return self.binding_key.database_id | ||
|
||
@property | ||
def engine_id(self) -> str: | ||
return self.binding_key.engine_id |
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,3 @@ | ||
# Temporary fix for airflow-provider-firebolt | ||
class Engine: | ||
pass |
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,49 @@ | ||
import logging | ||
from typing import List, Optional | ||
|
||
from firebolt.model.V1.binding import Binding | ||
from firebolt.service.V1.base import BaseService | ||
from firebolt.utils.urls import ACCOUNT_BINDINGS_URL | ||
from firebolt.utils.util import prune_dict | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class BindingService(BaseService): | ||
def get_many( | ||
self, | ||
database_id: Optional[str] = None, | ||
engine_id: Optional[str] = None, | ||
is_system_database: Optional[bool] = None, | ||
) -> List[Binding]: | ||
""" | ||
List bindings on Firebolt, optionally filtering by database and engine. | ||
Args: | ||
database_id: | ||
Return bindings matching the database_id. | ||
If None, match any databases. | ||
engine_id: | ||
Return bindings matching the engine_id. | ||
If None, match any engines. | ||
is_system_database: | ||
If True, return only system databases. | ||
If False, return only non-system databases. | ||
If None, do not filter on this parameter. | ||
Returns: | ||
List of bindings matching the filter parameters | ||
""" | ||
|
||
response = self.client.get( | ||
url=ACCOUNT_BINDINGS_URL.format(account_id=self.account_id), | ||
params=prune_dict( | ||
{ | ||
"page.first": 5000, # FUTURE: pagination support w/ generator | ||
"filter.id_database_id_eq": database_id, | ||
"filter.id_engine_id_eq": engine_id, | ||
"filter.is_system_database_eq": is_system_database, | ||
} | ||
), | ||
) | ||
return [Binding.parse_obj(i["node"]) for i in response.json()["edges"]] |
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
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,29 @@ | ||
from re import Pattern | ||
from typing import Callable | ||
|
||
from pytest_httpx import HTTPXMock | ||
|
||
from firebolt.common.settings import Settings | ||
from firebolt.model.V1.engine import Engine | ||
from firebolt.service.manager import ResourceManager | ||
|
||
|
||
def test_get_many_bindings( | ||
httpx_mock: HTTPXMock, | ||
auth_callback: Callable, | ||
auth_url: str, | ||
account_id_callback: Callable, | ||
account_id_url: Pattern, | ||
bindings_url: str, | ||
bindings_callback: Callable, | ||
settings: Settings, | ||
mock_engine: Engine, | ||
): | ||
httpx_mock.add_callback(auth_callback, url=auth_url) | ||
httpx_mock.add_callback(account_id_callback, url=account_id_url) | ||
httpx_mock.add_callback(bindings_callback, url=bindings_url) | ||
|
||
resource_manager = ResourceManager(settings=settings) | ||
bindings = resource_manager.bindings.get_many(engine_id=mock_engine.engine_id) | ||
assert len(bindings) > 0 | ||
assert any(binding.is_default_engine for binding in bindings) |
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