- Timestamp:
- Aug 19, 2010, 6:50:13 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/ippTools/src/disttool.c
r28794 r28980 34 34 static bool updaterunMode(pxConfig *config); 35 35 static bool revertrunMode(pxConfig *config); 36 static bool rerunMode(pxConfig *config); 36 37 static bool pendingcomponentMode(pxConfig *config); 37 38 static bool addprocessedcomponentMode(pxConfig *config); … … 83 84 MODECASE(DISTTOOL_MODE_UPDATERUN, updaterunMode); 84 85 MODECASE(DISTTOOL_MODE_REVERTRUN, revertrunMode); 86 MODECASE(DISTTOOL_MODE_RERUN, rerunMode); 85 87 MODECASE(DISTTOOL_MODE_PENDINGCOMPONENT, pendingcomponentMode); 86 88 MODECASE(DISTTOOL_MODE_ADDPROCESSEDCOMPONENT, addprocessedcomponentMode); … … 327 329 // stack stage doesn't require magic 328 330 no_magic = true; 331 } else if (!strcmp(stage, "sky")) { 332 magicRunType = "staticskyRun"; 333 query = pxDataGet("disttool_definebyquery_sky.sql"); 334 if (!query) { 335 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 336 psFree(where); 337 return false; 338 } 339 340 if (label) { 341 psStringAppend(&query, " AND (staticskyRun.label = '%s')", label); 342 } 343 if (dist_group) { 344 psStringAppend(&query, " AND (sticskyRun.dist_group = '%s')", dist_group); 345 } 346 // (static)sky stage doesn't require magic 347 no_magic = true; 329 348 } else if (!strcmp(stage, "SSdiff")) { 330 349 magicRunType = "diffRun"; … … 587 606 } 588 607 608 static bool rerunMode(pxConfig *config) 609 { 610 psMetadata *where = psMetadataAlloc(); 611 PXOPT_COPY_S64(config->args, where, "-dist_id", "distRun.dist_id", "=="); 612 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");; 613 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 614 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 615 PXOPT_COPY_STR(config->args, where, "-data_group", "data_group", "=="); 616 617 // require data_group or dist_id to be supplied 618 PXOPT_LOOKUP_STR(data_group, config->args, "-data_group", true, false); 619 PXOPT_LOOKUP_S64(dist_id, config->args, "-dist_id", false, false); 620 if (!data_group && !dist_id) { 621 psError(PXTOOLS_ERR_CONFIG, true, "data_group or dist_id is required"); 622 return false; 623 } 624 PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false); 625 626 psString label_hook = psStringCopy(""); 627 if (set_label) { 628 psStringAppend(&label_hook, ", label = '%s'", set_label); 629 } 630 631 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 632 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 633 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 634 635 636 // It might be useful to be able to query by the parameters of the underlying runs 637 638 if (!psListLength(where->list)) { 639 psFree(where); 640 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 641 return false; 642 } 643 644 psString query = pxDataGet("disttool_rerun_select.sql"); 645 if (!query) { 646 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 647 if (!psDBRollback(config->dbh)) { 648 psError(PS_ERR_UNKNOWN, false, "database error"); 649 } 650 return false; 651 } 652 653 if (psListLength(where->list)) { 654 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 655 psStringAppend(&query, " AND %s", whereClause); 656 psFree(whereClause); 657 } 658 psFree(where); 659 660 if (limit) { 661 psString limitString = psDBGenerateLimitSQL(limit); 662 psStringAppend(&query, " %s", limitString); 663 psFree(limitString); 664 } 665 666 if (!p_psDBRunQuery(config->dbh, query)) { 667 psError(PS_ERR_UNKNOWN, false, "database error"); 668 psFree(query); 669 return false; 670 } 671 psFree(query); 672 673 psArray *output = p_psDBFetchResult(config->dbh); 674 if (!output) { 675 psError(PS_ERR_UNKNOWN, false, "database error"); 676 return false; 677 } 678 if (!psArrayLength(output)) { 679 psTrace("disttool", PS_LOG_INFO, "no rows found"); 680 psFree(output); 681 return true; 682 } 683 684 685 if (pretend) { 686 if (!ippdbPrintMetadatas(stdout, output, "distRunsToUpdate", true)) { 687 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 688 psFree(output); 689 return false; 690 } 691 psFree(output); 692 return true; 693 } 694 695 query = "DELETE FROM distComponent where dist_id = %" PRId64; 696 697 for (long i=0; i < psArrayLength(output); i++) { 698 psMetadata *md = output->data[i]; 699 psS64 dist_id = psMetadataLookupS64(NULL, md, "dist_id"); 700 701 if (!psDBTransaction(config->dbh)) { 702 psError(PS_ERR_UNKNOWN, false, "database error"); 703 return false; 704 } 705 706 if (!p_psDBRunQueryF(config->dbh, query, dist_id)) { 707 psError(PS_ERR_UNKNOWN, false, "database error"); 708 psFree(query); 709 if (!psDBRollback(config->dbh)) { 710 psError(PS_ERR_UNKNOWN, false, "database error"); 711 } 712 return false; 713 } 714 715 if (!p_psDBRunQueryF(config->dbh, 716 "UPDATE distRun SET state = 'new', fault=0 %s WHERE dist_id =%" PRId64, 717 label_hook, dist_id)) { 718 psError(PS_ERR_UNKNOWN, false, "database error"); 719 psFree(query); 720 if (!psDBRollback(config->dbh)) { 721 psError(PS_ERR_UNKNOWN, false, "database error"); 722 } 723 return false; 724 } 725 if (!psDBCommit(config->dbh)) { 726 psError(PS_ERR_UNKNOWN, false, "database error"); 727 return false; 728 } 729 printf("re-running distRun %" PRId64 "\n", dist_id); 730 } 731 732 psFree(output); 733 734 return true; 735 } 589 736 static bool revertrunMode(pxConfig *config) 590 737 {
Note:
See TracChangeset
for help on using the changeset viewer.
