IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 23, 2010, 11:23:02 AM (16 years ago)
Author:
bills
Message:

Enable the postage stamp server to handle requests for stamps
from cleaned up data.

File:
1 edited

Legend:

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

    r27282 r27740  
    5151static bool pendingdependentMode(pxConfig *config);
    5252static bool updatedependentMode(pxConfig *config);
     53static bool revertdependentMode(pxConfig *config);
    5354
    5455# define MODECASE(caseName, func) \
     
    9192        MODECASE(PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentMode);
    9293        MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode);
     94        MODECASE(PSTAMPTOOL_MODE_REVERTDEPENDENT, revertdependentMode);
    9395        default:
    9496            psAbort("invalid option (this should not happen)");
     
    464466    PXOPT_LOOKUP_STR(state,      config->args, "-state",      false, false);
    465467    PXOPT_LOOKUP_STR(outProduct, config->args, "-outProduct", false, false);
    466     PXOPT_LOOKUP_STR(fault,      config->args, "-fault",      false, false);
     468    PXOPT_LOOKUP_S16(fault,      config->args, "-fault",      false, false);
    467469    PXOPT_LOOKUP_STR(uri,        config->args, "-uri",        false, false);
    468470    PXOPT_LOOKUP_STR(name,       config->args, "-name",       false, false);
     
    482484    }
    483485    if (fault) {
    484         psStringAppend(&query, "%c fault = %s", c, fault);
     486        psStringAppend(&query, "%c fault = %d", c, fault);
    485487        c = ',';
    486488    }
     
    763765    PS_ASSERT_PTR_NON_NULL(config, false);
    764766
    765     PXOPT_LOOKUP_S64(job_id,    config->args, "-job_id", true, false);
     767    PXOPT_LOOKUP_S64(job_id,    config->args, "-job_id", false, false);
     768    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", false, false);
     769
     770    if (!job_id && !dep_id) {
     771        psError(PS_ERR_UNKNOWN, true, "at least -job_id or -dep_id is required");
     772        return false;
     773    }
    766774    PXOPT_LOOKUP_STR(state,     config->args, "-state",  true, false);
    767     PXOPT_LOOKUP_STR(fault,     config->args, "-fault",  false, false);
     775    PXOPT_LOOKUP_S32(fault,     config->args, "-fault",  false, false);
     776
     777    psMetadata *where = psMetadataAlloc();
     778
     779    PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
     780    PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
    768781
    769782    psString faultStr = NULL;
     
    771784        faultStr = psStringCopy("");
    772785    } else {
    773         psStringAppend(&faultStr, ", fault = '%s'", fault);
    774     }
    775 
    776     char *query ="UPDATE pstampJob"
    777         " SET state = '%s' %s"
    778         " WHERE job_id = %" PRId64;
    779 
    780     if (!p_psDBRunQueryF(config->dbh, query, state, faultStr, job_id)) {
     786        psStringAppend(&faultStr, "\n, pstampJob.fault = %d", fault);
     787    }
     788
     789    psString query = pxDataGet("pstamptool_updatejob.sql");
     790
     791    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     792    psStringAppend(&query, " WHERE %s", whereClause);
     793    psFree(whereClause);
     794    psFree(where);
     795
     796    if (!p_psDBRunQueryF(config->dbh, query, state, faultStr)) {
    781797        psError(PS_ERR_UNKNOWN, false, "database error");
    782798        psFree(query);
     
    784800    }
    785801    psFree(faultStr);
     802    psFree(query);
    786803
    787804    psU64 affected = psDBAffectedRows(config->dbh);
    788     if (affected != 1) {
    789         psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
    790                                         PRIu64 " rows were modified", affected);
    791         return false;
    792     }
     805    psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampJobs", affected);
    793806
    794807    return true;
     
    952965    PXOPT_LOOKUP_STR(stage,       config->args, "-stage",   true, false);
    953966    PXOPT_LOOKUP_S64(stage_id,    config->args, "-stage_id", true, false);
     967    PXOPT_LOOKUP_STR(component,   config->args, "-component",  true, false);
    954968    PXOPT_LOOKUP_STR(imagedb,     config->args, "-imagedb",  true, false);
    955969    PXOPT_LOOKUP_STR(rlabel,      config->args, "-rlabel",  false, false);
    956     PXOPT_LOOKUP_BOOL(no_magic,   config->args, "-no_magic", false);
     970    PXOPT_LOOKUP_BOOL(need_magic, config->args, "-need_magic", false);
    957971    PXOPT_LOOKUP_BOOL(no_create,  config->args, "-no_create", false);
    958972
     
    961975    PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "==");
    962976    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     977    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
    963978
    964979    // start a transaction eraly so it will contain any row level locks
     
    973988        return false;
    974989    }
    975     psString whereClause = psDBGenerateWhereSQL(where, "WHERE");
     990    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    976991    if (!no_create) {
    977992        // This will lock the row until the transaction is committed
    978         psStringAppend(&query, " %s FOR UPDATE", whereClause);
     993        psStringAppend(&query, " AND %s FOR UPDATE", whereClause);
    979994    } else {
    980         psStringAppend(&query, " %s", whereClause);
     995        psStringAppend(&query, " AND %s", whereClause);
    981996    }
    982997    psFree(whereClause);
     
    10271042        stage,
    10281043        stage_id,
     1044        component,
    10291045        imagedb,
    10301046        rlabel,
    1031         no_magic
     1047        need_magic,
     1048        0               // fault
    10321049        )) {
    10331050        if (!psDBRollback(config->dbh)) {
     
    10381055    }
    10391056
     1057    // if we try and get this after commit zero is returned
     1058    psS64 dep_id = psDBLastInsertID(config->dbh);
     1059    if (!dep_id) {
     1060        psError(PS_ERR_UNKNOWN, false, "psDBLastInsertID returned NULL");
     1061        if (!psDBRollback(config->dbh)) {
     1062            psError(PS_ERR_UNKNOWN, false, "database error");
     1063        }
     1064        return false;
     1065    }
     1066
    10401067    if (!psDBCommit(config->dbh)) {
    10411068        // rollback
     
    10471074    }
    10481075
    1049     psS64 dep_id = psDBLastInsertID(config->dbh);
    10501076    printf("%" PRId64 "\n", dep_id);
    10511077
     
    10581084
    10591085    psMetadata *where = psMetadataAlloc();
     1086    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1087    PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "==");
     1088    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     1089    PXOPT_COPY_STR(config->args, where, "-rlabel", "rlabel", "==");
     1090    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "==");
    10601091
    10611092    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    10691100
    10701101    if (psListLength(where->list)) {
    1071         psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampDependent");
     1102        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    10721103        psStringAppend(&query, " AND %s", whereClause);
    10731104        psFree(whereClause);
     
    11161147
    11171148    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", true, false);
    1118     PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  true, false);
    1119 
    1120     char *query ="UPDATE pstampDependent"
    1121         " SET state = '%s'"
    1122         " WHERE dep_id = %" PRId64;
    1123 
    1124     if (!p_psDBRunQueryF(config->dbh, query, state, dep_id)) {
     1149    PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  false, false);
     1150    PXOPT_LOOKUP_S16(fault,     config->args, "-fault",  false, false);
     1151
     1152    if (!fault && !state) {
     1153        psError(PS_ERR_UNKNOWN, true, "at least one of -set_state or fault is required");
     1154        return false;
     1155    }
     1156    psString query = psStringCopy("UPDATE pstampDependent SET");
     1157    bool needComma = false;
     1158    if (state) {
     1159        psStringAppend(&query, " state = '%s'", state);
     1160        needComma = true;
     1161    }
     1162    if (fault) {
     1163        psStringAppend(&query, "%s fault = %d", needComma ? ", " : "", fault);
     1164        needComma = true;
     1165    }
     1166    psStringAppend(&query, " WHERE dep_id = %" PRId64, dep_id);
     1167
     1168    if (!p_psDBRunQuery(config->dbh, query)) {
    11251169        psError(PS_ERR_UNKNOWN, false, "database error");
    11261170        psFree(query);
     
    11371181    return true;
    11381182}
     1183static bool revertdependentMode(pxConfig *config)
     1184{
     1185    PS_ASSERT_PTR_NON_NULL(config, false);
     1186
     1187    psMetadata *where = psMetadataAlloc();
     1188    PXOPT_COPY_S64(config->args, where, "-fault", "req_id", "==");
     1189    PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
     1190    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "==");
     1191
     1192    if (!psListLength(where->list)) {
     1193        psFree(where);
     1194        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1195        return false;
     1196    }
     1197    psString query = pxDataGet("pstamptool_revertdependent.sql");
     1198    if (!query) {
     1199        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1200        return false;
     1201    }
     1202
     1203    psString whereClause = psDBGenerateWhereSQL(where, NULL);
     1204    psStringAppend(&query, " %s", whereClause);
     1205    psFree(whereClause);
     1206    psFree(where);
     1207
     1208    if (!p_psDBRunQuery(config->dbh, query)) {
     1209        psError(PS_ERR_UNKNOWN, false, "database error");
     1210        psFree(query);
     1211        return false;
     1212    }
     1213
     1214    return true;
     1215}
Note: See TracChangeset for help on using the changeset viewer.