pbs 1.1.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,73 +1,190 @@
1
- require "ffi"
1
+ require 'ffi'
2
2
 
3
3
  module PBS
4
+ # An interface to the C-library of Torque
4
5
  module Torque
5
6
  extend FFI::Library
6
7
 
7
- # Define torque methods using a supplied library
8
- def self.init(args = {})
9
- @@lib = args[:lib] || "torque"
8
+ # @!attribute [rw] self.pbs_errno
9
+ # The internal PBS error number
10
+ # int pbs_errno
11
+ # @return [Fixnum] pbs error number
10
12
 
11
- # Set up FFI to use this library
12
- ffi_lib @@lib
13
+ # @!attribute [r] self.pbs_server
14
+ # The PBS server name
15
+ # char *pbs_server
16
+ # @return [String] pbs server name
13
17
 
14
- # int pbs_errno
15
- attach_variable :pbs_errno, :int
18
+ # @!method self.pbs_strerror(errno)
19
+ # Generates PBS error string from given error number
20
+ # char *pbs_strerror(int errno)
21
+ # @param errno [Fixnum] pbs error number
22
+ # @return [String] pbs error string
16
23
 
17
- # char *pbs_server
18
- attach_variable :pbs_server, :string
24
+ # @!method self.pbs_default
25
+ # Default PBS server name
26
+ # char *pbs_default(void)
27
+ # @see http://linux.die.net/man/3/pbs_default
28
+ # @return [String] default pbs server name
19
29
 
20
- # int pbs_connect(char *server)
21
- attach_function :pbs_connect, [ :pointer ], :int
30
+ # @!method self.pbs_connect(server)
31
+ # Connect to PBS batch server
32
+ # int pbs_connect(char *server)
33
+ # @see http://linux.die.net/man/3/pbs_connect
34
+ # @param server [String] name of pbs server
35
+ # @return [Fixnum] connection identifier
22
36
 
23
- # char *pbs_default(void)
24
- attach_function :pbs_default, [], :string
37
+ # @!method self.pbs_disconnect(connect)
38
+ # Disconnect from a PBS batch server
39
+ # int pbs_disconnect(int connect)
40
+ # @see http://linux.die.net/man/3/pbs_disconnect
41
+ # @param connect [Fixnum] connection identifier
42
+ # @return [Fixnum] exit status code
25
43
 
26
- # char *pbs_strerror(int errno)
27
- attach_function :pbs_strerror, [ :int ], :string
44
+ # @!method self.pbs_deljob(connect, job_id, extend)
45
+ # Delete a PBS batch job
46
+ # int pbs_deljob(int connect, char *job_id, char *extend)
47
+ # @see http://linux.die.net/man/3/pbs_deljob
48
+ # @param connect [Fixnum] connection identifier
49
+ # @param job_id [String] the job id
50
+ # @param extend [String] implementation defined extensions
51
+ # @return [Fixnum] exit status code
28
52
 
29
- # int pbs_deljob(int connect, char *job_id, char *extend)
30
- attach_function :pbs_deljob, [ :int, :pointer, :pointer ], :int
53
+ # @!method self.pbs_holdjob(connect, job_id, hold_type, extend)
54
+ # Place a hold on a PBS batch job
55
+ # int pbs_holdjob(int connect, char *job_id, char *hold_type, char *extend)
56
+ # @see http://linux.die.net/man/3/pbs_holdjob
57
+ # @param connect [Fixnum] connection identifier
58
+ # @param job_id [String] the job id
59
+ # @param hold_type [String] type of hold to be applied
60
+ # @param extend [String] implementation defined extensions
61
+ # @return [Fixnum] exit status code
31
62
 
32
- # int pbs_disconnect(int connect)
33
- attach_function :pbs_disconnect, [ :int ], :int
63
+ # @!method self.pbs_rlsjob(connect, job_id, hold_type, extend)
64
+ # Release a hold on a PBS batch job
65
+ # int pbs_rlsjob(int connect, char *job_id, char *hold_type, char *extend)
66
+ # @see http://linux.die.net/man/3/pbs_rlsjob
67
+ # @param connect [Fixnum] connection identifier
68
+ # @param job_id [String] the job id
69
+ # @param hold_type [String] type of hold to be released
70
+ # @param extend [String] implementation defined extensions
71
+ # @return [Fixnum] exit status code
34
72
 
