Skip to content

Commit 6948c9c

Browse files
committed
feat: add default tenant to get-shards endpoint
1 parent c4b424a commit 6948c9c

6 files changed

Lines changed: 69 additions & 33 deletions

File tree

src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandle.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ public CollectionHandle(
2929
GrpcTransport grpcTransport,
3030
CollectionDescriptor<PropertiesT> collection,
3131
CollectionHandleDefaults defaults) {
32-
this.config = new WeaviateConfigClient(collection, restTransport, grpcTransport);
32+
this.config = new WeaviateConfigClient(collection, restTransport, grpcTransport, defaults);
3333
this.aggregate = new WeaviateAggregateClient(collection, grpcTransport, defaults);
3434
this.query = new WeaviateQueryClient<>(collection, grpcTransport, defaults);
3535
this.data = new WeaviateDataClient<>(collection, restTransport, grpcTransport, defaults);
36-
this.tenants = new WeaviateTenantsClient(collection, restTransport, grpcTransport);
37-
3836
this.defaults = defaults;
37+
38+
this.tenants = new WeaviateTenantsClient(collection, restTransport, grpcTransport);
3939
}
4040

4141
/** Copy constructor that sets new defaults. */
4242
private CollectionHandle(CollectionHandle<PropertiesT> c, CollectionHandleDefaults defaults) {
43-
this.config = c.config;
4443
this.aggregate = c.aggregate;
4544
this.tenants = c.tenants;
45+
46+
this.config = new WeaviateConfigClient(c.config, defaults);
4647
this.query = new WeaviateQueryClient<>(c.query, defaults);
4748
this.data = new WeaviateDataClient<>(c.data, defaults);
48-
4949
this.defaults = defaults;
5050
}
5151

src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleAsync.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ public CollectionHandleAsync(
3232
CollectionDescriptor<PropertiesT> collection,
3333
CollectionHandleDefaults defaults) {
3434

35-
this.config = new WeaviateConfigClientAsync(collection, restTransport, grpcTransport);
35+
this.config = new WeaviateConfigClientAsync(collection, restTransport, grpcTransport, defaults);
3636
this.aggregate = new WeaviateAggregateClientAsync(collection, grpcTransport, defaults);
3737
this.query = new WeaviateQueryClientAsync<>(collection, grpcTransport, defaults);
3838
this.data = new WeaviateDataClientAsync<>(collection, restTransport, grpcTransport, defaults);
39-
this.tenants = new WeaviateTenantsClientAsync(collection, restTransport, grpcTransport);
40-
4139
this.defaults = defaults;
40+
41+
this.tenants = new WeaviateTenantsClientAsync(collection, restTransport, grpcTransport);
4242
}
4343

4444
/** Copy constructor that sets new defaults. */
4545
private CollectionHandleAsync(CollectionHandleAsync<PropertiesT> c, CollectionHandleDefaults defaults) {
46-
this.config = c.config;
4746
this.aggregate = c.aggregate;
4847
this.tenants = c.tenants;
48+
49+
this.config = new WeaviateConfigClientAsync(c.config, defaults);
4950
this.query = new WeaviateQueryClientAsync<>(c.query, defaults);
5051
this.data = new WeaviateDataClientAsync<>(c.data, defaults);
51-
5252
this.defaults = defaults;
5353
}
5454

src/main/java/io/weaviate/client6/v1/api/collections/config/GetShardsRequest.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@
22

33
import java.util.Collections;
44
import java.util.List;
5+
import java.util.Map;
56

67
import com.google.gson.reflect.TypeToken;
78

9+
import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults;
810
import io.weaviate.client6.v1.internal.json.JSON;
11+
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;
912
import io.weaviate.client6.v1.internal.rest.Endpoint;
1013
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;
1114

12-
public record GetShardsRequest(String collectionName) {
15+
public record GetShardsRequest() {
1316

1417
@SuppressWarnings("unchecked")
15-
public static final Endpoint<GetShardsRequest, List<Shard>> _ENDPOINT = SimpleEndpoint.noBody(
16-
request -> "GET",
17-
request -> "/schema/" + request.collectionName + "/shards", // TODO: tenant support
18-
request -> Collections.emptyMap(),
19-
(statusCode, response) -> (List<Shard>) JSON.deserialize(response, TypeToken.getParameterized(
20-
List.class, Shard.class)));
18+
public static final Endpoint<Void, List<Shard>> endpoint(
19+
CollectionDescriptor<?> collection,
20+
CollectionHandleDefaults defaults) {
21+
return SimpleEndpoint.noBody(
22+
request -> "GET",
23+
request -> "/schema/" + collection.name() + "/shards",
24+
request -> defaults.tenant() != null
25+
? Map.of("tenant", defaults.tenant())
26+
: Collections.emptyMap(),
27+
(statusCode, response) -> (List<Shard>) JSON.deserialize(response, TypeToken.getParameterized(
28+
List.class, Shard.class)));
29+
}
2130
}

src/main/java/io/weaviate/client6/v1/api/collections/config/WeaviateConfigClient.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.function.Function;
88

99
import io.weaviate.client6.v1.api.collections.CollectionConfig;
10+
import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults;
1011
import io.weaviate.client6.v1.api.collections.Property;
1112
import io.weaviate.client6.v1.api.collections.WeaviateCollectionsClient;
1213
import io.weaviate.client6.v1.internal.ObjectBuilder;
@@ -18,14 +19,27 @@ public class WeaviateConfigClient {
1819
private final RestTransport restTransport;
1920
private final WeaviateCollectionsClient collectionsClient;
2021

21-
protected final CollectionDescriptor<?> collection;
22+
private final CollectionDescriptor<?> collection;
23+
private final CollectionHandleDefaults defaults;
2224

23-
public WeaviateConfigClient(CollectionDescriptor<?> collection, RestTransport restTransport,
24-
GrpcTransport grpcTransport) {
25+
public WeaviateConfigClient(
26+
CollectionDescriptor<?> collection,
27+
RestTransport restTransport,
28+
GrpcTransport grpcTransport,
29+
CollectionHandleDefaults defaults) {
2530
this.restTransport = restTransport;
2631
this.collectionsClient = new WeaviateCollectionsClient(restTransport, grpcTransport);
2732

2833
this.collection = collection;
34+
this.defaults = defaults;
35+
}
36+
37+
/** Copy constructor that updates the {@link #defaults}. */
38+
public WeaviateConfigClient(WeaviateConfigClient c, CollectionHandleDefaults defaults) {
39+
this.restTransport = c.restTransport;
40+
this.collectionsClient = c.collectionsClient;
41+
this.collection = c.collection;
42+
this.defaults = defaults;
2943
}
3044

3145
public Optional<CollectionConfig> get() throws IOException {
@@ -49,7 +63,7 @@ public void update(String collectionName,
4963
}
5064

5165
public List<Shard> getShards() throws IOException {
52-
return this.restTransport.performRequest(new GetShardsRequest(collection.name()), GetShardsRequest._ENDPOINT);
66+
return this.restTransport.performRequest(null, GetShardsRequest.endpoint(collection, defaults));
5367
}
5468

5569
public List<Shard> updateShards(ShardStatus status, String... shards) throws IOException {

src/main/java/io/weaviate/client6/v1/api/collections/config/WeaviateConfigClientAsync.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.function.Function;
99

1010
import io.weaviate.client6.v1.api.collections.CollectionConfig;
11+
import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults;
1112
import io.weaviate.client6.v1.api.collections.Property;
1213
import io.weaviate.client6.v1.api.collections.WeaviateCollectionsClientAsync;
1314
import io.weaviate.client6.v1.internal.ObjectBuilder;
@@ -19,22 +20,35 @@ public class WeaviateConfigClientAsync {
1920
private final RestTransport restTransport;
2021
private final WeaviateCollectionsClientAsync collectionsClient;
2122

22-
protected final CollectionDescriptor<?> collectionDescriptor;
23+
private final CollectionDescriptor<?> collection;
24+
private final CollectionHandleDefaults defaults;
2325

24-
public WeaviateConfigClientAsync(CollectionDescriptor<?> collection, RestTransport restTransport,
25-
GrpcTransport grpcTransport) {
26+
public WeaviateConfigClientAsync(
27+
CollectionDescriptor<?> collection,
28+
RestTransport restTransport,
29+
GrpcTransport grpcTransport,
30+
CollectionHandleDefaults defaults) {
2631
this.restTransport = restTransport;
2732
this.collectionsClient = new WeaviateCollectionsClientAsync(restTransport, grpcTransport);
2833

29-
this.collectionDescriptor = collection;
34+
this.collection = collection;
35+
this.defaults = defaults;
36+
}
37+
38+
/** Copy constructor that updates the {@link #defaults}. */
39+
public WeaviateConfigClientAsync(WeaviateConfigClientAsync c, CollectionHandleDefaults defaults) {
40+
this.restTransport = c.restTransport;
41+
this.collectionsClient = c.collectionsClient;
42+
this.collection = c.collection;
43+
this.defaults = defaults;
3044
}
3145

3246
public CompletableFuture<Optional<CollectionConfig>> get() throws IOException {
33-
return collectionsClient.getConfig(collectionDescriptor.name());
47+
return collectionsClient.getConfig(collection.name());
3448
}
3549

3650
public CompletableFuture<Void> addProperty(Property property) throws IOException {
37-
return this.restTransport.performRequestAsync(new AddPropertyRequest(collectionDescriptor.name(), property),
51+
return this.restTransport.performRequestAsync(new AddPropertyRequest(collection.name(), property),
3852
AddPropertyRequest._ENDPOINT);
3953
}
4054

@@ -52,8 +66,7 @@ public CompletableFuture<Void> update(String collectionName,
5266
}
5367

5468
public CompletableFuture<List<Shard>> getShards() {
55-
return this.restTransport.performRequestAsync(new GetShardsRequest(collectionDescriptor.name()),
56-
GetShardsRequest._ENDPOINT);
69+
return this.restTransport.performRequestAsync(null, GetShardsRequest.endpoint(collection, defaults));
5770
}
5871

5972
public CompletableFuture<List<Shard>> updateShards(ShardStatus status, String... shards) throws IOException {
@@ -63,7 +76,7 @@ public CompletableFuture<List<Shard>> updateShards(ShardStatus status, String...
6376
public CompletableFuture<List<Shard>> updateShards(ShardStatus status, List<String> shards) throws IOException {
6477
var updates = shards.stream().map(
6578
shard -> this.restTransport.performRequestAsync(
66-
new UpdateShardStatusRequest(collectionDescriptor.name(), shard, status),
79+
new UpdateShardStatusRequest(collection.name(), shard, status),
6780
UpdateShardStatusRequest._ENDPOINT))
6881
.toArray(CompletableFuture[]::new);
6982
return CompletableFuture.allOf(updates).thenCompose(__ -> getShards());

src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public class WeaviateDataClient<PropertiesT> {
2525
private final CollectionHandleDefaults defaults;
2626

2727
public WeaviateDataClient(
28-
CollectionDescriptor<PropertiesT> collectionDescriptor,
28+
CollectionDescriptor<PropertiesT> collection,
2929
RestTransport restTransport,
3030
GrpcTransport grpcTransport,
3131
CollectionHandleDefaults defaults) {
3232
this.restTransport = restTransport;
3333
this.grpcTransport = grpcTransport;
34-
this.collection = collectionDescriptor;
35-
this.query = new WeaviateQueryClient<>(collectionDescriptor, grpcTransport, defaults);
34+
this.collection = collection;
35+
this.query = new WeaviateQueryClient<>(collection, grpcTransport, defaults);
3636
this.defaults = defaults;
3737
}
3838

0 commit comments

Comments
 (0)