From cea043c2acd491a85584bdb600b846cc339806cd Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Mar 2021 14:54:27 +0100 Subject: [PATCH] add storage-gateway --- ocis/pkg/runtime/runtime.go | 3 ++- storage/pkg/command/gateway.go | 45 ++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index f9f816871..7500f9ffb 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -44,7 +44,7 @@ var ( "settings", // done "store", // done "storage-metadata", // done - "storage-frontend", + "storage-frontend", // done "storage-gateway", "storage-userprovider", "storage-groupprovider", @@ -128,6 +128,7 @@ func (r *Runtime) Start() error { addServiceToken("web", supervisor.Add(web.NewSutureService(globalCtx, r.c.Web))) addServiceToken("webdav", supervisor.Add(webdav.NewSutureService(globalCtx, r.c.WebDAV))) addServiceToken("frontend", supervisor.Add(storage.NewFrontend(globalCtx, r.c.Storage))) + addServiceToken("gateway", supervisor.Add(storage.NewGateway(globalCtx, r.c.Storage))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index d04966efa..93fb2e76a 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -2,6 +2,7 @@ package command import ( "context" + "flag" "os" "os/signal" "path" @@ -101,8 +102,8 @@ func Gateway(cfg *config.Config) *cli.Command { "storageregistrysvc": cfg.Reva.Gateway.Endpoint, "appregistrysvc": cfg.Reva.Gateway.Endpoint, // user metadata is located on the users services - "preferencessvc": cfg.Reva.Users.Endpoint, - "userprovidersvc": cfg.Reva.Users.Endpoint, + "preferencessvc": cfg.Reva.Users.Endpoint, + "userprovidersvc": cfg.Reva.Users.Endpoint, "groupprovidersvc": cfg.Reva.Groups.Endpoint, // sharing is located on the sharing service "usershareprovidersvc": cfg.Reva.Sharing.Endpoint, @@ -255,3 +256,43 @@ func rules(cfg *config.Config) map[string]interface{} { // medatada storage not part of the global namespace } } + +// GatewaySutureService allows for the storage-gateway command to be embedded and supervised by a suture supervisor tree. +type GatewaySutureService struct { + ctx context.Context + cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service. + cfg *config.Config +} + +// NewGatewaySutureService creates a new gateway.GatewaySutureService +func NewGateway(ctx context.Context, cfg *config.Config) GatewaySutureService { + sctx, cancel := context.WithCancel(ctx) + cfg.Context = sctx + return GatewaySutureService{ + ctx: sctx, + cancel: cancel, + cfg: cfg, + } +} + +func (s GatewaySutureService) Serve() { + f := &flag.FlagSet{} + for k := range Gateway(s.cfg).Flags { + if err := Gateway(s.cfg).Flags[k].Apply(f); err != nil { + return + } + } + ctx := cli.NewContext(nil, f, nil) + if Gateway(s.cfg).Before != nil { + if err := Gateway(s.cfg).Before(ctx); err != nil { + return + } + } + if err := Gateway(s.cfg).Action(ctx); err != nil { + return + } +} + +func (s GatewaySutureService) Stop() { + s.cancel() +}