Setup plugin ids and dependencies
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -13,10 +13,18 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
plugin.Register("containers-grpc", &plugin.Registration{
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "containers",
|
||||
Requires: []plugin.PluginType{
|
||||
plugin.MetadataPlugin,
|
||||
},
|
||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
return NewService(ic.Meta), nil
|
||||
m, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewService(m.(*bolt.DB)), nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,15 +30,23 @@ var bufPool = sync.Pool{
|
||||
var _ api.ContentServer = &Service{}
|
||||
|
||||
func init() {
|
||||
plugin.Register("content-grpc", &plugin.Registration{
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "content",
|
||||
Requires: []plugin.PluginType{
|
||||
plugin.ContentPlugin,
|
||||
},
|
||||
Init: NewService,
|
||||
})
|
||||
}
|
||||
|
||||
func NewService(ic *plugin.InitContext) (interface{}, error) {
|
||||
c, err := ic.Get(plugin.ContentPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Service{
|
||||
store: ic.Content,
|
||||
store: c.(content.Store),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,19 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
plugin.Register("diff-grpc", &plugin.Registration{
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "diff",
|
||||
Requires: []plugin.PluginType{
|
||||
plugin.DiffPlugin,
|
||||
},
|
||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
d, err := ic.Get(plugin.DiffPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &service{
|
||||
diff: ic.Differ,
|
||||
diff: d.(plugin.Differ),
|
||||
}, nil
|
||||
},
|
||||
})
|
||||
|
||||
@@ -35,22 +35,45 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
plugin.Register("tasks-grpc", &plugin.Registration{
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "tasks",
|
||||
Requires: []plugin.PluginType{
|
||||
plugin.RuntimePlugin,
|
||||
plugin.MetadataPlugin,
|
||||
plugin.ContentPlugin,
|
||||
},
|
||||
Init: New,
|
||||
})
|
||||
}
|
||||
|
||||
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
c, err := newCollector(ic.Context, ic.Runtimes)
|
||||
rt, err := ic.GetAll(plugin.RuntimePlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ct, err := ic.Get(plugin.ContentPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
runtimes := make(map[string]plugin.Runtime)
|
||||
for _, rr := range rt {
|
||||
r := rr.(plugin.Runtime)
|
||||
runtimes[r.ID()] = r
|
||||
}
|
||||
c, err := newCollector(ic.Context, runtimes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Service{
|
||||
runtimes: ic.Runtimes,
|
||||
db: ic.Meta,
|
||||
runtimes: runtimes,
|
||||
db: m.(*bolt.DB),
|
||||
collector: c,
|
||||
store: ic.Content,
|
||||
store: ct.(content.Store),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -461,7 +484,7 @@ func (s *Service) getTask(ctx context.Context, id string) (plugin.Task, error) {
|
||||
func (s *Service) getRuntime(name string) (plugin.Runtime, error) {
|
||||
runtime, ok := s.runtimes[name]
|
||||
if !ok {
|
||||
return nil, plugin.ErrUnknownRuntime
|
||||
return nil, fmt.Errorf("unknown runtime %q", name)
|
||||
}
|
||||
return runtime, nil
|
||||
}
|
||||
|
||||
@@ -13,8 +13,9 @@ type Service struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
plugin.Register("healthcheck-grpc", &plugin.Registration{
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "healthcheck",
|
||||
Init: NewService,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -12,10 +12,18 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
plugin.Register("images-grpc", &plugin.Registration{
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "images",
|
||||
Requires: []plugin.PluginType{
|
||||
plugin.MetadataPlugin,
|
||||
},
|
||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
return NewService(ic.Meta), nil
|
||||
m, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewService(m.(*bolt.DB)), nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,10 +15,18 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
plugin.Register("namespaces-grpc", &plugin.Registration{
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "namespaces",
|
||||
Requires: []plugin.PluginType{
|
||||
plugin.MetadataPlugin,
|
||||
},
|
||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
return NewService(ic.Meta), nil
|
||||
m, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewService(m.(*bolt.DB)), nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,10 +16,18 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
plugin.Register("snapshots-grpc", &plugin.Registration{
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "snapshots",
|
||||
Requires: []plugin.PluginType{
|
||||
plugin.SnapshotPlugin,
|
||||
},
|
||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
return newService(ic.Snapshotter)
|
||||
s, err := ic.Get(plugin.SnapshotPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newService(s.(snapshot.Snapshotter))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -12,8 +12,9 @@ import (
|
||||
var _ api.VersionServer = &Service{}
|
||||
|
||||
func init() {
|
||||
plugin.Register("version-grpc", &plugin.Registration{
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "version",
|
||||
Init: New,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user