mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
executor: use grpc instead of netrpc as plugin protocol
* Added protobuf spec for executor * Seperated executor structs into their own package
This commit is contained in:
@@ -265,7 +265,7 @@ func (d *driverPluginClient) TaskStats(taskID string) (*cstructs.TaskResourceUsa
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stats, err := taskStatsFromProto(resp.Stats)
|
||||
stats, err := TaskStatsFromProto(resp.Stats)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ func (b *driverPluginServer) TaskStats(ctx context.Context, req *proto.TaskStats
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pb, err := taskStatsToProto(stats)
|
||||
pb, err := TaskStatsToProto(stats)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encode task stats: %v", err)
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ func taskStatusFromProto(pb *proto.TaskStatus) (*TaskStatus, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func taskStatsToProto(stats *cstructs.TaskResourceUsage) (*proto.TaskStats, error) {
|
||||
func TaskStatsToProto(stats *cstructs.TaskResourceUsage) (*proto.TaskStats, error) {
|
||||
timestamp, err := ptypes.TimestampProto(time.Unix(0, stats.Timestamp))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -391,7 +391,7 @@ func taskStatsToProto(stats *cstructs.TaskResourceUsage) (*proto.TaskStats, erro
|
||||
}, nil
|
||||
}
|
||||
|
||||
func taskStatsFromProto(pb *proto.TaskStats) (*cstructs.TaskResourceUsage, error) {
|
||||
func TaskStatsFromProto(pb *proto.TaskStats) (*cstructs.TaskResourceUsage, error) {
|
||||
timestamp, err := ptypes.Timestamp(pb.Timestamp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/client/taskenv"
|
||||
"github.com/hashicorp/nomad/drivers/shared/executor"
|
||||
estructs "github.com/hashicorp/nomad/drivers/shared/executor/structs"
|
||||
"github.com/hashicorp/nomad/helper/discover"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/plugins/base"
|
||||
@@ -64,7 +64,7 @@ func CgroupsMounted(node *structs.Node) bool {
|
||||
// CreateExecutor launches an executor plugin and returns an instance of the
|
||||
// Executor interface
|
||||
func CreateExecutor(w io.Writer, level hclog.Level, driverConfig *base.ClientDriverConfig,
|
||||
executorConfig *pexecutor.ExecutorConfig) (executor.Executor, *plugin.Client, error) {
|
||||
executorConfig *pexecutor.ExecutorConfig) (estructs.Executor, *plugin.Client, error) {
|
||||
|
||||
c, err := json.Marshal(executorConfig)
|
||||
if err != nil {
|
||||
@@ -80,6 +80,7 @@ func CreateExecutor(w io.Writer, level hclog.Level, driverConfig *base.ClientDri
|
||||
}
|
||||
config.HandshakeConfig = base.Handshake
|
||||
config.Plugins = pexecutor.GetPluginMap(w, level, executorConfig.FSIsolation)
|
||||
config.AllowedProtocols = []plugin.Protocol{plugin.ProtocolGRPC}
|
||||
|
||||
if driverConfig != nil {
|
||||
config.MaxPort = driverConfig.ClientMaxPort
|
||||
@@ -105,17 +106,20 @@ func CreateExecutor(w io.Writer, level hclog.Level, driverConfig *base.ClientDri
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to dispense the executor plugin: %v", err)
|
||||
}
|
||||
executorPlugin := raw.(executor.Executor)
|
||||
executorPlugin := raw.(estructs.Executor)
|
||||
return executorPlugin, executorClient, nil
|
||||
}
|
||||
|
||||
// CreateExecutorWithConfig launches a plugin with a given plugin config
|
||||
func CreateExecutorWithConfig(config *plugin.ClientConfig, w io.Writer) (executor.Executor, *plugin.Client, error) {
|
||||
func CreateExecutorWithConfig(config *plugin.ClientConfig, w io.Writer) (estructs.Executor, *plugin.Client, error) {
|
||||
config.HandshakeConfig = base.Handshake
|
||||
|
||||
// Setting this to DEBUG since the log level at the executor server process
|
||||
// is already set, and this effects only the executor client.
|
||||
// TODO: Use versioned plugin map to support backwards compatability with
|
||||
// existing pre-0.9 executors
|
||||
config.Plugins = pexecutor.GetPluginMap(w, hclog.Debug, false)
|
||||
config.AllowedProtocols = []plugin.Protocol{plugin.ProtocolGRPC}
|
||||
|
||||
executorClient := plugin.NewClient(config)
|
||||
rpcClient, err := executorClient.Client()
|
||||
@@ -127,7 +131,7 @@ func CreateExecutorWithConfig(config *plugin.ClientConfig, w io.Writer) (executo
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to dispense the executor plugin: %v", err)
|
||||
}
|
||||
executorPlugin, ok := raw.(*pexecutor.ExecutorRPC)
|
||||
executorPlugin, ok := raw.(estructs.Executor)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("unexpected executor rpc type: %T", raw)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user