IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16933 for trunk/pstamp/src


Ignore:
Timestamp:
Mar 10, 2008, 5:06:08 PM (18 years ago)
Author:
bills
Message:

changes to support get image (non postage stamp) jobs

Location:
trunk/pstamp/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/src/pstampfinish.c

    r16878 r16933  
    182182}
    183183
    184 static bool finishRequest(psrfOptions *options, pstampRequestRow *pReq, psArray *stoppedJobs)
     184static bool buildResultsFile(psrfOptions *options, pstampRequestRow *pReq, psArray *stoppedJobs)
    185185{
    186186    // build results file in dsRoot/pReq->outFileset
     
    238238    psString command = NULL;
    239239
    240     psStringAppend(&command, "dsreg --add --type PSRESPONSE --product %s --fileset %s",
     240    psStringAppend(&command, "dsreg --add --type PSRESULTS --product %s --fileset %s",
    241241            options->dsProduct, fileset_id);
    242242
     
    266266        psError(PS_ERR_UNKNOWN, true, "dsreg failed with status: %d", status);
    267267        return false;
     268    }
     269
     270    return true;
     271}
     272static bool finishRequest(psrfOptions *options, pstampRequestRow *pReq, psArray *stoppedJobs)
     273{
     274    if (pReq->resultsFile) {
     275        if (!buildResultsFile(options, pReq, stoppedJobs)) {
     276            return false;
     277        }
    268278    }
    269279    // update the database setting the request state to stop
  • trunk/pstamp/src/pstampparse.c

    r16897 r16933  
    7272        psArgumentRemove(argnum, &argc, argv);
    7373    }
     74
    7475    if ((argnum = psArgumentGet(argc, argv, "-req_id"))) {
    7576        psArgumentRemove(argnum, &argc, argv);
    7677        if (argnum == argc) {
    77             fprintf(stderr, "value required for mode\n");
     78            fprintf(stderr, "value required for req_id\n");
    7879            usage();
    7980        }
     
    598599
    599600static bool
    600 queueOneJob (pspOptions *options, psString uri, psString outputBase, psString commandArgs)
     601queueOneJob (pspOptions *options, psString job_type, psString uri, psString outputBase, psString commandArgs)
    601602{
    602603    psString cmd = NULL;
    603604
    604     psStringAppend(&cmd, "pstamptool -addjob -req_id %ld -uri %s -outputBase ", options->req_id, uri);
     605    psStringAppend(&cmd, "pstamptool -addjob -req_id %ld -job_type %s -uri %s ",
     606        options->req_id, job_type, uri);
    605607   
    606     if (options->outputDirectory) {
    607         psStringAppend(&cmd, "%s/", options->outputDirectory);
    608     }
     608    if (outputBase != NULL) {
     609        psStringAppend(&cmd, "-outputBase ");
    609610   
    610     psStringAppend(&cmd, "%s -args '%s' >/dev/null", outputBase, commandArgs);
     611        if (options->outputDirectory) {
     612            psStringAppend(&cmd, "%s/", options->outputDirectory);
     613        }
     614        psStringAppend(&cmd, "%s", outputBase);
     615    }
     616    if (commandArgs) {
     617        psStringAppend(&cmd, " -args '%s'", commandArgs);
     618    }
     619    psStringAppend(&cmd, " > /dev/null");
    611620
    612621    if (options->verbose) {
     
    626635
    627636static bool
    628 queueJobs (pspOptions *options, psArray *uris, psString user_tag, psString commandArgs)
     637queueJobs (pspOptions *options, psString job_type, psArray *uris, psString user_tag, psString commandArgs)
    629638{
    630639    int numURIs = psArrayLength(uris);
     
    633642    if (numURIs == 1) {
    634643        // use the user tag as the outputBase
    635         status = queueOneJob(options, uris->data[0], user_tag, commandArgs);
     644        status = queueOneJob(options, job_type, uris->data[0], user_tag, commandArgs);
    636645    } else {
    637646        for (int i = 0; i< numURIs; i++) {
     
    641650            psStringAppend(&outputBase, "%s_%d", user_tag, i);
    642651
    643             status = queueOneJob(options, uris->data[i], outputBase, commandArgs);
     652            status = queueOneJob(options, job_type, uris->data[i], outputBase, commandArgs);
    644653            psFree(outputBase);
    645654
     
    653662}
    654663
     664static bool
     665turnOffResultsFile(pspOptions *options)
     666{
     667    // turn off the creation of a results file for this request
     668    char * query = "UPDATE pstampRequest SET resultsFile = 0 WHERE req_id = %" PRId64;
     669    return p_psDBRunQuery(options->config->database, query, options->req_id);
     670}
     671
     672static bool
     673queueGetImageJob(pspOptions *options, psArray *uris, psString req_type)
     674{
     675    FILE        *listFile;
     676    psString    fileName = NULL;
     677    psString    img_type = psMetadataLookupStr(NULL, options->md, "IMG_TYPE");
     678
     679    if (! turnOffResultsFile(options)) {
     680        fprintf(stderr, "failed to update resultsFile for request %" PRId64 "\n", options->req_id);
     681        return false;
     682    }
     683
     684    if (options->outputDirectory == NULL) {
     685        fprintf(stderr, "outputDirectory is required\n");
     686        return false;
     687    }
     688    psStringAppend(&fileName, "%s/filelist", options->outputDirectory);
     689
     690    listFile = fopen(fileName, "w");
     691    if (listFile == NULL) {
     692        psError(PS_ERR_UNKNOWN, true, "failed to open get_image file list: %s\n", fileName);
     693        return false;
     694    }
     695
     696    for (int i=0; i<psArrayLength(uris); i++) {
     697        fprintf(listFile, "%s|%s\n", (psString) uris->data[i], img_type);
     698    }
     699    fclose(listFile);
     700
     701    psString cmd = NULL;
     702    psStringAppend(&cmd, "pstamptool -addjob -req_id %ld -job_type get_image -uri %s -outputBase %s",
     703        options->req_id, fileName, options->outputDirectory);
     704   
     705    int rstatus = system(cmd);
     706    if (rstatus) {
     707        fprintf(stderr, "%s failed with status: %d\n", cmd, rstatus);
     708    }
     709
     710    return rstatus == 0;
     711}
     712
    655713
    656714static bool
     
    658716{
    659717    bool status;
     718    psString job_type = psMetadataLookupStr(&status, options->md, "JOB_TYPE");
     719
     720    if (job_type == NULL) {
     721        // XXX: compatiabilty hack change to error at some point
     722        job_type = "stamp";
     723    }
     724
    660725    psString cmd_mode = psMetadataLookupStr(&status, options->md, "CMD_MODE");
    661726
    662     // if mode is set on the command line ignore the value in the request file
     727    // if cmd_mode is set on the command line ignore the value in the request file
    663728    if (options->mode == PSP_MODE_UNKNOWN) {
    664729        if (cmd_mode != NULL) {
     
    682747        return false;
    683748    }
     749
    684750    psString roiString = parseROI(options);
    685 #ifdef notdef
    686     if (!roiString) {
    687         return false;
    688     }
    689 #endif
    690751
    691752    psArray *uris = NULL;
     753
    692754    if (!strcmp(req_type, "byid")) {
    693755        // directly by exp_id, chip_id, warp_id etc
     756
    694757        uris = parseByID(options);
    695758    } else if (!strcmp(req_type, "byexp")) {
    696759        // images that resulted from a given exposure
     760
    697761        uris = parseByExp(options);
    698762    } else if (!strcmp(req_type, "bycoord")) {
    699763        // images from a particular region of the sky
     764
    700765        if (!roiString) {
    701             fprintf(stderr, "req_type: bycoord with NULL ROI\n");
     766            fprintf(stderr, "Region of interest required with req_type: bycoord\n");
    702767            return false;
    703768        }
    704769        uris = parseByCoord(options);
    705770    } else {
     771
    706772        psError(PS_ERR_UNKNOWN, true, "unknown REQ_TYPE: %s", req_type);
    707773        return false;
     
    728794            psStringAppend(&commandArgs, " -chip %s", class_id);
    729795        }
    730 
    731796        psString user_tag = psMetadataLookupStr(&status, options->md, "USER_TAG");
    732         if (user_tag == NULL) {
    733             psError(PS_ERR_UNKNOWN, true, "no user tag in request file");
    734             return false;
    735         }
    736797
    737798        if (options->mode == PSP_MODE_LIST_JOB) {
    738799            if (numURIs == 1) {
    739                 printf("%s %s %s\n", (psString) uris->data[0], user_tag, commandArgs);
     800                printf("%s %s %s %s\n", job_type, (psString) uris->data[0],
     801                    user_tag ? user_tag : "", commandArgs ? commandArgs : "") ;
    740802            } else {
    741803                // add an integer to the user_tag
    742804                for (int i = 0; i < numURIs; i++) {
    743                     printf("%s %s_%d %s\n", (psString) uris->data[i], user_tag, i, commandArgs);
     805                    printf("%s %s %s_%d %s\n", job_type, (psString) uris->data[i], user_tag, i,
     806                        commandArgs ? commandArgs :"");
    744807                }
    745808            }
    746809        } else if (options->mode == PSP_MODE_QUEUE_JOB) {
    747810
    748             if (!queueJobs(options, uris, user_tag, commandArgs)) {
    749                 return false;
     811            if (!strcmp(job_type, "stamp")) {
     812                // Postage stamp job
     813                if (user_tag == NULL) {
     814                    psError(PS_ERR_UNKNOWN, true, "no user tag in request file");
     815                    return false;
     816                }
     817
     818                if (!queueJobs(options, job_type, uris, user_tag, commandArgs)) {
     819                    return false;
     820                }
     821            } else {
     822
     823                return queueGetImageJob(options, uris, req_type);
    750824            }
    751825
  • trunk/pstamp/src/pstamprequest.c

    r16898 r16933  
    105105    psMetadata *md = psMetadataAlloc();
    106106    int         argnum;
    107     bool        gotStyle = false;
     107    bool        gotStyle  = false;
    108108    bool        needCoord = false;
    109109    bool        gotCenter = false;
    110     bool        gotRange = false;
    111     bool        needROI = true;
     110    bool        gotRange  = false;
     111    bool        needROI   = true;
    112112    bool        makeStamps = true;
    113113
     
    116116    psMetadataAdd (md, PS_LIST_TAIL, "VERSION", PS_DATA_STRING, "", STAMP_REQUEST_VERSION);
    117117
     118    // These mode arguments should be consistent with pstampparse
    118119    if ((argnum = psArgumentGet(argc, argv, "-list"))) {
    119         psMetadataAdd (md, PS_LIST_TAIL, "CMD_MODE", PS_DATA_STRING, "", "LIST_URI");
     120        psMetadataAdd (md, PS_LIST_TAIL, "CMD_MODE", PS_DATA_STRING, "", "list_uri");
    120121        psArgumentRemove(argnum, &argc, argv);
    121122        // we don't need coordinates if we're listing unless mode is -bycoord. May be set true below.
     
    123124        makeStamps = false;
    124125    }
     126
     127    if ((argnum = psArgumentGet(argc, argv, "-get_image"))) {
     128        psMetadataAdd (md, PS_LIST_TAIL, "JOB_TYPE", PS_DATA_STRING, "", "get_image");
     129        psArgumentRemove(argnum, &argc, argv);
     130        // we don't need coordinates if we're listing unless mode is -bycoord. May be set true below.
     131        needROI = false;   
     132        makeStamps = false;
     133    } else {
     134        psMetadataAdd (md, PS_LIST_TAIL, "JOB_TYPE", PS_DATA_STRING, "", "stamp");
     135    }
     136
    125137
    126138    // get project from command line
Note: See TracChangeset for help on using the changeset viewer.