IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 28, 2007, 12:01:22 PM (19 years ago)
Author:
jhoblitt
Message:

refactor chiptool & db to preserve metadata history

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/backtrack/ippTools/src/chiptool.c

    r13937 r13990  
    4242static bool unblockMode(pxConfig *config);
    4343
    44 static chipProcessedImfileRow *chipPendingToProcessedImfile(pxConfig *config, chipPendingImfileRow *imfile);
    45 static chipProcessedExpRow *chipPendingToProcessedExp(pxConfig *config, chipPendingExpRow *pendingExp);
    4644static bool chipProcessedCompleteExp(pxConfig *config);
    4745
     
    346344    PS_ASSERT_PTR_NON_NULL(config, false);
    347345
    348     // select * from chipProcessedImfiles
    349     // where
    350     // exp_tag & class_id are not in chipPendingImfile
    351 
    352     // add the completed imfile to
    353     // the chipProcessedeImfile tables
    354     // remove corresponding entries from the
    355     // chipPendingImfile table
    356     // check to see if any chipPendingExps have no
    357     // associated chipPendingImfiles
    358     // if so move the chipPendingExp(s) to chipProcessedExp
    359 
    360     psString query = pxDataGet("chiptool_find_unprocessed_imfile.pl");
    361     if (!query) {
    362         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    363         return false;
    364     }
    365 
    366     {
    367         psMetadata *where = psMetadataAlloc();
    368         bool status = false;
    369         psString chip_id = psMetadataLookupStr(&status, config->args, "-chip_id");        if (!status) {
    370             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -chip_id");
    371             psFree(query);
    372             return false;
    373         }
    374         if (chip_id) {
    375             if (!psMetadataAddStr(where, PS_LIST_TAIL, "chip_id", 0, "==", chip_id)) {
    376                 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id");
    377                 psFree(where);
    378                 psFree(query);
    379                 return false;
    380             }
    381         }
    382 
    383         psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
    384         if (!status) {
    385             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
    386             psFree(query);
    387             return false;
    388         }
    389         if (class_id) {
    390             if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", class_id)) {
    391                 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    392                 psFree(where);
    393                 psFree(query);
    394                 return false;
    395             }
    396         }
    397 
    398         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipPendingImfile");
    399         psFree(where);
    400         if (whereClause) {
    401             psStringAppend(&query, " AND %s", whereClause);
    402             psFree(whereClause);
    403         }
    404     }
    405 
    406     if (!p_psDBRunQuery(config->dbh, query)) {
    407         psError(PS_ERR_UNKNOWN, false, "database error");
    408         psFree(query);
    409         return false;
    410     }
    411     psFree(query);
    412 
    413     psArray *output = p_psDBFetchResult(config->dbh);
    414     if (!output) {
    415         psError(PS_ERR_UNKNOWN, false, "database error");
    416         return false;
    417     }
    418     if (!psArrayLength(output)) {
    419         // XXX check psError here
    420         psError(PS_ERR_UNKNOWN, false, "no chipPendingImfile rows found");
    421         psFree(output);
    422         return false;
    423     }
    424 
    425     // start a transaction so we don't end up with an incremented iteration
    426     // count but no detInputExps
    427     if (!psDBTransaction(config->dbh)) {
    428         psError(PS_ERR_UNKNOWN, false, "database error");
    429         psFree(output);
    430         return false;
    431     }
    432 
    433     // insert into chipProcessedImfile
    434     // remove chipPendingImfile entry
    435     for (long i = 0; i < psArrayLength(output); i++) {
    436         psMetadata *row = output->data[i];
    437         // convert metadata into a chipPendingImfile object
    438         chipPendingImfileRow *object = chipPendingImfileObjectFromMetadata(row);
    439         // convert chipPendingImfile object into a chipProcessedImfile object
    440         chipProcessedImfileRow *imfile = chipPendingToProcessedImfile(config, object);
    441         if (!imfile) {
    442             // rollback
    443             if (!psDBRollback(config->dbh)) {
    444                 psError(PS_ERR_UNKNOWN, false, "database error");
    445             }
    446             psError(PS_ERR_UNKNOWN, false, "failed to convert chipPendingImfile to chipProcessedImfile");
    447             psFree(object);
    448             psFree(output);
    449             return false;
    450         }
    451         // insert chipProccessedImfile object into the database
    452         if (!chipProcessedImfileInsertObject(config->dbh, imfile)) {
    453             // rollback
    454             if (!psDBRollback(config->dbh)) {
    455                 psError(PS_ERR_UNKNOWN, false, "database error");
    456             }
    457             psError(PS_ERR_UNKNOWN, false, "database error");
    458             psFree(imfile);
    459             psFree(object);
    460             psFree(output);
    461             return false;
    462         }
    463         psFree(imfile);
    464         // delete the chipPendingImfile object from the database
    465         if (!chipPendingImfileDeleteObject(config->dbh, object)) {
    466             // there must be atleast 1 Imfile to get this far
    467             // rollback
    468             if (!psDBRollback(config->dbh)) {
    469                 psError(PS_ERR_UNKNOWN, false, "database error");
    470             }
    471             psError(PS_ERR_UNKNOWN, false, "database error");
    472             psFree(object);
    473             psFree(output);
    474             return false;
    475         }
    476         psFree(object);
    477     }
    478 
    479     psFree(output);
    480 
    481     // XXX I've decided to make the transaction cover the Exp migration as
    482     // well.  Otherwise, if the last imfile in an exp is moved and the exp
    483     // migration fails then the data base is left in a satuation where the exp
    484     // migration can't happen.
    485 
    486     if (!chipProcessedCompleteExp(config)) {
    487         // rollback
    488         if (!psDBRollback(config->dbh)) {
    489             psError(PS_ERR_UNKNOWN, false, "database error");
    490         }
    491         psError(PS_ERR_UNKNOWN, false, "database error");
    492         return false;
    493     }
    494 
    495     // point of no return for chipPendingImfile -> chipProcessedImfile
    496     // point of no return for chipPendingExp -> chipProcessedExp
    497     if (!psDBCommit(config->dbh)) {
    498         psError(PS_ERR_UNKNOWN, false, "database error");
    499         return false;
    500     }
    501 
    502     return true;
    503 }
    504 
    505 
    506 static bool processedimfileMode(pxConfig *config)
    507 {
    508     PS_ASSERT_PTR_NON_NULL(config, NULL);
    509 
    510346    bool status = false;
    511     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    512     if (!status) {
    513         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    514         return false;
    515     }
    516 
    517     bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
    518     if (!status) {
    519         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
    520         return false;
    521     }
    522 
    523     // XXX does this need to be constrained so that it won't return any results
    524     // if a match chipPendingExp hasn't been registered?
    525     psString query = pxDataGet("chiptool_processedimfile.sql");
    526     if (!query) {
    527         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    528         return false;
    529     }
    530 
    531     if (config->where) {
    532         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipProcessedImfile");
    533         psStringAppend(&query, " AND %s", whereClause);
    534         psFree(whereClause);
    535     }
    536 
    537     if (faulted) {
    538         // list only faulted rows
    539         psStringAppend(&query, " %s", "AND chipProcessedImfile.fault != 0");
    540     } else {
    541         // don't list faulted rows
    542         psStringAppend(&query, " %s", "AND chipProcessedImfile.fault = 0");
    543     }
    544 
    545     // treat limit == 0 as "no limit"
    546     if (limit) {
    547         psString limitString = psDBGenerateLimitSQL(limit);
    548         psStringAppend(&query, " %s", limitString);
    549         psFree(limitString);
    550     }
    551 
    552     if (!p_psDBRunQuery(config->dbh, query)) {
    553         psError(PS_ERR_UNKNOWN, false, "database error");
    554         psFree(query);
    555         return false;
    556     }
    557     psFree(query);
    558 
    559     psArray *output = p_psDBFetchResult(config->dbh);
    560     if (!output) {
    561         psError(PS_ERR_UNKNOWN, false, "database error");
    562         return false;
    563     }
    564     if (!psArrayLength(output)) {
    565         psTrace("chiptool", PS_LOG_INFO, "no rows found");
    566         psFree(output);
    567         return true;
    568     }
    569 
    570     bool simple = false;
    571     {
    572         bool status = false;
    573         simple = psMetadataLookupBool(&status, config->args, "-simple");
    574         if (!status) {
    575             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    576             return false;
    577         }
    578     }
    579 
    580     if (!convertIdToStr(output)) {
    581         psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
    582         psFree(output);
    583         return false;
    584     }
    585 
    586     // negative simple so the default is true
    587     if (!ippdbPrintMetadatas(stdout, output, "chipProcessedImfile", !simple)) {
    588         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    589         psFree(output);
    590         return false;
    591     }
    592 
    593     psFree(output);
    594 
    595     return true;
    596 }
    597 
    598 
    599 static bool updateprocessedimfileMode(pxConfig *config)
    600 {
    601     PS_ASSERT_PTR_NON_NULL(config, false);
    602 
    603     bool status = false;
    604     psS16 code = psMetadataLookupS16(&status, config->args, "-code");
    605     if (!status) {
    606         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
    607         return false;
    608     }
    609     if (code == INT16_MAX) {
    610         psError(PS_ERR_UNKNOWN, true, "-code is required");
    611         return false;
    612     }
    613 
    614     if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", config->where, code)) {
    615         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
    616         return false;
    617     }
    618 
    619     return true;
    620 }
    621 
    622 
    623 static bool blockMode(pxConfig *config)
    624 {
    625     PS_ASSERT_PTR_NON_NULL(config, false);
    626 
    627     bool status = false;
    628     psString label = psMetadataLookupStr(&status, config->args, "-label");
    629     if (!status) {
    630         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label");
    631         return false;
    632     }
    633     if (!label) {
    634         psError(PS_ERR_UNKNOWN, true, "-label is required");
    635         return false;
    636     }
    637 
    638     if (!chipMaskInsert(config->dbh, label)) {
    639         psError(PS_ERR_UNKNOWN, false, "database error");
    640         return false;
    641     }
    642 
    643     return true;
    644 }
    645 
    646 
    647 static bool maskedMode(pxConfig *config)
    648 {
    649     PS_ASSERT_PTR_NON_NULL(config, false);
    650 
    651     psString query = psStringCopy("SELECT * FROM chipMask");
    652 
    653     if (!p_psDBRunQuery(config->dbh, query)) {
    654         psError(PS_ERR_UNKNOWN, false, "database error");
    655         psFree(query);
    656         return false;
    657     }
    658     psFree(query);
    659 
    660     psArray *output = p_psDBFetchResult(config->dbh);
    661     if (!output) {
    662         psError(PS_ERR_UNKNOWN, false, "database error");
    663         return false;
    664     }
    665     if (!psArrayLength(output)) {
    666         psTrace("chiptool", PS_LOG_INFO, "no rows found");
    667         psFree(output);
    668         return true;
    669     }
    670 
    671     bool simple = false;
    672     {
    673         bool status = false;
    674         simple = psMetadataLookupBool(&status, config->args, "-simple");
    675         if (!status) {
    676             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    677             return false;
    678         }
    679     }
    680 
    681     if (!convertIdToStr(output)) {
    682         psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
    683         psFree(output);
    684         return false;
    685     }
    686 
    687     // negative simple so the default is true
    688     if (!ippdbPrintMetadatas(stdout, output, "chipMask", !simple)) {
    689         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    690         psFree(output);
    691         return false;
    692     }
    693 
    694     psFree(output);
    695 
    696     return true;
    697 }
    698 
    699 
    700 static bool unblockMode(pxConfig *config)
    701 {
    702     PS_ASSERT_PTR_NON_NULL(config, false);
    703 
    704     bool status = false;
    705     psString label = psMetadataLookupStr(&status, config->args, "-label");
    706     if (!status) {
    707         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label");
    708         return false;
    709     }
    710     if (!label) {
    711         psError(PS_ERR_UNKNOWN, true, "-label is required");
    712         return false;
    713     }
    714 
    715     char *query = "DELETE FROM chipMask WHERE label = '%s'";
    716 
    717     if (!p_psDBRunQuery(config->dbh, query, label)) {
    718         psError(PS_ERR_UNKNOWN, false, "database error");
    719         psFree(query);
    720         return false;
    721     }
    722 
    723     return true;
    724 }
    725 
    726 
    727 static bool chipProcessedCompleteExp(pxConfig *config)
    728 {
    729     PS_ASSERT_PTR_NON_NULL(config, false);
    730 
    731     // look for completed chipPendingExp
    732     // migrate them to chipProccessedExp & camPendingExp
    733     psString query = pxDataGet("chiptool_completely_processed_exp.sql");
    734     if (!query) {
    735         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    736         return false;
    737     }
    738 
    739     if (!p_psDBRunQuery(config->dbh, query)) {
    740         psError(PS_ERR_UNKNOWN, false, "database error");
    741         psFree(query);
    742         return false;
    743     }
    744     psFree(query);
    745 
    746     psArray *output = p_psDBFetchResult(config->dbh);
    747     if (!output) {
    748         psError(PS_ERR_UNKNOWN, false, "database error");
    749         return false;
    750     }
    751     if (!psArrayLength(output)) {
    752         psTrace("chiptool", PS_LOG_INFO, "no rows found");
    753         psFree(output);
    754         return true;
    755     }
    756 
    757     // insert into chipProcessedExp
    758     // insert into camPendingExp
    759     // remove chipPendingExp entry
    760     for (long i = 0; i < psArrayLength(output); i++) {
    761         psMetadata *row = output->data[i];
    762 
    763         // convert metadata into a chipPendingExp object
    764         chipPendingExpRow *pendingExp = chipPendingExpObjectFromMetadata(row);
    765         if (!pendingExp) {
    766             psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipPendingExp");
    767             psFree(output);
    768             return false;
    769         }
    770 
    771         // convert chipPendingExp object into a chipProcesseExp object
    772         chipProcessedExpRow *processedExp = chipPendingToProcessedExp(config, pendingExp);
    773         if (!processedExp) {
    774             psError(PS_ERR_UNKNOWN, false, "failed to convert chipPendingExp to chipProcessedExp");
    775             psFree(pendingExp);
    776             psFree(output);
    777             return false;
    778         }
    779 
    780         // delete the chipPendingExp object from the database
    781         if (!chipPendingExpDeleteObject(config->dbh, pendingExp)) {
    782             // there must be atleast 1 Imfile to get this far
    783             psError(PS_ERR_UNKNOWN, false, "database error");
    784             psFree(processedExp);
    785             psFree(pendingExp);
    786             psFree(output);
    787             return false;
    788         }
    789         psFree(pendingExp);
    790 
    791         // insert chipProccessedExp object into the database
    792         if (!chipProcessedExpInsertObject(config->dbh, processedExp)) {
    793             psError(PS_ERR_UNKNOWN, false, "database error");
    794             psFree(processedExp);
    795             psFree(output);
    796             return false;
    797         }
    798 
    799         // camQueueChipID() can only be run after the chipProcessedExp entry
    800         // has been inserted.
    801         // queue the chip_id in the camPendingExp table
    802         if (!camQueueChipID(config,
    803                     processedExp->chip_id,
    804                     processedExp->workdir,
    805                     processedExp->label,
    806                     processedExp->reduction,
    807                     processedExp->expgroup,
    808                     processedExp->dvodb
    809         )) {
    810             // rollback
    811             if (!psDBRollback(config->dbh)) {
    812                 psError(PS_ERR_UNKNOWN, false, "database error");
    813             }
    814             psError(PS_ERR_UNKNOWN, false, "failed to queue camPendingExp");
    815             psFree(processedExp);
    816             psFree(output);
    817             return false;
    818         }
    819 
    820         psFree(processedExp);
    821     }
    822 
    823     psFree(output);
    824 
    825     return true;
    826 }
    827 
    828 
    829 static chipProcessedImfileRow *chipPendingToProcessedImfile(pxConfig *config, chipPendingImfileRow *imfile)
    830 {
    831     PS_ASSERT_PTR_NON_NULL(config, NULL);
    832     PS_ASSERT_PTR_NON_NULL(imfile, NULL);
    833 
    834     bool status = false;
     347    // chip_id, ext_tag, class_id are required
     348    psString chip_id = psMetadataLookupStr(&status, config->args, "-chip_id");
     349    if (!status) {
     350        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -chip_id");
     351        return false;
     352    }
     353    if (!chip_id) {
     354        psError(PS_ERR_UNKNOWN, true, "-chip_id is required");
     355        return false;
     356    }
     357
     358    psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
     359    if (!status) {
     360        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
     361        return false;
     362    }
     363    if (!exp_tag) {
     364        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
     365        return false;
     366    }
     367
     368    psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
     369    if (!status) {
     370        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
     371        return false;
     372    }
     373    if (!class_id) {
     374        psError(PS_ERR_UNKNOWN, true, "-class_id is required");
     375        return false;
     376    }
     377
    835378    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
    836379    if (!status) {
     
    961504    }
    962505
    963     return chipProcessedImfileRowAlloc(
    964         imfile->chip_id,
    965         imfile->class_id,
     506    if (!psDBTransaction(config->dbh)) {
     507        psError(PS_ERR_UNKNOWN, false, "database error");
     508        return false;
     509    }
     510
     511    chipProcessedImfileRow *imfile = chipProcessedImfileRowAlloc(
     512        (psU64)atoll(chip_id),
     513        exp_tag,
     514        class_id,
    966515        uri,
    967516        bg,
     
    985534        path_base,
    986535        code
    987         );
    988 }
    989 
    990 
    991 static chipProcessedExpRow *chipPendingToProcessedExp(pxConfig *config, chipPendingExpRow *pendingExp)
     536    );
     537    if (!imfile) {
     538        // rollback
     539        if (!psDBRollback(config->dbh)) {
     540            psError(PS_ERR_UNKNOWN, false, "database error");
     541        }
     542        psError(PS_ERR_UNKNOWN, false, "failed to alloc chipProcessedImfileRow object");
     543        return false;
     544    }
     545    if (!chipProcessedImfileInsertObject(config->dbh, imfile)) {
     546        // rollback
     547        if (!psDBRollback(config->dbh)) {
     548            psError(PS_ERR_UNKNOWN, false, "database error");
     549        }
     550        psError(PS_ERR_UNKNOWN, false, "database error");
     551        psFree(imfile);
     552        return false;
     553    }
     554
     555    // XXX I've decided to make the transaction cover the Exp migration as
     556    // well.  Otherwise, if the last imfile in an exp is moved and the exp
     557    // migration fails then the data base is left in a satuation where the exp
     558    // migration can't happen.
     559
     560    if (!chipProcessedCompleteExp(config)) {
     561        // rollback
     562        if (!psDBRollback(config->dbh)) {
     563            psError(PS_ERR_UNKNOWN, false, "database error");
     564        }
     565        psError(PS_ERR_UNKNOWN, false, "database error");
     566        return false;
     567    }
     568
     569    if (!psDBCommit(config->dbh)) {
     570        psError(PS_ERR_UNKNOWN, false, "database error");
     571        return false;
     572    }
     573
     574    return true;
     575}
     576
     577
     578static bool processedimfileMode(pxConfig *config)
    992579{
    993     PS_ASSERT_PTR_NON_NULL(pendingExp, NULL);
    994 
    995     return chipProcessedExpRowAlloc(
    996         pendingExp->chip_id,
    997         pendingExp->exp_tag,
    998         pendingExp->guide_id,
    999         pendingExp->workdir,
    1000         pendingExp->label,
    1001         pendingExp->reduction,
    1002         pendingExp->expgroup,
    1003         pendingExp->dvodb
    1004     );
    1005 }
     580    PS_ASSERT_PTR_NON_NULL(config, NULL);
     581
     582    bool status = false;
     583    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
     584    if (!status) {
     585        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
     586        return false;
     587    }
     588
     589    bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
     590    if (!status) {
     591        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
     592        return false;
     593    }
     594
     595    // XXX does this need to be constrained so that it won't return any results
     596    // if a match chipPendingExp hasn't been registered?
     597    psString query = pxDataGet("chiptool_processedimfile.sql");
     598    if (!query) {
     599        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     600        return false;
     601    }
     602
     603    if (config->where) {
     604        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipProcessedImfile");
     605        psStringAppend(&query, " AND %s", whereClause);
     606        psFree(whereClause);
     607    }
     608
     609    if (faulted) {
     610        // list only faulted rows
     611        psStringAppend(&query, " %s", "AND chipProcessedImfile.fault != 0");
     612    } else {
     613        // don't list faulted rows
     614        psStringAppend(&query, " %s", "AND chipProcessedImfile.fault = 0");
     615    }
     616
     617    // treat limit == 0 as "no limit"
     618    if (limit) {
     619        psString limitString = psDBGenerateLimitSQL(limit);
     620        psStringAppend(&query, " %s", limitString);
     621        psFree(limitString);
     622    }
     623
     624    if (!p_psDBRunQuery(config->dbh, query)) {
     625        psError(PS_ERR_UNKNOWN, false, "database error");
     626        psFree(query);
     627        return false;
     628    }
     629    psFree(query);
     630
     631    psArray *output = p_psDBFetchResult(config->dbh);
     632    if (!output) {
     633        psError(PS_ERR_UNKNOWN, false, "database error");
     634        return false;
     635    }
     636    if (!psArrayLength(output)) {
     637        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     638        psFree(output);
     639        return true;
     640    }
     641
     642    bool simple = false;
     643    {
     644        bool status = false;
     645        simple = psMetadataLookupBool(&status, config->args, "-simple");
     646        if (!status) {
     647            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     648            return false;
     649        }
     650    }
     651
     652    if (!convertIdToStr(output)) {
     653        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     654        psFree(output);
     655        return false;
     656    }
     657
     658    // negative simple so the default is true
     659    if (!ippdbPrintMetadatas(stdout, output, "chipProcessedImfile", !simple)) {
     660        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     661        psFree(output);
     662        return false;
     663    }
     664
     665    psFree(output);
     666
     667    return true;
     668}
     669
     670
     671static bool updateprocessedimfileMode(pxConfig *config)
     672{
     673    PS_ASSERT_PTR_NON_NULL(config, false);
     674
     675    bool status = false;
     676    psS16 code = psMetadataLookupS16(&status, config->args, "-code");
     677    if (!status) {
     678        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
     679        return false;
     680    }
     681    if (code == INT16_MAX) {
     682        psError(PS_ERR_UNKNOWN, true, "-code is required");
     683        return false;
     684    }
     685
     686    if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", config->where, code)) {
     687        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
     688        return false;
     689    }
     690
     691    return true;
     692}
     693
     694
     695static bool blockMode(pxConfig *config)
     696{
     697    PS_ASSERT_PTR_NON_NULL(config, false);
     698
     699    bool status = false;
     700    psString label = psMetadataLookupStr(&status, config->args, "-label");
     701    if (!status) {
     702        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label");
     703        return false;
     704    }
     705    if (!label) {
     706        psError(PS_ERR_UNKNOWN, true, "-label is required");
     707        return false;
     708    }
     709
     710    if (!chipMaskInsert(config->dbh, label)) {
     711        psError(PS_ERR_UNKNOWN, false, "database error");
     712        return false;
     713    }
     714
     715    return true;
     716}
     717
     718
     719static bool maskedMode(pxConfig *config)
     720{
     721    PS_ASSERT_PTR_NON_NULL(config, false);
     722
     723    psString query = psStringCopy("SELECT * FROM chipMask");
     724
     725    if (!p_psDBRunQuery(config->dbh, query)) {
     726        psError(PS_ERR_UNKNOWN, false, "database error");
     727        psFree(query);
     728        return false;
     729    }
     730    psFree(query);
     731
     732    psArray *output = p_psDBFetchResult(config->dbh);
     733    if (!output) {
     734        psError(PS_ERR_UNKNOWN, false, "database error");
     735        return false;
     736    }
     737    if (!psArrayLength(output)) {
     738        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     739        psFree(output);
     740        return true;
     741    }
     742
     743    bool simple = false;
     744    {
     745        bool status = false;
     746        simple = psMetadataLookupBool(&status, config->args, "-simple");
     747        if (!status) {
     748            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     749            return false;
     750        }
     751    }
     752
     753    if (!convertIdToStr(output)) {
     754        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     755        psFree(output);
     756        return false;
     757    }
     758
     759    // negative simple so the default is true
     760    if (!ippdbPrintMetadatas(stdout, output, "chipMask", !simple)) {
     761        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     762        psFree(output);
     763        return false;
     764    }
     765
     766    psFree(output);
     767
     768    return true;
     769}
     770
     771
     772static bool unblockMode(pxConfig *config)
     773{
     774    PS_ASSERT_PTR_NON_NULL(config, false);
     775
     776    bool status = false;
     777    psString label = psMetadataLookupStr(&status, config->args, "-label");
     778    if (!status) {
     779        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label");
     780        return false;
     781    }
     782    if (!label) {
     783        psError(PS_ERR_UNKNOWN, true, "-label is required");
     784        return false;
     785    }
     786
     787    char *query = "DELETE FROM chipMask WHERE label = '%s'";
     788
     789    if (!p_psDBRunQuery(config->dbh, query, label)) {
     790        psError(PS_ERR_UNKNOWN, false, "database error");
     791        psFree(query);
     792        return false;
     793    }
     794
     795    return true;
     796}
     797
     798
     799static bool chipProcessedCompleteExp(pxConfig *config)
     800{
     801    PS_ASSERT_PTR_NON_NULL(config, false);
     802
     803    // look for completed chipPendingExp
     804    // migrate them to chipProccessedExp & camPendingExp
     805    psString query = pxDataGet("chiptool_completely_processed_exp.sql");
     806    if (!query) {
     807        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     808        return false;
     809    }
     810
     811    if (!p_psDBRunQuery(config->dbh, query)) {
     812        psError(PS_ERR_UNKNOWN, false, "database error");
     813        psFree(query);
     814        return false;
     815    }
     816    psFree(query);
     817
     818    psArray *output = p_psDBFetchResult(config->dbh);
     819    if (!output) {
     820        psError(PS_ERR_UNKNOWN, false, "database error");
     821        return false;
     822    }
     823    if (!psArrayLength(output)) {
     824        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     825        psFree(output);
     826        return true;
     827    }
     828
     829    // insert into camPendingExp
     830    for (long i = 0; i < psArrayLength(output); i++) {
     831        psMetadata *row = output->data[i];
     832
     833        chipRunRow *chipRun = chipRunObjectFromMetadata(row);
     834
     835        // camQueueChipID() can only be run after the chipProcessedExp entry
     836        // has been inserted.
     837        // queue the chip_id in the camPendingExp table
     838        if (!camQueueChipID(config,
     839                    chipRun->chip_id,
     840                    chipRun->workdir,
     841                    chipRun->label,
     842                    chipRun->reduction,
     843                    chipRun->expgroup,
     844                    chipRun->dvodb
     845        )) {
     846            // rollback
     847            if (!psDBRollback(config->dbh)) {
     848                psError(PS_ERR_UNKNOWN, false, "database error");
     849            }
     850            psError(PS_ERR_UNKNOWN, false, "failed to queue camPendingExp");
     851            psFree(chipRun);
     852            psFree(output);
     853            return false;
     854        }
     855        psFree(chipRun);
     856    }
     857
     858    psFree(output);
     859
     860    return true;
     861}
Note: See TracChangeset for help on using the changeset viewer.