IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:41:49 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/tap_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/ippTools/src

    • Property svn:ignore
      •  

        old new  
        1616difftool
        1717disttool
         18dqstatstool
        1819faketool
        1920flatcorr
  • branches/tap_branches/ippTools/src/disttool.c

    r25835 r27838  
    4242static bool addfilesetMode(pxConfig *config);
    4343static bool revertfilesetMode(pxConfig *config);
     44static bool updatefilesetMode(pxConfig *config);
    4445static bool queuercrunMode(pxConfig *config);
    4546static bool updatercrunMode(pxConfig *config);
    4647static bool revertrcrunMode(pxConfig *config);
    4748static bool pendingdestMode(pxConfig *config);
     49static bool pendingcleanupMode(pxConfig *config);
     50static bool listfilesetsMode(pxConfig *config);
    4851
    4952static bool definetargetMode(pxConfig *config);
    5053static bool updatetargetMode(pxConfig *config);
    51 static bool listtargetMode(pxConfig *config);
     54static bool listtargetsMode(pxConfig *config);
    5255
    5356static bool definedestinationMode(pxConfig *config);
     
    8689        MODECASE(DISTTOOL_MODE_TOADVANCE, toadvanceMode);
    8790        MODECASE(DISTTOOL_MODE_PENDINGFILESET, pendingfilesetMode);
     91        MODECASE(DISTTOOL_MODE_PENDINGCLEANUP, pendingcleanupMode);
    8892        MODECASE(DISTTOOL_MODE_ADDFILESET, addfilesetMode);
    8993        MODECASE(DISTTOOL_MODE_REVERTFILESET, revertfilesetMode);
     94        MODECASE(DISTTOOL_MODE_LISTFILESETS, listfilesetsMode);
     95        MODECASE(DISTTOOL_MODE_UPDATEFILESET, updatefilesetMode);
    9096        MODECASE(DISTTOOL_MODE_QUEUERCRUN, queuercrunMode);
    9197        MODECASE(DISTTOOL_MODE_UPDATERCRUN, updatercrunMode);
     
    94100        MODECASE(DISTTOOL_MODE_DEFINETARGET, definetargetMode);
    95101        MODECASE(DISTTOOL_MODE_UPDATETARGET, updatetargetMode);
    96         MODECASE(DISTTOOL_MODE_LISTTARGET, listtargetMode);
     102        MODECASE(DISTTOOL_MODE_LISTTARGETS, listtargetsMode);
    97103        MODECASE(DISTTOOL_MODE_DEFINEDESTINATION, definedestinationMode);
    98104        MODECASE(DISTTOOL_MODE_UPDATEDESTINATION, updatedestinationMode);
     
    131137
    132138    // optional
    133     PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id",  false, false);
     139    PXOPT_LOOKUP_BOOL(use_alternate, config->args, "-use_alternate", false);
    134140    PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false);
    135141    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
     142    PXOPT_LOOKUP_STR(set_data_group, config->args, "-set_data_group", false, false);
    136143    PXOPT_LOOKUP_STR(set_note, config->args, "-set_note", false, false);
    137144
    138145    PXOPT_LOOKUP_S64(limit, config->args, "-limit", false, false);
    139146    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    140    
    141     PXOPT_LOOKUP_BOOL(dry_run, config->args, "-dry_run", false);
     147
     148    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     149
     150    if (use_alternate) {
     151        if (strcmp(stage, "raw")) {
     152            psError(PXTOOLS_ERR_SYS, true, "alternate inputs only supported for raw stage");
     153            return false;
     154        }
     155        if (no_magic) {
     156            psError(PXTOOLS_ERR_SYS, true, "no_magic forbidden with alternate inputs");
     157            return false;
     158        }
     159    }
    142160
    143161    // select arguments
     
    155173    psString runJoinStr = NULL;
    156174    if (!strcmp(stage, "raw")) {
    157         magicRunType = "rawExp";
    158         runJoinStr = "rawExp.exp_id";
     175        if (! use_alternate ) {
     176            magicRunType = "rawExp";
     177            runJoinStr = "rawExp.exp_id";
     178        } else {
     179            magicRunType = "camRun";
     180            runJoinStr = "camRun.exp_id";
     181        }
    159182        query = pxDataGet("disttool_definebyquery_raw.sql");
    160183        if (!query) {
    161             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     184            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    162185            psFree(where);
    163186            return false;
    164187        }
    165188
    166         // for raw stage we select by chipRun.label because raw labels typically aren't set
     189        // for raw stage we select by camRun.label and dist_group because rawExp doesn't have those columns
    167190        if (label) {
    168             psStringAppend(&query, " AND (chipRun.label = '%s')", label);
     191            psStringAppend(&query, " AND (magicDSRun.label = '%s')", label);
    169192        }
    170193        if (dist_group) {
    171             psStringAppend(&query, " AND (chipRun.dist_group = '%s')", dist_group);
     194            psStringAppend(&query, " AND (camRun.dist_group = '%s')", dist_group);
    172195        }
    173196    } else if (!strcmp(stage, "chip")) {
     
    176199        query = pxDataGet("disttool_definebyquery_chip.sql");
    177200        if (!query) {
    178             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     201            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    179202            psFree(where);
    180203            return false;
     
    192215        query = pxDataGet("disttool_definebyquery_camera.sql");
    193216        if (!query) {
    194             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     217            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    195218            psFree(where);
    196219            return false;
     
    207230        query = pxDataGet("disttool_definebyquery_fake.sql");
    208231        if (!query) {
    209             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     232            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    210233            psFree(where);
    211234            return false;
     
    225248        query = pxDataGet("disttool_definebyquery_warp.sql");
    226249        if (!query) {
    227             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     250            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    228251            psFree(where);
    229252            return false;
     
    242265        query = pxDataGet("disttool_definebyquery_diff.sql");
    243266        if (!query) {
    244             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     267            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    245268            psFree(where);
    246269            return false;
     
    258281        query = pxDataGet("disttool_definebyquery_stack.sql");
    259282        if (!query) {
    260             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     283            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    261284            psFree(where);
    262285            return false;
     
    271294        // stack stage doesn't require magic
    272295        no_magic = true;
     296    } else if (!strcmp(stage, "SSdiff")) {
     297      magicRunType = "diffRun";
     298      runJoinStr = "diffRun.diff_id";
     299      query = pxDataGet("disttool_definebyquery_SSdiff.sql");
     300      if (!query) {
     301        psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement");
     302        psFree(where);
     303        return(false);
     304      }
     305
     306      if (label) {
     307        psStringAppend(&query, " AND (diffRun.label = '%s') ", label);
     308      }
     309      if (dist_group) {
     310        psStringAppend(&query, " AND (diffRun.dist_group = '%s') ", dist_group);
     311      }
     312
     313      no_magic = true;   
    273314    } else {
    274315        psError(PS_ERR_UNKNOWN, true, "unknown value for stage: %s", stage);
    275316        psFree(where);
    276317        return false;
     318    }
     319
     320    if (!strcmp(stage, "raw")) {
     321        if (!no_magic) {
     322            psStringAppend(&query, " AND (magicDSRun.re_place = %d)", !use_alternate);
     323            psStringAppend(&query, " AND (camRun.state = 'full')");
     324        }
    277325    }
    278326
     
    287335
    288336    if (!no_magic) {
    289         psStringAppend(&query, " AND (%s.magicked)", magicRunType);
    290 
    291         // is selecting by magic_ds_id really interesting?
    292         if (magic_ds_id) {
    293             if (!runJoinStr) {
    294                 psError(PS_ERR_PROGRAMMING, true, "cannot select by magic_ds_id for stage: %s", stage);
    295                 psFree(query);
    296                 return false;
    297             }
    298             psStringAppend(&joinHook, "\nJOIN magicDSRun ON magicDSRun.stage = distTarget.stage"
    299                                               " AND magicDSRun.stage_id = %s", runJoinStr);
    300             psStringAppend(&query, " AND (magicDSRun.state = 'full' AND magicDSRun.re_place AND (magic_ds_id = %" PRId64 "))", magic_ds_id);
    301         }
     337        psStringAppend(&query, " AND (%s.magicked > 0)", magicRunType);
    302338    }
    303339
     
    307343        psFree(limitString);
    308344    }
    309 
     345    psTrace("disttool",2,query,joinHook ? joinHook : "");
    310346    if (!p_psDBRunQueryF(config->dbh, query, joinHook ? joinHook : "")) {
    311         psError(PS_ERR_UNKNOWN, false, "database error");
    312         psFree(query);
    313         return false;
     347      psError(PS_ERR_UNKNOWN, false, "database error");
     348      psFree(query);
     349      return false;
    314350    }
    315351    psFree(query);
     
    328364
    329365
    330     if (dry_run) {
     366    if (pretend) {
    331367        if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", true)) {
    332368            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     
    352388        psS64 target_id = psMetadataLookupS64(NULL, md, "target_id");
    353389        psString stage_label = psMetadataLookupStr(NULL, md, "label");
     390        psString stage_data_group = psMetadataLookupStr(NULL, md, "data_group");
    354391        bool clean = psMetadataLookupBool(NULL, md, "clean");
    355392
    356393        psString outroot = NULL;
    357         psStringAppend(&outroot, "%s/%s/%s", workdir, run_tag, stage); 
     394        psStringAppend(&outroot, "%s/%s/%s", workdir, run_tag, stage);
    358395
    359396        psString new_label;
     
    363400            new_label = stage_label;
    364401        }
     402        psString new_data_group;
     403        if (set_data_group != NULL) {
     404            new_data_group = set_data_group;
     405        } else {
     406            new_data_group = stage_data_group;
     407        }
     408
    365409        distRunRow *row = distRunRowAlloc(
    366410                0,      // dist_id
     
    371415                new_label,
    372416                outroot,
     417                NULL,     // outdir
    373418                clean,
    374419                no_magic,
     420                use_alternate,
    375421                "new",
    376                 NULL,   // time_stamp
     422                NULL,    // time_stamp
    377423                0,       // fault
    378                 set_note    // note does not propagate
     424                new_data_group,
     425                set_note // note does not propagate
    379426                );
    380427
     
    419466    PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "==");
    420467    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");;
    421     PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     468    PXOPT_COPY_STR(config->args, where, "-state", "distRun.state", "==");
    422469    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     470    PXOPT_COPY_STR(config->args, where, "-data_group", "distRun.data_group", "LIKE");
     471    PXOPT_COPY_STR(config->args, where, "-dist_group", "distTarget.dist_group", "==");
     472    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    423473
    424474    if (!psListLength(where->list)) {
    425475        psFree(where);
    426         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     476        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    427477        return false;
    428478    }
     
    430480    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    431481    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     482    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     483    PXOPT_LOOKUP_STR(outdir, config->args, "-set_outdir", false, false);
    432484    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
    433 
    434     if ((!state) && (!label) && (!fault)) {
    435         psError(PXTOOLS_ERR_DATA, false, "parameters (-fault or -set_state or -set_label) are required");
    436         psFree(where);
    437         return false;
    438     }
    439 
    440     psString query = psStringCopy("UPDATE distRun SET time_stamp = UTC_TIMESTAMP()");
    441 
     485    PXOPT_LOOKUP_STR(set_note, config->args, "-set_note", false, false);
     486
     487    if ((!state) && (!label) && (!fault) &&(!data_group)) {
     488        psError(PXTOOLS_ERR_CONFIG, false, "parameters (-fault or -set_state or -set_label -set_data_group) are required");
     489        psFree(where);
     490        return false;
     491    }
     492
     493    psString query = psStringCopy("UPDATE distRun join distTarget using(target_id, stage) SET distRun.time_stamp = UTC_TIMESTAMP()");
     494
     495    if (outdir) {
     496        psStringAppend(&query, " , distRun.outdir = '%s'", outdir);
     497    }
    442498    if (state) {
    443         psStringAppend(&query, " , state = '%s'", state);
     499        psStringAppend(&query, " , distRun.state = '%s'", state);
    444500    }
    445501
    446502    if (label) {
    447         psStringAppend(&query, " , label = '%s'", label);
     503        psStringAppend(&query, " , distRun.label = '%s'", label);
    448504    }
    449505
    450506    if (fault) {
    451         psStringAppend(&query, " , fault = %d", fault);
    452     }
     507        psStringAppend(&query, " , distRun.fault = %d", fault);
     508    }
     509
     510    if (data_group) {
     511        psStringAppend(&query, " , distRun.data_group = '%s'", data_group);
     512    }
     513
     514    if (set_note) {
     515        psStringAppend(&query, " , distRun.note = '%s'", set_note);
     516    }
     517
    453518
    454519    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     
    481546    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
    482547        psFree(where);
    483         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     548        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    484549        return false;
    485550    }
     
    487552    psString query = pxDataGet("disttool_revertrun.sql");
    488553    if (!query) {
    489         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     554        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    490555        if (!psDBRollback(config->dbh)) {
    491556            psError(PS_ERR_UNKNOWN, false, "database error");
     
    522587    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
    523588    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
    524     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     589    pxAddLabelSearchArgs(config, where, "-label", "distRun.label", "==");
    525590
    526591    PXOPT_COPY_S16(config->args, where,  "-fault", "distComponent.fault", "==");
     
    530595    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
    531596        psFree(where);
    532         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     597        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    533598        return false;
    534599    }
     
    536601    psString query = pxDataGet("disttool_revertcomponent.sql");
    537602    if (!query) {
    538         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     603        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    539604        psFree(where);
    540605        return false;
     
    568633
    569634    psMetadata *where = psMetadataAlloc();
    570     PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "==");
     635    PXOPT_COPY_S64(config->args, where, "-dist_id", "distRun.dist_id", "==");
    571636    pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "==");
    572637
     
    578643    psString query = pxDataGet(queryFile);
    579644    if (!query) {
    580         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", queryFile);
     645        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement from %s", queryFile);
    581646        return false;
    582647    }
     
    652717    PXOPT_LOOKUP_S32(bytes, config->args, "-bytes", require_fileinfo, false);
    653718    PXOPT_LOOKUP_STR(md5sum, config->args, "-md5sum", require_fileinfo, false);
     719    PXOPT_LOOKUP_STR(outdir, config->args, "-outdir", require_fileinfo, false);
    654720    PXOPT_LOOKUP_STR(name, config->args, "-name", require_fileinfo, false);
    655721
    656     if (!distComponentInsert(config->dbh, dist_id, component, bytes, md5sum, "full", name, fault)) {
     722    if (!distComponentInsert(config->dbh, dist_id, component, bytes, md5sum, "full", outdir, name, fault)) {
    657723        psError(PS_ERR_UNKNOWN, false, "database error");
    658724        return false;
     
    676742    psString query = pxDataGet("disttool_toadvance.sql");
    677743    if (!query) {
    678         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     744        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    679745        return false;
    680746    }
     
    747813    psString query = pxDataGet("disttool_processedcomponent.sql");
    748814    if (!query) {
    749         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     815        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    750816        return false;
    751817    }
     
    821887    psString query = pxDataGet("disttool_pendingfileset.sql");
    822888    if (!query) {
    823         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     889        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    824890        return false;
    825891    }
     
    891957    PXOPT_LOOKUP_STR(name, config->args, "-name", fault == 0, false);
    892958
    893     if (!rcDSFilesetInsert(config->dbh, 
     959    if (!rcDSFilesetInsert(config->dbh,
    894960            0,          // fs_id
    895961            dist_id,
     
    904970    return true;
    905971}
     972
    906973static bool revertfilesetMode(pxConfig *config)
    907974{
     
    920987    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
    921988        psFree(where);
    922         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     989        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    923990        return false;
    924991    }
     
    926993    psString query = pxDataGet("disttool_revertfileset.sql");
    927994    if (!query) {
    928         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     995        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    929996        psFree(where);
    930997        return false;
     
    9681035    psString query = pxDataGet("disttool_pendingdest.sql");
    9691036    if (!query) {
    970         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1037        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    9711038        return false;
    9721039    }
     
    10471114    psString query = pxDataGet("disttool_queuercrun.sql");
    10481115    if (!query) {
    1049         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1116        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    10501117        return false;
    10511118    }
     
    10931160    // We either need rc_id or (dest_id and fs_name) to identifiy the rcRun
    10941161    if ((!rc_id) && !(dest_id && fs_name)) {
    1095         psError(PXTOOLS_ERR_DATA, true, "either -rc_id or (-fs_name and -dest_id) are required");
     1162        psError(PXTOOLS_ERR_CONFIG, true, "either -rc_id or (-fs_name and -dest_id) are required");
    10961163        return false;
    10971164    }
     
    11051172        // this can't happen because we checked above
    11061173        psFree(where);
    1107         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     1174        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    11081175        return false;
    11091176    }
     
    11151182
    11161183    if (!state && (fault < 0)) {
    1117         psError(PXTOOLS_ERR_DATA, false, "parameters (-fault or -set_state) are required");
     1184        psError(PXTOOLS_ERR_CONFIG, false, "parameters (-fault or -set_state) are required");
    11181185        psFree(where);
    11191186        return false;
     
    11221189    psString query = pxDataGet("disttool_updatercrun.sql");
    11231190    if (!query) {
    1124         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1191        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    11251192        return false;
    11261193    }
     
    11791246    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
    11801247        psFree(where);
    1181         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     1248        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    11821249        return false;
    11831250    }
     
    11851252    psString query = pxDataGet("disttool_revertrcrun.sql");
    11861253    if (!query) {
    1187         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1254        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    11881255        if (!psDBRollback(config->dbh)) {
    11891256            psError(PS_ERR_UNKNOWN, false, "database error");
     
    12381305            comment
    12391306            );
    1240            
     1307
    12411308    if (!row) {
    12421309        psError(PS_ERR_UNKNOWN, false, "failed to allocate distTarget object");
     
    12981365}
    12991366
    1300 static bool listtargetMode(pxConfig *config)
     1367static bool listtargetsMode(pxConfig *config)
    13011368{
    13021369    PS_ASSERT_PTR_NON_NULL(config, false);
     
    14041471            state ? state : "enabled"
    14051472            );
    1406            
     1473
    14071474    if (!row) {
    14081475        psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDestination object");
     
    14411508    if (!(state || last_fileset)) {
    14421509        psError(PS_ERR_UNKNOWN, true, "one or more of -set_state or -set_last_fileset is required");
    1443 # else 
     1510# else
    14441511    if (!state) {
    14451512#endif
     
    15381605    PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE");
    15391606    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE");
    1540     PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1607    // if stage is all don't add it to the query (match all stages)
     1608    if (stage && strcmp(stage, "all")) {
     1609        PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1610    }
    15411611
    15421612    psString query = pxDataGet("disttool_defineinterest.sql");
     
    15981668    PXOPT_COPY_S64(config->args, where, "-dest_id",   "dest_id", "==");
    15991669    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
     1670    PXOPT_COPY_STR(config->args, where, "-dest_name", "rcDestination.name", "LIKE");
     1671    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1672    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE");
     1673    PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE");
     1674
     1675    PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
     1676    PXOPT_LOOKUP_BOOL(full, config->args, "-full", false);
     1677    if (full && clean) {
     1678        psError(PS_ERR_UNKNOWN, true, "-full and -clean makes no sense, chose one or the other");
     1679        psFree(where);
     1680        return false;
     1681    }
     1682       
    16001683
    16011684    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     
    16051688        return false;
    16061689    }
    1607     psString query = NULL;
    1608     psStringAppend(&query, "UPDATE rcInterest SET state = '%s'", state);
     1690    psString query = pxDataGet("disttool_updateinterest.sql");
    16091691
    16101692    if (psListLength(where->list)) {
     
    16201702    psFree(where);
    16211703
     1704    if (clean) {
     1705        psStringAppend(&query, " AND distTarget.clean");
     1706    } else {
     1707        psStringAppend(&query, " AND NOT distTarget.clean");
     1708    }
     1709
     1710    if (!p_psDBRunQueryF(config->dbh, query, state)) {
     1711        psError(PS_ERR_UNKNOWN, false, "database error");
     1712        psFree(query);
     1713        return false;
     1714    }
     1715    psFree(query);
     1716
     1717    psS64 numUpdated = psDBAffectedRows(config->dbh);
     1718    printf("updated %" PRId64 " interests\n", numUpdated);
     1719
     1720    return true;
     1721}
     1722static bool listinterestsMode(pxConfig *config)
     1723{
     1724    PS_ASSERT_PTR_NON_NULL(config, false);
     1725
     1726    psMetadata *where = psMetadataAlloc();
     1727    PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "==");
     1728    PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "==");
     1729    PXOPT_COPY_STR(config->args, where, "-dest_name", "name", "==");
     1730    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
     1731    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1732    PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE");
     1733    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE");
     1734    PXOPT_COPY_STR(config->args, where, "-state", "rcInterest.state", "==");
     1735
     1736    PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
     1737    PXOPT_LOOKUP_BOOL(full, config->args, "-full", false);
     1738
     1739    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1740    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1741
     1742    if (clean && full) {
     1743        psError(PS_ERR_UNKNOWN, false, "can't select both -clean and -full");
     1744        return false;
     1745    }
     1746
     1747    psString query = pxDataGet("disttool_listinterests.sql");
     1748
     1749    if (psListLength(where->list)) {
     1750        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1751        psStringAppend(&query, " WHERE %s", whereClause);
     1752        psFree(whereClause);
     1753        if (clean) {
     1754            psStringAppend(&query, " AND (clean)");
     1755        } else if (full) {
     1756            psStringAppend(&query, " AND (!clean)");
     1757        }
     1758    } else if (clean) {
     1759        psStringAppend(&query, " WHERE clean");
     1760    } else if (full) {
     1761        psStringAppend(&query, " WHERE !clean");
     1762    }
     1763    psFree(where);
     1764
     1765    // treat limit == 0 as "no limit"
     1766    if (limit) {
     1767        psString limitString = psDBGenerateLimitSQL(limit);
     1768        psStringAppend(&query, " %s", limitString);
     1769        psFree(limitString);
     1770    }
     1771
    16221772    if (!p_psDBRunQuery(config->dbh, query)) {
    16231773        psError(PS_ERR_UNKNOWN, false, "database error");
    16241774        psFree(query);
     1775        if (!psDBRollback(config->dbh)) {
     1776            psError(PS_ERR_UNKNOWN, false, "database error");
     1777        }
    16251778        return false;
    16261779    }
    16271780    psFree(query);
    16281781
    1629     return true;
    1630 }
    1631 static bool listinterestsMode(pxConfig *config)
     1782    psArray *output = p_psDBFetchResult(config->dbh);
     1783    if (!output) {
     1784        psError(PS_ERR_UNKNOWN, false, "database error");
     1785        return false;
     1786    }
     1787    if (!psArrayLength(output)) {
     1788        psTrace("disttool", PS_LOG_INFO, "no rows found");
     1789        psFree(output);
     1790        return true;
     1791    }
     1792
     1793    if (!ippdbPrintMetadatas(stdout, output, "rcInterest", !simple)) {
     1794        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1795        psFree(output);
     1796        return false;
     1797    }
     1798
     1799    psFree(output);
     1800
     1801    return true;
     1802}
     1803static bool pendingcleanupMode(pxConfig *config)
    16321804{
    16331805    PS_ASSERT_PTR_NON_NULL(config, false);
    16341806
    16351807    psMetadata *where = psMetadataAlloc();
     1808    PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "==");
     1809    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1810    pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "==");
     1811
     1812    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1813    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1814    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     1815
     1816    psString query = pxDataGet("disttool_pendingcleanup.sql");
     1817
     1818    if (psListLength(where->list)) {
     1819        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1820        psStringAppend(&query, " AND %s", whereClause);
     1821        psFree(whereClause);
     1822        psFree(where);
     1823    } else if (!all) {
     1824        psFree(where);
     1825        psError(PXTOOLS_ERR_CONFIG, false, "search parameters or -all are required");
     1826        return false;
     1827    }
     1828
     1829    // treat limit == 0 as "no limit"
     1830    if (limit) {
     1831        psString limitString = psDBGenerateLimitSQL(limit);
     1832        psStringAppend(&query, " %s", limitString);
     1833        psFree(limitString);
     1834    }
     1835
     1836    if (!p_psDBRunQuery(config->dbh, query)) {
     1837        psError(PS_ERR_UNKNOWN, false, "database error");
     1838        psFree(query);
     1839        if (!psDBRollback(config->dbh)) {
     1840            psError(PS_ERR_UNKNOWN, false, "database error");
     1841        }
     1842        return false;
     1843    }
     1844    psFree(query);
     1845
     1846    psArray *output = p_psDBFetchResult(config->dbh);
     1847    if (!output) {
     1848        psError(PS_ERR_UNKNOWN, false, "database error");
     1849        return false;
     1850    }
     1851    if (!psArrayLength(output)) {
     1852        psTrace("disttool", PS_LOG_INFO, "no rows found");
     1853        psFree(output);
     1854        return true;
     1855    }
     1856
     1857    if (!ippdbPrintMetadatas(stdout, output, "distToCleanup", !simple)) {
     1858        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1859        psFree(output);
     1860        return false;
     1861    }
     1862
     1863    psFree(output);
     1864
     1865    return true;
     1866}
     1867static bool listfilesetsMode(pxConfig *config)
     1868{
     1869    PS_ASSERT_PTR_NON_NULL(config, false);
     1870
     1871    psMetadata *where = psMetadataAlloc();
     1872    PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "==");
    16361873    PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "==");
    16371874    PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "==");
     
    16461883    PXOPT_LOOKUP_BOOL(full, config->args, "-full", false);
    16471884
     1885    pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "==");
     1886
    16481887    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    16491888    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    16501889
    1651     if (clean && full) {
    1652         psError(PS_ERR_UNKNOWN, false, "can't select both -clean and -full");
    1653         return false;
    1654     }
    1655 
    1656     psString query = pxDataGet("disttool_listinterests.sql");
    1657 
    1658     if (psListLength(where->list)) {
    1659         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    1660         psStringAppend(&query, " WHERE %s", whereClause);
    1661         psFree(whereClause);
    1662         if (clean) {
    1663             psStringAppend(&query, " AND (clean)");
    1664         } else if (full) {
    1665             psStringAppend(&query, " AND (!clean)");
    1666         }
    1667     } else if (clean) {
    1668         psStringAppend(&query, " WHERE clean");
    1669     } else if (full) {
    1670         psStringAppend(&query, " WHERE !clean");
    1671     }
     1890    if (!psListLength(where->list)) {
     1891        psFree(where);
     1892        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1893        return false;
     1894    }
     1895
     1896    psString query = pxDataGet("disttool_listfilesets.sql");
     1897
     1898    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1899    psStringAppend(&query, " WHERE %s", whereClause);
     1900    psFree(whereClause);
    16721901    psFree(where);
    16731902
     
    17001929    }
    17011930
    1702     if (!ippdbPrintMetadatas(stdout, output, "rcInterest", !simple)) {
     1931    if (!ippdbPrintMetadatas(stdout, output, "distFilesets", !simple)) {
    17031932        psError(PS_ERR_UNKNOWN, false, "failed to print array");
    17041933        psFree(output);
     
    17101939    return true;
    17111940}
     1941static bool updatefilesetMode(pxConfig *config)
     1942{
     1943    psMetadata *where = psMetadataAlloc();
     1944    PXOPT_COPY_S64(config->args, where, "-fs_id", "fs_id", "==");
     1945
     1946    if (!psListLength(where->list)) {
     1947        psFree(where);
     1948        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1949        return false;
     1950    }
     1951
     1952    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     1953
     1954    // We don't use PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); here
     1955    // because we want -fault 0 to work
     1956    bool gotFault = false;
     1957    psS16 fault = psMetadataLookupS16(&gotFault, config->args, "-fault");
     1958
     1959    if ((!state) && (!gotFault)) {
     1960        psError(PXTOOLS_ERR_CONFIG, true, "parameters (-fault or -set_state) is required");
     1961        psFree(where);
     1962        return false;
     1963    }
     1964
     1965    psString query = psStringCopy("UPDATE rcDSFileset SET ");
     1966
     1967    if (state) {
     1968        psStringAppend(&query, " state = '%s'", state);
     1969    }
     1970
     1971    if (gotFault) {
     1972        psStringAppend(&query, "%s fault = %d", state ? ", " : "", fault);
     1973    }
     1974
     1975    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1976    psStringAppend(&query, " WHERE %s", whereClause);
     1977    psFree(whereClause);
     1978    psFree(where);
     1979
     1980    if (!p_psDBRunQuery(config->dbh, query)) {
     1981        psError(PS_ERR_UNKNOWN, false, "database error");
     1982        psFree(query);
     1983        return false;
     1984    }
     1985
     1986    return true;
     1987}
Note: See TracChangeset for help on using the changeset viewer.