Skip to content

Commit

Permalink
Mostly complete support of reading the jobset API.
Browse files Browse the repository at this point in the history
  • Loading branch information
priteau committed Jul 16, 2009
1 parent b064c32 commit 2f38436
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bin/gosen
Expand Up @@ -29,7 +29,14 @@ puts idle_cluster.uid if idle_cluster
puts paradent_13.status.hardware
puts paradent_13.status.system

# TODO: the jobset API should be supported, so that you can submit a 1-hour deploy job with 2 nodes on each cluster like this:
# Example: using the jobset API
me = Gosen::User.new('priteau')
# List all my jobsets
puts me.jobsets.map{ |js| js.name }.join(', ')
# List the job IDs of my first jobset
puts me.jobsets.detect{ |js| js.name == "My First Jobset" }.jobs.map{ |j| j.id }.join(', ')

# TODO: submitting to the jobset API should be supported, so that you can submit a 1-hour deploy job with 2 nodes on each cluster like this:
# grid.sites.each do |site|
# site.clusters.each do |cluster|
# Gosen::Job.new(:cluster => cluster, nodes => 2, walltime => 3600, :type => :deploy)
Expand Down
3 changes: 3 additions & 0 deletions lib/gosen.rb
@@ -1,7 +1,10 @@
require 'gosen/model'
require 'gosen/models/cluster'
require 'gosen/models/grid'
require 'gosen/models/job'
require 'gosen/models/jobset'
require 'gosen/models/node'
require 'gosen/models/reservation'
require 'gosen/models/site'
require 'gosen/models/user'
require 'gosen/session'
37 changes: 37 additions & 0 deletions lib/gosen/models/job.rb
@@ -0,0 +1,37 @@
require 'gosen/model'
require 'json'

module Gosen
class Job
include Model
attr_accessor :resources_uri, :created_at, :uri, :command, :ssh_public_key_uri, :ssh_private_key_uri, :cluster_jobs, :id, :ssh_key_path, :state, :cluster_jobs

def initialize(hash)
@hash = hash
populate_from_hash!(@hash)
@cluster_jobs = []
@hash['cluster_jobs'].each do |cj|
@cluster_jobs.push(Gosen::Job::Cluster.new(cj))
end
end

class Cluster
include Model
attr_accessor :dependencies, :name, :assigned_resources, :scheduledStart, :uri, :command, :walltime, :reservation, :project, :submissionTime, :wanted_resources, :jobType, :events, :id, :cluster, :types, :resubmit_job_id, :startTime, :launchingDirectory, :queue, :assigned_network_address, :cpuset_name, :message, :state, :owner, :properties

def initialize(hash)
fullhash = JSON.parse(Gosen::Session.jobset[hash['uri']].get(:accept => 'application/json'))
populate_from_hash!(fullhash)
@events = []
fullhash['events'].each do |e|
@events.push(Gosen::Job::Cluster::Event.new(e))
end
end

class Event
include Model
attr_accessor :event_id, :date, :type, :to_check, :description, :job_id
end
end
end
end
22 changes: 22 additions & 0 deletions lib/gosen/models/jobset.rb
@@ -0,0 +1,22 @@
require 'gosen/model'
require 'json'

module Gosen
class Jobset
include Model
attr_accessor :user, :name, :uri, :updated_at, :misc, :project, :public_uri, :jobs_uri, :id, :created_at

def initialize(hash)
populate_from_hash!(hash)
end

def jobs
@jobs = []
h = JSON.parse(Gosen::Session.jobset[@jobs_uri].get(:accept => 'application/json'))
h.each do |job|
@jobs.push(Gosen::Job.new(job))
end
return @jobs
end
end
end
25 changes: 25 additions & 0 deletions lib/gosen/models/user.rb
@@ -0,0 +1,25 @@
require 'gosen/model'
require 'json'

module Gosen
class User
attr_reader :login

def initialize(login)
@login = login
end

def uri
"users/#{@login}"
end

def jobsets
@jobsets = []
h = JSON.parse(Gosen::Session.jobset[self.uri]['jobsets'].get(:accept => 'application/json'))
h.each do |jobset|
@jobsets.push(Gosen::Jobset.new(jobset))
end
return @jobsets
end
end
end

0 comments on commit 2f38436

Please sign in to comment.