[ARVADOS] created: 1.3.0-2757-gbef1b89ee

Git user git at public.arvados.org
Thu Jul 9 14:30:07 UTC 2020


        at  bef1b89ee6ba0225765a5fdb7e2ddf826b30cb30 (commit)


commit bef1b89ee6ba0225765a5fdb7e2ddf826b30cb30
Author: Tom Clegg <tom at tomclegg.ca>
Date:   Thu Jul 9 10:28:05 2020 -0400

    16534: Add example of calling other controller APIs.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at tomclegg.ca>

diff --git a/lib/controller/example/controller.go b/lib/controller/example/controller.go
index 03db99d4d..5acc40e6d 100644
--- a/lib/controller/example/controller.go
+++ b/lib/controller/example/controller.go
@@ -11,22 +11,37 @@ import (
 	"git.arvados.org/arvados.git/sdk/go/arvados"
 )
 
-func New(cluster *arvados.Cluster) *Controller {
+func New(cluster *arvados.Cluster, parent arvados.API) *Controller {
 	return &Controller{
 		cluster: cluster,
+		parent:  parent,
 	}
 }
 
 type Controller struct {
 	cluster *arvados.Cluster
+	parent  arvados.API
 }
 
 func (ctrl *Controller) ExampleCount(ctx context.Context, opts arvados.ExampleCountOptions) (resp arvados.ExampleCountResponse, err error) {
+	// Example of direct database access
 	tx, err := ctrlctx.CurrentTx(ctx)
 	if err != nil {
 		return
 	}
 	err = tx.QueryRowContext(ctx, `select count(*) from users`).Scan(&resp.Count)
+	if err != nil {
+		return
+	}
+
+	// Example of calling other controller APIs that are
+	// implemented in different packages
+	userlist, err := ctrl.parent.UserList(ctx, arvados.ListOptions{Limit: 0, Count: "exact"})
+	if err != nil {
+		return
+	}
+	resp.Count += userlist.ItemsAvailable
+
 	return
 }
 
diff --git a/lib/controller/example/controller_test.go b/lib/controller/example/controller_test.go
index be0f4da66..e67323c43 100644
--- a/lib/controller/example/controller_test.go
+++ b/lib/controller/example/controller_test.go
@@ -25,6 +25,7 @@ var _ = check.Suite(&ExampleSuite{})
 type ExampleSuite struct {
 	ctrl     *Controller
 	ctx      context.Context
+	stub     *arvadostest.APIStub
 	rollback func()
 }
 
@@ -34,7 +35,8 @@ func (s *ExampleSuite) SetUpTest(c *check.C) {
 	cluster, err := cfg.GetCluster("")
 	c.Assert(err, check.IsNil)
 	s.ctx, s.rollback = arvadostest.TransactionContext(c, arvadostest.DB(c, cluster))
-	s.ctrl = New(cluster)
+	s.stub = &arvadostest.APIStub{}
+	s.ctrl = New(cluster, s.stub)
 }
 
 func (s *ExampleSuite) TearDownTest(c *check.C) {
@@ -48,6 +50,7 @@ func (s *ExampleSuite) TestCount(c *check.C) {
 	resp, err := s.ctrl.ExampleCount(s.ctx, arvados.ExampleCountOptions{})
 	c.Check(err, check.IsNil)
 	c.Check(resp.Count, check.Equals, 29)
+	c.Check(s.stub.Calls(s.stub.UserList), check.HasLen, 1)
 }
 
 func (s *ExampleSuite) TestGet(c *check.C) {
@@ -55,4 +58,5 @@ func (s *ExampleSuite) TestGet(c *check.C) {
 	c.Check(err, check.IsNil)
 	c.Check(resp.UUID, check.Equals, "alice")
 	c.Check(resp.HairStyle, check.Equals, "bob")
+	c.Check(s.stub.Calls(s.stub.UserList), check.HasLen, 0)
 }
diff --git a/lib/controller/localdb/conn.go b/lib/controller/localdb/conn.go
index 32246531f..a0c226919 100644
--- a/lib/controller/localdb/conn.go
+++ b/lib/controller/localdb/conn.go
@@ -29,7 +29,7 @@ func NewConn(cluster *arvados.Cluster) *Conn {
 		cluster:         cluster,
 		railsProxy:      railsProxy,
 		loginController: chooseLoginController(cluster, railsProxy),
-		example:         example.New(cluster, currenttx),
+		example:         example.New(cluster, &conn),
 	}
 	return &conn
 }

commit de928ad3b7d36eba92ebbf0d30838b5314eeddec
Author: Tom Clegg <tom at tomclegg.ca>
Date:   Mon Jul 6 16:19:29 2020 -0400

    16534: Add example API.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at tomclegg.ca>

diff --git a/lib/controller/example/controller.go b/lib/controller/example/controller.go
new file mode 100644
index 000000000..03db99d4d
--- /dev/null
+++ b/lib/controller/example/controller.go
@@ -0,0 +1,37 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package example
+
+import (
+	"context"
+
+	"git.arvados.org/arvados.git/lib/ctrlctx"
+	"git.arvados.org/arvados.git/sdk/go/arvados"
+)
+
+func New(cluster *arvados.Cluster) *Controller {
+	return &Controller{
+		cluster: cluster,
+	}
+}
+
+type Controller struct {
+	cluster *arvados.Cluster
+}
+
+func (ctrl *Controller) ExampleCount(ctx context.Context, opts arvados.ExampleCountOptions) (resp arvados.ExampleCountResponse, err error) {
+	tx, err := ctrlctx.CurrentTx(ctx)
+	if err != nil {
+		return
+	}
+	err = tx.QueryRowContext(ctx, `select count(*) from users`).Scan(&resp.Count)
+	return
+}
+
+func (ctrl *Controller) ExampleGet(ctx context.Context, opts arvados.GetOptions) (resp arvados.Example, err error) {
+	resp.UUID = opts.UUID
+	resp.HairStyle = "bob"
+	return
+}
diff --git a/lib/controller/example/controller_test.go b/lib/controller/example/controller_test.go
new file mode 100644
index 000000000..be0f4da66
--- /dev/null
+++ b/lib/controller/example/controller_test.go
@@ -0,0 +1,58 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package example
+
+import (
+	"context"
+	"testing"
+
+	"git.arvados.org/arvados.git/lib/config"
+	"git.arvados.org/arvados.git/sdk/go/arvados"
+	"git.arvados.org/arvados.git/sdk/go/arvadostest"
+	"git.arvados.org/arvados.git/sdk/go/ctxlog"
+	check "gopkg.in/check.v1"
+)
+
+// Gocheck boilerplate
+func Test(t *testing.T) {
+	check.TestingT(t)
+}
+
+var _ = check.Suite(&ExampleSuite{})
+
+type ExampleSuite struct {
+	ctrl     *Controller
+	ctx      context.Context
+	rollback func()
+}
+
+func (s *ExampleSuite) SetUpTest(c *check.C) {
+	cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
+	c.Assert(err, check.IsNil)
+	cluster, err := cfg.GetCluster("")
+	c.Assert(err, check.IsNil)
+	s.ctx, s.rollback = arvadostest.TransactionContext(c, arvadostest.DB(c, cluster))
+	s.ctrl = New(cluster)
+}
+
+func (s *ExampleSuite) TearDownTest(c *check.C) {
+	if s.rollback != nil {
+		s.rollback()
+		s.rollback = nil
+	}
+}
+
+func (s *ExampleSuite) TestCount(c *check.C) {
+	resp, err := s.ctrl.ExampleCount(s.ctx, arvados.ExampleCountOptions{})
+	c.Check(err, check.IsNil)
+	c.Check(resp.Count, check.Equals, 29)
+}
+
+func (s *ExampleSuite) TestGet(c *check.C) {
+	resp, err := s.ctrl.ExampleGet(s.ctx, arvados.GetOptions{UUID: "alice"})
+	c.Check(err, check.IsNil)
+	c.Check(resp.UUID, check.Equals, "alice")
+	c.Check(resp.HairStyle, check.Equals, "bob")
+}
diff --git a/lib/controller/federation/conn.go b/lib/controller/federation/conn.go
index 418b6811b..025bb73b6 100644
--- a/lib/controller/federation/conn.go
+++ b/lib/controller/federation/conn.go
@@ -323,6 +323,14 @@ func (conn *Conn) ContainerUnlock(ctx context.Context, options arvados.GetOption
 	return conn.chooseBackend(options.UUID).ContainerUnlock(ctx, options)
 }
 
+func (conn *Conn) ExampleCount(ctx context.Context, options arvados.ExampleCountOptions) (arvados.ExampleCountResponse, error) {
+	return conn.chooseBackend(options.ClusterID).ExampleCount(ctx, options)
+}
+
+func (conn *Conn) ExampleGet(ctx context.Context, options arvados.GetOptions) (arvados.Example, error) {
+	return conn.chooseBackend(options.UUID).ExampleGet(ctx, options)
+}
+
 func (conn *Conn) SpecimenList(ctx context.Context, options arvados.ListOptions) (arvados.SpecimenList, error) {
 	return conn.generated_SpecimenList(ctx, options)
 }
diff --git a/lib/controller/handler.go b/lib/controller/handler.go
index e742bbc59..0052493f4 100644
--- a/lib/controller/handler.go
+++ b/lib/controller/handler.go
@@ -94,6 +94,8 @@ func (h *Handler) setup() {
 	if !h.Cluster.ForceLegacyAPI14 {
 		mux.Handle("/arvados/v1/collections", rtr)
 		mux.Handle("/arvados/v1/collections/", rtr)
+		mux.Handle("/arvados/v1/examples", rtr)
+		mux.Handle("/arvados/v1/examples/", rtr)
 		mux.Handle("/arvados/v1/users", rtr)
 		mux.Handle("/arvados/v1/users/", rtr)
 		mux.Handle("/login", rtr)
diff --git a/lib/controller/localdb/conn.go b/lib/controller/localdb/conn.go
index 4f0035edf..32246531f 100644
--- a/lib/controller/localdb/conn.go
+++ b/lib/controller/localdb/conn.go
@@ -7,6 +7,7 @@ package localdb
 import (
 	"context"
 
+	"git.arvados.org/arvados.git/lib/controller/example"
 	"git.arvados.org/arvados.git/lib/controller/railsproxy"
 	"git.arvados.org/arvados.git/lib/controller/rpc"
 	"git.arvados.org/arvados.git/sdk/go/arvados"
@@ -18,6 +19,7 @@ type Conn struct {
 	cluster     *arvados.Cluster
 	*railsProxy // handles API methods that aren't defined on Conn itself
 	loginController
+	example *example.Controller
 }
 
 func NewConn(cluster *arvados.Cluster) *Conn {
@@ -27,10 +29,19 @@ func NewConn(cluster *arvados.Cluster) *Conn {
 		cluster:         cluster,
 		railsProxy:      railsProxy,
 		loginController: chooseLoginController(cluster, railsProxy),
+		example:         example.New(cluster, currenttx),
 	}
 	return &conn
 }
 
+func (conn *Conn) ExampleCount(ctx context.Context, opts arvados.ExampleCountOptions) (arvados.ExampleCountResponse, error) {
+	return conn.example.ExampleCount(ctx, opts)
+}
+
+func (conn *Conn) ExampleGet(ctx context.Context, opts arvados.GetOptions) (arvados.Example, error) {
+	return conn.example.ExampleGet(ctx, opts)
+}
+
 func (conn *Conn) Logout(ctx context.Context, opts arvados.LogoutOptions) (arvados.LogoutResponse, error) {
 	return conn.loginController.Logout(ctx, opts)
 }
diff --git a/lib/controller/router/router.go b/lib/controller/router/router.go
index 294452434..7df199f77 100644
--- a/lib/controller/router/router.go
+++ b/lib/controller/router/router.go
@@ -186,6 +186,20 @@ func (rtr *router) addRoutes() {
 				return rtr.backend.ContainerUnlock(ctx, *opts.(*arvados.GetOptions))
 			},
 		},
+		{
+			arvados.EndpointExampleCount,
+			func() interface{} { return &arvados.ExampleCountOptions{} },
+			func(ctx context.Context, opts interface{}) (interface{}, error) {
+				return rtr.backend.ExampleCount(ctx, *opts.(*arvados.ExampleCountOptions))
+			},
+		},
+		{
+			arvados.EndpointExampleGet,
+			func() interface{} { return &arvados.GetOptions{} },
+			func(ctx context.Context, opts interface{}) (interface{}, error) {
+				return rtr.backend.ExampleGet(ctx, *opts.(*arvados.GetOptions))
+			},
+		},
 		{
 			arvados.EndpointSpecimenCreate,
 			func() interface{} { return &arvados.CreateOptions{} },
diff --git a/lib/controller/rpc/conn.go b/lib/controller/rpc/conn.go
index 729d8bdde..9ef3cce06 100644
--- a/lib/controller/rpc/conn.go
+++ b/lib/controller/rpc/conn.go
@@ -287,6 +287,17 @@ func (conn *Conn) ContainerUnlock(ctx context.Context, options arvados.GetOption
 	return resp, err
 }
 
+func (conn *Conn) ExampleCount(ctx context.Context, options arvados.ExampleCountOptions) (resp arvados.ExampleCountResponse, err error) {
+	ep := arvados.EndpointExampleCount
+	err = conn.requestAndDecode(ctx, &resp, ep, nil, options)
+	return
+}
+func (conn *Conn) ExampleGet(ctx context.Context, options arvados.GetOptions) (resp arvados.Example, err error) {
+	ep := arvados.EndpointExampleGet
+	err = conn.requestAndDecode(ctx, &resp, ep, nil, options)
+	return
+}
+
 func (conn *Conn) SpecimenCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Specimen, error) {
 	ep := arvados.EndpointSpecimenCreate
 	var resp arvados.Specimen
diff --git a/sdk/go/arvados/api.go b/sdk/go/arvados/api.go
index c32f88864..7994562ba 100644
--- a/sdk/go/arvados/api.go
+++ b/sdk/go/arvados/api.go
@@ -41,6 +41,8 @@ var (
 	EndpointContainerDelete               = APIEndpoint{"DELETE", "arvados/v1/containers/{uuid}", ""}
 	EndpointContainerLock                 = APIEndpoint{"POST", "arvados/v1/containers/{uuid}/lock", ""}
 	EndpointContainerUnlock               = APIEndpoint{"POST", "arvados/v1/containers/{uuid}/unlock", ""}
+	EndpointExampleCount                  = APIEndpoint{"GET", "arvados/v1/examples/count", ""}
+	EndpointExampleGet                    = APIEndpoint{"GET", "arvados/v1/examples/{uuid}", ""}
 	EndpointUserActivate                  = APIEndpoint{"POST", "arvados/v1/users/{uuid}/activate", ""}
 	EndpointUserCreate                    = APIEndpoint{"POST", "arvados/v1/users", "user"}
 	EndpointUserCurrent                   = APIEndpoint{"GET", "arvados/v1/users/current", ""}
@@ -174,6 +176,8 @@ type API interface {
 	ContainerDelete(ctx context.Context, options DeleteOptions) (Container, error)
 	ContainerLock(ctx context.Context, options GetOptions) (Container, error)
 	ContainerUnlock(ctx context.Context, options GetOptions) (Container, error)
+	ExampleCount(ctx context.Context, options ExampleCountOptions) (ExampleCountResponse, error)
+	ExampleGet(ctx context.Context, options GetOptions) (Example, error)
 	SpecimenCreate(ctx context.Context, options CreateOptions) (Specimen, error)
 	SpecimenUpdate(ctx context.Context, options UpdateOptions) (Specimen, error)
 	SpecimenGet(ctx context.Context, options GetOptions) (Specimen, error)
diff --git a/sdk/go/arvados/example.go b/sdk/go/arvados/example.go
new file mode 100644
index 000000000..ce8d42a33
--- /dev/null
+++ b/sdk/go/arvados/example.go
@@ -0,0 +1,18 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package arvados
+
+type Example struct {
+	UUID      string `json:"uuid"`
+	HairStyle string `json:"hair_style"`
+}
+
+type ExampleCountOptions struct {
+	ClusterID string `json:"cluster_id"`
+}
+
+type ExampleCountResponse struct {
+	Count int `json:"count"`
+}
diff --git a/sdk/go/arvadostest/api.go b/sdk/go/arvadostest/api.go
index fa5f53936..12357d98e 100644
--- a/sdk/go/arvadostest/api.go
+++ b/sdk/go/arvadostest/api.go
@@ -105,6 +105,14 @@ func (as *APIStub) ContainerUnlock(ctx context.Context, options arvados.GetOptio
 	as.appendCall(as.ContainerUnlock, ctx, options)
 	return arvados.Container{}, as.Error
 }
+func (as *APIStub) ExampleCount(ctx context.Context, options arvados.ExampleCountOptions) (arvados.ExampleCountResponse, error) {
+	as.appendCall(as.ExampleCount, ctx, options)
+	return arvados.ExampleCountResponse{}, as.Error
+}
+func (as *APIStub) ExampleGet(ctx context.Context, options arvados.GetOptions) (arvados.Example, error) {
+	as.appendCall(as.ExampleGet, ctx, options)
+	return arvados.Example{}, as.Error
+}
 func (as *APIStub) SpecimenCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Specimen, error) {
 	as.appendCall(as.SpecimenCreate, ctx, options)
 	return arvados.Specimen{}, as.Error

commit 424910a551a2d564068693babb8058109203f4e5
Author: Tom Clegg <tom at tomclegg.ca>
Date:   Thu Jul 9 10:24:55 2020 -0400

    16534: Get ready to pass parent handle to controllers.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at tomclegg.ca>

diff --git a/lib/controller/localdb/conn.go b/lib/controller/localdb/conn.go
index 60263455b..4f0035edf 100644
--- a/lib/controller/localdb/conn.go
+++ b/lib/controller/localdb/conn.go
@@ -22,11 +22,13 @@ type Conn struct {
 
 func NewConn(cluster *arvados.Cluster) *Conn {
 	railsProxy := railsproxy.NewConn(cluster)
-	return &Conn{
+	var conn Conn
+	conn = Conn{
 		cluster:         cluster,
 		railsProxy:      railsProxy,
 		loginController: chooseLoginController(cluster, railsProxy),
 	}
+	return &conn
 }
 
 func (conn *Conn) Logout(ctx context.Context, opts arvados.LogoutOptions) (arvados.LogoutResponse, error) {

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list