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

Allocation autocomplete, client api #2995

Merged
merged 13 commits into from
Aug 14, 2017
Merged

Conversation

chelseakomlo
Copy link
Contributor

This PR introduces two changes:

  1. Autocomplete of nomad alloc-status for allocation ids
  2. API pkg for resource list

One thing to consider is that we use the term resource in #2964, but this term already exists in for machine resources in /api/resources. I used /api/job_resources to differentiate, but let me know if this should be named something differently or included in /api/resources

@chelseakomlo chelseakomlo changed the title Allocation autocomplete, client api WIP- Allocation autocomplete, client api Aug 9, 2017
@chelseakomlo chelseakomlo changed the title WIP- Allocation autocomplete, client api Allocation autocomplete, client api Aug 9, 2017
"github.com/hashicorp/nomad/nomad/structs"
)

type JobResources struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why JobResources and not just Resources. The object can list more than just jobs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that was one thing I wasn't sure about, as currently a resource in the api package is commented as "Resource encapsulates the required resources of a given task or task group."

}

// List returns a list of all resources for a particular context. If a
// context is not specified, matches for all contezts are returned.
Copy link
Contributor

Choose a reason for hiding this comment

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

contezts -> contexts


// List returns a list of all resources for a particular context. If a
// context is not specified, matches for all contezts are returned.
func (j *JobResources) List(prefix string, context string) (*structs.ResourceListResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't want to take or return anything from structs in this package. Create a copy of the ListResponse here.

@@ -73,6 +73,15 @@ func getResourceIter(context, prefix string, ws memdb.WatchSet, state *state.Sta
}
}

// If the length of a string is odd, return a subset of the string to the last
// even character
func roundDownIfOdd(s string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am fine with this if it is a place holder to a slightly more advanced implementation. My concern here is two fold:

  1. Jobs don't need to be rounded, only UUIDs.
  2. If I do a prefix of ab1 and I get a return of: ["ab12..", "ab23...", "ab34", ...] something seems broken :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, understood. So we can round the UUID for the query, and then use a filter function for the remaining character.

var resp structs.ResourceListResponse
req := &structs.ResourceListRequest{Prefix: prefix, Context: context}

_, err := j.client.write("/v1/resources/", req, &resp, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

is /v1/resources a new endpoint?

Copy link
Contributor Author

@chelseakomlo chelseakomlo Aug 10, 2017

Choose a reason for hiding this comment

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

We renamed it to /v1/search in a later commit, but this is a new endpoint.

@chelseakomlo chelseakomlo changed the title Allocation autocomplete, client api WIP: Allocation autocomplete, client api Aug 10, 2017
@chelseakomlo chelseakomlo force-pushed the f-allocation-autocomplete branch 3 times, most recently from 438c137 to 7b6f82e Compare August 10, 2017 20:41
api/search.go Outdated

// List returns a list of matches for a particular context and prefix. If a
// context is not specified, matches for all contexts are returned.
func (s *Search) List(prefix, context string) (*structs.SearchResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

List -> PrefixSearch

api/search.go Outdated
import (
"github.com/hashicorp/nomad/nomad/structs"
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add consts for the various contexts and use them in the commands pkg

Copy link
Contributor Author

@chelseakomlo chelseakomlo Aug 10, 2017

Choose a reason for hiding this comment

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

Definitely. These should live in the api package?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably both where API pkg defines them from structs

if len(prefix)%2 == 0 {
return prefix
}
return prefix[:len(prefix)-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

l := len(prefix)
return prefix[:l-l%2]

continue
}

if !isSubset(prefix, id) {
break
Copy link
Contributor

Choose a reason for hiding this comment

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

break or continue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I caught this after pushing.

@chelseakomlo chelseakomlo force-pushed the f-allocation-autocomplete branch 2 times, most recently from 8518a9a to e59e21a Compare August 11, 2017 21:41
@chelseakomlo chelseakomlo changed the title WIP: Allocation autocomplete, client api Allocation autocomplete, client api Aug 11, 2017
st "github.com/hashicorp/nomad/nomad/structs"
)

// truncateLimit is the maximum number of matches that will be returned for a
Copy link
Contributor

Choose a reason for hiding this comment

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

Put comment over field

Copy link
Contributor

Choose a reason for hiding this comment

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

And below


memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/nomad/nomad/state"
st "github.com/hashicorp/nomad/nomad/structs"
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 keep it as structs. Avoid named imports unless there is a conflict or the name is terribly long

continue
}

if !isSubset(prefix, id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

contexts = []st.Context{args.Context}
}

for _, e := range contexts {
Copy link
Contributor

Choose a reason for hiding this comment

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

e -> context or ctx

@@ -89,6 +89,17 @@ const (
GetterModeDir = "dir"
)

// Context is a type which is searchable via a unique identifier.
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment doesn't make much sense.

Context defines the scope in which a search for Nomad object operates

@chelseakomlo chelseakomlo force-pushed the f-allocation-autocomplete branch 2 times, most recently from cc5a49f to 26c8aea Compare August 14, 2017 14:55
api/search.go Outdated
}

// PrefixSearch returns a list of matches for a particular context and prefix. If a
// context is not specified, matches for all contexts are returned.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Might be worth deleting the last line of the comment since we now assume there will always be a context, just contexts.All

@chelseakomlo chelseakomlo merged commit 49bf7f9 into master Aug 14, 2017
@chelseakomlo chelseakomlo deleted the f-allocation-autocomplete branch August 14, 2017 19:26
@github-actions
Copy link

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 26, 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.

None yet

3 participants