Skip to content

Commit e617862

Browse files
authored
Merge pull request #76 from weaviate/node-status-class
Add class parameter to nodes API
2 parents 829aa08 + a544efb commit e617862

File tree

3 files changed

+97
-36
lines changed

3 files changed

+97
-36
lines changed

src/cluster/journey.test.ts

Lines changed: 82 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import weaviate from '..';
1+
import weaviate, { NodesStatusResponse } from '..';
22

3-
const {
3+
import {
44
createTestFoodSchemaAndData,
55
cleanupTestFood,
66
PIZZA_CLASS_NAME,
77
SOUP_CLASS_NAME,
8-
} = require('../utils/testData');
8+
} from '../utils/testData';
99

1010
const EXPECTED_WEAVIATE_VERSION = '1.20.0-prealpha';
1111
const EXPECTED_WEAVIATE_GIT_HASH = '0529e8e';
@@ -20,16 +20,22 @@ describe('cluster nodes endpoint', () => {
2020
return client.cluster
2121
.nodesStatusGetter()
2222
.do()
23-
.then((nodesStatusResponse: any) => {
23+
.then((nodesStatusResponse: NodesStatusResponse) => {
24+
expect(nodesStatusResponse.nodes).toBeDefined();
2425
expect(nodesStatusResponse.nodes).toHaveLength(1);
25-
const node = nodesStatusResponse.nodes[0];
26-
expect(node.name).toMatch(/.+/);
27-
expect(node.version).toEqual(EXPECTED_WEAVIATE_VERSION);
28-
expect(node.gitHash).toEqual(EXPECTED_WEAVIATE_GIT_HASH);
29-
expect(node.status).toEqual('HEALTHY');
30-
expect(node.stats.objectCount).toEqual(0);
31-
expect(node.stats.shardCount).toEqual(0);
32-
expect(node.shards).toBeNull();
26+
if (nodesStatusResponse.nodes) {
27+
const node = nodesStatusResponse.nodes[0] ?? [];
28+
expect(node.name).toMatch(/.+/);
29+
expect(node.version).toEqual(EXPECTED_WEAVIATE_VERSION);
30+
expect(node.gitHash).toEqual(EXPECTED_WEAVIATE_GIT_HASH);
31+
expect(node.status).toEqual('HEALTHY');
32+
expect(node.stats).toBeDefined();
33+
expect(node.stats?.objectCount).toEqual(0);
34+
expect(node.stats?.shardCount).toEqual(0);
35+
expect(node.shards).toBeNull();
36+
} else {
37+
throw new Error('nodesStatusResponse.nodes should be defined');
38+
}
3339
})
3440
.catch((e: any) => {
3541
throw new Error('should not fail on getting nodes: ' + e);
@@ -42,31 +48,73 @@ describe('cluster nodes endpoint', () => {
4248
return client.cluster
4349
.nodesStatusGetter()
4450
.do()
45-
.then((nodesStatusResponse: any) => {
51+
.then((nodesStatusResponse: NodesStatusResponse) => {
4652
expect(nodesStatusResponse.nodes).toHaveLength(1);
47-
const node = nodesStatusResponse.nodes[0];
48-
expect(node.name).toMatch(/.+/);
49-
expect(node.version).toEqual(EXPECTED_WEAVIATE_VERSION);
50-
expect(node.gitHash).toEqual(EXPECTED_WEAVIATE_GIT_HASH);
51-
expect(node.status).toEqual('HEALTHY');
52-
expect(node.stats.objectCount).toEqual(6);
53-
expect(node.stats.shardCount).toEqual(2);
54-
expect(node.shards).toHaveLength(2);
55-
expect([node.shards[0].class, node.shards[1].class]).toEqual(
56-
expect.arrayContaining([PIZZA_CLASS_NAME, SOUP_CLASS_NAME])
57-
);
58-
for (let i = 0; i < node.shards.length; i++) {
59-
const shard = node.shards[i];
53+
if (nodesStatusResponse.nodes) {
54+
const node = nodesStatusResponse.nodes[0];
55+
expect(node.name).toMatch(/.+/);
56+
expect(node.version).toEqual(EXPECTED_WEAVIATE_VERSION);
57+
expect(node.gitHash).toEqual(EXPECTED_WEAVIATE_GIT_HASH);
58+
expect(node.status).toEqual('HEALTHY');
59+
expect(node.stats?.objectCount).toEqual(6);
60+
expect(node.stats?.shardCount).toEqual(2);
61+
expect(node.shards).toBeDefined();
62+
expect(node.shards).toHaveLength(2);
63+
if (node.shards) {
64+
expect([node.shards[0].class, node.shards[1].class]).toEqual(
65+
expect.arrayContaining([PIZZA_CLASS_NAME, SOUP_CLASS_NAME])
66+
);
67+
for (let i = 0; i < node.shards.length; i++) {
68+
const shard = node.shards[i];
69+
expect(shard.name).toMatch(/.+/);
70+
switch (shard.class) {
71+
case PIZZA_CLASS_NAME:
72+
expect(shard.objectCount).toEqual(4);
73+
break;
74+
case SOUP_CLASS_NAME:
75+
expect(shard.objectCount).toEqual(2);
76+
break;
77+
}
78+
}
79+
} else {
80+
throw new Error('node.shards should be defined');
81+
}
82+
} else {
83+
throw new Error('nodesStatusResponse.nodes should be defined');
84+
}
85+
})
86+
.catch((e: any) => {
87+
throw new Error('should not fail on getting nodes: ' + e);
88+
});
89+
});
6090

61-
expect(shard.name).toMatch(/.+/);
62-
switch (shard.class) {
63-
case PIZZA_CLASS_NAME:
64-
expect(shard.objectCount).toEqual(4);
65-
break;
66-
case SOUP_CLASS_NAME:
67-
expect(shard.objectCount).toEqual(2);
68-
break;
91+
it('get nodes status of only Pizza class in food db', () => {
92+
return client.cluster
93+
.nodesStatusGetter()
94+
.withClassName(PIZZA_CLASS_NAME)
95+
.do()
96+
.then((nodesStatusResponse: NodesStatusResponse) => {
97+
expect(nodesStatusResponse.nodes).toBeDefined();
98+
expect(nodesStatusResponse.nodes).toHaveLength(1);
99+
if (nodesStatusResponse.nodes) {
100+
const node = nodesStatusResponse.nodes[0];
101+
expect(node.name).toMatch(/.+/);
102+
expect(node.version).toEqual(EXPECTED_WEAVIATE_VERSION);
103+
expect(node.gitHash).toEqual(EXPECTED_WEAVIATE_GIT_HASH);
104+
expect(node.status).toEqual('HEALTHY');
105+
expect(node.stats?.objectCount).toEqual(4);
106+
expect(node.stats?.shardCount).toEqual(1);
107+
expect(node.shards).toBeDefined();
108+
expect(node.shards).toHaveLength(1);
109+
if (node.shards) {
110+
expect(node.shards[0].class).toEqual(PIZZA_CLASS_NAME);
111+
expect(node.shards[0].objectCount).toEqual(4);
112+
expect(node.shards[0].name).toBeDefined();
113+
} else {
114+
throw new Error('node.shards should be defined');
69115
}
116+
} else {
117+
throw new Error('nodesStatusResponse.nodes should be defined');
70118
}
71119
})
72120
.catch((e: any) => {

src/cluster/nodesStatusGetter.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
import Connection from '../connection';
2+
import { NodesStatusResponse } from '../openapi/types';
23
import { CommandBase } from '../validation/commandBase';
34

45
export default class NodesStatusGetter extends CommandBase {
6+
private className?: string;
7+
58
constructor(client: Connection) {
69
super(client);
710
}
811

12+
withClassName = (className: string) => {
13+
this.className = className;
14+
return this;
15+
};
16+
917
validate() {
1018
// nothing to validate
1119
}
1220

13-
do() {
21+
do = (): Promise<NodesStatusResponse> => {
22+
if (this.className) {
23+
return this.client.get(`/nodes/${this.className}`);
24+
}
1425
return this.client.get('/nodes');
15-
}
26+
};
1627
}

src/openapi/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ export type ShardStatus = definitions['ShardStatus'];
3838
export type ShardStatusList = definitions['ShardStatusList'];
3939
export type Tenant = definitions['Tenant'];
4040
export type SchemaClusterStatus = definitions['SchemaClusterStatus'];
41+
// Nodes
42+
export type NodesStatusResponse = definitions['NodesStatusResponse'];

0 commit comments

Comments
 (0)