Changeset 27838 for branches/tap_branches/ippTools/src/disttool.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/disttool.c (modified) (54 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/ippTools/src
- Property svn:ignore
-
old new 16 16 difftool 17 17 disttool 18 dqstatstool 18 19 faketool 19 20 flatcorr
-
- Property svn:ignore
-
branches/tap_branches/ippTools/src/disttool.c
r25835 r27838 42 42 static bool addfilesetMode(pxConfig *config); 43 43 static bool revertfilesetMode(pxConfig *config); 44 static bool updatefilesetMode(pxConfig *config); 44 45 static bool queuercrunMode(pxConfig *config); 45 46 static bool updatercrunMode(pxConfig *config); 46 47 static bool revertrcrunMode(pxConfig *config); 47 48 static bool pendingdestMode(pxConfig *config); 49 static bool pendingcleanupMode(pxConfig *config); 50 static bool listfilesetsMode(pxConfig *config); 48 51 49 52 static bool definetargetMode(pxConfig *config); 50 53 static bool updatetargetMode(pxConfig *config); 51 static bool listtarget Mode(pxConfig *config);54 static bool listtargetsMode(pxConfig *config); 52 55 53 56 static bool definedestinationMode(pxConfig *config); … … 86 89 MODECASE(DISTTOOL_MODE_TOADVANCE, toadvanceMode); 87 90 MODECASE(DISTTOOL_MODE_PENDINGFILESET, pendingfilesetMode); 91 MODECASE(DISTTOOL_MODE_PENDINGCLEANUP, pendingcleanupMode); 88 92 MODECASE(DISTTOOL_MODE_ADDFILESET, addfilesetMode); 89 93 MODECASE(DISTTOOL_MODE_REVERTFILESET, revertfilesetMode); 94 MODECASE(DISTTOOL_MODE_LISTFILESETS, listfilesetsMode); 95 MODECASE(DISTTOOL_MODE_UPDATEFILESET, updatefilesetMode); 90 96 MODECASE(DISTTOOL_MODE_QUEUERCRUN, queuercrunMode); 91 97 MODECASE(DISTTOOL_MODE_UPDATERCRUN, updatercrunMode); … … 94 100 MODECASE(DISTTOOL_MODE_DEFINETARGET, definetargetMode); 95 101 MODECASE(DISTTOOL_MODE_UPDATETARGET, updatetargetMode); 96 MODECASE(DISTTOOL_MODE_LISTTARGET , listtargetMode);102 MODECASE(DISTTOOL_MODE_LISTTARGETS, listtargetsMode); 97 103 MODECASE(DISTTOOL_MODE_DEFINEDESTINATION, definedestinationMode); 98 104 MODECASE(DISTTOOL_MODE_UPDATEDESTINATION, updatedestinationMode); … … 131 137 132 138 // 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); 134 140 PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false); 135 141 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); 136 143 PXOPT_LOOKUP_STR(set_note, config->args, "-set_note", false, false); 137 144 138 145 PXOPT_LOOKUP_S64(limit, config->args, "-limit", false, false); 139 146 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 } 142 160 143 161 // select arguments … … 155 173 psString runJoinStr = NULL; 156 174 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 } 159 182 query = pxDataGet("disttool_definebyquery_raw.sql"); 160 183 if (!query) { 161 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");184 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 162 185 psFree(where); 163 186 return false; 164 187 } 165 188 166 // for raw stage we select by c hipRun.label because raw labels typically aren't set189 // for raw stage we select by camRun.label and dist_group because rawExp doesn't have those columns 167 190 if (label) { 168 psStringAppend(&query, " AND ( chipRun.label = '%s')", label);191 psStringAppend(&query, " AND (magicDSRun.label = '%s')", label); 169 192 } 170 193 if (dist_group) { 171 psStringAppend(&query, " AND (c hipRun.dist_group = '%s')", dist_group);194 psStringAppend(&query, " AND (camRun.dist_group = '%s')", dist_group); 172 195 } 173 196 } else if (!strcmp(stage, "chip")) { … … 176 199 query = pxDataGet("disttool_definebyquery_chip.sql"); 177 200 if (!query) { 178 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");201 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 179 202 psFree(where); 180 203 return false; … … 192 215 query = pxDataGet("disttool_definebyquery_camera.sql"); 193 216 if (!query) { 194 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");217 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 195 218 psFree(where); 196 219 return false; … … 207 230 query = pxDataGet("disttool_definebyquery_fake.sql"); 208 231 if (!query) { 209 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");232 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 210 233 psFree(where); 211 234 return false; … … 225 248 query = pxDataGet("disttool_definebyquery_warp.sql"); 226 249 if (!query) { 227 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");250 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 228 251 psFree(where); 229 252 return false; … … 242 265 query = pxDataGet("disttool_definebyquery_diff.sql"); 243 266 if (!query) { 244 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");267 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 245 268 psFree(where); 246 269 return false; … … 258 281 query = pxDataGet("disttool_definebyquery_stack.sql"); 259 282 if (!query) { 260 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");283 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 261 284 psFree(where); 262 285 return false; … … 271 294 // stack stage doesn't require magic 272 295 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; 273 314 } else { 274 315 psError(PS_ERR_UNKNOWN, true, "unknown value for stage: %s", stage); 275 316 psFree(where); 276 317 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 } 277 325 } 278 326 … … 287 335 288 336 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); 302 338 } 303 339 … … 307 343 psFree(limitString); 308 344 } 309 345 psTrace("disttool",2,query,joinHook ? joinHook : ""); 310 346 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; 314 350 } 315 351 psFree(query); … … 328 364 329 365 330 if ( dry_run) {366 if (pretend) { 331 367 if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", true)) { 332 368 psError(PS_ERR_UNKNOWN, false, "failed to print array"); … … 352 388 psS64 target_id = psMetadataLookupS64(NULL, md, "target_id"); 353 389 psString stage_label = psMetadataLookupStr(NULL, md, "label"); 390 psString stage_data_group = psMetadataLookupStr(NULL, md, "data_group"); 354 391 bool clean = psMetadataLookupBool(NULL, md, "clean"); 355 392 356 393 psString outroot = NULL; 357 psStringAppend(&outroot, "%s/%s/%s", workdir, run_tag, stage); 394 psStringAppend(&outroot, "%s/%s/%s", workdir, run_tag, stage); 358 395 359 396 psString new_label; … … 363 400 new_label = stage_label; 364 401 } 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 365 409 distRunRow *row = distRunRowAlloc( 366 410 0, // dist_id … … 371 415 new_label, 372 416 outroot, 417 NULL, // outdir 373 418 clean, 374 419 no_magic, 420 use_alternate, 375 421 "new", 376 NULL, // time_stamp422 NULL, // time_stamp 377 423 0, // fault 378 set_note // note does not propagate 424 new_data_group, 425 set_note // note does not propagate 379 426 ); 380 427 … … 419 466 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 420 467 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", "=="); 422 469 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", "=="); 423 473 424 474 if (!psListLength(where->list)) { 425 475 psFree(where); 426 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");476 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 427 477 return false; 428 478 } … … 430 480 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 431 481 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); 432 484 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 } 442 498 if (state) { 443 psStringAppend(&query, " , state = '%s'", state);499 psStringAppend(&query, " , distRun.state = '%s'", state); 444 500 } 445 501 446 502 if (label) { 447 psStringAppend(&query, " , label = '%s'", label);503 psStringAppend(&query, " , distRun.label = '%s'", label); 448 504 } 449 505 450 506 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 453 518 454 519 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); … … 481 546 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 482 547 psFree(where); 483 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");548 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 484 549 return false; 485 550 } … … 487 552 psString query = pxDataGet("disttool_revertrun.sql"); 488 553 if (!query) { 489 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");554 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 490 555 if (!psDBRollback(config->dbh)) { 491 556 psError(PS_ERR_UNKNOWN, false, "database error"); … … 522 587 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 523 588 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 524 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");589 pxAddLabelSearchArgs(config, where, "-label", "distRun.label", "=="); 525 590 526 591 PXOPT_COPY_S16(config->args, where, "-fault", "distComponent.fault", "=="); … … 530 595 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 531 596 psFree(where); 532 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");597 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 533 598 return false; 534 599 } … … 536 601 psString query = pxDataGet("disttool_revertcomponent.sql"); 537 602 if (!query) { 538 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");603 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 539 604 psFree(where); 540 605 return false; … … 568 633 569 634 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", "=="); 571 636 pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "=="); 572 637 … … 578 643 psString query = pxDataGet(queryFile); 579 644 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); 581 646 return false; 582 647 } … … 652 717 PXOPT_LOOKUP_S32(bytes, config->args, "-bytes", require_fileinfo, false); 653 718 PXOPT_LOOKUP_STR(md5sum, config->args, "-md5sum", require_fileinfo, false); 719 PXOPT_LOOKUP_STR(outdir, config->args, "-outdir", require_fileinfo, false); 654 720 PXOPT_LOOKUP_STR(name, config->args, "-name", require_fileinfo, false); 655 721 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)) { 657 723 psError(PS_ERR_UNKNOWN, false, "database error"); 658 724 return false; … … 676 742 psString query = pxDataGet("disttool_toadvance.sql"); 677 743 if (!query) { 678 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");744 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 679 745 return false; 680 746 } … … 747 813 psString query = pxDataGet("disttool_processedcomponent.sql"); 748 814 if (!query) { 749 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");815 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 750 816 return false; 751 817 } … … 821 887 psString query = pxDataGet("disttool_pendingfileset.sql"); 822 888 if (!query) { 823 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");889 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 824 890 return false; 825 891 } … … 891 957 PXOPT_LOOKUP_STR(name, config->args, "-name", fault == 0, false); 892 958 893 if (!rcDSFilesetInsert(config->dbh, 959 if (!rcDSFilesetInsert(config->dbh, 894 960 0, // fs_id 895 961 dist_id, … … 904 970 return true; 905 971 } 972 906 973 static bool revertfilesetMode(pxConfig *config) 907 974 { … … 920 987 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 921 988 psFree(where); 922 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");989 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 923 990 return false; 924 991 } … … 926 993 psString query = pxDataGet("disttool_revertfileset.sql"); 927 994 if (!query) { 928 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");995 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 929 996 psFree(where); 930 997 return false; … … 968 1035 psString query = pxDataGet("disttool_pendingdest.sql"); 969 1036 if (!query) { 970 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1037 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 971 1038 return false; 972 1039 } … … 1047 1114 psString query = pxDataGet("disttool_queuercrun.sql"); 1048 1115 if (!query) { 1049 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1116 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1050 1117 return false; 1051 1118 } … … 1093 1160 // We either need rc_id or (dest_id and fs_name) to identifiy the rcRun 1094 1161 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"); 1096 1163 return false; 1097 1164 } … … 1105 1172 // this can't happen because we checked above 1106 1173 psFree(where); 1107 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");1174 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1108 1175 return false; 1109 1176 } … … 1115 1182 1116 1183 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"); 1118 1185 psFree(where); 1119 1186 return false; … … 1122 1189 psString query = pxDataGet("disttool_updatercrun.sql"); 1123 1190 if (!query) { 1124 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1191 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1125 1192 return false; 1126 1193 } … … 1179 1246 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 1180 1247 psFree(where); 1181 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");1248 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1182 1249 return false; 1183 1250 } … … 1185 1252 psString query = pxDataGet("disttool_revertrcrun.sql"); 1186 1253 if (!query) { 1187 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1254 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1188 1255 if (!psDBRollback(config->dbh)) { 1189 1256 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1238 1305 comment 1239 1306 ); 1240 1307 1241 1308 if (!row) { 1242 1309 psError(PS_ERR_UNKNOWN, false, "failed to allocate distTarget object"); … … 1298 1365 } 1299 1366 1300 static bool listtarget Mode(pxConfig *config)1367 static bool listtargetsMode(pxConfig *config) 1301 1368 { 1302 1369 PS_ASSERT_PTR_NON_NULL(config, false); … … 1404 1471 state ? state : "enabled" 1405 1472 ); 1406 1473 1407 1474 if (!row) { 1408 1475 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDestination object"); … … 1441 1508 if (!(state || last_fileset)) { 1442 1509 psError(PS_ERR_UNKNOWN, true, "one or more of -set_state or -set_last_fileset is required"); 1443 # else 1510 # else 1444 1511 if (!state) { 1445 1512 #endif … … 1538 1605 PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE"); 1539 1606 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 } 1541 1611 1542 1612 psString query = pxDataGet("disttool_defineinterest.sql"); … … 1598 1668 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1599 1669 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 1600 1683 1601 1684 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); … … 1605 1688 return false; 1606 1689 } 1607 psString query = NULL; 1608 psStringAppend(&query, "UPDATE rcInterest SET state = '%s'", state); 1690 psString query = pxDataGet("disttool_updateinterest.sql"); 1609 1691 1610 1692 if (psListLength(where->list)) { … … 1620 1702 psFree(where); 1621 1703 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 } 1722 static 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 1622 1772 if (!p_psDBRunQuery(config->dbh, query)) { 1623 1773 psError(PS_ERR_UNKNOWN, false, "database error"); 1624 1774 psFree(query); 1775 if (!psDBRollback(config->dbh)) { 1776 psError(PS_ERR_UNKNOWN, false, "database error"); 1777 } 1625 1778 return false; 1626 1779 } 1627 1780 psFree(query); 1628 1781 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 } 1803 static bool pendingcleanupMode(pxConfig *config) 1632 1804 { 1633 1805 PS_ASSERT_PTR_NON_NULL(config, false); 1634 1806 1635 1807 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 } 1867 static 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", "=="); 1636 1873 PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "=="); 1637 1874 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); … … 1646 1883 PXOPT_LOOKUP_BOOL(full, config->args, "-full", false); 1647 1884 1885 pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "=="); 1886 1648 1887 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1649 1888 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1650 1889 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); 1672 1901 psFree(where); 1673 1902 … … 1700 1929 } 1701 1930 1702 if (!ippdbPrintMetadatas(stdout, output, " rcInterest", !simple)) {1931 if (!ippdbPrintMetadatas(stdout, output, "distFilesets", !simple)) { 1703 1932 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1704 1933 psFree(output); … … 1710 1939 return true; 1711 1940 } 1941 static 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.
