From 88524c5dda09879659f66b42f8dc9282ddf54696 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Sat, 7 Dec 2024 16:57:02 +0100 Subject: [PATCH 1/8] feat(gh-327): set custom backup location (sync) --- .../client/v1/backup/api/BackupCanceler.java | 26 ++++++- .../backup/api/BackupCreateStatusGetter.java | 27 +++++++- .../client/v1/backup/api/BackupCreator.java | 4 ++ .../backup/api/BackupRestoreStatusGetter.java | 27 +++++++- .../client/v1/backup/api/BackupRestorer.java | 4 ++ .../integration/client/WeaviateVersion.java | 6 +- .../client/backup/ClientBackupTest.java | 38 ++++++++++- .../tests/backup/BackupTestSuite.java | 68 +++++++++++++++++++ 8 files changed, 193 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java index f8812bc8..b23a7d32 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java @@ -1,5 +1,9 @@ package io.weaviate.client.v1.backup.api; +import java.net.URISyntaxException; + +import org.apache.hc.core5.net.URIBuilder; + import io.weaviate.client.Config; import io.weaviate.client.base.BaseClient; import io.weaviate.client.base.ClientResult; @@ -16,6 +20,8 @@ public class BackupCanceler extends BaseClient implements ClientResult { private String backend; private String backupId; + private String bucket; + private String path; public BackupCanceler(HttpClient client, Config config) { super(client, config); @@ -26,6 +32,16 @@ public BackupCanceler withBackend(String backend) { return this; } + public BackupCanceler withBucket(String bucket) { + this.bucket = bucket; + return this; + } + + public BackupCanceler withPath(String path) { + this.path = path; + return this; + } + public BackupCanceler withBackupId(String backupId) { this.backupId = backupId; return this; @@ -38,7 +54,15 @@ public Result run() { } private String path() { - return String.format("/backups/%s/%s", backend, backupId); + String base = String.format("/backups/%s/%s", backend, backupId); + try { + return new URIBuilder(base) + .addParameter("bucket", bucket) + .addParameter("path", path) + .toString(); + } catch (URISyntaxException e) { + return base; + } } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java index dafb25c9..9cff83be 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java @@ -1,6 +1,11 @@ package io.weaviate.client.v1.backup.api; import io.weaviate.client.v1.backup.model.BackupCreateStatusResponse; + +import java.net.URISyntaxException; + +import org.apache.hc.core5.net.URIBuilder; + import io.weaviate.client.Config; import io.weaviate.client.base.BaseClient; import io.weaviate.client.base.ClientResult; @@ -12,6 +17,8 @@ public class BackupCreateStatusGetter extends BaseClient run() { return new Result<>(statusCreate()); @@ -37,6 +54,14 @@ Response statusCreate() { } private String path() { - return String.format("/backups/%s/%s", backend, backupId); + String base = String.format("/backups/%s/%s", backend, backupId); + try { + return new URIBuilder(base) + .addParameter("bucket", bucket) + .addParameter("path", path) + .toString(); + } catch (URISyntaxException e) { + return base; + } } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreator.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreator.java index f02c7edc..61fe9f4d 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreator.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreator.java @@ -150,6 +150,10 @@ public static class BackupCreateConfig { Integer chunkSize; @SerializedName("CompressionLevel") String compressionLevel; + @SerializedName("Bucket") + String bucket; + @SerializedName("Path") + String path; } public interface BackupCompression { diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java index 06ffa72a..9b7a9349 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java @@ -1,6 +1,11 @@ package io.weaviate.client.v1.backup.api; import io.weaviate.client.v1.backup.model.BackupRestoreStatusResponse; + +import java.net.URISyntaxException; + +import org.apache.hc.core5.net.URIBuilder; + import io.weaviate.client.Config; import io.weaviate.client.base.BaseClient; import io.weaviate.client.base.ClientResult; @@ -12,6 +17,8 @@ public class BackupRestoreStatusGetter extends BaseClient run() { return new Result<>(statusRestore()); @@ -37,6 +54,14 @@ Response statusRestore() { } private String path() { - return String.format("/backups/%s/%s/restore", backend, backupId); + String base = String.format("/backups/%s/%s/restore", backend, backupId); + try { + return new URIBuilder(base) + .addParameter("bucket", bucket) + .addParameter("path", path) + .toString(); + } catch (URISyntaxException e) { + return base; + } } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestorer.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestorer.java index 77c7ce3f..849ad458 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestorer.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestorer.java @@ -150,5 +150,9 @@ private static class BackupRestore { public static class BackupRestoreConfig { @SerializedName("CPUPercentage") Integer cpuPercentage; + @SerializedName("Bucket") + String bucket; + @SerializedName("Path") + String path; } } diff --git a/src/test/java/io/weaviate/integration/client/WeaviateVersion.java b/src/test/java/io/weaviate/integration/client/WeaviateVersion.java index 72946175..1eb10fdb 100644 --- a/src/test/java/io/weaviate/integration/client/WeaviateVersion.java +++ b/src/test/java/io/weaviate/integration/client/WeaviateVersion.java @@ -3,12 +3,12 @@ public class WeaviateVersion { // docker image version - public static final String WEAVIATE_IMAGE = "1.27.0"; + public static final String WEAVIATE_IMAGE = "stable-v1.28-ac93b01"; // to be set according to weaviate docker image - public static final String EXPECTED_WEAVIATE_VERSION = "1.27.0"; + public static final String EXPECTED_WEAVIATE_VERSION = "1.28.0"; // to be set according to weaviate docker image - public static final String EXPECTED_WEAVIATE_GIT_HASH = "6c571ff"; + public static final String EXPECTED_WEAVIATE_GIT_HASH = "ac93b01"; private WeaviateVersion() { } diff --git a/src/test/java/io/weaviate/integration/client/backup/ClientBackupTest.java b/src/test/java/io/weaviate/integration/client/backup/ClientBackupTest.java index 086591b1..afdb0be0 100644 --- a/src/test/java/io/weaviate/integration/client/backup/ClientBackupTest.java +++ b/src/test/java/io/weaviate/integration/client/backup/ClientBackupTest.java @@ -3,7 +3,6 @@ import io.weaviate.client.Config; import io.weaviate.client.WeaviateClient; import io.weaviate.client.base.Result; -import io.weaviate.client.v1.async.WeaviateAsyncClient; import io.weaviate.client.v1.backup.api.BackupCreator; import io.weaviate.client.v1.backup.api.BackupRestorer; import io.weaviate.client.v1.backup.model.BackupCreateResponse; @@ -118,6 +117,43 @@ public void shouldCreateAndRestoreBackupWithoutWaiting() throws InterruptedExcep supplierRestoreResult, supplierRestoreStatusResult, supplierDeleteClass, createSupplierGQLOfClass(), backupId); } + @Test + public void shouldCreateAndRestoreBackupWithDynamicLocation() throws InterruptedException { + String bucket = "test-bucket"; // irrelevant for "filesystem" backend, here only to illustrate + String path = "/custom/backup/location"; + + Supplier> supplierCreateResult = () -> client.backup().creator() + .withIncludeClassNames(BackupTestSuite.CLASS_NAME_PIZZA) + .withBackend(BackupTestSuite.BACKEND) + .withBackupId(backupId) + .withConfig(BackupCreator.BackupCreateConfig.builder().bucket(bucket).path(path).build()) + .run(); + Supplier> supplierCreateStatusResult = () -> client.backup().createStatusGetter() + .withBackend(BackupTestSuite.BACKEND) + .withBackupId(backupId) + .withBucket(bucket) + .withPath(path) + .run(); + Supplier> supplierDeleteClass = () -> client.schema().classDeleter() + .withClassName(BackupTestSuite.CLASS_NAME_PIZZA) + .run(); + Supplier> supplierRestoreResult = () -> client.backup().restorer() + .withIncludeClassNames(BackupTestSuite.CLASS_NAME_PIZZA) + .withBackend(BackupTestSuite.BACKEND) + .withBackupId(backupId) + .withConfig(BackupRestorer.BackupRestoreConfig.builder().bucket(bucket).path(path).build()) + .run(); + Supplier> supplierRestoreStatusResult = () -> client.backup().restoreStatusGetter() + .withBackend(BackupTestSuite.BACKEND) + .withBackupId(backupId) + .withBucket(bucket) + .withPath(path) + .run(); + + BackupTestSuite.testCreateWithDynamicLocation(supplierCreateResult, supplierCreateStatusResult, + supplierRestoreResult, supplierRestoreStatusResult, supplierDeleteClass, createSupplierGQLOfClass(), backupId, bucket, path); + } + @Test public void shouldCreateAndRestore1Of2Classes() { Supplier> supplierCreateResult = () -> client.backup().creator() diff --git a/src/test/java/io/weaviate/integration/tests/backup/BackupTestSuite.java b/src/test/java/io/weaviate/integration/tests/backup/BackupTestSuite.java index 752279fd..a8257f16 100644 --- a/src/test/java/io/weaviate/integration/tests/backup/BackupTestSuite.java +++ b/src/test/java/io/weaviate/integration/tests/backup/BackupTestSuite.java @@ -6,6 +6,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.CHAR_SEQUENCE; import static org.junit.Assume.assumeTrue; +import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; @@ -102,6 +103,73 @@ public static void testCreateAndRestoreBackupWithWaiting(Supplier> supplierCreate, + Supplier> supplierCreateStatus, + Supplier> supplierRestore, + Supplier> supplierRestoreStatus, + Supplier> supplierDeleteClass, + Function> supplierGQLOfClass, + String backupId, String bucket, String path) throws InterruptedException { + assertThatAllPizzasExist(supplierGQLOfClass); + String wantFullPath = Paths.get(path, backupId).toString(); + + Result createResult = supplierCreate.get(); + assertThat(createResult.getError()).as("create backup").isNull(); + assertThat(createResult.getResult()).isNotNull() + .returns(backupId, BackupCreateResponse::getId) + .returns(wantFullPath, BackupCreateResponse::getPath).as("path in BackupCreateResponse"); + + // Wait until created + Result createStatusResult; + while (true) { + createStatusResult = supplierCreateStatus.get(); + + assertThat(createStatusResult.getError()).as("check backup creation status").isNull(); + assertThat(createStatusResult.getResult()).isNotNull() + .returns(backupId, BackupCreateStatusResponse::getId) + .returns(wantFullPath, BackupCreateStatusResponse::getPath) + .extracting(BackupCreateStatusResponse::getStatus) + .isIn(CreateStatus.STARTED, CreateStatus.TRANSFERRING, CreateStatus.TRANSFERRED, CreateStatus.SUCCESS); + + if (CreateStatus.SUCCESS.equals(createStatusResult.getResult().getStatus())) { + break; + } + Thread.sleep(100); + } + + // Delete all data to then restore it from backup. + Result delete = supplierDeleteClass.get(); + assertThat(delete.getError()).as("drop Pizza collection").isNull(); + assertThat(delete.getResult()).isTrue(); + + + Result restoreResult = supplierRestore.get(); + assertThat(restoreResult.getError()).as("restore from backup").isNull(); + assertThat(restoreResult.getResult()).isNotNull() + .returns(backupId, BackupRestoreResponse::getId) + .returns(wantFullPath, BackupRestoreResponse::getPath); + + // Wait until restored + Result restoreStatusResult; + while (true) { + restoreStatusResult = supplierRestoreStatus.get(); + + assertThat(restoreStatusResult.getError()).as("get restore status").isNull(); + assertThat(restoreStatusResult.getResult()).isNotNull() + .returns(backupId, BackupRestoreStatusResponse::getId) + .returns(wantFullPath, BackupRestoreStatusResponse::getPath) + .extracting(BackupRestoreStatusResponse::getStatus) + .isIn(RestoreStatus.STARTED, RestoreStatus.TRANSFERRING, RestoreStatus.TRANSFERRED, RestoreStatus.SUCCESS); + + if (RestoreStatus.SUCCESS.equals(restoreStatusResult.getResult().getStatus())) { + break; + } + Thread.sleep(100); + } + + assertThatAllPizzasExist(supplierGQLOfClass); + } + public static void testCreateAndRestoreBackupWithoutWaiting(Supplier> supplierCreate, Supplier> supplierCreateStatus, Supplier> supplierRestore, From ed3a0f7182ed91f385e1066883fefc564ff15b51 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Sat, 7 Dec 2024 17:08:31 +0100 Subject: [PATCH 2/8] feat(gh-327): set custom backup location (async) --- .../v1/async/backup/api/BackupCanceler.java | 22 +++++++++- .../backup/api/BackupCreateStatusGetter.java | 31 +++++++++++--- .../v1/async/backup/api/BackupCreator.java | 4 ++ .../backup/api/BackupRestoreStatusGetter.java | 21 +++++++++- .../v1/async/backup/api/BackupRestorer.java | 4 ++ .../backup/api/BackupCreateStatusGetter.java | 3 +- .../backup/api/BackupRestoreStatusGetter.java | 3 +- .../client/async/backup/ClientBackupTest.java | 41 +++++++++++++++++++ 8 files changed, 118 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java index dde418ab..a0cf7615 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java @@ -8,7 +8,9 @@ import io.weaviate.client.v1.auth.provider.AccessTokenProvider; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.core5.concurrent.FutureCallback; +import org.apache.hc.core5.net.URIBuilder; +import java.net.URISyntaxException; import java.util.concurrent.Future; /** @@ -22,13 +24,14 @@ public class BackupCanceler extends AsyncBaseClient private String backend; private String backupId; + private String bucket; + private String path; public BackupCanceler(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) { super(client, config, tokenProvider); } - public BackupCanceler withBackend(String backend) { this.backend = backend; return this; @@ -39,10 +42,27 @@ public BackupCanceler withBackupId(String backupId) { return this; } + public BackupCanceler withBucket(String bucket) { + this.bucket = bucket; + return this; + } + + public BackupCanceler withPath(String path) { + this.path = path; + return this; + } + @Override public Future> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); + try { + path = new URIBuilder(path) + .addParameter("bucket", bucket) + .addParameter("path", this.path) + .toString(); + } catch (URISyntaxException e) { + } return sendDeleteRequest(path, null, Void.class, callback); } } diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java index cbad847f..6d8cf61b 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java @@ -1,5 +1,12 @@ package io.weaviate.client.v1.async.backup.api; +import java.net.URISyntaxException; +import java.util.concurrent.Future; + +import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; +import org.apache.hc.core5.concurrent.FutureCallback; +import org.apache.hc.core5.net.URIBuilder; + import io.weaviate.client.Config; import io.weaviate.client.base.AsyncBaseClient; import io.weaviate.client.base.AsyncClientResult; @@ -7,17 +14,14 @@ import io.weaviate.client.base.util.UrlEncoder; import io.weaviate.client.v1.auth.provider.AccessTokenProvider; import io.weaviate.client.v1.backup.model.BackupCreateStatusResponse; -import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; -import org.apache.hc.core5.concurrent.FutureCallback; - -import java.util.concurrent.Future; public class BackupCreateStatusGetter extends AsyncBaseClient implements AsyncClientResult { private String backend; private String backupId; - + private String bucket; + private String path; public BackupCreateStatusGetter(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) { super(client, config, tokenProvider); @@ -34,9 +38,26 @@ public BackupCreateStatusGetter withBackupId(String backupId) { return this; } + public BackupCreateStatusGetter withBucket(String bucket) { + this.bucket = bucket; + return this; + } + + public BackupCreateStatusGetter withPath(String path) { + this.path = path; + return this; + } + @Override public Future> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); + try { + path = new URIBuilder(path) + .addParameter("bucket", bucket) + .addParameter("path", this.path) + .toString(); + } catch (URISyntaxException e) { + } return sendGetRequest(path, BackupCreateStatusResponse.class, callback); } } diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreator.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreator.java index 84487916..b09072f7 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreator.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreator.java @@ -242,6 +242,10 @@ public static class BackupCreateConfig { Integer chunkSize; @SerializedName("CompressionLevel") String compressionLevel; + @SerializedName("Bucket") + String bucket; + @SerializedName("Path") + String path; } public interface BackupCompression { diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java index 4ef10ce2..ab13b577 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java @@ -9,7 +9,9 @@ import io.weaviate.client.v1.backup.model.BackupRestoreStatusResponse; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.core5.concurrent.FutureCallback; +import org.apache.hc.core5.net.URIBuilder; +import java.net.URISyntaxException; import java.util.concurrent.Future; public class BackupRestoreStatusGetter extends AsyncBaseClient @@ -17,7 +19,8 @@ public class BackupRestoreStatusGetter extends AsyncBaseClient> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s/restore", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); + try { + path = new URIBuilder(path) + .addParameter("bucket", bucket) + .addParameter("path", this.path) + .toString(); + } catch (URISyntaxException e) { + } return sendGetRequest(path, BackupRestoreStatusResponse.class, callback); } } diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestorer.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestorer.java index f4015786..5882b3d7 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestorer.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestorer.java @@ -237,5 +237,9 @@ private static class BackupRestore { public static class BackupRestoreConfig { @SerializedName("CPUPercentage") Integer cpuPercentage; + @SerializedName("Bucket") + String bucket; + @SerializedName("Path") + String path; } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java index 9cff83be..b24e8a16 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java @@ -1,7 +1,5 @@ package io.weaviate.client.v1.backup.api; -import io.weaviate.client.v1.backup.model.BackupCreateStatusResponse; - import java.net.URISyntaxException; import org.apache.hc.core5.net.URIBuilder; @@ -12,6 +10,7 @@ import io.weaviate.client.base.Response; import io.weaviate.client.base.Result; import io.weaviate.client.base.http.HttpClient; +import io.weaviate.client.v1.backup.model.BackupCreateStatusResponse; public class BackupCreateStatusGetter extends BaseClient implements ClientResult { diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java index 9b7a9349..52b7e8cd 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java @@ -1,7 +1,5 @@ package io.weaviate.client.v1.backup.api; -import io.weaviate.client.v1.backup.model.BackupRestoreStatusResponse; - import java.net.URISyntaxException; import org.apache.hc.core5.net.URIBuilder; @@ -12,6 +10,7 @@ import io.weaviate.client.base.Response; import io.weaviate.client.base.Result; import io.weaviate.client.base.http.HttpClient; +import io.weaviate.client.v1.backup.model.BackupRestoreStatusResponse; public class BackupRestoreStatusGetter extends BaseClient implements ClientResult { diff --git a/src/test/java/io/weaviate/integration/client/async/backup/ClientBackupTest.java b/src/test/java/io/weaviate/integration/client/async/backup/ClientBackupTest.java index 38b69828..a03baecf 100644 --- a/src/test/java/io/weaviate/integration/client/async/backup/ClientBackupTest.java +++ b/src/test/java/io/weaviate/integration/client/async/backup/ClientBackupTest.java @@ -133,6 +133,47 @@ public void shouldCreateAndRestoreBackupWithoutWaiting() throws InterruptedExcep } } + @Test + public void shouldCreateAndRestoreBackupWithDynamicLocation() throws InterruptedException { + String bucket = "test-bucket"; // irrelevant for "filesystem" backend, here only to illustrate + String path = "/custom/backup/location"; + + try (WeaviateAsyncClient asyncClient = client.async()) { + Supplier> supplierCreateResult = createSupplierCreate( + asyncClient, creator -> creator + .withIncludeClassNames(BackupTestSuite.CLASS_NAME_PIZZA) + .withBackend(BackupTestSuite.BACKEND) + .withBackupId(backupId) + .withConfig(BackupCreator.BackupCreateConfig.builder().bucket(bucket).path(path).build()) + ); + Supplier> supplierCreateStatusResult = createSupplierCreateStatus( + asyncClient, createStatusGetter -> createStatusGetter + .withBackend(BackupTestSuite.BACKEND) + .withBackupId(backupId) + .withBucket(bucket) + .withPath(path) + ); + Supplier> supplierRestoreResult = createSupplierRestore( + asyncClient, restorer -> restorer + .withIncludeClassNames(BackupTestSuite.CLASS_NAME_PIZZA) + .withBackend(BackupTestSuite.BACKEND) + .withBackupId(backupId) + .withConfig(BackupRestorer.BackupRestoreConfig.builder().bucket(bucket).path(path).build()) + ); + Supplier> supplierRestoreStatusResult = createSupplierRestoreStatus( + asyncClient, restoreStatusGetter -> restoreStatusGetter + .withBackend(BackupTestSuite.BACKEND) + .withBackupId(backupId) + .withBucket(bucket) + .withPath(path) + ); + + BackupTestSuite.testCreateWithDynamicLocation(supplierCreateResult, supplierCreateStatusResult, + supplierRestoreResult, supplierRestoreStatusResult, + createSupplierDeletePizza(), createSupplierGQLOfClass(), backupId, bucket, path); + } + } + @Test public void shouldCreateAndRestore1Of2Classes() { try (WeaviateAsyncClient asyncClient = client.async()) { From a4b43eeaf2468f8e435bd39333d9f088f07b6981 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Sat, 7 Dec 2024 17:36:49 +0100 Subject: [PATCH 3/8] test: update expected Weaviate version --- .../java/io/weaviate/integration/client/WeaviateVersion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/weaviate/integration/client/WeaviateVersion.java b/src/test/java/io/weaviate/integration/client/WeaviateVersion.java index 1eb10fdb..102389d6 100644 --- a/src/test/java/io/weaviate/integration/client/WeaviateVersion.java +++ b/src/test/java/io/weaviate/integration/client/WeaviateVersion.java @@ -6,7 +6,7 @@ public class WeaviateVersion { public static final String WEAVIATE_IMAGE = "stable-v1.28-ac93b01"; // to be set according to weaviate docker image - public static final String EXPECTED_WEAVIATE_VERSION = "1.28.0"; + public static final String EXPECTED_WEAVIATE_VERSION = "1.28.0-rc.0"; // to be set according to weaviate docker image public static final String EXPECTED_WEAVIATE_GIT_HASH = "ac93b01"; From ad6cb545ec1fa5c490ddd28ca078bf921390a679 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Mon, 9 Dec 2024 17:31:28 +0100 Subject: [PATCH 4/8] ci: target Weaviate v1.27.7 --- .../io/weaviate/integration/client/WeaviateVersion.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/weaviate/integration/client/WeaviateVersion.java b/src/test/java/io/weaviate/integration/client/WeaviateVersion.java index 102389d6..a74e1942 100644 --- a/src/test/java/io/weaviate/integration/client/WeaviateVersion.java +++ b/src/test/java/io/weaviate/integration/client/WeaviateVersion.java @@ -3,12 +3,12 @@ public class WeaviateVersion { // docker image version - public static final String WEAVIATE_IMAGE = "stable-v1.28-ac93b01"; + public static final String WEAVIATE_IMAGE = "stable-v1.27.7"; // to be set according to weaviate docker image - public static final String EXPECTED_WEAVIATE_VERSION = "1.28.0-rc.0"; + public static final String EXPECTED_WEAVIATE_VERSION = "1.27.7"; // to be set according to weaviate docker image - public static final String EXPECTED_WEAVIATE_GIT_HASH = "ac93b01"; + public static final String EXPECTED_WEAVIATE_GIT_HASH = "a6d7f16"; private WeaviateVersion() { } From 024a85f9a677b291559be572753b20216f1da2ef Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Mon, 9 Dec 2024 17:49:31 +0100 Subject: [PATCH 5/8] ci: fix target version tag Use preview version from https://github.com/weaviate/weaviate/actions/runs/12175355466 --- .../java/io/weaviate/integration/client/WeaviateVersion.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/weaviate/integration/client/WeaviateVersion.java b/src/test/java/io/weaviate/integration/client/WeaviateVersion.java index a74e1942..dc37e52f 100644 --- a/src/test/java/io/weaviate/integration/client/WeaviateVersion.java +++ b/src/test/java/io/weaviate/integration/client/WeaviateVersion.java @@ -3,12 +3,12 @@ public class WeaviateVersion { // docker image version - public static final String WEAVIATE_IMAGE = "stable-v1.27.7"; + public static final String WEAVIATE_IMAGE = "1.27.7-8f0e033"; // to be set according to weaviate docker image public static final String EXPECTED_WEAVIATE_VERSION = "1.27.7"; // to be set according to weaviate docker image - public static final String EXPECTED_WEAVIATE_GIT_HASH = "a6d7f16"; + public static final String EXPECTED_WEAVIATE_GIT_HASH = "8f0e033"; private WeaviateVersion() { } From f2bc91658f8efc06f930360a117e791395ea7682 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 10 Dec 2024 16:40:21 +0100 Subject: [PATCH 6/8] refactor: use UrlEncoder to add query params --- .../v1/async/backup/api/BackupCanceler.java | 29 +++++++++++-------- .../backup/api/BackupCreateStatusGetter.java | 20 ++++++++----- .../backup/api/BackupRestoreStatusGetter.java | 29 +++++++++++-------- .../client/v1/backup/api/BackupCanceler.java | 24 ++++++++------- .../backup/api/BackupCreateStatusGetter.java | 24 ++++++++------- .../backup/api/BackupRestoreStatusGetter.java | 24 ++++++++------- 6 files changed, 88 insertions(+), 62 deletions(-) diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java index a0cf7615..3a1c8ce8 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java @@ -1,17 +1,19 @@ package io.weaviate.client.v1.async.backup.api; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.Future; + +import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; +import org.apache.hc.core5.concurrent.FutureCallback; + import io.weaviate.client.Config; import io.weaviate.client.base.AsyncBaseClient; import io.weaviate.client.base.AsyncClientResult; import io.weaviate.client.base.Result; import io.weaviate.client.base.util.UrlEncoder; import io.weaviate.client.v1.auth.provider.AccessTokenProvider; -import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; -import org.apache.hc.core5.concurrent.FutureCallback; -import org.apache.hc.core5.net.URIBuilder; - -import java.net.URISyntaxException; -import java.util.concurrent.Future; /** * BackupCanceler can cancel an in-progress backup by ID. @@ -56,13 +58,16 @@ public BackupCanceler withPath(String path) { @Override public Future> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); - try { - path = new URIBuilder(path) - .addParameter("bucket", bucket) - .addParameter("path", this.path) - .toString(); - } catch (URISyntaxException e) { + + List queryParams = Arrays.asList( + UrlEncoder.encodeQueryParam("bucket", this.bucket), + UrlEncoder.encodeQueryParam("path", this.path) + ); + queryParams.removeIf(Objects::isNull); + if (!queryParams.isEmpty()) { + path = path + "?" + String.join("&", queryParams); } + return sendDeleteRequest(path, null, Void.class, callback); } } diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java index 6d8cf61b..127aec9f 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java @@ -1,11 +1,12 @@ package io.weaviate.client.v1.async.backup.api; -import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; import java.util.concurrent.Future; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.core5.concurrent.FutureCallback; -import org.apache.hc.core5.net.URIBuilder; import io.weaviate.client.Config; import io.weaviate.client.base.AsyncBaseClient; @@ -51,13 +52,16 @@ public BackupCreateStatusGetter withPath(String path) { @Override public Future> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); - try { - path = new URIBuilder(path) - .addParameter("bucket", bucket) - .addParameter("path", this.path) - .toString(); - } catch (URISyntaxException e) { + + List queryParams = Arrays.asList( + UrlEncoder.encodeQueryParam("bucket", this.bucket), + UrlEncoder.encodeQueryParam("path", this.path) + ); + queryParams.removeIf(Objects::isNull); + if (!queryParams.isEmpty()) { + path = path + "?" + String.join("&", queryParams); } + return sendGetRequest(path, BackupCreateStatusResponse.class, callback); } } diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java index ab13b577..95d24c3a 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java @@ -1,5 +1,13 @@ package io.weaviate.client.v1.async.backup.api; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.Future; + +import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; +import org.apache.hc.core5.concurrent.FutureCallback; + import io.weaviate.client.Config; import io.weaviate.client.base.AsyncBaseClient; import io.weaviate.client.base.AsyncClientResult; @@ -7,12 +15,6 @@ import io.weaviate.client.base.util.UrlEncoder; import io.weaviate.client.v1.auth.provider.AccessTokenProvider; import io.weaviate.client.v1.backup.model.BackupRestoreStatusResponse; -import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; -import org.apache.hc.core5.concurrent.FutureCallback; -import org.apache.hc.core5.net.URIBuilder; - -import java.net.URISyntaxException; -import java.util.concurrent.Future; public class BackupRestoreStatusGetter extends AsyncBaseClient implements AsyncClientResult { @@ -50,13 +52,16 @@ public BackupRestoreStatusGetter withPath(String path) { @Override public Future> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s/restore", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); - try { - path = new URIBuilder(path) - .addParameter("bucket", bucket) - .addParameter("path", this.path) - .toString(); - } catch (URISyntaxException e) { + + List queryParams = Arrays.asList( + UrlEncoder.encodeQueryParam("bucket", this.bucket), + UrlEncoder.encodeQueryParam("path", this.path) + ); + queryParams.removeIf(Objects::isNull); + if (!queryParams.isEmpty()) { + path = path + "?" + String.join("&", queryParams); } + return sendGetRequest(path, BackupRestoreStatusResponse.class, callback); } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java index b23a7d32..3f1e9874 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java @@ -1,8 +1,8 @@ package io.weaviate.client.v1.backup.api; -import java.net.URISyntaxException; - -import org.apache.hc.core5.net.URIBuilder; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; import io.weaviate.client.Config; import io.weaviate.client.base.BaseClient; @@ -10,6 +10,7 @@ import io.weaviate.client.base.Response; import io.weaviate.client.base.Result; import io.weaviate.client.base.http.HttpClient; +import io.weaviate.client.base.util.UrlEncoder; /** * BackupCanceler can cancel an in-progress backup by ID. @@ -55,14 +56,17 @@ public Result run() { private String path() { String base = String.format("/backups/%s/%s", backend, backupId); - try { - return new URIBuilder(base) - .addParameter("bucket", bucket) - .addParameter("path", path) - .toString(); - } catch (URISyntaxException e) { - return base; + + List queryParams = Arrays.asList( + UrlEncoder.encodeQueryParam("bucket", this.bucket), + UrlEncoder.encodeQueryParam("path", this.path) + ); + queryParams.removeIf(Objects::isNull); + if (!queryParams.isEmpty()) { + base = base + "?" + String.join("&", queryParams); } + + return base; } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java index b24e8a16..41297be1 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java @@ -1,8 +1,8 @@ package io.weaviate.client.v1.backup.api; -import java.net.URISyntaxException; - -import org.apache.hc.core5.net.URIBuilder; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; import io.weaviate.client.Config; import io.weaviate.client.base.BaseClient; @@ -10,6 +10,7 @@ import io.weaviate.client.base.Response; import io.weaviate.client.base.Result; import io.weaviate.client.base.http.HttpClient; +import io.weaviate.client.base.util.UrlEncoder; import io.weaviate.client.v1.backup.model.BackupCreateStatusResponse; public class BackupCreateStatusGetter extends BaseClient implements ClientResult { @@ -54,13 +55,16 @@ Response statusCreate() { private String path() { String base = String.format("/backups/%s/%s", backend, backupId); - try { - return new URIBuilder(base) - .addParameter("bucket", bucket) - .addParameter("path", path) - .toString(); - } catch (URISyntaxException e) { - return base; + + List queryParams = Arrays.asList( + UrlEncoder.encodeQueryParam("bucket", this.bucket), + UrlEncoder.encodeQueryParam("path", this.path) + ); + queryParams.removeIf(Objects::isNull); + if (!queryParams.isEmpty()) { + base = base + "?" + String.join("&", queryParams); } + + return base; } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java index 52b7e8cd..82091124 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java @@ -1,8 +1,8 @@ package io.weaviate.client.v1.backup.api; -import java.net.URISyntaxException; - -import org.apache.hc.core5.net.URIBuilder; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; import io.weaviate.client.Config; import io.weaviate.client.base.BaseClient; @@ -10,6 +10,7 @@ import io.weaviate.client.base.Response; import io.weaviate.client.base.Result; import io.weaviate.client.base.http.HttpClient; +import io.weaviate.client.base.util.UrlEncoder; import io.weaviate.client.v1.backup.model.BackupRestoreStatusResponse; public class BackupRestoreStatusGetter extends BaseClient implements ClientResult { @@ -54,13 +55,16 @@ Response statusRestore() { private String path() { String base = String.format("/backups/%s/%s/restore", backend, backupId); - try { - return new URIBuilder(base) - .addParameter("bucket", bucket) - .addParameter("path", path) - .toString(); - } catch (URISyntaxException e) { - return base; + + List queryParams = Arrays.asList( + UrlEncoder.encodeQueryParam("bucket", this.bucket), + UrlEncoder.encodeQueryParam("path", this.path) + ); + queryParams.removeIf(Objects::isNull); + if (!queryParams.isEmpty()) { + base = base + "?" + String.join("&", queryParams); } + + return base; } } From f292312d65859bd0a7f45f27af08db3a4ebbba95 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 10 Dec 2024 17:19:00 +0100 Subject: [PATCH 7/8] fix: do not encode null params --- .../v1/async/backup/api/BackupCanceler.java | 23 ++++++++-------- .../backup/api/BackupCreateStatusGetter.java | 23 ++++++++-------- .../backup/api/BackupRestoreStatusGetter.java | 23 ++++++++-------- .../client/v1/backup/api/BackupCanceler.java | 27 ++++++++++--------- .../backup/api/BackupCreateStatusGetter.java | 27 ++++++++++--------- .../backup/api/BackupRestoreStatusGetter.java | 27 ++++++++++--------- 6 files changed, 78 insertions(+), 72 deletions(-) diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java index 3a1c8ce8..3e9abada 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java @@ -1,8 +1,7 @@ package io.weaviate.client.v1.async.backup.api; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.concurrent.Future; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; @@ -27,7 +26,7 @@ public class BackupCanceler extends AsyncBaseClient private String backend; private String backupId; private String bucket; - private String path; + private String backupPath; public BackupCanceler(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) { @@ -50,7 +49,7 @@ public BackupCanceler withBucket(String bucket) { } public BackupCanceler withPath(String path) { - this.path = path; + this.backupPath = path; return this; } @@ -59,15 +58,17 @@ public BackupCanceler withPath(String path) { public Future> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); - List queryParams = Arrays.asList( - UrlEncoder.encodeQueryParam("bucket", this.bucket), - UrlEncoder.encodeQueryParam("path", this.path) - ); - queryParams.removeIf(Objects::isNull); - if (!queryParams.isEmpty()) { - path = path + "?" + String.join("&", queryParams); + List queryParams = new ArrayList<>(); + if (this.bucket != null){ + queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); + } + if (this.backupPath != null){ + queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } + if (!queryParams.isEmpty()) { + path += "?" + String.join("&", queryParams); + } return sendDeleteRequest(path, null, Void.class, callback); } } diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java index 127aec9f..fbe6e1fa 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java @@ -1,8 +1,7 @@ package io.weaviate.client.v1.async.backup.api; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.concurrent.Future; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; @@ -22,7 +21,7 @@ public class BackupCreateStatusGetter extends AsyncBaseClient> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); - List queryParams = Arrays.asList( - UrlEncoder.encodeQueryParam("bucket", this.bucket), - UrlEncoder.encodeQueryParam("path", this.path) - ); - queryParams.removeIf(Objects::isNull); - if (!queryParams.isEmpty()) { - path = path + "?" + String.join("&", queryParams); + List queryParams = new ArrayList<>(); + if (this.bucket != null){ + queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); + } + if (this.backupPath != null){ + queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } + if (!queryParams.isEmpty()) { + path += "?" + String.join("&", queryParams); + } return sendGetRequest(path, BackupCreateStatusResponse.class, callback); } } diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java index 95d24c3a..de269915 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java @@ -1,8 +1,7 @@ package io.weaviate.client.v1.async.backup.api; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.concurrent.Future; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; @@ -22,7 +21,7 @@ public class BackupRestoreStatusGetter extends AsyncBaseClient> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s/restore", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); - List queryParams = Arrays.asList( - UrlEncoder.encodeQueryParam("bucket", this.bucket), - UrlEncoder.encodeQueryParam("path", this.path) - ); - queryParams.removeIf(Objects::isNull); - if (!queryParams.isEmpty()) { - path = path + "?" + String.join("&", queryParams); + List queryParams = new ArrayList<>(); + if (this.bucket != null){ + queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); + } + if (this.backupPath != null){ + queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } + if (!queryParams.isEmpty()) { + path += "?" + String.join("&", queryParams); + } return sendGetRequest(path, BackupRestoreStatusResponse.class, callback); } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java index 3f1e9874..362c6fe0 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java @@ -1,8 +1,7 @@ package io.weaviate.client.v1.backup.api; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import java.util.Objects; import io.weaviate.client.Config; import io.weaviate.client.base.BaseClient; @@ -22,7 +21,7 @@ public class BackupCanceler extends BaseClient implements ClientResult run() { } private String path() { - String base = String.format("/backups/%s/%s", backend, backupId); + String path = String.format("/backups/%s/%s", backend, backupId); - List queryParams = Arrays.asList( - UrlEncoder.encodeQueryParam("bucket", this.bucket), - UrlEncoder.encodeQueryParam("path", this.path) - ); - queryParams.removeIf(Objects::isNull); - if (!queryParams.isEmpty()) { - base = base + "?" + String.join("&", queryParams); + List queryParams = new ArrayList<>(); + if (this.bucket != null){ + queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); + } + if (this.backupPath != null){ + queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } - return base; + if (!queryParams.isEmpty()) { + path += "?" + String.join("&", queryParams); + } + return path; } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java index 41297be1..03af6b4e 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java @@ -1,8 +1,7 @@ package io.weaviate.client.v1.backup.api; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import java.util.Objects; import io.weaviate.client.Config; import io.weaviate.client.base.BaseClient; @@ -18,7 +17,7 @@ public class BackupCreateStatusGetter extends BaseClient statusCreate() { } private String path() { - String base = String.format("/backups/%s/%s", backend, backupId); + String path = String.format("/backups/%s/%s", backend, backupId); - List queryParams = Arrays.asList( - UrlEncoder.encodeQueryParam("bucket", this.bucket), - UrlEncoder.encodeQueryParam("path", this.path) - ); - queryParams.removeIf(Objects::isNull); - if (!queryParams.isEmpty()) { - base = base + "?" + String.join("&", queryParams); + List queryParams = new ArrayList<>(); + if (this.bucket != null){ + queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); + } + if (this.backupPath != null){ + queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } - return base; + if (!queryParams.isEmpty()) { + path += "?" + String.join("&", queryParams); + } + return path; } } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java index 82091124..bc211a6f 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java @@ -1,8 +1,7 @@ package io.weaviate.client.v1.backup.api; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import java.util.Objects; import io.weaviate.client.Config; import io.weaviate.client.base.BaseClient; @@ -18,7 +17,7 @@ public class BackupRestoreStatusGetter extends BaseClient statusRestore() { } private String path() { - String base = String.format("/backups/%s/%s/restore", backend, backupId); + String path = String.format("/backups/%s/%s/restore", backend, backupId); - List queryParams = Arrays.asList( - UrlEncoder.encodeQueryParam("bucket", this.bucket), - UrlEncoder.encodeQueryParam("path", this.path) - ); - queryParams.removeIf(Objects::isNull); - if (!queryParams.isEmpty()) { - base = base + "?" + String.join("&", queryParams); + List queryParams = new ArrayList<>(); + if (this.bucket != null){ + queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); + } + if (this.backupPath != null){ + queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } - return base; + if (!queryParams.isEmpty()) { + path += "?" + String.join("&", queryParams); + } + return path; } } From a8c1ad6e3ade8d1595842a6defdbb4a8cf68e430 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 10 Dec 2024 17:33:26 +0100 Subject: [PATCH 8/8] chore: format new code --- .../weaviate/client/v1/async/backup/api/BackupCanceler.java | 4 ++-- .../client/v1/async/backup/api/BackupCreateStatusGetter.java | 4 ++-- .../client/v1/async/backup/api/BackupRestoreStatusGetter.java | 4 ++-- .../java/io/weaviate/client/v1/backup/api/BackupCanceler.java | 4 ++-- .../client/v1/backup/api/BackupCreateStatusGetter.java | 4 ++-- .../client/v1/backup/api/BackupRestoreStatusGetter.java | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java index 3e9abada..1d2fb931 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCanceler.java @@ -59,10 +59,10 @@ public Future> run(FutureCallback> callback) { String path = String.format("/backups/%s/%s", UrlEncoder.encodePathParam(backend), UrlEncoder.encodePathParam(backupId)); List queryParams = new ArrayList<>(); - if (this.bucket != null){ + if (this.bucket != null) { queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); } - if (this.backupPath != null){ + if (this.backupPath != null) { queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java index fbe6e1fa..32c65572 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupCreateStatusGetter.java @@ -53,10 +53,10 @@ public Future> run(FutureCallback queryParams = new ArrayList<>(); - if (this.bucket != null){ + if (this.bucket != null) { queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); } - if (this.backupPath != null){ + if (this.backupPath != null) { queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } diff --git a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java index de269915..e1331cb0 100644 --- a/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/async/backup/api/BackupRestoreStatusGetter.java @@ -53,10 +53,10 @@ public Future> run(FutureCallback queryParams = new ArrayList<>(); - if (this.bucket != null){ + if (this.bucket != null) { queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); } - if (this.backupPath != null){ + if (this.backupPath != null) { queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java index 362c6fe0..15d8890a 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java @@ -57,10 +57,10 @@ private String path() { String path = String.format("/backups/%s/%s", backend, backupId); List queryParams = new ArrayList<>(); - if (this.bucket != null){ + if (this.bucket != null) { queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); } - if (this.backupPath != null){ + if (this.backupPath != null) { queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java index 03af6b4e..b8d59dd8 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupCreateStatusGetter.java @@ -56,10 +56,10 @@ private String path() { String path = String.format("/backups/%s/%s", backend, backupId); List queryParams = new ArrayList<>(); - if (this.bucket != null){ + if (this.bucket != null) { queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); } - if (this.backupPath != null){ + if (this.backupPath != null) { queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); } diff --git a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java index bc211a6f..3807d4a4 100644 --- a/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java +++ b/src/main/java/io/weaviate/client/v1/backup/api/BackupRestoreStatusGetter.java @@ -56,10 +56,10 @@ private String path() { String path = String.format("/backups/%s/%s/restore", backend, backupId); List queryParams = new ArrayList<>(); - if (this.bucket != null){ + if (this.bucket != null) { queryParams.add(UrlEncoder.encodeQueryParam("bucket", this.bucket)); } - if (this.backupPath != null){ + if (this.backupPath != null) { queryParams.add(UrlEncoder.encodeQueryParam("path", this.backupPath)); }