35
- # int pbs_holdjob(int connect, char *job_id, char *hold_type, char *extend)
36
- attach_function :pbs_holdjob, [ :int, :pointer, :pointer, :pointer ], :int
73
+ # @!method self.pbs_statfree(stat)
74
+ # Free the memory allocated by {BatchStatus} object
75
+ # void pbs_statfree(struct batch_status *stat)
76
+ # @param stat [BatchStatus] the batch status object
77
+ # @return [void]
37
78
 
38
- # int pbs_rlsjob(int connect, char *job_id, char *hold_type, char *extend)
39
- attach_function :pbs_rlsjob, [ :int, :pointer, :pointer, :pointer ], :int
79
+ # @!method self.pbs_statjob(connect, id, attrib, extend)
80
+ # Obtain status of PBS batch jobs
81
+ # batch_status * pbs_statjob(int connect, char *id, struct attrl *attrib, char *extend)
82
+ # @see http://linux.die.net/man/3/pbs_statjob
83
+ # @param connect [Fixnum] connection identifier
84
+ # @param id [String] job or destination identifier
85
+ # @param attrib [Attrl] the attribute c-linked list object
86
+ # @param extend [String] implementation defined extensions
87
+ # @return [BatchStatus] c-linked list of batch status objects
88
+ # @note It is up to the user to free the space of the batch status objects
40
89
 
41
- # void pbs_statfree(struct batch_status *stat)
42
- attach_function :pbs_statfree, [ :pointer ], :void
90
+ # @!method self.pbs_statnode(connect, id, attrib, extend)
91
+ # Obtain status of PBS nodes
92
+ # batch_status * pbs_statnode(int connect, char *id, struct attrl *attrib, char *extend)
93
+ # @see http://linux.die.net/man/3/pbs_statnode
94
+ # @param connect [Fixnum] connection identifier
95
+ # @param id [String] name of a node or null string
96
+ # @param attrib [Attrl] the attribute c-linked list object
97
+ # @param extend [String] implementation defined extensions
98
+ # @return [BatchStatus] c-linked list of batch status objects
99
+ # @note It is up to the user to free the space of the batch status objects
43
100
 
44
- # batch_status * pbs_statjob(int connect, char *id, struct attrl *attrib, char *extend)
45
- attach_function :pbs_statjob, [ :int, :pointer, :pointer, :pointer ], BatchStatus.ptr
101
+ # @!method self.pbs_statque(connect, id, attrib, extend)
102
+ # Obtain status of PBS batch queues
103
+ # batch_status * pbs_statque(int connect, char *id, struct attrl *attrib, char *extend)
104
+ # @see http://linux.die.net/man/3/pbs_statque
105
+ # @param connect [Fixnum] connection identifier
106
+ # @param id [String] name of a queue or null string
107
+ # @param attrib [Attrl] the attribute c-linked list object
108
+ # @param extend [String] implementation defined extensions
109
+ # @return [BatchStatus] c-linked list of batch status objects
110
+ # @note It is up to the user to free the space of the batch status objects
46
111
 
47
- # batch_status * pbs_statnode(int connect, char *id, struct attrl *attrib, char *extend)
48
- attach_function :pbs_statnode, [ :int, :pointer, :pointer, :pointer ], BatchStatus.ptr
112
+ # @!method self.pbs_statserver(connect, attrib, extend)
113
+ # Obtain status of a PBS batch server
114
+ # batch_status * pbs_statserver(int connect, struct attrl *attrib, char *extend)
115
+ # @see http://linux.die.net/man/3/pbs_statserver
116
+ # @param connect [Fixnum] connection identifier
117
+ # @param attrib [Attrl] the attribute c-linked list object
118
+ # @param extend [String] implementation defined extensions
119
+ # @return [BatchStatus] c-linked list of batch status objects
120
+ # @note It is up to the user to free the space of the batch status objects
49
121
 
50
- # batch_status * pbs_statque(int connect, char *id, struct attrl *attrib, char *extend)
51
- attach_function :pbs_statque, [ :int, :pointer, :pointer, :pointer ], BatchStatus.ptr
122
+ # @!method self.pbs_submit(connect, attrib, script, destination, extend)
123
+ # Submit a PBS batch job
124
+ # char *pbs_submit(int connect, struct attropl *attrib, char *script, char *destination, char *extend)
125
+ # @see http://linux.die.net/man/3/pbs_submit
126
+ # @param connect [Fixnum] connection identifier
127
+ # @param attrib [Attropl] the attribute operation c-linked list object
128
+ # @param script [String] the path to the script
129
+ # @param destination [String] the queue to send job to
130
+ # @param extend [String] implementation defined extensions
131
+ # @return [String] the job id
52
132
 
