From b4849a286580e12e8082f1ffd318538096b9dbf4 Mon Sep 17 00:00:00 2001 From: matveyvarg Date: Wed, 12 Jun 2024 12:08:14 +0200 Subject: [PATCH] return none and array status --- deker_server_adapters/base.py | 9 +++++++-- deker_server_adapters/models.py | 1 + deker_server_adapters/utils/requests.py | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/deker_server_adapters/base.py b/deker_server_adapters/base.py index 3fd40a7..3f37a97 100644 --- a/deker_server_adapters/base.py +++ b/deker_server_adapters/base.py @@ -360,8 +360,10 @@ def get_by_primary_attributes( response = self.client.get( f"{self.collection_host}{url}", ) - if not response or response.status_code != STATUS_OK: + if not response or response.status_code not in [STATUS_OK, NOT_FOUND]: raise DekerServerError(response, "Couldn't fetch array") + if response.status_code == NOT_FOUND: + return None return self.__create_array_from_response( response, dict( @@ -408,9 +410,12 @@ def get_by_id( f"{self.collection_host}{url}", ) - if not response or response.status_code != STATUS_OK: + if not response or response.status_code not in [STATUS_OK, NOT_FOUND]: raise DekerServerError(response, "Couldn't fetch array") + if response.status_code == NOT_FOUND: + return None + return self.__create_array_from_response( response, dict( diff --git a/deker_server_adapters/models.py b/deker_server_adapters/models.py index ecf2794..aa427ff 100644 --- a/deker_server_adapters/models.py +++ b/deker_server_adapters/models.py @@ -6,3 +6,4 @@ class Status(str, Enum): MOVED = "exported" UNMOVED = "exporting" + NORMAL = "normal" diff --git a/deker_server_adapters/utils/requests.py b/deker_server_adapters/utils/requests.py index 24ab86d..327b64d 100644 --- a/deker_server_adapters/utils/requests.py +++ b/deker_server_adapters/utils/requests.py @@ -12,6 +12,7 @@ from deker_server_adapters.errors import DekerServerError from deker_server_adapters.models import Status from deker_server_adapters.utils.hashing import get_hash_key, get_id_and_primary_attributes +from deker_server_adapters.utils.version import get_api_version if TYPE_CHECKING: @@ -78,7 +79,7 @@ def check_status(ctx: CTX, array: BaseArray) -> Status: client: "HttpxClient" = ctx.extra["httpx_client"] node = ctx.extra["hash_ring"].get_node(get_hash_key(array)) id_, _ = get_id_and_primary_attributes(array) - url = node.url / f"/cluster/collection/{array.collection}/array/by-id/{id_}/status" + url = node.url / f"{get_api_version()}/cluster/collection/{array.collection}/array/by-id/{id_}/status" response = client.get(url.raw_url) if not response or response.status_code != STATUS_OK: