Skip to content

Commit 9de7434

Browse files
authored
Merge pull request #218 from weaviate/multi_tenancy_support_p3
Multi tenancy support (part 3)
2 parents 86a67d4 + 8da48c1 commit 9de7434

File tree

51 files changed

+3178
-1557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3178
-1557
lines changed

src/main/java/io/weaviate/client/v1/batch/api/ObjectsBatchDeleter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ObjectsBatchDeleter extends BaseClient<BatchDeleteResponse> impleme
1818
private final ObjectsPath objectsPath;
1919
private String className;
2020
private String consistencyLevel;
21-
private String tenantKey;
21+
private String tenant;
2222
private WhereFilter where;
2323
private String output;
2424
private Boolean dryRun;
@@ -40,8 +40,8 @@ public ObjectsBatchDeleter withConsistencyLevel(String consistencyLevel) {
4040
return this;
4141
}
4242

43-
public ObjectsBatchDeleter withTenantKey(String tenantKey) {
44-
this.tenantKey = tenantKey;
43+
public ObjectsBatchDeleter withTenant(String tenant) {
44+
this.tenant = tenant;
4545
return this;
4646
}
4747

@@ -74,7 +74,7 @@ public Result<BatchDeleteResponse> run() {
7474
.build();
7575
String path = objectsPath.buildDelete(ObjectsPath.Params.builder()
7676
.consistencyLevel(consistencyLevel)
77-
.tenantKey(tenantKey)
77+
.tenant(tenant)
7878
.build());
7979
Response<BatchDeleteResponse> resp = sendDeleteRequest(path, batchDelete, BatchDeleteResponse.class);
8080
return new Result<>(resp);

src/main/java/io/weaviate/client/v1/batch/api/ObjectsBatcher.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public class ObjectsBatcher extends BaseClient<ObjectGetResponse[]>
5858
private final DelayedExecutor<?> delayedExecutor;
5959
private final List<WeaviateObject> objects;
6060
private String consistencyLevel;
61-
private String tenantKey;
6261
private final List<CompletableFuture<Result<ObjectGetResponse[]>>> undoneFutures;
6362

6463

@@ -115,11 +114,6 @@ public ObjectsBatcher withConsistencyLevel(String consistencyLevel) {
115114
return this;
116115
}
117116

118-
public ObjectsBatcher withTenantKey(String tenantKey) {
119-
this.tenantKey = tenantKey;
120-
return this;
121-
}
122-
123117
@Override
124118
public Result<ObjectGetResponse[]> run() {
125119
if (autoRunEnabled) {
@@ -273,7 +267,6 @@ private Result<ObjectGetResponse[]> internalRun(List<WeaviateObject> batch) {
273267
.build();
274268
String path = objectsPath.buildCreate(ObjectsPath.Params.builder()
275269
.consistencyLevel(consistencyLevel)
276-
.tenantKey(tenantKey)
277270
.build());
278271
Response<ObjectGetResponse[]> resp = sendPostRequest(path, batchRequest, ObjectGetResponse[].class);
279272
return new Result<>(resp);

src/main/java/io/weaviate/client/v1/batch/api/ReferencePayloadBuilder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class ReferencePayloadBuilder {
1414
private String fromPropertyName;
1515
private String toUUID;
1616
private String toClassName;
17+
private String tenant;
1718

1819
@Deprecated
1920
public ReferencePayloadBuilder() {
@@ -50,6 +51,11 @@ public ReferencePayloadBuilder withToClassName(String className) {
5051
return this;
5152
}
5253

54+
public ReferencePayloadBuilder withTenant(String tenant) {
55+
this.tenant = tenant;
56+
return this;
57+
}
58+
5359
public BatchReference payload() {
5460
if (StringUtils.isBlank(fromClassName) || StringUtils.isBlank(fromUUID) ||
5561
StringUtils.isBlank(fromPropertyName) || StringUtils.isBlank(toUUID)) {
@@ -73,7 +79,7 @@ public BatchReference payload() {
7379
to = beaconToDeprecated();
7480
}
7581

76-
return BatchReference.builder().from(from).to(to).build();
82+
return BatchReference.builder().from(from).to(to).tenant(tenant).build();
7783
}
7884

7985
private String beaconFromDeprecated() {

src/main/java/io/weaviate/client/v1/batch/api/ReferencesBatcher.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class ReferencesBatcher extends BaseClient<BatchReferenceResponse[]>
4949
private final DelayedExecutor<?> delayedExecutor;
5050
private final List<BatchReference> references;
5151
private String consistencyLevel;
52-
private String tenantKey;
5352
private final List<CompletableFuture<Result<BatchReferenceResponse[]>>> undoneFutures;
5453

5554

@@ -104,11 +103,6 @@ public ReferencesBatcher withConsistencyLevel(String consistencyLevel) {
104103
return this;
105104
}
106105

107-
public ReferencesBatcher withTenantKey(String tenantKey) {
108-
this.tenantKey = tenantKey;
109-
return this;
110-
}
111-
112106
@Override
113107
public Result<BatchReferenceResponse[]> run() {
114108
if (autoRunEnabled) {
@@ -247,7 +241,6 @@ private Result<BatchReferenceResponse[]> internalRun(List<BatchReference> batch)
247241
BatchReference[] payload = batch.toArray(new BatchReference[0]);
248242
String path = referencesPath.buildCreate(ReferencesPath.Params.builder()
249243
.consistencyLevel(consistencyLevel)
250-
.tenantKey(tenantKey)
251244
.build());
252245
Response<BatchReferenceResponse[]> resp = sendPostRequest(path, payload, BatchReferenceResponse[].class);
253246
return new Result<>(resp);

src/main/java/io/weaviate/client/v1/batch/model/BatchReference.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
public class BatchReference {
1616
String from;
1717
String to;
18+
String tenant;
1819
}

src/main/java/io/weaviate/client/v1/batch/model/BatchReferenceResponseAO1Result.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,31 @@
77
import lombok.ToString;
88
import lombok.experimental.FieldDefaults;
99

10+
import java.util.List;
11+
1012
@Getter
1113
@Setter
1214
@ToString
1315
@EqualsAndHashCode
1416
@FieldDefaults(level = AccessLevel.PRIVATE)
1517
public class BatchReferenceResponseAO1Result {
16-
String errors;
18+
ErrorResponse errors;
1719
String status;
20+
21+
22+
@Getter
23+
@ToString
24+
@EqualsAndHashCode
25+
@FieldDefaults(level = AccessLevel.PRIVATE)
26+
public static class ErrorResponse {
27+
List<ErrorItem> error;
28+
}
29+
30+
@Getter
31+
@ToString
32+
@EqualsAndHashCode
33+
@FieldDefaults(level = AccessLevel.PRIVATE)
34+
public static class ErrorItem {
35+
String message;
36+
}
1837
}

src/main/java/io/weaviate/client/v1/batch/model/ObjectGetResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class ObjectGetResponse {
2626
Map<String, Object> additional;
2727
Float[] vector;
2828
Object vectorWeights;
29+
String tenant;
2930

3031
Deprecation[] deprecations;
3132
ObjectsGetResponseAO2Result result;

src/main/java/io/weaviate/client/v1/batch/util/ObjectsPath.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
public class ObjectsPath {
1717

1818
public String buildCreate(Params params) {
19-
return commonBuild(params);
19+
return build(
20+
params,
21+
this::addQueryConsistencyLevel
22+
);
2023
}
2124

2225
public String buildDelete(Params params) {
23-
return commonBuild(params);
24-
}
25-
26-
private String commonBuild(Params params) {
2726
return build(
2827
params,
2928
this::addQueryConsistencyLevel,
30-
this::addQueryTenantKey
29+
this::addQueryTenant
3130
);
3231
}
3332

@@ -55,9 +54,9 @@ private void addQueryConsistencyLevel(Params params, List<String> pathParams, Li
5554
}
5655
}
5756

58-
private void addQueryTenantKey(Params params, List<String> pathParams, List<String> queryParams) {
59-
if (StringUtils.isNotBlank(params.tenantKey)) {
60-
queryParams.add(UrlEncoder.encodeQueryParam("tenant_key", params.tenantKey));
57+
private void addQueryTenant(Params params, List<String> pathParams, List<String> queryParams) {
58+
if (StringUtils.isNotBlank(params.tenant)) {
59+
queryParams.add(UrlEncoder.encodeQueryParam("tenant", params.tenant));
6160
}
6261
}
6362

@@ -68,6 +67,6 @@ private void addQueryTenantKey(Params params, List<String> pathParams, List<Stri
6867
public static class Params {
6968

7069
String consistencyLevel;
71-
String tenantKey;
70+
String tenant;
7271
}
7372
}

src/main/java/io/weaviate/client/v1/batch/util/ReferencesPath.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public class ReferencesPath {
1818
public String buildCreate(Params params) {
1919
return build(
2020
params,
21-
this::addQueryConsistencyLevel,
22-
this::addQueryTenantKey
21+
this::addQueryConsistencyLevel
2322
);
2423
}
2524

@@ -47,19 +46,12 @@ private void addQueryConsistencyLevel(Params params, List<String> pathParams, Li
4746
}
4847
}
4948

50-
private void addQueryTenantKey(Params params, List<String> pathParams, List<String> queryParams) {
51-
if (StringUtils.isNotBlank(params.tenantKey)) {
52-
queryParams.add(UrlEncoder.encodeQueryParam("tenant_key", params.tenantKey));
53-
}
54-
}
55-
5649

5750
@Builder
5851
@ToString
5952
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
6053
public static class Params {
6154

6255
String consistencyLevel;
63-
String tenantKey;
6456
}
6557
}

src/main/java/io/weaviate/client/v1/cluster/api/NodesStatusGetter.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,34 @@
66
import io.weaviate.client.base.Response;
77
import io.weaviate.client.base.Result;
88
import io.weaviate.client.base.http.HttpClient;
9+
import io.weaviate.client.base.util.UrlEncoder;
910
import io.weaviate.client.v1.cluster.model.NodesStatusResponse;
11+
import org.apache.commons.lang3.StringUtils;
1012

1113
public class NodesStatusGetter extends BaseClient<NodesStatusResponse> implements ClientResult<NodesStatusResponse> {
1214

15+
private String className;
16+
1317
public NodesStatusGetter(HttpClient httpClient, Config config) {
1418
super(httpClient, config);
1519
}
1620

21+
public NodesStatusGetter withClassName(String className) {
22+
this.className = className;
23+
return this;
24+
}
25+
1726
@Override
1827
public Result<NodesStatusResponse> run() {
19-
Response<NodesStatusResponse> resp = sendGetRequest("/nodes", NodesStatusResponse.class);
28+
Response<NodesStatusResponse> resp = sendGetRequest(path(), NodesStatusResponse.class);
2029
return new Result<>(resp);
2130
}
31+
32+
private String path() {
33+
String path = "/nodes";
34+
if (StringUtils.isNotBlank(className)) {
35+
path = String.format("%s/%s", path, UrlEncoder.encodePathParam(className));
36+
}
37+
return path;
38+
}
2239
}

0 commit comments

Comments
 (0)