53
- # batch_status * pbs_statserver(int connect, struct attrl *attrib, char *extend)
54
- attach_function :pbs_statserver, [ :int, :pointer, :pointer ], BatchStatus.ptr
133
+ # The path to the torque library file
134
+ # @return [String] path to torque library
135
+ def self.lib
136
+ @lib
137
+ end
138
+
139
+ # Define torque methods using a supplied library
140
+ # @param lib [#to_s, nil] path to library file
141
+ # @return [void]
142
+ def self.lib=(lib)
143
+ @lib = lib ? lib.to_s : 'torque'
55
144
 
56
- # char *pbs_submit(int connect, struct attropl *attrib, char *script, char *destination, char *extend)
57
- attach_function :pbs_submit, [ :int, :pointer, :pointer, :pointer, :pointer ], :string
145
+ # Set up FFI to use this library
146
+ ffi_lib @lib
147
+
148
+ attach_variable :pbs_errno, :int
149
+ attach_variable :pbs_server, :string
150
+ attach_function :pbs_strerror, [ :int ], :string
151
+ attach_function :pbs_default, [], :string
152
+ attach_function :pbs_connect, [ :string ], :int
153
+ attach_function :pbs_disconnect, [ :int ], :int
154
+ attach_function :pbs_deljob, [ :int, :string, :string ], :int
155
+ attach_function :pbs_holdjob, [ :int, :string, :string, :string ], :int
156
+ attach_function :pbs_rlsjob, [ :int, :string, :string, :string ], :int
157
+ attach_function :pbs_statfree, [ BatchStatus.ptr ], :void
158
+ attach_function :pbs_statjob, [ :int, :string, Attrl.ptr, :string ], BatchStatus.ptr
159
+ attach_function :pbs_statnode, [ :int, :string, Attrl.ptr, :string ], BatchStatus.ptr
160
+ attach_function :pbs_statque, [ :int, :string, Attrl.ptr, :string ], BatchStatus.ptr
161
+ attach_function :pbs_statserver, [ :int, Attrl.ptr, :string ], BatchStatus.ptr
162
+
163
+ # FIXME: The space for the job_identifier string is allocated by
164
+ # pbs_submit() and should be released via a call to free() when no longer
165
+ # needed
166
+ attach_function :pbs_submit, [ :int, Attropl.ptr, :string, :string, :string ], :string
58
167
  end
59
168
 
169
+ # Check for any errors set in the errno
170
+ # @return [void]
60
171
  def self.check_for_error
61
172
  errno = pbs_errno
62
173
  self.pbs_errno = 0 # reset error number
63
174
  raise_error(errno) if errno > 0
64
175
  end
65
176
 
177
+ # For a given errno, raise the corresponding error with error message
178
+ # @param errno [Fixnum] the error number
179
+ # @raise [Error] if errno is not 0
180
+ # @return [void]
66
181
  def self.raise_error(errno)
67
182
  raise (ERROR_CODES[errno] || PBS::Error), "#{pbs_strerror(errno)}"
68
183
  end
69
184
 
185
+ #
70
186
  # Data structures defined in pbs_ifl.h
187
+ #
71
188
 
72
189
  # Enum for Batch Operation
73
190
  BatchOp = enum(:set, :unset, :incr, :decr, :eq, :ne, :ge, :gt, :le, :lt, :dflt, :merge, :incr_old)
@@ -80,34 +197,31 @@ module PBS
80
197
  :value, :pointer, # string for value of attribute
81
198
  :op, BatchOp # not used in an Attrl object
82
199
 
200
+ # Given an array of attribute names convert it to {Attrl} C-linked list
201
+ # @param list [Array<Symbol>] list of attribute names
202
+ # @return [Attrl] generated attribute c-linked list object
83
203
  def self.from_list(list)
84
204
  attrl = nil
85
205
  prev = Attrl.new(FFI::Pointer::NULL)
86
206
  list.each do |key|
87
207
  attrl = Attrl.new
88
208
  attrl[:name] = FFI::MemoryPointer.from_string(key.to_s)
89
- attrl[:resource] = FFI::Pointer::NULL
90
- attrl[:value] = FFI::Pointer::NULL
91
- attrl[:op] = 0
92
209
  attrl[:next] = prev
93
210
  prev = attrl
94
211
  end
95
212
  attrl
96
213
  end
97
214
 
98
- def to_hash
99
- hash = Hash.new{ |h,k| h[k] = Hash.new() }
215
+ # Convert to hash describing this linked list
216
+ # @return [Hash] hash describing linked list
217
+ def to_h
100
218
  attrl = self
219
+ hash = {}
101
220
  until attrl.to_ptr.null?
