Enable plugin mappers
This commit is contained in:
parent
038d4b16c3
commit
7595f1533f
@ -524,7 +524,9 @@ func (b *Basis) Run(ctx context.Context, task *vagrant_server.Task) (err error)
|
||||
fn := cmd.Value.(component.Command).ExecuteFunc(
|
||||
strings.Split(task.CommandName, " "))
|
||||
result, err := b.callDynamicFunc(ctx, b.logger, fn, (*int32)(nil),
|
||||
argmapper.Typed(task.CliArgs, b.jobInfo, b.dir))
|
||||
argmapper.Typed(task.CliArgs, b.jobInfo, b.dir),
|
||||
argmapper.ConverterFunc(cmd.mappers...),
|
||||
)
|
||||
|
||||
if err != nil || result == nil || result.(int32) != 0 {
|
||||
b.logger.Error("failed to execute command",
|
||||
@ -633,7 +635,7 @@ func (b *Basis) component(
|
||||
ServerAddr: b.Client().ServerTarget(),
|
||||
},
|
||||
hooks: hooks,
|
||||
mappers: b.mappers,
|
||||
mappers: append(b.mappers, p.Mappers...),
|
||||
plugin: c,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -286,6 +286,7 @@ func (p *Project) Run(ctx context.Context, task *vagrant_server.Task) (err error
|
||||
strings.Split(task.CommandName, " "))
|
||||
result, err := p.callDynamicFunc(ctx, p.logger, fn, (*int32)(nil),
|
||||
argmapper.Typed(task.CliArgs, p.jobInfo, p.dir),
|
||||
argmapper.ConverterFunc(cmd.mappers...),
|
||||
)
|
||||
|
||||
p.logger.Warn("completed running command from project", "result", result)
|
||||
|
||||
@ -228,6 +228,7 @@ func (t *Target) Run(ctx context.Context, task *vagrant_server.Task) (err error)
|
||||
strings.Split(task.CommandName, " "))
|
||||
result, err := t.callDynamicFunc(ctx, t.logger, fn, (*int32)(nil),
|
||||
argmapper.Typed(task.CliArgs, t.jobInfo, t.dir),
|
||||
argmapper.ConverterFunc(cmd.mappers...),
|
||||
)
|
||||
|
||||
if err != nil || result == nil || result.(int32) != 0 {
|
||||
|
||||
@ -83,12 +83,27 @@ func Factory(
|
||||
return nil, fmt.Errorf("failed to load plugin information interface")
|
||||
}
|
||||
|
||||
mappers, err := pluginclient.Mappers(client)
|
||||
if err != nil {
|
||||
log.Error("error requesting plugin mappers",
|
||||
"error", err,
|
||||
)
|
||||
client.Kill()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Info("collected mappers from plugin",
|
||||
"name", info.Name(),
|
||||
"mappers", mappers,
|
||||
)
|
||||
|
||||
p = &Plugin{
|
||||
Builtin: false,
|
||||
Client: rpcClient,
|
||||
Location: cmd.Path,
|
||||
Name: info.Name(),
|
||||
Types: info.ComponentTypes(),
|
||||
Mappers: mappers,
|
||||
components: map[component.Type]*Instance{},
|
||||
logger: nlog.Named(info.Name()),
|
||||
src: client,
|
||||
@ -103,15 +118,6 @@ func Factory(
|
||||
}
|
||||
}
|
||||
|
||||
// Request the mappers
|
||||
// mappers, err := pluginclient.Mappers(client)
|
||||
// if err != nil {
|
||||
// log.Error("error requesting plugin mappers",
|
||||
// "error", err)
|
||||
// client.Kill()
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// BuiltinFactory creates a factory for a built-in plugin type.
|
||||
func BuiltinFactory(name string) PluginRegistration {
|
||||
cmd := exec.Command(exePath, "plugin-run", name)
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/go-argmapper"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/go-plugin"
|
||||
@ -42,6 +43,7 @@ type Plugin struct {
|
||||
Types []component.Type // Component types supported by this plugin
|
||||
Cache cacher.Cache
|
||||
ParentPlugin *Plugin
|
||||
Mappers []*argmapper.Func
|
||||
|
||||
closers []func() error
|
||||
components map[component.Type]*Instance
|
||||
@ -177,7 +179,7 @@ func (p *Plugin) InstanceOf(
|
||||
i = &Instance{
|
||||
Component: raw,
|
||||
Broker: b.GRPCBroker(),
|
||||
Mappers: nil,
|
||||
Mappers: p.Mappers,
|
||||
}
|
||||
|
||||
// Store the instance for later usage
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user