Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dispatched optional meta correctly #4403

Merged
merged 7 commits into from
Jun 11, 2018

Conversation

nickethier
Copy link
Member

This fixes a bug in PR #4262 due to the fact that dispatched jobs never return true for job.IsParameterized thus missing the logic implemented in the PR. The fix was to add a new Dispatched field to the Job struct which is set when a new job is dispatched and not allowed to be mutated from the api.

fixes #3720

New -bash: Dispatch: command not found field is used to denote if the Job is a child dispatched job of
a parameterized job.
@nickethier nickethier force-pushed the b-fix-dispatched-optional-meta branch from a06f5c5 to e325e85 Compare June 11, 2018 16:15
@@ -1327,6 +1325,13 @@ func validateJob(job *structs.Job) (invalid, warnings error) {

// validateJobUpdate ensures updates to a job are valid.
func validateJobUpdate(old, new *structs.Job) error {
if old == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment above saying we are validating a new job

@@ -4343,6 +4381,9 @@ func TestJobEndpoint_Dispatch(t *testing.T) {
if out.ParentID != tc.parameterizedJob.ID {
t.Fatalf("bad parent ID")
}
if !out.Dispatched {
t.Fatal("expected dispatched job")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test that the parameterized stanza is on the job

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1403,6 +1412,7 @@ func (j *Job) Dispatch(args *structs.JobDispatchRequest, reply *structs.JobDispa
dispatchJob.ParentID = parameterizedJob.ID
dispatchJob.Name = dispatchJob.ID
dispatchJob.SetSubmitTime()
dispatchJob.Dispatched = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// if job is parameterized initialize optional meta to empty strings
if alloc.Job.Dispatched {
b.taskMeta = make(map[string]string,
taskMetaSize+(len(alloc.Job.ParameterizedJob.MetaOptional)*2))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract the size into a named variable so reading this is clearer.

@@ -458,6 +458,33 @@ func TestJobEndpoint_Register_ParameterizedJob(t *testing.T) {
}
}

func TestJobEndpoint_Register_Dispatched(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use require for new tests

task := a.Job.TaskGroups[0].Tasks[0]
task.Meta = map[string]string{"metaopt1": "metaopt1val"}
env := NewBuilder(mock.Node(), a, task, "global").Build()
require.Equal(t, "metaopt1val", env.ReplaceEnv("${NOMAD_META_metaopt1}"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other tests, initialize require := require.New(t)


new = mock.Job()
new.Dispatched = true
require.Error(validateJobUpdate(old, new),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally you want to assert the error you are expecting. require.Contains(err.Error(), "foo bar")

@nickethier nickethier merged commit d3e6c10 into master Jun 11, 2018
@nickethier nickethier deleted the b-fix-dispatched-optional-meta branch July 11, 2018 01:31
@github-actions
Copy link

github-actions bot commented Mar 1, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional meta should really be optional
4 participants