Skip to content

Commit

Permalink
Merge pull request #877 from weaviate/minimal_node_api
Browse files Browse the repository at this point in the history
Fix minimal nodes API with newer weaviate versions
  • Loading branch information
dirkkul authored Feb 15, 2024
2 parents 460323d + 538c18a commit 40047cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
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
18 changes: 8 additions & 10 deletions weaviate/collections/classes/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,25 @@ class Stats:


Shards = List[Shard]
S = TypeVar("S")
Sh = TypeVar("Sh")
St = TypeVar("St")


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

git_hash: str
name: str
shards: S
stats: Stats
shards: Sh
stats: St
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)

0 comments on commit 40047cd

Please sign in to comment.