Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/nomad/api/allocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ def read(id, **options)
json = client.get("/v1/allocation/#{CGI.escape(id)}", options)
return Alloc.decode(json)
end

# Read all allocations for a given job
#
# @param [String] job_id The Job ID of the job
#
# @return Array<Alloc>
def for_job(job_id, **options)
json = client.get("/v1/job/#{CGI.escape(job_id)}/allocations", options)
return json.map do |alloc_json|
Alloc.decode(alloc_json)
end
end
end

class Alloc < Response
Expand Down
10 changes: 10 additions & 0 deletions spec/integration/api/allocation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,15 @@ module Nomad
expect(result.task_states).to be_a(Hash)
end
end

describe "#for_job" do
it "reads allocations for a specific job" do
result = subject.for_job "job"
expect(result).to be
expect(result).to be_a(Array)
expect(result.count).to eq(3)
expect(result.first).to be_a(Alloc)
end
end
end
end