Class: RemoteCodeRunner
- Inherits:
-
CodeRunner
- Object
- CodeRunner
- RemoteCodeRunner
- Defined in:
- lib/coderunner/remote_code_runner.rb
Constant Summary collapse
- DISPLAY_REMOTE_INVOCATION =
false
- RUNNER_CACHE =
ENV['HOME'] + '/.coderunner/remote_cache/'
Constants inherited from CodeRunner
CodeRunner::CLASS_OPTIONS, CodeRunner::CLF, CodeRunner::CLF_BOOLS, CodeRunner::CLF_INVERSE_BOOLS, CodeRunner::CLF_TO_LONG, CodeRunner::CLF_TO_SHORT_COPTS, CodeRunner::CODE_COMMAND_OPTIONS, CodeRunner::CODE_OPTIONS, CodeRunner::CODE_RUNNER_VERSION, CodeRunner::COMMANDS, CodeRunner::COMMANDS_WITH_HELP, CodeRunner::COMMAND_FOLDER, CodeRunner::COMMAND_LINE_FLAGS_WITH_HELP, CodeRunner::DEFAULT_COMMAND_OPTIONS, CodeRunner::DEFAULT_RUNNER_OPTIONS, CodeRunner::FOLDER_DEFAULTS, CodeRunner::GLOBAL_BINDING, CodeRunner::GLOBAL_OPTIONS, CodeRunner::GraphKit, CodeRunner::LONG_COMMAND_LINE_FLAGS, CodeRunner::LONG_COMMAND_LINE_OPTIONS, CodeRunner::LONG_TO_SHORT, CodeRunner::NECESSARY_RUN_CLASS_PROPERTIES, CodeRunner::NECESSARY_RUN_CODE_METHODS, CodeRunner::NECESSARY_RUN_SYSTEM_METHODS, CodeRunner::PERMITTED_STATI, CodeRunner::SCRIPT_FOLDER, CodeRunner::SETUP_RUN_CLASSES, CodeRunner::SUBMIT_OPTIONS, CodeRunner::SYS, CodeRunner::SYSTEM_MODULE
Instance Attribute Summary collapse
-
#combined_ids ⇒ Object
end.
-
#combined_run_list ⇒ Object
end.
-
#ids ⇒ Object
end.
-
#libraries ⇒ Object
end.
-
#phantom_ids ⇒ Object
end.
-
#phantom_run_list ⇒ Object
end.
-
#remote_cache ⇒ Object
end.
-
#run_list ⇒ Object
end.
Attributes inherited from CodeRunner
#cache, #cmaxes, #cmins, #code, #current_request, #current_status, #defaults_file, #executable, #max_id, #maxes, #mins, #modlet, #print_out_size, #requests, #root_folder, #run_class, #start_id
Class Method Summary collapse
- .cache_file(host, folder) ⇒ Object
- .cache_folder(host, folder) ⇒ Object
- .new(host, folder, copts = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(host, folder, copts = {}) ⇒ RemoteCodeRunner
constructor
A new instance of RemoteCodeRunner.
- #method_missing(method, *args) ⇒ Object
- #process_copts(copts) ⇒ Object
- #retrieve(string) ⇒ Object
- #retrieve_method(method, *args) ⇒ Object
- #update ⇒ Object
Methods inherited from CodeRunner
#add_phantom_run, #alter_ids, available_defaults_files, available_modlets, #axiskit, cancel, #cancel_job, code_command, #code_run_environment, code_runner_execute, #continue_in_new_folder, continue_in_new_folder, #create_archive, delete, #destroy, differences_between, directory, dumb_film, #dup, #executable_location, #executable_name, execute, fetch_runner, film, #film_graphkit, film_graphkit_frame_array, #film_run_graphkit, #filter, #filtered_ids, #generate_combined_ids, generate_documentation, #get_all_root_folder_contents, #get_max, #get_min, #get_run_class, get_run_class_name, #get_run_class_name, gets, #gets, #graphkit, #graphkit_from_lists, #graphkit_from_lists_with_frame_array, graphkit_multiple_runners, graphkit_multiple_runners_with_frame_array, #graphkit_shorthand, #increment_max_id, interactive_mode, #job_identifier, launcher_directory, load_file, #make_film_from_lists, make_film_multiple_runners, make_film_multiple_runners_old, manual, #marshalled_variables, #merge, #merge_method, netcdf_plot, #new_run, old_get_run_class_name, #p, parameter_scan, #parameter_scan, plot_graph, #print, #print_out, print_queue_status, process_command_line_option, process_command_options, #puts, #rcp, read_default_command_options, #read_defaults, #read_folder_defaults, readout, #readout, #readout_cols, recheck, #recheck_filtered_runs, #recheck_incomplete_runs, reference, repair_marshal_run_class_not_found_error, #respond_to_requests, resubmit, run_command, #run_graphkit, #run_graphkit_shorthand, run_script, runner, runner_eval, #runs, #save_all, #save_large_cache, scan, #server_dump, server_dump, set_class_defaults, set_default_command_options_from_command_line, set_runner_defaults, #set_start_id, #setup_run_class, setup_run_class, show_values_of, #similar_runs, #simple_scan, #sort_runs, start_launcher, status, status_loop, status_with_comments, #submit, submit, submit_command, #sweep_graphkits, update_runners, #write_data, write_graph
Constructor Details
#initialize(host, folder, copts = {}) ⇒ RemoteCodeRunner
Returns a new instance of RemoteCodeRunner.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/coderunner/remote_code_runner.rb', line 89 def initialize(host, folder, copts = {}) @folder = folder @host = host #eputs "setting libraries" @libraries = [] if host.length == 1 unless Object.constants.include? HostManager.to_s.to_sym raise CRFatal.new("Host manager not available") end HostManager.phoenix($default_host_manager_store) do |host_manager| # @user_name = host_manager.hosts[host].user_name # @host = host_manager.hosts[host].host # @port = host_manager.hosts[host].port @ssh_command = host_manager.hosts[host].ssh end else # @user_name, @host = host.split(/@/) @ssh_command = "ssh " + host end # @coderunner_location = coderunner_location @attributes = {} process_copts(copts) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/coderunner/remote_code_runner.rb', line 119 def method_missing(method, *args) raise "Not a CodeRunner method #{method}" unless (CodeRunner.instance_methods + [:puts]).include? method # ep method; STDIN.gets if method.to_s =~ /=$/ raise NoMethodError.new("unknown set method: #{method}") # @attributes[method] = args[0] # return end data = retrieve_method(method, *args) if method.to_s =~ /graphkit/ # puts Marshal.load(data).pretty_inspect unless data raise "Error: No data was returned from remote server when calling '#{method}'" end #return Marshal.load(data) return data else puts data end end |
Instance Attribute Details
#combined_ids ⇒ Object
end
27 28 29 |
# File 'lib/coderunner/remote_code_runner.rb', line 27 def combined_ids @combined_ids end |
#combined_run_list ⇒ Object
end
27 28 29 |
# File 'lib/coderunner/remote_code_runner.rb', line 27 def combined_run_list @combined_run_list end |
#libraries ⇒ Object
end
27 28 29 |
# File 'lib/coderunner/remote_code_runner.rb', line 27 def libraries @libraries end |
#phantom_ids ⇒ Object
end
27 28 29 |
# File 'lib/coderunner/remote_code_runner.rb', line 27 def phantom_ids @phantom_ids end |
#phantom_run_list ⇒ Object
end
27 28 29 |
# File 'lib/coderunner/remote_code_runner.rb', line 27 def phantom_run_list @phantom_run_list end |
#remote_cache ⇒ Object
end
27 28 29 |
# File 'lib/coderunner/remote_code_runner.rb', line 27 def remote_cache @remote_cache end |
#run_list ⇒ Object
end
27 28 29 |
# File 'lib/coderunner/remote_code_runner.rb', line 27 def run_list @run_list end |
Class Method Details
.cache_file(host, folder) ⇒ Object
80 81 82 |
# File 'lib/coderunner/remote_code_runner.rb', line 80 def cache_file(host, folder) cache_folder(host, folder) + '/runner.msl' end |
.cache_folder(host, folder) ⇒ Object
77 78 79 |
# File 'lib/coderunner/remote_code_runner.rb', line 77 def cache_folder(host, folder) RUNNER_CACHE + "/#{host}/#{folder.gsub(/\//, '_')}" end |
.new(host, folder, copts = {}) ⇒ Object
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 68 69 70 71 72 73 74 75 76 |
# File 'lib/coderunner/remote_code_runner.rb', line 34 def new(host, folder, copts = {}) if host.length == 0 # p 'hello' # copts[:Y] = folder # copts[:no_print_out] = true # copts[:no_update] = true # return go(copts) folder.sub!(/~/, ENV['HOME']) # Dir.chdir(folder){read_defaults(copts)} # p copts return CodeRunner.new(folder, copts) end if copts[:cache] if copts[:cache] == :auto and FileTest.exists? cache_file(host, folder) begin runner = Marshal.load(File.read(cache_file(host, folder))) rescue TypeError, ArgumentError => err eputs err eputs data [0..100] if err.class == TypeError raise err unless err. =~ /undefined class/ repair_marshal_run_class_not_found_error(err) retry end runner.remote_cache = copts[:cache] runner.libraries ||= [] return runner else runner = old_new(host, folder, copts) runner.update runner.remote_cache = copts[:cache] unless FileTest.exist? cache_folder(host, folder) FileUtils.makedirs cache_folder(host, folder) end File.open(cache_file(host, folder), 'w') do |file| file.puts Marshal.dump(runner) end return runner end else return old_new(host, folder, copts) end end |
Instance Method Details
#process_copts(copts) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/coderunner/remote_code_runner.rb', line 112 def process_copts(copts) @copts = copts.dup @copts[:g] = @copts[:G] = [] # @copts[:f] = nil @copts[:Y] = @copts[:w] = @copts[:r] = @copts[:e] = nil @copts.delete(:E) end |
#retrieve(string) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/coderunner/remote_code_runner.rb', line 144 def retrieve(string) #ep '@host', @host, '@remote_cache', @remote_cache cachename = self.class.cache_folder(@host, @folder) + '/' + string.gsub(/[\/:\\\[\]\(\)]/, '.') if @remote_cache == :auto and FileTest.exist?(cachename) return eval(File.read(cachename)) end string = @libraries.map{|lib| "require #{lib}"}.join(";") + ";" + string eputs "Connecting to server using '#{@ssh_command}'..." eputs "Loading folder #{@folder}..." # eval = # > /dev/null 2> /dev/null > /dev/null 2> /dev/null shell_script = <<EOF cd #@folder export ROWS=#{Terminal.terminal_size[0]} export COLS=#{Terminal.terminal_size[1]} source /etc/bashrc /etc/profile > /dev/null 2> /dev/null source ~/.bashrc ~/.bash_login ~/.bash_profile ~/.profile > /dev/null 2> /dev/null if [ "$CODE_RUNNER_COMMAND" ] then $CODE_RUNNER_COMMAND runner_eval #{string.inspect} -Z #{@copts.inspect.inspect} else coderunner runner_eval #{string.inspect} -Z #{@copts.inspect.inspect} fi EOF # coderunner runner_eval #{"#{method.to_s}(*#{args.inspect})".inspect} -Z #{@copts.inspect.inspect} eputs shell_script if DISPLAY_REMOTE_INVOCATION data = %x[#@ssh_command '#{shell_script}'] # ep data eputs "\nDisconnecting from server..." eprint "Extracting data..." data_arr = [] in_dump = false i = 0 loop do if i>=80 #data.size break else #if data[i-1] == "E" and data[i-2] == "_" # ep data[i...(i + "code_runner_server_dump_start_E".size)], '.....' # ep data[(-"code_runner_server_dump_end_E\n".size-i+1)..-i] if in_dump # string = data[0...i] # p string if !in_dump and data[i...(i + "code_runner_server_dump_start_E".size)] == "code_runner_server_dump_start_E" # =~ /.*Begin Output\n\Z/ # ep "IN DUMP" data = data[(i + "code_runner_server_dump_start_E".size)..-1] in_dump = true i = 0 elsif in_dump and data[(-"code_runner_server_dump_end_E\n".size-i+1)..-i] == "code_runner_server_dump_end_E\n" # data_arr.push data[0...(data.size - ("code_runner_server_dump_end_E\n".size+i-1))] # ep "OUT DUMP" # ep data_arr # data = data[0...-(-"code_runner_server_dump_end_E".size-i)] in_dump = false # i = 1 break end end i+=1 end eputs "done" # ep data_arr; exit begin case data_arr.size when 0 output = nil when 1 output = Marshal.load(data_arr[0]) else output = data_arr.map{|str| Marshal.load(str)} end rescue TypeError, ArgumentError => err eputs err eputs data[0..100] if err.class == TypeError raise err unless err. =~ /undefined class/ self.class.repair_marshal_run_class_not_found_error(err) #NB this means that all code_names have to contain only lowercase letters: # code, modlet = err.message.scan(/CodeRunner\:\:([A-Z][a-z0-9]+)([A-Z][\w]+)?Run/)[0] # ep code, modlet # modlet.gsub!(/\B([A-Z])/, '_\1') if modlet # modlet = modlet.downcase if modlet # @run_class = CodeRunner.setup_run_class(code.downcase, modlet: modlet) retry end if [:refresh, :auto].include? @remote_cache eputs "Writing Cache" File.open(cachename, 'w'){|file| file.puts(output.inspect)} end return output end |
#retrieve_method(method, *args) ⇒ Object
140 141 142 143 |
# File 'lib/coderunner/remote_code_runner.rb', line 140 def retrieve_method(method, *args) eputs "Calling Remote Method: #{method}" retrieve("#{method.to_s}(*#{args.inspect})") end |
#update ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/coderunner/remote_code_runner.rb', line 243 def update # ep '@server1', @server instance_vars = retrieve_method(:marshalled_variables) #.sub(/\A\s*/, '') #begin #instance_vars = Marshal.load(data) #rescue TypeError, ArgumentError => err #eputs err #eputs data [0..100] if err.class == TypeError #raise err unless err.message =~ /undefined class/ #self.class.repair_marshal_run_class_not_found_error(err) ##NB this means that all code_names have to contain only lowercase letters: ## code, modlet = err.message.scan(/CodeRunner\:\:([A-Z][a-z0-9]+)([A-Z][\w]+)?Run/)[0] ## ep code, modlet ## modlet.gsub!(/\B([A-Z])/, '_\1') if modlet ## modlet = modlet.downcase if modlet ## @run_class = CodeRunner.setup_run_class(code.downcase, modlet: modlet) #retry #end # ep @run_class.executable instance_vars[:@run_list].values.each{|run| run.runner=self} # class_vars.each do |var, val| # # raise 'found it ' + var.to_s if val.class == CodeRunner # next if [:@@global_binding, :@@server, :SCRIPT_FOLDER, :@@sys].include? var # self.class.class_variable_set(var, val) # end instance_vars.each do |var, val| # puts val.class # raise 'found it ' + var.to_s if val.class == CodeRunner next if [:@server, :@sys].include? var instance_variable_set(var, val) end # @run_class.executable = instance_vars[:@executable] # ep @run_class.executable # ep '@sort', @sort sort_runs # ep '@server', @server return self end |