2016-02-10 02:24:30 +00:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/rpc"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-plugin"
|
2016-02-19 21:08:25 +00:00
|
|
|
"github.com/hashicorp/nomad/client/driver/logging"
|
2016-02-10 02:24:30 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SyslogCollectorRPC struct {
|
|
|
|
client *rpc.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
type LaunchCollectorArgs struct {
|
2016-02-19 21:08:25 +00:00
|
|
|
Ctx *logging.LogCollectorContext
|
2016-02-10 02:24:30 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 21:08:25 +00:00
|
|
|
func (e *SyslogCollectorRPC) LaunchCollector(ctx *logging.LogCollectorContext) (*logging.SyslogCollectorState, error) {
|
|
|
|
var ss *logging.SyslogCollectorState
|
2016-02-10 15:52:15 +00:00
|
|
|
err := e.client.Call("Plugin.LaunchCollector", LaunchCollectorArgs{Ctx: ctx}, &ss)
|
2016-02-10 02:24:30 +00:00
|
|
|
return ss, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SyslogCollectorRPC) Exit() error {
|
|
|
|
return e.client.Call("Plugin.Exit", new(interface{}), new(interface{}))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SyslogCollectorRPC) UpdateLogConfig(logConfig *structs.LogConfig) error {
|
|
|
|
return e.client.Call("Plugin.UpdateLogConfig", logConfig, new(interface{}))
|
|
|
|
}
|
|
|
|
|
|
|
|
type SyslogCollectorRPCServer struct {
|
2016-02-19 21:08:25 +00:00
|
|
|
Impl logging.LogCollector
|
2016-02-10 02:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyslogCollectorRPCServer) LaunchCollector(args LaunchCollectorArgs,
|
2016-02-19 21:08:25 +00:00
|
|
|
resp *logging.SyslogCollectorState) error {
|
2016-02-10 15:52:15 +00:00
|
|
|
ss, err := s.Impl.LaunchCollector(args.Ctx)
|
|
|
|
if ss != nil {
|
2016-02-10 02:24:30 +00:00
|
|
|
*resp = *ss
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyslogCollectorRPCServer) Exit(args interface{}, resp *interface{}) error {
|
|
|
|
return s.Impl.Exit()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyslogCollectorRPCServer) UpdateLogConfig(logConfig *structs.LogConfig, resp *interface{}) error {
|
|
|
|
return s.Impl.UpdateLogConfig(logConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
type SyslogCollectorPlugin struct {
|
|
|
|
logger *log.Logger
|
|
|
|
Impl *SyslogCollectorRPCServer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *SyslogCollectorPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
|
|
|
|
if p.Impl == nil {
|
2016-02-19 21:08:25 +00:00
|
|
|
p.Impl = &SyslogCollectorRPCServer{Impl: logging.NewSyslogCollector(p.logger)}
|
2016-02-10 02:24:30 +00:00
|
|
|
}
|
|
|
|
return p.Impl, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *SyslogCollectorPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
|
|
|
|
return &SyslogCollectorRPC{client: c}, nil
|
|
|
|
}
|