IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29561


Ignore:
Timestamp:
Oct 26, 2010, 8:39:32 AM (16 years ago)
Author:
bills
Message:

Change the destreak cleanup to preserve the rows in the magicDSFile table

Location:
trunk
Files:
4 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/magic_destreak.pl

    r29495 r29561  
    4242# Parse the command-line arguments
    4343my ($magic_ds_id, $camera, $streaks, $inv_streaks, $exp_id, $stage, $stage_id, $component, $uri, $path_base, $cam_path_base, $cam_reduction);
    44 my ($streaks_path_base, $inv_streaks_path_base);
     44my ($streaks_path_base, $inv_streaks_path_base, $run_state);
    4545my ($outroot, $recoveryroot, $magicked);
    4646my ($replace, $release);
     
    5050           'magic_ds_id=s'  => \$magic_ds_id,# Magic destreak run identifier
    5151           'camera=s'       => \$camera,     # camera for evaluating file rules
     52           'run-state=s'    => \$run_state,   # state of run (new or update)
    5253           'streaks_path_base=s'      => \$streaks_path_base,    # path_base for streaks data
    5354           'inv_streaks_path_base=s'  => \$inv_streaks_path_base, #path_base for streaks from inverse diff
     
    7778
    7879pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    79 pod2usage( -msg => "Required options: --magic_ds_id --camera --streaks --stage --stage_id --component --uri --path_base --outroot --magicked",
     80pod2usage( -msg => "Required options: --magic_ds_id --camera --run_state --streaks --stage --stage_id --component --uri --path_base --outroot --magicked",
    8081           -exitval => 3) unless
    8182    defined $magic_ds_id and
    8283    defined $camera and
     84    defined $run_state and
    8385    defined $streaks and
    8486    defined $streaks_path_base and
     
    113115    &my_die("Invalid value for stage: $stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
    114116}
     117
     118&my_die("Invalid value for run-state: $run_state", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR)
     119    unless ($run_state eq 'new') or ($run_state eq 'update');
     120
    115121$inv_streaks_path_base = undef if defined($inv_streaks_path_base) and ($inv_streaks_path_base eq "NULL");
    116122$inv_streaks = undef if defined($inv_streaks) and ($inv_streaks eq "NULL");
     
    479485# Input result into database
    480486{
    481     my $command = "$magicdstool -adddestreakedfile";
     487    my $command = "$magicdstool";
    482488    $command   .= " -magic_ds_id $magic_ds_id";
    483489    $command   .= " -component $component";
    484490    $command   .= " -setmagicked" if $replace;
    485     $command   .= " -backup_path_base $backup_path_base" if $backup_path_base;
    486     $command   .= " -recovery_path_base $recovery_path_base" if $recovery_path_base;
    487     $command   .= " $statsFlags" if $statsFlags;
     491    if ($run_state eq 'new') {
     492        $command .= " -adddestreakedfile";
     493        $command .= " -backup_path_base $backup_path_base" if $backup_path_base;
     494        $command .= " -recovery_path_base $recovery_path_base" if $recovery_path_base;
     495        $command .= " $statsFlags" if $statsFlags;
     496    } else {
     497        $command .= " -tofullfile";
     498    }
    488499    $command   .= " -dbname $dbname" if defined $dbname;
    489500
     
    581592    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
    582593
    583     my $command = "$magicdstool -adddestreakedfile";
     594    my $command = "$magicdstool";
     595   
     596    if ($run_state eq 'new') {
     597        $command .= " -adddestreakedfile";
     598    } else {
     599        $command .= " -updatedestreakedfile";
     600    }
    584601    $command   .= " -magic_ds_id $magic_ds_id";
    585602    $command   .= " -component $component";
  • trunk/ippScripts/scripts/magic_destreak_cleanup.pl

    r29097 r29561  
    8989$q1 .= " WHERE magic_ds_id = $magic_ds_id";
    9090
    91 my $q2 = "SELECT * from magicDSFile where magic_ds_id = $magic_ds_id";
     91my $q2 = "SELECT * from magicDSFile WHERE (data_state = 'full' OR data_state = 'update') AND magic_ds_id = $magic_ds_id";
    9292
    9393my $stmt1 = $dbh->prepare($q1);
     
    245245            delete_files($rimage, $rmask, $rweight, $rsources, undef, $bimage, $bmask, $bweight, $bsources);
    246246        }
    247 }
    248 
    249 $dbh = DBI->connect($dsn, $dbuser, $dbpassword) or die "Cannot connect to mysql server\n";
    250 
    251 if (!$no_update and ($num_components > 0)) {
    252     my $result = $dbh->do("DELETE FROM magicDSFile WHERE magic_ds_id = ?", undef, $magic_ds_id);
    253     # my $result = $stmt3->do($magic_ds_id);
    254     my_die("attempt to delete magicDSFiles failed", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR) if $result eq "0E0";
    255 }
    256 
    257 if (!$no_update) {
    258     my $result = $dbh->do("UPDATE magicDSRun SET state = 'cleaned' WHERE magic_ds_id = ?", undef, $magic_ds_id);
    259     my_die("attempt to update magicDSRun.state failed", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR) if $result eq "0E0";
    260 } else {
    261     print STDERR "skipping update of magicDSRun\n";
    262 }
    263 
     247        my $command = "$magicdstool -tocleanedfile -magic_ds_id $magic_ds_id -component $component";
     248        $command   .= " -dbname $dbname" if defined $dbname;
     249
     250        unless ($no_update) {
     251            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     252                run(command => $command, verbose => $verbose);
     253            unless ($success) {
     254                carp("failed to update database for $magic_ds_id");
     255            }
     256        } else {
     257            print "Skipping command: $command\n";
     258        }
     259}
    264260
    265261### Pau.
     
    292288    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
    293289
    294     my $command = "$magicdstool -updaterun -set_state failed_cleanup";
     290    my $command = "$magicdstool -updaterun -set_state error_cleaned";
    295291    $command   .= " -magic_ds_id $magic_ds_id";
    296292    $command   .= " -dbname $dbname" if defined $dbname;
  • trunk/ippScripts/scripts/magic_destreak_revert.pl

    r27946 r29561  
    3838
    3939# Parse the command-line arguments
    40 my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $bothways, $cam_path_base, $cam_reduction, $magicked);
     40my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $bothways, $cam_path_base, $cam_reduction, $magicked, $run_state);
    4141my ($outroot, $recoveryroot, $replace, $release, $bytes, $md5sum);
    4242my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
     
    4747           'stage=s'        => \$stage,      # raw, chip, warp, or diff
    4848           'stage_id=s'     => \$stage_id,   # exp_id, chip_id, warp_id, or diff_id
     49           'run-state=s'    => \$run_state, # current state of run
    4950           'component=s'    => \$component,  # the class_id or skycell_id
    5051           'path_base=s'    => \$path_base,  # path_base of the input
     
    7475    defined $path_base and
    7576    defined $magicked and
     77    defined $run_state and
    7678    defined $outroot;
    7779
     
    248250{
    249251    my $command = "$magicdstool -revertdestreakedfile -i_am_sure";
     252    $command   .= " -state $run_state";
    250253    $command   .= " -magic_ds_id $magic_ds_id";
    251254    $command   .= " -component $component";
  • trunk/ippTasks/destreak.cleanup.pro

    r29250 r29561  
    5050  periods      -timeout 20
    5151  npending     1
    52   active       false
    5352
    5453  stdout NULL
     
    105104  periods      -exec $RUNEXEC
    106105  periods      -timeout 60
    107   active       false
    108106
    109107  task.exec
  • trunk/ippTasks/destreak.pro

    r29502 r29561  
    185185    book getword magicToDS $pageName exp_id -var EXP_ID
    186186    book getword magicToDS $pageName magic_ds_id -var MAGIC_DS_ID
     187    book getword magicToDS $pageName state -var RUN_STATE
    187188    book getword magicToDS $pageName camera -var CAMERA
    188189    book getword magicToDS $pageName streaks_uri -var STREAKS
     
    215216    # TODO: do not add recoveryroot or replace if they are null or zero
    216217
    217     $run = magic_destreak.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --exp_id $EXP_ID --streaks_path_base $STREAKS_PATH_BASE --inv_streaks_path_base $INV_STREAKS_PATH_BASE --streaks $STREAKS --inv_streaks $INV_STREAKS --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --uri $URI --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --cam_reduction $CAM_REDUCTION --outroot $OUTROOT --logfile $logfile --recoveryroot $RECROOT --replace $REPLACE --magicked $MAGICKED
     218    $run = magic_destreak.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --exp_id $EXP_ID --streaks_path_base $STREAKS_PATH_BASE --inv_streaks_path_base $INV_STREAKS_PATH_BASE --streaks $STREAKS --inv_streaks $INV_STREAKS --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --uri $URI --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --cam_reduction $CAM_REDUCTION --outroot $OUTROOT --logfile $logfile --recoveryroot $RECROOT --replace $REPLACE --magicked $MAGICKED --run-state $RUN_STATE
    218219
    219220    add_standard_args run
     
    390391    book getword magicDSToRevert $pageName camera -var CAMERA
    391392    book getword magicDSToRevert $pageName stage -var STAGE
     393    book getword magicDSToRevert $pageName state -var RUN_STATE
    392394    book getword magicDSToRevert $pageName stage_id -var STAGE_ID
    393395    book getword magicDSToRevert $pageName component -var COMPONENT
     
    414416    end
    415417
    416     $run = magic_destreak_revert.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --cam_reduction $CAM_REDUCTION --outroot $OUTROOT --logfile $logfile --replace $REPLACE --bothways $BOTHWAYS --magicked $MAGICKED
     418    $run = magic_destreak_revert.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --cam_reduction $CAM_REDUCTION --outroot $OUTROOT --logfile $logfile --replace $REPLACE --bothways $BOTHWAYS --magicked $MAGICKED --run-state $RUN_STATE
    417419
    418420    add_standard_args run
  • trunk/ippTools/share/Makefile.am

    r29528 r29561  
    238238        magictool_exposure.sql \
    239239        magicdstool_clearstatefaults.sql \
     240        magicdstool_change_file_data_state.sql \
     241        magicdstool_change_run_state.sql \
    240242        magicdstool_completed_runs.sql \
    241243        magicdstool_completedrevert.sql \
     
    252254        magicdstool_getskycells.sql \
    253255        magicdstool_revertdestreakedfile.sql \
     256        magicdstool_revertupdated.sql \
     257        magicdstool_setfiletoupdate.sql \
    254258        magicdstool_tocleanup.sql \
    255259        magicdstool_todestreak_camera.sql \
  • trunk/ippTools/share/chiptool_setimfiletoupdate.sql

    r28934 r29561  
    1111    AND (chipRun.state = 'cleaned' OR chipRun.state = 'update')
    1212    AND (chipProcessedImfile.data_state = 'cleaned')
    13     -- don't queue update if the associated magicDSFile exists
     13    -- don't queue update if the associated magicDSFile exists and isn't cleaned
    1414    AND (chipRun.magicked = 0
    15       OR (magicDSRun.state = 'cleaned' OR magicDSRun.state = 'new')
    16             AND magicDSFile.component IS NULL)
     15      OR ((magicDSRun.state = 'cleaned' OR magicDSRun.state = 'update')
     16            AND (magicDSFile.data_state = 'cleaned`' OR magicDSFile.data_state = 'update'))
     17    )
  • trunk/ippTools/share/magicdstool_todestreak_camera.sql

    r29495 r29561  
    22    magicDSRun.magic_ds_id,
    33    magicDSRun.magic_id,
     4    magicDSRun.state,
    45    chipRun.exp_id,
    56    camRun.magicked,
  • trunk/ippTools/share/magicdstool_todestreak_chip.sql

    r29495 r29561  
    22    magicDSRun.magic_ds_id,
    33    magicDSRun.magic_id,
     4    magicDSRun.state,
    45    chipRun.exp_id,
    56    chipRun.magicked,
     
    3738    ON magicDSRun.label = Label.label
    3839WHERE
    39     magicDSRun.state = 'new'
     40    ((magicDSRun.state = 'new' AND magicDSFile.component IS NULL)
     41     OR (magicDSRun.state = 'update' AND magicDSFile.data_state = 'update'
     42         AND magicDSFile.fault = 0))
    4043    AND magicDSRun.stage = 'chip'
    4144    AND (chipRun.state = 'full' OR (chipRun.state = 'update' and chipProcessedImfile.data_state = 'full'))
    4245    AND chipProcessedImfile.fault = 0
    4346    AND chipProcessedImfile.quality = 0
    44     AND magicDSFile.component IS NULL
    4547    AND (Label.active OR Label.active IS NULL)
  • trunk/ippTools/share/magicdstool_todestreak_diff.sql

    r29495 r29561  
    33    magicDSRun.magic_ds_id,
    44    magicRun.magic_id,
     5    magicDSRun.state,
    56    magicRun.exp_id,
    67    magicDSRun.label,
     
    5051    magicDSRun.magic_ds_id,
    5152    magicRun.magic_id,
     53    magicDSRun.state,
    5254    magicRun.exp_id,
    5355    magicDSRun.label,
  • trunk/ippTools/share/magicdstool_todestreak_raw.sql

    r29495 r29561  
    22    magicDSRun.magic_ds_id,
    33    magicRun.magic_id,
     4    magicDSRun.state,
    45    magicRun.exp_id,
    56    magicDSRun.label,
  • trunk/ippTools/share/magicdstool_todestreak_warp.sql

    r29495 r29561  
    22    magicDSRun.magic_ds_id,
    33    magicRun.magic_id,
     4    magicDSRun.state,
    45    magicRun.exp_id,
    56    magicDSRun.label,
  • trunk/ippTools/share/magicdstool_torevert_chip.sql

    r28853 r29561  
    2222    JOIN rawExp ON chipRun.exp_id = rawExp.exp_id
    2323WHERE magicDSRun.stage = 'chip'
    24     AND ((magicDSRun.state = 'new' AND magicDSFile.fault > 0)
     24    AND (((magicDSRun.state = 'new' OR (magicDSRun.state = 'update'))
     25            AND magicDSFile.fault > 0)
     26            -- why don't we require a fault for these states?
    2527         OR ((magicDSRun.state = 'goto_censored' OR magicDSRun.state = 'goto_restored')
    2628              AND ((backup_path_base IS NOT NULL) OR (recovery_path_base IS NOT NULL))
  • trunk/ippTools/src/magicdstool.c

    r29358 r29561  
    3939static bool advancerunMode(pxConfig *config);
    4040static bool revertdestreakedfileMode(pxConfig *config);
     41static bool updatedestreakedfileMode(pxConfig *config);
    4142static bool clearstatefaultsMode(pxConfig *config);
    4243static bool getskycellsMode(pxConfig *config);
     
    4546static bool completedrevertMode(pxConfig *config);
    4647static bool tocleanupMode(pxConfig *config);
     48static bool tofullfileMode(pxConfig *config);
     49static bool tocleanedfileMode(pxConfig *config);
     50static bool setfiletoupdateMode(pxConfig *config);
    4751
    4852static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psString extraSetString, psMetadata *where, const char *state);
     
    7377        MODECASE(MAGICDSTOOL_MODE_ADVANCERUN,          advancerunMode);
    7478        MODECASE(MAGICDSTOOL_MODE_REVERTDESTREAKEDFILE,revertdestreakedfileMode);
     79        MODECASE(MAGICDSTOOL_MODE_UPDATEDESTREAKEDFILE,updatedestreakedfileMode);
    7580        MODECASE(MAGICDSTOOL_MODE_CLEARSTATEFAULTS,    clearstatefaultsMode);
    7681        MODECASE(MAGICDSTOOL_MODE_GETSKYCELLS,         getskycellsMode);
     
    7984        MODECASE(MAGICDSTOOL_MODE_COMPLETEDREVERT,     completedrevertMode);
    8085        MODECASE(MAGICDSTOOL_MODE_TOCLEANUP,           tocleanupMode);
     86        MODECASE(MAGICDSTOOL_MODE_TOFULLFILE,          tofullfileMode);
     87        MODECASE(MAGICDSTOOL_MODE_TOCLEANEDFILE,       tocleanedfileMode);
     88        MODECASE(MAGICDSTOOL_MODE_SETFILETOUPDATE,     setfiletoupdateMode);
    8189        default:
    8290            psAbort("invalid option (this should not happen)");
     
    558566    PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false);
    559567
     568    if (!strcmp(state, "update")) {
     569        fprintf(stderr, "'-updaterun -set_state update' is not supported. Use -setfiletoupdate");
     570        return false;
     571    }
     572
    560573    // optional
    561574    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
     
    907920        return false;
    908921    }
     922
     923    return true;
     924}
     925static bool updatedestreakedfileMode(pxConfig *config)
     926{
     927    PS_ASSERT_PTR_NON_NULL(config, false);
     928
     929    // required values
     930    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false);
     931    PXOPT_LOOKUP_STR(component, config->args, "-component", true, false);
     932
     933    // default values
     934    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
     935    PXOPT_LOOKUP_STR(backup_path_base, config->args, "-backup_path_base", false, false);
     936    PXOPT_LOOKUP_STR(recovery_path_base, config->args, "-recovery_path_base", false, false);
     937    PXOPT_LOOKUP_STR(data_state, config->args, "-data_state", false, false);
     938    PXOPT_LOOKUP_F32(streak_frac, config->args, "-streak_frac", false, false);
     939    PXOPT_LOOKUP_F32(nondiff_frac, config->args, "-nondiff_frac", false, false);
     940    PXOPT_LOOKUP_F32(run_time, config->args, "-run_time", false, false);
     941
     942    psString query = psStringCopy("UPDATE magicDSFile");
     943
     944
     945    char *initial_separator = " SET";
     946    char *sep = initial_separator;
     947    if (fault) {
     948        psStringAppend(&query, "%s fault = %d", sep, fault);
     949        sep = ", ";
     950    }
     951    if (backup_path_base) {
     952        psStringAppend(&query, "%s backup_path_base = '%s'", sep, backup_path_base);
     953        sep = ", ";
     954    }
     955    if (recovery_path_base) {
     956        psStringAppend(&query, "%s recovery_path_base = '%s'", sep, recovery_path_base);
     957        sep = ", ";
     958    }
     959    if (data_state) {
     960        psStringAppend(&query, "%s data_state = '%s'", sep, data_state);
     961        sep = ", ";
     962    }
     963    if (streak_frac) {
     964        psStringAppend(&query, "%s streak_frac = '%f'", sep, streak_frac);
     965        sep = ", ";
     966    }
     967    if (nondiff_frac) {
     968        psStringAppend(&query, "%s nondiff_frac = '%f'", sep, nondiff_frac);
     969        sep = ", ";
     970    }
     971    if (run_time) {
     972        psStringAppend(&query, "%s run_time = '%f'", sep, run_time);
     973        sep = ", ";
     974    }
     975    if (sep == initial_separator) {
     976        psFree(query);
     977        psError(PS_ERR_UNKNOWN, true, "must set at least one value");
     978        return false;
     979    }
     980
     981    psStringAppend(&query, "\nWHERE magic_ds_id = %" PRId64 " AND component = '%s'\n", magic_ds_id, component);
     982
     983    if (!p_psDBRunQuery(config->dbh, query)) {
     984        psError(PS_ERR_UNKNOWN, false, "database error");
     985        psFree(query);
     986        return false;
     987    }
     988    psFree(query);
    909989
    910990    return true;
     
    10191099    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "==");
    10201100    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
     1101    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
    10211102    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
    10221103    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    10231104
    1024     psString query = pxDataGet("magicdstool_revertdestreakedfile.sql");
     1105    PXOPT_LOOKUP_STR(state, config->args, "-state", false, false);
     1106
     1107    psString queryFile = NULL;
     1108    if (state) {
     1109        if (! strcmp(state, "new") ) {
     1110            queryFile = "magicdstool_revertdestreakedfile.sql";
     1111        } else if (!strcmp(state, "update")) {
     1112            queryFile = "magicdstool_revertupdated.sql";
     1113        } else {
     1114            psError(PXTOOLS_ERR_SYS, true, "%s is not a valid value for state", state);
     1115            return false;
     1116        }
     1117    } else {
     1118        queryFile = "magicdstool_revertdestreakedfile.sql";
     1119    }
     1120    psString query = pxDataGet(queryFile);
     1121    if (!query) {
     1122        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1123        return false;
     1124    }
    10251125
    10261126    if (psListLength(where->list)) {
     
    12411341          (strcmp(state, "censored") == 0) ||
    12421342          (strcmp(state, "cleaned") == 0) ||
     1343          (strcmp(state, "update") == 0) ||
    12431344          (strcmp(state, "goto_restored") == 0) ||
    12441345          (strcmp(state, "goto_censored") == 0) ||
     
    15201621    return true;
    15211622}
     1623
     1624// update magicDSFile.data_state to given value.
     1625// afterwards, if all files in the magicDSRun have the new state,
     1626// update the state for it as well
     1627// shared code for the modes -tocleanedfile -tofullfile
     1628
     1629static bool change_file_data_state(pxConfig *config, psString data_state)
     1630{
     1631    PS_ASSERT_PTR_NON_NULL(config, false);
     1632
     1633    // magic_id, component
     1634    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false);
     1635    PXOPT_LOOKUP_STR(component, config->args, "-component", true, false);
     1636
     1637    psString query = pxDataGet("magicdstool_change_file_data_state.sql");
     1638
     1639    if (!psDBTransaction(config->dbh)) {
     1640        psError(PS_ERR_UNKNOWN, false, "database error");
     1641        return false;
     1642    }
     1643    if (!strcmp(data_state, "full")) {
     1644        // if -tofullfile optoinally set the magicked value for the component
     1645        PXOPT_LOOKUP_BOOL(setmagicked, config->args, "-setmagicked", false);
     1646        // set the image file's magicked flag
     1647        if (!setMagicked(config, magic_ds_id, component)) {
     1648            psError(PS_ERR_UNKNOWN, false, "setMagicked failed");
     1649            if (!psDBRollback(config->dbh)) {
     1650                psError(PS_ERR_UNKNOWN, false, "database error");
     1651            }
     1652            return false;
     1653        }
     1654    }
     1655
     1656    if (!p_psDBRunQueryF(config->dbh, query, data_state, magic_ds_id, component)) {
     1657        psFree(query);
     1658        psError(PS_ERR_UNKNOWN, false, "database error");
     1659        // rollback
     1660        if (!psDBRollback(config->dbh)) {
     1661            psError(PS_ERR_UNKNOWN, false, "database error");
     1662        }
     1663        psError(PS_ERR_UNKNOWN, false, "database error");
     1664        return false;
     1665    }
     1666    psFree(query);
     1667    if (psDBAffectedRows(config->dbh) < 1) {
     1668        psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
     1669        return false;
     1670    }
     1671
     1672    query = pxDataGet("magicdstool_change_run_state.sql");
     1673    if (!p_psDBRunQueryF(config->dbh, query, data_state, magic_ds_id, data_state)) {
     1674        psFree(query);
     1675        // rollback
     1676        if (!psDBRollback(config->dbh)) {
     1677            psError(PS_ERR_UNKNOWN, false, "database error");
     1678        }
     1679        psError(PS_ERR_UNKNOWN, false, "database error");
     1680        return false;
     1681    }
     1682    psFree(query);
     1683
     1684    if (!psDBCommit(config->dbh)) {
     1685        psError(PS_ERR_UNKNOWN, false, "database error");
     1686        return false;
     1687    }
     1688
     1689    return true;
     1690}
     1691static bool tocleanedfileMode(pxConfig *config)
     1692{
     1693    return change_file_data_state(config, "cleaned");
     1694}
     1695static bool tofullfileMode(pxConfig *config)
     1696{
     1697    return change_file_data_state(config, "full");
     1698}
     1699/*
     1700static bool topurgedimfileMode(pxConfig *config)
     1701{
     1702    return change_imfile_data_state(config, "purged", "goto_purged");
     1703}
     1704static bool toscrubbedfileMode(pxConfig *config)
     1705{
     1706  return change_file_data_state(config, "scrubbed", "goto_scrubbed");
     1707}
     1708*/
     1709
     1710// a very specfic function to queue a cleaned magicDSFile to be updated
     1711static bool setfiletoupdateMode(pxConfig *config)
     1712{
     1713    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1714
     1715    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false);
     1716    PXOPT_LOOKUP_STR(component, config->args, "-component", false, false);
     1717    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     1718
     1719    psString query = pxDataGet("magicdstool_setfiletoupdate.sql");
     1720    if (!query) {
     1721        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1722        return false;
     1723    }
     1724
     1725    psString setHook = psStringCopy("");
     1726    if (label) {
     1727        psStringAppend(&setHook, "\n , magicDSRun.label = '%s'", label);
     1728    }
     1729
     1730    if (component) {
     1731        psStringAppend(&query, " AND (magicDSFile.component = '%s')", component);
     1732    }
     1733
     1734    if (!p_psDBRunQueryF(config->dbh, query, setHook, magic_ds_id)) {
     1735        psError(PS_ERR_UNKNOWN, false, "database error");
     1736        return false;
     1737    }
     1738
     1739    psFree(setHook);
     1740    psFree(query);
     1741
     1742    return true;
     1743}
     1744
     1745
  • trunk/ippTools/src/magicdstool.h

    r26960 r29561  
    3838    MAGICDSTOOL_MODE_COMPLETEDREVERT,
    3939    MAGICDSTOOL_MODE_TOCLEANUP,
     40    MAGICDSTOOL_MODE_TOCLEANEDFILE,
     41    MAGICDSTOOL_MODE_TOFULLFILE,
     42    MAGICDSTOOL_MODE_SETFILETOUPDATE,
     43    MAGICDSTOOL_MODE_UPDATEDESTREAKEDFILE,
    4044} MAGICDStoolMode;
    4145
  • trunk/ippTools/src/magicdstoolConfig.c

    r28936 r29561  
    137137    psMetadataAddS16(adddestreakedfileArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
    138138
     139    // -updatedestreakedfile
     140    psMetadata *updatedestreakedfileArgs = psMetadataAlloc();
     141    psMetadataAddS64(updatedestreakedfileArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magictool ID (required)", 0);
     142    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-component", 0, "define component name (required)", NULL);
     143    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-state", 0, "current value for magicDSRun.state", NULL);
     144    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-backup_path_base", 0, "define backup URI", NULL);
     145    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-recovery_path_base", 0, "define recovery pixels URI", NULL);
     146    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-data_state", 0, "change data_state", NULL);
     147    psMetadataAddBool(updatedestreakedfileArgs, PS_LIST_TAIL, "-setmagicked", 0, "update the magicked state of the file", false);
     148    psMetadataAddF32(updatedestreakedfileArgs, PS_LIST_TAIL, "-streak_frac", 0, "set fraction of pixels masked by streaks", 0);
     149    psMetadataAddF32(updatedestreakedfileArgs, PS_LIST_TAIL, "-nondiff_frac", 0, "set fraction of pixels masked because nondiffed", 0);
     150    psMetadataAddF32(updatedestreakedfileArgs, PS_LIST_TAIL, "-run_time", 0, "set the streaksremove run time for component ", 0);
     151    psMetadataAddS16(updatedestreakedfileArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
     152
    139153    // -revertdestreakedfile
    140154    psMetadata *revertdestreakedfileArgs = psMetadataAlloc();
    141155    psMetadataAddS64(revertdestreakedfileArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "search by magictool de-streak ID", 0);
     156    psMetadataAddStr(revertdestreakedfileArgs, PS_LIST_TAIL, "-state", 0, "current value for magicDSRun.state", NULL);
    142157    psMetadataAddStr(revertdestreakedfileArgs, PS_LIST_TAIL, "-component", 0, "search by component", NULL);
    143158    psMetadataAddS16(revertdestreakedfileArgs, PS_LIST_TAIL, "-fault", 0, "search by fault code", 0);
     
    197212    psMetadataAddU64(tocleanupArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);
    198213    psMetadataAddBool(tocleanupArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
     214
     215    // -tocleanedfile
     216    psMetadata *tocleanedfileArgs = psMetadataAlloc();
     217    psMetadataAddS64(tocleanedfileArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magic_ds_id", 0);
     218    psMetadataAddStr(tocleanedfileArgs, PS_LIST_TAIL, "-component", 0, "define component", NULL);
     219
     220    // -tofullfile
     221    psMetadata *tofullfileArgs = psMetadataAlloc();
     222    psMetadataAddS64(tofullfileArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magic_ds_id", 0);
     223    psMetadataAddStr(tofullfileArgs, PS_LIST_TAIL, "-component", 0, "define component", NULL);
     224    psMetadataAddBool(tofullfileArgs, PS_LIST_TAIL, "-setmagicked", 0, "update the magicked state of the file", false);
     225
     226    // -setfiletoupdate
     227    psMetadata *setfiletoupdateArgs = psMetadataAlloc();
     228    psMetadataAddS64(setfiletoupdateArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magic_ds_id", 0);
     229    psMetadataAddStr(setfiletoupdateArgs, PS_LIST_TAIL, "-component", 0, "define component", NULL);
     230    psMetadataAddStr(setfiletoupdateArgs, PS_LIST_TAIL, "-set_label", 0, "set new label", NULL);
     231
    199232    psFree(now);
    200233
     
    230263                    MAGICDSTOOL_MODE_TOCLEANUP, tocleanupArgs);
    231264
     265    PXOPT_ADD_MODE("-tofullfile", "set component's data_state to full",
     266                    MAGICDSTOOL_MODE_TOFULLFILE, tofullfileArgs);
     267    PXOPT_ADD_MODE("-tocleanedfile", "set component's data_state to cleaned",
     268                    MAGICDSTOOL_MODE_TOCLEANEDFILE, tocleanedfileArgs);
     269    PXOPT_ADD_MODE("-setfiletoupdate", "set component's data_state to update",
     270                    MAGICDSTOOL_MODE_SETFILETOUPDATE, setfiletoupdateArgs);
     271    PXOPT_ADD_MODE("-updatedestreakedfile", "update parameters of destreaked file",
     272                    MAGICDSTOOL_MODE_UPDATEDESTREAKEDFILE, updatedestreakedfileArgs);
     273
    232274
    233275    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
  • trunk/pstamp/scripts/pstamp_checkdependent.pl

    r29348 r29561  
    197197    if (!$job_fault and ($stage eq 'chip')) {
    198198        # chip processing is done, start destreaking.
    199         $job_fault = check_states_magicDSRun($stage, $stage_id, $rlabel, $need_magic, $it->{raw_magicked}, $it->{dsRun_state});
     199        my @chips;
     200        push @chips, $it->{class_id};
     201        $job_fault = check_states_magicDSRun($stage, $stage_id, \@chips, $rlabel, $need_magic, $it->{raw_magicked}, $it->{magic_ds_id}, $it->{dsRun_state});
    200202    }
    201203    if ($job_fault) {
     
    217219    my $dsRun_state;
    218220    my $raw_all_magicked = 1; # this gets cleared if any of the inputs aren't destreaked
     221    my @chips;
     222    my $magic_ds_id;
    219223    if (!$whole_run) {
    220224        foreach my $chip (@$metadatas) {
    221225            $dsRun_state = $chip->{dsRun_state};
    222226            $raw_all_magicked &= ($chip->{raw_magicked} > 0);
     227            $magic_ds_id = $chip->{magic_ds_id};
     228
     229            push @chips, $chip->{class_id};
    223230
    224231            if (($chip->{state} =~ /error/) or ($chip->{state} =~ /purged/) or ($chip->{state} =~ /scrubbed/)) {
     
    273280    }
    274281
    275     my $status = check_states_magicDSRun('chip', $chip_id, $rlabel, $need_magic, $raw_all_magicked, $dsRun_state);
     282    my $status = check_states_magicDSRun('chip', $chip_id, \@chips, $rlabel, $need_magic, $raw_all_magicked, $magic_ds_id, $dsRun_state);
    276283
    277284    return $status;
     
    633640    my $stage = shift;
    634641    my $stage_id = shift;
     642    my $components = shift;
    635643    my $rlabel  = shift;
    636644    my $need_magic = shift;
    637645    my $input_magicked = shift;
     646    my $magic_ds_id = shift;
    638647    my $dsRun_state = shift;
    639648
    640649    # XXX: this code assumes that destreaking is handled at the chip stage
    641     my_die ("check_states_magicDSRun only works for stage chip", $PS_EXIT_PROG_ERROR) if $stage ne 'chip';
     650    my_die ("check_states_magicDSRun only implemented for chip stage", $PS_EXIT_PROG_ERROR) if $stage ne 'chip';
    642651
    643652    # if called from check_states_warp dsRun_state is unknown. Go find it.
     
    654663            print "No magicDSRun for chipRun $stage_id and magic is required\n";
    655664            faultJobs('stop', undef, undef, $PSTAMP_NOT_DESTREAKED);
    656         } elsif ($dsRun_state eq 'cleaned') {
    657             my $command = "$magicdstool -updaterun -set_state new -stage $stage -stage_id $stage_id";
    658             $command .= " -set_label $rlabel" if $rlabel;
    659             if (!$no_update) {
    660                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    661                     run(command => $command, verbose => $verbose);
    662                 unless ($success) {
    663                     my_die("failed to set destreak run to 'new' for ${stage}Run $stage_id",
    664                         $PS_EXIT_UNKNOWN_ERROR);
     665        } elsif (($dsRun_state eq 'cleaned') or ($dsRun_state eq 'update')) {
     666            foreach my $c (@$components) {
     667                my $command = "$magicdstool -setfiletoupdate -magic_ds_id $magic_ds_id -component $c";
     668                $command .= " -set_label $rlabel" if $rlabel;
     669                if (!$no_update) {
     670                    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     671                        run(command => $command, verbose => $verbose);
     672                    unless ($success) {
     673                        my_die("failed to set destreaked component to 'update' for ${stage}Run $stage_id $c",
     674                            $PS_EXIT_UNKNOWN_ERROR);
     675                    }
     676                } else {
     677                    print "skipping $command\n";
    665678                }
    666             } else {
    667                 print "skipping $command\n";
    668679            }
    669680        } elsif ($dsRun_state eq 'failed_revert') {
  • trunk/pstamp/scripts/pstamp_get_image_job.pl

    r27874 r29561  
    105105    $command .= " --prefix $prefix";
    106106    $command .= " --magicked" if $magicked;
     107    # DANGER DANGER do not commit next line
     108#    $command .= " --no_magic";
     109    # DANGER DANGER do not commit last line
    107110    $command .= " --dbname $dbname" if $dbname;
    108111    $command .= " --verbose" if $verbose;
  • trunk/pstamp/scripts/pstamp_server_status

    r29174 r29561  
    5757    $error_code = (($error_code >> 8) or 1);
    5858    if ($error_code == 12) {
    59         print "Postage Stamp Server is not running\n";
     59        #print "Postage Stamp Server is not running\n";
     60        print "Postage Stamp Server will be down for maintenance until approximately 0400 UTC October 26\n";
    6061        exit 0;
    6162    }
Note: See TracChangeset for help on using the changeset viewer.