IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25793


Ignore:
Timestamp:
Oct 7, 2009, 1:05:22 PM (17 years ago)
Author:
bills
Message:

Add new table pstampDependent. An entry gets created by the postage stamp request parser
when the source run has been cleaned. The pstampJob is blocked from running until
the system detects that the run has been updated and magicked. (This code is yet
to be developed.)

Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm

    r25776 r25793  
    128128}
    129129
    130 sub lookup {
     130sub lookup
     131{
    131132    my $ipprc    = shift;
    132133    my $image_db = shift;
     
    296297
    297298        # if uri is nil this will get overridded below
    298         # (this is for raw stage)
     299        # (we do this here for raw stage)
    299300        $out->{image}  = $image->{uri};
    300301        if ($set_class_id) {
     
    302303            $out->{component} = $class_id;
    303304        }
     305        my $stage_id;
     306        if ($img_type eq "raw") {
     307            $stage_id = $image->{exp_id};
     308        } elsif ($img_type eq "chip") {
     309            $stage_id = $image->{chip};
     310        } elsif ($img_type eq "warp") {
     311            $stage_id = $image->{warp_id};
     312        } elsif ($img_type eq "diff") {
     313            $stage_id = $image->{diff_id};
     314        } elsif ($img_type eq "stack") {
     315            $stage_id = $image->{stack_id};
     316        }
     317        $image->{stage_id} = $stage_id;
     318        $image->{stage}    = $img_type;
     319        $image->{image_db} = $image_db;
    304320
    305321        # find the mask and weight images
    306322        if ($base) {
    307             $out->{image}  = $ipprc->filename($image_name,   $base, $class_id) if $image_name;
     323            $out->{image}  = $ipprc->filename($image_name,  $base, $class_id) if $image_name;
    308324            $out->{mask}   = $ipprc->filename($mask_name,   $base, $class_id) if $mask_name;
    309325            $out->{weight} = $ipprc->filename($weight_name, $base, $class_id) if $weight_name;
  • trunk/dbconfig/changes.txt

    r25711 r25793  
    13001300
    13011301ALTER TABLE pstampJob ADD COLUMN options BIGINT;
     1302ALTER TABLE pstampJob ADD COLUMN dep_id BIGINT;
     1303CREATE TABLE pstampDependent (
     1304        dep_id BIGINT AUTO_INCREMENT,
     1305        stage      VARCHAR(64),
     1306        stage_id   BIGINT,
     1307        need_magic TINYINT,
     1308        image_db   VARCHAR(64),
     1309        rlabel     VARCHAR(64),
     1310        PRIMARY KEY(dep_id)
     1311) ENGINE=innodb DEFAULT CHARSET=latin1;
     1312
  • trunk/dbconfig/pstamp.md

    r25711 r25793  
    4040    outputBase  STR         255
    4141    options     S64         64
     42    dep_id      S64         0
    4243END
     44
     45pstampDependent       METADATA
     46    dep_id      S64         0       # Primary Key AUTO_INCREMENT
     47    state       STR         64
     48    stage       STR         64
     49    stage_id    S64         0
     50    imagedb     STR         64
     51    rlabel      STR         64
     52    no_magic    BOOL        f
     53END
  • trunk/ippTools/share/Makefile.am

    r25789 r25793  
    201201     pstamptool_datastore.sql \
    202202     pstamptool_listjob.sql \
     203     pstamptool_pendingdependent.sql \
    203204     pstamptool_pendingjob.sql \
    204205     pstamptool_pendingreq.sql \
  • trunk/ippTools/share/pstamptool_pendingjob.sql

    r25199 r25793  
    11SELECT pstampJob.*
    22FROM pstampJob
    3     JOIN pstampRequest using(req_id)
     3    JOIN pstampRequest USING(req_id)
     4    LEFT JOIN pstampDependent USING(dep_id)
    45WHERE pstampRequest.state = 'run'
    56    AND pstampRequest.fault = 0
    67    AND pstampJob.state = 'run'
    78    AND pstampJob.fault = 0
     9    AND (dep_id = 0 OR pstampDependent.state = 'full')
  • trunk/ippTools/share/pxadmin_create_tables.sql

    r25711 r25793  
    12501250        outputBase VARCHAR(255),
    12511251        options BIGINT,
     1252        dep_id BIGINT,
    12521253        PRIMARY KEY(job_id, req_id),
    12531254        KEY(job_id),
    12541255        FOREIGN KEY(req_id) REFERENCES pstampRequest(req_id)
     1256) ENGINE=innodb DEFAULT CHARSET=latin1;
     1257
     1258CREATE TABLE pstampDependent (
     1259        dep_id BIGINT AUTO_INCREMENT,
     1260        state      VARCHAR(64),
     1261        stage      VARCHAR(64),
     1262        stage_id   BIGINT,
     1263        image_db   VARCHAR(64),
     1264        rlabel     VARCHAR(64),
     1265        need_magic TINYINT,
     1266        PRIMARY KEY(dep_id)
    12551267) ENGINE=innodb DEFAULT CHARSET=latin1;
    12561268
  • trunk/ippTools/src/pstamptool.c

    r25711 r25793  
    4848static bool projectMode(pxConfig *config);
    4949static bool modprojectMode(pxConfig *config);
     50static bool getdependentMode(pxConfig *config);
     51static bool pendingdependentMode(pxConfig *config);
     52static bool updatedependentMode(pxConfig *config);
    5053
    5154# define MODECASE(caseName, func) \
     
    8588        MODECASE(PSTAMPTOOL_MODE_MODPROJECT, modprojectMode);
    8689        MODECASE(PSTAMPTOOL_MODE_PROJECT, projectMode);
     90        MODECASE(PSTAMPTOOL_MODE_GETDEPENDENT, getdependentMode);
     91        MODECASE(PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentMode);
     92        MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode);
    8793        default:
    8894            psAbort("invalid option (this should not happen)");
     
    545551    PXOPT_LOOKUP_S64(exp_id,      config->args, "-exp_id",     false, false);
    546552    PXOPT_LOOKUP_S64(options,     config->args, "-options",     false, false);
     553    PXOPT_LOOKUP_S64(dep_id,      config->args, "-dep_id",     false, false);
    547554
    548555    // unless the job is being inserted with stop state require outputBase
     
    570577            exp_id,
    571578            outputBase,
    572             options
     579            options,
     580            dep_id
    573581            )) {
    574582        psError(PS_ERR_UNKNOWN, false, "database error");
     
    896904}
    897905
     906static bool getdependentMode(pxConfig *config)
     907{
     908    PS_ASSERT_PTR_NON_NULL(config, false);
     909
     910    PXOPT_LOOKUP_STR(stage,       config->args, "-stage",   true, false);
     911    PXOPT_LOOKUP_S64(stage_id,    config->args, "-stage_id", true, false);
     912    PXOPT_LOOKUP_STR(imagedb,     config->args, "-imagedb",  true, false);
     913    PXOPT_LOOKUP_STR(rlabel,      config->args, "-rlabel",  false, false);
     914    PXOPT_LOOKUP_BOOL(no_magic,   config->args, "-no_magic", false);
     915    PXOPT_LOOKUP_BOOL(no_create,  config->args, "-no_create", false);
     916
     917    psString query = pxDataGet("pstamptool_pendingdependent.sql");
     918    if (!query) {
     919        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     920        return false;
     921    }
     922    if (!p_psDBRunQuery(config->dbh, query)) {
     923        psError(PS_ERR_UNKNOWN, false, "database error");
     924        psFree(query);
     925        return false;
     926    }
     927    psFree(query);
     928
     929    psArray *output = p_psDBFetchResult(config->dbh);
     930    if (!output) {
     931        psError(PS_ERR_UNKNOWN, false, "database error");
     932        return false;
     933    }
     934    if (psArrayLength(output)) {
     935        psMetadata *dep = output->data[0];
     936        psS64 dep_id = psMetadataLookupS64(NULL, dep, "dep_id");
     937        if (!dep_id) {
     938            psError(PS_ERR_UNKNOWN, false, "database error");
     939            return false;
     940        }
     941        printf("%" PRId64 "\n", dep_id);
     942        return true;
     943    }
     944    if (no_create) {
     945        return true;
     946    }
     947    // no existing dependent that matches, insert one
     948
     949    if (!pstampDependentInsert(
     950        config->dbh,
     951        0,              // dep_id
     952        "new",          // state
     953        stage,
     954        stage_id,
     955        imagedb,
     956        rlabel,
     957        no_magic
     958        )) {
     959        psError(PS_ERR_UNKNOWN, false, "failed to insert pstampDependent");
     960        return false;
     961    }
     962
     963    psS64 dep_id = psDBLastInsertID(config->dbh);
     964
     965    printf("%" PRId64 "\n", dep_id);
     966
     967    return true;
     968}
     969
     970static bool pendingdependentMode(pxConfig *config)
     971{
     972    PS_ASSERT_PTR_NON_NULL(config, false);
     973
     974    psMetadata *where = psMetadataAlloc();
     975
     976    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     977    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     978
     979    psString query = pxDataGet("pstamptool_pendingdependent.sql");
     980    if (!query) {
     981        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     982        return false;
     983    }
     984
     985    if (psListLength(where->list)) {
     986        psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampDependent");
     987        psStringAppend(&query, " AND %s", whereClause);
     988        psFree(whereClause);
     989    }
     990    psFree(where);
     991
     992    // treat limit == 0 as "no limit"
     993    if (limit) {
     994        psString limitString = psDBGenerateLimitSQL(limit);
     995        psStringAppend(&query, " %s", limitString);
     996        psFree(limitString);
     997    }
     998
     999    if (!p_psDBRunQuery(config->dbh, query)) {
     1000        psError(PS_ERR_UNKNOWN, false, "database error");
     1001        psFree(query);
     1002        return false;
     1003    }
     1004    psFree(query);
     1005
     1006    psArray *output = p_psDBFetchResult(config->dbh);
     1007    if (!output) {
     1008        psError(PS_ERR_UNKNOWN, false, "database error");
     1009        return false;
     1010    }
     1011    if (!psArrayLength(output)) {
     1012        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
     1013        psFree(output);
     1014        return true;
     1015    }
     1016
     1017    // negative simple so the default is true
     1018    if (!ippdbPrintMetadatas(stdout, output, "pstampDependent", !simple)) {
     1019        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1020        psFree(output);
     1021        return false;
     1022    }
     1023
     1024    psFree(output);
     1025
     1026    return true;
     1027}
     1028static bool updatedependentMode(pxConfig *config)
     1029{
     1030    PS_ASSERT_PTR_NON_NULL(config, false);
     1031
     1032    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", true, false);
     1033    PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  true, false);
     1034
     1035    char *query ="UPDATE pstampDependent"
     1036        " SET state = '%s'"
     1037        " WHERE dep_id = %" PRId64;
     1038   
     1039    if (!p_psDBRunQueryF(config->dbh, query, state, dep_id)) {
     1040        psError(PS_ERR_UNKNOWN, false, "database error");
     1041        psFree(query);
     1042        return false;
     1043    }
     1044
     1045    psU64 affected = psDBAffectedRows(config->dbh);
     1046    if (affected != 1) {
     1047        psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
     1048                                        PRIu64 " rows were modified", affected);
     1049        return false;
     1050    }
     1051
     1052    return true;
     1053}
  • trunk/ippTools/src/pstamptool.h

    r25199 r25793  
    4343    PSTAMPTOOL_MODE_MODPROJECT,
    4444    PSTAMPTOOL_MODE_PROJECT,
     45    PSTAMPTOOL_MODE_GETDEPENDENT,
     46    PSTAMPTOOL_MODE_PENDINGDEPENDENT,
     47    PSTAMPTOOL_MODE_UPDATEDEPENDENT,
    4548} pstamptoolMode;
    4649
  • trunk/ippTools/src/pstamptoolConfig.c

    r25711 r25793  
    112112    psMetadataAddS64(addjobArgs, PS_LIST_TAIL, "-exp_id", 0,           "define exposure id", 0);
    113113    psMetadataAddS64(addjobArgs, PS_LIST_TAIL, "-options", 0,          "define options", 0);
     114    psMetadataAddS64(addjobArgs, PS_LIST_TAIL, "-dep_id", 0,           "define job dep_id", 0);
    114115    psMetadataAddS16(addjobArgs, PS_LIST_TAIL, "-fault", 0,            "define job result", 0);
    115116
     
    143144    psMetadataAddBool(revertjobArgs, PS_LIST_TAIL, "-all", 0,       "revert all faulted jobs", false);
    144145    psMetadataAddU64(revertjobArgs, PS_LIST_TAIL, "-limit", 0,      "limit result set to N items", 0);
     146
     147    // -getdependent
     148    psMetadata *getdependentArgs = psMetadataAlloc();
     149    psMetadataAddS64(getdependentArgs, PS_LIST_TAIL, "-stage_id", 0, "define id for dependent run (required)", 0);
     150    psMetadataAddStr(getdependentArgs, PS_LIST_TAIL, "-stage", 0,    "define stage for dependent run (required)", NULL);
     151    psMetadataAddStr(getdependentArgs, PS_LIST_TAIL, "-imagedb", 0,  "define imagedb for depenent run (required)", NULL);
     152    psMetadataAddStr(getdependentArgs, PS_LIST_TAIL, "-rlabel", 0,   "define label for dependent run", NULL);
     153    psMetadataAddBool(getdependentArgs,PS_LIST_TAIL, "-no_magic", 0, "define no_magic", false);
     154    psMetadataAddBool(getdependentArgs,PS_LIST_TAIL, "-no_create", 0, "if no run exists do not create one", false);
     155
     156    // -updatedependent
     157    psMetadata *updatedependentArgs = psMetadataAlloc();
     158    psMetadataAddS64(updatedependentArgs, PS_LIST_TAIL, "-dep_id", 0, "define id for dependent run (required)", 0);
     159    psMetadataAddStr(updatedependentArgs, PS_LIST_TAIL, "-set_state", 0, "new value for state (required)", NULL);
     160
     161    // -pendingdependent
     162    psMetadata *pendingdependentArgs = psMetadataAlloc();
     163    psMetadataAddS64(pendingdependentArgs, PS_LIST_TAIL, "-stage_id", 0, "define id for dependent run", 0);
     164    psMetadataAddStr(pendingdependentArgs, PS_LIST_TAIL, "-stage", 0,    "define stage for dependent run", NULL);
     165    psMetadataAddStr(pendingdependentArgs, PS_LIST_TAIL, "-imagedb", 0,  "define imagedb for depenent run", NULL);
     166    psMetadataAddStr(pendingdependentArgs, PS_LIST_TAIL, "-rlabel", 0,   "define label for dependent run", NULL);
     167    psMetadataAddBool(pendingdependentArgs,PS_LIST_TAIL, "-no_magic", 0, "define no_magic", false);
     168    psMetadataAddBool(pendingdependentArgs,PS_LIST_TAIL, "-no_create", 0, "if no run exists do not create one", false);
     169    psMetadataAddU64(pendingdependentArgs, PS_LIST_TAIL, "-limit",  0,    "limit result set to N items", 0);
     170    psMetadataAddBool(pendingdependentArgs, PS_LIST_TAIL, "-simple", 0,   "use the simple output format", false);
    145171
    146172    // -addproject
     
    189215    PXOPT_ADD_MODE("-moddatastore",    "", PSTAMPTOOL_MODE_MODDATASTORE, moddatastoreArgs);
    190216
     217    PXOPT_ADD_MODE("-getdependent",    "", PSTAMPTOOL_MODE_GETDEPENDENT, getdependentArgs);
     218    PXOPT_ADD_MODE("-updatedependent", "", PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentArgs);
     219    PXOPT_ADD_MODE("-pendingdependent","", PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentArgs);
     220
    191221    PXOPT_ADD_MODE("-addproject",      "", PSTAMPTOOL_MODE_ADDPROJECT, addprojectArgs);
    192222    PXOPT_ADD_MODE("-modproject",      "", PSTAMPTOOL_MODE_MODPROJECT, modprojectArgs);
  • trunk/pstamp/scripts/pstampparse.pl

    r25776 r25793  
    7272}
    7373
     74# just deal with these arguments once and for all
     75$pstamptool .= " -dbname $dbname" if $dbname;
     76$pstamptool .= " -dbserver $dbserver" if $dbserver;
     77
    7478# list_job is a deugging mode
    7579$no_update = 1 if $mode eq "list_job";
     
    105109if ($req_id and !$no_update) {
    106110    my $command = "$pstamptool -listreq  -name $req_name -not_req_id $req_id";
    107     $command .= " -dbname $dbname" if $dbname;
    108     $command .= " -dbserver $dbserver" if $dbserver;
    109111    # no verbose so that error message about request not found doesn't appear in parse_error.txt
    110112    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    127129    my $command = "$pstamptool -updatereq -req_id $req_id  -name $req_name";
    128130    $command .= " -outProduct $product";
    129     $command .= " -dbname $dbname" if $dbname;
    130     $command .= " -dbserver $dbserver" if $dbserver;
    131131    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    132132        run(command => $command, verbose => $verbose);
     
    398398        my $newState = "run";
    399399        my $fault = 0;
    400 
    401         if (($stage ne 'stack') and ($stage ne 'raw')) {
    402             if (($image->{state} eq 'goto_purged') or ($image->{data_state} eq 'purged')) {
     400        my $dep_id;
     401
     402        if ($stage ne 'raw') {
     403            my $run_state = $image->{state};
     404            my $data_state = $image->{data_state};
     405            if (($run_state eq 'goto_purged') or ($data_state eq 'purged') or
     406                ($run_state eq 'goto_scrubbed') or ($data_state eq 'scrubbed')) {
     407                # image is gone and it's not coming back
    403408                $newState = 'stop';
    404409                $fault = $PSTAMP_GONE;
    405             } elsif (($image->{data_state} ne 'full') or ($image->{state} ne 'full' )) {
    406                 # XXX here is where we need to queue an update job
    407                 # for now just say that the image is not available
    408                 $newState = 'stop';
    409                 $fault = $PSTAMP_NOT_AVAILABLE;
     410            } elsif (($data_state ne 'full') or ($run_state ne 'full' )) {
     411                my $PSTAMP_NO_UPDATE = 2048;
     412                # for now just fault while I build pstampDependent
     413                if ($option_mask & $PSTAMP_NO_UPDATE) {
     414                    $newState = 'stop';
     415                    $fault = $PSTAMP_NOT_AVAILABLE;
     416                } else {
     417                    # cause the image to be re-made
     418                    # set up to queue an update run
     419                    queue_update_run(\$newState, \$fault, \$dep_id, $image->{image_db},
     420                        $run_state, $stage, $image->{stage_id}, $need_magic, $image->{label});
     421                }
    410422            }
    411423        }
     
    416428        $command .= " -fault $fault" if $fault;
    417429        $command .= " -exp_id $exp_id" if $exp_id;
    418         $command .= " -dbname $dbname" if $dbname;
    419         $command .= " -dbserver $dbserver" if $dbserver;
     430        $command .= " -dep_id $dep_id" if $dep_id;
    420431
    421432        if ($mode eq "list_job") {
     
    594605    my $command = "$pstamptool -addjob  -req_id $req_id -job_type $job_type"
    595606                        . " -rownum $rownum -state stop -fault $fault";
    596     $command .= " -dbname $dbname" if $dbname;
    597     $command .= " -dbserver $dbserver" if $dbserver;
    598607
    599608    if ($mode eq "list_job") {
     
    718727}
    719728
     729sub queue_update_run
     730{
     731    my ($r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $need_magic, $label) = @_;
     732
     733    if (($state ne 'cleaned') and ($state ne 'update') and ($state ne 'goto_cleaned')) {
     734        my_die("$stage $stage_id is in unexpected state $state", $PS_EXIT_PROG_ERROR);
     735    }
     736
     737    my $dep_id;
     738    my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb";
     739    $command .= " -rlabel $label" if $label;
     740    $command .= " -no_magic" if !$need_magic;
     741    if (!$no_update) {
     742        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     743            run(command => $command, verbose => $verbose);
     744        unless ($success) {
     745            my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
     746        }
     747        my $output = join "", @$stdout_buf;
     748        chomp $output;
     749        $dep_id = $output;
     750        my_die("pstamptool -getdependent returned invalid dep_id", $PS_EXIT_PROG_ERROR) if !$dep_id;
     751    } else {
     752        print STDERR "skipping $command\n";
     753        $dep_id = 42;
     754    }
     755   
     756    $$r_dep_id = $dep_id;
     757    $r_fault = 0;
     758    $r_jobState = 'blocked';
     759}
     760
    720761sub my_die
    721762{
Note: See TracChangeset for help on using the changeset viewer.