nera 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.2.1
2
+ * 1 major enhancement:
3
+ * "show log" menu is implemented into the CUI program.
4
+ * functions of local execution are implemented.
5
+ * 2 bug fixes
6
+ * fixes a bug which happens when a job script is created without any parameter.
7
+
1
8
  == 0.2.0
2
9
  * 1 major enhancement:
3
10
  * logger is implemented. Log informatios are stored in "db_name"/Tables/logfile.txt.
data/lib/nera/nera_cui.rb CHANGED
@@ -74,7 +74,7 @@ HEADER
74
74
  r[:name]
75
75
  end
76
76
  names.unshift("go to Jobs layer")
77
- names += ["exit"]
77
+ names += ["show logs", "exit"]
78
78
  selected = 0
79
79
  Dir.chdir( slc.path_to_sim_layer) {
80
80
  selected = Dialog::select_one_or_return_string( names, "Select a simulator.")
@@ -85,6 +85,9 @@ HEADER
85
85
  }
86
86
  if names[selected] == "go to Jobs layer"
87
87
  return :job_layer
88
+ elsif names[selected] == "show logs"
89
+ system "less #{slc.path_to_log_file}"
90
+ return :simulator_layer
88
91
  elsif names[selected] == "exit"
89
92
  return :exit
90
93
  else
