14287: Use map instead of UpdateBody to update specific attrs.
authorTom Clegg <tclegg@veritasgenetics.com>
Fri, 17 May 2019 19:30:20 +0000 (15:30 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Mon, 17 Jun 2019 13:54:39 +0000 (09:54 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

sdk/go/arvados/fs_backend.go
sdk/go/arvados/fs_collection.go
sdk/go/arvados/fs_project_test.go
services/keep-web/cache.go
services/keep-web/cadaver_test.go
services/keep-web/handler_test.go

index 9ae0fc3a5f4dc2a1e674325b5c4d9f86f19e5afa..c8308aea59e94d06be2e94235b2f0bda4f16f8c0 100644 (file)
@@ -26,5 +26,4 @@ type keepClient interface {
 
 type apiClient interface {
        RequestAndDecode(dst interface{}, method, path string, body io.Reader, params interface{}) error
-       UpdateBody(rsc resource) io.Reader
 }
index 6644f4cfb8e93ef7d601e667cee21a9dbce5d39b..972b3979fcfa4dd7fdb3cde62a90eacd37b27c56 100644 (file)
@@ -131,7 +131,12 @@ func (fs *collectionFileSystem) Sync() error {
                UUID:         fs.uuid,
                ManifestText: txt,
        }
-       err = fs.RequestAndDecode(nil, "PUT", "arvados/v1/collections/"+fs.uuid, fs.UpdateBody(coll), map[string]interface{}{"select": []string{"uuid"}})
+       err = fs.RequestAndDecode(nil, "PUT", "arvados/v1/collections/"+fs.uuid, nil, map[string]interface{}{
+               "collection": map[string]string{
+                       "manifest_text": coll.ManifestText,
+               },
+               "select": []string{"uuid"},
+       })
        if err != nil {
                return fmt.Errorf("sync failed: update %s: %s", fs.uuid, err)
        }
index 49e7d675f8b5c6729b61d94d0f271f615c68e924..91b8222cdc631d6ac80bf005c3f07c84fe641b92 100644 (file)
@@ -118,20 +118,24 @@ func (s *SiteFSSuite) TestProjectReaddirAfterLoadOne(c *check.C) {
 }
 
 func (s *SiteFSSuite) TestSlashInName(c *check.C) {
-       badCollection := Collection{
-               Name:      "bad/collection",
-               OwnerUUID: fixtureAProjectUUID,
-       }
-       err := s.client.RequestAndDecode(&badCollection, "POST", "arvados/v1/collections", s.client.UpdateBody(&badCollection), nil)
+       var badCollection Collection
+       err := s.client.RequestAndDecode(&badCollection, "POST", "arvados/v1/collections", nil, map[string]interface{}{
+               "collection": map[string]string{
+                       "name":       "bad/collection",
+                       "owner_uuid": fixtureAProjectUUID,
+               },
+       })
        c.Assert(err, check.IsNil)
        defer s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/collections/"+badCollection.UUID, nil, nil)
 
-       badProject := Group{
-               Name:       "bad/project",
-               GroupClass: "project",
-               OwnerUUID:  fixtureAProjectUUID,
-       }
-       err = s.client.RequestAndDecode(&badProject, "POST", "arvados/v1/groups", s.client.UpdateBody(&badProject), nil)
+       var badProject Group
+       err = s.client.RequestAndDecode(&badProject, "POST", "arvados/v1/groups", nil, map[string]interface{}{
+               "group": map[string]string{
+                       "name":        "bad/project",
+                       "group_class": "project",
+                       "owner_uuid":  fixtureAProjectUUID,
+               },
+       })
        c.Assert(err, check.IsNil)
        defer s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/groups/"+badProject.UUID, nil, nil)
 
@@ -154,11 +158,13 @@ func (s *SiteFSSuite) TestProjectUpdatedByOther(c *check.C) {
        _, err = s.fs.Open("/home/A Project/oob")
        c.Check(err, check.NotNil)
 
-       oob := Collection{
-               Name:      "oob",
-               OwnerUUID: fixtureAProjectUUID,
-       }
-       err = s.client.RequestAndDecode(&oob, "POST", "arvados/v1/collections", s.client.UpdateBody(&oob), nil)
+       var oob Collection
+       err = s.client.RequestAndDecode(&oob, "POST", "arvados/v1/collections", nil, map[string]interface{}{
+               "collection": map[string]string{
+                       "name":       "oob",
+                       "owner_uuid": fixtureAProjectUUID,
+               },
+       })
        c.Assert(err, check.IsNil)
        defer s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/collections/"+oob.UUID, nil, nil)
 
@@ -179,8 +185,13 @@ func (s *SiteFSSuite) TestProjectUpdatedByOther(c *check.C) {
        c.Check(err, check.IsNil)
 
        // Delete test.txt behind s.fs's back by updating the
-       // collection record with the old (empty) ManifestText.
-       err = s.client.RequestAndDecode(nil, "PATCH", "arvados/v1/collections/"+oob.UUID, s.client.UpdateBody(&oob), nil)
+       // collection record with an empty ManifestText.
+       err = s.client.RequestAndDecode(nil, "PATCH", "arvados/v1/collections/"+oob.UUID, nil, map[string]interface{}{
+               "collection": map[string]string{
+                       "manifest_text":      "",
+                       "portable_data_hash": "d41d8cd98f00b204e9800998ecf8427e+0",
+               },
+       })
        c.Assert(err, check.IsNil)
 
        err = project.Sync()
index 8336b78f9ea9614af2796211d9ed89d58da741e8..b9a1f3069f9d3e8bd03563c6785cb0b00d388582 100644 (file)
@@ -157,7 +157,11 @@ func (c *cache) Update(client *arvados.Client, coll arvados.Collection, fs arvad
        }
        var updated arvados.Collection
        defer c.pdhs.Remove(coll.UUID)
-       err := client.RequestAndDecode(&updated, "PATCH", "arvados/v1/collections/"+coll.UUID, client.UpdateBody(coll), nil)
+       err := client.RequestAndDecode(&updated, "PATCH", "arvados/v1/collections/"+coll.UUID, nil, map[string]interface{}{
+               "collection": map[string]string{
+                       "manifest_text": coll.ManifestText,
+               },
+       })
        if err == nil {
                c.collections.Add(client.AuthToken+"\000"+coll.PortableDataHash, &cachedCollection{
                        expire:     time.Now().Add(time.Duration(c.TTL)),
index 1c93a2b91c0981840c5ac2dde998a55adb1d9b51..9d9e314fcaf7e25710f1fdd341ca13c7491413f0 100644 (file)
@@ -9,7 +9,6 @@ import (
        "fmt"
        "io"
        "io/ioutil"
-       "net/url"
        "os"
        "os/exec"
        "path/filepath"
@@ -74,7 +73,7 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun
        var newCollection arvados.Collection
        arv := arvados.NewClientFromEnv()
        arv.AuthToken = arvadostest.ActiveToken
-       err = arv.RequestAndDecode(&newCollection, "POST", "arvados/v1/collections", bytes.NewBufferString(url.Values{"collection": {"{}"}}.Encode()), nil)
+       err = arv.RequestAndDecode(&newCollection, "POST", "arvados/v1/collections", nil, map[string]interface{}{"collection": map[string]interface{}{}})
        c.Assert(err, check.IsNil)
 
        readPath, writePath, pdhPath := pathFunc(newCollection)
index 040638623748f8aa57150b314886871703157287..93259f74cd9c2f2692555bc4a995cf3ce261241a 100644 (file)
@@ -465,8 +465,12 @@ func (s *IntegrationSuite) TestSpecialCharsInPath(c *check.C) {
        f.Close()
        mtxt, err := fs.MarshalManifest(".")
        c.Assert(err, check.IsNil)
-       coll := arvados.Collection{ManifestText: mtxt}
-       err = client.RequestAndDecode(&coll, "POST", "arvados/v1/collections", client.UpdateBody(coll), nil)
+       var coll arvados.Collection
+       err = client.RequestAndDecode(&coll, "POST", "arvados/v1/collections", nil, map[string]interface{}{
+               "collection": map[string]string{
+                       "manifest_text": mtxt,
+               },
+       })
        c.Assert(err, check.IsNil)
 
        u, _ := url.Parse("http://download.example.com/c=" + coll.UUID + "/")
@@ -773,11 +777,14 @@ func (s *IntegrationSuite) TestDirectoryListing(c *check.C) {
 func (s *IntegrationSuite) TestDeleteLastFile(c *check.C) {
        arv := arvados.NewClientFromEnv()
        var newCollection arvados.Collection
-       err := arv.RequestAndDecode(&newCollection, "POST", "arvados/v1/collections", arv.UpdateBody(&arvados.Collection{
-               OwnerUUID:    arvadostest.ActiveUserUUID,
-               ManifestText: ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt 0:3:bar.txt\n",
-               Name:         "keep-web test collection",
-       }), map[string]bool{"ensure_unique_name": true})
+       err := arv.RequestAndDecode(&newCollection, "POST", "arvados/v1/collections", nil, map[string]interface{}{
+               "collection": map[string]string{
+                       "owner_uuid":    arvadostest.ActiveUserUUID,
+                       "manifest_text": ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt 0:3:bar.txt\n",
+                       "name":          "keep-web test collection",
+               },
+               "ensure_unique_name": true,
+       })
        c.Assert(err, check.IsNil)
        defer arv.RequestAndDecode(&newCollection, "DELETE", "arvados/v1/collections/"+newCollection.UUID, nil, nil)