IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 15, 2008, 4:16:16 PM (18 years ago)
Author:
Paul Price
Message:

Adding revert options, fault code handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/magictool.c

    r18571 r18573  
    3838static bool totreeMode(pxConfig *config);
    3939static bool inputtreeMode(pxConfig *config);
     40static bool reverttreeMode(pxConfig *config);
    4041static bool toprocessMode(pxConfig *config);
    4142static bool addresultMode(pxConfig *config);
     43static bool revertnodeMode(pxConfig *config);
    4244static bool inputsMode(pxConfig *config);
    4345static bool tomaskMode(pxConfig *config);
    4446static bool addmaskMode(pxConfig *config);
     47static bool revertmaskMode(pxConfig *config);
    4548static bool maskMode(pxConfig *config);
    4649
     
    7376        MODECASE(MAGICTOOL_MODE_TOTREE,         totreeMode);
    7477        MODECASE(MAGICTOOL_MODE_INPUTTREE,      inputtreeMode);
     78        MODECASE(MAGICTOOL_MODE_REVERTTREE,     reverttreeMode);
    7579        MODECASE(MAGICTOOL_MODE_TOPROCESS,      toprocessMode);
    7680        MODECASE(MAGICTOOL_MODE_ADDRESULT,      addresultMode);
     81        MODECASE(MAGICTOOL_MODE_REVERTNODE,     revertnodeMode);
    7782        MODECASE(MAGICTOOL_MODE_INPUTS,         inputsMode);
    7883        MODECASE(MAGICTOOL_MODE_TOMASK,         tomaskMode);
    7984        MODECASE(MAGICTOOL_MODE_ADDMASK,        addmaskMode);
     85        MODECASE(MAGICTOOL_MODE_REVERTMASK,     revertmaskMode);
    8086        MODECASE(MAGICTOOL_MODE_MASK,           maskMode);
    8187        default:
     
    512518
    513519    if (code > 0) {
    514         char *query = "UPDATE magicRun SET fault = %d WHERE magic_id = %" PRId64;
     520        char *query = "UPDATE magicRun SET fault = %d, state = 'stop' WHERE magic_id = %" PRId64;
    515521        if (!p_psDBRunQuery(config->dbh, query, code, magic_id)) {
    516522            psError(PS_ERR_UNKNOWN, false,
     
    528534    return true;
    529535}
     536
     537static bool reverttreeMode(pxConfig *config)
     538{
     539    PS_ASSERT_PTR_NON_NULL(config, false);
     540
     541    psMetadata *where = psMetadataAlloc();
     542    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     543    PXOPT_COPY_S16(config->args, where, "-code", "fault", "==");
     544
     545    psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = 'run' WHERE fault != 0");
     546
     547    if (psListLength(where->list)) {
     548        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     549        psStringAppend(&query, " AND %s", whereClause);
     550        psFree(whereClause);
     551    }
     552    psFree(where);
     553
     554    if (!p_psDBRunQuery(config->dbh, query)) {
     555        psError(PS_ERR_UNKNOWN, false, "failed to revert");
     556        return false;
     557    }
     558    return true;
     559}
     560
    530561
    531562static bool inputsMode(pxConfig *config)
     
    622653bool findReadyNodes(void *arg, pxNode *node)
    623654{
     655    if (!node) {
     656        // It's not there --- must have failed
     657        return false;
     658    }
     659
    624660    if (psMetadataLookupBool(NULL, node->data, "done")) {
    625661        // It's already done
     
    632668        psMetadataRemoveKey(work, "dep");
    633669        psMetadataRemoveKey(work, "done");
    634 #if 0
    635         psMetadataRemoveKey(work, "uri");
    636 #endif
    637670        pxNode *child = NULL;
    638671        while ((child = psListGetAndIncrement(iter))) {
     
    644677                psAbort("failed to lookup value for done column");
    645678            }
    646 
    647             if (!done) {
     679            psS16 bad = psMetadataLookupS16(&status, data, "bad");
     680            if (!status) {
     681                psAbort("failed to lookup value for bad column");
     682            }
     683
     684            if (!done || bad) {
    648685                // if a child isn't "done", give up on this node and continue
    649686                // to crawl the tree
     
    652689                return true;
    653690            }
    654 #if 0
    655             char *uri = psMetadataLookupStr(&status, data, "uri");
    656             if (!status) {
    657                 psAbort("failed to lookup value for uri column");
    658             }
    659 
    660             psMetadataAddStr(work, PS_LIST_TAIL, "uri", PS_META_DUPLICATE_OK, NULL, uri);
    661 #endif
    662691        }
    663692        psFree(iter);
     
    835864}
    836865
     866static bool revertnodeMode(pxConfig *config)
     867{
     868    PS_ASSERT_PTR_NON_NULL(config, false);
     869
     870    psMetadata *where = psMetadataAlloc();
     871    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     872    PXOPT_COPY_STR(config->args, where, "-node", "node", "==");
     873    PXOPT_COPY_S16(config->args, where, "-code", "fault", "==");
     874
     875    psString query = psStringCopy("DELETE FROM magicNodeResult WHERE fault != 0");
     876
     877    if (psListLength(where->list)) {
     878        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     879        psStringAppend(&query, " AND %s", whereClause);
     880        psFree(whereClause);
     881    }
     882    psFree(where);
     883
     884    if (!p_psDBRunQuery(config->dbh, query)) {
     885        psError(PS_ERR_UNKNOWN, false, "failed to revert");
     886        return false;
     887    }
     888    return true;
     889}
     890
     891
    837892static bool tomaskMode(pxConfig *config)
    838893{
     
    885940    if (psArrayLength(output)) {
    886941        // negative simple so the default is true
    887         if (!ippdbPrintMetadatas(stdout, output, "toprocess", !simple)) {
     942        if (!ippdbPrintMetadatas(stdout, output, "tomask", !simple)) {
    888943            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    889944            psFree(output);
     
    924979        )) {
    925980        psError(PS_ERR_UNKNOWN, false, "database error");
     981        if (!psDBRollback(config->dbh)) {
     982            psError(PS_ERR_UNKNOWN, false, "database error");
     983        }
    926984        return false;
    927985    }
     
    931989    if (!query) {
    932990        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     991        if (!psDBRollback(config->dbh)) {
     992            psError(PS_ERR_UNKNOWN, false, "database error");
     993        }
    933994        return false;
    934995    }
     
    9401001        psError(PS_ERR_UNKNOWN, false, "database error");
    9411002        psFree(query);
     1003        if (!psDBRollback(config->dbh)) {
     1004            psError(PS_ERR_UNKNOWN, false, "database error");
     1005        }
    9421006        return false;
    9431007    }
     
    9481012        return false;
    9491013    }
     1014
     1015    return true;
     1016}
     1017
     1018static bool revertmaskMode(pxConfig *config)
     1019{
     1020    PS_ASSERT_PTR_NON_NULL(config, false);
     1021
     1022    psMetadata *where = psMetadataAlloc();
     1023    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     1024    PXOPT_COPY_S16(config->args, where, "-code", "fault", "==");
     1025
     1026    if (!psDBTransaction(config->dbh)) {
     1027        psError(PS_ERR_UNKNOWN, false, "database error");
     1028        return false;
     1029    }
     1030
     1031    // Set to "run"
     1032    {
     1033        psString query = psStringCopy("UPDATE magicRun JOIN magicMask USING(magic_id) "
     1034                                      "SET magicRun.state = 'run' WHERE magicMask.fault != 0");
     1035
     1036        if (psListLength(where->list)) {
     1037            psString whereClause = psDBGenerateWhereConditionSQL(where, "magicMask");
     1038            psStringAppend(&query, " AND %s", whereClause);
     1039            psFree(whereClause);
     1040        }
     1041
     1042        if (!p_psDBRunQuery(config->dbh, query)) {
     1043            psError(PS_ERR_UNKNOWN, false, "failed to revert");
     1044            if (!psDBRollback(config->dbh)) {
     1045                psError(PS_ERR_UNKNOWN, false, "database error");
     1046            }
     1047            return false;
     1048        }
     1049
     1050        psFree(query);
     1051    }
     1052
     1053    // Delete failed attempt at mask
     1054    {
     1055        psString query = psStringCopy("DELETE FROM magicMask WHERE fault != 0");
     1056
     1057        if (psListLength(where->list)) {
     1058            psString whereClause = psDBGenerateWhereConditionSQL(where, "magicMask");
     1059            psStringAppend(&query, " AND %s", whereClause);
     1060            psFree(whereClause);
     1061        }
     1062
     1063        if (!p_psDBRunQuery(config->dbh, query)) {
     1064            psError(PS_ERR_UNKNOWN, false, "failed to revert");
     1065            if (!psDBRollback(config->dbh)) {
     1066                psError(PS_ERR_UNKNOWN, false, "database error");
     1067            }
     1068            return false;
     1069        }
     1070
     1071        psFree(query);
     1072    }
     1073
     1074    if (!psDBCommit(config->dbh)) {
     1075        psError(PS_ERR_UNKNOWN, false, "database error");
     1076        return false;
     1077    }
     1078
     1079    psFree(where);
    9501080
    9511081    return true;
     
    10121142    if (psArrayLength(output)) {
    10131143        // negative simple so the default is true
    1014         if (!ippdbPrintMetadatas(stdout, output, "magicNode", !simple)) {
     1144        if (!ippdbPrintMetadatas(stdout, output, "magicMask", !simple)) {
    10151145            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    10161146            psFree(output);
Note: See TracChangeset for help on using the changeset viewer.