IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 17, 2010, 10:42:12 AM (16 years ago)
Author:
bills
Message:

add -rerun mode to disttool

File:
1 edited

Legend:

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

    r28536 r28938  
    3434static bool updaterunMode(pxConfig *config);
    3535static bool revertrunMode(pxConfig *config);
     36static bool rerunMode(pxConfig *config);
    3637static bool pendingcomponentMode(pxConfig *config);
    3738static bool addprocessedcomponentMode(pxConfig *config);
     
    8384        MODECASE(DISTTOOL_MODE_UPDATERUN, updaterunMode);
    8485        MODECASE(DISTTOOL_MODE_REVERTRUN, revertrunMode);
     86        MODECASE(DISTTOOL_MODE_RERUN, rerunMode);
    8587        MODECASE(DISTTOOL_MODE_PENDINGCOMPONENT, pendingcomponentMode);
    8688        MODECASE(DISTTOOL_MODE_ADDPROCESSEDCOMPONENT, addprocessedcomponentMode);
     
    587589}
    588590
     591static bool rerunMode(pxConfig *config)
     592{
     593    psMetadata *where = psMetadataAlloc();
     594    PXOPT_COPY_S64(config->args, where, "-dist_id", "distRun.dist_id", "==");
     595    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");;
     596    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     597    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     598    PXOPT_COPY_STR(config->args, where, "-data_group", "data_group", "==");
     599
     600    // require data_group or dist_id to be supplied
     601    PXOPT_LOOKUP_STR(data_group, config->args, "-data_group", true, false);
     602    PXOPT_LOOKUP_S64(dist_id, config->args, "-dist_id", false, false);
     603    if (!data_group && !dist_id) {
     604        psError(PXTOOLS_ERR_CONFIG, true, "data_group or dist_id is required");
     605        return false;
     606    }
     607    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
     608
     609    psString label_hook = psStringCopy("");
     610    if (set_label) {
     611        psStringAppend(&label_hook, ", label = '%s'", set_label);
     612    }
     613
     614    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     615    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     616    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     617
     618
     619    // It might be useful to be able to query by the parameters of the underlying runs
     620
     621    if (!psListLength(where->list)) {
     622        psFree(where);
     623        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     624        return false;
     625    }
     626
     627    psString query = pxDataGet("disttool_rerun_select.sql");
     628    if (!query) {
     629        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     630        if (!psDBRollback(config->dbh)) {
     631            psError(PS_ERR_UNKNOWN, false, "database error");
     632        }
     633        return false;
     634    }
     635
     636    if (psListLength(where->list)) {
     637        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     638        psStringAppend(&query, " AND %s", whereClause);
     639        psFree(whereClause);
     640    }
     641    psFree(where);
     642
     643    if (limit) {
     644        psString limitString = psDBGenerateLimitSQL(limit);
     645        psStringAppend(&query, " %s", limitString);
     646        psFree(limitString);
     647    }
     648
     649    if (!p_psDBRunQuery(config->dbh, query)) {
     650        psError(PS_ERR_UNKNOWN, false, "database error");
     651        psFree(query);
     652        return false;
     653    }
     654    psFree(query);
     655
     656    psArray *output = p_psDBFetchResult(config->dbh);
     657    if (!output) {
     658        psError(PS_ERR_UNKNOWN, false, "database error");
     659        return false;
     660    }
     661    if (!psArrayLength(output)) {
     662        psTrace("disttool", PS_LOG_INFO, "no rows found");
     663        psFree(output);
     664        return true;
     665    }
     666
     667
     668    if (pretend) {
     669        if (!ippdbPrintMetadatas(stdout, output, "distRunsToUpdate", true)) {
     670            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     671            psFree(output);
     672            return false;
     673        }
     674        psFree(output);
     675        return true;
     676    }
     677
     678    query = "DELETE FROM distComponent where dist_id = %" PRId64;
     679   
     680    for (long i=0; i < psArrayLength(output); i++) {
     681        psMetadata *md = output->data[i];
     682        psS64 dist_id = psMetadataLookupS64(NULL, md, "dist_id");
     683
     684        if (!psDBTransaction(config->dbh)) {
     685            psError(PS_ERR_UNKNOWN, false, "database error");
     686            return false;
     687        }
     688
     689        if (!p_psDBRunQueryF(config->dbh, query, dist_id)) {
     690            psError(PS_ERR_UNKNOWN, false, "database error");
     691            psFree(query);
     692            if (!psDBRollback(config->dbh)) {
     693                psError(PS_ERR_UNKNOWN, false, "database error");
     694            }
     695            return false;
     696        }
     697
     698        if (!p_psDBRunQueryF(config->dbh,
     699        "UPDATE distRun SET state = 'new', fault=0 %s WHERE dist_id =%" PRId64,
     700                label_hook, dist_id)) {
     701            psError(PS_ERR_UNKNOWN, false, "database error");
     702            psFree(query);
     703            if (!psDBRollback(config->dbh)) {
     704                psError(PS_ERR_UNKNOWN, false, "database error");
     705            }
     706            return false;
     707        }
     708        if (!psDBCommit(config->dbh)) {
     709            psError(PS_ERR_UNKNOWN, false, "database error");
     710            return false;
     711        }
     712        printf("re-running distRun %" PRId64 "\n", dist_id);
     713    }
     714
     715    psFree(output);
     716
     717    return true;
     718}
    589719static bool revertrunMode(pxConfig *config)
    590720{
Note: See TracChangeset for help on using the changeset viewer.