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

Fix minimal nodes API with newer weaviate versions #877

Merged
merged 2 commits into from
Feb 15, 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
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

env:
OLD_WEAVIATE_VERSION: 1.23.7
NEW_WEAVIATE_VERSION: preview-add-nil-props-to-grpc-map-625f009
NEW_WEAVIATE_VERSION: 1.23.9-61c4f2f

jobs:
lint-and-format:
Expand Down
14 changes: 6 additions & 8 deletions weaviate/collections/classes/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@ class Stats:

Shards = List[Shard]
S = TypeVar("S")
S2 = TypeVar("S2")
dirkkul marked this conversation as resolved.
Show resolved Hide resolved


@dataclass
class Node(Generic[S]):
class Node(Generic[S, S2]):
"""The properties of a single node in the cluster."""

git_hash: str
name: str
shards: S
stats: Stats
stats: S2
status: str
version: str


class _ConvertFromREST:
@staticmethod
def nodes_verbose(nodes: List[NodeREST]) -> List[Node[Shards]]:
def nodes_verbose(nodes: List[NodeREST]) -> List[Node[Shards, Stats]]:
return [
Node(
git_hash=node["gitHash"],
Expand All @@ -65,16 +66,13 @@ def nodes_verbose(nodes: List[NodeREST]) -> List[Node[Shards]]:
]

@staticmethod
def nodes_minimal(nodes: List[NodeREST]) -> List[Node[None]]:
def nodes_minimal(nodes: List[NodeREST]) -> List[Node[None, None]]:
return [
Node(
git_hash=node["gitHash"],
name=node["name"],
shards=None,
stats=Stats(
object_count=node["stats"]["objectCount"],
shard_count=node["stats"]["shardCount"],
),
stats=None,
status=node["status"],
version=node["version"],
)
Expand Down
20 changes: 10 additions & 10 deletions weaviate/collections/cluster.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import List, Literal, Optional, Union, overload

from weaviate.collections.classes.cluster import Node, Shards, _ConvertFromREST
from weaviate.collections.classes.cluster import Node, Shards, _ConvertFromREST, Stats
from weaviate.connect import ConnectionV4
from weaviate.exceptions import (
EmptyResponseError,
)

from ..util import _capitalize_first_letter, _decode_json_response_dict


Expand All @@ -18,7 +19,7 @@ def nodes(
collection: Optional[str] = None,
*,
output: Literal[None] = None,
) -> List[Node[None]]:
) -> List[Node[None, None]]:
...

@overload
Expand All @@ -27,7 +28,7 @@ def nodes(
collection: Optional[str] = None,
*,
output: Literal["minimal"],
) -> List[Node[None]]:
) -> List[Node[None, None]]:
...

@overload
Expand All @@ -36,14 +37,14 @@ def nodes(
collection: Optional[str] = None,
*,
output: Literal["verbose"],
) -> List[Node[Shards]]:
) -> List[Node[Shards, Stats]]:
...

def nodes(
self,
collection: Optional[str] = None,
output: Optional[Literal["minimal", "verbose"]] = None,
) -> Union[List[Node[None]], List[Node[Shards]]]:
) -> Union[List[Node[None, None]], List[Node[Shards, Stats]]]:
"""
Get the status of all nodes in the cluster.

Expand Down Expand Up @@ -78,8 +79,7 @@ def nodes(
if nodes is None or nodes == []:
raise EmptyResponseError("Nodes status response returned empty")

return (
_ConvertFromREST.nodes_verbose(nodes)
if output == "verbose"
else _ConvertFromREST.nodes_minimal(nodes)
)
if output == "verbose":
return _ConvertFromREST.nodes_verbose(nodes)
else:
return _ConvertFromREST.nodes_minimal(nodes)
Loading