IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 29, 2009, 3:29:41 PM (17 years ago)
Author:
bills
Message:

Add modes for creating the various tables used for the server side of distribution.
Add task to run disttool -definebyquery periodically to queue bundling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/disttool.c

    r23972 r24001  
    4747static bool pendingdestMode(pxConfig *config);
    4848
     49static bool definetargetMode(pxConfig *config);
     50static bool updatetargetMode(pxConfig *config);
     51static bool listtargetMode(pxConfig *config);
     52
     53static bool definedsproductMode(pxConfig *config);
     54static bool updatedsproductMode(pxConfig *config);
     55
     56static bool definedestinationMode(pxConfig *config);
     57static bool updatedestinationMode(pxConfig *config);
     58
     59static bool defineinterestMode(pxConfig *config);
     60static bool updateinterestMode(pxConfig *config);
     61
    4962# define MODECASE(caseName, func) \
    5063    case caseName: \
     
    8194        MODECASE(DISTTOOL_MODE_REVERTRCRUN, revertrcrunMode);
    8295        MODECASE(DISTTOOL_MODE_PENDINGDEST, pendingdestMode);
     96        MODECASE(DISTTOOL_MODE_DEFINETARGET, definetargetMode);
     97        MODECASE(DISTTOOL_MODE_UPDATETARGET, updatetargetMode);
     98        MODECASE(DISTTOOL_MODE_LISTTARGET, listtargetMode);
     99        MODECASE(DISTTOOL_MODE_DEFINEDSPRODUCT, definedsproductMode);
     100        MODECASE(DISTTOOL_MODE_UPDATEDSPRODUCT, updatedsproductMode);
     101        MODECASE(DISTTOOL_MODE_DEFINEDESTINATION, definedestinationMode);
     102        MODECASE(DISTTOOL_MODE_UPDATEDESTINATION, updatedestinationMode);
     103        MODECASE(DISTTOOL_MODE_DEFINEINTEREST, defineinterestMode);
     104        MODECASE(DISTTOOL_MODE_UPDATEINTEREST, updateinterestMode);
    83105        default:
    84106            psAbort("invalid option (this should not happen)");
     
    157179    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
    158180    PXOPT_LOOKUP_S64(limit, config->args, "-limit", false, false);
     181    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    159182   
    160183    PXOPT_LOOKUP_BOOL(dry_run, config->args, "-dry_run", false);
     
    323346    }
    324347    if (!psArrayLength(output)) {
    325         psTrace("warptool", PS_LOG_INFO, "no rows found");
     348        psTrace("disttool", PS_LOG_INFO, "no rows found");
    326349        psFree(output);
    327350        return true;
    328351    }
    329352
    330     // XXX Remove this debugging output at some point
    331     if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", true)) {
    332         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    333         psFree(output);
    334         return false;
    335     }
     353
    336354    if (dry_run) {
     355        if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", true)) {
     356            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     357            psFree(output);
     358            return false;
     359        }
    337360        psFree(output);
    338361        return true;
    339362    }
    340363
     364    if (!psDBTransaction(config->dbh)) {
     365        psError(PS_ERR_UNKNOWN, false, "database error");
     366        return false;
     367    }
     368
     369    psArray *list = psArrayAllocEmpty(limit);
    341370    for (long i=0; i < psArrayLength(output); i++) {
    342371        psMetadata *md = output->data[i];
     
    350379        psStringAppend(&outroot, "%s/%s/%s", workdir, run_tag, stage);
    351380
    352         if (!distRunInsert(config->dbh,
     381        distRunRow *row = distRunRowAlloc(
    353382                0,      // dist_id
    354383                target_id,
     
    362391                NULL,   // time_stamp
    363392                0       // fault
    364         )) {
     393                );
     394
     395        if (!row) {
     396            psError(PS_ERR_UNKNOWN, false, "failed to allocate distRunRow");
     397            psFree(outroot);
     398            psFree(output);
     399            return false;
     400        }
     401        if (!distRunInsertObject(config->dbh, row)) {
    365402            psError(PS_ERR_UNKNOWN, false, "database error");
    366403            psFree(outroot);
     
    369406        }
    370407        psFree(outroot);
    371     }
    372 
     408        psS64 dist_id = psDBLastInsertID(config->dbh);
     409        row->dist_id = dist_id;
     410        psArrayAdd(list, list->n, row);
     411        psFree(row);
     412    }
     413
     414    if (!psDBCommit(config->dbh)) {
     415        psError(PS_ERR_UNKNOWN, false, "database error");
     416        return false;
     417    }
     418    if (!distRunPrintObjects(stdout, list, !simple)) {
     419        psError(PS_ERR_UNKNOWN, false, "failed to print object");
     420        psFree(list);
     421        return false;
     422    }
     423
     424    psFree(list);
    373425    psFree(output);
    374426
     
    11091161
    11101162
    1111     PXOPT_LOOKUP_STR(last_fileset, config->args, "-last_fileset", false, false);
     1163    PXOPT_LOOKUP_STR(last_fileset, config->args, "-set_last_fileset", false, false);
    11121164    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    11131165    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
     
    12131265    return true;
    12141266}
     1267
     1268static bool definetargetMode(pxConfig *config)
     1269{
     1270    PS_ASSERT_PTR_NON_NULL(config, false);
     1271
     1272    // required
     1273    PXOPT_LOOKUP_STR(obs_mode, config->args, "-obs_mode", true, false);
     1274    PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
     1275
     1276    // optional
     1277    PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
     1278    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     1279    PXOPT_LOOKUP_STR(comment, config->args, "-comment", false, false);
     1280
     1281    distTargetRow *row = distTargetRowAlloc(
     1282            0,          // target_id
     1283            obs_mode,
     1284            stage,
     1285            clean,
     1286            state ? state : "enabled",
     1287            comment
     1288            );
     1289           
     1290    if (!row) {
     1291        psError(PS_ERR_UNKNOWN, false, "failed to allocate distTarget object");
     1292        return false;
     1293    }
     1294   if (!distTargetInsertObject(config->dbh, row)) {
     1295        psError(PS_ERR_UNKNOWN, false, "database error");
     1296        psFree(row);
     1297        return false;
     1298    }
     1299
     1300    // get the assigned target_id
     1301    row->target_id = psDBLastInsertID(config->dbh);
     1302
     1303    if (!distTargetPrintObject(stdout, row, true)) {
     1304            psError(PS_ERR_UNKNOWN, false, "failed to print object");
     1305            psFree(row);
     1306            return false;
     1307    }
     1308
     1309    psFree(row);
     1310
     1311    return true;
     1312}
     1313static bool updatetargetMode(pxConfig *config)
     1314{
     1315    PS_ASSERT_PTR_NON_NULL(config, false);
     1316
     1317    psMetadata *where = psMetadataAlloc();
     1318    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
     1319    PXOPT_COPY_STR(config->args, where, "-obs_mode", "obs_mode", "==");
     1320    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1321
     1322    PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false);
     1323
     1324    psString query = psStringCopy("UPDATE distTarget SET state = '%s'");
     1325
     1326    if (psListLength(where->list)) {
     1327        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1328        psStringAppend(&query, " WHERE %s", whereClause);
     1329        psFree(whereClause);
     1330    } else {
     1331        psError(PS_ERR_UNKNOWN, true, "search parameters are required");
     1332        psFree(where);
     1333        psFree(query);
     1334        return false;
     1335    }
     1336    psFree(where);
     1337
     1338    if (!p_psDBRunQueryF(config->dbh, query, state)) {
     1339        psError(PS_ERR_UNKNOWN, false, "database error");
     1340        psFree(query);
     1341        return false;
     1342    }
     1343    psFree(query);
     1344
     1345    return true;
     1346}
     1347
     1348static bool listtargetMode(pxConfig *config)
     1349{
     1350    PS_ASSERT_PTR_NON_NULL(config, false);
     1351
     1352    psMetadata *where = psMetadataAlloc();
     1353    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
     1354    PXOPT_COPY_STR(config->args, where, "-obs_mode", "obs_mode", "==");
     1355    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1356    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     1357
     1358    PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
     1359    PXOPT_LOOKUP_BOOL(full, config->args, "-full", false);
     1360
     1361    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1362    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1363
     1364    if (clean && full) {
     1365        psError(PS_ERR_UNKNOWN, false, "can't select both -clean and -full");
     1366        return false;
     1367    }
     1368
     1369    psString query = psStringCopy("SELECT * FROM distTarget");
     1370
     1371    if (psListLength(where->list)) {
     1372        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1373        psStringAppend(&query, " WHERE %s", whereClause);
     1374        psFree(whereClause);
     1375        if (clean) {
     1376            psStringAppend(&query, " (AND clean)");
     1377        } else if (full) {
     1378            psStringAppend(&query, " (AND !clean)");
     1379        }
     1380    } else if (clean) {
     1381        psStringAppend(&query, " WHERE clean");
     1382    } else if (full) {
     1383        psStringAppend(&query, " WHERE !clean");
     1384    }
     1385    psFree(where);
     1386
     1387    // treat limit == 0 as "no limit"
     1388    if (limit) {
     1389        psString limitString = psDBGenerateLimitSQL(limit);
     1390        psStringAppend(&query, " %s", limitString);
     1391        psFree(limitString);
     1392    }
     1393
     1394    if (!p_psDBRunQuery(config->dbh, query)) {
     1395        psError(PS_ERR_UNKNOWN, false, "database error");
     1396        psFree(query);
     1397        if (!psDBRollback(config->dbh)) {
     1398            psError(PS_ERR_UNKNOWN, false, "database error");
     1399        }
     1400        return false;
     1401    }
     1402    psFree(query);
     1403
     1404    psArray *output = p_psDBFetchResult(config->dbh);
     1405    if (!output) {
     1406        psError(PS_ERR_UNKNOWN, false, "database error");
     1407        return false;
     1408    }
     1409    if (!psArrayLength(output)) {
     1410        psTrace("disttool", PS_LOG_INFO, "no rows found");
     1411        psFree(output);
     1412        return true;
     1413    }
     1414
     1415    if (!ippdbPrintMetadatas(stdout, output, "distTarget", !simple)) {
     1416        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1417        psFree(output);
     1418        return false;
     1419    }
     1420
     1421    psFree(output);
     1422
     1423    return true;
     1424}
     1425
     1426static bool definedsproductMode(pxConfig *config)
     1427{
     1428    PS_ASSERT_PTR_NON_NULL(config, false);
     1429
     1430    // required
     1431    PXOPT_LOOKUP_STR(name, config->args,   "-name", true, false);
     1432    PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", true, false);
     1433    PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", true, false);
     1434
     1435    // XXX: should we insure that these names do not contatin any whitespace?
     1436
     1437    rcDSProductRow *row = rcDSProductRowAlloc(
     1438            0,          // prod_id
     1439            name,
     1440            dbname,
     1441            dbhost
     1442            );
     1443           
     1444    if (!row) {
     1445        psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDSProduct object");
     1446        return false;
     1447    }
     1448   if (!rcDSProductInsertObject(config->dbh, row)) {
     1449        psError(PS_ERR_UNKNOWN, false, "database error");
     1450        psFree(row);
     1451        return false;
     1452    }
     1453
     1454    // get the assigned target_id
     1455    row->prod_id = psDBLastInsertID(config->dbh);
     1456
     1457    if (!rcDSProductPrintObject(stdout, row, true)) {
     1458        psError(PS_ERR_UNKNOWN, false, "failed to print object");
     1459        psFree(row);
     1460        return false;
     1461    }
     1462
     1463    psFree(row);
     1464
     1465    return true;
     1466}
     1467static bool updatedsproductMode(pxConfig *config)
     1468{
     1469    PS_ASSERT_PTR_NON_NULL(config, false);
     1470
     1471    psMetadata *where = psMetadataAlloc();
     1472    PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "==");
     1473
     1474    PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", false, false);
     1475    PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", false, false);
     1476
     1477    if (!(dbname || dbhost)) {
     1478        psError(PS_ERR_UNKNOWN, true, "one or more of dbname or dbhost is required");
     1479        psFree(where);
     1480        return false;
     1481    }
     1482    psString query = psStringCopy("UPDATE rcDSProduct SET");
     1483    psString sep = "";
     1484    if (dbname) {
     1485        psStringAppend(&query, " dbname = '%s'", dbname);
     1486        sep = ",";
     1487    }
     1488    if (dbhost) {
     1489        psStringAppend(&query, " %s dbhost = '%s'", sep, dbhost);
     1490    }
     1491
     1492    if (psListLength(where->list)) {
     1493        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1494        psStringAppend(&query, " WHERE %s", whereClause);
     1495        psFree(whereClause);
     1496    } else {
     1497        psError(PS_ERR_UNKNOWN, true, "search parameters are required");
     1498        psFree(where);
     1499        psFree(query);
     1500        return false;
     1501    }
     1502    psFree(where);
     1503
     1504    if (!p_psDBRunQuery(config->dbh, query)) {
     1505        psError(PS_ERR_UNKNOWN, false, "database error");
     1506        psFree(query);
     1507        return false;
     1508    }
     1509    psFree(query);
     1510
     1511    return true;
     1512}
     1513
     1514static bool definedestinationMode(pxConfig *config)
     1515{
     1516    PS_ASSERT_PTR_NON_NULL(config, false);
     1517
     1518    // required
     1519    PXOPT_LOOKUP_S64(prod_id, config->args,      "-prod_id", true, false);
     1520    PXOPT_LOOKUP_STR(name, config->args,         "-name", true, false);
     1521
     1522    // optional
     1523    PXOPT_LOOKUP_STR(status_uri, config->args,   "-status_uri", false, false);
     1524    PXOPT_LOOKUP_STR(comment, config->args,      "-comment", false, false);
     1525    PXOPT_LOOKUP_STR(last_fileset, config->args, "-last_fileset", false, false);
     1526    PXOPT_LOOKUP_STR(state, config->args,        "-set_state", false, false);
     1527
     1528    // XXX: should we insure that these names do not contatin any whitespace?
     1529
     1530    rcDestinationRow *row = rcDestinationRowAlloc(
     1531            0,          // dest_id
     1532            prod_id,
     1533            name,
     1534            status_uri,
     1535            comment,
     1536            last_fileset,
     1537            state ? state : "enabled"
     1538            );
     1539           
     1540    if (!row) {
     1541        psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDestination object");
     1542        return false;
     1543    }
     1544   if (!rcDestinationInsertObject(config->dbh, row)) {
     1545        psError(PS_ERR_UNKNOWN, false, "database error");
     1546        psFree(row);
     1547        return false;
     1548    }
     1549
     1550    // get the assigned target_id
     1551    row->dest_id = psDBLastInsertID(config->dbh);
     1552
     1553    if (!rcDestinationPrintObject(stdout, row, true)) {
     1554        psError(PS_ERR_UNKNOWN, false, "failed to print object");
     1555        psFree(row);
     1556        return false;
     1557    }
     1558
     1559    psFree(row);
     1560
     1561    return true;
     1562}
     1563
     1564static bool updatedestinationMode(pxConfig *config)
     1565{
     1566    PS_ASSERT_PTR_NON_NULL(config, false);
     1567
     1568    psMetadata *where = psMetadataAlloc();
     1569    PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "==");
     1570    PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "==");
     1571
     1572    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     1573#ifdef ALLOW_UPDATE_LAST_FILESET
     1574    PXOPT_LOOKUP_STR(last_fileset, config->args, "-set_last_fileset", false, false);
     1575    if (!(state || last_fileset)) {
     1576        psError(PS_ERR_UNKNOWN, true, "one or more of -set_state or -set_last_fileset is required");
     1577# else
     1578    if (!state) {
     1579#endif
     1580        psFree(where);
     1581        return false;
     1582    }
     1583    psString query = psStringCopy("UPDATE rcDestination SET");
     1584    psString sep = "";
     1585    if (state) {
     1586        psStringAppend(&query, " state = '%s'", state);
     1587        sep = ",";
     1588    }
     1589#ifdef ALLOW_UPDATE_LAST_FILESET
     1590    // last_fileset normally gets set by updatercrunMode
     1591    // Allowing it to be set here might cause problems
     1592    // especially since we are allowing selection by prod_id
     1593    if (last_fileset) {
     1594        psStringAppend(&query, " %s last_fileset = '%s'", sep, last_fileset);
     1595    }
     1596#endif
     1597
     1598    if (psListLength(where->list)) {
     1599        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1600        psStringAppend(&query, " WHERE %s", whereClause);
     1601        psFree(whereClause);
     1602    } else {
     1603        psError(PS_ERR_UNKNOWN, true, "search parameters are required");
     1604        psFree(where);
     1605        psFree(query);
     1606        return false;
     1607    }
     1608    psFree(where);
     1609
     1610    if (!p_psDBRunQuery(config->dbh, query)) {
     1611        psError(PS_ERR_UNKNOWN, false, "database error");
     1612        psFree(query);
     1613        return false;
     1614    }
     1615    psFree(query);
     1616
     1617    return true;
     1618}
     1619
     1620static bool defineinterestMode(pxConfig *config)
     1621{
     1622    PS_ASSERT_PTR_NON_NULL(config, false);
     1623
     1624    // required
     1625    PXOPT_LOOKUP_S64(dest_id, config->args,      "-dest_id", true, false);
     1626    PXOPT_LOOKUP_S64(target_id, config->args,    "-target_id", true, false);
     1627
     1628    // optional
     1629    PXOPT_LOOKUP_STR(state, config->args,        "-set_state", false, false);
     1630
     1631    // XXX: should we insure that these names do not contatin any whitespace?
     1632
     1633    rcInterestRow *row = rcInterestRowAlloc(
     1634            0,          // int_id
     1635            dest_id,
     1636            target_id,
     1637            state ? state : "enabled"
     1638            );
     1639           
     1640    if (!row) {
     1641        psError(PS_ERR_UNKNOWN, false, "failed to allocate rcInterest object");
     1642        return false;
     1643    }
     1644   if (!rcInterestInsertObject(config->dbh, row)) {
     1645        psError(PS_ERR_UNKNOWN, false, "database error");
     1646        psFree(row);
     1647        return false;
     1648    }
     1649
     1650    // get the assigned target_id
     1651    row->int_id = psDBLastInsertID(config->dbh);
     1652
     1653    if (!rcInterestPrintObject(stdout, row, true)) {
     1654        psError(PS_ERR_UNKNOWN, false, "failed to print object");
     1655        psFree(row);
     1656        return false;
     1657    }
     1658
     1659    psFree(row);
     1660
     1661    return true;
     1662}
     1663
     1664static bool updateinterestMode(pxConfig *config)
     1665{
     1666    PS_ASSERT_PTR_NON_NULL(config, false);
     1667
     1668    psMetadata *where = psMetadataAlloc();
     1669    PXOPT_COPY_S64(config->args, where, "-int_id",    "int_id", "==");
     1670    PXOPT_COPY_S64(config->args, where, "-dest_id",   "dest_id", "==");
     1671    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
     1672
     1673    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     1674    if (!state) {
     1675        psError(PS_ERR_UNKNOWN, true, "-set_state is required");
     1676        psFree(where);
     1677        return false;
     1678    }
     1679    psString query = NULL;
     1680    psStringAppend(&query, "UPDATE rcInterest SET state = '%s'", state);
     1681
     1682    if (psListLength(where->list)) {
     1683        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1684        psStringAppend(&query, " WHERE %s", whereClause);
     1685        psFree(whereClause);
     1686    } else {
     1687        psError(PS_ERR_UNKNOWN, true, "search parameters are required");
     1688        psFree(where);
     1689        psFree(query);
     1690        return false;
     1691    }
     1692    psFree(where);
     1693
     1694    if (!p_psDBRunQuery(config->dbh, query)) {
     1695        psError(PS_ERR_UNKNOWN, false, "database error");
     1696        psFree(query);
     1697        return false;
     1698    }
     1699    psFree(query);
     1700
     1701    return true;
     1702}
     1703
Note: See TracChangeset for help on using the changeset viewer.