2016-02-09 20:59:05 +00:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"net"
|
2017-01-09 19:21:51 +00:00
|
|
|
"strings"
|
2016-02-09 20:59:05 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/go-plugin"
|
2017-01-09 19:21:51 +00:00
|
|
|
"github.com/hashicorp/logutils"
|
2016-02-09 20:59:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var HandshakeConfig = plugin.HandshakeConfig{
|
|
|
|
ProtocolVersion: 1,
|
|
|
|
MagicCookieKey: "NOMAD_PLUGIN_MAGIC_COOKIE",
|
|
|
|
MagicCookieValue: "e4327c2e01eabfd75a8a67adb114fb34a757d57eee7728d857a8cec6e91a7255",
|
|
|
|
}
|
|
|
|
|
2017-01-09 19:21:51 +00:00
|
|
|
func GetPluginMap(w io.Writer, logLevel string) map[string]plugin.Plugin {
|
2016-02-10 02:24:30 +00:00
|
|
|
e := new(ExecutorPlugin)
|
2017-01-09 19:21:51 +00:00
|
|
|
filter := &logutils.LevelFilter{
|
|
|
|
Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERR"},
|
|
|
|
MinLevel: logutils.LogLevel(strings.ToUpper(logLevel)),
|
2017-01-12 19:50:49 +00:00
|
|
|
Writer: w,
|
2017-01-09 19:21:51 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 19:50:49 +00:00
|
|
|
e.logger = log.New(filter, "", log.LstdFlags|log.Lmicroseconds)
|
2016-02-10 02:24:30 +00:00
|
|
|
|
|
|
|
return map[string]plugin.Plugin{
|
2017-01-12 19:50:49 +00:00
|
|
|
"executor": e,
|
2016-02-10 02:24:30 +00:00
|
|
|
}
|
2016-02-09 20:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExecutorReattachConfig is the config that we seralize and de-serialize and
|
|
|
|
// store in disk
|
|
|
|
type PluginReattachConfig struct {
|
|
|
|
Pid int
|
|
|
|
AddrNet string
|
|
|
|
AddrName string
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginConfig returns a config from an ExecutorReattachConfig
|
|
|
|
func (c *PluginReattachConfig) PluginConfig() *plugin.ReattachConfig {
|
|
|
|
var addr net.Addr
|
|
|
|
switch c.AddrNet {
|
|
|
|
case "unix", "unixgram", "unixpacket":
|
|
|
|
addr, _ = net.ResolveUnixAddr(c.AddrNet, c.AddrName)
|
|
|
|
case "tcp", "tcp4", "tcp6":
|
|
|
|
addr, _ = net.ResolveTCPAddr(c.AddrNet, c.AddrName)
|
|
|
|
}
|
|
|
|
return &plugin.ReattachConfig{Pid: c.Pid, Addr: addr}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPluginReattachConfig(c *plugin.ReattachConfig) *PluginReattachConfig {
|
|
|
|
return &PluginReattachConfig{Pid: c.Pid, AddrNet: c.Addr.Network(), AddrName: c.Addr.String()}
|
|
|
|
}
|