IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 15, 2009, 3:58:41 PM (17 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/eam_branches/20090715/ippTools/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/ippTools/src

    • Property svn:ignore
      •  

        old new  
        3434disttool
        3535receivetool
        36 
         36addtool
        3737pubtool
  • branches/eam_branches/20090715/ippTools/src/pstamptool.c

    r25022 r25400  
    4444static bool pendingjobMode(pxConfig *config);
    4545static bool updatejobMode(pxConfig *config);
     46static bool revertjobMode(pxConfig *config);
    4647static bool addprojectMode(pxConfig *config);
    4748static bool projectMode(pxConfig *config);
     
    8081        MODECASE(PSTAMPTOOL_MODE_PENDINGJOB, pendingjobMode);
    8182        MODECASE(PSTAMPTOOL_MODE_UPDATEJOB, updatejobMode);
     83        MODECASE(PSTAMPTOOL_MODE_REVERTJOB, revertjobMode);
    8284        MODECASE(PSTAMPTOOL_MODE_ADDPROJECT, addprojectMode);
    8385        MODECASE(PSTAMPTOOL_MODE_MODPROJECT, modprojectMode);
     
    224226    PS_ASSERT_PTR_NON_NULL(config, false);
    225227
    226     PXOPT_LOOKUP_STR(uri,         config->args, "-uri",           true, false);
    227     // PXOPT_LOOKUP_STR(outFileset,  config->args, "-out_fileset",   true, false);
    228     PXOPT_LOOKUP_S64(ds_id,       config->args, "-ds_id",         false, false);
    229 
    230     char *query ="INSERT INTO pstampRequest"
    231                      " (state, uri, ds_id, fault)"
    232                      " VALUES( 'new', '%s', %" PRId64 ", 0 )";
    233     if (!p_psDBRunQueryF(config->dbh, query, uri, ds_id)) {
    234         psError(PS_ERR_UNKNOWN, false, "database error");
    235         return false;
    236     }
    237 
    238     psU64 affected = psDBAffectedRows(config->dbh);
    239     if (affected != 1) {
    240         psError(PS_ERR_UNKNOWN, false,
    241             "should have affected one row but %" PRIu64 " rows were modified",
    242             affected);
     228    PXOPT_LOOKUP_STR(uri,         config->args, "-uri",   true, false);
     229    PXOPT_LOOKUP_STR(name,        config->args, "-name",  false, false);
     230    PXOPT_LOOKUP_S64(ds_id,       config->args, "-ds_id", false, false);
     231
     232    if (!pstampRequestInsert(config->dbh,
     233        0,      // req_id
     234        ds_id,
     235        "new",  //state
     236        name,
     237        NULL,   // reqType
     238        NULL,   // outProduct
     239        uri,   
     240        0       // fault
     241        )) {
     242        psError(PS_ERR_UNKNOWN, false, "failed to insert request");
    243243        return false;
    244244    }
     
    315315    PS_ASSERT_PTR_NON_NULL(config, false);
    316316
    317     PXOPT_LOOKUP_S64(req_id,  config->args, "-req_id", true, false);
     317    psMetadata *where = psMetadataAlloc();
     318    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
     319    PXOPT_COPY_S64(config->args, where, "-not_req_id", "req_id", "!=");
     320    PXOPT_COPY_STR(config->args, where, "-name", "name", "==");
     321
    318322    PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
    319323    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    320324
    321     psString query = NULL;
    322     psStringAppend(&query, "SELECT * from pstampRequest WHERE req_id = %" PRId64, req_id);
     325    if (!psListLength(where->list)) {
     326        psError(PS_ERR_UNKNOWN, true, "-req_id or -name must be supplied");
     327        return false;
     328    }
     329
     330    psString query = psStringCopy("SELECT * from pstampRequest");
     331
     332    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     333    psStringAppend(&query, " WHERE %s", whereClause);
     334    psFree(whereClause);
     335    psFree(where);
    323336   
    324337    // treat limit == 0 as "no limit"
     
    342355    }
    343356    if (!psArrayLength(output)) {
    344         psTrace("pstamptool", PS_LOG_INFO, "no rows found");
    345         psFree(output);
    346         return true;
     357        psTrace("pstamptool", PS_LOG_INFO, "request not found");
     358        // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for
     359        psError(PXTOOLS_ERR_DATA, true, "request not found");
     360        psFree(output);
     361        // we return false so that the caller can determine that a request does not exist
     362        return false;
    347363    }
    348364
     
    366382    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    367383
    368     psString query =
    369         "SELECT * FROM pstampRequest WHERE state = 'run' AND "
    370             "(SELECT count(*) FROM pstampJob WHERE pstampJob.req_id = pstampRequest.req_id "
    371             " AND pstampJob.state != 'stop') = 0" ;
     384    psString query = pxDataGet("pstamptool_completedreq.sql");
    372385
    373386    // treat limit == 0 as "no limit"
     
    476489    PS_ASSERT_PTR_NON_NULL(config, false);
    477490
    478     PXOPT_LOOKUP_S64(req_id,     config->args, "-req_id",     true, false);
    479 
    480     // printf("Revert request %" PRId64 "\n", req_id);
     491    psMetadata *where = psMetadataAlloc();
     492
     493    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
     494    PXOPT_COPY_S64(config->args, where, "-fault", "req_id", "==");
     495    PXOPT_COPY_STR(config->args, where, "-state", "pstampRequest.state", "==");
     496
     497    if (!psListLength(where->list)) {
     498        psFree(where);
     499        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     500        return false;
     501    }
     502
     503    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     504    psFree(where);
     505
     506    // delete any jobs that were queued by requests that didn't complete parsing (pstampRequest.state = 'new'
     507    // If state =  'run' was supplied this will be a no-op
     508    psString query = pxDataGet("pstamptool_revertreq_deletejobs.sql");
     509    psStringAppend(&query, " AND %s", whereClause);
     510    if (!p_psDBRunQuery(config->dbh, query)) {
     511        psError(PS_ERR_UNKNOWN, false, "database error");
     512        return false;
     513    }
     514    psFree(query);
     515
     516    // clear fault for requests
     517    query = pxDataGet("pstamptool_revertreq.sql");
     518    psStringAppend(&query, " AND %s", whereClause);
    481519   
    482     if (!p_psDBRunQueryF(config->dbh, "DELETE FROM pstampJob where req_id = %" PRId64, req_id)) {
    483         psError(PS_ERR_UNKNOWN, false, "database error");
    484         return false;
    485     }
    486     if (!p_psDBRunQueryF(config->dbh,
    487         "UPDATE pstampRequest set state ='new', name=NULL, reqType=NULL, fault=0 where req_id = %" PRId64, req_id)) {
    488         psError(PS_ERR_UNKNOWN, false, "database error");
    489         return false;
    490     }
     520    psFree(whereClause);
     521
     522    if (!p_psDBRunQuery(config->dbh, query)) {
     523        psError(PS_ERR_UNKNOWN, false, "database error");
     524        return false;
     525    }
     526    psFree(query);
    491527
    492528    return true;
     
    496532{
    497533    bool    stampJob = false;
    498     char   *query = NULL;
    499534
    500535    PS_ASSERT_PTR_NON_NULL(config, false);
     
    503538    PXOPT_LOOKUP_STR(rownum,      config->args, "-rownum",     true, false);
    504539    PXOPT_LOOKUP_STR(job_type,    config->args, "-job_type",   false, false);
    505     PXOPT_LOOKUP_STR(outputBase,  config->args, "-outputBase", true,  false);
     540    PXOPT_LOOKUP_STR(outputBase,  config->args, "-outputBase", false,  false);
    506541    PXOPT_LOOKUP_STR(stateString, config->args, "-state",      false, false);
    507     PXOPT_LOOKUP_STR(fault,       config->args, "-fault",      false, false);
     542    PXOPT_LOOKUP_S16(fault,       config->args, "-fault",      false, false);
    508543    PXOPT_LOOKUP_S64(exp_id,      config->args, "-exp_id",     false, false);
    509544
     545    // unless the job is being inserted with stop state require outputBase
     546    if (strcmp(stateString, "stop") && !outputBase) {
     547        psError(PS_ERR_UNKNOWN, true, "-outputBase is required");
     548        return false;
     549    }
     550
    510551    // default value for job_type is defined in pstamptoolConfig.c
    511     if (!strcmp(job_type, "get_image") || !strcmp(job_type, "detect_query")) {
     552    if (!strcmp(job_type, "get_image") || !strcmp(job_type, "detect_query") || !strcmp(job_type, "none")) {
    512553        stampJob = false;
    513554    } else if (!strcmp(job_type, "stamp")) {
     
    517558        return false;
    518559    }
    519     if (stampJob) {
    520         query = pxDataGet("pstamptool_addjob_stampjob.sql");
    521     } else {
    522         query = pxDataGet("pstamptool_addjob_otherjob.sql");
    523     }
    524     if (!query) {
    525         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    526         return false;
    527     }
    528 
    529     if (!p_psDBRunQueryF(config->dbh, query, req_id, rownum, stateString, job_type, exp_id, outputBase, fault)) {
     560    if (!pstampJobInsert(config->dbh,
     561            0, // job_id
     562            req_id,
     563            rownum,
     564            stateString,
     565            job_type,
     566            fault,
     567            exp_id,
     568            outputBase
     569            )) {
    530570        psError(PS_ERR_UNKNOWN, false, "database error");
    531571        return false;
     
    715755    return true;
    716756}
     757
     758static bool revertjobMode(pxConfig *config)
     759{
     760    PS_ASSERT_PTR_NON_NULL(config, false);
     761
     762    psMetadata *where = psMetadataAlloc();
     763
     764    PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
     765    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
     766    PXOPT_COPY_S64(config->args, where, "-fault",  "fault", "==");
     767
     768    if (!psListLength(where->list)) {
     769        psFree(where);
     770        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     771        return false;
     772    }
     773
     774    psString query = pxDataGet("pstamptool_revertjob.sql");
     775    psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampJob");
     776    psStringAppend(&query, " AND %s", whereClause);
     777    psFree(whereClause);
     778    psFree(where);
     779   
     780    if (!p_psDBRunQuery(config->dbh, query)) {
     781        psError(PS_ERR_UNKNOWN, false, "database error");
     782        return false;
     783    }
     784
     785    return true;
     786}
    717787static bool addprojectMode(pxConfig *config)
    718788{
Note: See TracChangeset for help on using the changeset viewer.