Skip to content

Commit

Permalink
Merge pull request #309 from bevzzz/feature/backup_cancel
Browse files Browse the repository at this point in the history
gh-297: support cancellation for backups
  • Loading branch information
antas-marcin authored Oct 21, 2024
2 parents cb3bf9d + 7f5acbc commit cb1c6b8
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 90 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# Weaviate Java client <img alt='Weaviate logo' src='https://raw.githubusercontent.com/weaviate/weaviate/19de0956c69b66c5552447e84d016f4fe29d12c9/docs/assets/weaviate-logo.png' width='180' align='right' />

A Java native client for weaviate.
A Java native client for Weaviate.

## Usage

In order to get start using the java client one needs to add it's dependency:
To start using Weaviate Java client add this dependency to `pom.xml`:

```xml

<dependency>
<groupId>io.weaviate</groupId>
<artifactId>client</artifactId>
<version>4.8.3</version>
<groupId>io.weaviate</groupId>
<artifactId>client</artifactId>
<version>4.8.3</version>
</dependency>
```


### For applications on Java 9 or above

The client utilizes Gson for JSON serialization/deserialization and Gson uses reflection of internal `java.lang` classes
to do it. This is not allowed by default in Java 9 and above.

To work around this, it's necessary to add this JVM commandline argument:

```
--add-opens=java.base/java.lang=ALL-UNNAMED
```
Expand All @@ -29,11 +30,10 @@ If you're using Gradle, you can add this instead to your `application` block in

```kotlin
applicationDefaultJvmArgs += listOf(
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.lang=ALL-UNNAMED",
)
```


Here's a simple code to start up working with Java client:

1. Add dependency to your java project.
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/io/weaviate/client/v1/backup/Backup.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package io.weaviate.client.v1.backup;

import io.weaviate.client.Config;
import io.weaviate.client.base.http.HttpClient;
import io.weaviate.client.v1.backup.api.BackupCreateStatusGetter;
import io.weaviate.client.v1.backup.api.BackupCreator;
import io.weaviate.client.v1.backup.api.BackupRestoreStatusGetter;
import io.weaviate.client.v1.backup.api.BackupRestorer;
import io.weaviate.client.v1.backup.api.*;
import lombok.RequiredArgsConstructor;
import io.weaviate.client.Config;

@RequiredArgsConstructor
public class Backup {
Expand All @@ -30,7 +27,7 @@ public BackupRestoreStatusGetter restoreStatusGetter() {
return new BackupRestoreStatusGetter(httpClient, config);
}

// public BackupGetter getter() {
// return new BackupGetter(config);
// }
public BackupCanceler canceler() {
return new BackupCanceler(httpClient, config);
}
}
44 changes: 44 additions & 0 deletions src/main/java/io/weaviate/client/v1/backup/api/BackupCanceler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.weaviate.client.v1.backup.api;

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;

/**
* BackupCanceler can cancel an in-progress backup by ID.
*
* <p>
* Canceling backups which have successfully completed before being interrupted is not supported and will result in an error.
*/
public class BackupCanceler extends BaseClient<Void> implements ClientResult<Void> {
private String backend;
private String backupId;

public BackupCanceler(HttpClient client, Config config) {
super(client, config);
}

public BackupCanceler withBackend(String backend) {
this.backend = backend;
return this;
}

public BackupCanceler withBackupId(String backupId) {
this.backupId = backupId;
return this;
}

@Override
public Result<Void> run() {
Response<Void> result = sendDeleteRequest(path(), null, Void.class);
return new Result<>(result);
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public interface CreateStatus {
String TRANSFERRED = "TRANSFERRED";
String SUCCESS = "SUCCESS";
String FAILED = "FAILED";
String CANCELED = "CANCELED";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
public class WeaviateVersion {

// docker image version
public static final String WEAVIATE_IMAGE = "1.26.4";
public static final String WEAVIATE_IMAGE = "stable-v1.26-6a411a4";

// to be set according to weaviate docker image
public static final String EXPECTED_WEAVIATE_VERSION = "1.26.4";
public static final String EXPECTED_WEAVIATE_VERSION = "1.26.6";
// to be set according to weaviate docker image
public static final String EXPECTED_WEAVIATE_GIT_HASH = "584532a";
public static final String EXPECTED_WEAVIATE_GIT_HASH = "6a411a4";

private WeaviateVersion() {}
private WeaviateVersion() {
}
}
Loading

0 comments on commit cb1c6b8

Please sign in to comment.