@@ -351,6 +354,7 @@ HEADER
351
354
  action_list = ["Back to simulator layer",
352
355
  "Show job infos",
353
356
  "Cancel jobs",
357
+ "Execute jobs now",
354
358
  "Show host infos",
355
359
  "Upload jobs",
356
360
  "Download data",
@@ -391,6 +395,23 @@ HEADER
391
395
  Dialog::message("Cancellation failed.")
392
396
  end
393
397
  end
398
+ return :job_layer
399
+ when "Execute jobs now"
400
+ header,list = jlc.not_finished_list_in_csv
401
+ list.unshift("Cancel")
402
+ selected_jobs = Dialog::select_many( list, header).map do |num|
403
+ list[num].split(',')[0].to_i
404
+ end
405
+ return :job_layer if selected_jobs.include?(0)
406
+
407
+ system "top"
408
+ if Dialog::ask("Will you execute now?", true)
409
+ flag = jlc.execute_jobs_now( selected_jobs)
410
+ Dialog::message("The following jobs are successfully submitted.\n#{flag.join(', ')}") if flag
411
+ non_submitted = selected_jobs - flag.to_a
412
+ Dialog::message("Warning! The following jobs are not submitted.\n#{non_submitted.join(', ')}") if non_submitted.size > 0
413
+ end
414
+
394
415
  return :job_layer
395
416
  when "Show host infos"
396
417
  h_list = ["Cancel", "All"] + rc.hostnames
@@ -37,7 +37,7 @@ module NERA
37
37
  end
38
38
 
39
39
  # logger instance
40
- @logger = Logger.new( "#{@db_folder}/Tables/logfile.txt", 8)
40
+ @logger = Logger.new( path_to_log_file, 8)
41
41
  @logger.level = Logger::INFO
42
42
  end
43
43
 
@@ -238,6 +238,10 @@ module NERA
238
238
  return @db_folder + "Tables/hosts.yml"
239
239
  end
240
240
 
241
+ def path_to_log_file
242
+ return @db_folder + "Tables/logfile.txt"
243
+ end
244
+
241
245
  end
242
246
  end
243
247
 
@@ -91,6 +91,41 @@ module NERA
91
91
  return destroyed_jobids
92
92
  end
93
93
 
94
+ def execute_jobs_now( job_ids)
95
+ unless job_ids.is_a?(Array)
96
+ raise ArgumentError, "job_ids must be an Array."
97
+ end
98
+ job_ids.each do |x|
99
+ raise ArgumentError, "each element of job_ids must be an Integer" unless x.is_a?(Integer)
100
+ end
101
+
102
+ submitted_jobs = []
103
+ @job_records.transaction {
104
+ jids = []
105
+ job_ids.uniq.each do |jid|
106
+ jids << jid if @job_records.find_by_id(jid)
107
+ end
108
+ return nil if jids.size == 0
109
+
110
+ jids.each do |jid|
111
+ js_path = File.expand_path( @db_folders.path_to_job_script(jid) )
112
+ FileUtils.chmod(0744, js_path)
113
+ next if File.directory?( @db_folders.path_to_include_layer+File.basename( js_path).sub(/\.sh$/,'') ) or File.exist?( @db_folders.path_to_include_layer + File.basename( js_path).sub(/\.sh$/,'.tar.bz2'))
114
+ Dir.chdir( @db_folders.path_to_include_layer) {
115
+ system "nohup #{js_path} &"
116
+ submitted_jobs << jid
117
+ }
118
+ @job_records.update_to_state_submitted( jid, "localhost")
119
+ @db_folders.logger.info( self.class.to_s) {
120
+ "submitted a job (jobid:#{jid}) to localhost"
121
+ }
122
+ end
123
+ }
124
+ submitted_jobs = nil if submitted_jobs.size == 0
125
+ return submitted_jobs
126
+ end
127
+
128
+
94
129
  def include_list
95
130
  list = @db_folders.search_include_files
96
131
  list.map! do |path|
@@ -112,9 +112,9 @@ BODY
112
112
  unless sim_inst.kind_of?(NERA::Simulator)
113
113
  raise ArgumentError, "Simulation_Instance must be a subclass of NERA::Simulator."
114
114
  else
115
- if sim_inst.param == {}
116
- raise ArgumentError, "@param in Simulation_Instance must be set a parameter."
117
- end
115
+ # if sim_inst.param == {}
116
+ # raise ArgumentError, "@param in Simulation_Instance must be set a parameter."
117
+ # end
118
118
  end
119
119
  unless run_stat.is_a?(Array)
120
120
  raise ArgumentError, "Run_Status must be an Array."
@@ -63,6 +63,11 @@ module NERA
63
63
  return a
64
64
  end
65
65
 
66
+ public
67
+ def path_to_log_file
68
+ @db_folders.path_to_log_file
69
+ end
70
+
66
71
  end
67
72
 
68
73
  end
data/lib/nera.rb CHANGED
@@ -22,5 +22,5 @@ require 'nera_simulator_records'
22
22
  require 'nera_remote_connector'
23
23
 
24
24
  module NERA
25
- VERSION = '0.2.0'
25
+ VERSION = '0.2.1'
26
26
  end
@@ -210,6 +210,11 @@ class TC_NERA_DB_FOLDERS < Test::Unit::TestCase
210
210
  assert_equal( @db_folder+"/Tables/hosts.yml",p)
211
211
  end
212
212
 
213
+ def test_path_to_log_file
214
+ path = @dbf.path_to_log_file
215
+ assert_equal( @db_folder + "/Tables/logfile.txt", path)
216
+ end
217
+
213
218
  def test_logger
214
219
  @dbf.logger.info("controller") do "test_message" end
215
220
  assert( File.exist?( @db_folder+"/Tables/logfile.txt") )
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/test_helper'
4
4
  class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- @testdir = 'test_sim_controller'
7
+ @testdir = 'test_job_controller'
8
8
  FileUtils.mkdir(@testdir)
9
9
  FileUtils.chdir(@testdir)
10
10
  @db_folder = "nera_db"
@@ -87,6 +87,43 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
87
87
 
88
88
  end
89
89
 
90
+ def test_execute_jobs_now
91
+ assert_raise( ArgumentError) {
92
+ @jlc.execute_jobs_now(1)
93
+ }
94
+
95
+ logp = @db_folder+'/Tables/logfile.txt'
96
+ s1 = File.open(logp,'r').readlines.size
97
+ f = @jlc.execute_jobs_now( [1,2] )
98
+ assert_equal([1,2], f)
99
+ h, l = @jlc.not_finished_list_in_csv
100
+ assert_equal( 3, l.size)
101
+ assert_equal( "submitted", l[0].split(',')[1].strip)
102
+ assert_equal( "localhost", l[0].split(',')[-1].strip)
103
+ assert_equal( "submitted", l[1].split(',')[1].strip)
104
+ assert_equal( "localhost", l[1].split(',')[-1].strip)
105
+ s2 = File.open(logp,'r').readlines.size
106
+ assert_equal( s1+2, s2)
107
+
108
+ sleep 2
109
+ l = @jlc.include_list
110
+ assert_equal( 2, l.size)
111
+
112
+ f = @jlc.execute_jobs_now( [1,2] )
113
+ assert_nil( f)
114
+ s2 = File.open(logp,'r').readlines.size
115
+ assert_equal( s1+2, s2)
116
+
117
+ f = @jlc.execute_jobs_now( [2,3] )
118
+ assert_equal([3], f)
119
+ s3 = File.open(logp,'r').readlines.size
120
+ assert_equal( s2+1, s3)
121
+ sleep 2
122
+
123
+ end
124
+
125
+
126
+
90
127
  def test_include_list
91
128
  l = @jlc.include_list
92
129
  assert_equal( 0, l.size)
@@ -60,4 +60,9 @@ class TC_NERA_SIM_LAYER_CONTROLLER < Test::Unit::TestCase
60
60
  assert_nil(found)
61
61
  end
62
62
 
63
+ def test_path_to_log_file
64
+ path = @slc.path_to_log_file
65
+ assert_equal( @db_folder + "/Tables/logfile.txt", path)
66
+
67
+ end
63
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nera
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yohsuke Murase
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-24 00:00:00 +09:00
12
+ date: 2009-05-25 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency