manband 0.5.0 → 0.5.1

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.
data/bin/jobhandler.rb CHANGED
@@ -80,6 +80,10 @@ if options[:conf]!=nil
80
80
  puts "Using configuration file "+options[:conf]
81
81
  FlowConfig.sets3(conf["s3"]["host"],conf["s3"]["port"],conf["s3"]["path"])
82
82
  FlowConfig.setworkdir(conf["workdir"])
83
+ if conf["sudo"] != nil
84
+ log.info "Sudo mode:"+conf["sudo"].to_s
85
+ FlowConfig.setsudo(conf["sudo"])
86
+ end
83
87
  end
84
88
 
85
89
  if options[:store]!=nil
@@ -93,23 +97,8 @@ job "manband.node"+options[:queue] do |args|
93
97
  msg = JSON.parse(args["msg"])
94
98
  if args["operation"] == OP_DESTROY
95
99
  myworkflow = WorkFlow.get(msg["id"])
96
- if myworkflow == nil
97
- log.error "Error: workflow does not exists "+msg["id"]
98
- else
99
- myworkflow.clean
100
- jobs = Job.all(:wid => msg[:id])
101
- if jobs!=nil
102
- jobs.destroy
103
- end
104
- links = JobLink.all(:wid => msg[:id])
105
- if links!=nil
106
- links.destroy
107
- end
108
- myworkflow.destroy
109
- messages = BandMessage.all(:wid => msg[:id])
110
- if messages != nil
111
- messages.destroy
112
- end
100
+ if myworkflow != nil
101
+ myworkflow.delete()
113
102
  end
114
103
  elsif args["operation"] == OP_CLEAN
115
104
  myworkflow = WorkFlow.get(msg["id"])
@@ -44,6 +44,22 @@ class FlowConfig
44
44
 
45
45
  @@uploaddir = '/tmp/upload'
46
46
 
47
+ # Sudo commands
48
+ @@sudo = false
49
+
50
+ def self.sudo
51
+ return @@sudo
52
+ end
53
+
54
+ # Sets sudo mode
55
+ # If sudo is set, job commands are run with a sudo on user id.
56
+ # User must exists on the system.
57
+ #
58
+ # Can be set in user config file with sudo: true
59
+ def self.setsudo(dosudo)
60
+ @@sudo = dosudo
61
+ end
62
+
47
63
  def self.uploaddir
48
64
  return @@uploaddir
49
65
  end
@@ -53,6 +69,8 @@ class FlowConfig
53
69
  end
54
70
 
55
71
  # Sets S3 storage parameters
72
+ #
73
+ # Parameters can be set in user config fiel under s3 parameter
56
74
  def self.sets3(host,port= '8773',path='/services/Walrus')
57
75
  @@s3host = host
58
76
  @@s3port = port
data/lib/manband/job.rb CHANGED
@@ -101,10 +101,23 @@ class Job
101
101
  curjob = Job.get(@id)
102
102
  command = JSON.parse(curjob.command)
103
103
  if command.length > 1
104
- system(initcmd+command[0])
104
+ cmd = initcmd+command[0]
105
105
  else
106
- system(initcmd+command[instance-1])
106
+ cmd = initcmd+command[instance-1]
107
107
  end
108
+ if FlowConfig.sudo() == true
109
+ wflow = WorkFlow.get(@wid)
110
+ script = wflow.workdir+"/"+self.id.to_s+"-"+instance.to_s+".sh"
111
+ if !File.exists?(wflow.workdir)
112
+ Dir.mkdir(wflow.workdir)
113
+ system("chown -R "+wflow.uid+" "+wflow.workdir)
114
+ end
115
+ File.open(script, 'w') {|f| f.write("#!/bin/bash\n"+cmd) }
116
+ File.chmod(0755,script)
117
+ cmd = "sudo -u "+wflow.uid+" '"+script+"'"
118
+ end
119
+ @@log.debug cmd
120
+ system(cmd)
108
121
  end
109
122
 
110
123
  # Change instance counter
@@ -259,15 +259,41 @@ class WorkFlow
259
259
 
260
260
  # Clean a workflow directory
261
261
  def clean
262
- workflow = WorkFlow.get(@id)
263
- if workflow.workdir == nil
262
+ if self.workdir == nil
264
263
  return
265
264
  end
266
- if File.directory? workflow.workdir
267
- FileUtils.rm_rf(workflow.workdir)
265
+ if File.directory? self.workdir
266
+ FileUtils.rm_rf(self.workdir)
268
267
  end
269
268
  end
270
269
 
270
+ # Delete workflow, its directory and all its components (jobs, messages,...)
271
+ # deletesub: delete sub workflows too
272
+ def delete(deletesub=true)
273
+ self.clean
274
+ jobs = Job.all(:wid => self.id)
275
+ if jobs!=nil
276
+ jobs.destroy
277
+ end
278
+ links = JobLink.all(:wid => self.id)
279
+ if links!=nil
280
+ links.destroy
281
+ end
282
+ messages = BandMessage.all(:wid => self.id)
283
+ if messages != nil
284
+ messages.destroy
285
+ end
286
+ if deletesub
287
+ subworkflows = WorkFlow.all(:parent => self.id)
288
+ if subworkflows != nil
289
+ subworkflows.each do |sub|
290
+ sub.delete(false)
291
+ end
292
+ end
293
+ end
294
+ self.destroy
295
+ end
296
+
271
297
  end
272
298
 
273
299
  # Table hosting workflow handler messages
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manband
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 0
10
- version: 0.5.0
9
+ - 1
10
+ version: 0.5.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Olivier Sallou
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-10 00:00:00 Z
18
+ date: 2012-07-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: amqp
@@ -115,6 +115,20 @@ dependencies:
115
115
  version: "0"
116
116
  type: :runtime
117
117
  version_requirements: *id007
118
+ - !ruby/object:Gem::Dependency
119
+ name: uuid
120
+ prerelease: false
121
+ requirement: &id008 !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ type: :runtime
131
+ version_requirements: *id008
118
132
  description:
119
133
  email: olivier.sallou@irisa.fr
120
134
  executables: []
@@ -167,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
181
  requirements: []
168
182
 
169
183
  rubyforge_project:
170
- rubygems_version: 1.8.15
184
+ rubygems_version: 1.8.24
171
185
  signing_key:
172
186
  specification_version: 3
173
187
  summary: Workflow orchestrator based on RabbitMQ