IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 16, 2009, 5:05:19 PM (17 years ago)
Author:
bills
Message:

added new magicDSRun.states goto_restored and goto_censored
The 'revert' process handles processing these transitions
the end result is either 'restored' or 'cesored'
Removed torestoreMode which wasn't implemented yet

File:
1 edited

Legend:

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

    r25419 r25423  
    4040static bool getskycellsMode(pxConfig *config);
    4141static bool toremoveMode(pxConfig *config);
    42 static bool torestoreMode(pxConfig *config);
    4342static bool torevertMode(pxConfig *config);
    4443static bool completedrevertMode(pxConfig *config);
     
    7473        MODECASE(MAGICDSTOOL_MODE_GETSKYCELLS,         getskycellsMode);
    7574        MODECASE(MAGICDSTOOL_MODE_TOREMOVE,            toremoveMode);
    76         MODECASE(MAGICDSTOOL_MODE_TORESTORE,           torestoreMode);
    7775        MODECASE(MAGICDSTOOL_MODE_TOREVERT,            torevertMode);
    7876        MODECASE(MAGICDSTOOL_MODE_COMPLETEDREVERT,     completedrevertMode);
     
    401399
    402400    psMetadata *where = psMetadataAlloc();
    403     PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     401    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "==");
    404402    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
    405403    pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "==");
     
    803801    PS_ASSERT_PTR_NON_NULL(config, false);
    804802
     803    PXOPT_LOOKUP_BOOL(i_am_sure, config->args, "-i_am_sure", true);
     804    if (!i_am_sure) {
     805        psError(PS_ERR_UNKNOWN, true, "Reverting destreaked files must be done carefully. -i_am_sure is required.");
     806        return false;
     807    }
     808
    805809    psMetadata *where = psMetadataAlloc();
    806810    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "==");
     
    809813    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    810814
    811     psString query = psStringCopy("DELETE FROM magicDSFile USING magicDSFile, magicDSRun  WHERE (magicDSRun.magic_ds_id = magicDSFile.magic_ds_id) AND magicDSFile.fault != 0");
     815    psString query = pxDataGet("magicdstool_revertdestreakedfile.sql");
    812816
    813817    if (psListLength(where->list)) {
     
    815819        psStringAppend(&query, " AND %s", whereClause);
    816820        psFree(whereClause);
     821    } else {
     822        psError(PS_ERR_UNKNOWN, true, "search arguments are required");
     823        return false;
    817824    }
    818825    psFree(where);
     
    820827    if (!p_psDBRunQuery(config->dbh, query)) {
    821828        psError(PS_ERR_UNKNOWN, false, "failed to revert");
    822         return false;
    823     }
     829        psFree(query);
     830        return false;
     831    }
     832    psFree(query);
    824833    return true;
    825834}
     
    891900        }
    892901        char *query2 = "UPDATE magicDSRun SET state = '%s' WHERE magic_ds_id = %" PRId64;
    893         if (!p_psDBRunQueryF(config->dbh, query2, magic_ds_id, new_state)) {
     902        if (!p_psDBRunQueryF(config->dbh, query2, new_state, magic_ds_id)) {
    894903            psError(PS_ERR_UNKNOWN, false, "failed to set run magicDSRun.state to %s", new_state);
    895904            return false;
     
    971980
    972981    // check that state is a valid string value
    973     if (!(
    974             (strncmp(state, "new", 4) == 0)
    975             || (strncmp(state, "full", 5) == 0)
    976         )
    977     ) {
     982    if (!((strcmp(state, "new") == 0) ||
     983          (strcmp(state, "full") == 0) ||
     984          (strcmp(state, "restored") == 0) ||
     985          (strcmp(state, "censored") == 0) ||
     986          (strcmp(state, "purged") == 0) ||
     987          (strcmp(state, "goto_restored") == 0) ||
     988          (strcmp(state, "goto_censored") == 0) ||
     989          (strcmp(state, "goto_purged") == 0))
     990        ) {
    978991        psError(PS_ERR_UNKNOWN, false,
    979992                "invalid magicDSRun state: %s", state);
     
    10641077    return true;
    10651078}
    1066 static bool torestoreMode(pxConfig *config)
     1079
     1080static bool torevertMode(pxConfig *config)
    10671081{
    10681082    PS_ASSERT_PTR_NON_NULL(config, false);
    10691083
    10701084    psMetadata *where = psMetadataAlloc();
     1085    PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
     1086
    10711087    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
    10721088    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
    1073     pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     1089    pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "==");
    10741090
    10751091    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    10761092    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    10771093
    1078     // look for "inputs" that need to processed
    1079     psString query = pxDataGet("magicdstool_torestore.sql");
     1094    psString sql_file = NULL;
     1095    psStringAppend(&sql_file, "magicdstool_torevert_%s.sql", stage);
     1096
     1097    psString query = pxDataGet(sql_file);
    10801098    if (!query) {
    1081         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    1082         return false;
    1083     }
     1099        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", sql_file);
     1100        psFree(sql_file);
     1101        return false;
     1102    }
     1103    psFree(sql_file);
    10841104
    10851105    if (psListLength(where->list)) {
    10861106        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    1087         psStringAppend(&query, " WHERE %s", whereClause);
     1107        psStringAppend(&query, " AND %s", whereClause);
    10881108        psFree(whereClause);
    10891109    }
     
    11261146    if (psArrayLength(output)) {
    11271147        // negative simple so the default is true
    1128         if (!ippdbPrintMetadatas(stdout, output, "torestore", !simple)) {
    1129             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    1130             psFree(output);
    1131             return false;
    1132         }
    1133     }
    1134 
    1135     psFree(output);
    1136 
    1137     return true;
    1138 }
    1139 
    1140 
    1141 static bool torevertMode(pxConfig *config)
    1142 {
    1143     PS_ASSERT_PTR_NON_NULL(config, false);
    1144 
    1145     psMetadata *where = psMetadataAlloc();
    1146     PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
    1147 
    1148     PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
    1149     PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
    1150     pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "==");
    1151 
    1152     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    1153     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    1154 
    1155     psString sql_file = NULL;
    1156     psStringAppend(&sql_file, "magicdstool_torevert_%s.sql", stage);
    1157 
    1158     psString query = pxDataGet(sql_file);
    1159     if (!query) {
    1160         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", sql_file);
    1161         psFree(sql_file);
    1162         return false;
    1163     }
    1164     psFree(sql_file);
    1165 
    1166     if (psListLength(where->list)) {
    1167         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    1168         psStringAppend(&query, " AND %s", whereClause);
    1169         psFree(whereClause);
    1170     }
    1171     psFree(where);
    1172 
    1173     // treat limit == 0 as "no limit"
    1174     if (limit) {
    1175         psString limitString = psDBGenerateLimitSQL(limit);
    1176         psStringAppend(&query, " %s", limitString);
    1177         psFree(limitString);
    1178     }
    1179 
    1180     if (!p_psDBRunQuery(config->dbh, query)) {
    1181         psError(PS_ERR_UNKNOWN, false, "database error");
    1182         psFree(query);
    1183         return false;
    1184     }
    1185     psFree(query);
    1186 
    1187     psArray *output = p_psDBFetchResult(config->dbh);
    1188     if (!output) {
    1189         psErrorCode err = psErrorCodeLast();
    1190         switch (err) {
    1191             case PS_ERR_DB_CLIENT:
    1192                 psError(PXTOOLS_ERR_SYS, false, "database error");
    1193             case PS_ERR_DB_SERVER:
    1194                 psError(PXTOOLS_ERR_PROG, false, "database error");
    1195             default:
    1196                 psError(PXTOOLS_ERR_PROG, false, "unknown error");
    1197         }
    1198 
    1199         return false;
    1200     }
    1201     if (!psArrayLength(output)) {
    1202         psTrace("magicdstool", PS_LOG_INFO, "no rows found");
    1203         psFree(output);
    1204         return true;
    1205     }
    1206 
    1207     if (psArrayLength(output)) {
    1208         // negative simple so the default is true
    12091148        if (!ippdbPrintMetadatas(stdout, output, "torevert", !simple)) {
    12101149            psError(PS_ERR_UNKNOWN, false, "failed to print array");
Note: See TracChangeset for help on using the changeset viewer.