Class: WorkflowManager::FGCZDebian10Cluster

Inherits:
Cluster
  • Object
show all
Defined in:
lib/workflow_manager/cluster.rb

Direct Known Subclasses

FGCZDebian10DemoCluster

Instance Attribute Summary

Attributes inherited from Cluster

#log_dir, #name, #options

Instance Method Summary collapse

Methods inherited from Cluster

#default_node, #generate_new_job_script, #initialize, #node_list

Constructor Details

This class inherits a constructor from WorkflowManager::Cluster

Instance Method Details

#cluster_nodesObject



542
543
544
545
546
547
# File 'lib/workflow_manager/cluster.rb', line 542

def cluster_nodes
  nodes = {
    'fgcz-h-110: cpu 8,mem  30 GB,scr 500G' => 'fgcz-h-110',
    'fgcz-h-111: cpu 8,mem  30 GB,scr 400G' => 'fgcz-h-111',
  }
end

#copy_commands(org_dir, dest_parent_dir, now = nil, queue = "light") ⇒ Object



524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/workflow_manager/cluster.rb', line 524

def copy_commands(org_dir, dest_parent_dir, now=nil, queue="light")
  commands = if now == "force"
               target_file = File.join(dest_parent_dir, File.basename(org_dir))
               ["g-req copynow -f #{org_dir} #{dest_parent_dir}"]
             elsif now
               ["g-req copynow #{org_dir} #{dest_parent_dir}"]
             elsif queue.nil? or queue == "light"
               ["g-req -w copy #{org_dir} #{dest_parent_dir}"]
             else
               ["g-req -w copy -f heavy #{org_dir} #{dest_parent_dir}"]
             end
end

#delete_command(target) ⇒ Object



539
540
541
# File 'lib/workflow_manager/cluster.rb', line 539

def delete_command(target)
  command = "g-req remove #{target}"
end

#job_ends?(log_file) ⇒ Boolean

Returns:

  • (Boolean)


499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/workflow_manager/cluster.rb', line 499

def job_ends?(log_file)
  log_flag = false
  IO.popen("tail -n 10 #{log_file} 2> /dev/null") do |io|
    while line=io.gets
      if line =~ /__SCRIPT END__/
        log_flag = true
        break
      end
    end
  end
  log_flag
end

#job_pending?(job_id) ⇒ Boolean

Returns:

  • (Boolean)


511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/workflow_manager/cluster.rb', line 511

def job_pending?(job_id)
 qstat_flag = false
  IO.popen('squeue') do |io|
    while line=io.gets
      jobid, partition, name, user, state, *others = line.chomp.split
      if jobid.strip == job_id and state =~ /PD/
        qstat_flag = true
        break
      end
    end
  end
  qstat_flag
end

#job_running?(job_id) ⇒ Boolean

Returns:

  • (Boolean)


484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/workflow_manager/cluster.rb', line 484

def job_running?(job_id)
 qstat_flag = false
  IO.popen('squeue') do |io|
    while line=io.gets
      # ["JOBID", "PARTITION", "NAME", "USER", "ST", "TIME", "NODES", "NODELIST(REASON)"]
      # ["206", "employee", "test.sh", "masaomi", "R", "0:03", "1", "fgcz-h-030"]
      jobid, partition, name, user, state, *others = line.chomp.split
      if jobid.strip == job_id and state == 'R'
        qstat_flag = true
        break
      end
    end
  end
  qstat_flag
end

#kill_command(job_id) ⇒ Object



536
537
538
# File 'lib/workflow_manager/cluster.rb', line 536

def kill_command(job_id)
  command = "scancel #{job_id}"
end

#parse(options) ⇒ Object



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/workflow_manager/cluster.rb', line 439

def parse(options)
  options = options.split
  ram = if i = options.index("-r")
          options[i+1]
        end
  cores = if i = options.index("-c")
            options[i+1]
          end
  scratch = if i = options.index("-s")
              options[i+1]
            end
  partition = if i = options.index("-p")
                options[i+1]
              end
  nice = if i = options.index("-i")
           options[i+1]
         end
  new_options = []
  new_options << "--mem=#{ram}G" if ram
  new_options << "-n #{cores}" if cores
  new_options << "--tmp=#{scratch}G" if scratch
  new_options << "-p #{partition}" if partition
  new_options << "--nice=#{nice}" if nice
  new_options.join(" ")
end

#submit_job(script_file, script_content, option = '') ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/workflow_manager/cluster.rb', line 464

def submit_job(script_file, script_content, option='')
  if script_name = File.basename(script_file) and script_name =~ /\.sh/
    script_name = script_name.split(/\.sh/).first + ".sh"
    new_job_script = generate_new_job_script(script_name, script_content)
    new_job_script_base = File.basename(new_job_script)
    log_file = File.join(@log_dir, new_job_script_base + "_o.log")
    err_file = File.join(@log_dir, new_job_script_base + "_e.log")
    #command = "g-sub -o #{log_file} -e #{err_file} -q user #{option} #{new_job_script}"
    sbatch_options = parse(option)
    command = "sbatch -o #{log_file} -e #{err_file} -N 1 #{sbatch_options} #{new_job_script}"
    puts command
    job_id = `#{command}`
    job_id = job_id.chomp.split.last
    [job_id, log_file, command]
  else
    err_msg = "FGCZDebian10Cluster#submit_job, ERROR: script_name is not *.sh: #{File.basename(script_file)}"
    warn err_msg
    raise err_msg
  end
end