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

Making the API default missing values #2300

Merged
merged 18 commits into from
Feb 21, 2017
Merged

Making the API default missing values #2300

merged 18 commits into from
Feb 21, 2017

Conversation

diptanu
Copy link
Contributor

@diptanu diptanu commented Feb 9, 2017

No description provided.

api/jobs.go Outdated
if p.Spec != nil {
p.SpecType = helper.StringToPtr(PeriodicSpecCron)
}
if p.ProhibitOverlap == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

SpecType?

j.Periodic.Canonicalize()
}

for _, tg := range j.TaskGroups {
Copy link
Contributor

Choose a reason for hiding this comment

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

Break these up into different functions

api/jobs.go Outdated
}
} else {
if task.LogConfig.MaxFiles == nil {
task.LogConfig.MaxFiles = helper.IntToPtr(10)
Copy link
Contributor

Choose a reason for hiding this comment

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

The fields should be handled separately

api/jobs.go Outdated
if task.Vault != nil {
if task.Vault.Env == nil {
task.Vault.Env = helper.BoolToPtr(true)
task.Vault.ChangeMode = helper.StringToPtr("restart")
Copy link
Contributor

Choose a reason for hiding this comment

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

These should be handled separately

Copy link
Contributor

Choose a reason for hiding this comment

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

Handle changemode being signal but signal not being set?

api/jobs_test.go Outdated
_, err := jobs.Validate(job, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
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 failure case

var out structs.JobValidateResponse
if err := s.agent.RPC("Job.Validate", &args, &out); err != nil {

// Fall back to do local validation
Copy link
Contributor

Choose a reason for hiding this comment

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

Set that the driver configs were not validated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default is false, so don't need it.

@@ -111,6 +114,40 @@ func (s *HTTPServer) jobPlan(resp http.ResponseWriter, req *http.Request,
return out, nil
}

func (s *HTTPServer) ValidateJobRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
var validateRequest api.JobValidateRequest
Copy link
Contributor

Choose a reason for hiding this comment

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

Check that the request is PUT/POST

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't be PUT, we should check for POST

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well looks like client.Write sets the method to PUT.

@@ -310,3 +347,86 @@ func (s *HTTPServer) jobDispatchRequest(resp http.ResponseWriter, req *http.Requ
setIndex(resp, out.Index)
return out, nil
}

func (s *HTTPServer) apiJobToStructJob(job *api.Job) *structs.Job {
if job.Priority == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this not api.Canonicalize() and then just setting each field. It is probably also worth adding apiJobToStructJob which calls apiTaskGroupsToStructTaskGroups and so on.

command/plan.go Outdated
@@ -129,12 +112,18 @@ func (c *PlanCommand) Run(args []string) int {
}

// Force the region to be that of the job.
if r := job.Region; r != "" {
if r := *job.Region; r != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be a nil pointer dereference since the API job has not been canonicalized


// JobValidateResponse is the response from validate request
type JobValidateResponse struct {
DriverConfigValidated bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comments

api/jobs.go Outdated
@@ -371,6 +487,11 @@ func (j *Job) AddPeriodicConfig(cfg *PeriodicConfig) *Job {
return j
}

// JobValidateRequest is used to validate a job
type JobValidateRequest struct {
Job *Job
Copy link
Contributor

Choose a reason for hiding this comment

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

WriteRequest?

jobspec/parse.go Outdated
Name: t.Name,
Count: 1,
EphemeralDisk: structs.DefaultEphemeralDisk(),
Tasks: []*structs.Task{t},
EphemeralDisk: &api.EphemeralDisk{SizeMB: 300},
Copy link
Contributor

Choose a reason for hiding this comment

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

Those should be pointers ^ (we decided on all of them being pointers)

jobspec/parse.go Outdated
@@ -317,7 +324,7 @@ func parseGroups(result *structs.Job, list *ast.ObjectList) error {
}

// Parse ephemeral disk
g.EphemeralDisk = structs.DefaultEphemeralDisk()
g.EphemeralDisk = &api.EphemeralDisk{SizeMB: 300}
Copy link
Contributor

Choose a reason for hiding this comment

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

Pointer ^

jobspec/parse.go Outdated
}

// Combine the parsed resources with a default resource block.
min := structs.DefaultResources()
min := &api.Resources{
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a min resources for API

@diptanu diptanu force-pushed the refactor-parser branch 15 times, most recently from 7ee7cad to 57b5fdf Compare February 14, 2017 02:39
if j.JobModifyIndex == nil {
j.JobModifyIndex = helper.Uint64ToPtr(0)
}
if j.Periodic != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar block for update strategy and parameterized?

}
if tmpl.Perms == nil {
tmpl.Perms = helper.StringToPtr("0644")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a case for if *tmpl.ChangeMode == "signal" && tmpl.ChangeSignal == nil { tmpl.ChangeSignal = helper.StringToPtr("SIGHUP") }

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is set upper case the signal

api/tasks.go Outdated
v.ChangeMode = helper.StringToPtr("restart")
}
if v.ChangeSignal == nil {
v.ChangeSignal = helper.StringToPtr("sighup")
Copy link
Contributor

Choose a reason for hiding this comment

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

Capitalize the signal both in that helper and put an else if it is set and upper case it

r.Networks = other.Networks
}
}

type Port struct {
Label string
Copy link
Contributor

Choose a reason for hiding this comment

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

Make these pointers and give a default value to the mbits (10 seems fine)


j.Constraints = make([]*structs.Constraint, len(job.Constraints))
for i, c := range job.Constraints {
j.Constraints[i] = &structs.Constraint{
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be a method so it can be reused

api/tasks.go Outdated
if g.RestartPolicy == nil {
switch jobType {
case "service", "system":
g.RestartPolicy = &RestartPolicy{
Copy link
Contributor

Choose a reason for hiding this comment

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

Make these pointers and add a merge method. Get the default and the user submitted one and merge them


// Check that the job is valid
if err := job.Validate(); err != nil {
if _, _, err := client.Jobs().Validate(job, nil); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Put a warning message in orange if the drivers were not validated

@@ -285,6 +285,25 @@ func (j *Job) Summary(args *structs.JobSummaryRequest,
return j.srv.blockingRPC(&opts)
}

// Validate validates a job
func (j *Job) Validate(args *structs.JobValidateRequest,
Copy link
Contributor

Choose a reason for hiding this comment

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

HTTP documentation

@diptanu diptanu force-pushed the refactor-parser branch 4 times, most recently from 08ae0a4 to e66827b Compare February 14, 2017 23:19
s.parseRegion(req, &args.Region)

var out structs.JobValidateResponse
if err := s.agent.RPC("Job.Validate", &args, &out); err != nil {
Copy link
Member

@schmichael schmichael Feb 15, 2017

Choose a reason for hiding this comment

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

Should we do something with this err even if no other errs happen?

Update: no need!

}
}
} else {
out.ValidationErrors = append(out.ValidationErrors, vErr.Error())
Copy link
Member

Choose a reason for hiding this comment

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

Isn't vErr nil here?

// Fall back to do local validation
args.Job.Canonicalize()
if vErr := args.Job.Validate(); vErr != nil {
if merr, ok := err.(*multierror.Error); ok {
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean vErr here?

jobspec/parse.go Outdated
MaxFiles: helper.IntToPtr(10),
MaxFileSizeMB: helper.IntToPtr(10),
}

Copy link
Member

Choose a reason for hiding this comment

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

Why not use api.DefaultLogConfig()?

@diptanu diptanu force-pushed the refactor-parser branch 4 times, most recently from bd7dbc7 to 14052ed Compare February 15, 2017 21:23
@diptanu diptanu force-pushed the refactor-parser branch 2 times, most recently from fd28fad to a2d7651 Compare February 15, 2017 21:35
@dadgar dadgar merged commit 139bb3d into master Feb 21, 2017
@dadgar dadgar deleted the refactor-parser branch February 21, 2017 00:22
@phinze
Copy link
Contributor

phinze commented Mar 3, 2017

Hi folks!

It seems this PR changes nomad validate to require that an agent be running? Our CI runs nomad validate on our job files - do we need to update it to spin up a local agent for itself after this change?

If all this is accurate, I think we should call this out in the "Backwards Incompatibilities" section of the changelog.

@dadgar
Copy link
Contributor

dadgar commented Mar 3, 2017

@phinze Hey this was not suppose to happen! It was an oversight and 0.5.5 RC2 will restore the original behavior.

@github-actions
Copy link

github-actions bot commented Apr 4, 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 Apr 4, 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.

4 participants