Skip to content

Commit 79d620f

Browse files
authored
Merge pull request #213 from weaviate/multi_tenancy_support
Multi tenancy support
2 parents c86116c + a6b6a72 commit 79d620f

File tree

95 files changed

+2249
-249
lines changed

Some content is hidden

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

95 files changed

+2249
-249
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.weaviate.client.base.util;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
5+
import java.io.UnsupportedEncodingException;
6+
import java.net.URLEncoder;
7+
import java.nio.charset.StandardCharsets;
8+
9+
public class UrlEncoder {
10+
11+
private UrlEncoder() {}
12+
13+
public static String encodeQueryParam(String key, String value) {
14+
return String.format("%s=%s", key, encode(StringUtils.trim(value)));
15+
}
16+
17+
public static String encodePathParam(String value) {
18+
return encode(StringUtils.trim(value));
19+
}
20+
21+
public static String encode(String value) {
22+
try {
23+
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
24+
} catch (UnsupportedEncodingException e) {
25+
return value;
26+
}
27+
}
28+
}

src/main/java/io/weaviate/client/v1/backup/model/BackupCreateResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.annotations.SerializedName;
44
import lombok.AccessLevel;
5+
import lombok.EqualsAndHashCode;
56
import lombok.Getter;
67
import lombok.Setter;
78
import lombok.ToString;
@@ -10,6 +11,7 @@
1011
@Getter
1112
@Setter
1213
@ToString
14+
@EqualsAndHashCode
1315
@FieldDefaults(level = AccessLevel.PRIVATE)
1416
public class BackupCreateResponse {
1517

src/main/java/io/weaviate/client/v1/backup/model/BackupCreateStatusResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.weaviate.client.v1.backup.model;
22

33
import lombok.AccessLevel;
4+
import lombok.EqualsAndHashCode;
45
import lombok.Getter;
56
import lombok.Setter;
67
import lombok.ToString;
@@ -9,6 +10,7 @@
910
@Getter
1011
@Setter
1112
@ToString
13+
@EqualsAndHashCode
1214
@FieldDefaults(level = AccessLevel.PRIVATE)
1315
public class BackupCreateStatusResponse {
1416

src/main/java/io/weaviate/client/v1/backup/model/BackupRestoreResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.annotations.SerializedName;
44
import lombok.AccessLevel;
5+
import lombok.EqualsAndHashCode;
56
import lombok.Getter;
67
import lombok.Setter;
78
import lombok.ToString;
@@ -10,6 +11,7 @@
1011
@Getter
1112
@Setter
1213
@ToString
14+
@EqualsAndHashCode
1315
@FieldDefaults(level = AccessLevel.PRIVATE)
1416
public class BackupRestoreResponse {
1517

src/main/java/io/weaviate/client/v1/backup/model/BackupRestoreStatusResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.weaviate.client.v1.backup.model;
22

33
import lombok.AccessLevel;
4+
import lombok.EqualsAndHashCode;
45
import lombok.Getter;
56
import lombok.Setter;
67
import lombok.ToString;
@@ -9,6 +10,7 @@
910
@Getter
1011
@Setter
1112
@ToString
13+
@EqualsAndHashCode
1214
@FieldDefaults(level = AccessLevel.PRIVATE)
1315
public class BackupRestoreStatusResponse {
1416

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

Lines changed: 84 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -15,81 +15,88 @@
1515

1616
public class ObjectsBatchDeleter extends BaseClient<BatchDeleteResponse> implements ClientResult<BatchDeleteResponse> {
1717

18-
private final ObjectsPath objectsPath;
19-
private String className;
20-
private String consistencyLevel;
21-
private WhereFilter where;
22-
private String output;
23-
private Boolean dryRun;
24-
25-
26-
public ObjectsBatchDeleter(HttpClient httpClient, Config config, ObjectsPath objectsPath) {
27-
super(httpClient, config);
28-
this.objectsPath = objectsPath;
29-
}
30-
31-
32-
public ObjectsBatchDeleter withClassName(String className) {
33-
this.className = className;
34-
return this;
35-
}
36-
37-
public ObjectsBatchDeleter withConsistencyLevel(String consistencyLevel) {
38-
this.consistencyLevel = consistencyLevel;
39-
return this;
40-
}
41-
42-
public ObjectsBatchDeleter withWhere(WhereFilter where) {
43-
this.where = where;
44-
return this;
45-
}
46-
47-
public ObjectsBatchDeleter withOutput(String output) {
48-
this.output = output;
49-
return this;
50-
}
51-
52-
public ObjectsBatchDeleter withDryRun(Boolean dryRun) {
53-
this.dryRun = dryRun;
54-
return this;
55-
}
56-
57-
58-
@Override
59-
public Result<BatchDeleteResponse> run() {
60-
BatchDeleteMatch match = BatchDeleteMatch.builder()
61-
.className(className)
62-
.whereFilter(where)
63-
.build();
64-
BatchDelete batchDelete = BatchDelete.builder()
65-
.dryRun(dryRun)
66-
.output(output)
67-
.match(match)
68-
.build();
69-
String path = objectsPath.buildDelete(ObjectsPath.Params.builder()
70-
.consistencyLevel(consistencyLevel)
71-
.build());
72-
Response<BatchDeleteResponse> resp = sendDeleteRequest(path, batchDelete, BatchDeleteResponse.class);
73-
return new Result<>(resp);
74-
}
75-
76-
77-
@Getter
78-
@Builder
79-
private static class BatchDelete {
80-
81-
BatchDeleteMatch match;
82-
String output;
83-
Boolean dryRun;
84-
}
85-
86-
@Getter
87-
@Builder
88-
private static class BatchDeleteMatch {
89-
90-
@SerializedName("class")
91-
String className;
92-
@SerializedName("where")
93-
WhereFilter whereFilter;
94-
}
18+
private final ObjectsPath objectsPath;
19+
private String className;
20+
private String consistencyLevel;
21+
private String tenantKey;
22+
private WhereFilter where;
23+
private String output;
24+
private Boolean dryRun;
25+
26+
27+
public ObjectsBatchDeleter(HttpClient httpClient, Config config, ObjectsPath objectsPath) {
28+
super(httpClient, config);
29+
this.objectsPath = objectsPath;
30+
}
31+
32+
33+
public ObjectsBatchDeleter withClassName(String className) {
34+
this.className = className;
35+
return this;
36+
}
37+
38+
public ObjectsBatchDeleter withConsistencyLevel(String consistencyLevel) {
39+
this.consistencyLevel = consistencyLevel;
40+
return this;
41+
}
42+
43+
public ObjectsBatchDeleter withTenantKey(String tenantKey) {
44+
this.tenantKey = tenantKey;
45+
return this;
46+
}
47+
48+
public ObjectsBatchDeleter withWhere(WhereFilter where) {
49+
this.where = where;
50+
return this;
51+
}
52+
53+
public ObjectsBatchDeleter withOutput(String output) {
54+
this.output = output;
55+
return this;
56+
}
57+
58+
public ObjectsBatchDeleter withDryRun(Boolean dryRun) {
59+
this.dryRun = dryRun;
60+
return this;
61+
}
62+
63+
64+
@Override
65+
public Result<BatchDeleteResponse> run() {
66+
BatchDeleteMatch match = BatchDeleteMatch.builder()
67+
.className(className)
68+
.whereFilter(where)
69+
.build();
70+
BatchDelete batchDelete = BatchDelete.builder()
71+
.dryRun(dryRun)
72+
.output(output)
73+
.match(match)
74+
.build();
75+
String path = objectsPath.buildDelete(ObjectsPath.Params.builder()
76+
.consistencyLevel(consistencyLevel)
77+
.tenantKey(tenantKey)
78+
.build());
79+
Response<BatchDeleteResponse> resp = sendDeleteRequest(path, batchDelete, BatchDeleteResponse.class);
80+
return new Result<>(resp);
81+
}
82+
83+
84+
@Getter
85+
@Builder
86+
private static class BatchDelete {
87+
88+
BatchDeleteMatch match;
89+
String output;
90+
Boolean dryRun;
91+
}
92+
93+
@Getter
94+
@Builder
95+
private static class BatchDeleteMatch {
96+
97+
@SerializedName("class")
98+
String className;
99+
@SerializedName("where")
100+
WhereFilter whereFilter;
101+
}
95102
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import io.weaviate.client.v1.batch.util.ObjectsPath;
66
import lombok.AccessLevel;
77
import lombok.Builder;
8+
import lombok.EqualsAndHashCode;
89
import lombok.Getter;
910
import lombok.RequiredArgsConstructor;
11+
import lombok.ToString;
1012
import lombok.experimental.FieldDefaults;
1113
import org.apache.commons.lang3.ArrayUtils;
1214
import org.apache.commons.lang3.ObjectUtils;
@@ -56,6 +58,7 @@ public class ObjectsBatcher extends BaseClient<ObjectGetResponse[]>
5658
private final DelayedExecutor<?> delayedExecutor;
5759
private final List<WeaviateObject> objects;
5860
private String consistencyLevel;
61+
private String tenantKey;
5962
private final List<CompletableFuture<Result<ObjectGetResponse[]>>> undoneFutures;
6063

6164

@@ -112,6 +115,11 @@ public ObjectsBatcher withConsistencyLevel(String consistencyLevel) {
112115
return this;
113116
}
114117

118+
public ObjectsBatcher withTenantKey(String tenantKey) {
119+
this.tenantKey = tenantKey;
120+
return this;
121+
}
122+
115123
@Override
116124
public Result<ObjectGetResponse[]> run() {
117125
if (autoRunEnabled) {
@@ -265,6 +273,7 @@ private Result<ObjectGetResponse[]> internalRun(List<WeaviateObject> batch) {
265273
.build();
266274
String path = objectsPath.buildCreate(ObjectsPath.Params.builder()
267275
.consistencyLevel(consistencyLevel)
276+
.tenantKey(tenantKey)
268277
.build());
269278
Response<ObjectGetResponse[]> resp = sendPostRequest(path, batchRequest, ObjectGetResponse[].class);
270279
return new Result<>(resp);
@@ -440,6 +449,8 @@ public Result<ObjectGetResponse[]> now(Result<ObjectGetResponse[]> result) {
440449

441450
@Getter
442451
@Builder
452+
@ToString
453+
@EqualsAndHashCode
443454
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
444455
public static class BatchRetriesConfig {
445456

@@ -471,6 +482,8 @@ public static BatchRetriesConfigBuilder defaultConfig() {
471482

472483
@Getter
473484
@Builder
485+
@ToString
486+
@EqualsAndHashCode
474487
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
475488
public static class AutoBatchConfig {
476489

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import io.weaviate.client.v1.batch.util.ReferencesPath;
66
import lombok.AccessLevel;
77
import lombok.Builder;
8+
import lombok.EqualsAndHashCode;
89
import lombok.Getter;
910
import lombok.RequiredArgsConstructor;
11+
import lombok.ToString;
1012
import lombok.experimental.FieldDefaults;
1113
import org.apache.commons.lang3.ObjectUtils;
1214
import io.weaviate.client.Config;
@@ -47,6 +49,7 @@ public class ReferencesBatcher extends BaseClient<BatchReferenceResponse[]>
4749
private final DelayedExecutor<?> delayedExecutor;
4850
private final List<BatchReference> references;
4951
private String consistencyLevel;
52+
private String tenantKey;
5053
private final List<CompletableFuture<Result<BatchReferenceResponse[]>>> undoneFutures;
5154

5255

@@ -101,6 +104,11 @@ public ReferencesBatcher withConsistencyLevel(String consistencyLevel) {
101104
return this;
102105
}
103106

107+
public ReferencesBatcher withTenantKey(String tenantKey) {
108+
this.tenantKey = tenantKey;
109+
return this;
110+
}
111+
104112
@Override
105113
public Result<BatchReferenceResponse[]> run() {
106114
if (autoRunEnabled) {
@@ -239,6 +247,7 @@ private Result<BatchReferenceResponse[]> internalRun(List<BatchReference> batch)
239247
BatchReference[] payload = batch.toArray(new BatchReference[0]);
240248
String path = referencesPath.buildCreate(ReferencesPath.Params.builder()
241249
.consistencyLevel(consistencyLevel)
250+
.tenantKey(tenantKey)
242251
.build());
243252
Response<BatchReferenceResponse[]> resp = sendPostRequest(path, payload, BatchReferenceResponse[].class);
244253
return new Result<>(resp);
@@ -320,6 +329,8 @@ public Result<BatchReferenceResponse[]> now(Result<BatchReferenceResponse[]> res
320329

321330
@Getter
322331
@Builder
332+
@ToString
333+
@EqualsAndHashCode
323334
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
324335
public static class BatchRetriesConfig {
325336

@@ -351,6 +362,8 @@ public static BatchRetriesConfigBuilder defaultConfig() {
351362

352363
@Getter
353364
@Builder
365+
@ToString
366+
@EqualsAndHashCode
354367
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
355368
public static class AutoBatchConfig {
356369

0 commit comments

Comments
 (0)