102
- name = attrl[:name].read_string.to_sym
103
- value = attrl[:value].read_string
104
- resource = nil
105
- resource = attrl[:resource].read_string.to_sym unless attrl[:resource].null?
106
- if resource.nil?
107
- hash[name] = value
108
- else
109
- hash[name][resource] = value
110
- end
221
+ n = attrl[:name].read_string
222
+ v = attrl[:value].read_string
223
+ r = attrl[:resource].null? ? nil : attrl[:resource].read_string
224
+ r ? (hash[n.to_sym] ||= {} and hash[n.to_sym][r.to_sym] = v) : hash[n.to_sym] = v
111
225
  attrl = attrl[:next]
112
226
  end
113
227
  hash
@@ -122,6 +236,9 @@ module PBS
122
236
  :value, :pointer, # string for value of attribute
123
237
  :op, BatchOp # operation to perform for this attribute
124
238
 
239
+ # Convert to C-linked list of structs from hash
240
+ # @param hash [Hash] hash representation of this c-linked list
241
+ # @return [Attropl] generated attribute operation c-linked list object
125
242
  def self.from_hash(hash)
126
243
  # Convert hash into array
127
244
  # Format: {name: value, name: {resource: value, resource: value}}
@@ -131,41 +248,42 @@ module PBS
131
248
  prev = Attropl.new(FFI::Pointer::NULL)
132
249
  ary.each do |attrib|
133
250
  attropl = Attropl.new
134
- attropl[:name] = FFI::MemoryPointer.from_string(attrib[0].to_s)
135
- attropl[:value] = FFI::MemoryPointer.from_string(attrib[1])
136
- attropl[:resource] = FFI::MemoryPointer.from_string(attrib[2].to_s) unless attrib[2].nil?
137
- attropl[:op] = 0
138
- attropl[:next] = prev
251
+ attropl[:name] = FFI::MemoryPointer.from_string attrib[0].to_s
252
+ attropl[:value] = FFI::MemoryPointer.from_string attrib[1].to_s
253
+ attropl[:resource] = FFI::MemoryPointer.from_string attrib[2].to_s if attrib[2]
254
+ attropl[:next] = prev
139
255
  prev = attropl
140
256
  end
141
257
  attropl
142
258
  end
143
259
  end
144
260
 
145
- # Struct for status of batch
261
+ # Struct for PBS batch server status responses
146
262
  class BatchStatus < FFI::ManagedStruct
147
263
  layout :next, BatchStatus.ptr, # pointer to next BatchStatus object
148
264
  :name, :string, # string for name of this status
149
265
  :attribs, Attrl.ptr, # pointer to beginning of C-linked list of an Attrl object
150
266
  :text, :string # string containing unknown text
151
267
 
268
+ # Free memory for allocated {BatchStatus} C-linked list
152
269
  def self.release(ptr)
153
270
  pbs_statfree(ptr)
154
271
  end
155
272
 
156
- def to_a
157
- ary = []
273
+ # Convert to hash describing this linked list
274
+ # @return [Hash] hash describing linked list
275
+ def to_h
158
276
  batch = self
277
+ hash = {}
159
278
  until batch.to_ptr.null?
160
- ary << {name: batch[:name], attribs: batch[:attribs].to_hash}
279
+ hash[batch[:name]] = batch[:attribs].to_h
161
280
  batch = batch[:next]
162
281
  end
163
- ary
282
+ hash
164
283
  end
165
284
  end
166
285
 
