IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 6, 2010, 1:55:20 PM (16 years ago)
Author:
bills
Message:

Various changes to the postage stamp server and associated tables.
Implemented cleanup. Added pstampRequest.outdir changed spelling of out_dir
to outdir. various other cleanups

File:
1 edited

Legend:

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

    r27856 r27874  
    4040static bool updatereqMode(pxConfig *config);
    4141static bool revertreqMode(pxConfig *config);
     42static bool pendingcleanupMode(pxConfig *config);
    4243static bool addjobMode(pxConfig *config);
    4344static bool listjobMode(pxConfig *config);
     
    8182        MODECASE(PSTAMPTOOL_MODE_UPDATEREQ, updatereqMode);
    8283        MODECASE(PSTAMPTOOL_MODE_REVERTREQ, revertreqMode);
     84        MODECASE(PSTAMPTOOL_MODE_PENDINGCLEANUP, pendingcleanupMode);
    8385        MODECASE(PSTAMPTOOL_MODE_ADDJOB, addjobMode);
    8486        MODECASE(PSTAMPTOOL_MODE_LISTJOB, listjobMode);
     
    265267        NULL,   // outProduct
    266268        uri,
     269        NULL,   // outdir
    267270        0       // fault
    268271        )) {
     
    341344}
    342345
    343 static bool listreqMode(pxConfig *config)
     346static bool pendingcleanupMode(pxConfig *config)
    344347{
    345348    PS_ASSERT_PTR_NON_NULL(config, false);
     
    347350    psMetadata *where = psMetadataAlloc();
    348351    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
    349     PXOPT_COPY_S64(config->args, where, "-not_req_id", "req_id", "!=");
    350     PXOPT_COPY_STR(config->args, where, "-name", "name", "==");
    351 
    352     PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
     352    pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
     353
     354    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    353355    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    354356
    355     if (!psListLength(where->list)) {
    356         psError(PS_ERR_UNKNOWN, true, "-req_id or -name must be supplied");
    357         return false;
    358     }
    359 
    360     psString query = psStringCopy("SELECT * from pstampRequest");
    361 
    362     psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    363     psStringAppend(&query, " WHERE %s", whereClause);
    364     psFree(whereClause);
    365     psFree(where);
     357    psString query = pxDataGet("pstamptool_pendingcleanup.sql");
     358    if (!query) {
     359        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     360        return false;
     361    }
     362
     363    if (psListLength(where->list)) {
     364        psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampRequest");
     365        psStringAppend(&query, " AND %s", whereClause);
     366        psFree(whereClause);
     367    }
     368    psFree(where);
     369
     370    psStringAppend(&query, " ORDER BY priority DESC, req_id");
    366371
    367372    // treat limit == 0 as "no limit"
     
    385390    }
    386391    if (!psArrayLength(output)) {
    387         psTrace("pstamptool", PS_LOG_INFO, "request not found");
    388         // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for
    389         psError(PXTOOLS_ERR_CONFIG, true, "request not found");
    390         psFree(output);
    391         // we return false so that the caller can determine that a request does not exist
    392         return false;
     392        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
     393        psFree(output);
     394        return true;
    393395    }
    394396
     
    405407}
    406408
    407 static bool completedreqMode(pxConfig *config)
    408 {
    409     PS_ASSERT_PTR_NON_NULL(config, false);
    410 
    411     psMetadata *where = psMetadataAlloc();
    412     pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
    413 
    414     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     409static bool listreqMode(pxConfig *config)
     410{
     411    PS_ASSERT_PTR_NON_NULL(config, false);
     412
     413    psMetadata *where = psMetadataAlloc();
     414    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
     415    PXOPT_COPY_S64(config->args, where, "-not_req_id", "req_id", "!=");
     416    PXOPT_COPY_STR(config->args, where, "-name", "name", "==");
     417
     418    PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
    415419    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    416420
    417     psString query = pxDataGet("pstamptool_completedreq.sql");
    418 
    419     if (psListLength(where->list)) {
    420         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    421         psStringAppend(&query, " AND %s", whereClause);
    422         psFree(whereClause);
    423     }
    424     psFree(where);
    425 
    426     psStringAppend(&query, " ORDER BY priority DESC, req_id");
     421    if (!psListLength(where->list)) {
     422        psError(PS_ERR_UNKNOWN, true, "-req_id or -name must be supplied");
     423        return false;
     424    }
     425
     426    psString query = psStringCopy("SELECT * from pstampRequest");
     427
     428    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     429    psStringAppend(&query, " WHERE %s", whereClause);
     430    psFree(whereClause);
     431    psFree(where);
    427432
    428433    // treat limit == 0 as "no limit"
     
    438443        return false;
    439444    }
     445    psFree(query);
    440446
    441447    psArray *output = p_psDBFetchResult(config->dbh);
     
    444450        return false;
    445451    }
    446 
    447452    if (!psArrayLength(output)) {
    448         psTrace("pstamptool", PS_LOG_INFO, "no rows found");
    449         psFree(output);
    450         return true;
     453        psTrace("pstamptool", PS_LOG_INFO, "request not found");
     454        // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for
     455        psError(PXTOOLS_ERR_CONFIG, true, "request not found");
     456        psFree(output);
     457        // we return false so that the caller can determine that a request does not exist
     458        return false;
    451459    }
    452460
     
    463471}
    464472
     473static bool completedreqMode(pxConfig *config)
     474{
     475    PS_ASSERT_PTR_NON_NULL(config, false);
     476
     477    psMetadata *where = psMetadataAlloc();
     478    pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
     479
     480    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     481    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     482
     483    psString query = pxDataGet("pstamptool_completedreq.sql");
     484
     485    if (psListLength(where->list)) {
     486        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     487        psStringAppend(&query, " AND %s", whereClause);
     488        psFree(whereClause);
     489    }
     490    psFree(where);
     491
     492    psStringAppend(&query, " ORDER BY priority DESC, req_id");
     493
     494    // treat limit == 0 as "no limit"
     495    if (limit) {
     496        psString limitString = psDBGenerateLimitSQL(limit);
     497        psStringAppend(&query, " %s", limitString);
     498        psFree(limitString);
     499    }
     500
     501    if (!p_psDBRunQuery(config->dbh, query)) {
     502        psError(PS_ERR_UNKNOWN, false, "database error");
     503        psFree(query);
     504        return false;
     505    }
     506
     507    psArray *output = p_psDBFetchResult(config->dbh);
     508    if (!output) {
     509        psError(PS_ERR_UNKNOWN, false, "database error");
     510        return false;
     511    }
     512
     513    if (!psArrayLength(output)) {
     514        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
     515        psFree(output);
     516        return true;
     517    }
     518
     519    // negative simple so the default is true
     520    if (!ippdbPrintMetadatas(stdout, output, "pstampRequest", !simple)) {
     521        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     522        psFree(output);
     523        return false;
     524    }
     525
     526    psFree(output);
     527
     528    return true;
     529}
     530
    465531static bool updatereqMode(pxConfig *config)
    466532{
    467533    PS_ASSERT_PTR_NON_NULL(config, false);
    468534
    469     PXOPT_LOOKUP_S64(req_id,     config->args, "-req_id",     true, false);
    470     PXOPT_LOOKUP_STR(state,      config->args, "-state",      false, false);
    471     PXOPT_LOOKUP_STR(outProduct, config->args, "-outProduct", false, false);
    472     PXOPT_LOOKUP_S16(fault,      config->args, "-fault",      false, false);
    473     PXOPT_LOOKUP_STR(uri,        config->args, "-uri",        false, false);
    474     PXOPT_LOOKUP_STR(name,       config->args, "-name",       false, false);
    475     PXOPT_LOOKUP_STR(reqType,    config->args, "-reqType",    false, false);
    476 
    477     psString query = NULL;
    478     psStringAppend(&query, "UPDATE pstampRequest SET");
    479 
     535    // PXOPT_LOOKUP_S64(req_id,     config->args, "-req_id",   true, false);
     536    PXOPT_LOOKUP_STR(state,      config->args, "-set_state",      false, false);
     537    PXOPT_LOOKUP_STR(label,      config->args, "-set_label",      false, false);
     538    PXOPT_LOOKUP_STR(outProduct, config->args, "-set_outProduct", false, false);
     539    PXOPT_LOOKUP_S16(fault,      config->args, "-set_fault",          false, false);
     540    PXOPT_LOOKUP_STR(uri,        config->args, "-set_uri",        false, false);
     541    PXOPT_LOOKUP_STR(outdir,     config->args, "-set_outdir",        false, false);
     542    PXOPT_LOOKUP_STR(name,       config->args, "-set_name",       false, false);
     543    PXOPT_LOOKUP_STR(reqType,    config->args, "-set_reqType",    false, false);
     544    PXOPT_LOOKUP_BOOL(clearfault,config->args, "-clearfault",    false);
     545
     546    psMetadata *where = psMetadataAlloc();
     547    PXOPT_COPY_S64(config->args, where, "-req_id",     "req_id", "==");
     548    PXOPT_COPY_S64(config->args, where, "-req_id_max", "req_id", "<=");
     549    PXOPT_COPY_S32(config->args, where, "-fault",      "fault", "==");
     550    PXOPT_COPY_STR(config->args, where, "-state",      "state", "==");
     551    pxAddLabelSearchArgs(config, where, "-label",      "pstampRequest.label", "LIKE");
     552    if (!psListLength(where->list)) {
     553        psFree(where);
     554        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     555        return false;
     556    }
     557
     558    psString query = psStringCopy("UPDATE pstampRequest SET");
     559
     560    psString stateCheck = NULL;
    480561    char c = ' ';
    481562    if (state) {
    482563        psStringAppend(&query, "%c state = '%s'", c, state);
    483564        c = ',';
     565        if (!strcmp(state, "goto_cleaned")) {
     566            psStringAppend(&stateCheck, " AND state != 'cleaned'");
     567        }
     568    }
     569    if (label) {
     570        psStringAppend(&query, "%c label = '%s'", c, label);
     571        c = ',';
    484572    }
    485573    if (outProduct) {
     
    487575        c = ',';
    488576    }
    489     if (fault) {
     577    if (outdir) {
     578        psStringAppend(&query, "%c outdir = '%s'", c, outdir);
     579        c = ',';
     580    }
     581    if (clearfault) {
     582        if (fault) {
     583            psError(PXTOOLS_ERR_CONFIG, true, "only one of -fault and -clearfault is allowed");
     584            return false;
     585        }
     586        psStringAppend(&query, "%c fault = 0", c);
     587        c = ',';
     588    } else if (fault) {
    490589        psStringAppend(&query, "%c fault = %d", c, fault);
    491590        c = ',';
     
    503602        c = ',';
    504603    }
    505     if (!state && !outProduct && !fault && !uri && !name && !reqType) {
    506         psError(PS_ERR_UNKNOWN, true, "at least one of state, outProduct, fault, uri, name, and reqType must be specified");
    507         return false;
    508     }
    509 
    510     psStringAppend(&query, " WHERE req_id = %" PRId64, req_id);
     604    if (c != ',') {
     605        psError(PS_ERR_UNKNOWN, true, "at least one set option is required");
     606        return false;
     607    }
     608
     609    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     610    psStringAppend(&query, "\nWHERE %s", whereClause);
     611    psFree(whereClause);
     612    psFree(where);
     613
     614    if (stateCheck) {
     615        psStringAppend(&query, stateCheck);
     616    }
    511617
    512618    if (!p_psDBRunQuery(config->dbh, query)) {
     
    516622    }
    517623
    518     psU64 affected = psDBAffectedRows(config->dbh);
    519     // note zero is not an error
    520     if (affected > 1) {
    521         psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
    522                                         PRIu64 " rows were modified", affected);
    523         return false;
    524     }
     624    // psU64 affected = psDBAffectedRows(config->dbh);
     625    // psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampRequests", affected);
    525626
    526627    return true;
     
    778879        return false;
    779880    }
    780     PXOPT_LOOKUP_STR(state,     config->args, "-state",  true, false);
    781     PXOPT_LOOKUP_S32(fault,     config->args, "-fault",  false, false);
     881
     882    PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  false, false);
     883    PXOPT_LOOKUP_S32(fault,     config->args, "-set_fault",  false, false);
     884   
     885    if (!state && !fault) {
     886        psError(PS_ERR_UNKNOWN, true, "at least one of -set_state and -set_fault is required");
     887        return false;
     888    }
    782889
    783890    psMetadata *where = psMetadataAlloc();
     
    786893    PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
    787894
    788     psString faultStr = NULL;
    789     if (!fault) {
    790         faultStr = psStringCopy("");
    791     } else {
    792         psStringAppend(&faultStr, "\n, pstampJob.fault = %d", fault);
    793     }
    794 
    795895    psString query = pxDataGet("pstamptool_updatejob.sql");
    796896
     897    char c = ' ';
     898    if (state) {
     899        psStringAppend(&query, "\n %c pstampJob.state = '%s'", c, state);
     900        c = ',';
     901    }
     902    if (fault) {
     903        psStringAppend(&query, "\n %c pstampJob.fault = %d", c, fault);
     904        c = ',';
     905    }
     906   
    797907    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    798908    psStringAppend(&query, " WHERE %s", whereClause);
     
    800910    psFree(where);
    801911
    802     if (!p_psDBRunQueryF(config->dbh, query, state, faultStr)) {
     912    if (!p_psDBRunQuery(config->dbh, query)) {
    803913        psError(PS_ERR_UNKNOWN, false, "database error");
    804914        psFree(query);
    805915        return false;
    806916    }
    807     psFree(faultStr);
    808917    psFree(query);
    809918
     
    11591268    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", true, false);
    11601269    PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  false, false);
    1161     PXOPT_LOOKUP_S16(fault,     config->args, "-fault",  false, false);
     1270    PXOPT_LOOKUP_S16(fault,     config->args, "-set_fault",  false, false);
    11621271
    11631272    if (!fault && !state) {
Note: See TracChangeset for help on using the changeset viewer.