Changeset 25493 for trunk/ippTools/src/disttool.c
- Timestamp:
- Sep 23, 2009, 10:22:33 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/disttool.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/disttool.c
r25460 r25493 37 37 static bool pendingcomponentMode(pxConfig *config); 38 38 static bool addprocessedcomponentMode(pxConfig *config); 39 static bool revertcomponentMode(pxConfig *config); 39 40 static bool processedcomponentMode(pxConfig *config); 40 41 static bool toadvanceMode(pxConfig *config); … … 51 52 static bool listtargetMode(pxConfig *config); 52 53 53 static bool definedsproductMode(pxConfig *config);54 static bool updatedsproductMode(pxConfig *config);55 56 54 static bool definedestinationMode(pxConfig *config); 57 55 static bool updatedestinationMode(pxConfig *config); … … 59 57 static bool defineinterestMode(pxConfig *config); 60 58 static bool updateinterestMode(pxConfig *config); 59 static bool listinterestMode(pxConfig *config); 61 60 62 61 # define MODECASE(caseName, func) \ … … 86 85 MODECASE(DISTTOOL_MODE_ADDPROCESSEDCOMPONENT, addprocessedcomponentMode); 87 86 MODECASE(DISTTOOL_MODE_PROCESSEDCOMPONENT, processedcomponentMode); 87 MODECASE(DISTTOOL_MODE_REVERTCOMPONENT, revertcomponentMode); 88 88 MODECASE(DISTTOOL_MODE_TOADVANCE, toadvanceMode); 89 89 MODECASE(DISTTOOL_MODE_PENDINGFILESET, pendingfilesetMode); … … 97 97 MODECASE(DISTTOOL_MODE_UPDATETARGET, updatetargetMode); 98 98 MODECASE(DISTTOOL_MODE_LISTTARGET, listtargetMode); 99 MODECASE(DISTTOOL_MODE_DEFINEDSPRODUCT, definedsproductMode);100 MODECASE(DISTTOOL_MODE_UPDATEDSPRODUCT, updatedsproductMode);101 99 MODECASE(DISTTOOL_MODE_DEFINEDESTINATION, definedestinationMode); 102 100 MODECASE(DISTTOOL_MODE_UPDATEDESTINATION, updatedestinationMode); 103 101 MODECASE(DISTTOOL_MODE_DEFINEINTEREST, defineinterestMode); 104 102 MODECASE(DISTTOOL_MODE_UPDATEINTEREST, updateinterestMode); 103 MODECASE(DISTTOOL_MODE_LISTINTEREST, listinterestMode); 105 104 default: 106 105 psAbort("invalid option (this should not happen)"); … … 500 499 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 501 500 502 // we need to disambiguate fault so make a copy of the where list before adding fault503 psMetadata *whereComponent = psMetadataCopy(NULL, where);504 501 PXOPT_COPY_S16(config->args, where, "-fault", "distRun.fault", "=="); 505 PXOPT_COPY_S16(config->args, whereComponent, "-fault", "distComponent.fault", "==");506 502 507 503 // It might be useful to be able to query by the parameters of the underlying runs … … 513 509 } 514 510 515 if (!psDBTransaction(config->dbh)) { 516 psError(PS_ERR_UNKNOWN, false, "database error"); 511 psString query = pxDataGet("disttool_revertrun.sql"); 512 if (!query) { 513 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 514 if (!psDBRollback(config->dbh)) { 515 psError(PS_ERR_UNKNOWN, false, "database error"); 516 } 517 return false; 518 } 519 520 if (psListLength(where->list)) { 521 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 522 psStringAppend(&query, " AND %s", whereClause); 523 psFree(whereClause); 524 } 525 psFree(where); 526 527 if (!p_psDBRunQuery(config->dbh, query)) { 528 psError(PS_ERR_UNKNOWN, false, "database error"); 529 psFree(query); 530 return false; 531 } 532 533 int numUpdated = psDBAffectedRows(config->dbh); 534 535 psLogMsg("disttool", PS_LOG_INFO, "Updated %d dist runs", numUpdated); 536 537 return true; 538 } 539 540 static bool revertcomponentMode(pxConfig *config) 541 { 542 psMetadata *where = psMetadataAlloc(); 543 PXOPT_COPY_S64(config->args, where, "-dist_id", "distRun.dist_id", "=="); 544 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");; 545 PXOPT_COPY_STR(config->args, where, "-component", "component", "==");; 546 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 547 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 548 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 549 550 PXOPT_COPY_S16(config->args, where, "-fault", "distComponent.fault", "=="); 551 552 // It might be useful to be able to query by the parameters of the underlying runs 553 554 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 517 555 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)) { 540 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 } 551 552 psLogMsg("disttool", PS_LOG_INFO, "Updated %d dist runs", numUpdated); 553 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 } 556 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 557 return false; 558 } 559 560 psString query = pxDataGet("disttool_revertcomponent.sql"); 561 if (!query) { 562 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 563 psFree(where); 564 return false; 565 } 566 567 if (psListLength(where->list)) { 568 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 569 psStringAppend(&query, " AND %s", whereClause); 570 psFree(whereClause); 571 } 572 psFree(where); 573 574 if (!p_psDBRunQuery(config->dbh, query)) { 575 psError(PS_ERR_UNKNOWN, false, "database error"); 576 psFree(query); 577 return false; 578 } 579 580 int numDeleted = psDBAffectedRows(config->dbh); 584 581 585 582 psLogMsg("disttool", PS_LOG_INFO, "Deleted %d distComponents", numDeleted); 586 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 583 595 584 return true; … … 1413 1402 } 1414 1403 1415 static bool defined sproductMode(pxConfig *config)1404 static bool definedestinationMode(pxConfig *config) 1416 1405 { 1417 1406 PS_ASSERT_PTR_NON_NULL(config, false); 1418 1407 1419 1408 // required 1420 PXOPT_LOOKUP_STR(name, config->args, "-name", true, false);1421 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", true, false);1422 PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", true, false);1423 1424 // XXX: should we insure that these names do not contatin any whitespace?1425 1426 rcDSProductRow *row = rcDSProductRowAlloc(1427 0, // prod_id1428 name,1429 dbname,1430 dbhost1431 );1432 1433 if (!row) {1434 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDSProduct object");1435 return false;1436 }1437 if (!rcDSProductInsertObject(config->dbh, row)) {1438 psError(PS_ERR_UNKNOWN, false, "database error");1439 psFree(row);1440 return false;1441 }1442 1443 // get the assigned target_id1444 row->prod_id = psDBLastInsertID(config->dbh);1445 1446 if (!rcDSProductPrintObject(stdout, row, true)) {1447 psError(PS_ERR_UNKNOWN, false, "failed to print object");1448 psFree(row);1449 return false;1450 }1451 1452 psFree(row);1453 1454 return true;1455 }1456 static bool updatedsproductMode(pxConfig *config)1457 {1458 PS_ASSERT_PTR_NON_NULL(config, false);1459 1460 psMetadata *where = psMetadataAlloc();1461 PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "==");1462 1463 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", false, false);1464 PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", false, false);1465 1466 if (!(dbname || dbhost)) {1467 psError(PS_ERR_UNKNOWN, true, "one or more of dbname or dbhost is required");1468 psFree(where);1469 return false;1470 }1471 psString query = psStringCopy("UPDATE rcDSProduct SET");1472 psString sep = "";1473 if (dbname) {1474 psStringAppend(&query, " dbname = '%s'", dbname);1475 sep = ",";1476 }1477 if (dbhost) {1478 psStringAppend(&query, " %s dbhost = '%s'", sep, dbhost);1479 }1480 1481 if (psListLength(where->list)) {1482 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);1483 psStringAppend(&query, " WHERE %s", whereClause);1484 psFree(whereClause);1485 } else {1486 psError(PS_ERR_UNKNOWN, true, "search parameters are required");1487 psFree(where);1488 psFree(query);1489 return false;1490 }1491 psFree(where);1492 1493 if (!p_psDBRunQuery(config->dbh, query)) {1494 psError(PS_ERR_UNKNOWN, false, "database error");1495 psFree(query);1496 return false;1497 }1498 psFree(query);1499 1500 return true;1501 }1502 1503 static bool definedestinationMode(pxConfig *config)1504 {1505 PS_ASSERT_PTR_NON_NULL(config, false);1506 1507 // required1508 PXOPT_LOOKUP_S64(prod_id, config->args, "-prod_id", true, false);1509 1409 PXOPT_LOOKUP_STR(name, config->args, "-name", true, false); 1410 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", true, false); 1411 PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", true, false); 1510 1412 1511 1413 // optional … … 1519 1421 rcDestinationRow *row = rcDestinationRowAlloc( 1520 1422 0, // dest_id 1521 prod_id,1522 1423 name, 1523 1424 status_uri, 1524 1425 comment, 1525 1426 last_fileset, 1427 dbname, 1428 dbhost, 1526 1429 state ? state : "enabled" 1527 1430 ); … … 1611 1514 PS_ASSERT_PTR_NON_NULL(config, false); 1612 1515 1613 // required 1614 PXOPT_LOOKUP_S64(dest_id, config->args, "-dest_id", true, false); 1615 PXOPT_LOOKUP_S64(target_id, config->args, "-target_id", true, false); 1516 // one of these is required 1517 PXOPT_LOOKUP_S64(dest_id, config->args, "-dest_id", false, false); 1518 PXOPT_LOOKUP_STR(dest_name, config->args, "-dest_name", false, false); 1519 if (!dest_id && !dest_name) { 1520 psError(PS_ERR_UNKNOWN, true, "either dest_id or dest_name is required"); 1521 return false; 1522 } 1523 1524 // either target_id or stage and label are required 1525 PXOPT_LOOKUP_S64(target_id, config->args, "-target_id", false, false); 1526 PXOPT_LOOKUP_STR(stage, config->args, "-stage", false, false); 1527 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 1528 PXOPT_LOOKUP_STR(filter, config->args, "-filter", false, false); 1529 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 1530 1531 if (!target_id) { 1532 bool error = false; 1533 if (!stage) { 1534 psError(PS_ERR_UNKNOWN, true, "stage is required if target_id is not supplied"); 1535 error = true; 1536 } 1537 if (!label) { 1538 psError(PS_ERR_UNKNOWN, !error, "label is required if target_id is not supplied"); 1539 error = true; 1540 } 1541 if (error) { 1542 return false; 1543 } 1544 } 1616 1545 1617 1546 // optional 1547 PXOPT_LOOKUP_S64(limit, config->args, "-limit", false, false); 1618 1548 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1619 1620 // XXX: should we insure that these names do not contatin any whitespace? 1621 1622 rcInterestRow *row = rcInterestRowAlloc( 1623 0, // int_id 1624 dest_id, 1625 target_id, 1626 state ? state : "enabled" 1627 ); 1628 1629 if (!row) { 1630 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcInterest object"); 1631 return false; 1632 } 1633 if (!rcInterestInsertObject(config->dbh, row)) { 1634 psError(PS_ERR_UNKNOWN, false, "database error"); 1635 psFree(row); 1636 return false; 1637 } 1638 1639 // get the assigned target_id 1640 row->int_id = psDBLastInsertID(config->dbh); 1641 1642 if (!rcInterestPrintObject(stdout, row, true)) { 1643 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1644 psFree(row); 1645 return false; 1646 } 1647 1648 psFree(row); 1549 if (state) { 1550 if (strcmp(state, "enabled") && strcmp(state, "disabled")) { 1551 psError(PS_ERR_PROGRAMMING, true, "state must be enabled or disabled"); 1552 return false; 1553 } 1554 } else { 1555 // default state 1556 state = "enabled"; 1557 } 1558 1559 // now that we've done all of our argument checking, copy the values to where 1560 psMetadata *where = psMetadataAlloc(); 1561 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1562 PXOPT_COPY_STR(config->args, where, "-dest_name", "rcDestination.name", "=="); 1563 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1564 PXOPT_COPY_STR(config->args, where, "-label", "label", "LIKE"); 1565 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE"); 1566 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 1567 1568 psString query = pxDataGet("disttool_defineinterest.sql"); 1569 1570 if (!psListLength(where->list)) { 1571 // can't get here 1572 psError(PS_ERR_PROGRAMMING, true, "search parameters are required"); 1573 psFree(where); 1574 psFree(query); 1575 return false; 1576 } 1577 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1578 psStringAppend(&query, " AND %s", whereClause); 1579 psFree(whereClause); 1580 psFree(where); 1581 if (clean) { 1582 psStringAppend(&query, " AND (distTarget.clean)"); 1583 } else { 1584 psStringAppend(&query, " AND (!distTarget.clean)"); 1585 } 1586 if (limit) { 1587 psString limitString = psDBGenerateLimitSQL(limit); 1588 psStringAppend(&query, " %s", limitString); 1589 psFree(limitString); 1590 } 1591 { 1592 // psStringSubstitute fails unless the input is a psString which it determines by 1593 // comparing the memory blocks free function to an expected value. 1594 // pxDataGet uses psSlurp which leaves a different free function on the memory block. 1595 // To work around this make a copy of the query before doing the substitution. 1596 psString queryCopy = psStringCopy(query); 1597 psFree(query); 1598 query = queryCopy; 1599 } 1600 // change the @STATE@ in the sql file to our state 1601 if (!psStringSubstitute(&query, state, "@STATE@")) { 1602 psError(PS_ERR_UNKNOWN, false, "failed to substitute state string"); 1603 return false; 1604 } 1605 1606 if (!p_psDBRunQuery(config->dbh, query)) { 1607 psError(PS_ERR_UNKNOWN, false, "database error"); 1608 psFree(query); 1609 return false; 1610 } 1611 psFree(query); 1612 int numInserted = psDBAffectedRows(config->dbh); 1613 printf("inserted %d rows into rcInterest\n", numInserted); 1649 1614 1650 1615 return true; … … 1690 1655 return true; 1691 1656 } 1692 1657 static bool listinterestMode(pxConfig *config) 1658 { 1659 PS_ASSERT_PTR_NON_NULL(config, false); 1660 1661 psMetadata *where = psMetadataAlloc(); 1662 PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "=="); 1663 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1664 PXOPT_COPY_STR(config->args, where, "-dest_name", "name", "=="); 1665 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1666 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 1667 PXOPT_COPY_STR(config->args, where, "-label", "label", "LIKE"); 1668 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE"); 1669 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 1670 1671 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 1672 PXOPT_LOOKUP_BOOL(full, config->args, "-full", false); 1673 1674 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1675 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1676 1677 if (clean && full) { 1678 psError(PS_ERR_UNKNOWN, false, "can't select both -clean and -full"); 1679 return false; 1680 } 1681 1682 psString query = pxDataGet("disttool_listinterest.sql"); 1683 1684 if (psListLength(where->list)) { 1685 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1686 psStringAppend(&query, " WHERE %s", whereClause); 1687 psFree(whereClause); 1688 if (clean) { 1689 psStringAppend(&query, " AND (clean)"); 1690 } else if (full) { 1691 psStringAppend(&query, " AND (!clean)"); 1692 } 1693 } else if (clean) { 1694 psStringAppend(&query, " WHERE clean"); 1695 } else if (full) { 1696 psStringAppend(&query, " WHERE !clean"); 1697 } 1698 psFree(where); 1699 1700 // treat limit == 0 as "no limit" 1701 if (limit) { 1702 psString limitString = psDBGenerateLimitSQL(limit); 1703 psStringAppend(&query, " %s", limitString); 1704 psFree(limitString); 1705 } 1706 1707 if (!p_psDBRunQuery(config->dbh, query)) { 1708 psError(PS_ERR_UNKNOWN, false, "database error"); 1709 psFree(query); 1710 if (!psDBRollback(config->dbh)) { 1711 psError(PS_ERR_UNKNOWN, false, "database error"); 1712 } 1713 return false; 1714 } 1715 psFree(query); 1716 1717 psArray *output = p_psDBFetchResult(config->dbh); 1718 if (!output) { 1719 psError(PS_ERR_UNKNOWN, false, "database error"); 1720 return false; 1721 } 1722 if (!psArrayLength(output)) { 1723 psTrace("disttool", PS_LOG_INFO, "no rows found"); 1724 psFree(output); 1725 return true; 1726 } 1727 1728 if (!ippdbPrintMetadatas(stdout, output, "rcInterest", !simple)) { 1729 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1730 psFree(output); 1731 return false; 1732 } 1733 1734 psFree(output); 1735 1736 return true; 1737 }
Note:
See TracChangeset
for help on using the changeset viewer.
