Merge branch '18858-sync-users-fixes'. Closes #18858
authorLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 7 Jul 2022 18:37:22 +0000 (15:37 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 7 Jul 2022 18:37:22 +0000 (15:37 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

lib/controller/integration_test.go
sdk/java-v2/src/main/java/org/arvados/client/api/client/KeepWebApiClient.java
sdk/java-v2/src/main/java/org/arvados/client/api/client/ProgressListener.java
sdk/java-v2/src/test/java/org/arvados/client/api/client/KeepWebApiClientTest.java [new file with mode: 0644]
sdk/java-v2/src/test/resources/org/arvados/client/api/client/keep-client-upload-response.json [new file with mode: 0644]

index 67d60197e7e160b5f7d99e510106a55a18ffd07f..b0ec4293a38acfdf6a349db48fff96c7bf3f7a1a 100644 (file)
@@ -1126,7 +1126,7 @@ func (s *IntegrationSuite) TestForwardRuntimeTokenToLoginCluster(c *check.C) {
 }
 
 func (s *IntegrationSuite) TestRunTrivialContainer(c *check.C) {
-       outcoll := s.runContainer(c, "z1111", map[string]interface{}{
+       outcoll, _ := s.runContainer(c, "z1111", "", map[string]interface{}{
                "command":             []string{"sh", "-c", "touch \"/out/hello world\" /out/ohai"},
                "container_image":     "busybox:uclibc",
                "cwd":                 "/tmp",
@@ -1141,10 +1141,49 @@ func (s *IntegrationSuite) TestRunTrivialContainer(c *check.C) {
        c.Check(outcoll.PortableDataHash, check.Equals, "8fa5dee9231a724d7cf377c5a2f4907c+65")
 }
 
-func (s *IntegrationSuite) runContainer(c *check.C, clusterID string, ctrSpec map[string]interface{}, expectExitCode int) arvados.Collection {
+func (s *IntegrationSuite) TestContainerInputOnDifferentCluster(c *check.C) {
+       conn := s.super.Conn("z1111")
+       rootctx, _, _ := s.super.RootClients("z1111")
+       userctx, ac, _, _ := s.super.UserClients("z1111", rootctx, c, conn, s.oidcprovider.AuthEmail, true)
+       z1coll, err := conn.CollectionCreate(userctx, arvados.CreateOptions{Attrs: map[string]interface{}{
+               "manifest_text": ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:ocelot\n",
+       }})
+       c.Assert(err, check.IsNil)
+
+       outcoll, logcfs := s.runContainer(c, "z2222", ac.AuthToken, map[string]interface{}{
+               "command":         []string{"ls", "/in"},
+               "container_image": "busybox:uclibc",
+               "cwd":             "/tmp",
+               "environment":     map[string]string{},
+               "mounts": map[string]arvados.Mount{
+                       "/in":  {Kind: "collection", PortableDataHash: z1coll.PortableDataHash},
+                       "/out": {Kind: "tmp", Capacity: 10000},
+               },
+               "output_path":         "/out",
+               "runtime_constraints": arvados.RuntimeConstraints{RAM: 100000000, VCPUs: 1},
+               "priority":            1,
+               "state":               arvados.ContainerRequestStateCommitted,
+               "container_count_max": 1,
+       }, -1)
+       if outcoll.UUID == "" {
+               arvmountlog, err := fs.ReadFile(arvados.FS(logcfs), "/arv-mount.txt")
+               c.Check(err, check.IsNil)
+               c.Check(string(arvmountlog), check.Matches, `(?ms).*cannot use a locally issued token to forward a request to our login cluster \(z1111\).*`)
+               c.Skip("this use case is not supported yet")
+       }
+       stdout, err := fs.ReadFile(arvados.FS(logcfs), "/stdout.txt")
+       c.Check(err, check.IsNil)
+       c.Check(string(stdout), check.Equals, "ocelot\n")
+}
+
+func (s *IntegrationSuite) runContainer(c *check.C, clusterID string, token string, ctrSpec map[string]interface{}, expectExitCode int) (outcoll arvados.Collection, logcfs arvados.CollectionFileSystem) {
        conn := s.super.Conn(clusterID)
        rootctx, _, _ := s.super.RootClients(clusterID)
-       _, ac, kc, _ := s.super.UserClients(clusterID, rootctx, c, conn, s.oidcprovider.AuthEmail, true)
+       if token == "" {
+               _, ac, _, _ := s.super.UserClients(clusterID, rootctx, c, conn, s.oidcprovider.AuthEmail, true)
+               token = ac.AuthToken
+       }
+       _, ac, kc := s.super.ClientsWithToken(clusterID, token)
 
        c.Log("[docker load]")
        out, err := exec.Command("docker", "load", "--input", arvadostest.BusyboxDockerImage(c)).CombinedOutput()
@@ -1164,7 +1203,7 @@ func (s *IntegrationSuite) runContainer(c *check.C, clusterID string, ctrSpec ma
        })
        c.Assert(err, check.IsNil)
 
-       showlogs := func(collectionID string) {
+       showlogs := func(collectionID string) arvados.CollectionFileSystem {
                var logcoll arvados.Collection
                err = ac.RequestAndDecode(&logcoll, "GET", "/arvados/v1/collections/"+collectionID, nil, nil)
                c.Assert(err, check.IsNil)
@@ -1182,42 +1221,36 @@ func (s *IntegrationSuite) runContainer(c *check.C, clusterID string, ctrSpec ma
                        c.Logf("=== %s\n%s\n", path, buf)
                        return nil
                })
+               return cfs
        }
 
        var ctr arvados.Container
        var lastState arvados.ContainerState
        deadline := time.Now().Add(time.Minute)
-wait:
-       for ; ; lastState = ctr.State {
-               err = ac.RequestAndDecode(&ctr, "GET", "/arvados/v1/containers/"+cr.ContainerUUID, nil, nil)
+       for cr.State != arvados.ContainerRequestStateFinal {
+               err = ac.RequestAndDecode(&cr, "GET", "/arvados/v1/container_requests/"+cr.UUID, nil, nil)
                c.Assert(err, check.IsNil)
-               switch ctr.State {
-               case lastState:
+               err = ac.RequestAndDecode(&ctr, "GET", "/arvados/v1/containers/"+cr.ContainerUUID, nil, nil)
+               if err != nil {
+                       c.Logf("error getting container state: %s", err)
+               } else if ctr.State != lastState {
+                       c.Logf("container state changed to %q", ctr.State)
+                       lastState = ctr.State
+               } else {
                        if time.Now().After(deadline) {
-                               c.Errorf("timed out, container request state is %q", cr.State)
+                               c.Errorf("timed out, container state is %q", cr.State)
                                showlogs(ctr.Log)
                                c.FailNow()
                        }
                        time.Sleep(time.Second / 2)
-               case arvados.ContainerStateComplete:
-                       break wait
-               case arvados.ContainerStateQueued, arvados.ContainerStateLocked, arvados.ContainerStateRunning:
-                       c.Logf("container state changed to %q", ctr.State)
-               default:
-                       c.Errorf("unexpected container state %q", ctr.State)
-                       showlogs(ctr.Log)
-                       c.FailNow()
                }
        }
-       c.Check(ctr.ExitCode, check.Equals, 0)
-
-       err = ac.RequestAndDecode(&cr, "GET", "/arvados/v1/container_requests/"+cr.UUID, nil, nil)
-       c.Assert(err, check.IsNil)
-
-       showlogs(cr.LogUUID)
-
-       var outcoll arvados.Collection
-       err = ac.RequestAndDecode(&outcoll, "GET", "/arvados/v1/collections/"+cr.OutputUUID, nil, nil)
-       c.Assert(err, check.IsNil)
-       return outcoll
+       if expectExitCode >= 0 {
+               c.Check(ctr.State, check.Equals, arvados.ContainerStateComplete)
+               c.Check(ctr.ExitCode, check.Equals, expectExitCode)
+               err = ac.RequestAndDecode(&outcoll, "GET", "/arvados/v1/collections/"+cr.OutputUUID, nil, nil)
+               c.Assert(err, check.IsNil)
+       }
+       logcfs = showlogs(cr.LogUUID)
+       return outcoll, logcfs
 }
index 0145b0fc4c5129948d132f0662ed05b6807a3a96..05d39e9e6085ac66f6ea0aa1901c3ce2ae096f68 100644 (file)
@@ -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())
index 8563adcc763bb0415ad6ccbee320d108448ec8d8..596c9421aca160bf677a9bcf94d200431c33ac51 100644 (file)
@@ -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 (file)
index 0000000..07b7b25
--- /dev/null
@@ -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 (file)
index 0000000..5284f28
--- /dev/null
@@ -0,0 +1 @@
+Created
\ No newline at end of file