Rename dispatch_input to dispatch_payload

This commit is contained in:
Alex Dadgar 2017-01-25 21:06:16 -08:00
parent 4cfeefd4a5
commit 8196a58c4c
10 changed files with 60 additions and 60 deletions

View File

@ -141,28 +141,28 @@ type LogConfig struct {
MaxFileSizeMB int MaxFileSizeMB int
} }
// DispatchInputConfig configures how a task gets its input from a job dispatch // DispatchPayloadConfig configures how a task gets its input from a job dispatch
type DispatchInputConfig struct { type DispatchPayloadConfig struct {
File string File string
} }
// Task is a single process in a task group. // Task is a single process in a task group.
type Task struct { type Task struct {
Name string Name string
Driver string Driver string
User string User string
Config map[string]interface{} Config map[string]interface{}
Constraints []*Constraint Constraints []*Constraint
Env map[string]string Env map[string]string
Services []Service Services []Service
Resources *Resources Resources *Resources
Meta map[string]string Meta map[string]string
KillTimeout time.Duration KillTimeout time.Duration
LogConfig *LogConfig LogConfig *LogConfig
Artifacts []*TaskArtifact Artifacts []*TaskArtifact
Vault *Vault Vault *Vault
Templates []*Template Templates []*Template
DispatchInput *DispatchInputConfig DispatchPayload *DispatchPayloadConfig
} }
// TaskArtifact is used to download artifacts before running a task. // TaskArtifact is used to download artifacts before running a task.

View File

