Changeset 27839 for branches/simmosaic_branches/ippTools/src/disttool.c
- Timestamp:
- May 3, 2010, 8:45:22 AM (16 years ago)
- Location:
- branches/simmosaic_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/disttool.c (modified) (67 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simmosaic_branches
- Property svn:mergeinfo changed
-
branches/simmosaic_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/simmosaic_branches/ippTools/src/disttool.c
r24731 r27839 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); 385 386 if (set_label == NULL) { 387 set_label = target_label; 388 } 394 psStringAppend(&outroot, "%s/%s/%s", workdir, run_tag, stage); 395 396 psString new_label; 397 if (set_label != NULL) { 398 new_label = set_label; 399 } else { 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 389 409 distRunRow *row = distRunRowAlloc( 390 410 0, // dist_id … … 392 412 stage, 393 413 stage_id, 394 set_label, 414 magic_ds_id, 415 new_label, 395 416 outroot, 417 NULL, // outdir 396 418 clean, 397 419 no_magic, 420 use_alternate, 398 421 "new", 399 NULL, // time_stamp 400 0 // fault 422 NULL, // time_stamp 423 0, // fault 424 new_data_group, 425 set_note // note does not propagate 401 426 ); 402 427 … … 441 466 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 442 467 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");; 443 PXOPT_COPY_STR(config->args, where, "-state", " state", "==");468 PXOPT_COPY_STR(config->args, where, "-state", "distRun.state", "=="); 444 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", "=="); 445 473 446 474 if (!psListLength(where->list)) { 447 475 psFree(where); 448 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");476 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 449 477 return false; 450 478 } … … 452 480 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 453 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); 454 484 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 455 456 if ((!state) && (!label) && (!fault)) { 457 psError(PXTOOLS_ERR_DATA, false, "parameters (-fault or -set_state or -set_label) are required"); 458 psFree(where); 459 return false; 460 } 461 462 psString query = psStringCopy("UPDATE distRun SET time_stamp = UTC_TIMESTAMP()"); 463 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 } 464 498 if (state) { 465 psStringAppend(&query, " , state = '%s'", state);499 psStringAppend(&query, " , distRun.state = '%s'", state); 466 500 } 467 501 468 502 if (label) { 469 psStringAppend(&query, " , label = '%s'", label);503 psStringAppend(&query, " , distRun.label = '%s'", label); 470 504 } 471 505 472 506 if (fault) { 473 psStringAppend(&query, " , fault = %d", fault); 474 } 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 475 518 476 519 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); … … 497 540 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 498 541 499 // we need to disambiguate fault so make a copy of the where list before adding fault500 psMetadata *whereComponent = psMetadataCopy(NULL, where);501 542 PXOPT_COPY_S16(config->args, where, "-fault", "distRun.fault", "=="); 502 PXOPT_COPY_S16(config->args, whereComponent, "-fault", "distComponent.fault", "==");503 543 504 544 // It might be useful to be able to query by the parameters of the underlying runs … … 506 546 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 507 547 psFree(where); 508 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 509 return false; 510 } 511 512 if (!psDBTransaction(config->dbh)) { 513 psError(PS_ERR_UNKNOWN, false, "database error"); 514 psFree(where); 515 return false; 516 } 517 518 // Update state to 'new' 519 int numUpdated; // Number updated 520 { 521 psString query = pxDataGet("disttool_revertrun_update.sql"); 522 if (!query) { 523 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 524 if (!psDBRollback(config->dbh)) { 525 psError(PS_ERR_UNKNOWN, false, "database error"); 526 } 527 return false; 528 } 529 530 if (psListLength(where->list)) { 531 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 532 psStringAppend(&query, " AND %s", whereClause); 533 psFree(whereClause); 534 } 535 536 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)) { 537 556 psError(PS_ERR_UNKNOWN, false, "database error"); 538 psFree(query); 539 if (!psDBRollback(config->dbh)) { 540 psError(PS_ERR_UNKNOWN, false, "database error"); 541 } 542 return false; 543 } 544 psFree(query); 545 546 numUpdated = psDBAffectedRows(config->dbh); 547 } 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); 548 575 549 576 psLogMsg("disttool", PS_LOG_INFO, "Updated %d dist runs", numUpdated); 550 577 551 // Delete product 552 int numDeleted; // Number deleted 553 { 554 psString query = pxDataGet("disttool_revertrun_delete.sql"); 555 if (!query) { 556 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 557 if (!psDBRollback(config->dbh)) { 558 psError(PS_ERR_UNKNOWN, false, "database error"); 559 } 560 return false; 561 } 562 563 if (psListLength(whereComponent->list)) { 564 psString whereClause = psDBGenerateWhereConditionSQL(whereComponent, NULL); 565 psStringAppend(&query, " AND %s", whereClause); 566 psFree(whereClause); 567 } 568 569 if (!p_psDBRunQuery(config->dbh, query)) { 570 psError(PS_ERR_UNKNOWN, false, "database error"); 571 psFree(query); 572 if (!psDBRollback(config->dbh)) { 573 psError(PS_ERR_UNKNOWN, false, "database error"); 574 } 575 return false; 576 } 577 psFree(query); 578 579 numDeleted = psDBAffectedRows(config->dbh); 580 } 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); 581 622 582 623 psLogMsg("disttool", PS_LOG_INFO, "Deleted %d distComponents", numDeleted); 583 624 584 psFree(where);585 psFree(whereComponent);586 587 if (!psDBCommit(config->dbh)) {588 psError(PS_ERR_UNKNOWN, false, "database error");589 return false;590 }591 592 625 return true; 593 626 } … … 597 630 PS_ASSERT_PTR_NON_NULL(config, false); 598 631 599 psMetadata *where = psMetadataAlloc(); 600 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 601 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 602 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", "=="); 603 637 604 638 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 605 639 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 606 640 607 // look for "inputs" that need to processed 608 psString query = pxDataGet("disttool_pendingcomponent.sql"); 641 psString queryFile = NULL; 642 psStringAppend(&queryFile, "disttool_pending_%s.sql", stage); 643 psString query = pxDataGet(queryFile); 609 644 if (!query) { 610 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");645 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement from %s", queryFile); 611 646 return false; 612 647 } … … 614 649 if (psListLength(where->list)) { 615 650 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 616 psStringAppend(&query, " WHERE%s", whereClause);651 psStringAppend(&query, " AND %s", whereClause); 617 652 psFree(whereClause); 618 653 } … … 626 661 } 627 662 628 // the query has where hooks for each stage. 629 // right now we aren't using them. 630 // XXX: I think that I want to change the query from a union of selects on the various 631 // stages to separate queries. As it is pending data at the later stages of the pipline 632 // will get blocked by pending earlier stages 633 psString raw_where = ""; 634 psString raw_clean_where = ""; 635 psString chip_where = ""; 636 psString camera_where = ""; 637 psString fake_where = ""; 638 psString warp_where = ""; 639 psString diff_where = ""; 640 psString stack_where = ""; 641 642 if (!p_psDBRunQueryF(config->dbh, 643 query, 644 raw_where, 645 raw_clean_where, 646 chip_where, 647 camera_where, 648 fake_where, 649 warp_where, 650 diff_where, 651 stack_where)) { 663 if (!p_psDBRunQuery(config->dbh, query)) { 652 664 psError(PS_ERR_UNKNOWN, false, "database error"); 653 665 psFree(query); … … 705 717 PXOPT_LOOKUP_S32(bytes, config->args, "-bytes", require_fileinfo, false); 706 718 PXOPT_LOOKUP_STR(md5sum, config->args, "-md5sum", require_fileinfo, false); 719 PXOPT_LOOKUP_STR(outdir, config->args, "-outdir", require_fileinfo, false); 707 720 PXOPT_LOOKUP_STR(name, config->args, "-name", require_fileinfo, false); 708 721 709 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)) { 710 723 psError(PS_ERR_UNKNOWN, false, "database error"); 711 724 return false; … … 729 742 psString query = pxDataGet("disttool_toadvance.sql"); 730 743 if (!query) { 731 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");744 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 732 745 return false; 733 746 } … … 800 813 psString query = pxDataGet("disttool_processedcomponent.sql"); 801 814 if (!query) { 802 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");815 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 803 816 return false; 804 817 } … … 865 878 psMetadata *where = psMetadataAlloc(); 866 879 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 880 PXOPT_COPY_STR(config->args, where, "-stage", "distRun.stage", "=="); 867 881 pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "=="); 868 882 … … 873 887 psString query = pxDataGet("disttool_pendingfileset.sql"); 874 888 if (!query) { 875 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");889 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 876 890 return false; 877 891 } … … 936 950 // required values 937 951 PXOPT_LOOKUP_S64(dist_id, config->args, "-dist_id", true, false); 938 PXOPT_LOOKUP_S64( prod_id, config->args, "-prod_id", true, false);952 PXOPT_LOOKUP_S64(dest_id, config->args, "-dest_id", true, false); 939 953 940 954 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); … … 943 957 PXOPT_LOOKUP_STR(name, config->args, "-name", fault == 0, false); 944 958 945 if (!rcDSFilesetInsert(config->dbh, 959 if (!rcDSFilesetInsert(config->dbh, 946 960 0, // fs_id 947 961 dist_id, 948 prod_id,962 dest_id, 949 963 name, 950 964 "full", … … 956 970 return true; 957 971 } 972 958 973 static bool revertfilesetMode(pxConfig *config) 959 974 { … … 961 976 PXOPT_COPY_S64(config->args, where, "-fs_id", "fs_id", "=="); 962 977 PXOPT_COPY_S64(config->args, where, "-dist_id", "rcDSFileset.dist_id", "=="); 963 PXOPT_COPY_S64(config->args, where, "- prod_id", "prod_id", "==");978 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 964 979 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");; 965 980 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); … … 972 987 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 973 988 psFree(where); 974 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");989 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 975 990 return false; 976 991 } … … 978 993 psString query = pxDataGet("disttool_revertfileset.sql"); 979 994 if (!query) { 980 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");995 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 981 996 psFree(where); 982 997 return false; … … 1020 1035 psString query = pxDataGet("disttool_pendingdest.sql"); 1021 1036 if (!query) { 1022 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1037 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1023 1038 return false; 1024 1039 } … … 1089 1104 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 1090 1105 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1091 PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "==");1092 1106 PXOPT_COPY_S64(config->args, where, "-target_id","target_id", "=="); 1093 1107 PXOPT_COPY_S64(config->args, where, "-fs_id", "fs_id", "=="); … … 1100 1114 psString query = pxDataGet("disttool_queuercrun.sql"); 1101 1115 if (!query) { 1102 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1116 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1103 1117 return false; 1104 1118 } … … 1146 1160 // We either need rc_id or (dest_id and fs_name) to identifiy the rcRun 1147 1161 if ((!rc_id) && !(dest_id && fs_name)) { 1148 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"); 1149 1163 return false; 1150 1164 } … … 1158 1172 // this can't happen because we checked above 1159 1173 psFree(where); 1160 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");1174 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1161 1175 return false; 1162 1176 } … … 1168 1182 1169 1183 if (!state && (fault < 0)) { 1170 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"); 1171 1185 psFree(where); 1172 1186 return false; … … 1175 1189 psString query = pxDataGet("disttool_updatercrun.sql"); 1176 1190 if (!query) { 1177 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1191 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1178 1192 return false; 1179 1193 } … … 1232 1246 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 1233 1247 psFree(where); 1234 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");1248 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1235 1249 return false; 1236 1250 } … … 1238 1252 psString query = pxDataGet("disttool_revertrcrun.sql"); 1239 1253 if (!query) { 1240 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1254 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1241 1255 if (!psDBRollback(config->dbh)) { 1242 1256 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1273 1287 1274 1288 // required 1275 PXOPT_LOOKUP_STR( label, config->args, "-label", true, false);1289 PXOPT_LOOKUP_STR(dist_group, config->args, "-dist_group", true, false); 1276 1290 PXOPT_LOOKUP_STR(filter, config->args, "-filter", true, false); 1277 1291 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); … … 1284 1298 distTargetRow *row = distTargetRowAlloc( 1285 1299 0, // target_id 1286 label,1300 dist_group, 1287 1301 filter, 1288 1302 stage, … … 1291 1305 comment 1292 1306 ); 1293 1307 1294 1308 if (!row) { 1295 1309 psError(PS_ERR_UNKNOWN, false, "failed to allocate distTarget object"); … … 1321 1335 psMetadata *where = psMetadataAlloc(); 1322 1336 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1323 PXOPT_COPY_STR(config->args, where, "- label", "label", "==");1337 PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "=="); 1324 1338 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "=="); 1325 1339 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); … … 1351 1365 } 1352 1366 1353 static bool listtarget Mode(pxConfig *config)1367 static bool listtargetsMode(pxConfig *config) 1354 1368 { 1355 1369 PS_ASSERT_PTR_NON_NULL(config, false); … … 1357 1371 psMetadata *where = psMetadataAlloc(); 1358 1372 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1359 PXOPT_COPY_STR(config->args, where, "- label", "label", "==");1373 PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE"); 1360 1374 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "=="); 1361 1375 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); … … 1430 1444 } 1431 1445 1432 static bool defined sproductMode(pxConfig *config)1446 static bool definedestinationMode(pxConfig *config) 1433 1447 { 1434 1448 PS_ASSERT_PTR_NON_NULL(config, false); 1435 1449 1436 1450 // required 1437 PXOPT_LOOKUP_STR(name, config->args, "-name", true, false); 1438 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", true, false); 1439 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); 1440 1460 1441 1461 // XXX: should we insure that these names do not contatin any whitespace? 1442 1462 1443 rcD SProductRow *row = rcDSProductRowAlloc(1444 0, // prod_id1463 rcDestinationRow *row = rcDestinationRowAlloc( 1464 0, // dest_id 1445 1465 name, 1466 status_uri, 1467 comment, 1468 last_fileset, 1446 1469 dbname, 1447 dbhost 1470 dbhost, 1471 state ? state : "enabled" 1448 1472 ); 1449 1473 1450 1474 if (!row) { 1451 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcD SProductobject");1452 return false; 1453 } 1454 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)) { 1455 1479 psError(PS_ERR_UNKNOWN, false, "database error"); 1456 1480 psFree(row); … … 1459 1483 1460 1484 // get the assigned target_id 1461 row-> prod_id = psDBLastInsertID(config->dbh);1462 1463 if (!rcD SProductPrintObject(stdout, row, true)) {1485 row->dest_id = psDBLastInsertID(config->dbh); 1486 1487 if (!rcDestinationPrintObject(stdout, row, true)) { 1464 1488 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1465 1489 psFree(row); … … 1471 1495 return true; 1472 1496 } 1473 static bool updatedsproductMode(pxConfig *config) 1497 1498 static bool updatedestinationMode(pxConfig *config) 1474 1499 { 1475 1500 PS_ASSERT_PTR_NON_NULL(config, false); 1476 1501 1477 1502 psMetadata *where = psMetadataAlloc(); 1478 PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "=="); 1479 1480 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", false, false); 1481 PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", false, false); 1482 1483 if (!(dbname || dbhost)) { 1484 psError(PS_ERR_UNKNOWN, true, "one or more of dbname or dbhost is required"); 1485 psFree(where); 1486 return false; 1487 } 1488 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"); 1489 1517 psString sep = ""; 1490 if ( dbname) {1491 psStringAppend(&query, " dbname = '%s'", dbname);1518 if (state) { 1519 psStringAppend(&query, " state = '%s'", state); 1492 1520 sep = ","; 1493 1521 } 1494 if (dbhost) { 1495 psStringAppend(&query, " %s dbhost = '%s'", sep, dbhost); 1496 } 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 1497 1530 1498 1531 if (psListLength(where->list)) { … … 1518 1551 } 1519 1552 1520 static bool define destinationMode(pxConfig *config)1553 static bool defineinterestMode(pxConfig *config) 1521 1554 { 1522 1555 PS_ASSERT_PTR_NON_NULL(config, false); 1523 1556 1524 // required 1525 PXOPT_LOOKUP_S64(prod_id, config->args, "-prod_id", true, false); 1526 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 } 1527 1586 1528 1587 // optional 1529 PXOPT_LOOKUP_STR(status_uri, config->args, "-status_uri", false, false); 1530 PXOPT_LOOKUP_STR(comment, config->args, "-comment", false, false); 1531 PXOPT_LOOKUP_STR(last_fileset, config->args, "-last_fileset", false, false); 1532 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1533 1534 // XXX: should we insure that these names do not contatin any whitespace? 1535 1536 rcDestinationRow *row = rcDestinationRowAlloc( 1537 0, // dest_id 1538 prod_id, 1539 name, 1540 status_uri, 1541 comment, 1542 last_fileset, 1543 state ? state : "enabled" 1544 ); 1545 1546 if (!row) { 1547 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDestination object"); 1548 return false; 1549 } 1550 if (!rcDestinationInsertObject(config->dbh, row)) { 1551 psError(PS_ERR_UNKNOWN, false, "database error"); 1552 psFree(row); 1553 return false; 1554 } 1555 1556 // get the assigned target_id 1557 row->dest_id = psDBLastInsertID(config->dbh); 1558 1559 if (!rcDestinationPrintObject(stdout, row, true)) { 1560 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1561 psFree(row); 1562 return false; 1563 } 1564 1565 psFree(row); 1566 1567 return true; 1568 } 1569 1570 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) 1571 1663 { 1572 1664 PS_ASSERT_PTR_NON_NULL(config, false); 1573 1665 1574 1666 psMetadata *where = psMetadataAlloc(); 1575 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1576 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 1577 1683 1578 1684 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1579 #ifdef ALLOW_UPDATE_LAST_FILESET1580 PXOPT_LOOKUP_STR(last_fileset, config->args, "-set_last_fileset", false, false);1581 if (!(state || last_fileset)) {1582 psError(PS_ERR_UNKNOWN, true, "one or more of -set_state or -set_last_fileset is required");1583 # else1584 1685 if (!state) { 1585 #endif 1586 psFree(where); 1587 return false; 1588 } 1589 psString query = psStringCopy("UPDATE rcDestination SET"); 1590 psString sep = ""; 1591 if (state) { 1592 psStringAppend(&query, " state = '%s'", state); 1593 sep = ","; 1594 } 1595 #ifdef ALLOW_UPDATE_LAST_FILESET 1596 // last_fileset normally gets set by updatercrunMode 1597 // Allowing it to be set here might cause problems 1598 // especially since we are allowing selection by prod_id 1599 if (last_fileset) { 1600 psStringAppend(&query, " %s last_fileset = '%s'", sep, last_fileset); 1601 } 1602 #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"); 1603 1691 1604 1692 if (psListLength(where->list)) { … … 1614 1702 psFree(where); 1615 1703 1616 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)) { 1617 1711 psError(PS_ERR_UNKNOWN, false, "database error"); 1618 1712 psFree(query); … … 1621 1715 psFree(query); 1622 1716 1623 return true; 1624 } 1625 1626 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) 1627 1723 { 1628 1724 PS_ASSERT_PTR_NON_NULL(config, false); 1629 1725 1630 // required 1631 PXOPT_LOOKUP_S64(dest_id, config->args, "-dest_id", true, false); 1632 PXOPT_LOOKUP_S64(target_id, config->args, "-target_id", true, false); 1633 1634 // optional 1635 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1636 1637 // XXX: should we insure that these names do not contatin any whitespace? 1638 1639 rcInterestRow *row = rcInterestRowAlloc( 1640 0, // int_id 1641 dest_id, 1642 target_id, 1643 state ? state : "enabled" 1644 ); 1645 1646 if (!row) { 1647 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcInterest object"); 1648 return false; 1649 } 1650 if (!rcInterestInsertObject(config->dbh, row)) { 1651 psError(PS_ERR_UNKNOWN, false, "database error"); 1652 psFree(row); 1653 return false; 1654 } 1655 1656 // get the assigned target_id 1657 row->int_id = psDBLastInsertID(config->dbh); 1658 1659 if (!rcInterestPrintObject(stdout, row, true)) { 1660 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1661 psFree(row); 1662 return false; 1663 } 1664 1665 psFree(row); 1666 1667 return true; 1668 } 1669 1670 static bool updateinterestMode(pxConfig *config) 1671 { 1672 PS_ASSERT_PTR_NON_NULL(config, false); 1673 1674 psMetadata *where = psMetadataAlloc(); 1675 PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "=="); 1676 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", "=="); 1677 1730 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1678 1679 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1680 if (!state) { 1681 psError(PS_ERR_UNKNOWN, true, "-set_state is required"); 1682 psFree(where); 1683 return false; 1684 } 1685 psString query = NULL; 1686 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"); 1687 1748 1688 1749 if (psListLength(where->list)) { … … 1690 1751 psStringAppend(&query, " WHERE %s", whereClause); 1691 1752 psFree(whereClause); 1692 } else { 1693 psError(PS_ERR_UNKNOWN, true, "search parameters are required"); 1694 psFree(where); 1695 psFree(query); 1696 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"); 1697 1762 } 1698 1763 psFree(where); 1699 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 1700 1772 if (!p_psDBRunQuery(config->dbh, query)) { 1701 1773 psError(PS_ERR_UNKNOWN, false, "database error"); 1702 1774 psFree(query); 1775 if (!psDBRollback(config->dbh)) { 1776 psError(PS_ERR_UNKNOWN, false, "database error"); 1777 } 1703 1778 return false; 1704 1779 } 1705 1780 psFree(query); 1706 1781 1707 return true; 1708 } 1709 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.
