IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24413


Ignore:
Timestamp:
Jun 15, 2009, 1:45:42 PM (17 years ago)
Author:
Paul Price
Message:

Got first cut at pubtool (for publishing detections) coded and compiling.

Location:
branches/pap_mops
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_mops/dbconfig/ipp.m4

    r23880 r24413  
    2626include(rc.md)
    2727include(receive.md)
     28include(publish.md)
  • branches/pap_mops/dbconfig/publish.md

    r24377 r24413  
    33publishClient   METADATA
    44    client_id   S64         0       # Primary Key AUTO_INCREMENT
     5    stage       STR         64
     6    destination STR         255
     7    format      STR         64
    58    comment     STR         255
    6     stage       STR         64
    7     format      STR         64
    8     destination STR         255
    99END
    1010
  • branches/pap_mops/ippTools/doc/publish_flow.txt

    r24377 r24413  
    1313pubtool -revert
    1414
    15 ### Regularly run by pantasks to mark running publishing runs as 'full'
     15### Regularly run by pantasks to mark running publish runs as 'full'
    1616pubtool -advance
  • branches/pap_mops/ippTools/share/pubtool_advance.sql

    r24392 r24413  
    1 SELECT
     1UPDATE publishRun
     2SET state = 'full'
     3WHERE pub_id IN SELECT
    24    pub_id
    35FROM ((
  • branches/pap_mops/ippTools/src

    • Property svn:ignore
      •  

        old new  
        3434disttool
        3535receivetool
         36
         37pubtool
  • branches/pap_mops/ippTools/src/pubtool.c

    r24377 r24413  
    11/*
    2  * receivetool.c
     2 * pubtool.c
    33 *
    44 * Copyright (C) 2008
     
    2929#include "pxtools.h"
    3030#include "pxdata.h"
    31 #include "receivetool.h"
    32 
    33 static bool definesourceMode(pxConfig *config);
    34 static bool listMode(pxConfig *config);
    35 static bool addfilesetMode(pxConfig *config);
    36 static bool updatelastMode(pxConfig *config);
    37 static bool pendingfilesetMode(pxConfig *config);
    38 static bool updatefilesetMode(pxConfig *config);
    39 static bool addfileMode(pxConfig *config);
    40 static bool pendingfileMode(pxConfig *config);
    41 static bool addresultMode(pxConfig *config);
    42 static bool toadvanceMode(pxConfig *config);
     31#include "pubtool.h"
     32
     33static bool defineclientMode(pxConfig *config);
     34static bool definerunMode(pxConfig *config);
     35static bool pendingMode(pxConfig *config);
     36static bool addMode(pxConfig *config);
    4337static bool revertMode(pxConfig *config);
     38static bool advanceMode(pxConfig *config);
    4439
    4540# define MODECASE(caseName, func) \
     
    5550    psLibInit(NULL);
    5651
    57     pxConfig *config = receivetoolConfig(NULL, argc, argv);
     52    pxConfig *config = pubtoolConfig(NULL, argc, argv);
    5853    if (!config) {
    5954        psError(PXTOOLS_ERR_CONFIG, false, "failed to configure");
     
    6257
    6358    switch (config->mode) {
    64         MODECASE(RECEIVETOOL_MODE_DEFINESOURCE, definesourceMode);
    65         MODECASE(RECEIVETOOL_MODE_LIST, listMode);
    66         MODECASE(RECEIVETOOL_MODE_ADDFILESET, addfilesetMode);
    67         MODECASE(RECEIVETOOL_MODE_UPDATELAST, updatelastMode);
    68         MODECASE(RECEIVETOOL_MODE_PENDINGFILESET, pendingfilesetMode);
    69         MODECASE(RECEIVETOOL_MODE_UPDATEFILESET, updatefilesetMode);
    70         MODECASE(RECEIVETOOL_MODE_TOADVANCE, toadvanceMode);
    71         MODECASE(RECEIVETOOL_MODE_ADDFILE, addfileMode);
    72         MODECASE(RECEIVETOOL_MODE_PENDINGFILE, pendingfileMode);
    73         MODECASE(RECEIVETOOL_MODE_ADDRESULT, addresultMode);
    74         MODECASE(RECEIVETOOL_MODE_REVERT, revertMode);
     59        MODECASE(PUBTOOL_MODE_DEFINECLIENT, defineclientMode);
     60        MODECASE(PUBTOOL_MODE_DEFINERUN, definerunMode);
     61        MODECASE(PUBTOOL_MODE_PENDING, pendingMode);
     62        MODECASE(PUBTOOL_MODE_ADD, addMode);
     63        MODECASE(PUBTOOL_MODE_REVERT, revertMode);
     64        MODECASE(PUBTOOL_MODE_ADVANCE, advanceMode);
    7565      default:
    7666        psAbort("invalid option (this should not happen)");
     
    9484}
    9585
    96 static bool definesourceMode(pxConfig *config)
     86static bool defineclientMode(pxConfig *config)
    9787{
    9888    PS_ASSERT_PTR_NON_NULL(config, false);
    9989
    10090    // required
    101     PXOPT_LOOKUP_STR(source, config->args, "-source", true, false);
    102     PXOPT_LOOKUP_STR(product, config->args, "-product",  true, false);
    103     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
     91    PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
     92    PXOPT_LOOKUP_STR(destination, config->args, "-destination",  true, false);
    10493
    10594    // optional
     95    PXOPT_LOOKUP_STR(format, config->args, "-format",  false, false);
    10696    PXOPT_LOOKUP_STR(comment, config->args, "-comment",  false, false);
    107     PXOPT_LOOKUP_STR(last, config->args, "-last",  false, false);
    108     PXOPT_LOOKUP_STR(status_product, config->args, "-status_product",  false, false);
    109     PXOPT_LOOKUP_STR(ds_dbname, config->args, "-ds_dbname",  false, false);
    110     PXOPT_LOOKUP_STR(ds_dbhost, config->args, "-ds_dbhost",  false, false);
    111 
    112     if (!receiveSourceInsert(config->dbh, 0, source, product, workdir, comment, last, status_product, ds_dbname, ds_dbhost)) {
    113         psError(PS_ERR_UNKNOWN, false, "Database error");
    114         return false;
    115     }
    116 
    117     return true;
    118 }
    119 
    120 static bool listMode(pxConfig *config)
     97
     98    if (!publishClientInsert(config->dbh, 0, stage, destination, format, comment)) {
     99        psError(PS_ERR_UNKNOWN, false, "Database error");
     100        return false;
     101    }
     102
     103    return true;
     104}
     105
     106static bool definerunMode(pxConfig *config)
    121107{
    122108    PS_ASSERT_PTR_NON_NULL(config, false);
     
    124110    psMetadata *where = psMetadataAlloc(); // WHERE conditions
    125111
    126     // required
    127     PXOPT_COPY_STR(config->args, where, "-source", "receiveSource.source", "==");
    128     PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
    129     PXOPT_COPY_S64(config->args, where, "-comment", "receiveSource.comment", "LIKE");
    130 
    131112    // optional
    132     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    133     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    134 
    135     psString query = pxDataGet("receivetool_list.sql");
     113    PXOPT_COPY_STR(config->args, where, "-client_id", "client_id", "==");
     114    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     115
     116    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
     117
     118    psString query = pxDataGet("pubtool_definerun.sql"); // Query to run
    136119    if (!query) {
    137120        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
     
    140123    }
    141124
     125    if (!psDBTransaction(config->dbh)) {
     126        psError(PS_ERR_UNKNOWN, false, "Database error");
     127        psFree(where);
     128        return false;
     129    }
     130
     131    psString whereClause = psStringCopy(""); // Additional constraints to add to query
    142132    if (psListLength(where->list)) {
    143         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    144         psStringAppend(&query, " WHERE %s", whereClause);
     133        psString clause = psDBGenerateWhereConditionSQL(where, NULL);
     134        psStringAppend(&whereClause, " AND %s", clause);
     135        psFree(clause);
     136    }
     137    psFree(where);
     138
     139    if (!p_psDBRunQueryF(config->dbh, query, whereClause, whereClause)) {
     140        psError(PS_ERR_UNKNOWN, false, "Database error");
     141        psFree(query);
    145142        psFree(whereClause);
    146     }
    147     psFree(where);
    148 
    149     if (limit) {
    150         psString limitString = psDBGenerateLimitSQL(limit);
    151         psStringAppend(&query, " %s", limitString);
    152         psFree(limitString);
    153     }
    154 
    155     if (!p_psDBRunQuery(config->dbh, query)) {
    156         psError(PS_ERR_UNKNOWN, false, "Database error");
    157         psFree(query);
     143        if (!psDBTransaction(config->dbh)) {
     144            psError(PS_ERR_UNKNOWN, false, "Database error");
     145        }
    158146        return false;
    159147    }
    160148    psFree(query);
    161 
    162     psArray *output = p_psDBFetchResult(config->dbh);
     149    psFree(whereClause);
     150
     151    psArray *output = p_psDBFetchResult(config->dbh); // Output of SELECT statement
    163152    if (!output) {
    164153        psError(PS_ERR_UNKNOWN, false, "Database error");
     154        if (!psDBTransaction(config->dbh)) {
     155            psError(PS_ERR_UNKNOWN, false, "Database error");
     156        }
    165157        return false;
    166158    }
    167159    if (!psArrayLength(output)) {
    168         psTrace("receivetool", PS_LOG_INFO, "No rows found");
     160        psTrace("pubtool", PS_LOG_INFO, "No rows found");
    169161        psFree(output);
     162        if (!psDBTransaction(config->dbh)) {
     163            psError(PS_ERR_UNKNOWN, false, "Database error");
     164        }
    170165        return true;
    171166    }
    172     if (!ippdbPrintMetadatas(stdout, output, "receiveSource", !simple)) {
    173         psError(PS_ERR_UNKNOWN, false, "Failed to print array");
    174         psFree(output);
    175         return false;
    176     }
    177     psFree(output);
    178 
    179     return true;
    180 }
    181 
    182 static bool addfilesetMode(pxConfig *config)
    183 {
    184     PS_ASSERT_PTR_NON_NULL(config, false);
    185 
    186     // required
    187     PXOPT_LOOKUP_S64(source_id, config->args, "-src_id", true, false);
    188     psMetadataItem *filesets = psMetadataLookup(config->args, "-fileset");
    189     if (!filesets) {
    190         psError(PS_ERR_UNKNOWN, true, "-fileset is required");
    191         return false;
    192     }
    193 
    194     psString query = pxDataGet("receivetool_addfileset.sql");
    195     if (!query) {
    196         psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
    197         return false;
    198     }
    199 
    200     if (!psDBTransaction(config->dbh)) {
    201         psError(PS_ERR_UNKNOWN, false, "Database error");
    202         return false;
    203     }
    204 
    205     psString source_id_str = NULL;      // source_id as a string
    206     psStringAppend(&source_id_str, "%" PRId64, source_id);
    207 
    208     psListIterator *iter = psListIteratorAlloc(filesets->data.list, PS_LIST_HEAD, false); // Iterator
    209     psMetadataItem *item = NULL;        // Item from iteration
    210     while ((item = psListGetAndIncrement(iter))) {
    211         psAssert(item && item->data.V && item->type == PS_DATA_STRING, "Argument is bad");
    212         const char *fileset = item->data.str; // Fileset name
    213 
    214         if (!p_psDBRunQueryF(config->dbh, query, source_id_str, fileset)) {
    215             psError(PS_ERR_UNKNOWN, false, "Database error");
    216             psFree(source_id_str);
    217             psFree(query);
    218             psFree(iter);
     167
     168    for (int i = 0; i < output->n; i++) {
     169        psMetadata *row = output->data[i]; // Row of interest
     170        psS64 client = psMetadataLookupS64(NULL, row, "client_id"); // Client identifier
     171        psS64 stage = psMetadataLookupS64(NULL, row, "stage_id");   // Stage identifier
     172
     173        if (!publishRunInsert(config->dbh, 0, client, stage, set_label, "new")) {
     174            psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
     175            psFree(output);
    219176            if (!psDBTransaction(config->dbh)) {
    220177                psError(PS_ERR_UNKNOWN, false, "Database error");
     
    222179            return false;
    223180        }
    224 
    225         psArray *output = p_psDBFetchResult(config->dbh); // Output of query
    226         if (!output) {
    227             psError(PS_ERR_UNKNOWN, false, "Database error");
    228             psFree(source_id_str);
    229             psFree(query);
    230             psFree(iter);
    231             return false;
    232         }
    233         if (psArrayLength(output) > 0) {
    234             psTrace("receivetool", PS_LOG_INFO, "Fileset %s is already present", fileset);
    235             psFree(output);
    236             continue;
    237         }
    238         psFree(output);
    239 
    240         if (!receiveFilesetInsert(config->dbh, 0, source_id, fileset, "reg", NULL, NULL, 0)) {
    241             psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
    242             psFree(source_id_str);
    243             psFree(query);
    244             psFree(iter);
    245             if (!psDBTransaction(config->dbh)) {
    246                 psError(PS_ERR_UNKNOWN, false, "Database error");
    247             }
    248             return false;
    249         }
    250     }
    251     psFree(iter);
    252     psFree(query);
    253     psFree(source_id_str);
    254 
    255     if (!psDBCommit(config->dbh)) {
    256         psError(PS_ERR_UNKNOWN, false, "Database error");
    257         return false;
    258     }
    259 
    260     return true;
    261 }
    262 
    263 static bool updatelastMode(pxConfig *config)
    264 {
    265     PS_ASSERT_PTR_NON_NULL(config, false);
     181    }
     182    psFree(output);
     183
     184    if (!psDBTransaction(config->dbh)) {
     185        psError(PS_ERR_UNKNOWN, false, "Database error");
     186        return false;
     187    }
     188
     189    return true;
     190}
     191
     192static bool pendingMode(pxConfig *config)
     193{
     194    PS_ASSERT_PTR_NON_NULL(config, false);
     195
     196    psMetadata *where = psMetadataAlloc(); // WHERE conditions
    266197
    267198    // required
    268     PXOPT_LOOKUP_S64(source_id, config->args, "-src_id", true, false);
    269     PXOPT_LOOKUP_STR(fileset, config->args, "-fileset",  true, false);
    270 
    271     psString query = NULL;              // Query to execute
    272     psStringAppend(&query, "UPDATE receiveSource SET fileset_last = \'%s\' WHERE source_id = %" PRId64,
    273                    fileset, source_id);
    274 
    275     if (!p_psDBRunQuery(config->dbh, query)) {
    276         psError(PS_ERR_UNKNOWN, false, "Database error");
    277         psFree(query);
    278         return false;
    279     }
    280     psFree(query);
    281 
    282     return true;
    283 }
    284 
    285 
    286 static bool pendingfilesetMode(pxConfig *config)
    287 {
    288     PS_ASSERT_PTR_NON_NULL(config, false);
    289 
    290     psMetadata *where = psMetadataAlloc(); // WHERE conditions
    291 
    292     // required
    293     PXOPT_COPY_STR(config->args, where, "-source", "receiveSource.source", "==");
    294     PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
    295     PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
     199    PXOPT_COPY_STR(config->args, where, "-client_id", "publishClient.client_id", "==");
     200    PXOPT_COPY_STR(config->args, where, "-stage", "publishClient.stage", "==");
     201    PXOPT_COPY_STR(config->args, where, "-comment", "publishClient.comment", "LIKE");
     202    PXOPT_COPY_STR(config->args, where, "-label", "publishRun.label", "==");
    296203
    297204    // optional
     
    299206    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    300207
    301     psString query = pxDataGet("receivetool_pendingfileset.sql");
     208    psString query = pxDataGet("pubtool_pending.sql");
    302209    if (!query) {
    303210        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
     
    332239    }
    333240    if (!psArrayLength(output)) {
    334         psTrace("receivetool", PS_LOG_INFO, "No rows found");
     241        psTrace("pubtool", PS_LOG_INFO, "No rows found");
    335242        psFree(output);
    336243        return true;
    337244    }
    338     if (!ippdbPrintMetadatas(stdout, output, "receiveFileset", !simple)) {
     245    if (!ippdbPrintMetadatas(stdout, output, "publishRun", !simple)) {
    339246        psError(PS_ERR_UNKNOWN, false, "Failed to print array");
    340247        psFree(output);
     
    346253}
    347254
    348 static bool addfileMode(pxConfig *config)
     255static bool addMode(pxConfig *config)
    349256{
    350257    PS_ASSERT_PTR_NON_NULL(config, false);
    351258
    352259    // required
    353     PXOPT_LOOKUP_S64(fileset_id, config->args, "-fileset_id", true, false);
    354     PXOPT_LOOKUP_STR(file_list, config->args, "-file_list", true, false);
    355 
    356     unsigned int numBad;
    357     psMetadata *files = psMetadataConfigRead(NULL, &numBad, file_list, false);
    358     if (!files) {
    359         psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to cleanly read MDC file with file list.");
    360         return false;
    361     }
    362 
    363 
    364     if (!psDBTransaction(config->dbh)) {
    365         psError(PS_ERR_UNKNOWN, false, "Database error");
    366         return false;
    367     }
    368 
    369     psMetadataIterator *iter = psMetadataIteratorAlloc(files, PS_LIST_HEAD, NULL); // Iterator
    370     psMetadataItem *item;
    371     while ((item = psMetadataGetAndIncrement(iter))) {
    372         psMetadata *md = item->data.md;
    373         psString file = psMetadataLookupStr(NULL, md, "file");
    374         psS64    bytes = psMetadataLookupS64(NULL, md, "bytes");
    375         psString md5sum = psMetadataLookupStr(NULL, md, "md5sum");
    376         psString file_type = psMetadataLookupStr(NULL, md, "file_type");
    377         psString component = psMetadataLookupStr(NULL, md, "component");
    378        
    379         if (!file) {
    380             psError(PS_ERR_UNKNOWN, false, "failed to find value for file");
    381             return false;
    382         }
    383         if (!component) {
    384             psError(PS_ERR_UNKNOWN, false, "failed to find value for component");
    385             return false;
    386         }
    387 
    388         if (!receiveFileInsert(config->dbh, 0, fileset_id, file, bytes, md5sum, file_type, component)) {
    389             psError(PS_ERR_UNKNOWN, false, "Unable to add file");
    390             if (!psDBRollback(config->dbh)) {
    391                 psError(PS_ERR_UNKNOWN, false, "Database error");
    392                 return false;
    393             }
    394             psFree(iter);
    395             return false;
    396         }
    397     }
    398 
    399     psFree(iter);
    400 
    401     if (!psDBCommit(config->dbh)) {
    402         psError(PS_ERR_UNKNOWN, false, "Database error");
    403         return false;
    404     }
    405 
    406     return true;
    407 }
    408 
    409 static bool pendingfileMode(pxConfig *config)
     260    PXOPT_LOOKUP_S64(pub_id, config->args, "-pub_id", true, false);
     261    PXOPT_LOOKUP_STR(component, config->args, "-component", true, false);
     262
     263    // optional
     264    PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
     265
     266    if (!publishFileInsert(config->dbh, pub_id, component, fault)) {
     267        psError(PS_ERR_UNKNOWN, false, "Unable to add file");
     268        return false;
     269    }
     270
     271    return true;
     272}
     273
     274
     275
     276
     277static bool revertMode(pxConfig *config)
    410278{
    411279    PS_ASSERT_PTR_NON_NULL(config, false);
    412280
    413281    psMetadata *where = psMetadataAlloc(); // WHERE conditions
    414 
    415     // required
    416     PXOPT_COPY_STR(config->args, where, "-source", "receiveSource.source", "==");
    417     PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
    418     PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
    419     PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveFile.fileset_id", "==");
    420     PXOPT_COPY_S64(config->args, where, "-file_id", "receiveFile.file_id", "==");
    421 
    422     // optional
    423     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    424     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    425 
    426     psString query = pxDataGet("receivetool_pendingfile.sql");
     282    PXOPT_COPY_S64(config->args, where, "-pub_id", "pub_id", "==");
     283    PXOPT_COPY_S32(config->args, where, "-fault", "fault", "==");
     284    PXOPT_COPY_STR(config->args, where, "-client_id", "client_id", "==");
     285    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
     286    PXOPT_COPY_STR(config->args, where, "-comment", "comment", "LIKE");
     287    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     288
     289    psString query = pxDataGet("pubtool_revert.sql");
    427290    if (!query) {
    428291        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
     
    438301    psFree(where);
    439302
    440     if (limit) {
    441         psString limitString = psDBGenerateLimitSQL(limit);
    442         psStringAppend(&query, " %s", limitString);
    443         psFree(limitString);
    444     }
    445 
    446303    if (!p_psDBRunQuery(config->dbh, query)) {
    447304        psError(PS_ERR_UNKNOWN, false, "Database error");
     
    451308    psFree(query);
    452309
    453     psArray *output = p_psDBFetchResult(config->dbh);
    454     if (!output) {
    455         psError(PS_ERR_UNKNOWN, false, "Database error");
    456         return false;
    457     }
    458     if (!psArrayLength(output)) {
    459         psTrace("receivetool", PS_LOG_INFO, "No rows found");
    460         psFree(output);
    461         return true;
    462     }
    463     if (!ippdbPrintMetadatas(stdout, output, "receiveFile", !simple)) {
    464         psError(PS_ERR_UNKNOWN, false, "Failed to print array");
    465         psFree(output);
    466         return false;
    467     }
    468     psFree(output);
    469 
    470     return true;
    471 }
    472 
    473 static bool addresultMode(pxConfig *config)
    474 {
    475     PS_ASSERT_PTR_NON_NULL(config, false);
    476 
    477     // required
    478     PXOPT_LOOKUP_S64(file_id, config->args, "-file_id", true, false);
    479 
    480     // optional
    481     PXOPT_LOOKUP_F32(dtime_copy, config->args, "-dtime_copy", false, false);
    482     PXOPT_LOOKUP_F32(dtime_extract, config->args, "-dtime_extract", false, false);
    483     PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
    484 
    485     if (!receiveResultInsert(config->dbh, file_id, dtime_copy, dtime_extract, fault)) {
    486         psError(PS_ERR_UNKNOWN, false, "Database error");
    487         return false;
    488     }
    489 
    490     return true;
    491 }
    492 
    493 static bool revertMode(pxConfig *config)
    494 {
    495     PS_ASSERT_PTR_NON_NULL(config, false);
    496 
    497     psMetadata *where = psMetadataAlloc(); // WHERE conditions
    498 
    499     PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveResult.fileset_id", "==");
    500     PXOPT_COPY_S32(config->args, where, "-fault", "receiveResult.fault", "==");
    501     PXOPT_COPY_STR(config->args, where, "-source", "receiveSource.source", "==");
    502     PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
    503     PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
    504 
    505     psString query = pxDataGet("receivetool_revert.sql");
     310    return true;
     311}
     312static bool advanceMode(pxConfig *config)
     313{
     314    PS_ASSERT_PTR_NON_NULL(config, false);
     315
     316    psString query = pxDataGet("pubtool_advance.sql");
    506317    if (!query) {
    507318        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
    508         psFree(where);
    509         return false;
    510     }
    511 
    512     if (psListLength(where->list)) {
    513         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    514         psStringAppend(&query, " AND %s", whereClause);
    515         psFree(whereClause);
    516     }
    517     psFree(where);
     319        return false;
     320    }
    518321
    519322    if (!p_psDBRunQuery(config->dbh, query)) {
     
    526329    return true;
    527330}
    528 static bool toadvanceMode(pxConfig *config)
    529 {
    530     PS_ASSERT_PTR_NON_NULL(config, false);
    531 
    532     psMetadata *where = psMetadataAlloc(); // WHERE conditions
    533 
    534     // optional
    535     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    536     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    537 
    538     psString query = pxDataGet("receivetool_toadvance.sql");
    539     if (!query) {
    540         psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
    541         psFree(where);
    542         return false;
    543     }
    544 
    545     if (psListLength(where->list)) {
    546         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    547         psStringAppend(&query, " AND %s", whereClause);
    548         psFree(whereClause);
    549     }
    550     psFree(where);
    551 
    552     if (limit) {
    553         psString limitString = psDBGenerateLimitSQL(limit);
    554         psStringAppend(&query, " %s", limitString);
    555         psFree(limitString);
    556     }
    557 
    558     if (!p_psDBRunQuery(config->dbh, query)) {
    559         psError(PS_ERR_UNKNOWN, false, "Database error");
    560         psFree(query);
    561         return false;
    562     }
    563     psFree(query);
    564 
    565     psArray *output = p_psDBFetchResult(config->dbh);
    566     if (!output) {
    567         psError(PS_ERR_UNKNOWN, false, "Database error");
    568         return false;
    569     }
    570     if (!psArrayLength(output)) {
    571         psTrace("receivetool", PS_LOG_INFO, "No rows found");
    572         psFree(output);
    573         return true;
    574     }
    575     if (!ippdbPrintMetadatas(stdout, output, "toadvanceFilesets", !simple)) {
    576         psError(PS_ERR_UNKNOWN, false, "Failed to print array");
    577         psFree(output);
    578         return false;
    579     }
    580     psFree(output);
    581 
    582     return true;
    583 }
    584 
    585 static bool updatefilesetMode(pxConfig *config)
    586 {
    587     PS_ASSERT_PTR_NON_NULL(config, false);
    588 
    589     // required
    590     PXOPT_LOOKUP_S64(fileset_id, config->args, "-fileset_id", true, false);
    591 
    592     // to chanage
    593     PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
    594     PXOPT_LOOKUP_STR(destdir, config->args, "-destdir", false, false);
    595     PXOPT_LOOKUP_STR(dirinfo, config->args, "-dirinfo", false, false);
    596     PXOPT_LOOKUP_STR(dbinfo, config->args, "-dbinfo", false, false);
    597     PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    598 
    599     if (!fault && !dirinfo &&!dbinfo && !state) {
    600         psError(PS_ERR_UNKNOWN, true, "at least one of -fault, -dirinfo, -dbinfo, -set_state are required");
    601         return false;
    602     }
    603 
    604     psString query = NULL;              // Query to execute
    605     psStringAppend(&query, "UPDATE receiveFileset SET ");
    606    
    607     psString sep = "";
    608     if (fault) {
    609         psStringAppend(&query, "%s fault = %d", sep, fault);
    610         sep = ",";
    611     }
    612     if (dirinfo) {
    613         psStringAppend(&query, "%s dirinfo = '%s'", sep, dirinfo);
    614         sep = ",";
    615     }
    616     if (dbinfo) {
    617         psStringAppend(&query, "%s dbinfo = '%s'", sep, dbinfo);
    618         sep = ",";
    619     }
    620     if (state) {
    621         psStringAppend(&query, "%s state = '%s'", sep, state);
    622         sep = ",";
    623     }
    624    
    625     psStringAppend(&query, " WHERE fileset_id = %" PRId64, fileset_id);
    626 
    627     if (!p_psDBRunQuery(config->dbh, query)) {
    628         psError(PS_ERR_UNKNOWN, false, "Database error");
    629         psFree(query);
    630         return false;
    631     }
    632     psFree(query);
    633 
    634     return true;
    635 }
  • branches/pap_mops/ippTools/src/pubtoolConfig.c

    r24377 r24413  
    4646    psMetadata *defineclientArgs = psMetadataAlloc();
    4747    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-stage", 0, "define stage (required)", NULL);
    48     psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-comment", 0, "define comment", NULL);
    4948    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-destination", 0, "define destination (required)", NULL);
    5049    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-format", 0, "define format", NULL);
     50    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-comment", 0, "define comment", NULL);
    5151
    5252    // -definerun
    5353    psMetadata *definerunArgs = psMetadataAlloc();
    54     psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-client_id", 0, "define client_id (required)", 0);
    5554    psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-set_label", 0, "define label", 0);
     55    psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-client_id", 0, "search by client_id", 0);
    5656    psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-label", 0, "search by label", 0);
    5757
     
    6161    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-stage", 0, "search on source", NULL);
    6262    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-comment", 0, "search on comment (LIKE)", NULL);
     63    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
    6364    psMetadataAddBool(pendingArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
    6465    psMetadataAddU64(pendingArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
    65     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
    6666
    6767    // -add
     
    8282    // -advance
    8383    psMetadata *advanceArgs = psMetadataAlloc();
    84     psMetadataAddS64(advanceArgs, PS_LIST_TAIL, "-pub_id", 0, "search on pub_id", 0);
    85     psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
    8684
    8785    psMetadata *argSets = psMetadataAlloc();
Note: See TracChangeset for help on using the changeset viewer.