Skip to content

Commit

Permalink
feat(gh-327): set custom backup location (async)
Browse files Browse the repository at this point in the history
  • Loading branch information
bevzzz committed Dec 7, 2024
1 parent 88524c5 commit ed3a0f7
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -22,13 +24,14 @@ public class BackupCanceler extends AsyncBaseClient<Void>

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;
Expand All @@ -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<Result<Void>> run(FutureCallback<Result<Void>> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
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;
import io.weaviate.client.base.Result;
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<BackupCreateStatusResponse>
implements AsyncClientResult<BackupCreateStatusResponse> {

private String backend;
private String backupId;

private String bucket;
private String path;

public BackupCreateStatusGetter(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) {
super(client, config, tokenProvider);
Expand All @@ -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<Result<BackupCreateStatusResponse>> run(FutureCallback<Result<BackupCreateStatusResponse>> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
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<BackupRestoreStatusResponse>
implements AsyncClientResult<BackupRestoreStatusResponse> {

private String backend;
private String backupId;

private String bucket;
private String path;

public BackupRestoreStatusGetter(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) {
super(client, config, tokenProvider);
Expand All @@ -34,10 +37,26 @@ public BackupRestoreStatusGetter withBackupId(String backupId) {
return this;
}

public BackupRestoreStatusGetter withBucket(String bucket) {
this.bucket = bucket;
return this;
}

public BackupRestoreStatusGetter withPath(String path) {
this.path = path;
return this;
}

@Override
public Future<Result<BackupRestoreStatusResponse>> run(FutureCallback<Result<BackupRestoreStatusResponse>> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,9 @@ private static class BackupRestore {
public static class BackupRestoreConfig {
@SerializedName("CPUPercentage")
Integer cpuPercentage;
@SerializedName("Bucket")
String bucket;
@SerializedName("Path")
String path;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<BackupCreateStatusResponse> implements ClientResult<BackupCreateStatusResponse> {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<BackupRestoreStatusResponse> implements ClientResult<BackupRestoreStatusResponse> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<BackupCreateResponse>> 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<Result<BackupCreateStatusResponse>> supplierCreateStatusResult = createSupplierCreateStatus(
asyncClient, createStatusGetter -> createStatusGetter
.withBackend(BackupTestSuite.BACKEND)
.withBackupId(backupId)
.withBucket(bucket)
.withPath(path)
);
Supplier<Result<BackupRestoreResponse>> 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<Result<BackupRestoreStatusResponse>> 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()) {
Expand Down

0 comments on commit ed3a0f7

Please sign in to comment.