Module: SSHDriver

Defined in:
lib/rbbt/workflow/remote/ssh/driver.rb

Class Method Summary collapse

Class Method Details

.clean(url, input_id, jobname = nil) ⇒ Object



137
138
139
140
141
142
143
144
145
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 137

def self.clean(url, input_id, jobname = nil)
  server, path = parse_url(url)
  
  script = path_script(path)
  script +=<<-EOF
job.clean
  EOF
  self.run(server, script)
end

.get_json(url, params) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 79

def self.get_json(url, params)
  server, path = parse_url(url)
  script = path_script(path)

  script +=<<-EOF
STDOUT.write res.to_json
  EOF

  JSON.parse(self.run(server, script))
end

.get_raw(url, params) ⇒ Object



90
91
92
93
94
95
96
97
98
99
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 90

def self.get_raw(url, params)
  server, path = parse_url(url)
  script = path_script(path)

  script +=<<-EOF
STDOUT.write res
  EOF

  self.run(server, script)
end

.job_script(inputs_id, jobname = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 69

def self.job_script(inputs_id, jobname = nil)
  script =<<-EOF
jobname = #{jobname.nil? ? 'nil' : "'#{jobname}'"}
path = File.join(ENV["HOME"], '.rbbt/tmp/tmp-ssh_job_inputs/#{inputs_id}')
job_inputs = Workflow.load_inputs(path, task_info[:inputs], task_info[:input_types])
job = wf.job(task, jobname, job_inputs)
  EOF
  script
end

.parse_url(url) ⇒ Object

def self.run_log(server, script)

Log.debug "Run and monitor ssh script in #{server}:\n#{script}"
CMD.cmd("ssh '#{server}' 'shopt -s expand_aliases; bash -ic \"ruby\"' ", :in => script, :log => true)

end



12
13
14
15
16
17
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 12

def self.parse_url(url)
  m = url.match(/ssh:\/\/([^:]+):(.*)/)
  server = m.captures[0]
  path = m.captures[1]
  [server, path]
end

.path_script(path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 19

def self.path_script(path) 

  workflow, task, job, *rest = path.split("/")
  
  script =<<-EOF
require 'rbbt/workflow'
wf = Workflow.require_workflow "#{workflow}"
  EOF

  case task
  when nil
    script +=<<-EOF
task_info = {}
wf.tasks.keys.each do |task|
task_info[task] = wf.task_info(task)
end
res = task_info
    EOF
  when 'documentation'
    script +=<<-EOF
res = documentation = wf.documentation
    EOF
  else
    if job.nil?
      script +=<<-EOF
task = '#{task}'
res = task_info = wf.task_info(task)
      EOF
    else
      case rest.first
      when nil
        script +=<<-EOF
task = '#{task}'
jobname = '#{job}'
res = job = wf.fast_load_id(File.join(task, jobname))
        EOF
      when "info"
        script +=<<-EOF
task = '#{task}'
jobname = '#{job}'
job = wf.fast_load_id(File.join(task, jobname))
res = job_info = job.info
        EOF
      else
        raise "Unkown path: #{[path, rest].inspect}"
      end
    end
  end
end

.post_job(url, inputs_id, jobname = nil) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 101

def self.post_job(url, inputs_id, jobname = nil)
  server, path = parse_url(url)

  script = path_script(path)
  script += job_script(inputs_id, jobname)
  script +=<<-EOF
job.init_info
STDOUT.write job.name
  EOF
  @name = self.run(server, script)
end

.run(server, script) ⇒ Object



2
3
4
5
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 2

def self.run(server, script)
  Log.debug "Run ssh script in #{server}:\n#{script}"
  CMD.cmd("ssh '#{server}' 'shopt -s expand_aliases; bash -l -i -c \"ruby\"' ", :in => script, :log => true).read
end

.run_job(url, input_id, jobname = nil) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 113

def self.run_job(url, input_id, jobname = nil)
  server, path = parse_url(url)
  
  script = path_script(path)
  script += job_script(input_id, jobname)
  script +=<<-EOF
job.produce
STDOUT.write job.path
  EOF
  self.run(server, script)
end

.run_slurm_job(url, input_id, jobname = nil) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rbbt/workflow/remote/ssh/driver.rb', line 125

def self.run_slurm_job(url, input_id, jobname = nil)
  server, path = parse_url(url)
  
  script = path_script(path)
  script += job_script(input_id, jobname)
  script +=<<-EOF
job.produce
STDOUT.write job.path
  EOF
  self.run(server, script)
end