Changeset 37833
- Timestamp:
- Jan 12, 2015, 12:53:36 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 27 edited
- 8 copied
-
ippScripts/Build.PL (modified) (1 diff, 1 prop)
-
ippScripts/MANIFEST (modified) (1 diff, 1 prop)
-
ippScripts/scripts (modified) (1 prop)
-
ippScripts/scripts/dist_defineruns.pl (modified) (1 diff)
-
ippScripts/scripts/lap_science.pl (modified) (5 diffs, 1 prop)
-
ippScripts/scripts/permcheck.pl (modified) (1 diff)
-
ippScripts/scripts/queuestaticsky.pl (modified) (1 prop)
-
ippScripts/scripts/sc_mk_stack_mdc.pl (modified) (1 diff)
-
ippScripts/scripts/sc_mk_staticsky_mdc.pl (copied) (copied from branches/eam_branches/ipp-pv3-20140717-merge/ippScripts/scripts/sc_mk_staticsky_mdc.pl )
-
ippScripts/scripts/sc_prepare_camera.pl (modified) (16 diffs)
-
ippScripts/scripts/sc_prepare_chip.pl (modified) (16 diffs)
-
ippScripts/scripts/sc_prepare_run.pl (copied) (copied from branches/eam_branches/ipp-pv3-20140717-merge/ippScripts/scripts/sc_prepare_run.pl )
-
ippScripts/scripts/sc_prepare_stack.pl (modified) (15 diffs)
-
ippScripts/scripts/sc_prepare_staticsky.pl (copied) (copied from branches/eam_branches/ipp-pv3-20140717-merge/ippScripts/scripts/sc_prepare_staticsky.pl )
-
ippScripts/scripts/sc_prepare_warp.pl (modified) (15 diffs)
-
ippScripts/scripts/sc_remote_exec.pl (modified) (12 diffs, 1 prop)
-
ippScripts/scripts/sc_remote_poll.pl (copied) (copied from branches/eam_branches/ipp-pv3-20140717-merge/ippScripts/scripts/sc_remote_poll.pl )
-
ippScripts/scripts/sc_retry_return.pl (copied) (copied from branches/eam_branches/ipp-pv3-20140717-merge/ippScripts/scripts/sc_retry_return.pl )
-
ippScripts/scripts/sc_transfer_tool.pl (modified) (6 diffs)
-
ippScripts/scripts/stack_skycell.pl (modified) (1 diff)
-
ippTools/share/Makefile.am (modified) (1 diff)
-
ippTools/share/laptool_exposures.sql (modified) (1 prop)
-
ippTools/share/pxadmin_create_tables.sql (modified) (1 diff)
-
ippTools/share/remotetool_definebyquery_cam.sql (modified) (1 diff)
-
ippTools/share/remotetool_definebyquery_chip.sql (modified) (2 diffs)
-
ippTools/share/remotetool_definebyquery_stack.sql (modified) (1 diff)
-
ippTools/share/remotetool_definebyquery_staticsky.sql (copied) (copied from branches/eam_branches/ipp-pv3-20140717-merge/ippTools/share/remotetool_definebyquery_staticsky.sql )
-
ippTools/share/remotetool_definebyquery_warp.sql (modified) (1 diff)
-
ippTools/share/remotetool_doneprep.sql (copied) (copied from branches/eam_branches/ipp-pv3-20140717-merge/ippTools/share/remotetool_doneprep.sql )
-
ippTools/share/remotetool_listcomponent.sql (copied) (copied from branches/eam_branches/ipp-pv3-20140717-merge/ippTools/share/remotetool_listcomponent.sql )
-
ippTools/src/remotetool.c (modified) (27 diffs)
-
ippTools/src/remotetool.h (modified) (1 diff)
-
ippTools/src/remotetoolConfig.c (modified) (6 diffs)
-
ippTools/src/stacktool.c (modified) (1 prop)
-
ippTools/src/stacktoolConfig.c (modified) (1 prop)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/Build.PL
- Property svn:mergeinfo set to
r37315 r37833 138 138 scripts/stack_bkg_mk_mdc.pl 139 139 scripts/sc_mk_stack_mdc.pl 140 scripts/sc_mk_staticsky_mdc.pl 140 141 scripts/sc_prepare_camera.pl 141 142 scripts/sc_prepare_chip.pl 142 143 scripts/sc_prepare_stack.pl 144 scripts/sc_prepare_staticsky.pl 143 145 scripts/sc_prepare_warp.pl 146 scripts/sc_prepare_run.pl 144 147 scripts/sc_remote_exec.pl 148 scripts/sc_remote_poll.pl 149 scripts/sc_retry_return.pl 145 150 scripts/sc_transfer_tool.pl 146 151 )], -
trunk/ippScripts/MANIFEST
- Property svn:mergeinfo set to
r37315 r37833 51 51 scripts/regenerate_background.pl 52 52 scripts/sc_mk_stack_mdc.pl 53 scripts/sc_mk_staticsky_mdc.pl 53 54 scripts/sc_prepare_camera.pl 54 55 scripts/sc_prepare_chip.pl 55 56 scripts/sc_prepare_stack.pl 57 scripts/sc_prepare_staticsky.pl 56 58 scripts/sc_prepare_warp.pl 57 59 scripts/sc_remote_exec.pl -
trunk/ippScripts/scripts
- Property svn:mergeinfo set to
-
trunk/ippScripts/scripts/dist_defineruns.pl
r37120 r37833 90 90 push @stages, $stage; 91 91 } else { 92 @stages = qw(chip chip_bg camera fake warp warp_bg diff stack SSdiff sky skysingle skycalff);92 @stages = qw(chip chip_bg camera fake warp warp_bg diff stack SSdiff sky skysingle ff); 93 93 } 94 94 -
trunk/ippScripts/scripts/lap_science.pl
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-pv3-20140717-merge/ippScripts/scripts/lap_science.pl (added) merged: 37830 /tags/ipp-pv3-20140717/ippScripts/scripts/lap_science.pl merged: 37788
r37812 r37833 34 34 my $qstack_threshold = 0.05; # Only make a quickstack if more than 5% of the exposures require it. 35 35 my $minimum_stack_inputs = 2; # We can avoid magicking stack inputs if we have more than this number. 36 my $maximum_stack_inputs = 25; # This is the place-holder guess on how big a stack we should process locally 36 my $maximum_stack_inputs = 25; # This is the place-holder guess on how big a stack we should process locally. 25 is the best guess. 37 37 my $do_updates_pv2 = 0; # Do updates using the calls needed for PV2. 38 38 … … 1058 1058 unless ($success) { 1059 1059 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 1060 &my_die("Unable to perform stacktool -definebyquery: $error_code ", $lap_id);1060 &my_die("Unable to perform stacktool -definebyquery: $error_code :: $command", $lap_id); 1061 1061 } 1062 1062 my $stacks_made = $mdcParser->parse_list(join "", @$stdout_buf) or … … 1066 1066 ## Queue the "deep" stacks that will run locally. 1067 1067 my $deep_minimum = $maximum_stack_inputs + 1; 1068 if ($deep_minimum < 2) { $deep_minimum = 2; } 1068 1069 $command = "$stacktool "; 1069 1070 $command .= " -pretend " if defined $debug; … … 1079 1080 unless ($success) { 1080 1081 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 1081 &my_die("Unable to perform stacktool -definebyquery: $error_code ", $lap_id);1082 } 1083 my $stacks_made_deep .= $mdcParser->parse_list(join "", @$stdout_buf) or1082 &my_die("Unable to perform stacktool -definebyquery: $error_code :: $command", $lap_id); 1083 } 1084 my $stacks_made_deep = $mdcParser->parse_list(join "", @$stdout_buf) or 1084 1085 &my_die("unable to parse metadata from stacktool -definebyquery", $lap_id, ""); 1085 1086 1086 1087 # Append deep stacks to stacks so we can get a complete count later. 1087 push @{ $stacks_made }, @{ $stacks_made_deep };1088 push @{ $stacks_made }, @{ $stacks_made_deep }; 1088 1089 1089 1090 ## Determine the sass_id so we can record it in the database. … … 1449 1450 1450 1451 my @clean_modes = ( 1451 #'chiptool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -chip_id @CHIP_ID@',1452 'chiptool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -chip_id @CHIP_ID@', 1452 1453 # 'warptool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -warp_id @WARP_ID@', 1453 1454 'difftool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -diff_id @DIFF_ID@', - Property svn:mergeinfo changed
-
trunk/ippScripts/scripts/permcheck.pl
r37594 r37833 62 62 if ($stage eq 'warp') { # These things are destined to have their only copy on the stsciXX nodes. 63 63 %backup_hosts = ('stsci00' => 1, 'stsci01' => 1, 'stsci02' => 1, 64 'stsci03' => 1, 'stsci04' => 1, 'stsci05' => 1, 'stsci06' => 1, 64 #'stsci03' => 1, 65 'stsci04' => 1, 'stsci05' => 1, 'stsci06' => 1, 65 66 'stsci07' => 1, 'stsci08' => 1, 'stsci09' => 1, 66 67 'stsci10' => 1, 'stsci11' => 1, 'stsci12' => 1, -
trunk/ippScripts/scripts/queuestaticsky.pl
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-pv3-20140717-merge/ippScripts/scripts/queuestaticsky.pl (added) merged: 37830 /tags/ipp-pv3-20140717/ippScripts/scripts/queuestaticsky.pl (added) merged: 37082,37332
- Property svn:mergeinfo changed
-
trunk/ippScripts/scripts/sc_mk_stack_mdc.pl
r36844 r37833 1 1 #! /usr/bin/env perl 2 3 2 use Carp; 4 3 use warnings; 5 4 use strict; 6 5 6 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 7 use Pod::Usage qw( pod2usage ); 8 9 10 my $remote_root = '/scratch3/watersc1/'; 11 12 my ($compmap_file); 13 GetOptions( 14 'compmap=s' => \$compmap_file, 15 ) or pod2usage( 2 ); 16 17 pod2usage( -msg => "Required options: --compmap", -exitval => 3) unless 18 defined($compmap_file); 19 20 my %component_map = (); 21 open(CM,$compmap_file) || die "Cannot find requested compmap file"; 22 while(<CM>) { 23 chomp; 24 my ($symbolic_name,$disk_name) = split /\s+/; 25 $component_map{$symbolic_name} = $disk_name; 26 } 27 close(CM); 28 7 29 my $counter = 0; 8 30 9 31 foreach my $path_base (@ARGV) { 10 print "INPUT${counter} METADATA\n"; 11 print " IMAGE STR ${path_base}.fits\n"; 12 print " MASK STR ${path_base}.mask.fits\n"; 13 print " VARIANCE STR ${path_base}.wt.fits\n"; 14 print " PSF STR ${path_base}.psf\n"; 15 print " SOURCES STR ${path_base}.cmf\n"; 16 print " BKGMODEL STR ${path_base}.mdl.fits\n"; 17 print "END\n\n"; 32 my $mdc_content = ""; 33 my $file = ""; 34 my $error = 0; 35 36 # print "PB: $path_base\n"; 37 38 #header 39 $mdc_content .= "INPUT${counter} METADATA\n"; 40 41 # check each file against its possible locations, incrementing the error counter if not found 42 $file = do_checks("${path_base}.fits",$error); 43 $mdc_content .= " IMAGE STR $file\n"; 44 45 $file = do_checks("${path_base}.mask.fits",$error); 46 $mdc_content .= " MASK STR $file\n"; 47 48 $file = do_checks("${path_base}.wt.fits",$error); 49 $mdc_content .= " VARIANCE STR $file\n"; 50 51 $file = do_checks("${path_base}.psf",$error); 52 $mdc_content .= " PSF STR $file\n"; 53 54 $file = do_checks("${path_base}.cmf",$error); 55 $mdc_content .= " SOURCES STR $file\n"; 56 57 # This is static, and isn't used by ppStack, but I believe needs to exist in the mdc. 2014-08-28 czw 58 $mdc_content .= " BKGMODEL STR ${path_base}.mdl.fits\n"; 59 $mdc_content .= "END\n\n"; 60 # print "MDC: $mdc_content\n"; 61 # If we had no errors, print it and move on. 62 if ($error == 0) { 63 print $mdc_content; 64 } 65 18 66 $counter++; 19 67 } 68 69 sub do_checks { 70 my ($cfile,$error) = @_; 71 # print ">$cfile<\n"; 72 if (! ((-e $cfile)&&(-s $cfile))) { # This cfile does not exist or is zero size. 73 my $disk = $component_map{$cfile}; 74 $cfile = "${disk}"; 75 if (! ((-e $cfile)&&(-s $cfile))) { # The other expected cfile did not exist. 76 # $cfile = ''; 77 $error++; 78 die "Missing cfile $cfile!"; 79 } 80 } 81 return($cfile); 82 } 83 -
trunk/ippScripts/scripts/sc_prepare_camera.pl
r37125 r37833 1 1 #! /usr/bin/env perl 2 3 # generate the input & output files lists and commands for a single camRun 2 4 3 5 use Carp; … … 16 18 use Pod::Usage qw( pod2usage ); 17 19 18 19 20 # Hard coded values 20 # my $remote_root = '/scratch3/watersc1/'; # Far side destination base location 21 my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location 22 $remote_root = '/scratch3/watersc1/'; 23 my $threads = 2; # How many threads are we going to use? 24 my $job_cost = 1700 / 60 / 60; # Estimate of how long a job runs, in hours. 25 my $proc_per_node = 24; # processors per node 26 my $min_nodes = 1; # smallest allocation to ask for 27 my $max_nodes = 1000; # largest allocation to ask for 28 my $min_time = 1; # shortest allocation to ask for 29 my $max_time = 8; # longest allocation to ask for 30 my $remote_hostname= "LANL/Mustang"; # Name of the remote node. 31 my @return_component_list = ("DBINFO.EXP", "PSASTRO.CONFIG", "PSASTRO.OUTPUT", "LOG.EXP", "PSASTRO.STATS"); 21 # my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location 22 my $remote_root = '/scratch3/watersc1/'; # Far side destination base location 23 my $remote_hostname = "LANL/Mustang"; # Name of the remote node. 24 my $threads_req = 0; # How many threads are we going to use? 25 26 my $fail_state = "prep_fail"; 27 32 28 # Look for programs we need 33 29 my $missing_tools; 34 35 30 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1); 36 31 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1); … … 41 36 } 42 37 43 my ($remote_id,$cam_id, ,$camera,$dbname,$verbose,$path_base,$no_update);38 my ($remote_id,$cam_id,$camera,$dbname,$verbose,$path_base,$no_update); 44 39 GetOptions( 45 40 'remote_id=s' => \$remote_id, 41 'cam_id=s' => \$cam_id, 46 42 'camera|c=s' => \$camera, 47 43 'dbname|d=s' => \$dbname, … … 52 48 53 49 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 54 pod2usage( -msg => "Required options: --remote_id --cam era --dbname --path_base", -exitval => 3) unless50 pod2usage( -msg => "Required options: --remote_id --cam_id --camera --dbname --path_base", -exitval => 3) unless 55 51 defined($remote_id) and 52 defined($cam_id) and 56 53 defined($camera) and 57 54 defined($path_base) and 58 55 defined($dbname); 59 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id); 56 57 my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $cam_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 60 58 61 59 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 62 60 63 # 64 # Step 1: Get a list of the components that make up this remoteRun 65 66 # SHould this call listrun to ensure we're in state new? 67 my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id"; 68 $rt_cmd .= " -dbname $dbname " if defined($dbname); 69 70 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 71 run(command => $rt_cmd, verbose => $verbose); 72 unless ($success) { 73 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 74 &my_die("Unable to run remotetool to determine stage parameters.", 75 $remote_id,$error_code); 76 } 77 my $compData = $mdcParser->parse(join "", @$stdout_buf) or 78 &my_die("Unable to determine component information.", 79 $remote_id,$PS_EXIT_PROG_ERROR); 80 my $compData2= parse_md_list($compData); 81 82 # 83 # Step 1b: Open output files 84 my $uri_command = $path_base . ".cmd"; 61 my @return_component_list = ("DBINFO.EXP", "PSASTRO.CONFIG", "PSASTRO.OUTPUT", "LOG.EXP", "PSASTRO.STATS"); 62 63 # STEP 0: Open output files 85 64 my $uri_transfer= $path_base . ".transfer"; 86 65 my $uri_check = $path_base . ".check"; … … 89 68 my $uri_return = $path_base . ".return"; 90 69 91 my $disk_command = $ipprc->file_resolve($uri_command,1);92 70 my $disk_transfer= $ipprc->file_resolve($uri_transfer,1); 93 71 my $disk_check = $ipprc->file_resolve($uri_check,1); … … 96 74 my $disk_return = $ipprc->file_resolve($uri_return,1); 97 75 98 my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.99 100 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer",$remote_id, $PS_EXIT_SYS_ERROR);101 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check",$remote_id,$PS_EXIT_SYS_ERROR);102 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config",$remote_id,$PS_EXIT_SYS_ERROR);103 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id,$PS_EXIT_SYS_ERROR);104 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $PS_EXIT_SYS_ERROR);76 my (undef, $remote_config) = &uri_convert($uri_config); # Needs to be done after we've created it. 77 78 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer",$remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 79 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 80 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 81 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 82 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 105 83 my %file_filter = (); 106 84 107 #108 # Step 2: Iterate over all componenets in this remote run.109 85 my $job_index = 0; 110 my @pre_commands = (); 111 my @main_commands = (); 112 my @post_commands = (); 113 114 foreach my $compEntry (@$compData2) { 115 my $cam_id = $compEntry->{stage_id}; 116 117 # Get exposure level information from the camRun we're working from. 118 86 87 # STEP 1: Get exposure level information for this camRun 88 my ($workdir,$exp_tag,$reduction); 89 { 119 90 my $command = "$camtool -pendingexp -cam_id $cam_id "; 120 91 $command .= " -dbname $dbname " if defined($dbname); 121 92 122 93 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 123 94 run(command => $command, verbose => 0); 124 95 unless ($success) { 125 96 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 126 127 &my_die("Unable to run camtool to determine stage parameters.", 128 $cam_id,$error_code);129 } 130 131 my $camData = $mdcParser->parse(join "", @$stdout_buf) or132 &my_die("Unable to determine cam component information.", 133 $cam_id,$PS_EXIT_PROG_ERROR);134 my $camData2= parse_md_list($camData); 135 my $camEntry = ${ $camData2 }[0];136 137 my $workdir = $camEntry->{workdir};138 my $exp_tag = $camEntry->{exp_tag};97 98 &my_die("Unable to run camtool to determine stage parameters.", $remote_id, $cam_id, $error_code, $fail_state); 99 } 100 101 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 102 &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state); 103 my $metadata = parse_md_list($MDlist); 104 my $camEntry = $metadata->[0]; 105 106 $workdir = $camEntry->{workdir}; 107 $exp_tag = $camEntry->{exp_tag}; 108 $reduction = $camEntry->{reduction}; 109 $reduction = 'DEFAULT' unless defined $reduction; 139 110 unless (defined($workdir)) { 140 while( my ($k, $v) = each %$camEntry ) { 141 print "key: $k, value: $v.\n"; 142 } 143 144 print "%{ $camEntry }\n"; 145 die; 146 } 147 my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.cm.${cam_id}"; 148 my $remote_outroot = uri_local_to_remote($ipp_outroot); 149 150 151 # 111 while( my ($k, $v) = each %$camEntry ) { 112 print "key: $k, value: $v.\n"; 113 } 114 print "%{ $camEntry }\n"; 115 die; 116 } 117 } 118 119 my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.cm.${cam_id}"; 120 my $remote_outroot = uri_local_to_remote($ipp_outroot); 121 152 122 # Step 3: Iterate over the sub-components 153 154 my $ reg_command = "$camtool -pendingimfile -cam_id $cam_id ";155 $ reg_command .= " -dbname $dbname " if defined($dbname);156 157 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =158 run(command => $reg_command, verbose => 0);123 { 124 my $command = "$camtool -pendingimfile -cam_id $cam_id "; 125 $command .= " -dbname $dbname " if defined($dbname); 126 127 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 128 run(command => $command, verbose => 0); 159 129 unless ($success) { 160 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 161 &my_die("Unable to run camtool -pendingimfile ", 162 $cam_id,$error_code); 163 } 164 130 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 131 &my_die("Unable to run camtool -pendingimfile ", $remote_id, $cam_id, $error_code, $fail_state); 132 } 165 133 166 134 # We don't actually care about the input cam data other than to know which mask files to instantiate. 167 my $ inpData= $mdcParser->parse(join "", @$stdout_buf) or168 &my_die("Unable to determine cam component information.", 169 $cam_id, $PS_EXIT_PROG_ERROR); 170 my $ inpData2=parse_md_list($inpData);171 my $chipProto = ${ $inpData2 }[0];135 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 136 &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state); 137 138 my $metadata = parse_md_list($MDlist); 139 my $chipProto = $metadata->[0]; 172 140 my $chip_path = $chipProto->{path_base}; 173 my $remote_chip_path = uri_local_to_remote( $chip_path );141 my $remote_chip_path = &uri_local_to_remote( $chip_path ); 174 142 my $pre_cmd_cmfs = "ls -1 ${remote_chip_path}*.cmf > ${remote_outroot}.cmflist"; 175 143 my $pre_cmd_masks= "ls -1 ${remote_chip_path}*.mk.fits > ${remote_outroot}.masklist"; 176 144 177 my $reduction = 'DEFAULT' unless defined $camEntry->{reduction}; 178 my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use 145 my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use 146 if ($recipe_psastro eq "") { 147 &my_die("Unable to determine PSASTRO recipe", $cam_id, $PS_EXIT_PROG_ERROR); 148 } 179 149 180 150 my $psastro_command = " psastro -list ${remote_outroot}.cmflist "; 181 151 $psastro_command .= " -masklist ${remote_outroot}.masklist ${remote_outroot} "; 182 # $psastro_command .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} "; # This is used to do edge calculations. It should probably be smart enough to know that it can just use the masks I just specified, but it's not.183 # Uncomment when remote psastro supports this152 # $psastro_command .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} "; 153 $psastro_command .= " -refmasklist /turquoise/usr/projects/ps1/watersc1/references/gpc1.refmask.list "; 184 154 $psastro_command .= " -kh-correct /turquoise/usr/projects/ps1/watersc1/references/khcorrect.20140606.v0.fits "; 185 $psastro_command .= " -refmasklist /turquoise/usr/projects/ps1/watersc1/references/gpc1.refmask.list "; 186 # $psastro_command .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20080909.asm "; 155 # $psastro_command .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20080909.asm "; 187 156 $psastro_command .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20140505.asm "; 188 157 $psastro_command .= " -recipe PSASTRO $recipe_psastro "; … … 190 159 $psastro_command .= " -dumpconfig ${remote_outroot}.psastro.mdc -stats ${remote_outroot}.stats "; 191 160 $psastro_command .= " -recipe PPSTATS CAMSTATS "; 192 161 193 162 my $camtool_post_cmd = "camtool -cam_id $cam_id -addprocessedexp -uri UNKNOWN "; 194 $camtool_post_cmd .= " -dbname $dbname " if defined $dbname; $camtool_post_cmd .= " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 "; 163 $camtool_post_cmd .= " -dbname $dbname " if defined $dbname; 164 $camtool_post_cmd .= " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 "; 195 165 my $post_cmd_echo = " echo -n \"$camtool_post_cmd\" > ${remote_outroot}.dbinfo "; 196 166 my $post_cmd_SfM = " ppStatsFromMetadata ${remote_outroot}.stats - CAMERA_EXP_FPA >> ${remote_outroot}.dbinfo "; … … 201 171 # Determine which output files need to be returned 202 172 foreach my $component(@return_component_list) { 203 my $filename = $ipprc->filename($component,$ipp_outroot);204 my ($ipp_disk, $remote_disk) =uri_to_outputs_for_return( $filename);205 my $remote_outroot_dir = dirname($ipp_disk);206 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";207 } 208 foreach my $chipInfo (@{ $ inpData2}) {209 my $filename = $ipprc->filename("PSASTRO.OUTPUT.MASK",$ipp_outroot,$chipInfo->{class_id});210 my ($ipp_disk, $remote_disk) =uri_to_outputs_for_return( $filename);211 my $remote_outroot_dir = dirname($ipp_disk);212 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";173 my $filename = $ipprc->filename($component,$ipp_outroot); 174 my ($ipp_disk, $remote_disk) = &uri_to_outputs_for_return( $filename); 175 my $remote_outroot_dir = dirname($ipp_disk); 176 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk "; 177 } 178 foreach my $chipInfo (@{ $metadata }) { 179 my $filename = $ipprc->filename("PSASTRO.OUTPUT.MASK",$ipp_outroot,$chipInfo->{class_id}); 180 my ($ipp_disk, $remote_disk) = &uri_to_outputs_for_return( $filename); 181 my $remote_outroot_dir = dirname($ipp_disk); 182 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk "; 213 183 } 214 184 print CONFIG "\n"; … … 220 190 close(GENERATE); 221 191 222 #223 # Construct the moab command last, so we can use the job_index counter to estimate resources. Somehow.224 my $proc_need = $job_index * $threads; # how many total processors do we need?225 my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?226 my $time_need = $job_index * $job_cost; # How many seconds will this take?227 228 my $fill_factor = 0.8; # This is the factor of how much of the time allocation we'd like to fill229 my ($time_req,$node_req);230 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {231 $time_req = $min_time;232 $node_req = $min_nodes;233 }234 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {235 $time_req = $max_time;236 $node_req = $max_nodes;237 print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job. This exceeds the max limits ($max_nodes, $max_time). Using those max values instead. Good luck.\n";238 }239 else {240 $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;241 $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;242 }243 $time_req += 1; # Safety addition.244 245 open(COMMAND, ">$disk_command") || &my_die("Couldn't open file? $disk_command",$remote_id,$PS_EXIT_SYS_ERROR);246 print COMMAND "#!/bin/tcsh\n";247 print COMMAND "##### Moab controll lines\n";248 print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES249 print COMMAND "#MSUB -j oe\n";250 print COMMAND "#MSUB -V\n";251 print COMMAND "#MSUB -o ${remote_root}cam.${remote_id}.out\n";252 print COMMAND "date\n";253 print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";254 print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 1' . "\n";255 print COMMAND "date\n";256 close(COMMAND);257 258 192 unless($no_update) { 259 my $command = "remotetool -updaterun -remote_id $remote_id "; 260 $command .= " -set_state pending "; 261 $command .= " -dbname $dbname " if defined $dbname; 262 193 my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $cam_id "; 194 $command .= " -set_jobs $job_index"; 195 $command .= " -set_path_base $path_base"; 196 $command .= " -set_state prep_done"; 197 $command .= " -dbname $dbname " if defined $dbname; 263 198 system($command); 264 199 } 265 200 201 exit (0); 266 202 267 203 ## Common SC routines … … 271 207 my $ipp_disk= $ipprc->file_resolve( $neb_uri ); 272 208 my $remote_disk = $ipp_disk; 273 209 274 210 unless(defined($ipp_disk)) { 275 my_die();211 &my_die( "Unable to generate file for $neb_uri ", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 276 212 } 277 213 … … 287 223 my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1); 288 224 my $remote_disk = $ipp_disk; 289 225 290 226 unless(defined($ipp_disk)) { 291 my_die();227 &my_die( "Unable to generate file for $neb_uri ", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 292 228 } 293 229 … … 302 238 my $neb_uri = shift; 303 239 my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri ); 304 240 305 241 unless (exists($file_filter{$neb_uri})) { 306 242 $file_filter{$neb_uri} = 1; … … 332 268 return($remote_uri); 333 269 } 334 270 335 271 sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri); 336 272 # This needs to replace the remote root directory with the nebulous tag. … … 338 274 $remote_uri =~ s%${remote_root}%%; 339 275 my $local_uri = "neb:///" . $remote_uri; 340 276 341 277 return($local_uri); 342 278 } … … 345 281 sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status); 346 282 my $msg = shift; 347 my $id = shift; 283 my $remote_id = shift; 284 my $stage_id = shift; 348 285 my $exit_code = shift; 349 286 my $exit_state = shift; … … 352 289 353 290 carp($msg); 354 355 if (defined $id and not $no_update) { 356 my $command = "remotetool -updaterun -remote_id $id"; 357 $command .= " -fault $exit_code " if defined $exit_code; 291 292 if (defined $remote_id and defined $stage_id and not $no_update) { 293 my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id"; 358 294 $command .= " -set_state $exit_state " if defined $exit_state; 359 295 $command .= " -dbname $dbname " if defined $dbname; -
trunk/ippScripts/scripts/sc_prepare_chip.pl
r37125 r37833 1 1 #! /usr/bin/env perl 2 3 # generate the input & output files lists and commands for a single chipRun 2 4 3 5 use Carp; … … 16 18 use Pod::Usage qw( pod2usage ); 17 19 18 19 20 # Hard coded values 20 # my $remote_root = '/scratch3/watersc1/'; # Far side destination base location 21 my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location 22 $remote_root = '/scratch3/watersc1/'; 23 my $remote_raw = "${remote_root}/raw/"; # Directory to find raw data in. 24 my $threads = 2; # How many threads are we going to use? 25 my $job_cost = 150 / 60 / 60; # Estimate of how long a job runs, in hours. 26 my $proc_per_node = 24; # processors per node 27 my $min_nodes = 1; # smallest allocation to ask for 28 my $max_nodes = 1000; # largest allocation to ask for 29 my $min_time = 1; # shortest allocation to ask for 30 my $max_time = 8; # longest allocation to ask for 31 32 # We need to ensure we only ever try to transfer a file once. 33 my %file_filter = (); 21 # my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location 22 my $remote_root = '/scratch3/watersc1/'; # Far side destination base location 23 my $remote_hostname = "LANL/Mustang"; # Name of the remote node. 24 my $remote_raw = "${remote_root}/tmp/"; # Directory to find raw data in. 25 my $threads_req = 4; 26 27 my $fail_state = "prep_fail"; 28 my $hard_fail_state = "fail"; 34 29 35 30 # Look for programs we need 36 31 my $missing_tools; 37 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);38 32 my $chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1); 39 33 my $detselect= can_run('detselect') or (warn "Can't find detselect" and $missing_tools = 1); 40 34 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1); 35 my $ipp_burntool_fix = can_run('ipp_apply_burntool_fix.pl') or (warn "Can't find ipp_apply_burntool_fix.pl" and $missing_tools = 1); 41 36 42 37 if ($missing_tools) { … … 46 41 47 42 # Options 48 my ($ exp_id,$exp_name,$remote_id,$chip_id,$detrends,$camera,$dbname,$verbose,$path_base,$no_update);43 my ($remote_id,$chip_id,$camera,$dbname,$path_base,$no_update,$verbose,$dbverbose); 49 44 GetOptions( 50 45 'remote_id=s' => \$remote_id, 46 'chip_id=s' => \$chip_id, 51 47 'camera|c=s' => \$camera, 52 48 'dbname|d=s' => \$dbname, … … 54 50 'no_update' => \$no_update, 55 51 'verbose' => \$verbose, 52 'dbverbose' => \$dbverbose, 56 53 ) or pod2usage( 2 ); 57 54 58 55 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 59 pod2usage( -msg => "Required options: --remote_id --c amera --dbname --path_base", -exitval => 3) unless56 pod2usage( -msg => "Required options: --remote_id --chip_id --camera --dbname --path_base", -exitval => 3) unless 60 57 defined($remote_id) and 58 defined($chip_id) and 61 59 defined($camera) and 62 60 defined($path_base) and 63 61 defined($dbname); 64 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $exp_id); 62 63 my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 65 64 66 65 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 67 66 68 # 69 # Step 1: Get a list of the components that make up this remoteRun 70 71 # SHould this call listrun to ensure we're in state new? 72 my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id"; 73 $rt_cmd .= " -dbname $dbname " if defined($dbname); 74 75 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 76 run(command => $rt_cmd, verbose => $verbose); 77 unless ($success) { 78 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 79 80 &my_die("Unable to run chiptool to determine stage parameters.", 81 $remote_id,$error_code); 82 } 83 my $compData = $mdcParser->parse(join "", @$stdout_buf) or 84 &my_die("Unable to determine component information.", 85 $remote_id,$PS_EXIT_PROG_ERROR); 86 my $compData2= parse_md_list($compData); 87 88 # 89 # Step 1a: Load up the catalog of detrends 90 # Detrend concept holders 91 my %detrends = (); 92 my %det_types = ('MASK' => '-mask', 93 'FLAT' => '-flat', 94 'DARK' => '-dark', 95 'VIDEODARK' => '-dark', 96 'LINEARITY' => '-linearity', 97 'FRINGE' => '-fringe', 98 'NOISEMAP' => '-noisemap'); 99 100 foreach my $det_type (keys (%det_types)) { 101 my $dt_cmd = "$detselect -show -camera $camera -det_type $det_type "; 102 $dt_cmd .= " -dbname $dbname " if defined($dbname); 103 104 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 105 run(command => $dt_cmd, verbose => $verbose); 106 unless ($success) { 107 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 108 &my_die("UNable to run detselect to determine detrend catalog", 109 $remote_id,$error_code); 110 } 111 my $detData = $mdcParser->parse(join "", @$stdout_buf) or 112 &my_die("Unable to determine detrend information.", 113 $remote_id,$PS_EXIT_PROG_ERROR); 114 my $detData2= parse_md_list($detData); 115 116 # Data structure for this: 117 # $detrend{NAME} = \@list_of_detselect_shows 118 # $detrend{NAME}[0] = \%hash_of_detselect_constraint_results (first element) 119 # $detrend{NAME}[0]{class_id} = uri 120 121 # At this point, I have the list of detselect shows, assign it 122 $detrends{$det_type} = $detData2; 123 124 for (my $dd = 0; $dd <= $#{ @{ $detrends{$det_type} } }; $dd++) { 125 my $det_id = ${ $detrends{$det_type} }[$dd]->{det_id}; 126 my $det_iter=${ $detrends{$det_type} }[$dd]->{iteration}; 127 128 my $detselect_command2 = "detselect -select "; 129 $detselect_command2 .= " -det_id $det_id "; 130 $detselect_command2 .= " -iteration $det_iter "; 131 $detselect_command2 .= " -dbname $dbname " if defined($dbname); 132 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 133 run(command => $detselect_command2, verbose => 0); 134 unless ($success) { 135 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 136 137 &my_die("No valid detrend available for this image: $det_type $det_id $det_iter", 138 $chip_id,$error_code); 139 } 140 141 my $detImfile = $mdcParser->parse(join "", @$stdout_buf) or 142 &my_die("Could not parse detrend information for this image: $det_type $det_id $det_iter", 143 $chip_id,$error_code); 144 my $detImfile2= parse_md_list($detImfile); 145 foreach $detImfile (@$detImfile2) { 146 my $class_id = $detImfile->{class_id}; 147 my $duri = $detImfile->{uri}; 148 149 ${ $detrends{$det_type} }[$dd]->{$class_id} = $duri; 150 } 151 } 152 } 153 154 #print Dumper(%detrends); 67 # Detrend concept holders (name, ppImage option) 68 my %det_types = ( 69 'MASK' => '-mask', 70 'FLAT' => '-flat', 71 'DARK' => '-dark', 72 'VIDEODARK' => '-dark', 73 'LINEARITY' => '-linearity', 74 'FRINGE' => '-fringe', 75 'NOISEMAP' => '-noisemap' 76 ); 155 77 156 78 my @return_component_list = ("DBINFO.IMFILE","PPIMAGE.STATS","LOG.IMFILE","PPIMAGE.BACKMDL","PPIMAGE.PATTERN"); 157 79 158 # 159 # Step 1b: Open output files 160 my $uri_command = $path_base . ".cmd"; 80 # STEP 0: Open output files 161 81 my $uri_transfer= $path_base . ".transfer"; 162 82 my $uri_check = $path_base . ".check"; … … 165 85 my $uri_return = $path_base . ".return"; 166 86 167 my $disk_command = $ipprc->file_resolve($uri_command,1);168 87 my $disk_transfer= $ipprc->file_resolve($uri_transfer,1); 169 88 my $disk_check = $ipprc->file_resolve($uri_check,1); … … 174 93 my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it. 175 94 176 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer",$chip_id,$PS_EXIT_SYS_ERROR); 177 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check",$chip_id,$PS_EXIT_SYS_ERROR); 178 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config",$chip_id,$PS_EXIT_SYS_ERROR); 179 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$chip_id,$PS_EXIT_SYS_ERROR); 180 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $chip_id, $PS_EXIT_SYS_ERROR); 181 182 183 # 184 # Step 2: Iterate over all componenets in this remote run. 95 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 96 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 97 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 98 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 99 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 100 185 101 my $job_index = 0; 186 my @pre_commands = (); 187 my @main_commands = (); 188 my @post_commands = (); 189 190 foreach my $compEntry (@$compData2) { 191 192 my $chip_id = $compEntry->{stage_id}; 193 my $exp_id ; 194 # Get exposure level information from the chipRun we're working from. 102 103 # STEP 1 : Get exposure level information for this chipRun 104 my ($exp_id, $filter, $altfilt, $dateobs); 105 { 195 106 my $command = "$chiptool -listrun -chip_id $chip_id "; 196 107 $command .= " -dbname $dbname " if defined($dbname); 197 198 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =199 run(command => $command, verbose => 0);108 109 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 110 run(command => $command, verbose => $dbverbose); 200 111 unless ($success) { 201 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 202 203 &my_die("Unable to run chiptool to determine stage parameters.", 204 $chip_id,$error_code); 205 } 206 207 # Parse chipRun level data to determine detrend information 208 my %detrends_to_use = (); 209 { 210 my $chipData = $mdcParser->parse(join "", @$stdout_buf) or 211 &my_die("Unable to determine chip component information.", 212 $chip_id,$PS_EXIT_PROG_ERROR); 213 my $chipData2= parse_md_list($chipData); 214 my $chipEntry = ${ $chipData2 }[0]; 215 216 $exp_id = $chipEntry->{exp_id}; 217 my $filter = $chipEntry->{filter}; 218 my $altfilt= $filter; 219 $altfilt =~ s/.00000//; 220 my $dateobs= $chipEntry->{dateobs}; 221 my ($date, $time) = split /T/, $dateobs; 222 my ($year,$month,$day) = split /-/, $date; 223 my ($hour,$minute,$second) = split /:/, $time; #/; 224 my $dateobs_obj = DateTime->new(year => $year, month => $month, day => $day, hour => $hour, minute => $minute, second => $second); 225 226 foreach my $det_type (%detrends) { 227 if (($filter !~ /y/)&&($det_type eq 'FRINGE')) { next; } # We can skip fringe for all but y 228 229 foreach my $det_obj (@{ $detrends{$det_type} }) { # Iterate over the available options 230 if (defined($det_obj->{filter})) { 231 if (($det_obj->{filter} ne $filter)&&($det_obj->{filter} ne $altfilt)) { 232 next; # Skip detrends with a filter that we can't use. 233 } 234 } 235 if (defined($det_obj->{time_begin})) { 236 if (DateTime->compare($dateobs_obj,$det_obj->{time_begin}) == -1) { 237 next; # Skip detrends that come into effect after this exposure (d1 < d2) 238 } 239 } 240 if (defined($det_obj->{time_end})) { 241 if (DateTime->compare($dateobs_obj,$det_obj->{time_end}) == 1) { 242 next; # Skip detrends that stop working before this exposure (d1 > d2) 243 } 244 } 245 $detrends_to_use{$det_type} = $det_obj; 246 last; 112 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 113 114 &my_die("Unable to run chiptool to determine stage parameters.", $remote_id, $chip_id, $error_code, $fail_state); 115 } 116 117 # Parse chipRun level data to determine exposure information 118 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 119 &my_die("Unable to determine chip component information.", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 120 my $metadata = parse_md_list($MDlist); 121 my $chipEntry = $metadata->[0]; 122 123 $exp_id = $chipEntry->{exp_id}; 124 $filter = $chipEntry->{filter}; 125 $altfilt = $filter; 126 $altfilt =~ s/.00000//; 127 $dateobs = $chipEntry->{dateobs}; 128 } 129 130 # STEP 2 : select the det_ids for each desired det_type (appropriate to this exposure) 131 my %det_ids = (); 132 my %det_iters = (); 133 134 foreach my $det_type (keys (%det_types)) { 135 if (($filter !~ /y/) && ($det_type eq 'FRINGE')) { next; } # We can skip fringe for all but y 136 137 my $command = "detselect -search -det_type $det_type -time $dateobs"; 138 $command .= " -dbname $dbname " if defined($dbname); 139 140 if (($det_type eq 'FLAT') || ($det_type eq 'FRINGE')) { 141 $command .= " -filter $altfilt"; 142 } 143 144 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 145 run(command => $command, verbose => $dbverbose); 146 unless ($success) { 147 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 148 149 &my_die("No valid detrend available for this image: $det_type", $remote_id, $chip_id, $error_code, $fail_state); 150 } 151 152 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 153 &my_die("Could not parse detrend information for this image: $det_type", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 154 my $metadata = parse_md_list($MDlist); 155 my $detEntry = $metadata->[0]; 156 157 if ($verbose) { 158 print STDERR "det_id: $detEntry->{det_id}\n"; 159 print STDERR "det_iter: $detEntry->{iteration}\n"; 160 } 161 162 # save det_id and iteration 163 $det_ids{$det_type} = $detEntry->{det_id}; 164 $det_iters{$det_type} = $detEntry->{iteration}; 165 } 166 167 # Step 3: Iterate over the sub-components 168 { 169 # select chipProcessedImfile entries 170 my $command = "$chiptool -pendingimfile -chip_id $chip_id"; 171 $command .= " -dbname $dbname " if defined($dbname); 172 173 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 174 run(command => $command, verbose => $dbverbose); 175 176 unless ($success) { 177 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 178 179 &my_die("Unable to run chiptool -pendingimfile", $remote_id, $chip_id, $error_code, $fail_state); 180 } 181 182 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 183 &my_die("Unable to parse chiptool -pendingimfile information.", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 184 my $metadata = parse_md_list($MDlist); 185 186 # Iterate over the chipProcessedImfile level data. 187 foreach my $chipEntry (@$metadata) { 188 # Get information we need to pass to ppImage 189 my $uri = $chipEntry->{uri}; 190 my $class_id = $chipEntry->{class_id}; 191 my $video_cells = $chipEntry->{video_cells}; 192 my $reduction = $chipEntry->{reduction}; 193 my $exp_tag = $chipEntry->{exp_tag}; 194 my $workdir = $chipEntry->{workdir}; 195 my $chip_imfile_id = $chipEntry->{chip_imfile_id}; 196 197 # Process the image and burntool table 198 # IMAGE CHECK: Look up the image location, prove it exists, and if not, abort the prep for this object. 199 my ($ipp_uri, $remote_uri) = uri_convert($uri); 200 unless (-e $ipp_uri) { 201 # Try to fix it. 202 system("neb-repair $uri"); 203 ($ipp_uri, $remote_uri) = uri_convert($uri); 204 unless (-e $ipp_uri) { 205 # This image file is missing, so it will require manual intervention. 206 &my_die("Required image file $ipp_uri ($chip_id, $class_id) not found. Stopping this prep.", 207 $remote_id,$chip_id,$PS_EXIT_CONFIG_ERROR,$hard_fail_state); 247 208 } 248 209 } 249 } 250 251 # 252 # Step 3: Iterate over the sub-components 253 # Iterate over the chipProcessedImfile level data. 254 my $reg_command = "$chiptool -pendingimfile "; 255 $reg_command .= " -chip_id $chip_id " if defined($chip_id); 256 $reg_command .= " -dbname $dbname " if defined($dbname); 257 258 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 259 run(command => $reg_command, verbose => $verbose); 260 unless ($success) { 261 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 262 263 &my_die("Unable to run chiptool -pendingimfile", 264 $chip_id,$error_code); 265 } 266 267 my $chipData = $mdcParser->parse(join "", @$stdout_buf) or 268 next; 269 # &my_die("Unable to parse chiptool -pendingimfile information.", 270 # $chip_id,$error_code); 271 my $chipData2= parse_md_list($chipData); 272 273 274 foreach my $chipEntry (@$chipData2) { 275 # Get information we need to pass to ppImage 276 my $uri = $chipEntry->{uri}; 277 my $class_id = $chipEntry->{class_id}; 278 my $video_cells = $chipEntry->{video_cells}; 279 my $reduction = $chipEntry->{reduction}; 280 my $exp_tag = $chipEntry->{exp_tag}; 281 my $workdir = $chipEntry->{workdir}; 282 my $chip_imfile_id = $chipEntry->{chip_imfile_id}; 283 284 # Process the image and burntool table 285 my ($ipp_uri,$remote_uri) = uri_to_outputs_raw($uri); 286 my $btt = $uri; 287 $btt =~ s/fits$/burn.tbl/; 288 my ($ipp_btt,$remote_btt) = uri_to_outputs_raw($btt); 289 290 # Initialize the ppI command 291 my $ppImage_command = "ppImage -file $remote_uri"; 292 $ppImage_command .= " -burntool $remote_btt "; 293 294 # Add detrend information to the command line 295 foreach my $det (keys %detrends_to_use) { 296 if ((($video_cells)&&($det eq 'DARK'))|| 297 ((!$video_cells)&&($det eq 'VIDEODARK'))) { 298 next; 210 211 # The image exists, so continue. This resets the variables, but also outputs the file locations. 212 ($ipp_uri, $remote_uri) = uri_to_outputs_raw($uri); 213 my $btt = $uri; 214 $btt =~ s/fits$/burn.tbl/; 215 216 # Check burntool table for existance, and if it doesn't, regenerate it. 217 my ($ipp_btt, $remote_btt) = uri_convert($btt); 218 unless (-e $ipp_btt) { 219 my $exp_name = $chipEntry->{exp_name}; 220 my $burntool_command = "$ipp_burntool_fix --exp_name $exp_name --class_id $class_id"; 221 $burntool_command .= " -dbname $dbname" if defined($dbname); 222 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 223 run(command => $burntool_command, verbose => $dbverbose); 224 # That command repairs the tables, but the instance we learned about may not be correct. 225 # Look up the new one. 226 ($ipp_btt, $remote_btt) = uri_convert($btt); 227 228 unless (-e $ipp_btt) { 229 &my_die("Attempted regeneration of burntool table ($chip_id, $class_id) has failed. Stopping this prep.", 230 $remote_id,$chip_id, $PS_EXIT_CONFIG_ERROR, $hard_fail_state); 299 231 } 300 my $det_code = $det_types{$det};301 my $duri = $detrends_to_use{$det}->{$class_id};302 my ($ipp_det_uri, $remote_det_uri) = uri_to_outputs_raw($duri);303 $ppImage_command .= " $det_code $remote_det_uri ";304 232 } 305 306 307 # Add output root 308 my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.ch.${chip_id}"; 309 my $remote_outroot = uri_local_to_remote($ipp_outroot); 310 $ppImage_command .= " $remote_outroot "; 311 print STDERR "$remote_outroot $ipp_outroot $class_id\n"; 312 # Complete reduction information. 313 $reduction = 'DEFAULT' unless defined $reduction; 314 my $recipe_ppImage = $ipprc->reduction($reduction, 'CHIP_PPIMAGE'); # Recipe to use for ppImage 315 my $recipe_psphot = $ipprc->reduction($reduction, 'CHIP_PSPHOT'); # Recipe to use for psphot 316 317 $ppImage_command .= " -recipe PPIMAGE $recipe_ppImage "; 318 $ppImage_command .= " -recipe PSPHOT $recipe_psphot "; 319 $ppImage_command .= " -recipe PPSTATS CHIPSTATS -stats ${remote_outroot}.${class_id}.stats "; 320 $ppImage_command .= " -threads 4 "; 321 $ppImage_command .= " -image_id $chip_imfile_id "; 322 $ppImage_command .= " -tracedest ${remote_outroot}.${class_id}.trace "; 323 $ppImage_command .= " -log ${remote_outroot}.${class_id}.log "; 324 325 # push @main_commands, $ppImage_command; 326 327 # Calculate pre and post commands 328 my $remote_outroot_dir = dirname($remote_outroot); 329 my $pre_command = "mkdir -p $remote_outroot_dir"; 330 331 my $post_commandA = "chiptool -addprocessedimfile -exp_id $exp_id -chip_id $chip_id -class_id $class_id "; 332 $post_commandA .= " -uri ${ipp_outroot}.ch.${class_id}.ch.fits -path_base $ipp_outroot "; 333 $post_commandA .= " -magicked 0 -hostname REMOTE -dtime_script 0 "; 334 $post_commandA .= " -dbname $dbname " if defined $dbname; 335 336 my $post_commandB = "echo -n \"$post_commandA\" > ${remote_outroot}.${class_id}.dbinfo "; 337 my $post_commandC = "ppStatsFromMetadata ${remote_outroot}.${class_id}.stats - CHIP_IMFILE >> ${remote_outroot}.${class_id}.dbinfo"; 338 339 # push @post_commands, "$post_commandB $post_commandC"; 340 341 $job_index++; 342 343 print CONFIG "${pre_command} && ${ppImage_command} && ${post_commandB} && ${post_commandC}"; 344 345 346 # Determine which output files need to be returned. 347 foreach my $component (@return_component_list) { 348 # uri_convert_and_create( $ipprc->filename($component, $ipp_outroot, $class_id) ); 349 my $filename = $ipprc->filename($component, $ipp_outroot, $class_id); 350 my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename ); 351 my $remote_outroot_dir = dirname($ipp_disk); 352 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk "; 353 # print " $filename $ipp_disk $remote_disk\n"; 354 # die; 355 } 356 357 print CONFIG "\n"; 358 } 359 } 360 361 # Actually put the commands into the output file. 362 # my %unique_cmds = (); 363 # foreach my $cmd (@pre_commands) { 364 # unless(exists($unique_cmds{$cmd})) { 365 # print CONFIG $cmd . "\n"; 366 # $unique_cmds{$cmd} = 1; 367 # } 368 # } 369 # foreach my $cmd (@main_commands) { 370 # unless(exists($unique_cmds{$cmd})) { 371 # print CONFIG $cmd . "\n"; 372 # $unique_cmds{$cmd} = 1; 373 # } 374 # } 375 # foreach my $cmd (@post_commands) { 376 # unless(exists($unique_cmds{$cmd})) { 377 # print CONFIG $cmd . "\n"; 378 # $unique_cmds{$cmd} = 1; 379 # } 380 # } 233 ($ipp_btt, $remote_btt) = uri_to_outputs_raw($btt); 234 235 # Initialize the ppI command 236 my $ppImage_command = "ppImage -file $remote_uri"; 237 $ppImage_command .= " -burntool $remote_btt "; 238 239 foreach my $det_type (keys (%det_types)) { 240 if (( $video_cells) && ($det_type eq 'DARK')) { next; } 241 if ((!$video_cells) && ($det_type eq 'VIDEODARK')) { next; } 242 243 my $det_id = $det_ids{$det_type}; 244 my $det_iter = $det_iters{$det_type}; 245 246 if (not defined $det_id) { next; } 247 248 if ($verbose) { print STDERR "det_type, det_id, det_iter: $det_type, $det_id, $det_iter\n"; } 249 250 # Add detrend information to the command line 251 my $detselect_command = "detselect -select "; 252 $detselect_command .= " -det_id $det_id"; 253 $detselect_command .= " -iteration $det_iter"; 254 $detselect_command .= " -class_id $class_id"; 255 $detselect_command .= " -dbname $dbname " if defined($dbname); 256 257 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 258 run(command => $detselect_command, verbose => $dbverbose); 259 260 unless ($success) { 261 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 262 263 &my_die("No valid detrend available for this image: $det_type $det_id $det_iter", $remote_id, $chip_id, $error_code, $fail_state); 264 } 265 266 my $detMDlist = $mdcParser->parse(join "", @$stdout_buf) or 267 &my_die("Could not parse detrend information for this image: $det_type $det_id $det_iter", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 268 my $detImfileMD = parse_md_list($detMDlist); 269 my $detImfile = $detImfileMD->[0]; 270 my $duri = $detImfile->{uri}; 271 272 my $det_code = $det_types{$det_type}; 273 my ($ipp_det_uri, $remote_det_uri) = uri_to_outputs_raw($duri); 274 $ppImage_command .= " $det_code $remote_det_uri "; 275 } 276 277 # Add output root 278 my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.ch.${chip_id}"; 279 my $remote_outroot = uri_local_to_remote($ipp_outroot); 280 $ppImage_command .= " $remote_outroot "; 281 print STDERR "$remote_outroot $ipp_outroot $class_id\n"; 282 # Complete reduction information. 283 $reduction = 'DEFAULT' unless defined $reduction; 284 my $recipe_ppImage = $ipprc->reduction($reduction, 'CHIP_PPIMAGE'); # Recipe to use for ppImage 285 my $recipe_psphot = $ipprc->reduction($reduction, 'CHIP_PSPHOT'); # Recipe to use for psphot 286 287 $ppImage_command .= " -recipe PPIMAGE $recipe_ppImage "; 288 $ppImage_command .= " -recipe PSPHOT $recipe_psphot "; 289 $ppImage_command .= " -recipe PPSTATS CHIPSTATS -stats ${remote_outroot}.${class_id}.stats "; 290 $ppImage_command .= " -threads $threads_req "; 291 $ppImage_command .= " -image_id $chip_imfile_id "; 292 $ppImage_command .= " -tracedest ${remote_outroot}.${class_id}.trace "; 293 $ppImage_command .= " -log ${remote_outroot}.${class_id}.log "; 294 295 # Calculate pre and post commands 296 my $remote_outroot_dir = dirname($remote_outroot); 297 my $pre_command = "mkdir -p $remote_outroot_dir"; 298 299 my $post_commandA = "chiptool -addprocessedimfile -exp_id $exp_id -chip_id $chip_id -class_id $class_id "; 300 $post_commandA .= " -uri ${ipp_outroot}.ch.${class_id}.ch.fits -path_base $ipp_outroot "; 301 $post_commandA .= " -magicked 0 -hostname $remote_hostname -dtime_script 0 "; 302 $post_commandA .= " -dbname $dbname " if defined $dbname; 303 304 my $post_commandB = "echo -n \"$post_commandA\" > ${remote_outroot}.${class_id}.dbinfo "; 305 my $post_commandC = "ppStatsFromMetadata ${remote_outroot}.${class_id}.stats - CHIP_IMFILE >> ${remote_outroot}.${class_id}.dbinfo"; 306 307 $job_index++; 308 309 print CONFIG "${pre_command} && ${ppImage_command} && ${post_commandB} && ${post_commandC}"; 310 311 # Determine which output files need to be returned. 312 foreach my $component (@return_component_list) { 313 my $filename = $ipprc->filename($component, $ipp_outroot, $class_id); 314 my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename ); 315 my $remote_outroot_dir = dirname($ipp_disk); 316 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk "; 317 } 318 print CONFIG "\n"; 319 } 320 } 381 321 382 322 close(CONFIG); … … 386 326 close(GENERATE); 387 327 388 #389 # Construct the moab command last, so we can use the job_index counter to estimate resources. Somehow.390 my $proc_need = $job_index * $threads; # how many total processors do we need?391 my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?392 my $time_need = $job_index * $job_cost; # How many seconds will this take?393 394 my $fill_factor = 0.8; # This is the factor of how much of the time allocation we'd like to fill395 my ($time_req,$node_req);396 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {397 $time_req = $min_time;398 $node_req = $min_nodes;399 }400 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {401 $time_req = $max_time;402 $node_req = $max_nodes;403 print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job. This exceeds the max limits ($max_nodes, $max_time). Using those max values instead. Good luck.\n";404 }405 else {406 $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;407 $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;408 }409 $time_req += 1; # Safety addition.410 411 open(COMMAND, ">$disk_command") || &my_die("Couldn't open file? $disk_command",$chip_id,$PS_EXIT_SYS_ERROR);412 print COMMAND "#!/bin/tcsh\n";413 print COMMAND "##### Moab controll lines\n";414 print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES415 print COMMAND "#MSUB -j oe\n";416 print COMMAND "#MSUB -V\n";417 print COMMAND "#MSUB -o ${remote_root}chip.${remote_id}.out\n";418 print COMMAND "date\n";419 print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";420 print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 1' . "\n";421 #print COMMAND "validate_processing.pl ${remote_root}chip.${remote_id}.out\n";422 print COMMAND "date\n";423 close(COMMAND);424 425 426 328 ## We're done here. The execution and handling are done elsewhere. 427 329 # Quick review: … … 429 331 # auth 430 332 unless($no_update) { 431 my $command = "remotetool -updaterun -remote_id $remote_id "; 432 $command .= " -set_state pending "; 333 my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $chip_id "; 334 $command .= " -set_jobs $job_index"; 335 $command .= " -set_path_base $path_base"; 336 $command .= " -set_state prep_done"; 433 337 $command .= " -dbname $dbname " if defined $dbname; 434 338 435 339 system($command); 436 340 } 437 438 439 440 441 341 exit (0); 442 342 443 343 sub uri_convert { … … 445 345 my $ipp_disk= $ipprc->file_resolve( $neb_uri ); 446 346 my $remote_disk = $ipp_disk; 447 347 448 348 unless(defined($ipp_disk)) { 449 my_die();349 &my_die( "Unable to generate file for $neb_uri ", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 450 350 } 451 351 … … 461 361 my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1); 462 362 my $remote_disk = $ipp_disk; 463 363 464 364 unless(defined($ipp_disk)) { 465 my_die();365 &my_die( "Unable to generate file for $neb_uri ", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 466 366 } 467 367 … … 476 376 my $neb_uri = shift; 477 377 my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri ); 478 479 unless (exists($file_filter{$neb_uri})) { 480 $file_filter{$neb_uri} = 1; 481 print TRANSFER "$ipp_disk\n"; 482 print CHECK "$remote_disk\n"; 483 } 378 379 print TRANSFER "$ipp_disk\n"; 380 print CHECK "$remote_disk\n"; 484 381 return($ipp_disk,$remote_disk); 485 382 } … … 489 386 my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri ); 490 387 $remote_disk = $remote_raw . $ipp_disk; 491 unless (exists($file_filter{$neb_uri})) { 492 $file_filter{$neb_uri} = 1; 493 print TRANSFER "$ipp_disk\n"; 494 print CHECK "$remote_disk\n"; 495 } 388 389 print TRANSFER "$ipp_disk\n"; 390 print CHECK "$remote_disk\n"; 496 391 return($ipp_disk,$remote_disk); 497 392 } … … 500 395 my $neb_uri = shift; 501 396 my ($ipp_disk, $remote_disk) = uri_convert_and_create( $neb_uri ); 502 unless (exists($file_filter{$neb_uri})) { 503 $file_filter{$neb_uri} = 1; 504 print RETURN "$ipp_disk\n"; 505 print GENERATE "$remote_disk\n"; 506 } 397 print RETURN "$ipp_disk\n"; 398 print GENERATE "$remote_disk\n"; 507 399 return($ipp_disk,$remote_disk); 508 400 } … … 518 410 return($remote_uri); 519 411 } 520 412 521 413 sub uri_remote_to_local { 522 414 # This needs to replace the remote root directory with the nebulous tag. … … 524 416 $remote_uri =~ s%${remote_root}%%; 525 417 my $local_uri = "neb:///" . $remote_uri; 526 418 527 419 return($local_uri); 528 420 } 421 529 422 sub my_die { 530 423 my $msg = shift; 531 my $id = shift; 424 my $remote_id = shift; 425 my $stage_id = shift; 532 426 my $exit_code = shift; 533 427 my $exit_state = shift; … … 536 430 537 431 carp($msg); 538 539 if (defined $id and not $no_update) { 540 my $command = "remotetool -updaterun -remote_id $id"; 541 $command .= " -fault $exit_code " if defined $exit_code; 542 $command .= " -set_state $exit_state " if defined $exit_state; 543 $command .= " -dbname $dbname " if defined $dbname; 544 545 system($command); 432 433 if (defined $remote_id and defined $stage_id and not $no_update) { 434 my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id"; 435 $command .= " -set_state $exit_state " if defined $exit_state; 436 $command .= " -dbname $dbname " if defined $dbname; 437 438 system($command); 546 439 } 547 440 -
trunk/ippScripts/scripts/sc_prepare_stack.pl
r37195 r37833 1 1 #! /usr/bin/env perl 2 3 # generate the input & output files lists and commands for a single stackRun 2 4 3 5 use Carp; … … 16 18 use Pod::Usage qw( pod2usage ); 17 19 18 19 20 # Hard coded values 20 #my $remote_root = '/scratch3/watersc1/'; # Far side destination base location 21 my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location 22 $remote_root = '/scratch3/watersc1/'; 23 my $threads = 2; # How many threads are we going to use? 24 my $job_cost = 1500 / 60 / 60; # Estimate of how long a job runs, in hours. 25 my $proc_per_node = 24; # processors per node 26 my $min_nodes = 1; # smallest allocation to ask for 27 my $max_nodes = 1000; # largest allocation to ask for 28 my $min_time = 1; # shortest allocation to ask for 29 my $max_time = 8; # longest allocation to ask for 30 my $remote_hostname = "LANL/Mustang"; # Name of the remote node. 31 my @return_component_list = ("DBINFO.EXP", "PPSTACK.UNCONV","PPSTACK.UNCONV.MASK","PPSTACK.UNCONV.VARIANCE", 32 "PPSTACK.UNCONV.EXP","PPSTACK.UNCONV.EXPWT","PPSTACK.UNCONV.EXPNUM","PSPHOT.OUTPUT", 33 "LOG.EXP", "PSASTRO.STATS", 34 "PPSTACK.CONFIG","PPSTACK.TARGET.PSF","PSPHOT.STACK.PSF.SAVE"); 35 #,"PPSTACK.CONV.KERNEL"); 21 # my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location 22 my $remote_root = '/scratch3/watersc1/'; # Far side destination base location 23 my $remote_hostname = "LANL/Mustang"; # Name of the remote node. 24 my $threads_req = 4; # How many threads are we going to use? 25 26 my $fail_state = "prep_fail"; 27 36 28 # Look for programs we need 37 29 my $missing_tools; 38 39 30 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1); 40 my $stacktool = can_run('stacktool') or (warn "Can't find warptool" and $missing_tools = 1);31 my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1); 41 32 42 33 if ($missing_tools) { … … 48 39 GetOptions( 49 40 'remote_id=s' => \$remote_id, 41 'stack_id=s' => \$stack_id, 50 42 'camera|c=s' => \$camera, 51 43 'dbname|d=s' => \$dbname, … … 56 48 57 49 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 58 pod2usage( -msg => "Required options: --remote_id -- camera --dbname --path_base", -exitval => 3) unless50 pod2usage( -msg => "Required options: --remote_id --stack_id --camera --dbname --path_base", -exitval => 3) unless 59 51 defined($remote_id) and 52 defined($stack_id) and 60 53 defined($camera) and 61 54 defined($path_base) and 62 55 defined($dbname); 63 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id); 56 57 my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $stack_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 64 58 65 59 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 66 60 67 # 68 # Step 1: Get a list of the components that make up this remoteRun 69 70 # SHould this call listrun to ensure we're in state new? 71 my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id"; 72 $rt_cmd .= " -dbname $dbname " if defined($dbname); 73 74 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 75 run(command => $rt_cmd, verbose => $verbose); 76 unless ($success) { 77 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 78 &my_die("Unable to run remotetool to determine stage parameters.", 79 $remote_id,$error_code); 80 } 81 my $compData = $mdcParser->parse(join "", @$stdout_buf) or 82 &my_die("Unable to determine component information.", 83 $remote_id,$PS_EXIT_PROG_ERROR); 84 my $compData2= parse_md_list($compData); 85 86 # 87 # Step 1b: Open output files 88 my $uri_command = $path_base . ".cmd"; 61 my @return_component_list = ("DBINFO.EXP", "PPSTACK.UNCONV","PPSTACK.UNCONV.MASK","PPSTACK.UNCONV.VARIANCE", 62 "PPSTACK.UNCONV.EXP","PPSTACK.UNCONV.EXPWT","PPSTACK.UNCONV.EXPNUM", 63 "PSPHOT.OUT.CMF.MEF", # Use this output product to get the one that exists. 64 "LOG.EXP", "PSASTRO.STATS", 65 "PPSTACK.CONFIG","PPSTACK.TARGET.PSF","PSPHOT.STACK.PSF.SAVE"); 66 #,"PPSTACK.CONV.KERNEL"); 67 68 # STEP 0: Open output files 89 69 my $uri_transfer= $path_base . ".transfer"; 90 70 my $uri_check = $path_base . ".check"; … … 93 73 my $uri_return = $path_base . ".return"; 94 74 95 my $disk_command = $ipprc->file_resolve($uri_command,1);96 75 my $disk_transfer= $ipprc->file_resolve($uri_transfer,1); 97 76 my $disk_check = $ipprc->file_resolve($uri_check,1); … … 100 79 my $disk_return = $ipprc->file_resolve($uri_return,1); 101 80 102 my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it. 103 104 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer",$remote_id,$PS_EXIT_SYS_ERROR); 105 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check",$remote_id,$PS_EXIT_SYS_ERROR); 106 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config",$remote_id,$PS_EXIT_SYS_ERROR); 107 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id,$PS_EXIT_SYS_ERROR); 108 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $PS_EXIT_SYS_ERROR); 109 110 111 # 112 # Step 2: Iterate over all componenets in this remote run. 81 my (undef, $remote_config) = &uri_convert($uri_config); # Needs to be done after we've created it. 82 83 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer",$remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state); 84 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state); 85 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state); 86 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state); 87 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state); 88 113 89 my $job_index = 0; 114 my @pre_commands = (); 115 my @main_commands = (); 116 my @post_commands = (); 117 my %file_filter = (); 118 119 120 foreach my $compEntry (@$compData2) { 121 my $stack_id = $compEntry->{stage_id}; 122 123 # Get exposure level information from the stackRun we're working from. 124 my $run_command = "$stacktool -tosum -stack_id $stack_id"; 125 $run_command .= " -dbname $dbname " if defined($dbname); 126 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 127 run(command => $run_command, verbose => 0); 90 91 # STEP 1: Get exposure level information from the stackRun we're working from. 92 my ($reduction, $workdir, $tess_id, $skycell_id); 93 { 94 my $command = "$stacktool -tosum -stack_id $stack_id"; 95 $command .= " -dbname $dbname " if defined($dbname); 96 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 97 run(command => $command, verbose => $verbose); 128 98 unless ($success) { 129 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 130 &my_die("Unable to run stacktool -tosum ", 131 $stack_id,$error_code); 132 } 133 134 my $stackData = $mdcParser->parse(join "", @$stdout_buf) or 135 &my_die("Unable to determine stack component information.", 136 $stack_id,$PS_EXIT_PROG_ERROR); 137 my $stackData2= parse_md_list($stackData); 138 139 my $stack = ${ $stackData2 }[0]; 140 my $reduction = $stack->{reduction}; 99 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 100 &my_die("Unable to run stacktool -tosum ", $remote_id, $stack_id, $error_code, $fail_state); 101 } 102 103 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 104 &my_die("Unable to determine stack component information.", $remote_id, $stack_id, $PS_EXIT_PROG_ERROR, $fail_state); 105 my $metadata = parse_md_list($MDlist); 106 107 my $stack = $metadata->[0]; 108 109 $reduction = $stack->{reduction}; 141 110 $reduction = 'DEFAULT' unless defined($reduction); 142 my $workdir = $stack->{workdir}; 143 my $tess_id = $stack->{tess_id}; 144 my $skycell_id= $stack->{skycell_id}; 145 146 my $ipp_outroot = "${workdir}/${tess_id}/${skycell_id}/${tess_id}.${skycell_id}.stk.${stack_id}"; 147 my $remote_outroot = uri_local_to_remote($ipp_outroot); 148 my $remote_outdir = uri_local_to_remote("${workdir}/${tess_id}/${skycell_id}"); 111 $workdir = $stack->{workdir}; 112 $tess_id = $stack->{tess_id}; 113 $skycell_id= $stack->{skycell_id}; 114 } 115 my $ipp_outroot = "${workdir}/${tess_id}/${skycell_id}/${tess_id}.${skycell_id}.stk.${stack_id}"; 116 my $remote_outroot = &uri_local_to_remote($ipp_outroot); 117 my $remote_outdir = &uri_local_to_remote("${workdir}/${tess_id}/${skycell_id}"); 118 119 # STEP 2: Get the list of input warps 120 my ($warpData); 121 { 149 122 # This actually returns all the individual stack/skyfiles that comprise this run. Because consistency. 150 123 my $command = "$stacktool -inputskyfile -stack_id $stack_id "; 151 124 $command .= " -dbname $dbname " if defined($dbname); 152 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =153 run(command => $command, verbose => 0);125 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 126 run(command => $command, verbose => $verbose); 154 127 unless ($success) { 155 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 156 &my_die("Unable to run stacktool -inputskyfile ", 157 $stack_id,$error_code); 158 } 159 160 my $warpData = $mdcParser->parse(join "", @$stdout_buf) or 161 &my_die("Unable to determine stack component information.", 162 $stack_id,$PS_EXIT_PROG_ERROR); 163 my $warpData2= parse_md_list($warpData); 164 165 # 166 # Step 3: Iterate over the sub-components 128 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 129 &my_die("Unable to run stacktool -inputskyfile ", $remote_id, $stack_id, $error_code, $fail_state); 130 } 131 132 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 133 &my_die("Unable to determine stack component information.", $remote_id, $stack_id, $PS_EXIT_PROG_ERROR, $fail_state); 134 $warpData = parse_md_list($MDlist); 135 } 136 137 # STEP 3: Iterate over the sub-components 138 { 139 # Generate a file mapping the symbolic and "disk" representations of each needed file. 140 my $uri_compmap = "${ipp_outroot}.compmap"; 141 my $component_map = $ipprc->file_resolve($uri_compmap,1); 142 my ($ipp_compmap, $remote_compmap) = &uri_to_outputs($component_map); 143 open(COMPMAP,">$ipp_compmap") || &my_die("Couldn't open file? $ipp_compmap", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state); 144 145 # Loop over all needed components for this stack. 167 146 my $warp_path_base_string = ""; 168 foreach my $warpEntry ( @{ $warpData2 } ) { 169 my $warp_path_base = $warpEntry->{path_base}; 170 my $remote_path_base = uri_local_to_remote($warp_path_base); 171 $warp_path_base_string .= " $remote_path_base "; 172 173 # Append file names to transfer lists so we can recover if warps are deleted. 174 uri_to_outputs($warp_path_base . ".fits"); 175 uri_to_outputs($warp_path_base . ".wt.fits"); 176 uri_to_outputs($warp_path_base . ".mask.fits"); 177 uri_to_outputs($warp_path_base . ".cmf"); 178 # uri_to_outputs($warp_path_base . ".psf"); 179 } 180 my $mk_mdc_command = "mkdir -p $remote_outdir && sc_mk_stack_mdc.pl $warp_path_base_string > ${remote_outroot}.in.mdc"; 181 my $recipe_ppstack = $ipprc->reduction($reduction, 'STACK_PPSTACK'); # Recipe to use 147 foreach my $warpEntry ( @{ $warpData } ) { 148 my $warp_path_base = $warpEntry->{path_base}; 149 my $remote_path_base = &uri_local_to_remote($warp_path_base); 150 $warp_path_base_string .= " $remote_path_base "; 151 152 if ($verbose) { print STDERR "$warp_path_base_string\n"; } 153 154 # Append file names to transfer lists so we can recover if warps are deleted. 155 my $remote_file; 156 my $ipp_disk; 157 # ${remote_root}/tmp/${ipp_disk} 158 (undef,$remote_file) = &uri_to_outputs($warp_path_base . ".fits"); 159 ($ipp_disk,undef) = &uri_convert($warp_path_base . ".fits"); 160 print COMPMAP "$remote_file ${remote_root}/tmp/${ipp_disk}\n"; 161 (undef,$remote_file) = &uri_to_outputs($warp_path_base . ".wt.fits"); 162 ($ipp_disk,undef) = &uri_convert($warp_path_base . ".wt.fits"); 163 print COMPMAP "$remote_file ${remote_root}/tmp/${ipp_disk}\n"; 164 (undef,$remote_file) = &uri_to_outputs($warp_path_base . ".mask.fits"); 165 ($ipp_disk,undef) = &uri_convert($warp_path_base . ".mask.fits"); 166 print COMPMAP "$remote_file ${remote_root}/tmp/${ipp_disk}\n"; 167 (undef,$remote_file) = &uri_to_outputs($warp_path_base . ".cmf"); 168 ($ipp_disk,undef) = &uri_convert($warp_path_base . ".cmf"); 169 print COMPMAP "$remote_file ${remote_root}/tmp/${ipp_disk}\n"; 170 (undef,$remote_file) = &uri_to_outputs($warp_path_base . ".psf"); 171 ($ipp_disk,undef) = &uri_convert($warp_path_base . ".psf"); 172 print COMPMAP "$remote_file ${remote_root}/tmp/${ipp_disk}\n"; 173 } 174 175 close(COMPMAP); 176 177 my $mk_mdc_command = "mkdir -p $remote_outdir && sc_mk_stack_mdc.pl --compmap ${remote_root}/tmp/${component_map} $warp_path_base_string > ${remote_outroot}.in.mdc"; 178 my $recipe_ppstack = $ipprc->reduction($reduction, 'STACK_PPSTACK'); # Recipe to use 182 179 my $ppstack_command = " ppStack -input ${remote_outroot}.in.mdc "; 183 180 $ppstack_command .= " ${remote_outroot} -stats ${remote_outroot}.stats "; … … 191 188 $ppstack_command .= " -R PPSTACK.UNCONV.VARIANCE FITS.TYPE COMP_STACK"; 192 189 $ppstack_command .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log "; 193 $ppstack_command .= " -threads 4";190 $ppstack_command .= " -threads $threads_req "; 194 191 $ppstack_command .= " -dumpconfig ${remote_outroot}.mdc "; 195 192 $ppstack_command .= " -stack_id $stack_id -skycell_id $skycell_id -tess_id $tess_id "; … … 199 196 $post_cmd_echo .= " -dbname $dbname " if defined $dbname; 200 197 $post_cmd_echo .= " -hostname $remote_hostname -dtime_script 0 \" > ${remote_outroot}.dbinfo "; 201 198 202 199 my $post_cmd_SfM = " ppStatsFromMetadata ${remote_outroot}.stats - STACK_SKYCELL >> ${remote_outroot}.dbinfo "; 203 200 … … 207 204 # Determine which output files need to be returned 208 205 foreach my $component(@return_component_list) { 209 my $filename = $ipprc->filename($component,$ipp_outroot); 210 my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename); 211 my $remote_outroot_dir = dirname($ipp_disk); 212 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk "; 213 } 214 215 # my $cleanup_cmd = " (rm -f /scratch3/watersc1/sys_temp/${tess_id}.${skycell_id}.stk.${stack_id}.*conv.*.fits || true) "; 216 # print CONFIG " && ${cleanup_cmd} \n"; 217 206 my $filename = $ipprc->filename($component,$ipp_outroot); 207 my ($ipp_disk, $remote_disk) = &uri_to_outputs_for_return( $filename); 208 my $remote_outroot_dir = dirname($ipp_disk); 209 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk "; 210 } 218 211 print CONFIG "\n"; 219 212 } … … 224 217 close(GENERATE); 225 218 226 #227 # Construct the moab command last, so we can use the job_index counter to estimate resources. Somehow.228 my $proc_need = $job_index * $threads; # how many total processors do we need?229 my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?230 my $time_need = $job_index * $job_cost; # How many seconds will this take?231 232 my $fill_factor = 0.8; # This is the factor of how much of the time allocation we'd like to fill233 my ($time_req,$node_req);234 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {235 $time_req = $min_time;236 $node_req = $min_nodes;237 }238 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {239 $time_req = $max_time;240 $node_req = $max_nodes;241 print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job. This exceeds the max limits ($max_nodes, $max_time). Using those max values instead. Good luck.\n";242 }243 else {244 $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;245 $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;246 }247 248 $time_req += 2;249 $node_req *= 3;250 open(COMMAND, ">$disk_command") || &my_die("Couldn't open file? $disk_command",$remote_id,$PS_EXIT_SYS_ERROR);251 print COMMAND "#!/bin/tcsh\n";252 print COMMAND "##### Moab controll lines\n";253 print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES254 print COMMAND "#MSUB -j oe\n";255 print COMMAND "#MSUB -V\n";256 print COMMAND "#MSUB -o ${remote_root}stack.${remote_id}.out\n";257 print COMMAND "date\n";258 print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";259 print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 3' . "\n";260 print COMMAND "date\n";261 close(COMMAND);262 263 219 unless($no_update) { 264 my $command = "remotetool -updaterun -remote_id $remote_id "; 265 $command .= " -set_state pending "; 220 my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stack_id "; 221 $command .= " -set_jobs $job_index"; 222 $command .= " -set_path_base $path_base"; 223 $command .= " -set_state prep_done"; 266 224 $command .= " -dbname $dbname " if defined $dbname; 267 225 … … 269 227 } 270 228 271 272 229 ## Common SC routines 273 230 231 # KEEP 274 232 sub uri_convert { # (ipp_disk,remote_disk) = uri_convert(neb_uri); 275 233 my $neb_uri = shift; 276 234 my $ipp_disk= $ipprc->file_resolve( $neb_uri ); 277 235 my $remote_disk = $ipp_disk; 278 236 279 237 unless(defined($ipp_disk)) { 280 my_die();238 &my_die( "Unable to generate file for $neb_uri ", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state); 281 239 } 282 240 … … 288 246 } 289 247 248 # KEEP 290 249 sub uri_convert_and_create { # (ipp_disk,remote_disk) = uri_convert_and_create(neb_uri); ipp_disk is created if it doesn't exist 291 250 my $neb_uri = shift; 292 251 my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1); 293 252 my $remote_disk = $ipp_disk; 294 253 295 254 unless(defined($ipp_disk)) { 296 my_die();255 &my_die( "Unable to generate file for $neb_uri ", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state); 297 256 } 298 257 … … 304 263 } 305 264 265 # KEEP 306 266 sub uri_to_outputs { # (ipp_disk,remote_disk) = uri_to_output(neb_uri); Appends to TRANSFER and CHECK filehandles 307 267 my $neb_uri = shift; 308 268 my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri ); 309 310 unless (exists($file_filter{$neb_uri})) { 311 $file_filter{$neb_uri} = 1; 312 print TRANSFER "$ipp_disk\n"; 313 print CHECK "$remote_disk\n"; 314 } 269 270 print TRANSFER "$ipp_disk\n"; 271 print CHECK "$remote_disk\n"; 315 272 return($ipp_disk,$remote_disk); 316 273 } 317 274 275 # KEEP 318 276 sub uri_to_outputs_for_return { # (ipp_disk,remote_disk) = uri_to_outputs_for_return(neb_uri); create ipp_disk, append to RETURN and GENERATE 319 277 my $neb_uri = shift; 320 278 my ($ipp_disk, $remote_disk) = uri_convert_and_create( $neb_uri ); 321 unless (exists($file_filter{$neb_uri})) { 322 $file_filter{$neb_uri} = 1; 323 print RETURN "$ipp_disk\n"; 324 print GENERATE "$remote_disk\n"; 325 } 279 280 print RETURN "$ipp_disk\n"; 281 print GENERATE "$remote_disk\n"; 326 282 return($ipp_disk,$remote_disk); 327 283 } 328 284 285 # KEEP 329 286 sub uri_local_to_remote { #(remote_uri) = uri_local_to_remote(local_neb_uri); 330 287 # This needs to replace the nebulous tag with the remote root. … … 337 294 return($remote_uri); 338 295 } 339 340 sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri);341 # This needs to replace the remote root directory with the nebulous tag.342 my $remote_uri = shift;343 $remote_uri =~ s%${remote_root}%%;344 my $local_uri = "neb:///" . $remote_uri;345 346 return($local_uri);347 }348 349 296 350 297 sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status); 351 298 my $msg = shift; 352 my $id = shift; 299 my $remote_id = shift; 300 my $stage_id = shift; 353 301 my $exit_code = shift; 354 302 my $exit_state = shift; … … 357 305 358 306 carp($msg); 359 360 if (defined $id and not $no_update) { 361 my $command = "remotetool -updaterun -remote_id $id"; 362 $command .= " -fault $exit_code " if defined $exit_code; 307 308 if (defined $remote_id and defined $stage_id and not $no_update) { 309 my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id"; 363 310 $command .= " -set_state $exit_state " if defined $exit_state; 364 311 $command .= " -dbname $dbname " if defined $dbname; -
trunk/ippScripts/scripts/sc_prepare_warp.pl
r37154 r37833 1 1 #! /usr/bin/env perl 2 3 # generate the input & output files lists and commands for a single warpRun 2 4 3 5 use Carp; … … 16 18 use Pod::Usage qw( pod2usage ); 17 19 18 19 20 # Hard coded values 20 # my $remote_root = '/scratch3/watersc1/'; 21 my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location 22 $remote_root = '/scratch3/watersc1/'; 23 my $threads = 2; # How many threads are we going to use? 24 my $job_cost = 110 / 60 / 60; # Estimate of how long a job runs, in hours. 25 my $proc_per_node = 24; # processors per node 26 my $min_nodes = 1; # smallest allocation to ask for 27 my $max_nodes = 1000; # largest allocation to ask for 28 my $min_time = 1; # shortest allocation to ask for 29 my $max_time = 8; # longest allocation to ask for 30 my $remote_hostname= "LANL/Mustang"; # Name of the remote node. 31 my @return_component_list = ("DBINFO.EXP", "PSWARP.CONFIG", "PSWARP.OUTPUT", "PSWARP.OUTPUT.MASK", "PSWARP.OUTPUT.VARIANCE", "PSWARP.OUTPUT.SOURCES","PSPHOT.PSF.SKY.SAVE","LOG.EXP"); 21 # my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location 22 my $remote_root = '/scratch3/watersc1/'; 23 my $remote_hostname = "LANL/Mustang"; # Name of the remote node. 24 my $threads_req = 4; # How many threads are we going to use? 25 26 my $fail_state = "prep_fail"; 27 32 28 # Look for programs we need 33 29 my $missing_tools; 34 35 30 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1); 36 31 my $warptool = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1); … … 41 36 } 42 37 43 my ($remote_id,$warp_id, ,$camera,$dbname,$verbose,$path_base,$no_update);38 my ($remote_id,$warp_id,$camera,$dbname,$verbose,$path_base,$no_update); 44 39 GetOptions( 45 40 'remote_id=s' => \$remote_id, 41 'warp_id=s' => \$warp_id, 46 42 'camera|c=s' => \$camera, 47 43 'dbname|d=s' => \$dbname, … … 52 48 53 49 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 54 pod2usage( -msg => "Required options: --remote_id - -camera --dbname --path_base", -exitval => 3) unless50 pod2usage( -msg => "Required options: --remote_id -warp_id --camera --dbname --path_base", -exitval => 3) unless 55 51 defined($remote_id) and 52 defined($warp_id) and 56 53 defined($camera) and 57 54 defined($path_base) and 58 55 defined($dbname); 59 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $warp_id); 56 57 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id, $warp_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 60 58 61 59 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 62 60 63 # 64 # Step 1: Get a list of the components that make up this remoteRun 65 66 # SHould this call listrun to ensure we're in state new? 67 my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id"; 68 $rt_cmd .= " -dbname $dbname " if defined($dbname); 69 70 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 71 run(command => $rt_cmd, verbose => $verbose); 72 unless ($success) { 73 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 74 &my_die("Unable to run remotetool to determine stage parameters.", 75 $remote_id,$error_code); 76 } 77 my $compData = $mdcParser->parse(join "", @$stdout_buf) or 78 &my_die("Unable to determine component information.", 79 $remote_id,$PS_EXIT_PROG_ERROR); 80 my $compData2= parse_md_list($compData); 81 82 # 83 # Step 1b: Open output files 84 my $uri_command = $path_base . ".cmd"; 61 my @return_component_list = ("DBINFO.EXP", "PSWARP.CONFIG", "PSWARP.OUTPUT", "PSWARP.OUTPUT.MASK", "PSWARP.OUTPUT.VARIANCE", "PSWARP.OUTPUT.SOURCES","PSPHOT.PSF.SKY.SAVE","LOG.EXP"); 62 63 # STEP 0: Open output files 85 64 my $uri_transfer= $path_base . ".transfer"; 86 65 my $uri_check = $path_base . ".check"; … … 89 68 my $uri_return = $path_base . ".return"; 90 69 91 my $disk_command = $ipprc->file_resolve($uri_command,1);92 70 my $disk_transfer= $ipprc->file_resolve($uri_transfer,1); 93 71 my $disk_check = $ipprc->file_resolve($uri_check,1); … … 96 74 my $disk_return = $ipprc->file_resolve($uri_return,1); 97 75 98 my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it. 99 100 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer",$remote_id,$PS_EXIT_SYS_ERROR); 101 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check",$remote_id,$PS_EXIT_SYS_ERROR); 102 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config",$remote_id,$PS_EXIT_SYS_ERROR); 103 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id,$PS_EXIT_SYS_ERROR); 104 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $PS_EXIT_SYS_ERROR); 105 106 107 # 108 # Step 2: Iterate over all componenets in this remote run. 76 my (undef, $remote_config) = &uri_convert($uri_config); # Needs to be done after we've created it. 77 78 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer",$remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state); 79 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state); 80 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state); 81 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state); 82 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state); 83 109 84 my $job_index = 0; 110 my @pre_commands = (); 111 my @main_commands = (); 112 my @post_commands = (); 113 114 my %file_filter = (); 115 116 foreach my $compEntry (@$compData2) { 117 my $warp_id = $compEntry->{stage_id}; 118 119 # Get exposure level information from the warpRun we're working from. 85 86 # STEP 1: Get exposure level information from the warpRun we're working from. 87 my ($warpData); 88 { 120 89 # This actually returns all the individual warp/skyfiles that comprise this run. Because consistency. 121 90 my $command = "$warptool -towarped -warp_id $warp_id "; 122 91 $command .= " -dbname $dbname " if defined($dbname); 123 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 124 run(command => $command, verbose => 0); 92 93 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 94 run(command => $command, verbose => $verbose); 125 95 unless ($success) { 126 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 127 &my_die("Unable to run warptool -pendingimfile ", 128 $warp_id,$error_code); 129 } 130 my $warpData = $mdcParser->parse(join "", @$stdout_buf) or 131 &my_die("Unable to determine warp component information.", 132 $warp_id,$PS_EXIT_PROG_ERROR); 133 my $warpData2= parse_md_list($warpData); 134 135 # 136 # Step 3: Iterate over the sub-components 137 foreach my $warpEntry ( @{ $warpData2 } ) { 138 my $workdir = $warpEntry->{workdir}; 139 my $exp_tag = $warpEntry->{exp_tag}; 140 my $skycell_id = $warpEntry->{skycell_id}; 141 my $tess_id = $warpEntry->{tess_id}; 142 my $reduction = 'DEFAULT' unless defined $warpEntry->{reduction}; 143 my $recipe_pswarp = $ipprc->reduction($reduction, 'WARP_PSWARP'); # Recipe to use 144 my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.wrp.${warp_id}.${skycell_id}"; 145 print "$ipp_outroot\n"; 146 my $remote_outroot = uri_local_to_remote($ipp_outroot); 147 148 my $reg_command = "$warptool -scmap -warp_id $warp_id -skycell_id ${skycell_id}"; 149 $reg_command .= " -dbname $dbname " if defined($dbname); 150 151 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 152 run(command => $reg_command, verbose => 0); 153 unless ($success) { 154 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 155 &my_die("Unable to run warptool -pendingimfile: $reg_command ", 156 $warp_id,$error_code); 157 } 158 159 my $inpData = $mdcParser->parse(join "", @$stdout_buf) or 160 &my_die("Unable to determine warp component information.", 161 $warp_id, $PS_EXIT_PROG_ERROR); 162 my $inpData2=parse_md_list($inpData); 163 164 my $pre_cmd_ims = "ls -1 "; 165 my $pre_cmd_masks= "ls -1 "; 166 my $pre_cmd_vars = "ls -1 "; 167 my $pre_cmd_astrom = ""; 168 169 foreach my $imfile (@{ $inpData2 }) { 170 my $image = $ipprc->filename("PPIMAGE.CHIP", $imfile->{chip_path_base}, $imfile->{class_id}); 171 my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id}); 172 my $var = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id}); 173 174 my $astrom= $ipprc->filename("PSASTRO.OUTPUT", $imfile->{cam_path_base}); 175 176 my $remote_image = uri_local_to_remote($image); 177 my $remote_mask = uri_local_to_remote($mask); 178 my $remote_var = uri_local_to_remote($var); 179 my $remote_astrom= uri_local_to_remote($astrom); 180 181 $pre_cmd_ims .= " $remote_image "; 182 $pre_cmd_masks .= " $remote_mask "; 183 $pre_cmd_vars .= " $remote_var "; 184 $pre_cmd_astrom = "echo $remote_astrom > ${remote_outroot}.astrom "; 185 } 186 $pre_cmd_ims .= " > ${remote_outroot}.imlist "; 187 $pre_cmd_masks .= " > ${remote_outroot}.masklist "; 188 $pre_cmd_vars .= " > ${remote_outroot}.varlist "; 189 190 my $skycell_command = " dvoImageExtract -D CATDIR /turquoise/usr/projects/ps1/watersc1/tess/${tess_id} $skycell_id -o ${remote_outroot}.skyfile "; 191 192 my $pswarp_command = " pswarp -list ${remote_outroot}.imlist "; 193 $pswarp_command .= " -masklist ${remote_outroot}.masklist -variancelist ${remote_outroot}.varlist "; 194 $pswarp_command .= " -astromlist ${remote_outroot}.astrom "; 195 $pswarp_command .= " ${remote_outroot} ${remote_outroot}.skyfile "; 196 $pswarp_command .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE "; 197 $pswarp_command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF "; 198 $pswarp_command .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF "; 199 $pswarp_command .= " -F SOURCE.PLOT.MOMENTS SOURCE.PLOT.SKY.MOMENTS "; 200 $pswarp_command .= " -F SOURCE.PLOT.PSFMODEL SOURCE.PLOT.SKY.PSFMODEL "; 201 $pswarp_command .= " -F SOURCE.PLOT.APRESID SOURCE.PLOT.SKY.APRESID "; 202 $pswarp_command .= " -recipe PSWARP $recipe_pswarp "; 203 $pswarp_command .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log "; 204 $pswarp_command .= " -threads 4 "; # -image_id ${image_id} -source_id ${source_id} "; 205 $pswarp_command .= " -recipe PPSTATS WARPSTATS "; 206 $pswarp_command .= " -dumpconfig ${remote_outroot}.pswarp.mdc -stats ${remote_outroot}.stats "; 207 208 # print "$pswarp_command \n"; 209 210 my $post_cmd_echo = " echo -n \"warptool -addwarped -warp_id $warp_id -skycell_id $skycell_id -tess_id $tess_id "; 211 $post_cmd_echo .= " -path_base $remote_outroot -uri UNKNOWN "; 212 $post_cmd_echo .= " -dbname $dbname " if defined $dbname; 213 $post_cmd_echo .= " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 \" > ${remote_outroot}.dbinfo "; 214 215 my $post_cmd_SfM = " ppStatsFromMetadata ${remote_outroot}.stats - WARP_SKYCELL >> ${remote_outroot}.dbinfo "; 216 217 print CONFIG "${pre_cmd_ims} && ${pre_cmd_masks} && ${pre_cmd_vars} && ${pre_cmd_astrom} && ${skycell_command} && ${pswarp_command} && ${post_cmd_echo} && ${post_cmd_SfM} "; 218 $job_index++; 219 220 # Determine which output files need to be returned 221 foreach my $component(@return_component_list) { 222 my $filename = $ipprc->filename($component,$ipp_outroot,$skycell_id); 223 my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename); 224 my $remote_outroot_dir = dirname($ipp_disk); 225 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk "; 226 } 227 228 print CONFIG "\n"; 229 # die(); 96 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 97 &my_die("Unable to run warptool -pendingimfile ", $remote_id, $warp_id, $error_code, $fail_state); 98 } 99 100 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 101 &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state); 102 $warpData = parse_md_list($MDlist); 103 } 104 105 # STEP 2: Iterate over the sub-components 106 { 107 foreach my $warpEntry ( @{ $warpData } ) { 108 my $workdir = $warpEntry->{workdir}; 109 my $exp_tag = $warpEntry->{exp_tag}; 110 my $skycell_id = $warpEntry->{skycell_id}; 111 my $tess_id = $warpEntry->{tess_id}; 112 113 my $reduction = $warpEntry->{reduction}; 114 $reduction = 'DEFAULT' unless defined $warpEntry->{reduction}; 115 116 my $recipe_pswarp = $ipprc->reduction($reduction, 'WARP_PSWARP'); # Recipe to use 117 if ($recipe_pswarp eq "") { 118 &my_die("Unable to determine PSWARP recipe for $reduction", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state); 119 } 120 121 my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.wrp.${warp_id}.${skycell_id}"; 122 print "$ipp_outroot\n"; 123 my $remote_outroot = &uri_local_to_remote($ipp_outroot); 124 125 my $command = "$warptool -scmap -warp_id $warp_id -skycell_id ${skycell_id}"; 126 $command .= " -dbname $dbname " if defined($dbname); 127 128 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 129 run(command => $command, verbose => $verbose); 130 unless ($success) { 131 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 132 &my_die("Unable to run warptool -pendingimfile: $command ", $remote_id, $warp_id, $error_code, $fail_state); 133 } 134 135 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 136 &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state); 137 my $inData = parse_md_list($MDlist); 138 139 my $pre_cmd_ims = "ls -1 "; 140 my $pre_cmd_masks= "ls -1 "; 141 my $pre_cmd_vars = "ls -1 "; 142 my $pre_cmd_astrom = ""; 143 144 foreach my $imfile (@{ $inData }) { 145 my $image = $ipprc->filename("PPIMAGE.CHIP", $imfile->{chip_path_base}, $imfile->{class_id}); 146 my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id}); 147 my $var = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id}); 148 149 my $astrom= $ipprc->filename("PSASTRO.OUTPUT", $imfile->{cam_path_base}); 150 151 my $remote_image = &uri_local_to_remote($image); 152 my $remote_mask = &uri_local_to_remote($mask); 153 my $remote_var = &uri_local_to_remote($var); 154 my $remote_astrom= &uri_local_to_remote($astrom); 155 156 $pre_cmd_ims .= " $remote_image "; 157 $pre_cmd_masks .= " $remote_mask "; 158 $pre_cmd_vars .= " $remote_var "; 159 $pre_cmd_astrom = "echo $remote_astrom > ${remote_outroot}.astrom "; 160 } 161 $pre_cmd_ims .= " > ${remote_outroot}.imlist "; 162 $pre_cmd_masks .= " > ${remote_outroot}.masklist "; 163 $pre_cmd_vars .= " > ${remote_outroot}.varlist "; 164 165 my $skycell_command = " dvoImageExtract -D CATDIR /turquoise/usr/projects/ps1/watersc1/tess/${tess_id} $skycell_id -o ${remote_outroot}.skyfile "; 166 167 my $pswarp_command = " pswarp -list ${remote_outroot}.imlist "; 168 $pswarp_command .= " -masklist ${remote_outroot}.masklist -variancelist ${remote_outroot}.varlist "; 169 $pswarp_command .= " -astromlist ${remote_outroot}.astrom "; 170 $pswarp_command .= " ${remote_outroot} ${remote_outroot}.skyfile "; 171 $pswarp_command .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE "; 172 $pswarp_command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF "; 173 $pswarp_command .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF "; 174 $pswarp_command .= " -F SOURCE.PLOT.MOMENTS SOURCE.PLOT.SKY.MOMENTS "; 175 $pswarp_command .= " -F SOURCE.PLOT.PSFMODEL SOURCE.PLOT.SKY.PSFMODEL "; 176 $pswarp_command .= " -F SOURCE.PLOT.APRESID SOURCE.PLOT.SKY.APRESID "; 177 $pswarp_command .= " -recipe PSWARP $recipe_pswarp "; 178 $pswarp_command .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log "; 179 $pswarp_command .= " -threads $threads_req "; # -image_id ${image_id} -source_id ${source_id} "; 180 $pswarp_command .= " -recipe PPSTATS WARPSTATS "; 181 $pswarp_command .= " -dumpconfig ${remote_outroot}.pswarp.mdc -stats ${remote_outroot}.stats "; 182 183 # print "$pswarp_command \n"; 184 185 my $post_cmd_echo = " echo -n \"warptool -addwarped -warp_id $warp_id -skycell_id $skycell_id -tess_id $tess_id "; 186 $post_cmd_echo .= " -dbname $dbname " if defined $dbname; 187 $post_cmd_echo .= " -uri ${ipp_outroot}.fits "; 188 $post_cmd_echo .= " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 \" > ${remote_outroot}.dbinfo "; 189 190 my $post_cmd_SfM = " ppStatsFromMetadata ${remote_outroot}.stats - WARP_SKYCELL >> ${remote_outroot}.dbinfo "; 191 192 print CONFIG "${pre_cmd_ims} && ${pre_cmd_masks} && ${pre_cmd_vars} && ${pre_cmd_astrom} && ${skycell_command} && ${pswarp_command} && ${post_cmd_echo} && ${post_cmd_SfM} "; 193 $job_index++; 194 195 # Determine which output files need to be returned 196 foreach my $component(@return_component_list) { 197 my $filename = $ipprc->filename($component,$ipp_outroot,$skycell_id); 198 my ($ipp_disk, $remote_disk) = &uri_to_outputs_for_return( $filename); 199 my $remote_outroot_dir = dirname($ipp_disk); 200 print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk "; 201 } 202 print CONFIG "\n"; 203 # die(); 230 204 } 231 205 } … … 236 210 close(GENERATE); 237 211 238 #239 # Construct the moab command last, so we can use the job_index counter to estimate resources. Somehow.240 my $proc_need = $job_index * $threads; # how many total processors do we need?241 my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?242 my $time_need = $job_index * $job_cost; # How many seconds will this take?243 244 my $fill_factor = 0.8; # This is the factor of how much of the time allocation we'd like to fill245 my ($time_req,$node_req);246 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {247 $time_req = $min_time;248 $node_req = $min_nodes;249 }250 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {251 $time_req = $max_time;252 $node_req = $max_nodes;253 print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job. This exceeds the max limits ($max_nodes, $max_time). Using those max values instead. Good luck.\n";254 }255 else {256 $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;257 $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;258 }259 $time_req += 1; # Safety addition.260 261 open(COMMAND, ">$disk_command") || &my_die("Couldn't open file? $disk_command",$remote_id,$PS_EXIT_SYS_ERROR);262 print COMMAND "#!/bin/tcsh\n";263 print COMMAND "##### Moab controll lines\n";264 print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES265 print COMMAND "#MSUB -j oe\n";266 print COMMAND "#MSUB -V\n";267 print COMMAND "#MSUB -o ${remote_root}warp.${remote_id}.out\n";268 print COMMAND "date\n";269 print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";270 print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 1' . "\n";271 print COMMAND "date\n";272 close(COMMAND);273 274 212 unless($no_update) { 275 my $command = "remotetool -updaterun -remote_id $remote_id "; 276 $command .= " -set_state pending "; 213 my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $warp_id "; 214 $command .= " -set_jobs $job_index"; 215 $command .= " -set_path_base $path_base"; 216 $command .= " -set_state prep_done"; 277 217 $command .= " -dbname $dbname " if defined $dbname; 278 218 279 219 system($command); 280 220 } 281 221 exit (0); 282 222 283 223 ## Common SC routines … … 287 227 my $ipp_disk= $ipprc->file_resolve( $neb_uri ); 288 228 my $remote_disk = $ipp_disk; 289 229 290 230 unless(defined($ipp_disk)) { 291 my_die();231 &my_die( "Unable to generate file for $neb_uri ", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state); 292 232 } 293 233 … … 303 243 my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1); 304 244 my $remote_disk = $ipp_disk; 305 245 306 246 unless(defined($ipp_disk)) { 307 my_die();247 &my_die( "Unable to generate file for $neb_uri ", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state); 308 248 } 309 249 … … 317 257 sub uri_to_outputs { # (ipp_disk,remote_disk) = uri_to_output(neb_uri); Appends to TRANSFER and CHECK filehandles 318 258 my $neb_uri = shift; 319 my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri ); 320 321 unless (exists($file_filter{$neb_uri})) { 322 $file_filter{$neb_uri} = 1; 323 print TRANSFER "$ipp_disk\n"; 324 print CHECK "$remote_disk\n"; 325 } 259 my ($ipp_disk, $remote_disk) = &uri_convert( $neb_uri ); 260 261 print TRANSFER "$ipp_disk\n"; 262 print CHECK "$remote_disk\n"; 326 263 return($ipp_disk,$remote_disk); 327 264 } … … 329 266 sub uri_to_outputs_for_return { # (ipp_disk,remote_disk) = uri_to_outputs_for_return(neb_uri); create ipp_disk, append to RETURN and GENERATE 330 267 my $neb_uri = shift; 331 my ($ipp_disk, $remote_disk) = uri_convert_and_create( $neb_uri ); 332 unless (exists($file_filter{$neb_uri})) { 333 $file_filter{$neb_uri} = 1; 334 print RETURN "$ipp_disk\n"; 335 print GENERATE "$remote_disk\n"; 336 } 268 my ($ipp_disk, $remote_disk) = &uri_convert_and_create( $neb_uri ); 269 270 print RETURN "$ipp_disk\n"; 271 print GENERATE "$remote_disk\n"; 337 272 return($ipp_disk,$remote_disk); 338 273 } … … 348 283 return($remote_uri); 349 284 } 350 285 351 286 sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri); 352 287 # This needs to replace the remote root directory with the nebulous tag. … … 354 289 $remote_uri =~ s%${remote_root}%%; 355 290 my $local_uri = "neb:///" . $remote_uri; 356 291 357 292 return($local_uri); 358 293 } … … 361 296 sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status); 362 297 my $msg = shift; 363 my $id = shift; 298 my $remote_id = shift; 299 my $stage_id = shift; 364 300 my $exit_code = shift; 365 301 my $exit_state = shift; … … 368 304 369 305 carp($msg); 370 371 if (defined $id and not $no_update) { 372 my $command = "remotetool -updaterun -remote_id $id"; 373 $command .= " -fault $exit_code " if defined $exit_code; 306 307 if (defined $remote_id and defined $stage_id and not $no_update) { 308 my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id"; 374 309 $command .= " -set_state $exit_state " if defined $exit_state; 375 310 $command .= " -dbname $dbname " if defined $dbname; -
trunk/ippScripts/scripts/sc_remote_exec.pl
- Property svn:mergeinfo changed
r37812 r37833 1 #!/usr/bin/env perl 1 #!/usr/bin/env perl 2 2 3 3 use Carp; … … 16 16 # Hard coded values 17 17 my $DMZ_HOST = 'wtrw'; 18 my $SEC_HOST = 'mu-fe'; 18 my @SEC_HOSTS= ('mu-fe1','mu-fe2','mu-fe3' 19 # ,'mu-fe4' 20 ); 21 my $SEC_HOST = $SEC_HOSTS[int(rand(@SEC_HOSTS))]; # 'mu-fe'; 19 22 my $IPP_PATH = '/turquoise/usr/projects/cosmo/mswarren/ipp/'; 20 23 my $remote_root = '/scratch3/watersc1/'; … … 32 35 33 36 # Options 34 my ($remote_id,$path_base,$policy,$poll,$force,$job_id,$dbname,$verbose,$no_update,$camera); 35 $force = 0; 37 my ($remote_id,$job_id,$path_base,$dbname,$verbose,$no_update,$camera); 36 38 $verbose = 0; 37 39 GetOptions( 38 40 'remote_id=s' => \$remote_id, 39 'job_id=s' => \$job_id,40 41 'path_base=s' => \$path_base, 41 'policy=s' => \$policy,42 'poll' => \$poll,43 'force-poll' => \$force,44 42 'camera=s' => \$camera, 45 43 'dbname=s' => \$dbname, … … 54 52 55 53 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id); 56 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 54 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 57 55 58 56 # Phase 1: See if we can actually do anything. … … 69 67 unless ($rt_success) { 70 68 $rt_error_code = (($rt_error_code >> 8) or $PS_EXIT_PROG_ERROR); 71 &my_die("UNable to run remotetool to determine remote run status", 72 $remote_id,$rt_error_code); 73 } 74 my $rrData = $mdcParser->parse(join "", @$rt_stdout_buf) or 75 &my_die("UNable to run remotetool to determine remote run status", 76 $remote_id,$rt_error_code); 69 &my_die("Unable to run remotetool to determine remote run status", $remote_id, $rt_error_code); 70 } 71 my $rrData = $mdcParser->parse(join "", @$rt_stdout_buf) or 72 &my_die("Unable to run remotetool to determine remote run status", $remote_id, $rt_error_code); 77 73 my $rrData2 = parse_md_list($rrData); 78 74 my $runData = ${ $rrData2 }[0]; # There should be only one 79 75 80 # These are operations we only need to do on the first call, not on subsequent poll operations. 81 unless ($poll) { 76 my ($remote_path) = &uri_local_to_remote($path_base); 77 print "REMOTE PATH: $remote_path\n"; 78 82 79 # Phase 2: Ensure files are in place: 83 80 # Copy command files 84 my @files = (); 85 86 my $uri_command = $path_base . ".cmd"; 87 my $uri_transfer= $path_base . ".transfer"; 88 my $uri_check = $path_base . ".check"; 89 my $uri_config = $path_base . ".config"; 90 my $uri_generate= $path_base . ".generate"; 91 my $uri_return = $path_base . ".return"; 92 93 my $disk_command = $ipprc->file_resolve($uri_command); 94 my $disk_transfer= $ipprc->file_resolve($uri_transfer); 95 my $disk_check = $ipprc->file_resolve($uri_check); 96 my $disk_config = $ipprc->file_resolve($uri_config); 97 my $disk_generate= $ipprc->file_resolve($uri_generate); 98 my $disk_return = $ipprc->file_resolve($uri_return); 99 100 scp_put($disk_command,uri_local_to_remote($uri_command)); 101 scp_put($disk_transfer,uri_local_to_remote($uri_transfer)); 102 scp_put($disk_check,uri_local_to_remote($uri_check)); 103 scp_put($disk_config,uri_local_to_remote($uri_config)); 104 scp_put($disk_generate,uri_local_to_remote($uri_generate)); 105 scp_put($disk_return, uri_local_to_remote($uri_return)); 106 107 # Run check command 108 my (undef,$remote_check) = uri_convert($uri_check); 109 my (undef,$remote_transfer)= uri_convert($uri_transfer); 110 111 my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_check --fetch $remote_transfer"); 112 # We no longer need to parse this output, as it retrieves files itself. 113 foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) { 114 print "$l\n"; 115 } 81 my @files = (); 82 83 my $uri_command = $path_base . ".cmd"; 84 my $uri_transfer= $path_base . ".transfer"; 85 my $uri_check = $path_base . ".check"; 86 my $uri_config = $path_base . ".config"; 87 my $uri_generate= $path_base . ".generate"; 88 my $uri_return = $path_base . ".return"; 89 90 my $disk_command = $ipprc->file_resolve($uri_command); 91 my $disk_transfer= $ipprc->file_resolve($uri_transfer); 92 my $disk_check = $ipprc->file_resolve($uri_check); 93 my $disk_config = $ipprc->file_resolve($uri_config); 94 my $disk_generate= $ipprc->file_resolve($uri_generate); 95 my $disk_return = $ipprc->file_resolve($uri_return); 96 97 &scp_put($disk_command, &uri_local_to_remote($uri_command)); 98 &scp_put($disk_transfer, &uri_local_to_remote($uri_transfer)); 99 &scp_put($disk_check, &uri_local_to_remote($uri_check)); 100 &scp_put($disk_config, &uri_local_to_remote($uri_config)); 101 &scp_put($disk_generate, &uri_local_to_remote($uri_generate)); 102 &scp_put($disk_return, &uri_local_to_remote($uri_return)); 103 104 my $ssh_check_stdout = &ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_path --fetch"); 105 106 # We no longer need to parse this output, as it retrieves files itself. 107 foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) { 108 print "$l\n"; 109 } 116 110 117 111 # Run real command 118 my (undef,$remote_command) = uri_convert($uri_command); 119 my $ssh_exec_stdout = ssh_exec_command("msub -V $remote_command"); 120 if ($#{ $ssh_exec_stdout } != -1) { # Parse the output 121 $job_id = ${ $ssh_exec_stdout }[0]; 122 chomp($job_id); 123 $job_id =~ s/\s+//g; 124 } 125 126 unless(defined($job_id)) { # If we don't have a job_id from this command, it didn't run correctly. 127 &my_die("No job_id returned. Sorry.",$remote_id,$PS_EXIT_PROG_ERROR); 128 } 129 130 # Notify the database that this entry is currently running. 131 my $command = "$remotetool -updaterun -remote_id $remote_id "; 132 $command .= " -set_state run "; 133 $command .= " -job_id $job_id "; 134 $command .= " -dbname $dbname " if defined $dbname; 135 136 system($command); 137 138 } # End of exec phase 139 140 # Check that we have a valid job_id, either from the command line, or from the msub command. 112 my (undef,$remote_command) = &uri_convert($uri_command); 113 my $ssh_exec_stdout = &ssh_exec_command("msub -V $remote_command"); 114 if ($#{ $ssh_exec_stdout } != -1) { # Parse the output 115 $job_id = ${ $ssh_exec_stdout }[0]; 116 chomp($job_id); 117 $job_id =~ s/\s+//g; 118 } 119 141 120 unless(defined($job_id)) { # If we don't have a job_id from this command, it didn't run correctly. 142 &my_die("No job_id returned. Sorry.",$remote_id,$PS_EXIT_PROG_ERROR); 143 } 144 145 146 # Poll the job status? 147 my $poll_count = 0; 148 my $poll_max = 1; # If it isn't finished now, it's unlikely to magically finish in the next five minutes. 149 my $poll_sleep = 60; 150 my $poll_response = 0; 151 my $poll_word = "nothing"; 152 153 if ($force) { 154 $poll_response = 1; 155 $poll_word = "Completed"; 156 } 157 158 while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)&&($force != 1)) { 159 if ($verbose) { 160 print "Polling code. Sleeping. $poll_count of $poll_max $poll_response\n"; 161 } 162 unless ($poll_count == 0) { 163 sleep($poll_sleep); 164 } 165 ($poll_response,$poll_word) = poll_job($job_id); 166 167 if ($poll_response == 1) { # This job has completed 168 last; 169 } 170 elsif ($poll_response == -1) { # This job has an error 171 warn("The job exited incorrectly: $remote_id $job_id $poll_word. Attempting to recover what we can."); 172 $poll_response = 1; # To fool the check later into proceding 173 } 174 $poll_count++; 175 } 176 if ($verbose) { 177 print "Stopped Polling code. $poll_count of $poll_max $poll_response\n"; 178 } 179 if ($poll_response != 1) { 180 &my_die("Job hasn't completed. Ending polling.", $remote_id, 0, "run", $job_id); 181 } 182 183 184 # Initialize the remote side to sync things 185 186 # Once sync completes, execute all the database commands 187 # Grab the return list 188 my $uri_return = $path_base . ".return"; 189 my ($ipp_return,$remote_return) = uri_convert($uri_return); 190 # We shouldn't need to get this file. We made that file. 191 #scp_get($remote_return,$ipp_return); 192 193 # Construct list of dbinfo files we'll need to execute. 194 my @returned_files = (); 195 my @dbinfo_files = (); 196 my @dbindex = (); 197 my $iter = 0; 198 open(RETURN, "$ipp_return") || &my_die("Couldn't open file? $ipp_return", $remote_id,$PS_EXIT_SYS_ERROR); 199 while (<RETURN>) { 200 chomp; 201 push @returned_files, $_; 202 if ($_ =~ /dbinfo/) { 203 push @dbinfo_files, $_; 204 push @dbindex, $iter; 205 } 206 $iter++; 207 208 } 209 close(RETURN); 210 print STDERR "Expect $#dbinfo_files dbinfo files\n"; 211 212 my $first = 0; 213 my $last = $#dbinfo_files; 214 my $mid = 0; 215 my $range = 20; # How wide of a chunk to look through to catch threading drops 216 my $offset = 0; # Offset to start from. 217 218 # Feed the return list into the transfer tool 219 # If this fails, we should go to an auth wait point. 220 if ($poll_word eq 'Completed') { 221 # We're complete. All files should exist on disk 222 my $iter = 0; 223 my $transfer_success = 1; 224 do { 225 $transfer_success = 1; 226 $iter++; 227 check_ssh_connection(); 228 my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset"); 229 my $return_push_output_print = join "\n", @{ $return_push_output }; 230 if ($return_push_output_print =~ /exited with value 255/) { $transfer_success = 0; } 231 print "$return_push_output_print\n"; 232 } while (($transfer_success != 1) && ($iter < 10)); # Try harder; 233 } 234 else { 235 # Just try and fetch things, because we didn't complete correctly, it seems. 236 my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset"); 237 my $return_push_output_print = join "\n", @{ $return_push_output }; 238 print "$return_push_output_print\n"; 239 } 240 241 foreach my $file (@dbinfo_files) { 242 open(DBF,"$file") || warn "Missing file $file\n"; 243 my $cmd = <DBF>; 244 close(DBF); 245 chomp($cmd); 246 # print STDERR "$file $cmd\n"; 247 $cmd =~ s/-/ -/g; # This is just a safety check for missing space. 248 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 249 run(command => $cmd, verbose => $verbose); 250 unless ($success) { 251 252 # This shouldn't fail, but we also can't suddenly abort if something does fail. 253 # Now we're going to drop the component that owns this dbinfo, which should force a retry. 254 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 255 warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code"); 256 if ($poll_word ne 'Completed') { # If the job claims it completed, then we're fighting the network. 257 drop_component($remote_id,$cmd,$file); 258 } 259 } 260 261 } 262 263 # We're done, so set the state and exit. 264 &my_die("Finished",$remote_id,0,"full"); 265 121 &my_die("No job_id returned. Sorry.", $remote_id, $PS_EXIT_PROG_ERROR); 122 } 123 124 # Notify the database that this entry is currently running. 125 &my_die("Finished", $remote_id, 0, "run", $job_id); 266 126 267 127 # END PROGRAM 268 269 128 270 129 sub check_ssh_connection { … … 272 131 273 132 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 274 run(command => $cmd, verbose => $verbose);275 unless ($success) { 276 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);277 &my_die("Authorization check failed.",$remote_id,0,'auth');133 run(command => $cmd, verbose => $verbose); 134 unless ($success) { 135 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 136 &my_die("Authorization check failed.", $remote_id, 0, 'pending'); 278 137 } 279 138 } … … 285 144 286 145 my $directory = dirname($destination); 287 ssh_exec_command("mkdir -p $directory");288 289 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 290 run(command => $cmd, verbose => $verbose);291 unless ($success) { 292 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);293 &my_die(); 146 &ssh_exec_command("mkdir -p $directory"); 147 148 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 149 run(command => $cmd, verbose => $verbose); 150 unless ($success) { 151 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 152 &my_die("failed to send file $file to LANL", $remote_id, $error_code); 294 153 } 295 154 } … … 302 161 303 162 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 304 run(command => $cmd, verbose => $verbose);305 unless ($success) { 306 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);307 &my_die(); 163 run(command => $cmd, verbose => $verbose); 164 unless ($success) { 165 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 166 &my_die("failed to get file $file from LANL", $remote_id, $error_code); 308 167 } 309 168 } … … 311 170 sub ssh_exec_command { 312 171 my $cmd = shift; 313 $cmd = "$ssh $DMZ_HOST ssh ${SEC_HOST} $cmd";172 $cmd = "$ssh -n $DMZ_HOST ssh ${SEC_HOST} $cmd"; 314 173 print "EXEC: $cmd\n"; 315 174 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 316 run(command => $cmd, verbose => $verbose);317 unless ($success) { 318 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);319 # If we failed, see if we failed due to authorization.320 check_ssh_connection(); 321 &my_die("Failed to execute command: >>$cmd<<"); 175 run(command => $cmd, verbose => $verbose); 176 unless ($success) { 177 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 178 # If we failed, see if we failed due to authorization. 179 check_ssh_connection(); 180 &my_die("Failed to execute remote command: >>$cmd<<", $remote_id, $error_code); 322 181 } 323 182 return ($stdout_buf); 324 } 325 326 sub poll_job { 327 my $job_id = shift; 328 my $response_array = ssh_exec_command("checkjob -v $job_id"); 329 my $response = join "\n", @$response_array; 330 331 if ($response =~ /State: Running/) { 332 return(0,"Running"); 333 } 334 elsif ($response =~ /State: Completed/) { 335 return(1,"Completed"); 336 } 337 elsif ($response =~ /State: Idle/) { 338 return(-2,"Idle"); 339 } 340 else { 341 my $response_word = $response; 342 $response_word =~ s/.*State: //; 343 $response_word =~ s/\n.*//; 344 return(-1,$response_word); 345 } 346 } 347 348 183 } 184 185 # neb URI to (ipp_disk,remote_disk) 349 186 sub uri_convert { 350 187 my $neb_uri = shift; 351 188 my $ipp_disk= $ipprc->file_resolve( $neb_uri ); 352 189 my $remote_disk = $ipp_disk; 353 190 354 191 unless(defined($ipp_disk)) { 355 my_die();192 &my_die("Failed to generate or find uri $neb_uri", $remote_id, $PS_EXIT_SYS_ERROR); 356 193 } 357 194 … … 363 200 } 364 201 365 sub uri_to_outputs { 366 my $neb_uri = shift; 367 my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri ); 368 369 # print TRANSFER "$ipp_disk\n"; 370 # print CHECK "$remote_disk\n"; 371 return($ipp_disk,$remote_disk); 372 } 373 202 # neb URI to remote URI-on-disk 374 203 sub uri_local_to_remote { 375 204 # This needs to replace the nebulous tag with the remote root. … … 382 211 return($remote_uri); 383 212 } 384 385 sub uri_remote_to_local {386 # This needs to replace the remote root directory with the nebulous tag.387 my $remote_uri = shift;388 $remote_uri =~ s%${remote_root}%%;389 my $local_uri = "neb:///" . $remote_uri;390 391 return($local_uri);392 }393 394 sub drop_component {395 my $remote_id = shift;396 my $cmd = shift;397 my $file = shift;398 399 if ($cmd eq '') {400 # Zero byte file. This dbinfo was never constructed properly.401 402 # Steal the stage_id from the filename. This isn't something I'm happy about.403 my $stage = $runData->{stage};404 my $stage_id = $file;405 if ($stage eq 'chip') {406 $stage_id =~ s/^.*ch\.//;407 }408 elsif ($stage eq 'camera') {409 $stage_id =~ s/^.*cm\.//;410 }411 elsif ($stage eq 'warp') {412 $stage_id =~ s/^.*wrp\.//;413 }414 elsif ($stage eq 'stack') {415 $stage_id =~ s/^.*stk\.//;416 }417 $stage_id =~ s/\..*$//;418 419 # Drop this from the database420 my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id ";421 $drop_cmd .= " -dbname $dbname " if defined($dbname);422 system($drop_cmd);423 }424 425 }426 213 427 214 sub my_die { … … 434 221 435 222 carp($msg); 436 223 437 224 if (defined $id and not $no_update) { 438 my $command = "$remotetool -updaterun -remote_id $id";439 $command .= " -fault $exit_code " if defined $exit_code;440 $command .= " -job_id $job_id " if defined $jobid;441 $command .= " -set_state $exit_state " if defined $exit_state;442 $command .= " -dbname $dbname " if defined $dbname;443 444 system($command);225 my $command = "$remotetool -updaterun -remote_id $id"; 226 $command .= " -fault $exit_code " if defined $exit_code; 227 $command .= " -job_id $job_id " if defined $jobid; 228 $command .= " -set_state $exit_state " if defined $exit_state; 229 $command .= " -dbname $dbname " if defined $dbname; 230 231 system($command); 445 232 } 446 233 -
trunk/ippScripts/scripts/sc_transfer_tool.pl
r37125 r37833 10 10 use Sys::Hostname; 11 11 12 my $scp_cmd = "/usr/projects/cosmo/amd6100/bin/scp"; 13 my $ssh_cmd = "/usr/projects/cosmo/amd6100/bin/ssh"; 14 12 15 my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; 13 $remote_root = '/scratch3/watersc1/'; 14 my $local_raw = "${remote_root}/raw/"; 16 $remote_root = '/scratch3/watersc1/'; 17 18 #my $local_raw = "${remote_root}/tmp/"; 15 19 my $local_tmp = "${remote_root}/tmp/"; 16 my $threads = 10; 17 my @hosts = ('ippc20.ipp.ifa.hawaii.edu','ippc24.ipp.ifa.hawaii.edu','ippc28.ipp.ifa.hawaii.edu', 18 'ippc21.ipp.ifa.hawaii.edu','ippc25.ipp.ifa.hawaii.edu','ippc29.ipp.ifa.hawaii.edu', 19 'ippc22.ipp.ifa.hawaii.edu','ippc26.ipp.ifa.hawaii.edu', 20 'ippc23.ipp.ifa.hawaii.edu','ippc27.ipp.ifa.hawaii.edu' ); 20 my $threads = 11; 21 my @hosts = ( 22 'ippc20.ipp.ifa.hawaii.edu', 23 'ippc21.ipp.ifa.hawaii.edu', 24 'ippc22.ipp.ifa.hawaii.edu', 25 'ippc23.ipp.ifa.hawaii.edu', 26 'ippc24.ipp.ifa.hawaii.edu', 27 'ippc25.ipp.ifa.hawaii.edu', 28 'ippc26.ipp.ifa.hawaii.edu', 29 'ippc27.ipp.ifa.hawaii.edu', 30 'ippc28.ipp.ifa.hawaii.edu', 31 #'ippc29.ipp.ifa.hawaii.edu', (mark's hi-mem test machine) 32 #'ippc30.ipp.ifa.hawaii.edu', (postage stamp server) 33 'ippc31.ipp.ifa.hawaii.edu', 34 'ippc32.ipp.ifa.hawaii.edu' 35 ); 21 36 @hosts = (@hosts, @hosts, @hosts, @hosts, @hosts); 22 my $input_file; 37 my %server_options = ( 38 'ippc20.ipp.ifa.hawaii.edu' => '', 39 'ippc21.ipp.ifa.hawaii.edu' => '', 40 'ippc22.ipp.ifa.hawaii.edu' => '', 41 'ippc23.ipp.ifa.hawaii.edu' => '', 42 'ippc24.ipp.ifa.hawaii.edu' => '', 43 'ippc25.ipp.ifa.hawaii.edu' => '', 44 'ippc26.ipp.ifa.hawaii.edu' => '', # -o NoneSwitch=yes -o NoneEnabled=yes', 45 'ippc27.ipp.ifa.hawaii.edu' => '', # -o NoneSwitch=yes -o NoneEnabled=yes', 46 'ippc28.ipp.ifa.hawaii.edu' => '', # -o NoneSwitch=yes -o NoneEnabled=yes', 47 'ippc29.ipp.ifa.hawaii.edu' => '', # -o NoneSwitch=yes -o NoneEnabled=yes', 48 'ippc30.ipp.ifa.hawaii.edu' => '', # -o NoneSwitch=yes -o NoneEnabled=yes', 49 'ippc31.ipp.ifa.hawaii.edu' => '', # -o NoneSwitch=yes -o NoneEnabled=yes', 50 'ippc32.ipp.ifa.hawaii.edu' => '', # -o NoneSwitch=yes -o NoneEnabled=yes' 51 ); 52 53 my $input_path; 54 my $local_file; 55 my $remote_file; 56 23 57 my $verbose = 0; 24 58 my $fetch = 0; 25 59 my $offset = 0; 60 my $retry = 0; 61 my $quickfetch = 0; 26 62 27 63 GetOptions( 28 64 'threads=s' => \$threads, 29 'input=s' => \$input_file, 30 'fetch=s' => \$fetch, 65 'input=s' => \$input_path, 31 66 'offset=s' => \$offset, 67 'fetch' => \$fetch, 32 68 'verbose' => \$verbose, 69 'retry' => \$retry, 70 'quickfetch' => \$quickfetch, 33 71 ) or pod2usage( 2 ); 34 72 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2) if @ARGV; 35 73 pod2usage( -msg => "Required options: --input", -exitval => 3) unless 36 defined($input_ file);74 defined($input_path); 37 75 38 76 my $hostname = hostname; … … 41 79 # split in input file list 42 80 unless(-d $local_tmp) { system("mkdir -p $local_tmp"); } 43 unless(-d $local_raw) { system("mkdir -p $local_raw"); } 44 45 open(I,$input_file) || die "Couldn't find input file specified\n"; 81 #unless(-d $local_raw) { system("mkdir -p $local_raw"); } 82 83 # we have two modes: fetch (-> LANL) and return (-> IPP) 84 46 85 if ($fetch) { 47 open(F,$fetch) || die "Couldn't find fetch file specified\n"; 48 } 49 my $input_base = basename($input_file); 50 my @filehandles; 86 $local_file = "$input_path.check"; 87 $remote_file = "$input_path.transfer"; 88 } else { 89 $local_file = "$input_path.generate"; 90 $remote_file = "$input_path.return"; 91 } 92 my $input_base = basename($local_file); 93 94 unless ($retry) { 95 # open the input file list 96 open (LOCAL,$local_file) || die "Couldn't find input file specified $local_file\n"; 97 open (REMOTE,$remote_file) || die "Couldn't find input file specified $remote_file\n"; 98 99 # generate N output files (to be fed to the N rsync / tar threads) 100 my @filehandles; 101 my $i; 102 my $line = 0; 103 for ($i = 0; $i < $threads; $i++) { 104 open($filehandles[$i], ">${local_tmp}/${input_base}.${i}"); 105 } 106 107 unless ($fetch) { 108 my $stat_file = "$input_path.stat"; 109 print "STATFILE: $stat_file\n"; 110 open (STATFILE, ">$stat_file"); 111 } 112 113 $i = 0; 114 while (my $Lname = <LOCAL>) { 115 my $Rname = <REMOTE>; 116 117 chomp $Lname; 118 chomp $Rname; 119 120 $line++; 121 if ($line < $offset) { next; } # I think this is off-by-one in a safe direction 122 123 if ($line % 250 == 0) { print STDERR "line $line : $Lname\n"; } 124 125 $i = int(rand($#filehandles + 1)); 126 if ($i >= $threads) { 127 print STDERR "HUH: impossible file handle?\n"; 128 die; 129 } 130 131 # if we are fetching, and 'quickfetch' is requested, skip file if it exists 132 # NOTE: this does not check that the transfer was complete or the file is current 133 134 if ($fetch) { 135 # We are fetching, and do not already have this file. 136 if ($quickfetch && (-e $Lname)) { next; } 137 print { $filehandles[$i] } "$Rname\n"; 138 } else { 139 # We are pushing, but only send back files we actually have 140 # we cannot have the remote file unless the local file exists 141 # (it is a link to the local file and is generated after the local file) 142 my $haveRemote = -e "$local_tmp/$Rname"; 143 if ($haveRemote) { 144 print { $filehandles[$i] } "$Rname\n"; 145 print STATFILE "$Rname PASS\n"; 146 } else { 147 my $haveLocal = -e $Lname; 148 if ($haveLocal) { 149 print STATFILE "$Rname PART\n"; 150 } else { 151 print STATFILE "$Rname FAIL\n"; 152 } 153 } 154 } 155 } 156 close(LOCAL); 157 close(REMOTE); 158 unless ($fetch) { close(STATFILE); } 159 160 for ($i = 0; $i < $threads; $i++) { 161 close($filehandles[$i]); 162 } 163 } 164 51 165 my $i; 52 my $line = 0; 53 for ($i = 0; $i < $threads; $i++) { 54 open($filehandles[$i], ">${local_tmp}/${input_base}.${i}"); 55 } 56 $i = 0; 57 while(<I>) { 58 chomp; 59 $line++; 60 if ($line < $offset) { next; } # I think this is off-by-one in a safe direction 61 62 $i = int(rand($#filehandles + 1)); 63 64 my $fline; 65 if ($fetch) { 66 $fline = <F>; 67 } 68 if (($fetch)&&(!(-e $_))) { # We are fetching, and do not already have this file. 69 print { $filehandles[$i] } $fline; 70 } 71 elsif (!($fetch)) { # We are pushing 72 # The rsync call expects to find files of a given name in the directory specified. 73 # print { $filehandles[$i] } "${local_tmp}/$_" . "\n"; 74 print { $filehandles[$i] } "$_" . "\n"; 75 } 76 } 77 close(I); 78 79 for ($i = 0; $i < $threads; $i++) { 80 close($filehandles[$i]); 81 } 82 83 # fork the tars 166 # fork the rsync 84 167 my @pids = (); 85 168 for ($i = 0; $i < $threads; $i++) { … … 89 172 my $code = 0; 90 173 if ($fetch) { 91 $code = fetch_task($host,"${input_base}.${i}", 0); 92 } 93 else { 174 $code = fetch_task($host,"${local_tmp}/${input_base}.${i}", 0); 175 } else { 94 176 $code = transfer_task($host,"${local_tmp}/${input_base}.${i}", 0); 95 177 } 178 print STDERR "$host $input_base $i $code\n"; 96 179 exit($code); 97 180 } 98 181 } 182 183 my $global_status = 0; 99 184 for ($i = 0; $i < $threads; $i++) { 100 185 waitpid($pids[$i],0); 186 my $this_status = $?; 187 print "exit status $hosts[$i] : $this_status\n"; 188 if ($this_status) { $global_status = ($this_status >> 8); } 101 189 } 102 190 … … 105 193 } 106 194 195 # my $scp_command = "$scp_cmd $option ${local_tmp}/${input_base}.stat $hosts[0]:/tmp/"; 196 # print "$scp_command\n"; 197 # system("$scp_command"); 198 # XXX check return status 199 200 print "global status: $global_status\n"; 201 exit ($global_status); 107 202 108 203 # distribute bundles to nodes … … 115 210 my $error = shift; 116 211 117 # the transform bit is there because it looks like the ' gets dropped, so the * is interpreted, and why is our tar so out of date?118 # my $command = "tar cf - --ignore-failed-read --dereference --files-from=${transfer_filelist} | /usr/projects/cosmo/amd6100/bin/ssh -o NoneSwitch=yes -o NoneEnabled=yes $destination_host tar xf - -C /data/ --transform '" . 's,^.\*/data/,,' . "' --dereference"; 119 my $command = "rsync -L pt -e '/usr/projects/cosmo/amd6100/bin/ssh -o NoneSwitch=yes -o NoneEnabled=yes' --files-from=${transfer_filelist} ${local_tmp} ${destination_host}:/";212 my $option = $server_options{$destination_host}; 213 214 my $command = "rsync -L --size-only --omit-dir-times -e '$ssh_cmd ${option}' --files-from=${transfer_filelist} ${local_tmp} ${destination_host}:/"; 120 215 print STDERR "$command\n"; 121 216 122 217 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 123 218 run(command => $command, verbose => $verbose); 219 220 my $return_value = 0; 124 221 unless ($success) { 125 print STDERR "ERROR: $error_code\n"; 126 # my $std = join "\n", @{ $stdout_buf }; 127 # print "STDOUT: $std\n"; 128 # $std = join "\n", @{ $stderr_buf }; 129 # print "STDERR: $std\n"; 130 131 # foreach my $line (@{ $stderr_buf }) { # This is a hack. A messy ugly hack. 132 # if ($line =~ /No such file or directory/) { 133 # my $file = (split /\s+/, $line)[1]; 134 # $file =~ s/:$//; 135 # if ($file !~ /nebulous/) { next; } 136 # print STDERR "Touching $file so tar can continue.\n"; 137 # system("touch $file"); 138 # } 139 # } 140 141 warn("Transfer of $transfer_filelist to $destination_host failed with error $error_code."); 142 $error++; 143 if ($error < 4) { 144 $error_code = transfer_task($destination_host,$transfer_filelist,$error); 145 } 146 else { 147 die("Failed too many times $error $destination_host $transfer_filelist"); 222 if ($error_code =~ /value 23/) { 223 print STDERR "Some files failed to transfer. Partial run?\n"; 224 $error = 23; 225 $return_value = 23; 226 } else { 227 print STDERR "ERROR: $error_code\n"; 228 warn("Transfer of $transfer_filelist to $destination_host failed with error $error_code."); 229 sleep(5); 230 $error++; 231 if ($error < 4) { 232 $error_code = transfer_task($destination_host,$transfer_filelist,$error); 233 } 234 else { 235 die("Failed too many times $error $destination_host $transfer_filelist"); 236 } 237 $return_value = 1; 148 238 } 149 239 } 150 return($ error_code);240 return($return_value); 151 241 } 152 242 … … 156 246 my $error = shift; 157 247 158 system("/usr/projects/cosmo/amd6100/bin/scp -o NoneSwitch=yes -o NoneEnabled=yes ${local_tmp}/${transfer_filelist} ${destination_host}:/tmp/"); 159 my $command = "/usr/projects/cosmo/amd6100/bin/ssh -o NoneSwitch=yes -o NoneEnabled=yes $destination_host tar cf - --ignore-failed-read --dereference --files-from=/tmp/${transfer_filelist} | tar xf - -C ${local_raw} --skip-old-files --warning=existing-file --dereference "; 248 my $option = $server_options{$destination_host}; 249 250 my $command = "rsync --size-only -e '$ssh_cmd ${option}' --files-from=${transfer_filelist} ${destination_host}:/ ${local_tmp}"; 160 251 print STDERR "$command\n"; 161 252 162 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 253 my $error_code = 0; 254 my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) = 163 255 run(command => $command, verbose => $verbose); 164 256 unless ($success) { 165 $error_code = (($error_code >> 8) or 4); 166 warn("Transfer of $transfer_filelist to $destination_host failed with error $error_code."); 167 $error++; 168 if ($error < 4) { 169 $error_code = fetch_task($destination_host,$transfer_filelist,$error); 170 } 171 else { 172 die("Failed too many times $error $destination_host $transfer_filelist"); 257 print "raw error_msg: $error_msg...\n"; 258 ($error_code) = $error_msg =~ m/exited with value (\d+)/; 259 warn("Transfer of files in $transfer_filelist from $destination_host failed with error ($error_code) $error_msg."); 260 print "*** stdout: *** \n"; 261 foreach my $line (@$stdout_buf) { 262 print STDERR "stdout: $line\n"; 263 } 264 print "*** stderr: *** \n"; 265 foreach my $line (@$stderr_buf) { 266 print STDERR "stderr: $line\n"; 267 } 268 if ($error_code == 23) { 269 print STDERR "Some files failed to transfer\n"; 270 } else { 271 $error++; 272 if ($error < 4) { 273 $error_code = fetch_task($destination_host,$transfer_filelist,$error); 274 } else { 275 print STDERR "Failed too many times $error $destination_host $transfer_filelist\n"; 276 } 173 277 } 174 278 } -
trunk/ippScripts/scripts/stack_skycell.pl
r36397 r37833 225 225 $num++; 226 226 227 my $image = $file->{uri}; # Image name 227 # my $image = $file->{uri}; # Image name 228 my $image = $ipprc->filename("PSWARP.OUTPUT", $file->{path_base} ); # Image name 228 229 my $mask = $ipprc->filename( "PSWARP.OUTPUT.MASK", $file->{path_base} ); # Mask name 229 230 my $weight = $ipprc->filename( "PSWARP.OUTPUT.VARIANCE", $file->{path_base} ); # Weight name -
trunk/ippTools/share/Makefile.am
r37551 r37833 524 524 remotetool_definebyquery_warp.sql \ 525 525 remotetool_definebyquery_stack.sql \ 526 remotetool_definebyquery_staticsky.sql \ 526 527 remotetool_dropcomponent.sql \ 528 remotetool_listcomponent.sql \ 529 remotetool_doneprep.sql \ 527 530 remotetool_updatepoll.sql -
trunk/ippTools/share/laptool_exposures.sql
- Property svn:mergeinfo set to
-
trunk/ippTools/share/pxadmin_create_tables.sql
r37769 r37833 2385 2385 remote_id BIGINT, 2386 2386 stage_id BIGINT, 2387 jobs INT 2388 state VARCHAR(64) NOT NULL, 2389 path_base VARCHAR(255), 2387 2390 KEY (stage_id), 2388 2391 FOREIGN KEY (remote_id) REFERENCES remoteRun(remote_id) -
trunk/ippTools/share/remotetool_definebyquery_cam.sql
r36968 r37833 11 11 LEFT JOIN 12 12 13 (SELECT remote_id,remoteRun.stage,remoteRun.label,remoteComponent.stage_id,remoteRun.state 14 FROM remoteRun 13 (SELECT remote_id,remoteRun.stage,remoteRun.label,remoteComponent.stage_id,remoteRun.state 14 FROM remoteRun 15 15 JOIN remoteComponent USING (remote_id) 16 16 WHERE 17 remoteRun.stage = 'camera' 17 remoteRun.stage = 'camera' and remoteComponent.state != 'retry' 18 18 -- where hook %s 19 19 ) AS R -
trunk/ippTools/share/remotetool_definebyquery_chip.sql
r36968 r37833 11 11 LEFT JOIN 12 12 13 (SELECT remote_id,remoteRun.stage,remoteRun.label,remoteComponent.stage_id,remoteRun.state 14 FROM remoteRun 13 (SELECT remote_id,remoteRun.stage,remoteRun.label,remoteComponent.stage_id,remoteRun.state 14 FROM remoteRun 15 15 JOIN remoteComponent USING (remote_id) 16 16 WHERE 17 remoteRun.stage = 'chip' 17 remoteRun.stage = 'chip' and remoteComponent.state != 'retry' 18 18 -- where hook %s 19 19 ) AS R … … 24 24 25 25 26 26 -
trunk/ippTools/share/remotetool_definebyquery_stack.sql
r36968 r37833 15 15 JOIN remoteComponent USING (remote_id) 16 16 WHERE 17 remoteRun.stage = 'stack' 17 remoteRun.stage = 'stack' and remoteComponent.state != 'retry' 18 18 -- where hook %s 19 19 ) AS R -
trunk/ippTools/share/remotetool_definebyquery_warp.sql
r36968 r37833 17 17 JOIN remoteComponent USING (remote_id) 18 18 WHERE 19 remoteRun.stage = 'warp' 19 remoteRun.stage = 'warp' and remoteComponent.state != 'retry' 20 20 -- where hook %s 21 21 ) AS R -
trunk/ippTools/src/remotetool.c
r37054 r37833 21 21 static bool listrunMode(pxConfig *config); 22 22 static bool listcomponentMode(pxConfig *config); 23 24 // list remoteRuns with all remoteComponents in state 'prep_done' or 'prep_fail' 25 static bool doneprepMode(pxConfig *config); 23 26 24 27 // Update … … 26 29 static bool updaterunMode(pxConfig *config); 27 30 static bool updatepollMode(pxConfig *config); 31 static bool updatecomponentMode(pxConfig *config); 28 32 static bool revertrunMode(pxConfig *config); 29 33 static bool revertauthMode(pxConfig *config); 34 static bool revertcomponentMode(pxConfig *config); 30 35 31 36 # define MODECASE(caseName, func) \ … … 47 52 48 53 switch (config->mode) { 49 MODECASE(REMOTETOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 50 MODECASE(REMOTETOOL_MODE_LISTRUN, listrunMode); 51 MODECASE(REMOTETOOL_MODE_LISTCOMPONENT, listcomponentMode); 52 MODECASE(REMOTETOOL_MODE_DROPCOMPONENT, dropcomponentMode); 53 MODECASE(REMOTETOOL_MODE_UPDATERUN, updaterunMode); 54 MODECASE(REMOTETOOL_MODE_UPDATEPOLL, updatepollMode); 55 MODECASE(REMOTETOOL_MODE_REVERTRUN, revertrunMode); 56 MODECASE(REMOTETOOL_MODE_REVERTAUTH, revertauthMode); 54 MODECASE(REMOTETOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 55 MODECASE(REMOTETOOL_MODE_LISTRUN, listrunMode); 56 MODECASE(REMOTETOOL_MODE_DONEPREP, doneprepMode); 57 MODECASE(REMOTETOOL_MODE_LISTCOMPONENT, listcomponentMode); 58 MODECASE(REMOTETOOL_MODE_DROPCOMPONENT, dropcomponentMode); 59 MODECASE(REMOTETOOL_MODE_UPDATERUN, updaterunMode); 60 MODECASE(REMOTETOOL_MODE_UPDATEPOLL, updatepollMode); 61 MODECASE(REMOTETOOL_MODE_UPDATECOMPONENT, updatecomponentMode); 62 MODECASE(REMOTETOOL_MODE_REVERTRUN, revertrunMode); 63 MODECASE(REMOTETOOL_MODE_REVERTAUTH, revertauthMode); 64 MODECASE(REMOTETOOL_MODE_REVERTCOMPONENT, revertcomponentMode); 57 65 58 66 default: … … 92 100 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 93 101 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 94 102 95 103 set_label = set_label ? set_label : label; 96 104 … … 105 113 return(false); 106 114 } 107 115 108 116 if (label) { 109 117 psStringAppend(&whereOption, "\n AND (label = '%s')", label); … … 116 124 return(false); 117 125 } 118 126 119 127 if (label) { 120 128 psStringAppend(&whereOption, "\n AND (label = '%s')", label); 121 129 } 122 } 130 } 123 131 else if (!strcmp(stage,"warp")) { 124 132 query = pxDataGet("remotetool_definebyquery_warp.sql"); … … 127 135 return(false); 128 136 } 129 137 130 138 if (label) { 131 139 // Because warp has to check to see if something other than the state is set correctly, I have to use this wonky way to pass the label in. … … 133 141 psStringAppend(&whereOption, "\n AND (label = '%s')", label); 134 142 } 135 } 143 } 136 144 else if (!strcmp(stage,"stack")) { 137 145 query = pxDataGet("remotetool_definebyquery_stack.sql"); … … 140 148 return(false); 141 149 } 142 150 143 151 if (label) { 144 152 psStringAppend(&whereOption, "\n AND (label = '%s')", label); 145 153 } 146 } 154 } 155 else if (!strcmp(stage,"staticsky")) { 156 query = pxDataGet("remotetool_definebyquery_staticsky.sql"); 157 if (!query) { 158 psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement"); 159 return(false); 160 } 161 162 if (label) { 163 psStringAppend(&whereOption, "\n AND (label = '%s')", label); 164 } 165 } 147 166 else { 148 167 psError(PS_ERR_UNKNOWN, true, "unknown value for stage: %s", stage); … … 191 210 // Insert the top level run object 192 211 remoteRunRow *run = remoteRunRowAlloc(0, // remote_id 193 "new", // state194 stage,195 set_label,196 path_base,197 -1, // job_id198 NULL, // last_poll199 0 // fault200 );212 "new", // state 213 stage, 214 set_label, 215 path_base, 216 -1, // job_id 217 NULL, // last_poll 218 0 // fault 219 ); 201 220 if (!run) { 202 psError(PS_ERR_UNKNOWN, false, "failed to alloc lapRun object");221 psError(PS_ERR_UNKNOWN, false, "failed to alloc remoteRun object"); 203 222 return(true); 204 223 } 205 224 206 225 if (!remoteRunInsertObject(config->dbh, run)) { 207 226 if (!psDBRollback(config->dbh)) { … … 213 232 } 214 233 psS64 remote_id = psDBLastInsertID(config->dbh); 215 234 216 235 psArray *list = psArrayAllocEmpty(limit); 217 236 for (long i=0; i < psArrayLength(output); i++) { … … 219 238 psS64 stage_id = psMetadataLookupS64(NULL, md, "stage_id"); 220 239 221 remoteComponentRow *comp = remoteComponentRowAlloc(remote_id, 222 stage_id); 240 remoteComponentRow *comp = remoteComponentRowAlloc(remote_id, stage_id, 0, "new", NULL); 223 241 if (!comp) { 224 psError(PS_ERR_UNKNOWN, false, "failed to alloc lapRunobject");242 psError(PS_ERR_UNKNOWN, false, "failed to alloc remoteComponent object"); 225 243 return(true); 226 244 } 227 245 228 246 if (!remoteComponentInsertObject(config->dbh, comp)) { 229 247 if (!psDBRollback(config->dbh)) { 230 psError(PS_ERR_UNKNOWN, false, "database error");248 psError(PS_ERR_UNKNOWN, false, "database error"); 231 249 } 232 250 psError(PS_ERR_UNKNOWN, false, "database error"); … … 237 255 psArrayAdd(list, list->n, comp); 238 256 psFree(comp); 239 257 240 258 } 241 259 psFree(run); … … 245 263 return false; 246 264 } 247 265 248 266 if (!remoteComponentPrintObjects(stdout, list, !simple)) { 249 267 if (!psDBRollback(config->dbh)) { … … 254 272 return false; 255 273 } 256 274 257 275 psFree(list); 258 276 psFree(output); 259 277 260 278 return true; 261 279 } … … 265 283 { 266 284 psMetadata *where = psMetadataAlloc(); 267 285 268 286 PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "=="); 269 287 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); … … 274 292 PXOPT_COPY_TIME(config->args, where, "-poll_begin", "last_poll", ">="); 275 293 PXOPT_COPY_TIME(config->args, where, "-poll_end", "last_poll", "<="); 276 294 277 295 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 278 296 279 297 PXOPT_LOOKUP_S16(limit, config->args, "-limit", false, false); 280 298 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 281 282 299 283 300 psArray *remRuns = NULL; 284 301 remRuns = psDBSelectRows(config->dbh, "remoteRun", where, limit); 285 302 286 303 if (!ippdbPrintMetadatas(stdout, remRuns, "remoteRun", !simple)) { 287 304 psError(PS_ERR_UNKNOWN, false, "failed to print array"); … … 299 316 300 317 PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "=="); 318 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 319 PXOPT_COPY_S64(config->args, where, "-jobs", "jobs", "=="); 320 321 PXOPT_COPY_STR(config->args, where, "-state", "remoteComponent.state", "=="); 322 PXOPT_COPY_STR(config->args, where, "-label", "remoteRun.label", "=="); 323 301 324 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 302 303 psArray *remComps = NULL; 304 remComps = psDBSelectRows(config->dbh, "remoteComponent", where, 0); 305 306 if (!ippdbPrintMetadatas(stdout, remComps, "remoteComponent", !simple)) { 325 PXOPT_LOOKUP_S16(limit, config->args, "-limit", false, false); 326 327 psString query = pxDataGet("remotetool_listcomponent.sql"); 328 if (!query) { 329 psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement"); 330 return(false); 331 } 332 333 if (psListLength(where->list)) { 334 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 335 psStringAppend(&query, " WHERE %s", whereClause); 336 psFree(whereClause); 337 } 338 psFree(where); 339 340 if (limit) { 341 psString limitString = psDBGenerateLimitSQL(limit); 342 psStringAppend(&query, " %s", limitString); 343 psFree(limitString); 344 } 345 346 if (!p_psDBRunQuery(config->dbh, query)) { 347 psError(PS_ERR_UNKNOWN, false, "database error"); 348 psFree(query); 349 return false; 350 } 351 psFree(query); 352 353 psArray *output = p_psDBFetchResult(config->dbh); 354 if (!output) { 355 psError(PS_ERR_UNKNOWN, false, "database error"); 356 return false; 357 } 358 if (!psArrayLength(output)) { 359 psTrace("remotetool", PS_LOG_INFO, "no rows found"); 360 psFree(output); 361 return true; 362 } 363 364 if (!ippdbPrintMetadatas(stdout, output, "remoteComponent", !simple)) { 307 365 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 308 psFree( remComps);309 return false; 310 } 311 psFree( remComps);366 psFree(output); 367 return false; 368 } 369 psFree(output); 312 370 313 371 return true; 314 372 } 315 373 374 // List 375 static bool doneprepMode(pxConfig *config) 376 { 377 psMetadata *where = psMetadataAlloc(); 378 379 PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "=="); 380 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 381 382 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 383 PXOPT_COPY_STR(config->args, where, "-state", "remoteRun.state", "=="); 384 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 385 386 PXOPT_LOOKUP_S16(limit, config->args, "-limit", false, false); 387 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 388 389 psString query = pxDataGet("remotetool_doneprep.sql"); 390 if (!query) { 391 psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement"); 392 return(false); 393 } 394 395 psString whereDone = NULL; 396 psString whereJobs = NULL; 397 if (psListLength(where->list)) { 398 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 399 psStringAppend(&whereDone, " \n AND %s", whereClause); 400 psStringAppend(&whereJobs, " \n WHERE %s", whereClause); 401 psFree(whereClause); 402 } 403 404 if (limit) { 405 psString limitString = psDBGenerateLimitSQL(limit); 406 psStringAppend(&query, " %s", limitString); 407 psFree(limitString); 408 } 409 410 // fprintf (stderr, "query: %s\n", query); 411 // fprintf (stderr, "whereDone: %s\n", whereDone); 412 // fprintf (stderr, "whereJobs: %s\n", whereJobs); 413 414 if (!p_psDBRunQueryF(config->dbh, query, whereDone, whereJobs)) { 415 psError(PS_ERR_UNKNOWN, false, "database error"); 416 psFree(whereDone); 417 psFree(whereJobs); 418 psFree(query); 419 return false; 420 } 421 psFree(whereDone); 422 psFree(whereJobs); 423 psFree(query); 424 425 psArray *output = p_psDBFetchResult(config->dbh); 426 if (!output) { 427 psError(PS_ERR_UNKNOWN, false, "database error"); 428 return false; 429 } 430 if (!psArrayLength(output)) { 431 psTrace("remotetool", PS_LOG_INFO, "no rows found"); 432 psFree(output); 433 return true; 434 } 435 436 if (!ippdbPrintMetadatas(stdout, output, "remoteRun", !simple)) { 437 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 438 psFree(output); 439 return false; 440 } 441 psFree(output); 442 443 return true; 444 } 445 316 446 // Update 317 447 318 448 static bool dropcomponentMode(pxConfig *config) 319 449 { 450 fprintf (stderr, "do we really want to use -dropcomponent?\n"); 451 exit (1); 452 320 453 // Assert that we have a unique component to operate on. 321 454 PXOPT_LOOKUP_S64(remote_id,config->args, "-remote_id",true, false); … … 329 462 return false; 330 463 } 331 464 332 465 if (!psDBTransaction(config->dbh)) { 333 466 psError(PS_ERR_UNKNOWN, false, "database error"); … … 341 474 } 342 475 psFree(query); 343 344 345 476 346 477 // point of no return … … 349 480 return false; 350 481 } 351 482 352 483 return true; 353 484 } … … 364 495 // Wheres 365 496 PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "=="); 366 497 367 498 // Values to set 368 499 PXOPT_COPY_STR(config->args, values, "-set_label", "label", "=="); … … 374 505 psFree(values); 375 506 376 if (rows < 1) { 377 psError(PS_ERR_UNKNOWN,false, "no rows affected"); 378 return(false); 379 } 380 507 if (rows < 1) fprintf (stderr, "no rows changed (run may already be in desired state)\n"); 381 508 return(true); 382 509 } … … 393 520 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 394 521 psFree(where); 395 522 396 523 psString query = NULL; 397 524 query = pxDataGet("remotetool_updatepoll.sql"); … … 412 539 return(true); 413 540 } 414 415 416 541 542 static bool updatecomponentMode(pxConfig *config) 543 { 544 PS_ASSERT_PTR_NON_NULL(config, false); 545 PXOPT_LOOKUP_S64(remote_id, config->args, "-remote_id", true, false); 546 psAssert(remote_id,"This should have failed before this point."); 547 548 psMetadata *where = psMetadataAlloc(); 549 psMetadata *values = psMetadataAlloc(); 550 551 // Wheres 552 PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "=="); 553 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 554 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 555 556 // Values to set 557 PXOPT_COPY_S32(config->args, values, "-set_jobs", "jobs", "=="); 558 PXOPT_COPY_STR(config->args, values, "-set_path_base", "path_base", "=="); 559 PXOPT_COPY_STR(config->args, values, "-set_state", "state", "=="); 560 561 long rows = psDBUpdateRows(config->dbh, "remoteComponent", where, values); 562 psFree(values); 563 564 if (rows < 1) fprintf (stderr, "no rows changed (component may already be in desired state)\n"); 565 return true; 566 } 417 567 418 568 static bool revertrunMode(pxConfig *config) … … 426 576 PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "=="); 427 577 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 428 578 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 429 579 // Value to set 430 PXOPT_COPY_S16(config->args, values, "-fault", "fault", "=="); 431 long rows = psDBUpdateRows(config->dbh, "remoteRun", where, values); 432 psFree(values); 433 psFree(where); 434 if (rows < 1) { 435 psError(PS_ERR_UNKNOWN,false, "no rows affected"); 436 return(false); 437 } 438 439 return(true); 440 } 441 442 static bool revertauthMode(pxConfig *config) 443 { 444 PS_ASSERT_PTR_NON_NULL(config, false); 445 446 psMetadata *where = psMetadataAlloc(); 447 psMetadata *values = psMetadataAlloc(); 448 449 // required 450 PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "=="); 451 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 452 453 psMetadataAddStr(where, PS_LIST_TAIL, "state", 0, "==", "auth"); 454 455 // Value to set 456 psMetadataAddStr(values, PS_LIST_TAIL, "state", 0, "==", "run"); 580 psMetadataAddS16(values,PS_LIST_TAIL,"fault",0, "==", 0); 457 581 458 582 long rows = psDBUpdateRows(config->dbh, "remoteRun", where, values); … … 466 590 return(true); 467 591 } 468 592 593 static bool revertcomponentMode(pxConfig *config) 594 { 595 PS_ASSERT_PTR_NON_NULL(config,false); 596 psMetadata *where = psMetadataAlloc(); 597 psMetadata *values = psMetadataAlloc(); 598 599 // required 600 PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "=="); 601 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 602 psMetadataAddStr(where,PS_LIST_TAIL,"state",0, "LIKE", "%fail"); 603 604 // value to set 605 psMetadataAddStr(values, PS_LIST_TAIL, "state",0, "==", "retry"); 606 607 608 long rows = psDBUpdateRows(config->dbh, "remoteComponent", where, values); 609 psFree(values); 610 psFree(where); 611 if (rows < 1) { 612 psError(PS_ERR_UNKNOWN,false, "no rows affected"); 613 return(false); 614 } 615 616 return(true); 617 } 618 619 620 621 static bool revertauthMode(pxConfig *config) 622 { 623 PS_ASSERT_PTR_NON_NULL(config, false); 624 625 psMetadata *where = psMetadataAlloc(); 626 psMetadata *values = psMetadataAlloc(); 627 628 // required 629 PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "=="); 630 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 631 632 psMetadataAddStr(where, PS_LIST_TAIL, "state", 0, "==", "auth"); 633 634 // Value to set 635 psMetadataAddStr(values, PS_LIST_TAIL, "state", 0, "==", "run"); 636 637 long rows = psDBUpdateRows(config->dbh, "remoteRun", where, values); 638 psFree(values); 639 psFree(where); 640 if (rows < 1) { 641 psError(PS_ERR_UNKNOWN,false, "no rows affected"); 642 return(false); 643 } 644 645 return(true); 646 } 647 -
trunk/ippTools/src/remotetool.h
r36981 r37833 12 12 REMOTETOOL_MODE_DEFINEBYQUERY, 13 13 REMOTETOOL_MODE_LISTRUN, 14 REMOTETOOL_MODE_DONEPREP, 14 15 REMOTETOOL_MODE_LISTCOMPONENT, 15 16 REMOTETOOL_MODE_DROPCOMPONENT, 16 17 REMOTETOOL_MODE_UPDATERUN, 17 18 REMOTETOOL_MODE_UPDATEPOLL, 18 REMOTETOOL_MODE_REVERTRUN, 19 REMOTETOOL_MODE_REVERTAUTH, 19 REMOTETOOL_MODE_UPDATECOMPONENT, 20 REMOTETOOL_MODE_REVERTRUN, 21 REMOTETOOL_MODE_REVERTAUTH, 22 REMOTETOOL_MODE_REVERTCOMPONENT, 20 23 } remotetoolMode; 21 24 -
trunk/ippTools/src/remotetoolConfig.c
r36981 r37833 40 40 ADD_OPT(Bool, definebyqueryArgs, "-pretend", "pretend to do this.", 0); 41 41 ADD_OPT(Bool, definebyqueryArgs,"-simple", "simple print format",0); 42 42 43 43 // -listrun 44 44 psMetadata *listrunArgs = psMetadataAlloc(); … … 59 59 ADD_OPT(S16, listrunArgs, "-limit", "limit to number of runs to display", 0); 60 60 61 // -doneprep 62 psMetadata *doneprepArgs = psMetadataAlloc(); 63 ADD_OPT(S64, doneprepArgs, "-remote_id", "run to list", 0); 64 ADD_OPT(S64, doneprepArgs, "-job_id", "job_id", 0); 65 ADD_OPT(Str, doneprepArgs, "-stage", "stage to return", NULL); 66 ADD_OPT(Str, doneprepArgs, "-state", "state to return", NULL); 67 ADD_OPT(Str, doneprepArgs, "-label", "remRun label to use", NULL); 68 69 ADD_OPT(Bool, doneprepArgs, "-simple", "simple print format", false); 70 ADD_OPT(S16, doneprepArgs, "-limit", "limit to number of runs to display", 0); 71 72 // -revertcomponent 73 psMetadata *revertcomponentArgs = psMetadataAlloc(); 74 ADD_OPT(S64, revertcomponentArgs, "-remote_id", "run to revert components from", 0); 75 ADD_OPT(S64, revertcomponentArgs, "-stage_id", "component stage_id to revert", 0); 76 77 61 78 // -listcomponents 62 psMetadata *listcomponentArgs = psMetadataAlloc(); 63 ADD_OPT(S64, listcomponentArgs, "-remote_id", "run to list", 0); 64 ADD_OPT(S16, listcomponentArgs, "-limit", "limit to number of runs to display", 0); 79 psMetadata *listcomponentArgs = psMetadataAlloc(); 80 ADD_OPT(S64, listcomponentArgs, "-remote_id", "run to list", 0); 81 ADD_OPT(S64, listcomponentArgs, "-stage_id", "run to list", 0); 82 ADD_OPT(S32, listcomponentArgs, "-jobs", "run to list", 0); 83 ADD_OPT(Str, listcomponentArgs, "-state", "run to list", NULL); 84 ADD_OPT(S16, listcomponentArgs, "-limit", "limit to number of runs to display", 0); 65 85 ADD_OPT(Bool, listcomponentArgs, "-simple", "simple print format", false); 86 ADD_OPT(Str, listcomponentArgs, "-label", "label to use", NULL); 66 87 67 88 // -dropcomponent … … 69 90 ADD_OPT(S64, dropcomponentArgs, "-remote_id", "run to update", 0); 70 91 ADD_OPT(S64, dropcomponentArgs, "-stage_id", "stage_id to remote", 0); 71 92 72 93 // -updaterun 73 94 psMetadata *updaterunArgs = psMetadataAlloc(); … … 83 104 psMetadata *updatepollArgs = psMetadataAlloc(); 84 105 ADD_OPT(S64, updatepollArgs, "-remote_id", "run to update", 0); 85 106 107 // -updatecomponent 108 psMetadata *updatecomponentArgs = psMetadataAlloc(); 109 ADD_OPT(S64, updatecomponentArgs, "-remote_id", "remote_id to update", 0); 110 ADD_OPT(S64, updatecomponentArgs, "-stage_id", "stage_id to update", 0); 111 ADD_OPT(Str, updatecomponentArgs, "-state", "limit to this remoteComponent state", NULL); 112 ADD_OPT(Str, updatecomponentArgs, "-set_state", "remoteComponent state to assign", NULL); 113 ADD_OPT(Str, updatecomponentArgs, "-set_path_base", "remoteRun path_base to assign", NULL); 114 ADD_OPT(S32, updatecomponentArgs, "-set_jobs", "number of jobs for this stage_id", 0); 115 86 116 // -revertrun 87 117 psMetadata *revertrunArgs = psMetadataAlloc(); … … 89 119 ADD_OPT(Str, revertrunArgs, "-label", "remRun label to use", NULL); 90 120 ADD_OPT(S16, revertrunArgs, "-fault", "fault code", 0); 91 121 92 122 // -revertauth 93 123 psMetadata *revertauthArgs = psMetadataAlloc(); … … 98 128 psMetadata *modes = psMetadataAlloc(); 99 129 100 PXOPT_ADD_MODE("-definebyquery", "", REMOTETOOL_MODE_DEFINEBYQUERY, definebyqueryArgs); 101 PXOPT_ADD_MODE("-listrun", "", REMOTETOOL_MODE_LISTRUN, listrunArgs); 102 PXOPT_ADD_MODE("-listcomponent", "", REMOTETOOL_MODE_LISTCOMPONENT, listcomponentArgs); 103 PXOPT_ADD_MODE("-dropcomponent", "", REMOTETOOL_MODE_DROPCOMPONENT, dropcomponentArgs); 104 PXOPT_ADD_MODE("-updaterun", "", REMOTETOOL_MODE_UPDATERUN, updaterunArgs); 105 PXOPT_ADD_MODE("-updatepoll", "", REMOTETOOL_MODE_UPDATEPOLL, updatepollArgs); 106 PXOPT_ADD_MODE("-revertrun", "", REMOTETOOL_MODE_REVERTRUN, revertrunArgs); 107 PXOPT_ADD_MODE("-revertauth", "", REMOTETOOL_MODE_REVERTAUTH, revertauthArgs); 130 PXOPT_ADD_MODE("-definebyquery", "", REMOTETOOL_MODE_DEFINEBYQUERY, definebyqueryArgs); 131 PXOPT_ADD_MODE("-listrun", "", REMOTETOOL_MODE_LISTRUN, listrunArgs); 132 PXOPT_ADD_MODE("-doneprep", "", REMOTETOOL_MODE_DONEPREP, doneprepArgs); 133 PXOPT_ADD_MODE("-listcomponent", "", REMOTETOOL_MODE_LISTCOMPONENT, listcomponentArgs); 134 PXOPT_ADD_MODE("-revertcomponent", "", REMOTETOOL_MODE_REVERTCOMPONENT, revertcomponentArgs); 135 PXOPT_ADD_MODE("-dropcomponent", "", REMOTETOOL_MODE_DROPCOMPONENT, dropcomponentArgs); 136 PXOPT_ADD_MODE("-updaterun", "", REMOTETOOL_MODE_UPDATERUN, updaterunArgs); 137 PXOPT_ADD_MODE("-updatepoll", "", REMOTETOOL_MODE_UPDATEPOLL, updatepollArgs); 138 PXOPT_ADD_MODE("-updatecomponent", "", REMOTETOOL_MODE_UPDATECOMPONENT, updatecomponentArgs); 139 PXOPT_ADD_MODE("-revertrun", "", REMOTETOOL_MODE_REVERTRUN, revertrunArgs); 140 PXOPT_ADD_MODE("-revertauth", "", REMOTETOOL_MODE_REVERTAUTH, revertauthArgs); 108 141 109 142 -
trunk/ippTools/src/stacktool.c
- Property svn:mergeinfo set to
-
trunk/ippTools/src/stacktoolConfig.c
- Property svn:mergeinfo set to
Note:
See TracChangeset
for help on using the changeset viewer.
