Skip to content

Commit

Permalink
Support dynamic backup location (#341)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bevzzz authored Dec 10, 2024
1 parent 99593e9 commit eca4583
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package io.weaviate.client.v1.async.backup.api;

import java.util.ArrayList;
import java.util.List;
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 java.util.concurrent.Future;

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

private String backend;
private String backupId;
private String bucket;
private String backupPath;


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 +43,32 @@ public BackupCanceler withBackupId(String backupId) {
return this;
}

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

public BackupCanceler withPath(String path) {
this.backupPath = 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));

List<String> 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);
}
}
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.util.ArrayList;
import java.util.List;
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 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 backupPath;

public BackupCreateStatusGetter(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) {
super(client, config, tokenProvider);
Expand All @@ -34,9 +38,31 @@ public BackupCreateStatusGetter withBackupId(String backupId) {
return this;
}

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

public BackupCreateStatusGetter withPath(String path) {
this.backupPath = 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));

List<String> 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);
}
}
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
@@ -1,23 +1,27 @@
package io.weaviate.client.v1.async.backup.api;

import java.util.ArrayList;
import java.util.List;
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 io.weaviate.client.v1.backup.model.BackupRestoreStatusResponse;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;

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 backupPath;

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

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

public BackupRestoreStatusGetter withPath(String path) {
this.backupPath = 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));

List<String> 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);
}
}
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,11 +1,15 @@
package io.weaviate.client.v1.backup.api;

import java.util.ArrayList;
import java.util.List;

import io.weaviate.client.Config;
import io.weaviate.client.base.BaseClient;
import io.weaviate.client.base.ClientResult;
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.
Expand All @@ -16,6 +20,8 @@
public class BackupCanceler extends BaseClient<Void> implements ClientResult<Void> {
private String backend;
private String backupId;
private String bucket;
private String backupPath;

public BackupCanceler(HttpClient client, Config config) {
super(client, config);
Expand All @@ -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.backupPath = path;
return this;
}

public BackupCanceler withBackupId(String backupId) {
this.backupId = backupId;
return this;
Expand All @@ -38,7 +54,20 @@ public Result<Void> run() {
}

private String path() {
return String.format("/backups/%s/%s", backend, backupId);
String path = String.format("/backups/%s/%s", backend, backupId);

List<String> 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 path;
}
}

Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package io.weaviate.client.v1.backup.api;

import io.weaviate.client.v1.backup.model.BackupCreateStatusResponse;
import java.util.ArrayList;
import java.util.List;

import io.weaviate.client.Config;
import io.weaviate.client.base.BaseClient;
import io.weaviate.client.base.ClientResult;
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<BackupCreateStatusResponse> implements ClientResult<BackupCreateStatusResponse> {

private String backend;
private String backupId;
private String bucket;
private String backupPath;

public BackupCreateStatusGetter(HttpClient httpClient, Config config) {
super(httpClient, config);
Expand All @@ -27,6 +33,16 @@ public BackupCreateStatusGetter withBackupId(String backupId) {
return this;
}

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

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

@Override
public Result<BackupCreateStatusResponse> run() {
return new Result<>(statusCreate());
Expand All @@ -37,6 +53,19 @@ Response<BackupCreateStatusResponse> statusCreate() {
}

private String path() {
return String.format("/backups/%s/%s", backend, backupId);
String path = String.format("/backups/%s/%s", backend, backupId);

List<String> 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 path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit eca4583

Please sign in to comment.