Merge branch '20541-less-fetching-mounts'
authorTom Clegg <tom@curii.com>
Fri, 2 Jun 2023 16:11:02 +0000 (12:11 -0400)
committerTom Clegg <tom@curii.com>
Fri, 2 Jun 2023 16:11:02 +0000 (12:11 -0400)
fixes #20541

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/crunchrun/crunchrun.go
sdk/go/arvados/client.go
sdk/go/arvados/client_test.go

index 7d69fb0f977d408e890cd9a21d44f91be17dd132..8e7d3b0d6e9057b21b6ed66959d193889072f2b5 100644 (file)
@@ -1124,6 +1124,7 @@ func (runner *ContainerRunner) WaitFinish() error {
        }
        runner.CrunchLog.Printf("Container exited with status code %d%s", exitcode, extra)
        err = runner.DispatcherArvClient.Update("containers", runner.Container.UUID, arvadosclient.Dict{
+               "select":    []string{"uuid"},
                "container": arvadosclient.Dict{"exit_code": exitcode},
        }, nil)
        if err != nil {
@@ -1200,7 +1201,10 @@ func (runner *ContainerRunner) updateLogs() {
                }
 
                err = runner.DispatcherArvClient.Update("containers", runner.Container.UUID, arvadosclient.Dict{
-                       "container": arvadosclient.Dict{"log": saved.PortableDataHash},
+                       "select": []string{"uuid"},
+                       "container": arvadosclient.Dict{
+                               "log": saved.PortableDataHash,
+                       },
                }, nil)
                if err != nil {
                        runner.CrunchLog.Printf("error updating container log to %s: %s", saved.PortableDataHash, err)
@@ -1316,6 +1320,7 @@ func (runner *ContainerRunner) checkSpotInterruptionNotices() {
 
 func (runner *ContainerRunner) updateRuntimeStatus(status arvadosclient.Dict) {
        err := runner.DispatcherArvClient.Update("containers", runner.Container.UUID, arvadosclient.Dict{
+               "select": []string{"uuid"},
                "container": arvadosclient.Dict{
                        "runtime_status": status,
                },
@@ -1332,7 +1337,9 @@ func (runner *ContainerRunner) CaptureOutput(bindmounts map[string]bindmount) er
                // Output may have been set directly by the container, so
                // refresh the container record to check.
                err := runner.DispatcherArvClient.Get("containers", runner.Container.UUID,
-                       nil, &runner.Container)
+                       arvadosclient.Dict{
+                               "select": []string{"output"},
+                       }, &runner.Container)
                if err != nil {
                        return err
                }
@@ -1370,6 +1377,7 @@ func (runner *ContainerRunner) CaptureOutput(bindmounts map[string]bindmount) er
        var resp arvados.Collection
        err = runner.ContainerArvClient.Create("collections", arvadosclient.Dict{
                "ensure_unique_name": true,
+               "select":             []string{"portable_data_hash"},
                "collection": arvadosclient.Dict{
                        "is_trashed":    true,
                        "name":          "output for " + runner.Container.UUID,
@@ -1496,6 +1504,8 @@ func (runner *ContainerRunner) CommitLogs() error {
        return nil
 }
 
+// Create/update the log collection. Return value has UUID and
+// PortableDataHash fields populated, but others may be blank.
 func (runner *ContainerRunner) saveLogCollection(final bool) (response arvados.Collection, err error) {
        runner.logMtx.Lock()
        defer runner.logMtx.Unlock()
@@ -1530,7 +1540,10 @@ func (runner *ContainerRunner) saveLogCollection(final bool) (response arvados.C
                updates["trash_at"] = exp
                updates["delete_at"] = exp
        }
-       reqBody := arvadosclient.Dict{"collection": updates}
+       reqBody := arvadosclient.Dict{
+               "select":     []string{"uuid", "portable_data_hash"},
+               "collection": updates,
+       }
        var err2 error
        if runner.logUUID == "" {
                reqBody["ensure_unique_name"] = true
@@ -1565,7 +1578,10 @@ func (runner *ContainerRunner) UpdateContainerRunning(logId string) error {
        return runner.DispatcherArvClient.Update(
                "containers",
                runner.Container.UUID,
-               arvadosclient.Dict{"container": updates},
+               arvadosclient.Dict{
+                       "select":    []string{"uuid"},
+                       "container": updates,
+               },
                nil,
        )
 }
@@ -1603,7 +1619,10 @@ func (runner *ContainerRunner) UpdateContainerFinal() error {
                update["output"] = *runner.OutputPDH
        }
        update["cost"] = runner.calculateCost(time.Now())
-       return runner.DispatcherArvClient.Update("containers", runner.Container.UUID, arvadosclient.Dict{"container": update}, nil)
+       return runner.DispatcherArvClient.Update("containers", runner.Container.UUID, arvadosclient.Dict{
+               "select":    []string{"uuid"},
+               "container": update,
+       }, nil)
 }
 
 // IsCancelled returns the value of Cancelled, with goroutine safety.
@@ -2095,7 +2114,10 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s
                        cr.gateway.UpdateTunnelURL = func(url string) {
                                cr.gateway.Address = "tunnel " + url
                                cr.DispatcherArvClient.Update("containers", containerUUID,
-                                       arvadosclient.Dict{"container": arvadosclient.Dict{"gateway_address": cr.gateway.Address}}, nil)
+                                       arvadosclient.Dict{
+                                               "select":    []string{"uuid"},
+                                               "container": arvadosclient.Dict{"gateway_address": cr.gateway.Address},
+                                       }, nil)
                        }
                }
                err = cr.gateway.Start()
@@ -2464,6 +2486,7 @@ func (runner *ContainerRunner) handleSIGUSR2(sigchan chan os.Signal) {
        for range sigchan {
                runner.loadPrices()
                update := arvadosclient.Dict{
+                       "select": []string{"uuid"},
                        "container": arvadosclient.Dict{
                                "cost": runner.calculateCost(time.Now()),
                        },
index 636592b5ade01c6fe22914ff63a762597dd80fce..d71ade8a81f92e76fe0c9155d16e437fb3dbb267 100644 (file)
@@ -540,6 +540,12 @@ func (c *Client) RequestAndDecodeContext(ctx context.Context, dst interface{}, m
        if err != nil {
                return err
        }
+       if dst == nil {
+               if urlValues == nil {
+                       urlValues = url.Values{}
+               }
+               urlValues["select"] = []string{`["uuid"]`}
+       }
        if urlValues == nil {
                // Nothing to send
        } else if body != nil || ((method == "GET" || method == "HEAD") && len(urlValues.Encode()) < 1000) {
index b7c60fbf8dbfe8e53ffa3180d057294062d7d5d4..a196003b8fc01241472275741278aed929e42845 100644 (file)
@@ -170,6 +170,44 @@ func (*clientSuite) TestAnythingToValues(c *check.C) {
        }
 }
 
+// select=["uuid"] is added automatically when RequestAndDecode's
+// destination argument is nil.
+func (*clientSuite) TestAutoSelectUUID(c *check.C) {
+       var req *http.Request
+       var err error
+       server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+               c.Check(r.ParseForm(), check.IsNil)
+               req = r
+               w.Write([]byte("{}"))
+       }))
+       client := Client{
+               APIHost:   strings.TrimPrefix(server.URL, "https://"),
+               AuthToken: "zzz",
+               Insecure:  true,
+               Timeout:   2 * time.Second,
+       }
+
+       req = nil
+       err = client.RequestAndDecode(nil, http.MethodPost, "test", nil, nil)
+       c.Check(err, check.IsNil)
+       c.Check(req.FormValue("select"), check.Equals, `["uuid"]`)
+
+       req = nil
+       err = client.RequestAndDecode(nil, http.MethodGet, "test", nil, nil)
+       c.Check(err, check.IsNil)
+       c.Check(req.FormValue("select"), check.Equals, `["uuid"]`)
+
+       req = nil
+       err = client.RequestAndDecode(nil, http.MethodGet, "test", nil, map[string]interface{}{"select": []string{"blergh"}})
+       c.Check(err, check.IsNil)
+       c.Check(req.FormValue("select"), check.Equals, `["uuid"]`)
+
+       req = nil
+       err = client.RequestAndDecode(&struct{}{}, http.MethodGet, "test", nil, map[string]interface{}{"select": []string{"blergh"}})
+       c.Check(err, check.IsNil)
+       c.Check(req.FormValue("select"), check.Equals, `["blergh"]`)
+}
+
 func (*clientSuite) TestLoadConfig(c *check.C) {
        oldenv := os.Environ()
        defer func() {