cherrypick extensions to start v1

This commit is contained in:
A.Unger
2021-06-29 15:28:19 +02:00
parent f02f2a3d42
commit 2e28582c1b
34 changed files with 156 additions and 4 deletions
+42 -2
View File
@@ -22,6 +22,7 @@ import (
graphExplorer "github.com/owncloud/ocis/graph-explorer/pkg/command"
graph "github.com/owncloud/ocis/graph/pkg/command"
idp "github.com/owncloud/ocis/idp/pkg/command"
"github.com/owncloud/ocis/ocis-pkg/config"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
ocs "github.com/owncloud/ocis/ocs/pkg/command"
@@ -37,6 +38,11 @@ import (
"github.com/thejerf/suture/v4"
)
var (
// runset keeps track of which extensions to start supervised.
runset []string
)
// Service represents a RPC service.
type Service struct {
Supervisor *suture.Supervisor
@@ -180,7 +186,18 @@ func Start(o ...Option) error {
}
}()
for name := range s.ServicesRegistry {
// prepare runset
s.generateRunSet(s.cfg)
for _, name := range runset {
// skip delayed services for now
if _, ok := s.Delayed[name]; ok {
continue
}
// we do this so each service has its own copy. In a perfect world a config object should NOT be edited by
// the callers because this might trigger behavioral changes up the tree.
swap := deepcopy.Copy(s.cfg)
s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.ServicesRegistry[name](swap.(*ociscfg.Config))))
}
@@ -198,7 +215,12 @@ func Start(o ...Option) error {
time.Sleep(1 * time.Second)
// add services with delayed execution.
for name := range s.Delayed {
for _, name := range runset {
// this time around only run delayed jobs
if _, ok := s.Delayed[name]; !ok {
continue
}
swap := deepcopy.Copy(s.cfg)
s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.Delayed[name](swap.(*ociscfg.Config))))
}
@@ -206,6 +228,24 @@ func Start(o ...Option) error {
return http.Serve(l, nil)
}
func (s *Service) generateRunSet(cfg *config.Config) {
if cfg.Runtime.Extensions != "" {
e := strings.Split(strings.Replace(cfg.Runtime.Extensions, " ", "", -1), ",")
for i := range e {
runset = append(runset, e[i])
}
return
}
for name := range s.ServicesRegistry {
runset = append(runset, name)
}
for name := range s.Delayed {
runset = append(runset, name)
}
}
// Start indicates the Service Controller to start a new supervised service as an OS thread.
func (s *Service) Start(name string, reply *int) error {
// RPC calls to a Service object will allow for parsing config. Mind that since the runtime is running on a different