IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 1, 2009, 5:28:52 PM (17 years ago)
Author:
bills
Message:

on receive side of distribution, optionally create a fileset in a status data store
defer {$stage}tool -importrun until all of the files have been downloaded
in the dist.queuruns task queue rcruns

File:
1 edited

Legend:

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

    r23898 r24038  
    11/*
    2  * disttool.c
     2 * receivetool.c
    33 *
    44 * Copyright (C) 2008
     
    3636static bool updatelastMode(pxConfig *config);
    3737static bool pendingfilesetMode(pxConfig *config);
     38static bool updatefilesetMode(pxConfig *config);
    3839static bool addfileMode(pxConfig *config);
    3940static bool pendingfileMode(pxConfig *config);
    4041static bool addresultMode(pxConfig *config);
     42static bool toadvanceMode(pxConfig *config);
    4143static bool revertMode(pxConfig *config);
    4244
     
    6567        MODECASE(RECEIVETOOL_MODE_UPDATELAST, updatelastMode);
    6668        MODECASE(RECEIVETOOL_MODE_PENDINGFILESET, pendingfilesetMode);
     69        MODECASE(RECEIVETOOL_MODE_UPDATEFILESET, updatefilesetMode);
     70        MODECASE(RECEIVETOOL_MODE_TOADVANCE, toadvanceMode);
    6771        MODECASE(RECEIVETOOL_MODE_ADDFILE, addfileMode);
    6872        MODECASE(RECEIVETOOL_MODE_PENDINGFILE, pendingfileMode);
     
    102106    PXOPT_LOOKUP_STR(comment, config->args, "-comment",  false, false);
    103107    PXOPT_LOOKUP_STR(last, config->args, "-last",  false, false);
    104 
    105     if (!receiveSourceInsert(config->dbh, 0, source, product, workdir, comment, last)) {
     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)) {
    106113        psError(PS_ERR_UNKNOWN, false, "Database error");
    107114        return false;
     
    231238        psFree(output);
    232239
    233         if (!receiveFilesetInsert(config->dbh, 0, source_id, fileset)) {
     240        if (!receiveFilesetInsert(config->dbh, 0, source_id, fileset, "new", NULL, 0)) {
    234241            psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
    235242            psFree(source_id_str);
     
    391398    PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
    392399    PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
    393     PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveFile.file_id", "==");
     400    PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveFile.fileset_id", "==");
     401    PXOPT_COPY_S64(config->args, where, "-file_id", "receiveFile.file_id", "==");
    394402
    395403    // optional
     
    499507    return true;
    500508}
     509static bool toadvanceMode(pxConfig *config)
     510{
     511    PS_ASSERT_PTR_NON_NULL(config, false);
     512
     513    psMetadata *where = psMetadataAlloc(); // WHERE conditions
     514
     515    // optional
     516    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     517    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     518
     519    psString query = pxDataGet("receivetool_toadvance.sql");
     520    if (!query) {
     521        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
     522        psFree(where);
     523        return false;
     524    }
     525
     526    if (psListLength(where->list)) {
     527        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     528        psStringAppend(&query, " AND %s", whereClause);
     529        psFree(whereClause);
     530    }
     531    psFree(where);
     532
     533    if (limit) {
     534        psString limitString = psDBGenerateLimitSQL(limit);
     535        psStringAppend(&query, " %s", limitString);
     536        psFree(limitString);
     537    }
     538
     539    if (!p_psDBRunQueryF(config->dbh, query)) {
     540        psError(PS_ERR_UNKNOWN, false, "Database error");
     541        psFree(query);
     542        return false;
     543    }
     544    psFree(query);
     545
     546    psArray *output = p_psDBFetchResult(config->dbh);
     547    if (!output) {
     548        psError(PS_ERR_UNKNOWN, false, "Database error");
     549        return false;
     550    }
     551    if (!psArrayLength(output)) {
     552        psTrace("receivetool", PS_LOG_INFO, "No rows found");
     553        psFree(output);
     554        return true;
     555    }
     556    if (!ippdbPrintMetadatas(stdout, output, "toadvanceFilesets", !simple)) {
     557        psError(PS_ERR_UNKNOWN, false, "Failed to print array");
     558        psFree(output);
     559        return false;
     560    }
     561    psFree(output);
     562
     563    return true;
     564}
     565
     566static bool updatefilesetMode(pxConfig *config)
     567{
     568    PS_ASSERT_PTR_NON_NULL(config, false);
     569
     570    // required
     571    PXOPT_LOOKUP_S64(fileset_id, config->args, "-fileset_id", true, false);
     572
     573    // to chanage
     574    PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
     575    PXOPT_LOOKUP_STR(dbinfo_uri, config->args, "-dbinfo_uri", false, false);
     576    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     577
     578    if (!fault && !dbinfo_uri && !state) {
     579        psError(PS_ERR_UNKNOWN, true, "one of -fault, -dbinfo_uri, -set_state are required");
     580        return false;
     581    }
     582
     583    psString query = NULL;              // Query to execute
     584    psStringAppend(&query, "UPDATE receiveFileset SET ");
     585   
     586    psString sep = "";
     587    if (fault) {
     588        psStringAppend(&query, "%s fault = %d", sep, fault);
     589        sep = ",";
     590    }
     591    if (dbinfo_uri) {
     592        psStringAppend(&query, "%s dbinfo_uri = '%s'", sep, dbinfo_uri);
     593        sep = ",";
     594    }
     595    if (state) {
     596        psStringAppend(&query, "%s state = '%s'", sep, state);
     597        sep = ",";
     598    }
     599   
     600    psStringAppend(&query, " WHERE fileset_id = %" PRId64, fileset_id);
     601
     602    if (!p_psDBRunQuery(config->dbh, query)) {
     603        psError(PS_ERR_UNKNOWN, false, "Database error");
     604        psFree(query);
     605        return false;
     606    }
     607    psFree(query);
     608
     609    return true;
     610}
Note: See TracChangeset for help on using the changeset viewer.