[ARVADOS] created: 1.3.0-2753-gbbe1b29a5
Git user
git at public.arvados.org
Tue Jul 7 14:04:09 UTC 2020
at bbe1b29a54c58439f889b81ee7b08cdd2b49ed7d (commit)
commit bbe1b29a54c58439f889b81ee7b08cdd2b49ed7d
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 60263455b..32844cfa9 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 {
@@ -26,9 +28,18 @@ func NewConn(cluster *arvados.Cluster) *Conn {
cluster: cluster,
railsProxy: railsProxy,
loginController: chooseLoginController(cluster, railsProxy),
+ example: example.New(cluster, currenttx),
}
}
+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 ed638fe7e..d4cbf1e2c 100644
--- a/lib/controller/router/router.go
+++ b/lib/controller/router/router.go
@@ -185,6 +185,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 e97a365ad..6bbc96341 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", ""}
@@ -176,6 +178,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
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list