IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18541


Ignore:
Timestamp:
Jul 15, 2008, 10:06:26 AM (18 years ago)
Author:
bills
Message:

Significant changes to how requests flow through the system. Improved
fault handling and reporting.

Resolve a request's project into database name. (Hardcoded list in this
program for now. Will move this to a new database table at some point).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstampparse.pl

    r18380 r18541  
    1717my $request_file_name;
    1818my $mode = "list_uri";
    19 my $out_dir = ".";
     19my $out_dir;
     20my $product;
    2021
    2122# values for COORD_MASK
     
    2425
    2526# values for OPTION_MASK
    26 use constant PSTAMP_SELECT_IMAGE => 1;
    27 use constant PSTAMP_SELECT_MASK  => 2;
     27use constant PSTAMP_SELECT_IMAGE  => 1;
     28use constant PSTAMP_SELECT_MASK   => 2;
    2829use constant PSTAMP_SELECT_WEIGHT => 4;
    2930
     
    3233    'req_id=s'  =>  \$req_id,
    3334    'out_dir=s' =>  \$out_dir,
     35    'product=s' =>  \$product,
    3436    'mode=s'    =>  \$mode,
    3537    'dbname=s'  =>  \$dbname,
     
    3739);
    3840
    39 die "req_id is required"   if !defined($req_id);
     41die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "list_job") or ($mode eq "queue_job");
     42die "req_id is required"   if (!defined($req_id) && ($mode ne "list_uri"));
    4043die "file is required"     if !defined($request_file_name);
    4144die "out_dir is required"  if !defined($out_dir);
    42 
    43 die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "list_job") or ($mode eq "queue_job");
     45die "product is required"  if !defined($product);
     46
    4447
    4548use IPC::Cmd 0.36 qw( can_run run );
     
    6669
    6770my $pstamptool  = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
    68 my $pstampparse = can_run('pstampparse') or (warn "Can't find pstampparse" and $missing_tools = 1);
     71my $lookup_images = can_run('pstampparse') or (warn "Can't find pstampparse" and $missing_tools = 1);
    6972my $pstampdump  = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1);
     73my $fields  = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);
    7074
    7175if ($missing_tools) {
     
    7781
    7882#
    79 # convert the request table to an array of metadata config docs
    80 #
    81 # TODO: check the header for the correct EXTNAME
     83# get the data from the extension header
     84#
     85my $fields_output;
     86{
     87    my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME";
     88    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     89        run(command => $command, verbose => $verbose);
     90    unless ($success) {
     91        print STDERR @$stderr_buf;
     92    }
     93    $fields_output = join "", @$stdout_buf;
     94}
     95my (undef, $extname, $extver, $req_name) = split " ", $fields_output;
     96
     97# make sure the file contains what we are expecting
     98
     99die "$request_file_name is not a PS1_PS_REQEST" if $extname ne "PS1_PS_REQUEST";
     100die "REQ_NAME not found in $request_file_name"  if (!$req_name);
     101die "wrong EXTVER $extver found in $request_file_name" if ($extver ne "1");
     102
     103$out_dir .= "/$req_name";
     104if (! -e $out_dir ) {
     105    mkdir $out_dir or die "cannot create output directory $out_dir";
     106} elsif (! -d $out_dir ) {
     107    die "output fileset directory $out_dir exists but is not a directory";
     108}
     109
     110{
     111    my $command = "$pstamptool -processedreq -req_id $req_id -name $req_name -outProduct $product";
     112    $command .= " -dbname $dbname";
     113    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     114        run(command => $command, verbose => $verbose);
     115    unless ($success) {
     116        die "$command failed";
     117    }
     118}
     119
     120#
     121# now convert the request table to an array of metadata config docs
    82122#
    83123
     
    96136}
    97137
    98 # TODO: Make sure that the output directory exists
    99 
    100138foreach my $row (@$rows) {
     139    my $rownum   = $row->{ROWNUM};
    101140    my $job_type = $row->{JOB_TYPE};
    102141    my $project  = $row->{PROJECT};
     
    105144    my $id       = $row->{ID};
    106145    my $class_id = $row->{CLASS_ID};
    107     my $stamp_select = $row->{STAMP_SELECT};
    108146    my $stamp_name   = $row->{STAMP_NAME};
    109147    my $filter   = $row->{FILTER};
     
    117155    my $option_mask= $row->{OPTION_MASK};
    118156
     157    # XXX: TODO: don't die in this loop. If we encounter an error add a job with the proper fault
     158    # code
     159    # todo this needs some implementation work
     160    die "job_type is list_uri but mode is $mode" if ($job_type eq "list_uri") and ($mode ne "list_uri");
     161
     162    # TODO: sanity check all arguments
     163
     164    my ($image_db, $lookup_class_id ) = resolve_project($project, $img_type, $class_id);
     165
    119166    my $roi_string;
    120167    # XXX we're depending on other code to insure valid values for roi components
    121168    # this is checked in pstamprequest and ppstamp
    122     # arguably I should check here to but not today
     169    # I should check here to but not today
    123170    if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) {
    124171        if ($coord_mask & PSTAMP_CENTER_IN_PIXELS) {
     
    140187        if (($job_type eq "stamp") && !defined($roi_string));
    141188
    142     my $args = $roi_string ? $roi_string : "";
    143 
    144189    # find the uris for this request
    145190
     
    147192    # images/runs and prints out the uri and other metadata as a metadata config doc
    148193
    149     my $command = "$pstampparse -dbname $project -$req_type $img_type $id $class_id";
     194    my $command = "$lookup_images -dbname $image_db -$req_type $img_type $id $lookup_class_id";
     195
    150196    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    151197            run(command => $command, verbose => $verbose);
    152198    unless ($success) {
    153199        print STDERR @$stderr_buf;
     200        exit 1;
    154201    }
    155202    my @uris = split "^", join("", @$stdout_buf);
    156203
    157     foreach my $uri (@uris) {
    158         chomp $uri;
    159         if ($mode eq "list_uri") {
    160             print "$uri\n";
     204    if ($mode eq "list_uri") {
     205        foreach my $uri (@uris) {
     206            print $uri;
     207        }
     208    } elsif ($job_type eq "get_image") {
     209        my $listfile = "$out_dir/filelist";
     210
     211        open LISTFILE, ">$listfile"
     212            or die "failed to open file list: $listfile while parsing get_image request $req_id";
     213
     214        # XXX TODO: how do we expand URIS to include wt and mk images
     215        # I've been assuming that ppstamp would just know what to do based on flags and file rules.
     216        # Actually if we change the code that lists images to list outputBase's instead we can
     217        # translate the rules here
     218        foreach my $uri (@uris) {
     219            chomp $uri;
     220            print LISTFILE "$uri|$img_type\n";
     221        }
     222        close LISTFILE;
     223        $command = "$pstamptool -dbname $dbname -addjob -req_id $req_id -job_type get_image"
     224                    . " -uri $listfile -outputBase $out_dir -rownum $rownum";
     225        if ($mode eq "list_job") {
     226            print "$command\n";
    161227        } else {
    162 
    163             # TODO: here is where we need to check whether or not the source image still exists
    164             # and queue a regeneration job. Also remove streaks here ???
     228            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     229                run(command => $command, verbose => $verbose);
     230            unless ($success) {
     231                print STDERR @$stderr_buf;
     232                # XXX TODO: now what? Should we mark the error state for the request?
     233                die "failed to queue job for request $req_id: rownum: $rownum";
     234            }
     235        }
     236    } else {
     237        my $args = $roi_string ? $roi_string : "";
     238        $args .= " -class_id $class_id" if ($class_id and ($class_id ne "null"));
     239
     240#        my $numJobs = @uris;
     241        my $num = 0;
     242        foreach my $uri (@uris) {
     243            chomp $uri;
     244
     245            $num++;
     246            my $output_base = "$out_dir/${rownum}_${num}_${stamp_name}";
     247
     248            # XXX: TODO: here is where we need to check whether or not the source inputs still exist
     249            # and if not, queue a regeneration job and set the job state appropriately.
     250            # a simpler but slower option would be to set state to 'staged' and have a new task do
     251            # the checking. This would add latency to the processing when the images are available.
     252            # just share code.
    165253
    166254            $command = "$pstamptool -dbname $dbname -addjob -req_id $req_id -job_type $job_type"
    167                 . " -uri $uri -outputBase $out_dir/$stamp_name -args '$args'";
     255                . " -uri $uri -outputBase $output_base -args '$args' -rownum $rownum";
    168256            if ($mode eq "list_job") {
    169257                # this is a debugging mode, just print the pstamptool that would have run
     
    179267                    # should we keep going for other uris? If so how do we report that some
    180268                    # of the work that the request wanted isn't going to get done
    181                     die "failed to queue job";
     269                    die "failed to queue job for request $req_id";
    182270                }
    183271            }
     
    188276exit 0;
    189277
     278# resolve_project()
     279# get project specific information
     280# This is a placeholder final implementation will use configuration file and database to
     281# map from "project" to image database, dvo database, telescope, camera, etc
     282#
     283# For now just get the database and the class_id that will be used for image lookup
     284
     285sub resolve_project {
     286    my $project_name = shift;
     287    my $img_type     = shift;
     288    my $class_id     = shift;
     289    die "project is not defined" if !$project_name;
     290
     291    # for megacam and simtest since images are at the fpa level, leave out the
     292    # class_id at the lookup stage
     293    #
     294    # TODO: get this information from a database or a configuration file
     295
     296    my $ret_dbname;
     297    my $ret_class_id;
     298
     299    if ($project_name eq "megacam-mops") {
     300        $ret_dbname = "mops";
     301        $ret_class_id = "null";
     302    } elsif ($project_name eq "simtest") {
     303        $ret_dbname = "simtest";
     304        $ret_class_id = "null";
     305    } elsif ($project_name eq "gpc1") {
     306        $ret_dbname = "gpc1";
     307        $ret_class_id = $class_id;
     308    } else {
     309        die "unknown project $project_name";
     310    }
     311
     312    if (($img_type ne "raw") and ($img_type ne "chip")) {
     313        # don't need class_id
     314        $ret_class_id = "";
     315    }
     316
     317    return ($ret_dbname, $ret_class_id);
     318}
Note: See TracChangeset for help on using the changeset viewer.