- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/disttool.c (modified) (68 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ippTools/src
- Property svn:ignore
-
old new 1 *.la 2 *.lo 1 3 .deps 2 4 .gdb_history … … 4 6 Makefile 5 7 Makefile.in 8 addtool 9 caltool 10 camtool 11 chiptool 6 12 config.h 7 13 config.h.in 8 stamp-h1 9 *.la 10 *.lo 14 detselect 15 dettool 16 difftool 17 disttool 18 dqstatstool 19 faketool 20 flatcorr 21 guidetool 22 magicdstool 23 magictool 24 pstamptool 25 pubtool 26 pxadmin 27 pxdata.c 28 pxinject 11 29 pxtoolsErrorCodes.c 12 30 pxtoolsErrorCodes.h 13 pxadmin14 pxinject15 pztool16 31 pzgetexp 17 32 pzgetimfiles 33 pztool 34 receivetool 18 35 regtool 19 guidetool 20 chiptool 21 camtool 36 stacktool 37 stamp-h1 22 38 warptool 23 difftool24 stacktool25 faketool26 dettool27 detselect28 pxdata.c29 magictool30 magicdstool31 caltool32 flatcorr33 pstamptool34 disttool35 receivetool36 37 pubtool
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/ippTools/src/disttool.c
r25031 r27840 2 2 * disttool.c 3 3 * 4 * Copyright (C) 2008 4 * Copyright (C) 2008-2009 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify it … … 32 32 33 33 static bool definebyqueryMode(pxConfig *config); 34 static bool definerunMode(pxConfig *config);35 34 static bool updaterunMode(pxConfig *config); 36 35 static bool revertrunMode(pxConfig *config); 37 36 static bool pendingcomponentMode(pxConfig *config); 38 37 static bool addprocessedcomponentMode(pxConfig *config); 38 static bool revertcomponentMode(pxConfig *config); 39 39 static bool processedcomponentMode(pxConfig *config); 40 40 static bool toadvanceMode(pxConfig *config); … … 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 listtargetMode(pxConfig *config); 52 53 static bool definedsproductMode(pxConfig *config); 54 static bool updatedsproductMode(pxConfig *config); 54 static bool listtargetsMode(pxConfig *config); 55 55 56 56 static bool definedestinationMode(pxConfig *config); … … 59 59 static bool defineinterestMode(pxConfig *config); 60 60 static bool updateinterestMode(pxConfig *config); 61 static bool listinterestsMode(pxConfig *config); 61 62 62 63 # define MODECASE(caseName, func) \ … … 80 81 switch (config->mode) { 81 82 MODECASE(DISTTOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 82 MODECASE(DISTTOOL_MODE_DEFINERUN, definerunMode);83 83 MODECASE(DISTTOOL_MODE_UPDATERUN, updaterunMode); 84 84 MODECASE(DISTTOOL_MODE_REVERTRUN, revertrunMode); … … 86 86 MODECASE(DISTTOOL_MODE_ADDPROCESSEDCOMPONENT, addprocessedcomponentMode); 87 87 MODECASE(DISTTOOL_MODE_PROCESSEDCOMPONENT, processedcomponentMode); 88 MODECASE(DISTTOOL_MODE_REVERTCOMPONENT, revertcomponentMode); 88 89 MODECASE(DISTTOOL_MODE_TOADVANCE, toadvanceMode); 89 90 MODECASE(DISTTOOL_MODE_PENDINGFILESET, pendingfilesetMode); 91 MODECASE(DISTTOOL_MODE_PENDINGCLEANUP, pendingcleanupMode); 90 92 MODECASE(DISTTOOL_MODE_ADDFILESET, addfilesetMode); 91 93 MODECASE(DISTTOOL_MODE_REVERTFILESET, revertfilesetMode); 94 MODECASE(DISTTOOL_MODE_LISTFILESETS, listfilesetsMode); 95 MODECASE(DISTTOOL_MODE_UPDATEFILESET, updatefilesetMode); 92 96 MODECASE(DISTTOOL_MODE_QUEUERCRUN, queuercrunMode); 93 97 MODECASE(DISTTOOL_MODE_UPDATERCRUN, updatercrunMode); … … 96 100 MODECASE(DISTTOOL_MODE_DEFINETARGET, definetargetMode); 97 101 MODECASE(DISTTOOL_MODE_UPDATETARGET, updatetargetMode); 98 MODECASE(DISTTOOL_MODE_LISTTARGET, listtargetMode); 99 MODECASE(DISTTOOL_MODE_DEFINEDSPRODUCT, definedsproductMode); 100 MODECASE(DISTTOOL_MODE_UPDATEDSPRODUCT, updatedsproductMode); 102 MODECASE(DISTTOOL_MODE_LISTTARGETS, listtargetsMode); 101 103 MODECASE(DISTTOOL_MODE_DEFINEDESTINATION, definedestinationMode); 102 104 MODECASE(DISTTOOL_MODE_UPDATEDESTINATION, updatedestinationMode); 103 105 MODECASE(DISTTOOL_MODE_DEFINEINTEREST, defineinterestMode); 104 106 MODECASE(DISTTOOL_MODE_UPDATEINTEREST, updateinterestMode); 107 MODECASE(DISTTOOL_MODE_LISTINTERESTS, listinterestsMode); 105 108 default: 106 109 psAbort("invalid option (this should not happen)"); … … 124 127 } 125 128 126 static bool definerunMode(pxConfig *config)127 {128 PS_ASSERT_PTR_NON_NULL(config, false);129 130 // required131 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);132 PXOPT_LOOKUP_S64(stage_id, config->args, "-stage_id", true, false);133 PXOPT_LOOKUP_STR(outroot, config->args, "-outroot", true, false);134 PXOPT_LOOKUP_S64(target_id, config->args, "-target_id", true, false);135 136 // optional137 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);138 PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false);139 PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);140 141 // TODO: check that stage has an expected value142 // XXX: all of the following concerns will be managed properly by definebyquery143 144 // TODO: should we check that stage_id actually exists for stage145 // in magicdstool we queue off of a magic_id so the stage_id, exp_id, and cam_id get looked up146 // when the run is queued147 148 if (!distRunInsert(config->dbh,149 0, // dist_id150 target_id,151 stage,152 stage_id,153 set_label,154 outroot,155 clean,156 no_magic,157 "new",158 NULL, // time_stamp159 0 // fault160 )) {161 psError(PS_ERR_UNKNOWN, false, "database error");162 return false;163 }164 165 return true;166 }167 129 168 130 static bool definebyqueryMode(pxConfig *config) … … 175 137 176 138 // optional 177 PXOPT_LOOKUP_ S64(magic_ds_id, config->args, "-magic_ds_id", false, false);139 PXOPT_LOOKUP_BOOL(use_alternate, config->args, "-use_alternate", false); 178 140 PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false); 179 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); 143 PXOPT_LOOKUP_STR(set_note, config->args, "-set_note", false, false); 144 180 145 PXOPT_LOOKUP_S64(limit, config->args, "-limit", false, false); 181 146 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 182 183 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 } 184 160 185 161 // select arguments … … 191 167 192 168 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 169 PXOPT_LOOKUP_STR(dist_group, config->args, "-dist_group", false, false); 193 170 194 171 psString query = NULL; … … 196 173 psString runJoinStr = NULL; 197 174 if (!strcmp(stage, "raw")) { 198 magicRunType = "rawExp"; 199 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 } 200 182 query = pxDataGet("disttool_definebyquery_raw.sql"); 201 183 if (!query) { 202 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");184 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 203 185 psFree(where); 204 186 return false; 205 187 } 206 188 207 // 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 208 190 if (label) { 209 psStringAppend(&query, " AND (chipRun.label = '%s')", label); 191 psStringAppend(&query, " AND (magicDSRun.label = '%s')", label); 192 } 193 if (dist_group) { 194 psStringAppend(&query, " AND (camRun.dist_group = '%s')", dist_group); 210 195 } 211 196 } else if (!strcmp(stage, "chip")) { … … 214 199 query = pxDataGet("disttool_definebyquery_chip.sql"); 215 200 if (!query) { 216 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");201 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 217 202 psFree(where); 218 203 return false; … … 222 207 psStringAppend(&query, " AND (chipRun.label = '%s')", label); 223 208 } 209 if (dist_group) { 210 psStringAppend(&query, " AND (chipRun.dist_group = '%s')", dist_group); 211 } 224 212 } else if (!strcmp(stage, "camera")) { 225 magicRunType = "chipRun"; // This is used below to set the magicked business 213 magicRunType = "camRun"; // This is used below to set the magicked business 214 runJoinStr = "camRun.cam_id"; 226 215 query = pxDataGet("disttool_definebyquery_camera.sql"); 227 216 if (!query) { 228 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");217 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 229 218 psFree(where); 230 219 return false; … … 233 222 if (label) { 234 223 psStringAppend(&query, " AND (camRun.label = '%s')", label); 224 } 225 if (dist_group) { 226 psStringAppend(&query, " AND (camRun.dist_group = '%s')", dist_group); 235 227 } 236 228 } else if (!strcmp(stage, "fake")) { … … 238 230 query = pxDataGet("disttool_definebyquery_fake.sql"); 239 231 if (!query) { 240 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");232 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 241 233 psFree(where); 242 234 return false; … … 245 237 if (label) { 246 238 psStringAppend(&query, " AND (fakeRun.label = '%s')", label); 239 } 240 if (dist_group) { 241 psStringAppend(&query, " AND (fakeRun.dist_group = '%s')", dist_group); 247 242 } 248 243 // fake stage doesn't require magic … … 253 248 query = pxDataGet("disttool_definebyquery_warp.sql"); 254 249 if (!query) { 255 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");250 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 256 251 psFree(where); 257 252 return false; … … 260 255 if (label) { 261 256 psStringAppend(&query, " AND (warpRun.label = '%s')", label); 257 } 258 if (dist_group) { 259 psStringAppend(&query, " AND (warpRun.dist_group = '%s')", dist_group); 262 260 } 263 261 … … 267 265 query = pxDataGet("disttool_definebyquery_diff.sql"); 268 266 if (!query) { 269 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");267 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 270 268 psFree(where); 271 269 return false; … … 274 272 if (label) { 275 273 psStringAppend(&query, " AND (diffRun.label = '%s')", label); 274 } 275 if (dist_group) { 276 psStringAppend(&query, " AND (diffRun.dist_group = '%s')", dist_group); 276 277 } 277 278 … … 280 281 query = pxDataGet("disttool_definebyquery_stack.sql"); 281 282 if (!query) { 282 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");283 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 283 284 psFree(where); 284 285 return false; … … 288 289 psStringAppend(&query, " AND (stackRun.label = '%s')", label); 289 290 } 290 // stack stage doesn't require magic (perhaps let the script do this? 291 if (dist_group) { 292 psStringAppend(&query, " AND (stackRun.dist_group = '%s')", dist_group); 293 } 294 // stack stage doesn't require magic 291 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; 292 314 } else { 293 315 psError(PS_ERR_UNKNOWN, true, "unknown value for stage: %s", stage); 294 316 psFree(where); 295 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 } 296 325 } 297 326 … … 306 335 307 336 if (!no_magic) { 308 psStringAppend(&query, " AND (distTarget.clean OR %s.magicked)", magicRunType); 309 310 // is selecting by magic_ds_id really interesting? 311 if (magic_ds_id) { 312 if (strcmp(stage, "camera")) { 313 // stage other than camera 314 if (!runJoinStr) { 315 psError(PS_ERR_PROGRAMMING, true, "cannot select by magic_ds_id for stage: %s", stage); 316 psFree(query); 317 return false; 318 } 319 psStringAppend(&joinHook, "\nJOIN magicDSRun ON magicDSRun.stage = distTarget.stage" 320 " AND magicDSRun.stage_id = %s", runJoinStr); 321 } else { 322 // camera masks are magicked when the chipRun is magicked 323 // XXX: This is confusing. Is it dangerous? 324 // Maybe I should add a magicked bit to camRun. Note this isn't 325 psStringAppend(&joinHook, "\nJOIN magicDSRun ON magicDSRun.stage = 'chip'" 326 " AND magicDSRun.stage_id = chipRun.chip_id"); 327 } 328 psStringAppend(&query, " AND (magicDSRun.state = 'full' AND magicDSRun.re_place AND (magic_ds_id = %" PRId64 "))", magic_ds_id); 329 } 337 psStringAppend(&query, " AND (%s.magicked > 0)", magicRunType); 330 338 } 331 339 … … 335 343 psFree(limitString); 336 344 } 337 345 psTrace("disttool",2,query,joinHook ? joinHook : ""); 338 346 if (!p_psDBRunQueryF(config->dbh, query, joinHook ? joinHook : "")) { 339 psError(PS_ERR_UNKNOWN, false, "database error");340 psFree(query);341 return false;347 psError(PS_ERR_UNKNOWN, false, "database error"); 348 psFree(query); 349 return false; 342 350 } 343 351 psFree(query); … … 356 364 357 365 358 if ( dry_run) {366 if (pretend) { 359 367 if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", true)) { 360 368 psError(PS_ERR_UNKNOWN, false, "failed to print array"); … … 377 385 psString run_tag = psMetadataLookupStr(NULL, md, "run_tag"); 378 386 psS64 stage_id = psMetadataLookupS64(NULL, md, "stage_id"); 387 psS64 magic_ds_id = psMetadataLookupS64(NULL, md, "magicked"); 379 388 psS64 target_id = psMetadataLookupS64(NULL, md, "target_id"); 380 psString target_label = psMetadataLookupStr(NULL, md, "label"); 389 psString stage_label = psMetadataLookupStr(NULL, md, "label"); 390 psString stage_data_group = psMetadataLookupStr(NULL, md, "data_group"); 381 391 bool clean = psMetadataLookupBool(NULL, md, "clean"); 382 392 383 393 psString outroot = NULL; 384 psStringAppend(&outroot, "%s/%s/%s", workdir, run_tag, stage); 394 psStringAppend(&outroot, "%s/%s/%s", workdir, run_tag, stage); 385 395 386 396 psString new_label; … … 388 398 new_label = set_label; 389 399 } else { 390 new_label = target_label; 391 } 400 new_label = stage_label; 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 392 409 distRunRow *row = distRunRowAlloc( 393 410 0, // dist_id … … 395 412 stage, 396 413 stage_id, 414 magic_ds_id, 397 415 new_label, 398 416 outroot, 417 NULL, // outdir 399 418 clean, 400 419 no_magic, 420 use_alternate, 401 421 "new", 402 NULL, // time_stamp 403 0 // fault 422 NULL, // time_stamp 423 0, // fault 424 new_data_group, 425 set_note // note does not propagate 404 426 ); 405 427 … … 444 466 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 445 467 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");; 446 PXOPT_COPY_STR(config->args, where, "-state", " state", "==");468 PXOPT_COPY_STR(config->args, where, "-state", "distRun.state", "=="); 447 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", "=="); 448 473 449 474 if (!psListLength(where->list)) { 450 475 psFree(where); 451 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");476 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 452 477 return false; 453 478 } … … 455 480 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 456 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); 457 484 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 458 459 if ((!state) && (!label) && (!fault)) { 460 psError(PXTOOLS_ERR_DATA, false, "parameters (-fault or -set_state or -set_label) are required"); 461 psFree(where); 462 return false; 463 } 464 465 psString query = psStringCopy("UPDATE distRun SET time_stamp = UTC_TIMESTAMP()"); 466 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 } 467 498 if (state) { 468 psStringAppend(&query, " , state = '%s'", state);499 psStringAppend(&query, " , distRun.state = '%s'", state); 469 500 } 470 501 471 502 if (label) { 472 psStringAppend(&query, " , label = '%s'", label);503 psStringAppend(&query, " , distRun.label = '%s'", label); 473 504 } 474 505 475 506 if (fault) { 476 psStringAppend(&query, " , fault = %d", fault); 477 } 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 478 518 479 519 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); … … 500 540 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 501 541 502 // we need to disambiguate fault so make a copy of the where list before adding fault503 psMetadata *whereComponent = psMetadataCopy(NULL, where);504 542 PXOPT_COPY_S16(config->args, where, "-fault", "distRun.fault", "=="); 505 PXOPT_COPY_S16(config->args, whereComponent, "-fault", "distComponent.fault", "==");506 543 507 544 // It might be useful to be able to query by the parameters of the underlying runs … … 509 546 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 510 547 psFree(where); 511 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 512 return false; 513 } 514 515 if (!psDBTransaction(config->dbh)) { 516 psError(PS_ERR_UNKNOWN, false, "database error"); 517 psFree(where); 518 return false; 519 } 520 521 // Update state to 'new' 522 int numUpdated; // Number updated 523 { 524 psString query = pxDataGet("disttool_revertrun_update.sql"); 525 if (!query) { 526 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 527 if (!psDBRollback(config->dbh)) { 528 psError(PS_ERR_UNKNOWN, false, "database error"); 529 } 530 return false; 531 } 532 533 if (psListLength(where->list)) { 534 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 535 psStringAppend(&query, " AND %s", whereClause); 536 psFree(whereClause); 537 } 538 539 if (!p_psDBRunQuery(config->dbh, query)) { 548 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 549 return false; 550 } 551 552 psString query = pxDataGet("disttool_revertrun.sql"); 553 if (!query) { 554 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 555 if (!psDBRollback(config->dbh)) { 540 556 psError(PS_ERR_UNKNOWN, false, "database error"); 541 psFree(query); 542 if (!psDBRollback(config->dbh)) { 543 psError(PS_ERR_UNKNOWN, false, "database error"); 544 } 545 return false; 546 } 547 psFree(query); 548 549 numUpdated = psDBAffectedRows(config->dbh); 550 } 557 } 558 return false; 559 } 560 561 if (psListLength(where->list)) { 562 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 563 psStringAppend(&query, " AND %s", whereClause); 564 psFree(whereClause); 565 } 566 psFree(where); 567 568 if (!p_psDBRunQuery(config->dbh, query)) { 569 psError(PS_ERR_UNKNOWN, false, "database error"); 570 psFree(query); 571 return false; 572 } 573 574 int numUpdated = psDBAffectedRows(config->dbh); 551 575 552 576 psLogMsg("disttool", PS_LOG_INFO, "Updated %d dist runs", numUpdated); 553 577 554 // Delete product 555 int numDeleted; // Number deleted 556 { 557 psString query = pxDataGet("disttool_revertrun_delete.sql"); 558 if (!query) { 559 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 560 if (!psDBRollback(config->dbh)) { 561 psError(PS_ERR_UNKNOWN, false, "database error"); 562 } 563 return false; 564 } 565 566 if (psListLength(whereComponent->list)) { 567 psString whereClause = psDBGenerateWhereConditionSQL(whereComponent, NULL); 568 psStringAppend(&query, " AND %s", whereClause); 569 psFree(whereClause); 570 } 571 572 if (!p_psDBRunQuery(config->dbh, query)) { 573 psError(PS_ERR_UNKNOWN, false, "database error"); 574 psFree(query); 575 if (!psDBRollback(config->dbh)) { 576 psError(PS_ERR_UNKNOWN, false, "database error"); 577 } 578 return false; 579 } 580 psFree(query); 581 582 numDeleted = psDBAffectedRows(config->dbh); 583 } 578 return true; 579 } 580 581 static bool revertcomponentMode(pxConfig *config) 582 { 583 psMetadata *where = psMetadataAlloc(); 584 PXOPT_COPY_S64(config->args, where, "-dist_id", "distRun.dist_id", "=="); 585 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");; 586 PXOPT_COPY_STR(config->args, where, "-component", "component", "==");; 587 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 588 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 589 pxAddLabelSearchArgs(config, where, "-label", "distRun.label", "=="); 590 591 PXOPT_COPY_S16(config->args, where, "-fault", "distComponent.fault", "=="); 592 593 // It might be useful to be able to query by the parameters of the underlying runs 594 595 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 596 psFree(where); 597 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 598 return false; 599 } 600 601 psString query = pxDataGet("disttool_revertcomponent.sql"); 602 if (!query) { 603 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 604 psFree(where); 605 return false; 606 } 607 608 if (psListLength(where->list)) { 609 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 610 psStringAppend(&query, " AND %s", whereClause); 611 psFree(whereClause); 612 } 613 psFree(where); 614 615 if (!p_psDBRunQuery(config->dbh, query)) { 616 psError(PS_ERR_UNKNOWN, false, "database error"); 617 psFree(query); 618 return false; 619 } 620 621 int numDeleted = psDBAffectedRows(config->dbh); 584 622 585 623 psLogMsg("disttool", PS_LOG_INFO, "Deleted %d distComponents", numDeleted); 586 624 587 psFree(where);588 psFree(whereComponent);589 590 if (!psDBCommit(config->dbh)) {591 psError(PS_ERR_UNKNOWN, false, "database error");592 return false;593 }594 595 625 return true; 596 626 } … … 600 630 PS_ASSERT_PTR_NON_NULL(config, false); 601 631 602 psMetadata *where = psMetadataAlloc(); 603 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 604 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 605 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 632 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 633 634 psMetadata *where = psMetadataAlloc(); 635 PXOPT_COPY_S64(config->args, where, "-dist_id", "distRun.dist_id", "=="); 636 pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "=="); 606 637 607 638 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 608 639 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 609 640 610 // look for "inputs" that need to processed 611 psString query = pxDataGet("disttool_pendingcomponent.sql"); 641 psString queryFile = NULL; 642 psStringAppend(&queryFile, "disttool_pending_%s.sql", stage); 643 psString query = pxDataGet(queryFile); 612 644 if (!query) { 613 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");645 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement from %s", queryFile); 614 646 return false; 615 647 } … … 617 649 if (psListLength(where->list)) { 618 650 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 619 psStringAppend(&query, " WHERE%s", whereClause);651 psStringAppend(&query, " AND %s", whereClause); 620 652 psFree(whereClause); 621 653 } … … 629 661 } 630 662 631 // the query has where hooks for each stage. 632 // right now we aren't using them. 633 // XXX: I think that I want to change the query from a union of selects on the various 634 // stages to separate queries. As it is pending data at the later stages of the pipline 635 // will get blocked by pending earlier stages 636 psString raw_where = ""; 637 psString raw_clean_where = ""; 638 psString chip_where = ""; 639 psString camera_where = ""; 640 psString fake_where = ""; 641 psString warp_where = ""; 642 psString diff_where = ""; 643 psString stack_where = ""; 644 645 if (!p_psDBRunQueryF(config->dbh, 646 query, 647 raw_where, 648 raw_clean_where, 649 chip_where, 650 camera_where, 651 fake_where, 652 warp_where, 653 diff_where, 654 stack_where)) { 663 if (!p_psDBRunQuery(config->dbh, query)) { 655 664 psError(PS_ERR_UNKNOWN, false, "database error"); 656 665 psFree(query); … … 708 717 PXOPT_LOOKUP_S32(bytes, config->args, "-bytes", require_fileinfo, false); 709 718 PXOPT_LOOKUP_STR(md5sum, config->args, "-md5sum", require_fileinfo, false); 719 PXOPT_LOOKUP_STR(outdir, config->args, "-outdir", require_fileinfo, false); 710 720 PXOPT_LOOKUP_STR(name, config->args, "-name", require_fileinfo, false); 711 721 712 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)) { 713 723 psError(PS_ERR_UNKNOWN, false, "database error"); 714 724 return false; … … 732 742 psString query = pxDataGet("disttool_toadvance.sql"); 733 743 if (!query) { 734 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");744 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 735 745 return false; 736 746 } … … 803 813 psString query = pxDataGet("disttool_processedcomponent.sql"); 804 814 if (!query) { 805 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");815 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 806 816 return false; 807 817 } … … 868 878 psMetadata *where = psMetadataAlloc(); 869 879 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 880 PXOPT_COPY_STR(config->args, where, "-stage", "distRun.stage", "=="); 870 881 pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "=="); 871 882 … … 876 887 psString query = pxDataGet("disttool_pendingfileset.sql"); 877 888 if (!query) { 878 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");889 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 879 890 return false; 880 891 } … … 939 950 // required values 940 951 PXOPT_LOOKUP_S64(dist_id, config->args, "-dist_id", true, false); 941 PXOPT_LOOKUP_S64( prod_id, config->args, "-prod_id", true, false);952 PXOPT_LOOKUP_S64(dest_id, config->args, "-dest_id", true, false); 942 953 943 954 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); … … 946 957 PXOPT_LOOKUP_STR(name, config->args, "-name", fault == 0, false); 947 958 948 if (!rcDSFilesetInsert(config->dbh, 959 if (!rcDSFilesetInsert(config->dbh, 949 960 0, // fs_id 950 961 dist_id, 951 prod_id,962 dest_id, 952 963 name, 953 964 "full", … … 959 970 return true; 960 971 } 972 961 973 static bool revertfilesetMode(pxConfig *config) 962 974 { … … 964 976 PXOPT_COPY_S64(config->args, where, "-fs_id", "fs_id", "=="); 965 977 PXOPT_COPY_S64(config->args, where, "-dist_id", "rcDSFileset.dist_id", "=="); 966 PXOPT_COPY_S64(config->args, where, "- prod_id", "prod_id", "==");978 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 967 979 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");; 968 980 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); … … 975 987 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 976 988 psFree(where); 977 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");989 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 978 990 return false; 979 991 } … … 981 993 psString query = pxDataGet("disttool_revertfileset.sql"); 982 994 if (!query) { 983 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");995 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 984 996 psFree(where); 985 997 return false; … … 1023 1035 psString query = pxDataGet("disttool_pendingdest.sql"); 1024 1036 if (!query) { 1025 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1037 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1026 1038 return false; 1027 1039 } … … 1092 1104 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 1093 1105 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1094 PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "==");1095 1106 PXOPT_COPY_S64(config->args, where, "-target_id","target_id", "=="); 1096 1107 PXOPT_COPY_S64(config->args, where, "-fs_id", "fs_id", "=="); … … 1103 1114 psString query = pxDataGet("disttool_queuercrun.sql"); 1104 1115 if (!query) { 1105 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1116 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1106 1117 return false; 1107 1118 } … … 1149 1160 // We either need rc_id or (dest_id and fs_name) to identifiy the rcRun 1150 1161 if ((!rc_id) && !(dest_id && fs_name)) { 1151 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"); 1152 1163 return false; 1153 1164 } … … 1161 1172 // this can't happen because we checked above 1162 1173 psFree(where); 1163 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");1174 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1164 1175 return false; 1165 1176 } … … 1171 1182 1172 1183 if (!state && (fault < 0)) { 1173 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"); 1174 1185 psFree(where); 1175 1186 return false; … … 1178 1189 psString query = pxDataGet("disttool_updatercrun.sql"); 1179 1190 if (!query) { 1180 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1191 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1181 1192 return false; 1182 1193 } … … 1235 1246 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 1236 1247 psFree(where); 1237 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");1248 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1238 1249 return false; 1239 1250 } … … 1241 1252 psString query = pxDataGet("disttool_revertrcrun.sql"); 1242 1253 if (!query) { 1243 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1254 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1244 1255 if (!psDBRollback(config->dbh)) { 1245 1256 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1276 1287 1277 1288 // required 1278 PXOPT_LOOKUP_STR( label, config->args, "-label", true, false);1289 PXOPT_LOOKUP_STR(dist_group, config->args, "-dist_group", true, false); 1279 1290 PXOPT_LOOKUP_STR(filter, config->args, "-filter", true, false); 1280 1291 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); … … 1287 1298 distTargetRow *row = distTargetRowAlloc( 1288 1299 0, // target_id 1289 label,1300 dist_group, 1290 1301 filter, 1291 1302 stage, … … 1294 1305 comment 1295 1306 ); 1296 1307 1297 1308 if (!row) { 1298 1309 psError(PS_ERR_UNKNOWN, false, "failed to allocate distTarget object"); … … 1324 1335 psMetadata *where = psMetadataAlloc(); 1325 1336 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1326 PXOPT_COPY_STR(config->args, where, "- label", "label", "==");1337 PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "=="); 1327 1338 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "=="); 1328 1339 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); … … 1354 1365 } 1355 1366 1356 static bool listtarget Mode(pxConfig *config)1367 static bool listtargetsMode(pxConfig *config) 1357 1368 { 1358 1369 PS_ASSERT_PTR_NON_NULL(config, false); … … 1360 1371 psMetadata *where = psMetadataAlloc(); 1361 1372 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1362 PXOPT_COPY_STR(config->args, where, "- label", "label", "==");1373 PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE"); 1363 1374 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "=="); 1364 1375 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); … … 1433 1444 } 1434 1445 1435 static bool defined sproductMode(pxConfig *config)1446 static bool definedestinationMode(pxConfig *config) 1436 1447 { 1437 1448 PS_ASSERT_PTR_NON_NULL(config, false); 1438 1449 1439 1450 // required 1440 PXOPT_LOOKUP_STR(name, config->args, "-name", true, false); 1441 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", true, false); 1442 PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", true, false); 1451 PXOPT_LOOKUP_STR(name, config->args, "-name", true, false); 1452 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", true, false); 1453 PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", true, false); 1454 1455 // optional 1456 PXOPT_LOOKUP_STR(status_uri, config->args, "-status_uri", false, false); 1457 PXOPT_LOOKUP_STR(comment, config->args, "-comment", false, false); 1458 PXOPT_LOOKUP_STR(last_fileset, config->args, "-last_fileset", false, false); 1459 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1443 1460 1444 1461 // XXX: should we insure that these names do not contatin any whitespace? 1445 1462 1446 rcD SProductRow *row = rcDSProductRowAlloc(1447 0, // prod_id1463 rcDestinationRow *row = rcDestinationRowAlloc( 1464 0, // dest_id 1448 1465 name, 1466 status_uri, 1467 comment, 1468 last_fileset, 1449 1469 dbname, 1450 dbhost 1470 dbhost, 1471 state ? state : "enabled" 1451 1472 ); 1452 1473 1453 1474 if (!row) { 1454 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcD SProductobject");1455 return false; 1456 } 1457 if (!rcD SProductInsertObject(config->dbh, row)) {1475 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDestination object"); 1476 return false; 1477 } 1478 if (!rcDestinationInsertObject(config->dbh, row)) { 1458 1479 psError(PS_ERR_UNKNOWN, false, "database error"); 1459 1480 psFree(row); … … 1462 1483 1463 1484 // get the assigned target_id 1464 row-> prod_id = psDBLastInsertID(config->dbh);1465 1466 if (!rcD SProductPrintObject(stdout, row, true)) {1485 row->dest_id = psDBLastInsertID(config->dbh); 1486 1487 if (!rcDestinationPrintObject(stdout, row, true)) { 1467 1488 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1468 1489 psFree(row); … … 1474 1495 return true; 1475 1496 } 1476 static bool updatedsproductMode(pxConfig *config) 1497 1498 static bool updatedestinationMode(pxConfig *config) 1477 1499 { 1478 1500 PS_ASSERT_PTR_NON_NULL(config, false); 1479 1501 1480 1502 psMetadata *where = psMetadataAlloc(); 1481 PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "=="); 1482 1483 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", false, false); 1484 PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", false, false); 1485 1486 if (!(dbname || dbhost)) { 1487 psError(PS_ERR_UNKNOWN, true, "one or more of dbname or dbhost is required"); 1488 psFree(where); 1489 return false; 1490 } 1491 psString query = psStringCopy("UPDATE rcDSProduct SET"); 1503 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1504 1505 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1506 #ifdef ALLOW_UPDATE_LAST_FILESET 1507 PXOPT_LOOKUP_STR(last_fileset, config->args, "-set_last_fileset", false, false); 1508 if (!(state || last_fileset)) { 1509 psError(PS_ERR_UNKNOWN, true, "one or more of -set_state or -set_last_fileset is required"); 1510 # else 1511 if (!state) { 1512 #endif 1513 psFree(where); 1514 return false; 1515 } 1516 psString query = psStringCopy("UPDATE rcDestination SET"); 1492 1517 psString sep = ""; 1493 if ( dbname) {1494 psStringAppend(&query, " dbname = '%s'", dbname);1518 if (state) { 1519 psStringAppend(&query, " state = '%s'", state); 1495 1520 sep = ","; 1496 1521 } 1497 if (dbhost) { 1498 psStringAppend(&query, " %s dbhost = '%s'", sep, dbhost); 1499 } 1522 #ifdef ALLOW_UPDATE_LAST_FILESET 1523 // last_fileset normally gets set by updatercrunMode 1524 // Allowing it to be set here might cause problems 1525 // especially since we are allowing selection by dest_id 1526 if (last_fileset) { 1527 psStringAppend(&query, " %s last_fileset = '%s'", sep, last_fileset); 1528 } 1529 #endif 1500 1530 1501 1531 if (psListLength(where->list)) { … … 1521 1551 } 1522 1552 1523 static bool define destinationMode(pxConfig *config)1553 static bool defineinterestMode(pxConfig *config) 1524 1554 { 1525 1555 PS_ASSERT_PTR_NON_NULL(config, false); 1526 1556 1527 // required 1528 PXOPT_LOOKUP_S64(prod_id, config->args, "-prod_id", true, false); 1529 PXOPT_LOOKUP_STR(name, config->args, "-name", true, false); 1557 // one of these is required 1558 PXOPT_LOOKUP_S64(dest_id, config->args, "-dest_id", false, false); 1559 PXOPT_LOOKUP_STR(dest_name, config->args, "-dest_name", false, false); 1560 if (!dest_id && !dest_name) { 1561 psError(PS_ERR_UNKNOWN, true, "either dest_id or dest_name is required"); 1562 return false; 1563 } 1564 1565 // either target_id or stage and label are required 1566 PXOPT_LOOKUP_S64(target_id, config->args, "-target_id", false, false); 1567 PXOPT_LOOKUP_STR(stage, config->args, "-stage", false, false); 1568 PXOPT_LOOKUP_STR(dist_group, config->args, "-dist_group", false, false); 1569 PXOPT_LOOKUP_STR(filter, config->args, "-filter", false, false); 1570 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 1571 1572 if (!target_id) { 1573 bool error = false; 1574 if (!stage) { 1575 psError(PS_ERR_UNKNOWN, true, "stage is required if target_id is not supplied"); 1576 error = true; 1577 } 1578 if (!dist_group) { 1579 psError(PS_ERR_UNKNOWN, !error, "dist_group is required if target_id is not supplied"); 1580 error = true; 1581 } 1582 if (error) { 1583 return false; 1584 } 1585 } 1530 1586 1531 1587 // optional 1532 PXOPT_LOOKUP_STR(status_uri, config->args, "-status_uri", false, false); 1533 PXOPT_LOOKUP_STR(comment, config->args, "-comment", false, false); 1534 PXOPT_LOOKUP_STR(last_fileset, config->args, "-last_fileset", false, false); 1535 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1536 1537 // XXX: should we insure that these names do not contatin any whitespace? 1538 1539 rcDestinationRow *row = rcDestinationRowAlloc( 1540 0, // dest_id 1541 prod_id, 1542 name, 1543 status_uri, 1544 comment, 1545 last_fileset, 1546 state ? state : "enabled" 1547 ); 1548 1549 if (!row) { 1550 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDestination object"); 1551 return false; 1552 } 1553 if (!rcDestinationInsertObject(config->dbh, row)) { 1554 psError(PS_ERR_UNKNOWN, false, "database error"); 1555 psFree(row); 1556 return false; 1557 } 1558 1559 // get the assigned target_id 1560 row->dest_id = psDBLastInsertID(config->dbh); 1561 1562 if (!rcDestinationPrintObject(stdout, row, true)) { 1563 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1564 psFree(row); 1565 return false; 1566 } 1567 1568 psFree(row); 1569 1570 return true; 1571 } 1572 1573 static bool updatedestinationMode(pxConfig *config) 1588 PXOPT_LOOKUP_S64(limit, config->args, "-limit", false, false); 1589 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1590 if (state) { 1591 if (strcmp(state, "enabled") && strcmp(state, "disabled")) { 1592 psError(PS_ERR_PROGRAMMING, true, "state must be enabled or disabled"); 1593 return false; 1594 } 1595 } else { 1596 // default state 1597 state = "enabled"; 1598 } 1599 1600 // now that we've done all of our argument checking, copy the values to where 1601 psMetadata *where = psMetadataAlloc(); 1602 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1603 PXOPT_COPY_STR(config->args, where, "-dest_name", "rcDestination.name", "=="); 1604 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1605 PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE"); 1606 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE"); 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 } 1611 1612 psString query = pxDataGet("disttool_defineinterest.sql"); 1613 1614 if (!psListLength(where->list)) { 1615 // can't get here 1616 psError(PS_ERR_PROGRAMMING, true, "search parameters are required"); 1617 psFree(where); 1618 psFree(query); 1619 return false; 1620 } 1621 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1622 psStringAppend(&query, " AND %s", whereClause); 1623 psFree(whereClause); 1624 psFree(where); 1625 if (clean) { 1626 psStringAppend(&query, " AND (distTarget.clean)"); 1627 } else { 1628 psStringAppend(&query, " AND (!distTarget.clean)"); 1629 } 1630 if (limit) { 1631 psString limitString = psDBGenerateLimitSQL(limit); 1632 psStringAppend(&query, " %s", limitString); 1633 psFree(limitString); 1634 } 1635 { 1636 // psStringSubstitute fails unless the input is a psString which it determines by 1637 // comparing the memory blocks free function to an expected value. 1638 // pxDataGet uses psSlurp which leaves a different free function on the memory block. 1639 // To work around this make a copy of the query before doing the substitution. 1640 psString queryCopy = psStringCopy(query); 1641 psFree(query); 1642 query = queryCopy; 1643 } 1644 // change the @STATE@ in the sql file to our state 1645 if (!psStringSubstitute(&query, state, "@STATE@")) { 1646 psError(PS_ERR_UNKNOWN, false, "failed to substitute state string"); 1647 return false; 1648 } 1649 1650 if (!p_psDBRunQuery(config->dbh, query)) { 1651 psError(PS_ERR_UNKNOWN, false, "database error"); 1652 psFree(query); 1653 return false; 1654 } 1655 psFree(query); 1656 int numInserted = psDBAffectedRows(config->dbh); 1657 printf("inserted %d rows into rcInterest\n", numInserted); 1658 1659 return true; 1660 } 1661 1662 static bool updateinterestMode(pxConfig *config) 1574 1663 { 1575 1664 PS_ASSERT_PTR_NON_NULL(config, false); 1576 1665 1577 1666 psMetadata *where = psMetadataAlloc(); 1578 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1579 PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "=="); 1667 PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "=="); 1668 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 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 1580 1683 1581 1684 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1582 #ifdef ALLOW_UPDATE_LAST_FILESET1583 PXOPT_LOOKUP_STR(last_fileset, config->args, "-set_last_fileset", false, false);1584 if (!(state || last_fileset)) {1585 psError(PS_ERR_UNKNOWN, true, "one or more of -set_state or -set_last_fileset is required");1586 # else1587 1685 if (!state) { 1588 #endif 1589 psFree(where); 1590 return false; 1591 } 1592 psString query = psStringCopy("UPDATE rcDestination SET"); 1593 psString sep = ""; 1594 if (state) { 1595 psStringAppend(&query, " state = '%s'", state); 1596 sep = ","; 1597 } 1598 #ifdef ALLOW_UPDATE_LAST_FILESET 1599 // last_fileset normally gets set by updatercrunMode 1600 // Allowing it to be set here might cause problems 1601 // especially since we are allowing selection by prod_id 1602 if (last_fileset) { 1603 psStringAppend(&query, " %s last_fileset = '%s'", sep, last_fileset); 1604 } 1605 #endif 1686 psError(PS_ERR_UNKNOWN, true, "-set_state is required"); 1687 psFree(where); 1688 return false; 1689 } 1690 psString query = pxDataGet("disttool_updateinterest.sql"); 1606 1691 1607 1692 if (psListLength(where->list)) { … … 1617 1702 psFree(where); 1618 1703 1619 if (!p_psDBRunQuery(config->dbh, query)) { 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)) { 1620 1711 psError(PS_ERR_UNKNOWN, false, "database error"); 1621 1712 psFree(query); … … 1624 1715 psFree(query); 1625 1716 1626 return true; 1627 } 1628 1629 static bool defineinterestMode(pxConfig *config) 1717 psS64 numUpdated = psDBAffectedRows(config->dbh); 1718 printf("updated %" PRId64 " interests\n", numUpdated); 1719 1720 return true; 1721 } 1722 static bool listinterestsMode(pxConfig *config) 1630 1723 { 1631 1724 PS_ASSERT_PTR_NON_NULL(config, false); 1632 1725 1633 // required 1634 PXOPT_LOOKUP_S64(dest_id, config->args, "-dest_id", true, false); 1635 PXOPT_LOOKUP_S64(target_id, config->args, "-target_id", true, false); 1636 1637 // optional 1638 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1639 1640 // XXX: should we insure that these names do not contatin any whitespace? 1641 1642 rcInterestRow *row = rcInterestRowAlloc( 1643 0, // int_id 1644 dest_id, 1645 target_id, 1646 state ? state : "enabled" 1647 ); 1648 1649 if (!row) { 1650 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcInterest object"); 1651 return false; 1652 } 1653 if (!rcInterestInsertObject(config->dbh, row)) { 1654 psError(PS_ERR_UNKNOWN, false, "database error"); 1655 psFree(row); 1656 return false; 1657 } 1658 1659 // get the assigned target_id 1660 row->int_id = psDBLastInsertID(config->dbh); 1661 1662 if (!rcInterestPrintObject(stdout, row, true)) { 1663 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1664 psFree(row); 1665 return false; 1666 } 1667 1668 psFree(row); 1669 1670 return true; 1671 } 1672 1673 static bool updateinterestMode(pxConfig *config) 1674 { 1675 PS_ASSERT_PTR_NON_NULL(config, false); 1676 1677 psMetadata *where = psMetadataAlloc(); 1678 PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "=="); 1679 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 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", "=="); 1680 1730 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1681 1682 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1683 if (!state) { 1684 psError(PS_ERR_UNKNOWN, true, "-set_state is required"); 1685 psFree(where); 1686 return false; 1687 } 1688 psString query = NULL; 1689 psStringAppend(&query, "UPDATE rcInterest SET state = '%s'", state); 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"); 1690 1748 1691 1749 if (psListLength(where->list)) { … … 1693 1751 psStringAppend(&query, " WHERE %s", whereClause); 1694 1752 psFree(whereClause); 1695 } else { 1696 psError(PS_ERR_UNKNOWN, true, "search parameters are required"); 1697 psFree(where); 1698 psFree(query); 1699 return false; 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"); 1700 1762 } 1701 1763 psFree(where); 1702 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 1703 1772 if (!p_psDBRunQuery(config->dbh, query)) { 1704 1773 psError(PS_ERR_UNKNOWN, false, "database error"); 1705 1774 psFree(query); 1775 if (!psDBRollback(config->dbh)) { 1776 psError(PS_ERR_UNKNOWN, false, "database error"); 1777 } 1706 1778 return false; 1707 1779 } 1708 1780 psFree(query); 1709 1781 1710 return true; 1711 } 1712 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) 1804 { 1805 PS_ASSERT_PTR_NON_NULL(config, false); 1806 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", "=="); 1873 PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "=="); 1874 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1875 PXOPT_COPY_STR(config->args, where, "-dest_name", "name", "=="); 1876 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1877 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 1878 PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE"); 1879 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE"); 1880 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 1881 1882 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 1883 PXOPT_LOOKUP_BOOL(full, config->args, "-full", false); 1884 1885 pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "=="); 1886 1887 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1888 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1889 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); 1901 psFree(where); 1902 1903 // treat limit == 0 as "no limit" 1904 if (limit) { 1905 psString limitString = psDBGenerateLimitSQL(limit); 1906 psStringAppend(&query, " %s", limitString); 1907 psFree(limitString); 1908 } 1909 1910 if (!p_psDBRunQuery(config->dbh, query)) { 1911 psError(PS_ERR_UNKNOWN, false, "database error"); 1912 psFree(query); 1913 if (!psDBRollback(config->dbh)) { 1914 psError(PS_ERR_UNKNOWN, false, "database error"); 1915 } 1916 return false; 1917 } 1918 psFree(query); 1919 1920 psArray *output = p_psDBFetchResult(config->dbh); 1921 if (!output) { 1922 psError(PS_ERR_UNKNOWN, false, "database error"); 1923 return false; 1924 } 1925 if (!psArrayLength(output)) { 1926 psTrace("disttool", PS_LOG_INFO, "no rows found"); 1927 psFree(output); 1928 return true; 1929 } 1930 1931 if (!ippdbPrintMetadatas(stdout, output, "distFilesets", !simple)) { 1932 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1933 psFree(output); 1934 return false; 1935 } 1936 1937 psFree(output); 1938 1939 return true; 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.