@ -753,9 +753,9 @@ func (r *TaskRunner) prestart(resultCh chan bool) {
// If the job is a dispatch job and there is a payload write it to disk // If the job is a dispatch job and there is a payload write it to disk
requirePayload := len(r.alloc.Job.Payload) != 0 && requirePayload := len(r.alloc.Job.Payload) != 0 &&
(r.task.DispatchInput != nil && r.task.DispatchInput.File != "") (r.task.DispatchPayload != nil && r.task.DispatchPayload.File != "")
if !r.payloadRendered && requirePayload { if !r.payloadRendered && requirePayload {
renderTo := filepath.Join(r.taskDir.LocalDir, r.task.DispatchInput.File) renderTo := filepath.Join(r.taskDir.LocalDir, r.task.DispatchPayload.File)
decoded, err := snappy.Decode(nil, r.alloc.Job.Payload) decoded, err := snappy.Decode(nil, r.alloc.Job.Payload)
if err != nil { if err != nil {
r.setState( r.setState(

View File

@ -1232,7 +1232,7 @@ func TestTaskRunner_SimpleRun_Dispatch(t *testing.T) {
"run_for": "1s", "run_for": "1s",
} }
fileName := "test" fileName := "test"
task.DispatchInput = &structs.DispatchInputConfig{ task.DispatchPayload = &structs.DispatchPayloadConfig{
File: fileName, File: fileName,
} }
alloc.Job.ParameterizedJob = &structs.ParameterizedJobConfig{} alloc.Job.ParameterizedJob = &structs.ParameterizedJobConfig{}

View File

@ -564,7 +564,7 @@ func parseTasks(jobName string, taskGroupName string, result *[]*structs.Task, l
"artifact", "artifact",
"config", "config",
"constraint", "constraint",
"dispatch_input", "dispatch_payload",
"driver", "driver",
"env", "env",
"kill_timeout", "kill_timeout",
@ -587,7 +587,7 @@ func parseTasks(jobName string, taskGroupName string, result *[]*structs.Task, l
delete(m, "artifact") delete(m, "artifact")
delete(m, "config") delete(m, "config")
delete(m, "constraint") delete(m, "constraint")
delete(m, "dispatch_input") delete(m, "dispatch_payload")
delete(m, "env") delete(m, "env")
delete(m, "logs") delete(m, "logs")
delete(m, "meta") delete(m, "meta")
@ -747,10 +747,10 @@ func parseTasks(jobName string, taskGroupName string, result *[]*structs.Task, l
t.Vault = v t.Vault = v
} }
// If we have a dispatch_input block parse that // If we have a dispatch_payload block parse that
if o := listVal.Filter("dispatch_input"); len(o.Items) > 0 { if o := listVal.Filter("dispatch_payload"); len(o.Items) > 0 {
if len(o.Items) > 1 { if len(o.Items) > 1 {
return fmt.Errorf("only one dispatch_input block is allowed in a task. Number of dispatch_input blocks found: %d", len(o.Items)) return fmt.Errorf("only one dispatch_payload block is allowed in a task. Number of dispatch_payload blocks found: %d", len(o.Items))
} }
var m map[string]interface{} var m map[string]interface{}
dispatchBlock := o.Items[0] dispatchBlock := o.Items[0]
@ -760,15 +760,15 @@ func parseTasks(jobName string, taskGroupName string, result *[]*structs.Task, l
"file", "file",
} }
if err := checkHCLKeys(dispatchBlock.Val, valid); err != nil { if err := checkHCLKeys(dispatchBlock.Val, valid); err != nil {
return multierror.Prefix(err, fmt.Sprintf("'%s', dispatch_input ->", n)) return multierror.Prefix(err, fmt.Sprintf("'%s', dispatch_payload ->", n))
} }
if err := hcl.DecodeObject(&m, dispatchBlock.Val); err != nil { if err := hcl.DecodeObject(&m, dispatchBlock.Val); err != nil {
return err return err
} }
t.DispatchInput = &structs.DispatchInputConfig{} t.DispatchPayload = &structs.DispatchPayloadConfig{}
if err := mapstructure.WeakDecode(m, t.DispatchInput); err != nil { if err := mapstructure.WeakDecode(m, t.DispatchPayload); err != nil {
return err return err
} }
} }

View File

@ -571,7 +571,7 @@ func TestParse(t *testing.T) {
MaxFiles: 10, MaxFiles: 10,
MaxFileSizeMB: 10, MaxFileSizeMB: 10,
}, },
DispatchInput: &structs.DispatchInputConfig{ DispatchPayload: &structs.DispatchPayloadConfig{
File: "foo/bar", File: "foo/bar",
}, },
}, },

View File

@ -11,7 +11,7 @@ job "parameterized_job" {
driver = "docker" driver = "docker"
resources {} resources {}
dispatch_input { dispatch_payload {
file = "foo/bar" file = "foo/bar"
} }
} }

View File

@ -375,8 +375,8 @@ func (t *Task) Diff(other *Task, contextual bool) (*TaskDiff, error) {
diff.Objects = append(diff.Objects, lDiff) diff.Objects = append(diff.Objects, lDiff)
} }
// Dispatch Input diff // Dispatch payload diff
dDiff := primitiveObjectDiff(t.DispatchInput, other.DispatchInput, nil, "DispatchInput", contextual) dDiff := primitiveObjectDiff(t.DispatchPayload, other.DispatchPayload, nil, "DispatchPayload", contextual)
if dDiff != nil { if dDiff != nil {
diff.Objects = append(diff.Objects, dDiff) diff.Objects = append(diff.Objects, dDiff)
} }

View File

@ -3666,10 +3666,10 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// DispatchInput added // DispatchPayload added
Old: &Task{}, Old: &Task{},
New: &Task{ New: &Task{
DispatchInput: &DispatchInputConfig{ DispatchPayload: &DispatchPayloadConfig{
File: "foo", File: "foo",
}, },
}, },
@ -3678,7 +3678,7 @@ func TestTaskDiff(t *testing.T) {
Objects: []*ObjectDiff{ Objects: []*ObjectDiff{
{ {
Type: DiffTypeAdded, Type: DiffTypeAdded,
Name: "DispatchInput", Name: "DispatchPayload",
Fields: []*FieldDiff{ Fields: []*FieldDiff{
{ {
Type: DiffTypeAdded, Type: DiffTypeAdded,
@ -3692,9 +3692,9 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// DispatchInput deleted // DispatchPayload deleted
Old: &Task{ Old: &Task{
DispatchInput: &DispatchInputConfig{ DispatchPayload: &DispatchPayloadConfig{
File: "foo", File: "foo",
}, },
}, },
@ -3704,7 +3704,7 @@ func TestTaskDiff(t *testing.T) {
Objects: []*ObjectDiff{ Objects: []*ObjectDiff{
{ {
Type: DiffTypeDeleted, Type: DiffTypeDeleted,
Name: "DispatchInput", Name: "DispatchPayload",
Fields: []*FieldDiff{ Fields: []*FieldDiff{
{ {
Type: DiffTypeDeleted, Type: DiffTypeDeleted,
@ -3718,14 +3718,14 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Dispatch input edited // Dispatch payload edited
Old: &Task{ Old: &Task{
DispatchInput: &DispatchInputConfig{ DispatchPayload: &DispatchPayloadConfig{
File: "foo", File: "foo",
}, },
}, },
New: &Task{ New: &Task{
DispatchInput: &DispatchInputConfig{ DispatchPayload: &DispatchPayloadConfig{
File: "bar", File: "bar",
}, },
}, },
@ -3734,7 +3734,7 @@ func TestTaskDiff(t *testing.T) {
Objects: []*ObjectDiff{ Objects: []*ObjectDiff{
{ {
Type: DiffTypeEdited, Type: DiffTypeEdited,
Name: "DispatchInput", Name: "DispatchPayload",
Fields: []*FieldDiff{ Fields: []*FieldDiff{
{ {
Type: DiffTypeEdited, Type: DiffTypeEdited,
@ -3748,16 +3748,16 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// DispatchInput edited with context. Place holder for if more // DispatchPayload edited with context. Place holder for if more
// fields are added // fields are added
Contextual: true, Contextual: true,
Old: &Task{ Old: &Task{
DispatchInput: &DispatchInputConfig{ DispatchPayload: &DispatchPayloadConfig{
File: "foo", File: "foo",
}, },
}, },
New: &Task{ New: &Task{
DispatchInput: &DispatchInputConfig{ DispatchPayload: &DispatchPayloadConfig{
File: "bar", File: "bar",
}, },
}, },
@ -3766,7 +3766,7 @@ func TestTaskDiff(t *testing.T) {
Objects: []*ObjectDiff{ Objects: []*ObjectDiff{
{ {
Type: DiffTypeEdited, Type: DiffTypeEdited,
Name: "DispatchInput", Name: "DispatchPayload",
Fields: []*FieldDiff{ Fields: []*FieldDiff{
{ {
Type: DiffTypeEdited, Type: DiffTypeEdited,

View File

@ -1694,22 +1694,22 @@ func DispatchedID(templateID string, t time.Time) string {
return fmt.Sprintf("%s%s%d-%s", templateID, DispatchLaunchSuffix, t.Unix(), u) return fmt.Sprintf("%s%s%d-%s", templateID, DispatchLaunchSuffix, t.Unix(), u)
} }
// DispatchInputConfig configures how a task gets its input from a job dispatch // DispatchPayloadConfig configures how a task gets its input from a job dispatch
type DispatchInputConfig struct { type DispatchPayloadConfig struct {
// File specifies a relative path to where the input data should be written // File specifies a relative path to where the input data should be written
File string File string
} }
func (d *DispatchInputConfig) Copy() *DispatchInputConfig { func (d *DispatchPayloadConfig) Copy() *DispatchPayloadConfig {
if d == nil { if d == nil {
return nil return nil
} }
nd := new(DispatchInputConfig) nd := new(DispatchPayloadConfig)
*nd = *d *nd = *d
return nd return nd
} }
func (d *DispatchInputConfig) Validate() error { func (d *DispatchPayloadConfig) Validate() error {
// Verify the destination doesn't escape // Verify the destination doesn't escape
escaped, err := PathEscapesAllocDir("task/local/", d.File) escaped, err := PathEscapesAllocDir("task/local/", d.File)
if err != nil { if err != nil {
@ -2272,8 +2272,8 @@ type Task struct {
// Resources is the resources needed by this task // Resources is the resources needed by this task
Resources *Resources Resources *Resources
// DispatchInput configures how the task retrieves its input from a dispatch // DispatchPayload configures how the task retrieves its input from a dispatch
DispatchInput *DispatchInputConfig DispatchPayload *DispatchPayloadConfig
// Meta is used to associate arbitrary metadata with this // Meta is used to associate arbitrary metadata with this
// task. This is opaque to Nomad. // task. This is opaque to Nomad.
@ -2312,7 +2312,7 @@ func (t *Task) Copy() *Task {
nt.Vault = nt.Vault.Copy() nt.Vault = nt.Vault.Copy()
nt.Resources = nt.Resources.Copy() nt.Resources = nt.Resources.Copy()
nt.Meta = helper.CopyMapStringString(nt.Meta) nt.Meta = helper.CopyMapStringString(nt.Meta)
nt.DispatchInput = nt.DispatchInput.Copy() nt.DispatchPayload = nt.DispatchPayload.Copy()
if t.Artifacts != nil { if t.Artifacts != nil {
artifacts := make([]*TaskArtifact, 0, len(t.Artifacts)) artifacts := make([]*TaskArtifact, 0, len(t.Artifacts))
@ -2477,10 +2477,10 @@ func (t *Task) Validate(ephemeralDisk *EphemeralDisk) error {
} }
} }
// Validate the dispatch input block if there // Validate the dispatch payload block if there
if t.DispatchInput != nil { if t.DispatchPayload != nil {
if err := t.DispatchInput.Validate(); err != nil { if err := t.DispatchPayload.Validate(); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Dispatch Input validation failed: %v", err)) mErr.Errors = append(mErr.Errors, fmt.Errorf("Dispatch Payload validation failed: %v", err))
} }
} }

View File

@ -1518,8 +1518,8 @@ func TestParameterizedJobConfig_Canonicalize(t *testing.T) {
} }
} }
func TestDispatchInputConfig_Validate(t *testing.T) { func TestDispatchPayloadConfig_Validate(t *testing.T) {
d := &DispatchInputConfig{ d := &DispatchPayloadConfig{
File: "foo", File: "foo",
} }