167
- # Defined error codes
168
- # valid as of Torque >=4.2.10
286
+ # Defined error codes, valid as of Torque >=4.2.10
169
287
  ERROR_CODES = {
170
288
  15001 => PBS::UnkjobidError,
171
289
  15002 => PBS::NoattrError,
@@ -1,3 +1,4 @@
1
1
  module PBS
2
- VERSION = "1.1.4"
2
+ # The current version of PBS
3
+ VERSION = "2.0.0"
3
4
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.platform = Gem::Platform::RUBY
10
10
  spec.authors = ["Jeremy Nicklas"]
11
11
  spec.email = ["jnicklas@osc.edu"]
12
- spec.summary = %q{PBS FFI Ruby gem to use FFI to interface with Adaptive Computing's resource manager Torque}
13
- spec.description = %q{PBS FFI Ruby gem to use FFI to interface with Adaptive Computing's resource manager Torque}
12
+ spec.summary = %q{Ruby gem that uses FFI to interface with Adaptive Computing's resource manager Torque}
13
+ spec.description = %q{Ruby wrapper for the Torque C library utilizing Ruby-FFI. This has been successfully tested with Torque 4.2.10 and greater. Your mileage may vary.}
14
14
  spec.homepage = "https://github.com/OSC/pbs-ruby"
15
15
  spec.license = "MIT"
16
16
 
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
+ spec.required_ruby_version = '~> 2.2'
21
22
 
22
23
  spec.add_runtime_dependency "ffi", "~> 1.9", ">= 1.9.6"
23
24
  spec.add_development_dependency "bundler", "~> 1.7"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Nicklas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-07 00:00:00.000000000 Z
11
+ date: 2016-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -58,8 +58,8 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '10.0'
61
- description: PBS FFI Ruby gem to use FFI to interface with Adaptive Computing's resource
62
- manager Torque
61
+ description: Ruby wrapper for the Torque C library utilizing Ruby-FFI. This has been
62
+ successfully tested with Torque 4.2.10 and greater. Your mileage may vary.
63
63
  email:
64
64
  - jnicklas@osc.edu
65
65
  executables: []
@@ -67,20 +67,15 @@ extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
69
  - ".gitignore"
70
+ - CHANGELOG.md
70
71
  - Gemfile
71
72
  - LICENSE.txt
72
73
  - README.md
73
74
  - Rakefile
74
- - config/batch.yml
75
- - config/websvcs02.osc.edu.yml
76
- - config/websvcs08.osc.edu.yml
77
- - examples/simplejob.rb
78
75
  - lib/pbs.rb
79
76
  - lib/pbs/attributes.rb
80
- - lib/pbs/conn.rb
77
+ - lib/pbs/batch.rb
81
78
  - lib/pbs/error.rb
82
- - lib/pbs/job.rb
83
- - lib/pbs/query.rb
84
79
  - lib/pbs/torque.rb
85
80
  - lib/pbs/version.rb
86
81
  - pbs.gemspec
@@ -94,9 +89,9 @@ require_paths:
94
89
  - lib
95
90
  required_ruby_version: !ruby/object:Gem::Requirement
96
91
  requirements:
97
- - - ">="
92
+ - - "~>"
98
93
  - !ruby/object:Gem::Version
99
- version: '0'
94
+ version: '2.2'
100
95
  required_rubygems_version: !ruby/object:Gem::Requirement
101
96
  requirements:
102
97
  - - ">="
@@ -104,9 +99,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
99
  version: '0'
105
100
  requirements: []
106
101
  rubyforge_project:
107
- rubygems_version: 2.4.8
102
+ rubygems_version: 2.4.5
108
103
  signing_key:
109
104
  specification_version: 4
110
- summary: PBS FFI Ruby gem to use FFI to interface with Adaptive Computing's resource
111
- manager Torque
105
+ summary: Ruby gem that uses FFI to interface with Adaptive Computing's resource manager
106
+ Torque
112
107
  test_files: []
108
+ has_rdoc:
@@ -1,24 +0,0 @@
1
- oakley: &oakley
2
- lib: '/usr/local/torque/default/lib/libtorque.so'
3
- server: &oakley_server 'oak-batch.osc.edu'
4
- qsub: 'LD_LIBRARY_PATH=/usr/local/torque/default/lib:$LD_LIBRARY_PATH /usr/local/torque/default/bin/qsub'
5
- *oakley_server:
6
- <<: *oakley
7
- ruby: &ruby
8
- lib: '/usr/local/torque/default/lib/libtorque.so'
9
- server: &ruby_server 'ruby-batch.ten.osc.edu'
10
- qsub: 'LD_LIBRARY_PATH=/usr/local/torque/default/lib:$LD_LIBRARY_PATH /usr/local/torque/default/bin/qsub'
11
- *ruby_server:
12
- <<: *ruby
13
- oxymoron: &oxymoron
14
- lib: '/usr/local/torque/default/lib/libtorque.so'
15
- server: &oxymoron_server 'oak-batch.osc.edu:17001'
16
- qsub: 'LD_LIBRARY_PATH=/usr/local/torque/default/lib:$LD_LIBRARY_PATH /usr/local/torque/default/bin/qsub'
17
- *oxymoron_server:
18
- <<: *oxymoron
19
- quick: &quick
20
- lib: '/usr/local/torque/default/lib/libtorque.so'
21
- server: &quick_server 'quick-batch.osc.edu'
22
- qsub: 'LD_LIBRARY_PATH=/usr/local/torque/default/lib:$LD_LIBRARY_PATH /usr/local/torque/default/bin/qsub'
23
- *quick_server:
24
- <<: *quick