[ARVADOS] created: 2.1.0-779-g19e9af391

Git user git at public.arvados.org
Tue May 11 20:09:47 UTC 2021


        at  19e9af391ebd6766200bc76c9d1ee90f167e43a7 (commit)


commit 19e9af391ebd6766200bc76c9d1ee90f167e43a7
Author: Peter Amstutz <peter.amstutz at curii.com>
Date:   Tue May 11 16:09:19 2021 -0400

    17589: Ensure that 'group contents' requests are routed correctly
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz at curii.com>

diff --git a/lib/controller/federation/conn.go b/lib/controller/federation/conn.go
index 6029056b2..77bc97aed 100644
--- a/lib/controller/federation/conn.go
+++ b/lib/controller/federation/conn.go
@@ -421,8 +421,19 @@ func (conn *Conn) GroupList(ctx context.Context, options arvados.ListOptions) (a
 	return conn.generated_GroupList(ctx, options)
 }
 
+var userUuidRe = regexp.MustCompile(`^[0-9a-z]{5}-tpzed-[0-9a-z]{15}$`)
+
 func (conn *Conn) GroupContents(ctx context.Context, options arvados.GroupContentsOptions) (arvados.ObjectList, error) {
-	return conn.chooseBackend(options.UUID).GroupContents(ctx, options)
+	if options.ClusterID != "" {
+		// explicitly selected cluster
+		return conn.chooseBackend(options.ClusterID).GroupContents(ctx, options)
+	} else if userUuidRe.MatchString(options.UUID) {
+		// user, get the things they own on the local cluster
+		return conn.local.GroupContents(ctx, options)
+	} else {
+		// a group, potentially want to make federated request
+		return conn.chooseBackend(options.UUID).GroupContents(ctx, options)
+	}
 }
 
 func (conn *Conn) GroupShared(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
diff --git a/lib/controller/federation/group_test.go b/lib/controller/federation/group_test.go
new file mode 100644
index 000000000..1ee6f5876
--- /dev/null
+++ b/lib/controller/federation/group_test.go
@@ -0,0 +1,52 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package federation
+
+import (
+	"errors"
+
+	"git.arvados.org/arvados.git/sdk/go/arvados"
+	"git.arvados.org/arvados.git/sdk/go/arvadostest"
+	check "gopkg.in/check.v1"
+)
+
+var _ = check.Suite(&GroupSuite{})
+
+type GroupSuite struct {
+	FederationSuite
+}
+
+func makeConn() (*Conn, *arvadostest.APIStub, *arvadostest.APIStub) {
+	localAPIstub := &arvadostest.APIStub{Error: errors.New("No result")}
+	remoteAPIstub := &arvadostest.APIStub{Error: errors.New("No result")}
+	return &Conn{&arvados.Cluster{ClusterID: "local"}, localAPIstub, map[string]backend{"zzzzz": remoteAPIstub}}, localAPIstub, remoteAPIstub
+}
+
+func (s *UserSuite) TestGroupContents(c *check.C) {
+	conn, localAPIstub, remoteAPIstub := makeConn()
+	conn.GroupContents(s.ctx, arvados.GroupContentsOptions{UUID: "local-tpzed-xurymjxw79nv3jz"})
+	c.Check(len(localAPIstub.Calls(nil)), check.Equals, 1)
+	c.Check(len(remoteAPIstub.Calls(nil)), check.Equals, 0)
+
+	conn, localAPIstub, remoteAPIstub = makeConn()
+	conn.GroupContents(s.ctx, arvados.GroupContentsOptions{UUID: "zzzzz-tpzed-xurymjxw79nv3jz"})
+	c.Check(len(localAPIstub.Calls(nil)), check.Equals, 1)
+	c.Check(len(remoteAPIstub.Calls(nil)), check.Equals, 0)
+
+	conn, localAPIstub, remoteAPIstub = makeConn()
+	conn.GroupContents(s.ctx, arvados.GroupContentsOptions{UUID: "local-j7d0g-xurymjxw79nv3jz"})
+	c.Check(len(localAPIstub.Calls(nil)), check.Equals, 1)
+	c.Check(len(remoteAPIstub.Calls(nil)), check.Equals, 0)
+
+	conn, localAPIstub, remoteAPIstub = makeConn()
+	conn.GroupContents(s.ctx, arvados.GroupContentsOptions{UUID: "zzzzz-j7d0g-xurymjxw79nv3jz"})
+	c.Check(len(localAPIstub.Calls(nil)), check.Equals, 0)
+	c.Check(len(remoteAPIstub.Calls(nil)), check.Equals, 1)
+
+	conn, localAPIstub, remoteAPIstub = makeConn()
+	conn.GroupContents(s.ctx, arvados.GroupContentsOptions{UUID: "zzzzz-tpzed-xurymjxw79nv3jz", ClusterID: "zzzzz"})
+	c.Check(len(localAPIstub.Calls(nil)), check.Equals, 0)
+	c.Check(len(remoteAPIstub.Calls(nil)), check.Equals, 1)
+}
diff --git a/sdk/go/arvados/api.go b/sdk/go/arvados/api.go
index bfae393f8..4e0348c08 100644
--- a/sdk/go/arvados/api.go
+++ b/sdk/go/arvados/api.go
@@ -136,6 +136,7 @@ type UpdateOptions struct {
 }
 
 type GroupContentsOptions struct {
+	ClusterID          string   `json:"cluster_id"`
 	UUID               string   `json:"uuid,omitempty"`
 	Select             []string `json:"select"`
 	Filters            []Filter `json:"filters"`

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list