[arvados] updated: 2.4.1-20-g3ae5d83fc
git repository hosting
git at public.arvados.org
Fri Aug 5 14:10:10 UTC 2022
Summary of changes:
.../client/api/client/KeepWebApiClient.java | 13 ++++++++
.../client/api/client/ProgressListener.java | 2 +-
.../org/arvados/client/logic/keep/KeepClient.java | 4 +--
.../client/api/client/KeepWebApiClientTest.java | 39 ++++++++++++++++++++++
.../api/client/keep-client-upload-response.json | 1 +
5 files changed, 55 insertions(+), 4 deletions(-)
create mode 100644 sdk/java-v2/src/test/java/org/arvados/client/api/client/KeepWebApiClientTest.java
create mode 100644 sdk/java-v2/src/test/resources/org/arvados/client/api/client/keep-client-upload-response.json
via 3ae5d83fcfa21924f972efdfc19d1aa52637f936 (commit)
via 10904f7c2240d945876b46bc19ec76154bcd1f76 (commit)
from a58e9d7052c42510be3238dc7e1ade52c73f17cd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 3ae5d83fcfa21924f972efdfc19d1aa52637f936
Author: Peter Amstutz <peter.amstutz at curii.com>
Date: Fri Jul 22 15:45:24 2022 -0400
Merge branch 'MajewskiKrzysztof/use_api_token_from_config_object'
refs #19282
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz at curii.com>
diff --git a/sdk/java-v2/src/main/java/org/arvados/client/logic/keep/KeepClient.java b/sdk/java-v2/src/main/java/org/arvados/client/logic/keep/KeepClient.java
index 9cc732d46..cc409983b 100644
--- a/sdk/java-v2/src/main/java/org/arvados/client/logic/keep/KeepClient.java
+++ b/sdk/java-v2/src/main/java/org/arvados/client/logic/keep/KeepClient.java
@@ -39,14 +39,12 @@ public class KeepClient {
private List<KeepService> keepServices;
private List<KeepService> writableServices;
private Map<String, KeepService> gatewayServices;
- private final String apiToken;
private Integer maxReplicasPerService;
private final ConfigProvider config;
public KeepClient(ConfigProvider config) {
this.config = config;
keepServicesApiClient = new KeepServicesApiClient(config);
- apiToken = config.getApiToken();
}
public byte[] getDataChunk(KeepLocator keepLocator) {
@@ -122,7 +120,7 @@ public class KeepClient {
private List<String> mapNewServices(Map<String, FileTransferHandler> rootsMap, KeepLocator locator,
boolean forceRebuild, boolean needWritable, Map<String, String> headers) {
- headers.putIfAbsent("Authorization", String.format("OAuth2 %s", apiToken));
+ headers.putIfAbsent("Authorization", String.format("OAuth2 %s", config.getApiToken()));
List<String> localRoots = weightedServiceRoots(locator, forceRebuild, needWritable);
for (String root : localRoots) {
FileTransferHandler keepServiceLocal = new FileTransferHandler(root, headers, config);
commit 10904f7c2240d945876b46bc19ec76154bcd1f76
Author: Peter Amstutz <peter.amstutz at curii.com>
Date: Thu Jul 7 10:57:59 2022 -0400
Merge branch 'keep_web_api_client_upload_method' refs #19220
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz at curii.com>
diff --git a/sdk/java-v2/src/main/java/org/arvados/client/api/client/KeepWebApiClient.java b/sdk/java-v2/src/main/java/org/arvados/client/api/client/KeepWebApiClient.java
index 0145b0fc4..05d39e9e6 100644
--- a/sdk/java-v2/src/main/java/org/arvados/client/api/client/KeepWebApiClient.java
+++ b/sdk/java-v2/src/main/java/org/arvados/client/api/client/KeepWebApiClient.java
@@ -9,8 +9,11 @@ package org.arvados.client.api.client;
import okhttp3.HttpUrl;
import okhttp3.Request;
+import okhttp3.RequestBody;
import org.arvados.client.config.ConfigProvider;
+import java.io.File;
+
public class KeepWebApiClient extends BaseApiClient {
public KeepWebApiClient(ConfigProvider config) {
@@ -35,6 +38,16 @@ public class KeepWebApiClient extends BaseApiClient {
return newCall(request);
}
+ public String upload(String collectionUuid, File file, ProgressListener progressListener) {
+ RequestBody requestBody = new CountingFileRequestBody(file, progressListener);
+
+ Request request = getRequestBuilder()
+ .url(getUrlBuilder(collectionUuid, file.getName()).build())
+ .put(requestBody)
+ .build();
+ return newCall(request);
+ }
+
private HttpUrl.Builder getUrlBuilder(String collectionUuid, String filePathName) {
return new HttpUrl.Builder()
.scheme(config.getApiProtocol())
diff --git a/sdk/java-v2/src/main/java/org/arvados/client/api/client/ProgressListener.java b/sdk/java-v2/src/main/java/org/arvados/client/api/client/ProgressListener.java
index 8563adcc7..596c9421a 100644
--- a/sdk/java-v2/src/main/java/org/arvados/client/api/client/ProgressListener.java
+++ b/sdk/java-v2/src/main/java/org/arvados/client/api/client/ProgressListener.java
@@ -10,5 +10,5 @@ package org.arvados.client.api.client;
@FunctionalInterface
public interface ProgressListener {
- void updateProgress(long num);
+ void updateProgress(long uploadedBytes);
}
\ No newline at end of file
diff --git a/sdk/java-v2/src/test/java/org/arvados/client/api/client/KeepWebApiClientTest.java b/sdk/java-v2/src/test/java/org/arvados/client/api/client/KeepWebApiClientTest.java
new file mode 100644
index 000000000..07b7b2533
--- /dev/null
+++ b/sdk/java-v2/src/test/java/org/arvados/client/api/client/KeepWebApiClientTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) The Arvados Authors. All rights reserved.
+ *
+ * SPDX-License-Identifier: AGPL-3.0 OR Apache-2.0
+ *
+ */
+
+package org.arvados.client.api.client;
+
+import org.arvados.client.test.utils.ArvadosClientMockedWebServerTest;
+import org.junit.Test;
+
+import java.io.File;
+import java.nio.file.Files;
+
+import static org.arvados.client.test.utils.ApiClientTestUtils.getResponse;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class KeepWebApiClientTest extends ArvadosClientMockedWebServerTest {
+
+ private KeepWebApiClient client = new KeepWebApiClient(CONFIG);
+
+ @Test
+ public void uploadFile() throws Exception {
+ // given
+ String collectionUuid = "112ci-4zz18-p51w7z3fpopo6sm";
+ File file = Files.createTempFile("keep-upload-test", "txt").toFile();
+ Files.write(file.toPath(), "test data".getBytes());
+
+ server.enqueue(getResponse("keep-client-upload-response"));
+
+ // when
+ String uploadResponse = client.upload(collectionUuid, file, uploadedBytes -> System.out.printf("Uploaded bytes: %s/%s%n", uploadedBytes, file.length()));
+
+ // then
+ assertThat(uploadResponse).isEqualTo("Created");
+ }
+
+}
diff --git a/sdk/java-v2/src/test/resources/org/arvados/client/api/client/keep-client-upload-response.json b/sdk/java-v2/src/test/resources/org/arvados/client/api/client/keep-client-upload-response.json
new file mode 100644
index 000000000..5284f287d
--- /dev/null
+++ b/sdk/java-v2/src/test/resources/org/arvados/client/api/client/keep-client-upload-response.json
@@ -0,0 +1 @@
+Created
\ No newline at end of file
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list