Enable plugin mappers

This commit is contained in:
Chris Roberts 2021-10-25 15:38:33 -07:00 committed by Paul Hinze
parent 038d4b16c3
commit 7595f1533f
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
5 changed files with 24 additions and 12 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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 {

View File

@ -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)

View File

@ -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