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
}
// DispatchInputConfig configures how a task gets its input from a job dispatch
type DispatchInputConfig struct {
// DispatchPayloadConfig configures how a task gets its input from a job dispatch
type DispatchPayloadConfig struct {
File string
}
// Task is a single process in a task group.
type Task struct {
Name string
Driver string
User string
Config map[string]interface{}
Constraints []*Constraint
Env map[string]string
Services []Service
Resources *Resources
Meta map[string]string
KillTimeout time.Duration
LogConfig *LogConfig
Artifacts []*TaskArtifact
Vault *Vault
Templates []*Template
DispatchInput *DispatchInputConfig
Name string
Driver string
User string
Config map[string]interface{}
Constraints []*Constraint
Env map[string]string
Services []Service
Resources *Resources
Meta map[string]string
KillTimeout time.Duration
LogConfig *LogConfig
Artifacts []*TaskArtifact
Vault *Vault
Templates []*Template
DispatchPayload *DispatchPayloadConfig
}
// 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
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 {
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)
if err != nil {
r.setState(

View File

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

View File

@ -564,7 +564,7 @@ func parseTasks(jobName string, taskGroupName string, result *[]*structs.Task, l
"artifact",
"config",
"constraint",
"dispatch_input",
"dispatch_payload",
"driver",
"env",
"kill_timeout",
@ -587,7 +587,7 @@ func parseTasks(jobName string, taskGroupName string, result *[]*structs.Task, l
delete(m, "artifact")
delete(m, "config")
delete(m, "constraint")
delete(m, "dispatch_input")
delete(m, "dispatch_payload")
delete(m, "env")
delete(m, "logs")
delete(m, "meta")
@ -747,10 +747,10 @@ func parseTasks(jobName string, taskGroupName string, result *[]*structs.Task, l
t.Vault = v
}
// If we have a dispatch_input block parse that
if o := listVal.Filter("dispatch_input"); len(o.Items) > 0 {
// If we have a dispatch_payload block parse that
if o := listVal.Filter("dispatch_payload"); len(o.Items) > 0 {
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{}
dispatchBlock := o.Items[0]
@ -760,15 +760,15 @@ func parseTasks(jobName string, taskGroupName string, result *[]*structs.Task, l
"file",
}
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 {
return err
}
t.DispatchInput = &structs.DispatchInputConfig{}
if err := mapstructure.WeakDecode(m, t.DispatchInput); err != nil {
t.DispatchPayload = &structs.DispatchPayloadConfig{}
if err := mapstructure.WeakDecode(m, t.DispatchPayload); err != nil {
return err
}
}

View File

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

View File

@ -11,7 +11,7 @@ job "parameterized_job" {
driver = "docker"
resources {}
dispatch_input {
dispatch_payload {
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)
}
// Dispatch Input diff
dDiff := primitiveObjectDiff(t.DispatchInput, other.DispatchInput, nil, "DispatchInput", contextual)
// Dispatch payload diff
dDiff := primitiveObjectDiff(t.DispatchPayload, other.DispatchPayload, nil, "DispatchPayload", contextual)
if dDiff != nil {
diff.Objects = append(diff.Objects, dDiff)
}

View File

@ -3666,10 +3666,10 @@ func TestTaskDiff(t *testing.T) {
},
},
{
// DispatchInput added
// DispatchPayload added
Old: &Task{},
New: &Task{
DispatchInput: &DispatchInputConfig{
DispatchPayload: &DispatchPayloadConfig{
File: "foo",
},
},
@ -3678,7 +3678,7 @@ func TestTaskDiff(t *testing.T) {
Objects: []*ObjectDiff{
{
Type: DiffTypeAdded,
Name: "DispatchInput",
Name: "DispatchPayload",
Fields: []*FieldDiff{
{
Type: DiffTypeAdded,
@ -3692,9 +3692,9 @@ func TestTaskDiff(t *testing.T) {
},
},
{
// DispatchInput deleted
// DispatchPayload deleted
Old: &Task{
DispatchInput: &DispatchInputConfig{
DispatchPayload: &DispatchPayloadConfig{
File: "foo",
},
},
@ -3704,7 +3704,7 @@ func TestTaskDiff(t *testing.T) {
Objects: []*ObjectDiff{
{
Type: DiffTypeDeleted,
Name: "DispatchInput",
Name: "DispatchPayload",
Fields: []*FieldDiff{
{
Type: DiffTypeDeleted,
@ -3718,14 +3718,14 @@ func TestTaskDiff(t *testing.T) {
},
},
{
// Dispatch input edited
// Dispatch payload edited
Old: &Task{
DispatchInput: &DispatchInputConfig{
DispatchPayload: &DispatchPayloadConfig{
File: "foo",
},
},
New: &Task{
DispatchInput: &DispatchInputConfig{
DispatchPayload: &DispatchPayloadConfig{
File: "bar",
},
},
@ -3734,7 +3734,7 @@ func TestTaskDiff(t *testing.T) {
Objects: []*ObjectDiff{
{
Type: DiffTypeEdited,
Name: "DispatchInput",
Name: "DispatchPayload",
Fields: []*FieldDiff{
{
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
Contextual: true,
Old: &Task{
DispatchInput: &DispatchInputConfig{
DispatchPayload: &DispatchPayloadConfig{
File: "foo",
},
},
New: &Task{
DispatchInput: &DispatchInputConfig{
DispatchPayload: &DispatchPayloadConfig{
File: "bar",
},
},
@ -3766,7 +3766,7 @@ func TestTaskDiff(t *testing.T) {
Objects: []*ObjectDiff{
{
Type: DiffTypeEdited,
Name: "DispatchInput",
Name: "DispatchPayload",
Fields: []*FieldDiff{
{
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)
}
// DispatchInputConfig configures how a task gets its input from a job dispatch
type DispatchInputConfig struct {
// DispatchPayloadConfig configures how a task gets its input from a job dispatch
type DispatchPayloadConfig struct {
// File specifies a relative path to where the input data should be written
File string
}
func (d *DispatchInputConfig) Copy() *DispatchInputConfig {
func (d *DispatchPayloadConfig) Copy() *DispatchPayloadConfig {
if d == nil {
return nil
}
nd := new(DispatchInputConfig)
nd := new(DispatchPayloadConfig)
*nd = *d
return nd
}
func (d *DispatchInputConfig) Validate() error {
func (d *DispatchPayloadConfig) Validate() error {
// Verify the destination doesn't escape
escaped, err := PathEscapesAllocDir("task/local/", d.File)
if err != nil {
@ -2272,8 +2272,8 @@ type Task struct {
// Resources is the resources needed by this task
Resources *Resources
// DispatchInput configures how the task retrieves its input from a dispatch
DispatchInput *DispatchInputConfig
// DispatchPayload configures how the task retrieves its input from a dispatch
DispatchPayload *DispatchPayloadConfig
// Meta is used to associate arbitrary metadata with this
// task. This is opaque to Nomad.
@ -2312,7 +2312,7 @@ func (t *Task) Copy() *Task {
nt.Vault = nt.Vault.Copy()
nt.Resources = nt.Resources.Copy()
nt.Meta = helper.CopyMapStringString(nt.Meta)
nt.DispatchInput = nt.DispatchInput.Copy()
nt.DispatchPayload = nt.DispatchPayload.Copy()
if t.Artifacts != nil {
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
if t.DispatchInput != nil {
if err := t.DispatchInput.Validate(); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Dispatch Input validation failed: %v", err))
// Validate the dispatch payload block if there
if t.DispatchPayload != nil {
if err := t.DispatchPayload.Validate(); err != nil {
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) {
d := &DispatchInputConfig{
func TestDispatchPayloadConfig_Validate(t *testing.T) {
d := &DispatchPayloadConfig{
File: "foo",
}