- Timestamp:
- Sep 15, 2009, 3:58:41 PM (17 years ago)
- Location:
- branches/eam_branches/20090715/ippTools/src
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamptool.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090715/ippTools/src
- Property svn:ignore
-
old new 34 34 disttool 35 35 receivetool 36 36 addtool 37 37 pubtool
-
- Property svn:ignore
-
branches/eam_branches/20090715/ippTools/src/pstamptool.c
r25022 r25400 44 44 static bool pendingjobMode(pxConfig *config); 45 45 static bool updatejobMode(pxConfig *config); 46 static bool revertjobMode(pxConfig *config); 46 47 static bool addprojectMode(pxConfig *config); 47 48 static bool projectMode(pxConfig *config); … … 80 81 MODECASE(PSTAMPTOOL_MODE_PENDINGJOB, pendingjobMode); 81 82 MODECASE(PSTAMPTOOL_MODE_UPDATEJOB, updatejobMode); 83 MODECASE(PSTAMPTOOL_MODE_REVERTJOB, revertjobMode); 82 84 MODECASE(PSTAMPTOOL_MODE_ADDPROJECT, addprojectMode); 83 85 MODECASE(PSTAMPTOOL_MODE_MODPROJECT, modprojectMode); … … 224 226 PS_ASSERT_PTR_NON_NULL(config, false); 225 227 226 PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false); 227 // PXOPT_LOOKUP_STR(outFileset, config->args, "-out_fileset", true, false); 228 PXOPT_LOOKUP_S64(ds_id, config->args, "-ds_id", false, false); 229 230 char *query ="INSERT INTO pstampRequest" 231 " (state, uri, ds_id, fault)" 232 " VALUES( 'new', '%s', %" PRId64 ", 0 )"; 233 if (!p_psDBRunQueryF(config->dbh, query, uri, ds_id)) { 234 psError(PS_ERR_UNKNOWN, false, "database error"); 235 return false; 236 } 237 238 psU64 affected = psDBAffectedRows(config->dbh); 239 if (affected != 1) { 240 psError(PS_ERR_UNKNOWN, false, 241 "should have affected one row but %" PRIu64 " rows were modified", 242 affected); 228 PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false); 229 PXOPT_LOOKUP_STR(name, config->args, "-name", false, false); 230 PXOPT_LOOKUP_S64(ds_id, config->args, "-ds_id", false, false); 231 232 if (!pstampRequestInsert(config->dbh, 233 0, // req_id 234 ds_id, 235 "new", //state 236 name, 237 NULL, // reqType 238 NULL, // outProduct 239 uri, 240 0 // fault 241 )) { 242 psError(PS_ERR_UNKNOWN, false, "failed to insert request"); 243 243 return false; 244 244 } … … 315 315 PS_ASSERT_PTR_NON_NULL(config, false); 316 316 317 PXOPT_LOOKUP_S64(req_id, config->args, "-req_id", true, false); 317 psMetadata *where = psMetadataAlloc(); 318 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 319 PXOPT_COPY_S64(config->args, where, "-not_req_id", "req_id", "!="); 320 PXOPT_COPY_STR(config->args, where, "-name", "name", "=="); 321 318 322 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 319 323 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 320 324 321 psString query = NULL; 322 psStringAppend(&query, "SELECT * from pstampRequest WHERE req_id = %" PRId64, req_id); 325 if (!psListLength(where->list)) { 326 psError(PS_ERR_UNKNOWN, true, "-req_id or -name must be supplied"); 327 return false; 328 } 329 330 psString query = psStringCopy("SELECT * from pstampRequest"); 331 332 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 333 psStringAppend(&query, " WHERE %s", whereClause); 334 psFree(whereClause); 335 psFree(where); 323 336 324 337 // treat limit == 0 as "no limit" … … 342 355 } 343 356 if (!psArrayLength(output)) { 344 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 345 psFree(output); 346 return true; 357 psTrace("pstamptool", PS_LOG_INFO, "request not found"); 358 // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for 359 psError(PXTOOLS_ERR_DATA, true, "request not found"); 360 psFree(output); 361 // we return false so that the caller can determine that a request does not exist 362 return false; 347 363 } 348 364 … … 366 382 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 367 383 368 psString query = 369 "SELECT * FROM pstampRequest WHERE state = 'run' AND " 370 "(SELECT count(*) FROM pstampJob WHERE pstampJob.req_id = pstampRequest.req_id " 371 " AND pstampJob.state != 'stop') = 0" ; 384 psString query = pxDataGet("pstamptool_completedreq.sql"); 372 385 373 386 // treat limit == 0 as "no limit" … … 476 489 PS_ASSERT_PTR_NON_NULL(config, false); 477 490 478 PXOPT_LOOKUP_S64(req_id, config->args, "-req_id", true, false); 479 480 // printf("Revert request %" PRId64 "\n", req_id); 491 psMetadata *where = psMetadataAlloc(); 492 493 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 494 PXOPT_COPY_S64(config->args, where, "-fault", "req_id", "=="); 495 PXOPT_COPY_STR(config->args, where, "-state", "pstampRequest.state", "=="); 496 497 if (!psListLength(where->list)) { 498 psFree(where); 499 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 500 return false; 501 } 502 503 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 504 psFree(where); 505 506 // delete any jobs that were queued by requests that didn't complete parsing (pstampRequest.state = 'new' 507 // If state = 'run' was supplied this will be a no-op 508 psString query = pxDataGet("pstamptool_revertreq_deletejobs.sql"); 509 psStringAppend(&query, " AND %s", whereClause); 510 if (!p_psDBRunQuery(config->dbh, query)) { 511 psError(PS_ERR_UNKNOWN, false, "database error"); 512 return false; 513 } 514 psFree(query); 515 516 // clear fault for requests 517 query = pxDataGet("pstamptool_revertreq.sql"); 518 psStringAppend(&query, " AND %s", whereClause); 481 519 482 if (!p_psDBRunQueryF(config->dbh, "DELETE FROM pstampJob where req_id = %" PRId64, req_id)) { 483 psError(PS_ERR_UNKNOWN, false, "database error"); 484 return false; 485 } 486 if (!p_psDBRunQueryF(config->dbh, 487 "UPDATE pstampRequest set state ='new', name=NULL, reqType=NULL, fault=0 where req_id = %" PRId64, req_id)) { 488 psError(PS_ERR_UNKNOWN, false, "database error"); 489 return false; 490 } 520 psFree(whereClause); 521 522 if (!p_psDBRunQuery(config->dbh, query)) { 523 psError(PS_ERR_UNKNOWN, false, "database error"); 524 return false; 525 } 526 psFree(query); 491 527 492 528 return true; … … 496 532 { 497 533 bool stampJob = false; 498 char *query = NULL;499 534 500 535 PS_ASSERT_PTR_NON_NULL(config, false); … … 503 538 PXOPT_LOOKUP_STR(rownum, config->args, "-rownum", true, false); 504 539 PXOPT_LOOKUP_STR(job_type, config->args, "-job_type", false, false); 505 PXOPT_LOOKUP_STR(outputBase, config->args, "-outputBase", true, false);540 PXOPT_LOOKUP_STR(outputBase, config->args, "-outputBase", false, false); 506 541 PXOPT_LOOKUP_STR(stateString, config->args, "-state", false, false); 507 PXOPT_LOOKUP_S TR(fault, config->args, "-fault", false, false);542 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 508 543 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false); 509 544 545 // unless the job is being inserted with stop state require outputBase 546 if (strcmp(stateString, "stop") && !outputBase) { 547 psError(PS_ERR_UNKNOWN, true, "-outputBase is required"); 548 return false; 549 } 550 510 551 // default value for job_type is defined in pstamptoolConfig.c 511 if (!strcmp(job_type, "get_image") || !strcmp(job_type, "detect_query") ) {552 if (!strcmp(job_type, "get_image") || !strcmp(job_type, "detect_query") || !strcmp(job_type, "none")) { 512 553 stampJob = false; 513 554 } else if (!strcmp(job_type, "stamp")) { … … 517 558 return false; 518 559 } 519 if (stampJob) { 520 query = pxDataGet("pstamptool_addjob_stampjob.sql"); 521 } else { 522 query = pxDataGet("pstamptool_addjob_otherjob.sql"); 523 } 524 if (!query) { 525 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 526 return false; 527 } 528 529 if (!p_psDBRunQueryF(config->dbh, query, req_id, rownum, stateString, job_type, exp_id, outputBase, fault)) { 560 if (!pstampJobInsert(config->dbh, 561 0, // job_id 562 req_id, 563 rownum, 564 stateString, 565 job_type, 566 fault, 567 exp_id, 568 outputBase 569 )) { 530 570 psError(PS_ERR_UNKNOWN, false, "database error"); 531 571 return false; … … 715 755 return true; 716 756 } 757 758 static bool revertjobMode(pxConfig *config) 759 { 760 PS_ASSERT_PTR_NON_NULL(config, false); 761 762 psMetadata *where = psMetadataAlloc(); 763 764 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 765 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 766 PXOPT_COPY_S64(config->args, where, "-fault", "fault", "=="); 767 768 if (!psListLength(where->list)) { 769 psFree(where); 770 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 771 return false; 772 } 773 774 psString query = pxDataGet("pstamptool_revertjob.sql"); 775 psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampJob"); 776 psStringAppend(&query, " AND %s", whereClause); 777 psFree(whereClause); 778 psFree(where); 779 780 if (!p_psDBRunQuery(config->dbh, query)) { 781 psError(PS_ERR_UNKNOWN, false, "database error"); 782 return false; 783 } 784 785 return true; 786 } 717 787 static bool addprojectMode(pxConfig *config) 718 788 {
Note:
See TracChangeset
for help on using the changeset viewer.
