Skip to content

Commit eca4583

Browse files
authored
Support dynamic backup location (#341)
* feat(gh-327): set custom backup location (sync) * feat(gh-327): set custom backup location (async) * test: update expected Weaviate version * ci: target Weaviate v1.27.7 * ci: fix target version tag Use preview version from https://github.com/weaviate/weaviate/actions/runs/12175355466 * refactor: use UrlEncoder to add query params * fix: do not encode null params * chore: format new code
1 parent 99593e9 commit eca4583

File tree

14 files changed

+349
-24
lines changed

14 files changed

+349
-24
lines changed

src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package io.weaviate.client.v1.async.backup.api;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.concurrent.Future;
6+
7+
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
8+
import org.apache.hc.core5.concurrent.FutureCallback;
9+
310
import io.weaviate.client.Config;
411
import io.weaviate.client.base.AsyncBaseClient;
512
import io.weaviate.client.base.AsyncClientResult;
613
import io.weaviate.client.base.Result;
714
import io.weaviate.client.base.util.UrlEncoder;
815
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
9-
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
10-
import org.apache.hc.core5.concurrent.FutureCallback;
11-
12-
import java.util.concurrent.Future;
1316

1417
/**
1518
* BackupCanceler can cancel an in-progress backup by ID.
@@ -22,13 +25,14 @@ public class BackupCanceler extends AsyncBaseClient<Void>
2225

2326
private String backend;
2427
private String backupId;
28+
private String bucket;
29+
private String backupPath;
2530

2631

2732
public BackupCanceler(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) {
2833
super(client, config, tokenProvider);
2934
}
3035

31-
3236
public BackupCanceler withBackend(String backend) {
3337
this.backend = backend;
3438
return this;
@@ -39,10 +43,32 @@ public BackupCanceler withBackupId(String backupId) {
3943
return this;
4044
}
4145

46+
public BackupCanceler withBucket(String bucket) {
47+
this.bucket = bucket;
48+
return this;
49+
}
50+
51+
public BackupCanceler withPath(String path) {
52+
this.backupPath = path;
53+
return this;
54+
}
55+
4256

4357
@Override
4458
public Future<Result<Void>> run(FutureCallback<Result<Void>> callback) {
4559
String path = String.format("/backups/%s/%s", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId));
60+
61+
List<String> queryParams = new ArrayList<>();
62+
if (this.bucket != null) {
63+
queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket));
64+
}
65+
if (this.backupPath != null) {
66+
queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath));
67+
}
68+
69+
if (!queryParams.isEmpty()) {
70+
path += "?" + String.join("&", queryParams);
71+
}
4672
return sendDeleteRequest(path, null, Void.class, callback);
4773
}
4874
}

src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package io.weaviate.client.v1.async.backup.api;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.concurrent.Future;
6+
7+
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
8+
import org.apache.hc.core5.concurrent.FutureCallback;
9+
310
import io.weaviate.client.Config;
411
import io.weaviate.client.base.AsyncBaseClient;
512
import io.weaviate.client.base.AsyncClientResult;
613
import io.weaviate.client.base.Result;
714
import io.weaviate.client.base.util.UrlEncoder;
815
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
916
import io.weaviate.client.v1.backup.model.BackupCreateStatusResponse;
10-
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
11-
import org.apache.hc.core5.concurrent.FutureCallback;
12-
13-
import java.util.concurrent.Future;
1417

1518
public class BackupCreateStatusGetter extends AsyncBaseClient<BackupCreateStatusResponse>
1619
implements AsyncClientResult<BackupCreateStatusResponse> {
1720

1821
private String backend;
1922
private String backupId;
20-
23+
private String bucket;
24+
private String backupPath;
2125

2226
public BackupCreateStatusGetter(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) {
2327
super(client, config, tokenProvider);
@@ -34,9 +38,31 @@ public BackupCreateStatusGetter withBackupId(String backupId) {
3438
return this;
3539
}
3640

41+
public BackupCreateStatusGetter withBucket(String bucket) {
42+
this.bucket = bucket;
43+
return this;
44+
}
45+
46+
public BackupCreateStatusGetter withPath(String path) {
47+
this.backupPath = path;
48+
return this;
49+
}
50+
3751
@Override
3852
public Future<Result<BackupCreateStatusResponse>> run(FutureCallback<Result<BackupCreateStatusResponse>> callback) {
3953
String path = String.format("/backups/%s/%s", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId));
54+
55+
List<String> queryParams = new ArrayList<>();
56+
if (this.bucket != null) {
57+
queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket));
58+
}
59+
if (this.backupPath != null) {
60+
queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath));
61+
}
62+
63+
if (!queryParams.isEmpty()) {
64+
path += "?" + String.join("&", queryParams);
65+
}
4066
return sendGetRequest(path, BackupCreateStatusResponse.class, callback);
4167
}
4268
}

src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ public static class BackupCreateConfig {
242242
Integer chunkSize;
243243
@SerializedName("CompressionLevel")
244244
String compressionLevel;
245+
@SerializedName("Bucket")
246+
String bucket;
247+
@SerializedName("Path")
248+
String path;
245249
}
246250

247251
public interface BackupCompression {

src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package io.weaviate.client.v1.async.backup.api;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.concurrent.Future;
6+
7+
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
8+
import org.apache.hc.core5.concurrent.FutureCallback;
9+
310
import io.weaviate.client.Config;
411
import io.weaviate.client.base.AsyncBaseClient;
512
import io.weaviate.client.base.AsyncClientResult;
613
import io.weaviate.client.base.Result;
714
import io.weaviate.client.base.util.UrlEncoder;
815
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
916
import io.weaviate.client.v1.backup.model.BackupRestoreStatusResponse;
10-
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
11-
import org.apache.hc.core5.concurrent.FutureCallback;
12-
13-
import java.util.concurrent.Future;
1417

1518
public class BackupRestoreStatusGetter extends AsyncBaseClient<BackupRestoreStatusResponse>
1619
implements AsyncClientResult<BackupRestoreStatusResponse> {
1720

1821
private String backend;
1922
private String backupId;
20-
23+
private String bucket;
24+
private String backupPath;
2125

2226
public BackupRestoreStatusGetter(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) {
2327
super(client, config, tokenProvider);
@@ -34,10 +38,31 @@ public BackupRestoreStatusGetter withBackupId(String backupId) {
3438
return this;
3539
}
3640

41+
public BackupRestoreStatusGetter withBucket(String bucket) {
42+
this.bucket = bucket;
43+
return this;
44+
}
45+
46+
public BackupRestoreStatusGetter withPath(String path) {
47+
this.backupPath = path;
48+
return this;
49+
}
3750

3851
@Override
3952
public Future<Result<BackupRestoreStatusResponse>> run(FutureCallback<Result<BackupRestoreStatusResponse>> callback) {
4053
String path = String.format("/backups/%s/%s/restore", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId));
54+
55+
List<String> queryParams = new ArrayList<>();
56+
if (this.bucket != null) {
57+
queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket));
58+
}
59+
if (this.backupPath != null) {
60+
queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath));
61+
}
62+
63+
if (!queryParams.isEmpty()) {
64+
path += "?" + String.join("&", queryParams);
65+
}
4166
return sendGetRequest(path, BackupRestoreStatusResponse.class, callback);
4267
}
4368
}

src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestorer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,9 @@ private static class BackupRestore {
237237
public static class BackupRestoreConfig {
238238
@SerializedName("CPUPercentage")
239239
Integer cpuPercentage;
240+
@SerializedName("Bucket")
241+
String bucket;
242+
@SerializedName("Path")
243+
String path;
240244
}
241245
}

src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package io.weaviate.client.v1.backup.api;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
import io.weaviate.client.Config;
47
import io.weaviate.client.base.BaseClient;
58
import io.weaviate.client.base.ClientResult;
69
import io.weaviate.client.base.Response;
710
import io.weaviate.client.base.Result;
811
import io.weaviate.client.base.http.HttpClient;
12+
import io.weaviate.client.base.util.UrlEncoder;
913

1014
/**
1115
* BackupCanceler can cancel an in-progress backup by ID.
@@ -16,6 +20,8 @@
1620
public class BackupCanceler extends BaseClient<Void> implements ClientResult<Void> {
1721
private String backend;
1822
private String backupId;
23+
private String bucket;
24+
private String backupPath;
1925

2026
public BackupCanceler(HttpClient client, Config config) {
2127
super(client, config);
@@ -26,6 +32,16 @@ public BackupCanceler withBackend(String backend) {
2632
return this;
2733
}
2834

35+
public BackupCanceler withBucket(String bucket) {
36+
this.bucket = bucket;
37+
return this;
38+
}
39+
40+
public BackupCanceler withPath(String path) {
41+
this.backupPath = path;
42+
return this;
43+
}
44+
2945
public BackupCanceler withBackupId(String backupId) {
3046
this.backupId = backupId;
3147
return this;
@@ -38,7 +54,20 @@ public Result<Void> run() {
3854
}
3955

4056
private String path() {
41-
return String.format("/backups/%s/%s", backend, backupId);
57+
String path = String.format("/backups/%s/%s", backend, backupId);
58+
59+
List<String> queryParams = new ArrayList<>();
60+
if (this.bucket != null) {
61+
queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket));
62+
}
63+
if (this.backupPath != null) {
64+
queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath));
65+
}
66+
67+
if (!queryParams.isEmpty()) {
68+
path += "?" + String.join("&", queryParams);
69+
}
70+
return path;
4271
}
4372
}
4473

src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
package io.weaviate.client.v1.backup.api;
22

3-
import io.weaviate.client.v1.backup.model.BackupCreateStatusResponse;
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
46
import io.weaviate.client.Config;
57
import io.weaviate.client.base.BaseClient;
68
import io.weaviate.client.base.ClientResult;
79
import io.weaviate.client.base.Response;
810
import io.weaviate.client.base.Result;
911
import io.weaviate.client.base.http.HttpClient;
12+
import io.weaviate.client.base.util.UrlEncoder;
13+
import io.weaviate.client.v1.backup.model.BackupCreateStatusResponse;
1014

1115
public class BackupCreateStatusGetter extends BaseClient<BackupCreateStatusResponse> implements ClientResult<BackupCreateStatusResponse> {
1216

1317
private String backend;
1418
private String backupId;
19+
private String bucket;
20+
private String backupPath;
1521

1622
public BackupCreateStatusGetter(HttpClient httpClient, Config config) {
1723
super(httpClient, config);
@@ -27,6 +33,16 @@ public BackupCreateStatusGetter withBackupId(String backupId) {
2733
return this;
2834
}
2935

36+
public BackupCreateStatusGetter withBucket(String bucket) {
37+
this.bucket = bucket;
38+
return this;
39+
}
40+
41+
public BackupCreateStatusGetter withPath(String path) {
42+
this.backupPath = path;
43+
return this;
44+
}
45+
3046
@Override
3147
public Result<BackupCreateStatusResponse> run() {
3248
return new Result<>(statusCreate());
@@ -37,6 +53,19 @@ Response<BackupCreateStatusResponse> statusCreate() {
3753
}
3854

3955
private String path() {
40-
return String.format("/backups/%s/%s", backend, backupId);
56+
String path = String.format("/backups/%s/%s", backend, backupId);
57+
58+
List<String> queryParams = new ArrayList<>();
59+
if (this.bucket != null) {
60+
queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket));
61+
}
62+
if (this.backupPath != null) {
63+
queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath));
64+
}
65+
66+
if (!queryParams.isEmpty()) {
67+
path += "?" + String.join("&", queryParams);
68+
}
69+
return path;
4170
}
4271
}

src/main/java/io/weaviate/client/v1/backup/api/BackupCreator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ public static class BackupCreateConfig {
150150
Integer chunkSize;
151151
@SerializedName("CompressionLevel")
152152
String compressionLevel;
153+
@SerializedName("Bucket")
154+
String bucket;
155+
@SerializedName("Path")
156+
String path;
153157
}
154158

155159
public interface BackupCompression {

0 commit comments

Comments
 (0)