IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 10, 2009, 12:18:24 PM (17 years ago)
Author:
bills
Message:

add modes for managing distribution cleanup

File:
1 edited

Legend:

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

    r26015 r26088  
    4242static bool addfilesetMode(pxConfig *config);
    4343static bool revertfilesetMode(pxConfig *config);
     44static bool updatefilesetMode(pxConfig *config);
    4445static bool queuercrunMode(pxConfig *config);
    4546static bool updatercrunMode(pxConfig *config);
    4647static bool revertrcrunMode(pxConfig *config);
    4748static bool pendingdestMode(pxConfig *config);
     49static bool pendingcleanupMode(pxConfig *config);
     50static bool listfilesetsMode(pxConfig *config);
    4851
    4952static bool definetargetMode(pxConfig *config);
     
    8689        MODECASE(DISTTOOL_MODE_TOADVANCE, toadvanceMode);
    8790        MODECASE(DISTTOOL_MODE_PENDINGFILESET, pendingfilesetMode);
     91        MODECASE(DISTTOOL_MODE_PENDINGCLEANUP, pendingcleanupMode);
    8892        MODECASE(DISTTOOL_MODE_ADDFILESET, addfilesetMode);
    8993        MODECASE(DISTTOOL_MODE_REVERTFILESET, revertfilesetMode);
     94        MODECASE(DISTTOOL_MODE_LISTFILESETS, listfilesetsMode);
     95        MODECASE(DISTTOOL_MODE_UPDATEFILESET, updatefilesetMode);
    9096        MODECASE(DISTTOOL_MODE_QUEUERCRUN, queuercrunMode);
    9197        MODECASE(DISTTOOL_MODE_UPDATERCRUN, updatercrunMode);
     
    910916    return true;
    911917}
     918
    912919static bool revertfilesetMode(pxConfig *config)
    913920{
     
    17161723    return true;
    17171724}
     1725static bool pendingcleanupMode(pxConfig *config)
     1726{
     1727    PS_ASSERT_PTR_NON_NULL(config, false);
     1728
     1729    psMetadata *where = psMetadataAlloc();
     1730    PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "==");
     1731    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1732    pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "==");
     1733
     1734    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1735    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1736
     1737    if (!psListLength(where->list)) {
     1738        psFree(where);
     1739        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     1740        return false;
     1741    }
     1742
     1743    psString query = pxDataGet("disttool_pendingcleanup.sql");
     1744
     1745    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1746    psStringAppend(&query, " AND %s", whereClause);
     1747    psFree(whereClause);
     1748    psFree(where);
     1749
     1750    // treat limit == 0 as "no limit"
     1751    if (limit) {
     1752        psString limitString = psDBGenerateLimitSQL(limit);
     1753        psStringAppend(&query, " %s", limitString);
     1754        psFree(limitString);
     1755    }
     1756
     1757    if (!p_psDBRunQuery(config->dbh, query)) {
     1758        psError(PS_ERR_UNKNOWN, false, "database error");
     1759        psFree(query);
     1760        if (!psDBRollback(config->dbh)) {
     1761            psError(PS_ERR_UNKNOWN, false, "database error");
     1762        }
     1763        return false;
     1764    }
     1765    psFree(query);
     1766
     1767    psArray *output = p_psDBFetchResult(config->dbh);
     1768    if (!output) {
     1769        psError(PS_ERR_UNKNOWN, false, "database error");
     1770        return false;
     1771    }
     1772    if (!psArrayLength(output)) {
     1773        psTrace("disttool", PS_LOG_INFO, "no rows found");
     1774        psFree(output);
     1775        return true;
     1776    }
     1777
     1778    if (!ippdbPrintMetadatas(stdout, output, "distToCleanup", !simple)) {
     1779        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1780        psFree(output);
     1781        return false;
     1782    }
     1783
     1784    psFree(output);
     1785
     1786    return true;
     1787}
     1788static bool listfilesetsMode(pxConfig *config)
     1789{
     1790    PS_ASSERT_PTR_NON_NULL(config, false);
     1791
     1792    psMetadata *where = psMetadataAlloc();
     1793    PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "==");
     1794    PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "==");
     1795    PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "==");
     1796    PXOPT_COPY_STR(config->args, where, "-dest_name", "name", "==");
     1797    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
     1798    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1799    PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE");
     1800    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE");
     1801    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     1802
     1803    PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
     1804    PXOPT_LOOKUP_BOOL(full, config->args, "-full", false);
     1805
     1806    pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "==");
     1807
     1808    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1809    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1810
     1811    if (!psListLength(where->list)) {
     1812        psFree(where);
     1813        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     1814        return false;
     1815    }
     1816
     1817    psString query = pxDataGet("disttool_listfilesets.sql");
     1818
     1819    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1820    psStringAppend(&query, " WHERE %s", whereClause);
     1821    psFree(whereClause);
     1822    psFree(where);
     1823
     1824    // treat limit == 0 as "no limit"
     1825    if (limit) {
     1826        psString limitString = psDBGenerateLimitSQL(limit);
     1827        psStringAppend(&query, " %s", limitString);
     1828        psFree(limitString);
     1829    }
     1830
     1831    if (!p_psDBRunQuery(config->dbh, query)) {
     1832        psError(PS_ERR_UNKNOWN, false, "database error");
     1833        psFree(query);
     1834        if (!psDBRollback(config->dbh)) {
     1835            psError(PS_ERR_UNKNOWN, false, "database error");
     1836        }
     1837        return false;
     1838    }
     1839    psFree(query);
     1840
     1841    psArray *output = p_psDBFetchResult(config->dbh);
     1842    if (!output) {
     1843        psError(PS_ERR_UNKNOWN, false, "database error");
     1844        return false;
     1845    }
     1846    if (!psArrayLength(output)) {
     1847        psTrace("disttool", PS_LOG_INFO, "no rows found");
     1848        psFree(output);
     1849        return true;
     1850    }
     1851
     1852    if (!ippdbPrintMetadatas(stdout, output, "distFilesets", !simple)) {
     1853        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1854        psFree(output);
     1855        return false;
     1856    }
     1857
     1858    psFree(output);
     1859
     1860    return true;
     1861}
     1862static bool updatefilesetMode(pxConfig *config)
     1863{
     1864    psMetadata *where = psMetadataAlloc();
     1865    PXOPT_COPY_S64(config->args, where, "-fs_id", "fs_id", "==");
     1866
     1867    if (!psListLength(where->list)) {
     1868        psFree(where);
     1869        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     1870        return false;
     1871    }
     1872
     1873    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     1874
     1875    // We don't use PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); here
     1876    // because we want -fault 0 to work
     1877    bool gotFault = false;
     1878    psS16 fault = psMetadataLookupS16(&gotFault, config->args, "-fault");
     1879
     1880    if ((!state) && (!gotFault)) {
     1881        psError(PXTOOLS_ERR_DATA, false, "parameters (-fault or -set_state) is required");
     1882        psFree(where);
     1883        return false;
     1884    }
     1885
     1886    psString query = psStringCopy("UPDATE rcDSFileset SET ");
     1887
     1888    if (state) {
     1889        psStringAppend(&query, " state = '%s'", state);
     1890    }
     1891
     1892    if (gotFault) {
     1893        psStringAppend(&query, "%s fault = %d", state ? ", " : "", fault);
     1894    }
     1895
     1896    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1897    psStringAppend(&query, " WHERE %s", whereClause);
     1898    psFree(whereClause);
     1899    psFree(where);
     1900
     1901    if (!p_psDBRunQuery(config->dbh, query)) {
     1902        psError(PS_ERR_UNKNOWN, false, "database error");
     1903        psFree(query);
     1904        return false;
     1905    }
     1906
     1907    return true;
     1908}
Note: See TracChangeset for help on using the changeset viewer.