00001
00002
00003
00004
00005
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 #include "jsoc_main.h"
00221 #include "drms.h"
00222 #include "drms_names.h"
00223 #include "cmdparams.h"
00224 #include "drmssite_info.h"
00225 #include "printk.h"
00226 #include "qDecoder.h"
00227
00228
00229 #define kArgParseRS "e"
00230
00231 struct SIParts_struct
00232 {
00233 char *series;
00234 char *filter;
00235 };
00236 typedef struct SIParts_struct SIParts_t;
00237
00238 ModuleArgs_t module_args[] =
00239 {
00240 {ARG_STRING, "ds", "Not Specified", "<record_set query>"},
00241 {ARG_STRING, "key", "Not Specified", "<comma delimited keyword list>"},
00242 {ARG_STRING, "seg", "Not Specified", "<comma delimited segment list>"},
00243 {ARG_FLAG, "a", "0", "Show info for all keywords"},
00244 {ARG_FLAG, "A", "0", "Show info for all segments"},
00245 {ARG_FLAG, "b", NULL, "Disable prime-key logic"},
00246 {ARG_FLAG, "c", "0", "Show count of records in query"},
00247 {ARG_FLAG, "d", "0", "Show dimensions of segment files with selected segs"},
00248 {ARG_FLAG, "e", NULL, "Parse the provided record-set query into seriesnames and filters"},
00249 {ARG_FLAG, "h", "0", "help - print usage info"},
00250 {ARG_FLAG, "i", "0", "print record query, for each record, will be before any keywwords or segment data"},
00251 {ARG_FLAG, "I", "0", "print session information for record creation, host, sessionid, runtime, jsoc_version, and logdir"},
00252 {ARG_FLAG, "j", "0", "list series info in jsd format"},
00253 {ARG_FLAG, "k", "0", "keyword list one per line"},
00254 {ARG_FLAG, "l", "0", "just list series keywords with descriptions"},
00255 {ARG_FLAG, "K", "0", "Show info for all links"},
00256 {ARG_INT, "n", "0", "number of records to show, +from first, -from last"},
00257 {ARG_FLAG, "o", "0", "list the record\'s storage_unit online status"},
00258 {ARG_FLAG, "O", NULL, "disable the code that sets a database query time-out of 10 minutes"},
00259 {ARG_FLAG, "p", "0", "list the record\'s storage_unit path"},
00260 {ARG_FLAG, "P", "0", "list the record\'s storage_unit path but no retrieve"},
00261 {ARG_FLAG, "q", "0", "quiet - skip header of chosen keywords"},
00262 {ARG_FLAG, "r", "0", "recnum - show record number as first keyword"},
00263 {ARG_FLAG, "R", "0", "show the online retention date, i.e. expire date"},
00264 {ARG_FLAG, "s", "0", "stats - show some statistics about the series"},
00265 {ARG_FLAG, "S", "0", "SUNUM - show the sunum for the record"},
00266 {ARG_FLAG, "t", "0", "types - show types and print formats for keyword values"},
00267 {ARG_FLAG, "T", "0", "tapeinfo - show archive tapename and file number, or NA if not archived"},
00268 {ARG_FLAG, "v", NULL, "verbosity"},
00269 {ARG_FLAG, "x", "0", "archive - show archive status for storage unit"},
00270 {ARG_FLAG, "z", "0", "size - show size of storage unit containing record's segments"},
00271 {ARG_INTS, "sunum", "-1", "A list of comma-separated SUNUMs, find matching records"},
00272 {ARG_STRING, "QUERY_STRING", "Not Specified", "show_info called as cgi-bin program args here"},
00273 {ARG_END}
00274 };
00275
00276 char *module_name = "show_info";
00277 int nice_intro ()
00278 {
00279 int usage = cmdparams_get_int (&cmdparams, "h", NULL);
00280 if (usage)
00281 {
00282 printf ("Usage:\nshow_info [-ahjklpqr] "
00283 "ds=<recordset query> {n=0} {key=<keylist>} {seg=<segment_list>}\n"
00284 "sunum=<sunum> - use instead of ds= argument when SUNUM is known.\n"
00285 " summary information modes are:\n"
00286 " -c: count records in query\n"
00287 " -h: help - show this message then exit\n"
00288 " -j: list all series, keyword, segment, and link items in jsd file format, then exit\n"
00289 " -l: list all keywords with description, then exit\n"
00290 " -s: stats - show some statistics for how many records, etc.\n"
00291 " per-record information modes are:\n"
00292 " -a: show information for all keywords\n"
00293 " -A: show information for all segments\n"
00294 " -b: disable prime-key logic when opening records\n"
00295 " -d: Show dimensions of segment files with selected segs\n"
00296 " -i: query- show the record query that matches the current record\n"
00297 " -I: print session information for record creation, host, sessionid, runtime, jsoc_version, and logdir\n"
00298 " -K: show information for all links\n"
00299 " -o: online - tell the online state\n"
00300 " -O: disable the code that sets a database query time-out of 10 minutes\n"
00301 " -p: list the record's storage_unit path (retrieve if necessary)\n"
00302 " -P: list the record's storage_unit path (no retrieve)\n"
00303 " -r: recnum - show record number as first keyword\n"
00304 " -R: retention - show the online expire date\n"
00305 " -S: sunum - show sunum number as first keyword (but after recnum)\n"
00306 " -T: Tapename - show archive tapename and file number \n"
00307 " -v: verbose - print extra, useful information\n"
00308 " -x: archive - show archive status for the record's storage unit\n"
00309 " -z: size - show size of storage unit containing record's segments\n"
00310 " output appearance control flags are:\n"
00311 " -k: list keyword names and values, one per line\n"
00312 " -t: list keyword types and print formats as 2nd and 3rd lines in table mode\n"
00313 " -v: print extra, helpful information"
00314 " -q: quiet - skip header of chosen keywords\n"
00315 "ds=<recordset query> as <series>{[record specifier]} - required\n"
00316 "n=0 number of records in query to show, +n from start or -n from end\n"
00317 "key=<comma delimited keyword list>, for all use -a flag\n"
00318 "seg=<comma delimited segment list>, for all use -A flag\n"
00319 "The -p or -P flag will show the record directory by itself or as part of the\n"
00320 "full path to the segment file if seg=<segmentname> is specified.\n"
00321 "Note that the -p flag will cause the data to be staged if offline.\n");
00322 return(1);
00323 }
00324 return (0);
00325 }
00326
00327
00328 DRMS_RecordSet_t *drms_find_rec_first(DRMS_Record_t *rec, int wantprime)
00329 {
00330 int nprime;
00331 int status;
00332 DRMS_RecordSet_t *rs;
00333 char query[DRMS_MAXQUERYLEN];
00334 strcpy(query, rec->seriesinfo->seriesname);
00335 nprime = rec->seriesinfo->pidx_num;
00336 if (wantprime && nprime > 0)
00337
00338
00339 strcat(query, "[#^]");
00340 else
00341 strcat(query, "[:#^]");
00342 rs = drms_open_nrecords(rec->env, query, 1, &status);
00343 return(rs);
00344 }
00345
00346
00347 DRMS_RecordSet_t *drms_find_rec_last(DRMS_Record_t *rec, int wantprime)
00348 {
00349 int nprime;
00350 int status;
00351 DRMS_RecordSet_t *rs;
00352 char query[DRMS_MAXQUERYLEN];
00353 strcpy(query, rec->seriesinfo->seriesname);
00354 nprime = rec->seriesinfo->pidx_num;
00355 if (wantprime && nprime > 0)
00356
00357
00358 strcat(query, "[#$]");
00359 else
00360 strcat(query, "[:#$]");
00361 rs = drms_open_nrecords(rec->env, query, -1, &status);
00362 return(rs);
00363 }
00364
00365
00366 static void list_series_info(DRMS_Record_t *rec)
00367 {
00368 DRMS_Keyword_t *key;
00369 DRMS_Segment_t *seg;
00370 DRMS_Link_t *link;
00371 HIterator_t *last = NULL;
00372 char prevKeyName[DRMS_MAXNAMELEN] = "";
00373 char baseKeyName[DRMS_MAXNAMELEN];
00374
00375
00376 int npkeys = rec->seriesinfo->pidx_num;
00377 if (npkeys > 0)
00378 {
00379 int i;
00380 printf("Prime Keys are:\n");
00381 for (i=0; i<npkeys; i++)
00382 {
00383 DRMS_Keyword_t *skey, *pkey;
00384 int status;
00385 skey = pkey = rec->seriesinfo->pidx_keywords[i];
00386 if (pkey->info->recscope > 1)
00387 pkey = drms_keyword_slotfromindex(pkey);
00388 printf("\t%s", pkey->info->name);
00389 if (pkey != skey)
00390 {
00391 printf(" is slotted '%s' using %s",
00392 drms_keyword_getrecscopestr(pkey, &status), skey->info->name);
00393 }
00394 printf("\n");
00395 }
00396 }
00397 else
00398 printf("No Prime Keys are defined for this series.\n");
00399
00400
00401 if (rec->seriesinfo->dbidx_num > 0)
00402 {
00403 int i;
00404 printf("DB Index Keys are:\n");
00405 for (i=0; i<rec->seriesinfo->dbidx_num; i++)
00406 printf("\t%s\n",(rec->seriesinfo->dbidx_keywords[i])->info->name);
00407 }
00408 else
00409 printf("DB Index Keys are same as Prime Keys\n");
00410
00411
00412 printf("All Keywords for series %s:\n",rec->seriesinfo->seriesname);
00413
00414 while ((key = drms_record_nextkey(rec, &last, 0)))
00415 {
00416 int persegment = key->info->kwflags & kKeywordFlag_PerSegment;
00417 if (persegment)
00418 {
00419 char *underscore;
00420 strcpy(baseKeyName, key->info->name);
00421 underscore = rindex(baseKeyName, '_');
00422 if (underscore) *underscore = '\0';
00423 if (strcmp(prevKeyName, baseKeyName) == 0)
00424 continue;
00425 strcpy(prevKeyName, baseKeyName);
00426 }
00427 if (!drms_keyword_getimplicit(key))
00428 {
00429 printf ("\t%-10s", (persegment ? baseKeyName : key->info->name));
00430 if (key->info->islink)
00431 {
00432 printf("\tlink through %s",key->info->linkname);
00433 }
00434 else
00435 {
00436 printf ("\t(%s)", drms_type_names[key->info->type]);
00437 if (persegment)
00438 printf(", per-segment");
00439 }
00440 printf ("\t%s\n", key->info->description);
00441 }
00442 }
00443
00444
00445 if (rec->segments.num_total)
00446 {
00447 printf("Segments for series %s:\n",rec->seriesinfo->seriesname);
00448
00449 if (last)
00450 {
00451 hiter_destroy(&last);
00452 }
00453
00454 while ((seg = drms_record_nextseg(rec, &last, 0)))
00455 {
00456 if (seg->info->islink)
00457 {
00458 printf("\tlink through %s",seg->info->linkname);
00459 }
00460 else
00461 {
00462 char prot[DRMS_MAXNAMELEN];
00463 int iaxis, naxis = seg->info->naxis;
00464 strcpy(prot, drms_prot2str(seg->info->protocol));
00465 printf ("\t%-10s", seg->info->name);
00466 printf ("\t%7s", seg->info->unit);
00467 printf ("\t%7s",prot);
00468 for (iaxis=0; iaxis<naxis; iaxis++)
00469 {
00470 if (iaxis == 0)
00471 printf("\t");
00472 else
00473 printf("x");
00474 if (seg->info->scope == DRMS_VARDIM)
00475 printf("VAR");
00476 else
00477 printf("%d",seg->axis[iaxis]);
00478 }
00479 }
00480 printf ("\t%s\n", seg->info->description);
00481 }
00482 }
00483
00484
00485 if (rec->links.num_total)
00486 {
00487 printf("Links for series %s:\n",rec->seriesinfo->seriesname);
00488
00489 if (last)
00490 {
00491 hiter_destroy(&last);
00492 }
00493 while ((link = drms_record_nextlink(rec, &last)))
00494 {
00495 printf ("\t%-10s", link->info->name);
00496 if (link->info->type == STATIC_LINK)
00497 printf("\tSTATIC");
00498 else
00499 printf("\tDYNAMIC");
00500 printf ("\t%s", link->info->target_series);
00501 printf ("\t%s\n", link->info->description);
00502 }
00503 }
00504
00505 if (last)
00506 {
00507 hiter_destroy(&last);
00508 }
00509
00510 return;
00511 }
00512
00513
00514 #define show_info_return(status) \
00515 { \
00516 if (suinfo) \
00517 { \
00518 hcon_destroy(&suinfo); \
00519 } \
00520 if (given_sunum) \
00521 { \
00522 free(given_sunum); \
00523 given_sunum = NULL; \
00524 } \
00525 if (sunum_rs_query) \
00526 { \
00527 free(sunum_rs_query); \
00528 sunum_rs_query = NULL; \
00529 } \
00530 return(status); \
00531 } \
00532
00533
00534
00535
00536
00537
00538
00539 int get_session_info(DRMS_Record_t *rec, char **runhost, char **runtime, char **jsoc_vers, char **logdir)
00540 {
00541 int status;
00542 char query[DRMS_MAXQUERYLEN];
00543 DB_Text_Result_t *qres;
00544
00545 sprintf(query, "select sunum, hostname, starttime, jsoc_version "
00546 " from %s.drms_session where sessionid=%lld", rec->sessionns, rec->sessionid);
00547 if ((qres = drms_query_txt(drms_env->session, query)) && qres->num_rows>0)
00548 {
00549 if (qres->field[0][0][0] == '\0')
00550 *logdir = strdup("No log available");
00551 else
00552 {
00553 SUM_info_t *sinfo = rec->suinfo;
00554 if (!sinfo)
00555 *logdir = strdup("Log Lost");
00556 else if (strcmp("N", sinfo->online_status) == 0)
00557 *logdir = strdup("Log offline");
00558 else
00559 *logdir = strdup(sinfo->online_loc);
00560 }
00561 if (qres->field[0][1][0] == '\0')
00562 *runhost = strdup("No host");
00563 else
00564 *runhost = strdup(qres->field[0][1]);
00565 if (qres->field[0][2][0] == '\0')
00566 *runtime = strdup("No time");
00567 else
00568 *runtime = strdup(qres->field[0][2]);
00569 if (qres->field[0][3][0] == '\0')
00570 *jsoc_vers = strdup("No version");
00571 else
00572 *jsoc_vers = strdup(qres->field[0][3]);
00573 status = 0;
00574 }
00575 else
00576 status = 1;
00577 if (qres) db_free_text_result(qres);
00578 return status;
00579 }
00580
00581 static void ShowInfoFreeInfo(const void *value)
00582 {
00583 SUM_info_t *tofree = *((SUM_info_t **)value);
00584 if (tofree)
00585 {
00586 free(tofree);
00587 }
00588 }
00589
00590 static int GetSUMinfo(DRMS_Env_t *env, HContainer_t **info, int64_t *given_sunum, int nsunums)
00591 {
00592 int status = DRMS_SUCCESS;
00593
00594 if (info && given_sunum && nsunums > 0)
00595 {
00596 SUM_info_t **infostructs = NULL;
00597 int iremote;
00598 DRMS_StorageUnit_t **sus = NULL;
00599 int iinfo;
00600 LinkedList_t *remotesunums = NULL;
00601
00602 int natts;
00603
00604 *info = hcon_create(sizeof(SUM_info_t *), 128, ShowInfoFreeInfo, NULL, NULL, NULL, 0);
00605 infostructs = (SUM_info_t **)calloc(nsunums, sizeof(SUM_info_t *));
00606
00607 natts = 1;
00608 while (natts <= 2)
00609 {
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622 status = drms_getsuinfo(env, (long long *)given_sunum, nsunums, infostructs);
00623
00624 if (status != DRMS_SUCCESS)
00625 {
00626 fprintf(stderr, "drms_record_getinfo(): failure calling drms_getsuinfo(), error code %d.\n", status);
00627 break;
00628 }
00629 else
00630 {
00631
00632 for (iinfo = 0, iremote = 0; iinfo < nsunums; iinfo++)
00633 {
00634
00635
00636 if (!drmssite_sunum_is_local(infostructs[iinfo]->sunum) && *(infostructs[iinfo]->online_loc) == '\0')
00637 {
00638 printf("### show_info: SUNUM '%llu' unknown to local SUMS - initiating remotesums call.\n", (unsigned long long)infostructs[iinfo]->sunum);
00639
00640 if (!remotesunums)
00641 {
00642 remotesunums = list_llcreate(sizeof(long long), NULL);
00643 }
00644
00645 list_llinserttail(remotesunums, &(infostructs[iinfo]->sunum));
00646 iremote++;
00647 }
00648 }
00649 }
00650
00651 if (status)
00652 {
00653 break;
00654 }
00655
00656 if (iremote > 0)
00657 {
00658 if (natts == 1)
00659 {
00660
00661 int isu;
00662 DRMS_StorageUnit_t *su = NULL;
00663 ListNode_t *node = NULL;
00664 int suret = DRMS_SUCCESS;
00665
00666 sus = malloc(sizeof(DRMS_StorageUnit_t *) * iremote);
00667 list_llreset(remotesunums);
00668
00669 for (isu = 0; isu < iremote; isu++)
00670 {
00671 sus[isu] = malloc(sizeof(DRMS_StorageUnit_t));
00672 su = sus[isu];
00673
00674 node = list_llnext(remotesunums);
00675
00676 su->sunum = *((long long *)node->data);
00677 *(su->sudir) = '\0';
00678 su->mode = DRMS_READONLY;
00679 su->nfree = 0;
00680 su->state = NULL;
00681 su->recnum = NULL;
00682 su->refcount = 0;
00683 su->seriesinfo = NULL;
00684 }
00685
00686
00687
00688
00689 suret = drms_getsudirs(env, sus, iremote, 1, 0);
00690
00691 if (suret == DRMS_REMOTESUMS_TRYLATER)
00692 {
00693 fprintf(stdout, "Master remote SUMS script is ingesting"
00694 " storage unit asynchronously.\nRetry query later.\n");
00695 status = suret;
00696 break;
00697 }
00698 else if (suret != DRMS_SUCCESS)
00699 {
00700 printf("### show_info: Error calling drms_getsudirs(), must quit\n");
00701 status = suret;
00702 break;
00703 }
00704
00705
00706
00707 if (infostructs)
00708 {
00709 for (iinfo = 0; iinfo < nsunums; iinfo++)
00710 {
00711 if (infostructs[iinfo])
00712 {
00713 free(infostructs[iinfo]);
00714 infostructs[iinfo] = NULL;
00715 }
00716 }
00717 }
00718
00719 if (remotesunums)
00720 {
00721 list_llfree(&remotesunums);
00722 }
00723
00724 if (sus)
00725 {
00726 for (isu = 0; isu < iremote; isu++)
00727 {
00728 su = sus[isu];
00729 if (su)
00730 {
00731 free(su);
00732 su = NULL;
00733 }
00734 }
00735 }
00736 }
00737 else
00738 {
00739
00740
00741 printf("### show_info: at least one SUNUM was invalid.\n");
00742 status = DRMS_ERROR_INVALIDSU;
00743 break;
00744 }
00745 }
00746 else
00747 {
00748 break;
00749 }
00750
00751 natts++;
00752 }
00753
00754 if (status == DRMS_SUCCESS)
00755 {
00756 if (*info)
00757 {
00758 char key[128];
00759
00760
00761 for (iinfo = 0; iinfo < nsunums; iinfo++)
00762 {
00763 snprintf(key, sizeof(key), "%llu", (unsigned long long)infostructs[iinfo]->sunum);
00764 hcon_insert(*info, key, &(infostructs[iinfo]));
00765 }
00766 }
00767 }
00768 else
00769 {
00770 if (infostructs)
00771 {
00772
00773 for (iinfo = 0; iinfo < nsunums; iinfo++)
00774 {
00775 if (infostructs[iinfo])
00776 {
00777 free(infostructs[iinfo]);
00778 }
00779 }
00780 }
00781
00782 if (*info)
00783 {
00784 hcon_destroy(info);
00785 }
00786 }
00787
00788 if (infostructs)
00789 {
00790 free(infostructs);
00791 }
00792
00793 if (remotesunums)
00794 {
00795 list_llfree(&remotesunums);
00796 }
00797
00798 if (sus)
00799 {
00800 free(sus);
00801 }
00802 }
00803
00804 return status;
00805 }
00806
00807 #if 0
00808 static int susort(const void *a, const void *b)
00809 {
00810 SUM_info_t *first = (SUM_info_t *)hcon_getval(*((HContainerElement_t **)a));
00811 SUM_info_t *second = (SUM_info_t *)hcon_getval(*((HContainerElement_t **)b));
00812
00813 XASSERT(first && second);
00814
00815 return strcasecmp(first->owning_series, second->owning_series);
00816 }
00817 #endif
00818
00819
00820
00821 static int PrintHeader(DRMS_Env_t *env, const char* series, const char *keylist, const char *seglist, int show_all, int show_keys, int show_all_segs, int show_segs, int show_all_links, int quiet, int keyword_list, int show_recnum, int show_sunum, int show_recordspec, int show_online, int show_retention, int show_archive, int show_tapeinfo, int show_size, int show_session, int want_dims, int want_path, int show_types, char **keys, int *nkeys, char **segs, int *nsegs, int *linked_segs, char **links, int *nlinks)
00822 {
00823 int drmsstat;
00824 int iseg;
00825 int col;
00826 int ikey;
00827 int ilink;
00828 DRMS_Record_t *rec;
00829
00830 rec = NULL;
00831
00832 if (series)
00833 {
00834 rec = drms_template_record(env, series, &drmsstat);
00835
00836 if (drmsstat != DRMS_SUCCESS || !rec)
00837 {
00838 return drmsstat;
00839 }
00840 }
00841
00842
00843 if (nkeys)
00844 {
00845 *nkeys = 0;
00846 }
00847
00848 if (rec)
00849 {
00850 if (show_all)
00851 {
00852 DRMS_Keyword_t *key;
00853 HIterator_t *last = NULL;
00854
00855 while ((key = drms_record_nextkey(rec, &last, 0)))
00856 {
00857 if (!drms_keyword_getimplicit(key))
00858 {
00859 keys[(*nkeys)++] = strdup (key->info->name);
00860 }
00861 }
00862
00863 if (last)
00864 {
00865 hiter_destroy(&last);
00866 }
00867
00868 }
00869 else if (show_keys)
00870 {
00871 char *thiskey;
00872 for (thiskey=strtok(keylist, ","); thiskey; thiskey=strtok(NULL,","))
00873 keys[(*nkeys)++] = strdup(thiskey);
00874 }
00875 }
00876
00877 if (rec)
00878 {
00879
00880
00881
00882
00883
00884 *nsegs = 0;
00885 if (show_all_segs)
00886 {
00887 DRMS_Segment_t *seg;
00888 HIterator_t *last = NULL;
00889
00890 while ((seg = drms_record_nextseg(rec, &last, 0)))
00891 segs[(*nsegs)++] = strdup (seg->info->name);
00892
00893 if (last)
00894 {
00895 hiter_destroy(&last);
00896 }
00897 }
00898 else if (show_segs)
00899 {
00900 char *thisseg;
00901 for (thisseg=strtok(seglist, ","); thisseg; thisseg=strtok(NULL,","))
00902 {
00903 segs[(*nsegs)++] = strdup(thisseg);
00904 }
00905 }
00906
00907 for (iseg = 0; iseg<*nsegs; iseg++)
00908 {
00909 DRMS_Segment_t *seg = hcon_lookup_lower(&rec->segments, segs[iseg]);
00910 if (seg && seg->info && seg->info->islink)
00911 (*linked_segs)++;
00912 }
00913 }
00914
00915 if (rec)
00916 {
00917
00918
00919 *nlinks = 0;
00920 if (show_all_links)
00921 {
00922 DRMS_Link_t *link;
00923 HIterator_t *last = NULL;
00924
00925 while ((link = drms_record_nextlink(rec, &last)))
00926 links[(*nlinks)++] = strdup (link->info->name);
00927
00928 if (last)
00929 {
00930 hiter_destroy(&last);
00931 }
00932
00933 }
00934 }
00935
00936 if (!quiet && !keyword_list)
00937 {
00938
00939 col=0;
00940 if (show_recnum)
00941 printf ("%srecnum", (col++ ? "\t" : ""));
00942 if (show_sunum)
00943 printf ("%ssunum", (col++ ? "\t" : ""));
00944 if (show_recordspec)
00945 printf ("%squery", (col++ ? "\t" : ""));
00946 if (show_online)
00947 printf ("%sonline", (col++ ? "\t" : ""));
00948 if (show_retention)
00949 printf ("%sretain", (col++ ? "\t" : ""));
00950 if (show_archive)
00951 printf ("%sarchive", (col++ ? "\t" : ""));
00952 if (show_tapeinfo)
00953 {
00954 printf ("%stapename", (col++ ? "\t" : ""));
00955 printf ("%sfilenum", (col++ ? "\t" : ""));
00956 }
00957 if (show_size)
00958 printf ("%ssize", (col++ ? "\t" : ""));
00959 if (show_session)
00960 printf ("%shost\tsessionid\truntime\tjsoc_version\tlogdirectory", (col++ ? "\t" : ""));
00961
00962
00963
00964 if (keys)
00965 {
00966 for (ikey=0 ; ikey<*nkeys; ikey++)
00967 {
00968 printf ("%s%s", (col++ ? "\t" : ""), keys[ikey]);
00969 }
00970 }
00971
00972 if (segs)
00973 {
00974 for (iseg = 0; iseg<*nsegs; iseg++)
00975 {
00976 printf ("%s%s", (col++ ? "\t" : ""), segs[iseg]);
00977 if (want_dims)
00978 {
00979 printf("\t%s_info", segs[iseg]);
00980 }
00981 }
00982 }
00983
00984 if ((!segs || *nsegs==0) && want_path)
00985 printf("%sSUDIR", (col++ ? "\t" : ""));
00986
00987 if (links)
00988 {
00989 for (ilink=0 ; ilink<*nlinks; ilink++)
00990 {
00991 printf ("%s%s", (col++ ? "\t" : ""), links[ilink]);
00992 }
00993 }
00994
00995 printf ("\n");
00996
00997
00998 if (show_types)
00999 {
01000 col=0;
01001
01002
01003 if (show_recnum)
01004 printf ("%slonglong", (col++ ? "\t" : ""));
01005 if (show_sunum)
01006 printf ("%slonglong", (col++ ? "\t" : ""));
01007 if (show_recordspec)
01008 printf ("%sstring", (col++ ? "\t" : ""));
01009 if (show_online)
01010 printf ("%sstring", (col++ ? "\t" : ""));
01011 if (show_retention)
01012 printf ("%sstring", (col++ ? "\t" : ""));
01013 if (show_archive)
01014 printf ("%sstring", (col++ ? "\t" : ""));
01015 if (show_tapeinfo)
01016 {
01017 printf ("%sstring", (col++ ? "\t" : ""));
01018 printf ("%sint", (col++ ? "\t" : ""));
01019 }
01020 if (show_size)
01021 printf ("%slonglong", (col++ ? "\t" : ""));
01022 if (show_session)
01023 printf ("%sstring\tlonglong\tstring\tstring\tstring", (col++ ? "\t" : ""));
01024
01025
01026
01027
01028 if (keys)
01029 {
01030 for (ikey=0 ; ikey<*nkeys; ikey++)
01031 {
01032 DRMS_Keyword_t *rec_key_ikey = drms_keyword_lookup (rec, keys[ikey], 1);
01033 if (rec_key_ikey)
01034 printf ("%s%s", (col++ ? "\t" : ""), drms_type_names[rec_key_ikey->info->type]);
01035 else
01036 printf ("%s%s", (col++ ? "\t" : ""), "TBD");
01037 }
01038 }
01039
01040 if (segs)
01041 {
01042 for (iseg = 0; iseg<*nsegs; iseg++)
01043 {
01044 DRMS_Segment_t *rec_seg_iseg = drms_segment_lookup (rec, segs[iseg]);
01045 printf ("%s%s", (col++ ? "\t" : ""), drms_prot2str(rec_seg_iseg->info->protocol));
01046 if (want_dims)
01047 printf ("\tstring");
01048 }
01049 }
01050
01051 if ((!segs || *nsegs==0) && want_path)
01052 {
01053 printf ("%sstring", (col++ ? "\t" : ""));
01054 }
01055
01056 if (links)
01057 {
01058 for (ilink=0 ; ilink<*nlinks; ilink++)
01059 {
01060 DRMS_Link_t *rec_link = hcon_lookup_lower(&rec->links,links[ilink]);
01061 printf ("%s%s", (col++ ? "\t" : ""), rec_link->info->type == DYNAMIC_LINK ? "dynamic" : "static");
01062 }
01063 }
01064
01065 printf ("\n");
01066
01067
01068
01069 col=0;
01070 if (show_recnum)
01071 printf ("%s%%lld", (col++ ? "\t" : ""));
01072 if (show_sunum)
01073 printf ("%s%%lld", (col++ ? "\t" : ""));
01074 if (show_recordspec)
01075 printf ("%s%%s", (col++ ? "\t" : ""));
01076 if (show_online)
01077 printf ("%s%%s", (col++ ? "\t" : ""));
01078 if (show_retention)
01079 printf ("%s%%s", (col++ ? "\t" : ""));
01080 if (show_archive)
01081 printf ("%s%%s", (col++ ? "\t" : ""));
01082 if (show_tapeinfo)
01083 {
01084 printf ("%s%%s", (col++ ? "\t" : ""));
01085 printf ("%s%%04d", (col++ ? "\t" : ""));
01086 }
01087 if (show_size)
01088 printf ("%s%%lld", (col++ ? "\t" : ""));
01089 if (show_session)
01090 printf ("%s%%s\t%%lld\t%%s\t%%s\t%%s", (col++ ? "\t" : ""));
01091
01092
01093
01094 if (keys)
01095 {
01096 for (ikey=0 ; ikey<*nkeys; ikey++)
01097 {
01098 DRMS_Keyword_t *rec_key_ikey = drms_keyword_lookup (rec, keys[ikey], 1);
01099 if (rec_key_ikey)
01100 {
01101 if (rec_key_ikey->info->type == DRMS_TYPE_TIME)
01102 printf ("%s%%s", (col++ ? "\t" : ""));
01103 else
01104 printf ("%s%s", (col++ ? "\t" : ""), rec_key_ikey->info->format);
01105 }
01106 else
01107 printf ("%s%s", (col++ ? "\t" : ""), "TBD");
01108 }
01109 }
01110
01111 if (segs)
01112 {
01113 for (iseg = 0; iseg<*nsegs; iseg++)
01114 {
01115 printf ("%s%%s", (col++ ? "\t" : ""));
01116 if (want_dims)
01117 printf ("%s%%s", (col++ ? "\t" : ""));
01118 }
01119 }
01120
01121 if ((!segs || *nsegs==0) && want_path)
01122 printf ("%s%%s", (col++ ? "\t" : ""));
01123
01124 if (links)
01125 {
01126 for (ilink = 0; ilink<*nlinks; ilink++)
01127 {
01128 printf ("%s%%s", (col++ ? "\t" : ""));
01129 }
01130 }
01131 printf ("\n");
01132 }
01133 }
01134
01135 return DRMS_SUCCESS;
01136 }
01137
01138 static void PrintKeyInfo(int *col, DRMS_Record_t *rec, char **keys, int nkeys, int keyword_list)
01139 {
01140 int ikey;
01141
01142
01143 for (ikey=0; ikey<nkeys; ikey++)
01144 {
01145 DRMS_Keyword_t *rec_key_ikey = drms_keyword_lookup (rec, keys[ikey], 1);
01146 if (rec_key_ikey)
01147 {
01148 if (keyword_list)
01149 {
01150 printf("%s=", keys[ikey]);
01151 if (rec_key_ikey->info->type != DRMS_TYPE_STRING)
01152 drms_keyword_printval (rec_key_ikey);
01153 else
01154 {
01155 printf("\"");
01156 drms_keyword_printval (rec_key_ikey);
01157
01158 printf("\"");
01159 }
01160 printf("\n");
01161 }
01162 else
01163 {
01164 if ((*col)++)
01165 printf ("\t");
01166 drms_keyword_printval (rec_key_ikey);
01167
01168 }
01169 }
01170 else
01171 if (!keyword_list)
01172 printf ("%sInvalidKeyname", ((*col)++ ? "\t" : ""));
01173 }
01174 }
01175
01176 static int PrintSegInfo(int *col, DRMS_Record_t *rec, char **segs, int nsegs, int linked_segs, int want_path, int want_path_noret, int keyword_list, int want_dims)
01177 {
01178 int iseg;
01179 int stat;
01180
01181 stat = DRMS_SUCCESS;
01182
01183
01184 for (iseg=0; iseg<nsegs; iseg++)
01185 {
01186
01187
01188 DRMS_Segment_t *rec_seg_iseg = drms_segment_lookup (rec, segs[iseg]);
01189 if (rec_seg_iseg)
01190 {
01191 char fname[DRMS_MAXPATHLEN] = {0};
01192 char path[DRMS_MAXPATHLEN] = {0};
01193
01194 if (rec_seg_iseg->info->protocol != DRMS_DSDS && rec_seg_iseg->info->protocol != DRMS_LOCAL)
01195 {
01196 if (want_path)
01197 {
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215 if (want_path_noret)
01216 {
01217
01218 if (!rec_seg_iseg->record->su)
01219 {
01220
01221 *path = '\0';
01222 stat = DRMS_SUCCESS;
01223 }
01224 else
01225 {
01226
01227
01228 stat = drms_record_directory(rec_seg_iseg->record, path, 0);
01229 }
01230 }
01231 else
01232 {
01233
01234
01235
01236 stat = drms_record_directory(rec_seg_iseg->record, path, 1);
01237 }
01238
01239 if (stat || *path == '\0')
01240 {
01241
01242
01243 strcpy(path,"**_NO_sudir_**");
01244 }
01245 }
01246 else
01247 {
01248
01249 strcpy(path,"");
01250 }
01251
01252
01253 strncpy(fname, rec_seg_iseg->filename, DRMS_MAXPATHLEN);
01254 }
01255 else
01256 {
01257 char *tmp = strdup(rec_seg_iseg->filename);
01258 char *sep = NULL;
01259
01260 if (tmp)
01261 {
01262 if ((sep = strrchr(tmp, '/')) != NULL)
01263 {
01264 *sep = '\0';
01265 snprintf(path, sizeof(path), "%s", tmp);
01266 snprintf(fname, sizeof(fname), "%s", sep + 1);
01267 }
01268 else
01269 {
01270 snprintf(fname, sizeof(fname), "%s", tmp);
01271 }
01272
01273 free(tmp);
01274 }
01275
01276 if (!want_path)
01277 {
01278 *path = '\0';
01279 }
01280 }
01281
01282 if (keyword_list)
01283 printf("%s=", segs[iseg]);
01284 else
01285 if ((*col)++)
01286 printf("\t");
01287 printf("%s%s%s", path, (want_path ? "/" : ""), fname);
01288 if (keyword_list)
01289 printf("\n");
01290
01291 if (want_dims)
01292 {
01293 int iaxis, naxis = rec_seg_iseg->info->naxis;
01294 if (keyword_list)
01295 printf("%s_info=",segs[iseg]);
01296 else
01297 printf("\t");
01298 if (rec_seg_iseg->info->islink)
01299 sprintf("\"link to %s",rec_seg_iseg->info->linkname);
01300 else
01301 {
01302 printf("\"%s, %s, ", rec_seg_iseg->info->unit, drms_prot2str(rec_seg_iseg->info->protocol));
01303 for (iaxis=0; iaxis<naxis; iaxis++)
01304 {
01305 if (iaxis)
01306 printf("x");
01307 printf("%d",rec_seg_iseg->axis[iaxis]);
01308 }
01309 printf("\"");
01310 }
01311 if (keyword_list)
01312 printf("\n");
01313 }
01314 }
01315 else
01316 {
01317 char *nosegmsg = "InvalidSegName";
01318 DRMS_Segment_t *segment = hcon_lookup_lower(&rec->segments, segs[iseg]);
01319 if (segment && segment->info->islink)
01320 nosegmsg = "BadSegLink";
01321 if (!keyword_list)
01322 printf ("%s%s", ((*col)++ ? "\t" : ""), nosegmsg);
01323 else
01324 printf("%s=%s\n", segs[iseg], nosegmsg);
01325 }
01326 }
01327
01328 if (nsegs==0 && want_path)
01329 {
01330 char path[DRMS_MAXPATHLEN] = {0};
01331
01332 if (drms_record_numsegments(rec) <= 0)
01333 {
01334 snprintf(path,
01335 sizeof(path),
01336 "Record does not contain any segments - no record directory.");
01337 }
01338 #ifdef REVEALBUG
01339 else if (nsegs == linked_segs)
01340 {
01341 printf("All segments are links - no record directory.");
01342 }
01343 #endif
01344 else if (drms_record_isdsds(rec) || drms_record_islocal(rec))
01345 {
01346
01347
01348 DRMS_Segment_t *seg = drms_segment_lookupnum(rec, 0);
01349 if (*(seg->filename) == '\0')
01350 {
01351
01352 snprintf(path, sizeof(path), "Record has no data file.");
01353 }
01354 else
01355 {
01356 char *tmp = strdup(seg->filename);
01357 char *sep = NULL;
01358
01359 if (tmp)
01360 {
01361 if ((sep = strrchr(tmp, '/')) != NULL)
01362 {
01363 *sep = '\0';
01364 snprintf(path, sizeof(path), "%s", tmp);
01365 }
01366 else
01367 {
01368 snprintf(path, sizeof(path), "%s", tmp);
01369 }
01370
01371 free(tmp);
01372 }
01373 }
01374 }
01375 else
01376 {
01377 if (rec->su)
01378 {
01379
01380
01381 if(want_path_noret)
01382 stat=drms_record_directory (rec, path, 0);
01383 else
01384 stat=drms_record_directory (rec, path, 1);
01385 if (stat)
01386 strcpy(path,"**_NO_sudir_**");
01387 }
01388 else
01389 {
01390 strcpy(path,"**_NO_sudir_**");
01391 }
01392 }
01393
01394 if (keyword_list)
01395 printf("SUDIR=");
01396 else
01397 if ((*col)++)
01398 printf("\t");
01399 printf("%s", path);
01400 if (keyword_list)
01401 printf("\n");
01402 }
01403
01404 return stat;
01405 }
01406
01407 static void PrintLnkInfo(int *col, DRMS_Record_t *rec, char **links, int nlinks, int keyword_list)
01408 {
01409 int ilink;
01410 int status;
01411
01412
01413 for (ilink=0; ilink<nlinks; ilink++)
01414 {
01415 DRMS_Link_t *rec_link = hcon_lookup_lower(&rec->links,links[ilink]);
01416 DRMS_Record_t *linked_rec = drms_link_follow(rec, links[ilink], &status);
01417 if (linked_rec)
01418 {
01419 if (keyword_list)
01420 {
01421 printf("%s=", links[ilink]);
01422 if (rec_link->info->type == DYNAMIC_LINK)
01423 {
01424 printf("\"");
01425 drms_print_rec_query(linked_rec);
01426 printf("\"");
01427 }
01428 else
01429 {
01430 printf("\"");
01431 printf("%s[:#%lld]",linked_rec->seriesinfo->seriesname, linked_rec->recnum);
01432 printf("\"");
01433 }
01434 printf("\n");
01435 }
01436 else
01437 {
01438 if ((*col)++)
01439 printf ("\t");
01440 if (rec_link->info->type == DYNAMIC_LINK)
01441 drms_print_rec_query(linked_rec);
01442 else
01443 printf("%s[:#%lld]",linked_rec->seriesinfo->seriesname, linked_rec->recnum);
01444 }
01445 }
01446 else
01447 if (!keyword_list)
01448 printf ("%sInvalidLink", ((*col)++ ? "\t" : ""));
01449 }
01450 }
01451
01452 static int PrintStuff(DRMS_Record_t *rec, const char *rsq, int keyword_list, int show_recnum, int show_sunum, int show_recordspec, int parseRS, int show_online, int show_retention, int show_archive, int show_tapeinfo, int show_size, int show_session, int want_path, int want_path_noret, int want_dims, char **keys, int nkeys, char **segs, int nsegs, int linked_segs, char **links, int nlinks, int nrecs, int nl, int showKeySegLink)
01453 {
01454 int col;
01455 int status = 0;
01456 int printBogus = 0;
01457 int64_t sunum = -1;
01458 int noInfoReq = 0;
01459
01460 if (!rec)
01461 {
01462
01463 printBogus = 1;
01464
01465
01466 sunum = *((int64_t *)rsq);
01467 }
01468
01469 col=0;
01470 if (keyword_list)
01471 {
01472 if (nl)
01473 printf("\n");
01474
01475 if (printBogus)
01476 {
01477 printf("# sunum=%lld\n", sunum);
01478 }
01479 else
01480 {
01481 printf("# ");
01482 drms_print_rec_query(rec);
01483 }
01484 printf("\n");
01485 }
01486
01487 if (show_recnum)
01488 {
01489 if (printBogus)
01490 {
01491 if (keyword_list)
01492 printf("## recnum=NA\n");
01493 else
01494 printf ("%sNA", (col++ ? "\t" : ""));
01495 }
01496 else
01497 {
01498 if (keyword_list)
01499 printf("## recnum=%lld\n",rec->recnum);
01500 else
01501 printf ("%s%6lld", (col++ ? "\t" : ""), rec->recnum);
01502 }
01503
01504 }
01505
01506 if (show_sunum)
01507 {
01508 if (printBogus)
01509 {
01510 if (keyword_list)
01511 printf("## sunum=%lld\n", sunum);
01512 else
01513 printf ("%s%6lld", (col++ ? "\t" : ""), sunum);
01514 }
01515 else
01516 {
01517 if (keyword_list)
01518 printf("## sunum=%lld\n",rec->sunum);
01519 else
01520 printf ("%s%6lld", (col++ ? "\t" : ""), rec->sunum);
01521 }
01522 }
01523
01524 if (!keyword_list)
01525 {
01526 if (show_recordspec)
01527 {
01528 if (col++)
01529 {
01530 printf("\t");
01531 }
01532
01533 if (printBogus)
01534 {
01535 printf("NA");
01536 }
01537 else
01538 {
01539 if (!parseRS)
01540 {
01541 drms_print_rec_query(rec);
01542 }
01543 else
01544 {
01545 char querystring[DRMS_MAXQUERYLEN];
01546 char *allvers = NULL;
01547
01548
01549 char **sets = NULL;
01550 DRMS_RecordSetType_t *settypes = NULL;
01551 char **snames = NULL;
01552 char **filts = NULL;
01553 int nsets = 0;
01554 DRMS_RecQueryInfo_t rsinfo;
01555 char *filter = NULL;
01556 int err;
01557
01558
01559 drms_sprint_rec_query(querystring, rec);
01560
01561
01562 if (drms_record_parserecsetspec(querystring, &allvers, &sets, &settypes, &snames, &filts, &nsets, &rsinfo) != DRMS_SUCCESS || nsets != 1)
01563 {
01564 printf("%s(UNPARSEABLE)", querystring);
01565 }
01566 else
01567 {
01568 filter = drms_recordset_extractfilter(rec, sets[0], &err);
01569
01570 if (!err)
01571 {
01572 printf("%s|%s", snames[0], filter);
01573 }
01574 else
01575 {
01576 printf("%s(UNPARSEABLE)", querystring);
01577 }
01578 }
01579
01580 if (filter)
01581 {
01582 free(filter);
01583 }
01584
01585 drms_record_freerecsetspecarr(&allvers, &sets, &settypes, &snames, &filts, nsets);
01586 }
01587 }
01588 }
01589 }
01590
01591 if (show_online)
01592 {
01593
01594 char *msg;
01595
01596 if (printBogus)
01597 {
01598 msg = "NA";
01599 }
01600 else
01601 {
01602 if (!rec->suinfo)
01603
01604 msg = "NA";
01605 else if (*rec->suinfo->online_loc == '\0')
01606
01607 msg = "NA";
01608 else
01609 msg = rec->suinfo->online_status;
01610 }
01611
01612 if (keyword_list)
01613 printf("## online=%s\n", msg);
01614 else
01615 printf("%s%s", (col++ ? "\t" : ""), msg);
01616 }
01617
01618 if (show_retention)
01619 {
01620
01621 char retain[20];
01622
01623 if (printBogus)
01624 {
01625 strcpy(retain, "NA");
01626 }
01627 else
01628 {
01629 if (!rec->suinfo)
01630
01631 strcpy(retain, "NA");
01632 else if (*rec->suinfo->online_loc == '\0')
01633
01634 strcpy(retain, "NA");
01635 else
01636 {
01637 int y,m,d;
01638 if (strcmp("N", rec->suinfo->online_status) == 0)
01639 strcpy(retain,"-1");
01640 else
01641 {
01642 int nscanned = sscanf(rec->suinfo->effective_date, "%4d%2d%2d", &y,&m,&d);
01643 if (nscanned == 3)
01644 sprintf(retain, "%4d.%02d.%02d",y,m,d);
01645 else
01646 strcpy(retain, "NoRetValue ");
01647 }
01648 }
01649 }
01650
01651 if (keyword_list)
01652 printf("## retain=%s\n", retain);
01653 else
01654 printf("%s%s", (col++ ? "\t" : ""), retain);
01655 }
01656
01657 if (show_archive)
01658 {
01659
01660 char *msg;
01661
01662 if (printBogus)
01663 {
01664 msg = "NA";
01665 }
01666 else
01667 {
01668 if (!rec->suinfo)
01669
01670 msg = "NA";
01671 else if (*rec->suinfo->online_loc == '\0')
01672
01673 msg = "NA";
01674 else
01675 {
01676 if(rec->suinfo->pa_status == DAAP && rec->suinfo->pa_substatus == DAADP)
01677 msg = "Pending";
01678 else
01679 msg = rec->suinfo->archive_status;
01680 }
01681 }
01682
01683 if (keyword_list)
01684 printf("## archive=%s\n", msg);
01685 else
01686 printf("%s%s", (col++ ? "\t" : ""), msg);
01687 }
01688
01689
01690 if (show_tapeinfo)
01691 {
01692
01693 char *msg;
01694 int fn;
01695
01696 if (printBogus)
01697 {
01698 msg = "NA";
01699 fn = -9999;
01700 }
01701 else
01702 {
01703 if (!rec->suinfo)
01704 {
01705
01706 msg = "NA";
01707 fn = -9999;
01708 }
01709 else if (*rec->suinfo->arch_tape == '\0')
01710 {
01711 msg = "NA";
01712 fn = -9999;
01713 }
01714 else
01715 {
01716 msg = rec->suinfo->arch_tape;
01717 fn = rec->suinfo->arch_tape_fn;
01718 }
01719 }
01720
01721 if (keyword_list)
01722 {
01723 printf("## tapename=%s\n", msg);
01724 printf("## tapeinfo=%04d\n", fn);
01725 }
01726 else
01727 {
01728 printf("%s%s", (col++ ? "\t" : ""), msg);
01729 printf("%s%04d", (col++ ? "\t" : ""), fn);
01730 }
01731 }
01732
01733 if (show_size)
01734 {
01735
01736 char size[20];
01737
01738 if (printBogus)
01739 {
01740 strcpy(size, "NA");
01741 }
01742 else
01743 {
01744 if (!rec->suinfo)
01745
01746 strcpy(size, "NA");
01747 else if (*rec->suinfo->online_loc == '\0')
01748
01749 strcpy(size, "NA");
01750 else
01751 sprintf(size, "%.0f", rec->suinfo->bytes);
01752 }
01753
01754 if (keyword_list)
01755 printf("## size=%s\n", size);
01756 else
01757 printf("%s%s", (col++ ? "\t" : ""), size);
01758 }
01759
01760 if (show_session)
01761 {
01762 char *runhost, *runtime, *jsoc_vers, *logdir;
01763 if (printBogus || get_session_info(rec, &runhost, &runtime, &jsoc_vers, &logdir))
01764 {
01765 if (keyword_list)
01766 printf("## host=ERROR\n## sessionid=ERROR\n## runtime=ERROR\njsoc_version=ERROR\nlogdir=ERROR\n");
01767 else
01768 printf("%sERROR\tERROR\tERROR\tERROR\tERROR", (col++ ? "\t" : ""));
01769 }
01770 else
01771 {
01772 if (keyword_list)
01773 printf("## host=%s\n## sessionid=%lld\n## runtime=%s\n## jsoc_version=%s\n## logdir=%s\n",
01774 runhost, rec->sessionid, runtime, jsoc_vers, logdir);
01775 else
01776 printf("%s%s\t%lld\t%s\t%s\t%s", (col++ ? "\t" : ""), runhost, rec->sessionid, runtime, jsoc_vers, logdir);
01777 free(runhost);
01778 free(runtime);
01779 free(jsoc_vers);
01780 free(logdir);
01781 }
01782 }
01783
01784
01785
01786
01787
01788 if (!printBogus)
01789 {
01790
01791
01792
01793
01794
01795
01796
01797
01798 PrintKeyInfo(&col, rec, keys, nkeys, keyword_list);
01799
01800
01801 status = PrintSegInfo(&col, rec, segs, nsegs, linked_segs, want_path, want_path_noret, keyword_list, want_dims);
01802 PrintLnkInfo(&col, rec, links, nlinks, keyword_list);
01803
01804 noInfoReq = (col == 0);
01805 }
01806 else
01807 {
01808
01809
01810 if (want_path)
01811 {
01812 if (keyword_list)
01813 {
01814 printf("SUDIR=**_NO_sudir_**\n");
01815 }
01816 else
01817 {
01818 if (col++)
01819 {
01820 printf("\t");
01821 }
01822
01823 printf("**_NO_sudir_**");
01824 }
01825 }
01826
01827 noInfoReq = ((col == 0) && !showKeySegLink);
01828 }
01829
01830 if (!keyword_list && noInfoReq)
01831 {
01832
01833
01834
01835
01836 int count = 0;
01837
01838 if (nrecs < 0)
01839 {
01840
01841
01842
01843
01844
01845 if (!printBogus)
01846 {
01847 XASSERT(rsq != NULL);
01848
01849 count = drms_count_records(rec->env, (char *)rsq, &status);
01850 if (status)
01851 {
01852 fprintf(stderr,"can't call drms_count_records() on %s.\n", rsq);
01853 return 1;
01854 }
01855 }
01856 }
01857
01858 if (!printBogus)
01859 {
01860 printf("%d records found, no other information requested\n", count);
01861 }
01862 else
01863 {
01864 printf("No information requested. Provide at least one argument that requests information be printed.\n");
01865 }
01866
01867 return 1;
01868 }
01869 if (!keyword_list && (show_recnum || show_sunum || show_recordspec || show_online || show_session ||
01870 show_retention || show_archive || show_tapeinfo || show_size || nkeys || nsegs || nlinks || want_path))
01871 printf ("\n");
01872
01873 return status;
01874 }
01875
01876
01877
01878 static int RecordLoopCursor(DRMS_Env_t *env, const char *rsq, DRMS_RecordSet_t *recordset, LinkedList_t *bogusList, int requireSUMinfo, int64_t *given_sunum, HContainer_t *suinfo, int want_path, int want_path_noret, const char* series, const char *keylist, const char *seglist, int show_all, int show_keys, int show_all_segs, int show_segs, int show_all_links, int quiet, int keyword_list, int show_recnum, int show_sunum, int show_recordspec, int parseRS, int show_online, int show_retention, int show_archive, int show_tapeinfo, int show_size, int show_session, int want_dims, int show_types, char *sunum_rs_query, char **keys, int nkeys, char **segs, int nsegs, int linked_segs, char **links, int nlinks)
01879 {
01880
01881 char key[128];
01882 SUM_info_t **ponesuinfo = NULL;
01883 int status = 0;
01884 DRMS_RecChunking_t cstat = kRecChunking_None;
01885 int newchunk;
01886 int irec;
01887 DRMS_Record_t *rec = NULL;
01888 int atleastone = 0;
01889 int64_t sunum = -1;
01890 int isu;
01891 int first;
01892
01893
01894 if (bogusList)
01895 {
01896 ListNode_t *node = NULL;
01897
01898 list_llreset(bogusList);
01899 first = 1;
01900
01901 while ((node = list_llnext(bogusList)) != NULL)
01902 {
01903 sunum = *((int64_t *)(node->data));
01904
01905
01906 if ((status = PrintStuff(NULL, (const char *)&sunum, keyword_list, show_recnum, show_sunum, show_recordspec, parseRS, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_path, want_path_noret, want_dims, keys, nkeys, segs, nsegs, linked_segs, links, nlinks, -1, !first, show_all || show_keys || show_all_segs || show_segs || show_all_links)) != 0)
01907 {
01908 first = 0;
01909 break;
01910 }
01911
01912 first = 0;
01913 }
01914 }
01915
01916 irec = 0;
01917 while (!status && recordset && ((rec = drms_recordset_fetchnext(env, recordset, &status, &cstat, &newchunk)) != NULL))
01918 {
01919 atleastone = 1;
01920
01921
01922
01923 if (status == DRMS_ERROR_QUERYFAILED)
01924 {
01925
01926 const char *emsg = DB_GetErrmsg(env->session->db_handle);
01927
01928 if (emsg)
01929 {
01930 fprintf(stderr, "DB error message: %s\n", emsg);
01931 }
01932
01933 status = 1;
01934 break;
01935 }
01936
01937 if (rec->sunum >= 0 && rec->suinfo == NULL)
01938 {
01939
01940
01941
01942
01943
01944 if (requireSUMinfo && (given_sunum && given_sunum[0] >= 0))
01945 {
01946
01947
01948 snprintf(key, sizeof(key), "%lld", rec->sunum);
01949
01950 if ((ponesuinfo = (SUM_info_t **)hcon_lookup(suinfo, key)) != NULL)
01951 {
01952
01953
01954
01955 rec->suinfo = (SUM_info_t *)malloc(sizeof(SUM_info_t));
01956 *(rec->suinfo) = **ponesuinfo;
01957 }
01958 else
01959 {
01960
01961 fprintf(stderr, "Expected SUNUM '%s' not found.\n", key);
01962 show_info_return(1);
01963 }
01964 }
01965 }
01966
01967 if (want_path && (status == DRMS_REMOTESUMS_TRYLATER || status == DRMS_ERROR_SUMSTRYLATER))
01968 {
01969
01970
01971
01972 fprintf(stdout, "One or more data files are being staged asynchronously - try again later.\n");
01973
01974
01975
01976
01977
01978
01979
01980 status = 0;
01981 break;
01982 }
01983
01984 if (status)
01985 {
01986 break;
01987 }
01988
01989 if ((status = PrintStuff(rec, rsq, keyword_list, show_recnum, show_sunum, show_recordspec, parseRS, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_path, want_path_noret, want_dims, keys, nkeys, segs, nsegs, linked_segs, links, nlinks, -1, irec != 0 || (bogusList && list_llgetnitems(bogusList) > 0), show_all || show_keys || show_all_segs || show_segs || show_all_links)) != 0)
01990 {
01991 break;
01992 }
01993
01994 irec++;
01995 }
01996
01997 if (!quiet && !atleastone)
01998 {
01999 printf ("** No records in selected data set, query was %s **\n", rsq);
02000 }
02001
02002 return status;
02003 }
02004
02005 static int RecordLoopNoCursor(DRMS_Env_t *env, DRMS_RecordSet_t *recordset, LinkedList_t *bogusList, int requireSUMinfo, int64_t *given_sunum, HContainer_t *suinfo, int want_path, int want_path_noret, const char* series, const char *keylist, const char *seglist, int show_all, int show_keys, int show_all_segs, int show_segs, int show_all_links, int quiet, int keyword_list, int show_recnum, int show_sunum, int show_recordspec, int parseRS, int show_online, int show_retention, int show_archive, int show_tapeinfo, int show_size, int show_session, int want_dims, int show_types, char *sunum_rs_query, char **keys, int nkeys, char **segs, int nsegs, int linked_segs, char **links, int nlinks)
02006 {
02007
02008 char key[128];
02009 int irec;
02010 DRMS_Record_t *rec = NULL;
02011 SUM_info_t **ponesuinfo = NULL;
02012 int status = 0;
02013 int64_t sunum = -1;
02014 int isu;
02015 int first;
02016
02017
02018 if (bogusList)
02019 {
02020 ListNode_t *node = NULL;
02021
02022 list_llreset(bogusList);
02023 first = 1;
02024 while ((node = list_llnext(bogusList)) != NULL)
02025 {
02026 sunum = *((int64_t *)(node->data));
02027
02028
02029 if ((status = PrintStuff(NULL, (const char *)&sunum, keyword_list, show_recnum, show_sunum, show_recordspec, parseRS, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_path, want_path_noret, want_dims,keys, nkeys, segs, nsegs, linked_segs, links, nlinks, -1, !first, show_all || show_keys || show_all_segs || show_segs || show_all_links)) != 0)
02030 {
02031 first = 0;
02032 break;
02033 }
02034
02035 first = 0;
02036 }
02037 }
02038
02039 for (irec = 0; !status && recordset && irec < recordset->n; irec++)
02040 {
02041 rec = recordset->records[irec];
02042
02043 if (rec->sunum >= 0)
02044 {
02045 if (requireSUMinfo && (given_sunum && given_sunum[0] >= 0))
02046 {
02047 snprintf(key, sizeof(key), "%lld", rec->sunum);
02048
02049 if ((ponesuinfo = (SUM_info_t **)hcon_lookup(suinfo, key)) != NULL)
02050 {
02051
02052 rec->suinfo = *ponesuinfo;
02053 hcon_remove(suinfo, key);
02054 }
02055 else
02056 {
02057
02058 }
02059 }
02060 }
02061
02062 if ((status = PrintStuff(rec, NULL, keyword_list, show_recnum, show_sunum, show_recordspec, parseRS, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_path, want_path_noret, want_dims, keys, nkeys, segs, nsegs, linked_segs, links, nlinks, recordset->n, irec != 0 || (bogusList && list_llgetnitems(bogusList) > 0), show_all || show_keys || show_all_segs || show_segs || show_all_links)) != 0)
02063 {
02064 break;
02065 }
02066 }
02067
02068 return status;
02069 }
02070
02071 static void FreeParts(void *data)
02072 {
02073 SIParts_t *parts = (SIParts_t *)data;
02074
02075 if (parts->series)
02076 {
02077 free(parts->series);
02078 parts->series = NULL;
02079 }
02080
02081 if (parts->filter)
02082 {
02083 free(parts->filter);
02084 parts->filter = NULL;
02085 }
02086 }
02087
02088 static int SetWebArg(Q_ENTRY *req, const char *key, char **arglist, size_t *size)
02089 {
02090 char *value = NULL;
02091 char buf[1024];
02092
02093 if (req)
02094 {
02095 value = (char *)qEntryGetStr(req, key);
02096 if (value)
02097 {
02098 if (!cmdparams_set(&cmdparams, key, value))
02099 {
02100 return(1);
02101 }
02102
02103
02104 snprintf(buf, sizeof(buf), "%s='%s' ", key, value);
02105 *arglist = base_strcatalloc(*arglist, buf, size);
02106 }
02107 }
02108
02109 return(0);
02110 }
02111
02112
02113 int DoIt(void)
02114 {
02115 int status = 0;
02116 DRMS_RecordSet_t *recordset = NULL;
02117 DRMS_Record_t *rec;
02118 int inqry;
02119 int atfile;
02120
02121 const char *in;
02122 char *keylist;
02123 char *seglist;
02124 int show_keys;
02125 int show_segs;
02126 int jsd_list;
02127 int list_keys;
02128 int show_all;
02129 int show_all_segs;
02130 int autobang = 0;
02131 int show_all_links;
02132 int show_recordspec;
02133 int show_stats;
02134 int show_types;
02135 int parseRS;
02136 int verbose;
02137 int max_recs;
02138 int cursoredQ;
02139 int quiet;
02140 int show_retention;
02141 int show_archive;
02142 int show_online;
02143 int disableTO;
02144 int show_recnum;
02145 int show_sunum;
02146 int show_tapeinfo;
02147 int show_size;
02148 int show_session;
02149 int keyword_list;
02150 int want_count;
02151 int want_path;
02152 int want_path_noret;
02153 int want_dims;
02154 int dorecs;
02155 int64_t *given_sunum = NULL;
02156 int nsunum;
02157 int requireSUMinfo;
02158 char *sunum_rs_query = NULL;
02159 char *autobangstr = NULL;
02160 char *finalin = NULL;
02161 char seriesnameforheader[DRMS_MAXSERIESNAMELEN];
02162
02163 HContainer_t *suinfo = NULL;
02164 LinkedList_t *parsedrs = NULL;
02165 int iset;
02166 int err = 0;
02167 int drmsstat;
02168 DRMS_Record_t *templrec = NULL;
02169 char *filter = NULL;
02170 int64_t *bogus = NULL;
02171 int nBogus = 0;
02172 LinkedList_t *bogusList = NULL;
02173
02174
02175
02176
02177
02178
02179
02180 int from_web;
02181 char *web_query;
02182 web_query = strdup (cmdparams_get_str (&cmdparams, "QUERY_STRING", NULL));
02183 from_web = strcmp (web_query, "Not Specified") != 0;
02184
02185 int postorget = 0;
02186 char *webarglist = NULL;
02187 size_t webarglistsz;
02188
02189 if (getenv("REQUEST_METHOD"))
02190 {
02191 postorget = (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0 || strcasecmp(getenv("REQUEST_METHOD"), "GET") == 0);
02192 }
02193
02194 if (from_web)
02195 {
02196 Q_ENTRY *req = NULL;
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212 if (!getenv("QUERY_STRING"))
02213 {
02214
02215 if (!postorget)
02216 {
02217
02218 setenv("QUERY_STRING", web_query, 1);
02219
02220
02221 setenv("REQUEST_METHOD", "GET", 1);
02222 }
02223 }
02224
02225
02226
02227
02228
02229
02230 webarglistsz = 2048;
02231 webarglist = (char *)calloc(1, webarglistsz);
02232
02233 req = qCgiRequestParseQueries(NULL, NULL);
02234 if (req)
02235 {
02236
02237 if (SetWebArg(req, "ds", &webarglist, &webarglistsz)) show_info_return(1);
02238 if (SetWebArg(req, "key", &webarglist, &webarglistsz)) show_info_return(1);
02239 if (SetWebArg(req, "seg", &webarglist, &webarglistsz)) show_info_return(1);
02240 if (SetWebArg(req, "a", &webarglist, &webarglistsz)) show_info_return(1);
02241 if (SetWebArg(req, "A", &webarglist, &webarglistsz)) show_info_return(1);
02242 if (SetWebArg(req, "b", &webarglist, &webarglistsz)) show_info_return(1);
02243 if (SetWebArg(req, "c", &webarglist, &webarglistsz)) show_info_return(1);
02244 if (SetWebArg(req, "d", &webarglist, &webarglistsz)) show_info_return(1);
02245 if (SetWebArg(req, "e", &webarglist, &webarglistsz)) show_info_return(1);
02246 if (SetWebArg(req, "h", &webarglist, &webarglistsz)) show_info_return(1);
02247 if (SetWebArg(req, "i", &webarglist, &webarglistsz)) show_info_return(1);
02248 if (SetWebArg(req, "I", &webarglist, &webarglistsz)) show_info_return(1);
02249 if (SetWebArg(req, "j", &webarglist, &webarglistsz)) show_info_return(1);
02250 if (SetWebArg(req, "k", &webarglist, &webarglistsz)) show_info_return(1);
02251 if (SetWebArg(req, "K", &webarglist, &webarglistsz)) show_info_return(1);
02252 if (SetWebArg(req, "l", &webarglist, &webarglistsz)) show_info_return(1);
02253 if (SetWebArg(req, "n", &webarglist, &webarglistsz)) show_info_return(1);
02254 if (SetWebArg(req, "o", &webarglist, &webarglistsz)) show_info_return(1);
02255 if (SetWebArg(req, "O", &webarglist, &webarglistsz)) show_info_return(1);
02256 if (SetWebArg(req, "p", &webarglist, &webarglistsz)) show_info_return(1);
02257 if (SetWebArg(req, "P", &webarglist, &webarglistsz)) show_info_return(1);
02258 if (SetWebArg(req, "q", &webarglist, &webarglistsz)) show_info_return(1);
02259 if (SetWebArg(req, "r", &webarglist, &webarglistsz)) show_info_return(1);
02260 if (SetWebArg(req, "R", &webarglist, &webarglistsz)) show_info_return(1);
02261 if (SetWebArg(req, "s", &webarglist, &webarglistsz)) show_info_return(1);
02262 if (SetWebArg(req, "S", &webarglist, &webarglistsz)) show_info_return(1);
02263 if (SetWebArg(req, "t", &webarglist, &webarglistsz)) show_info_return(1);
02264 if (SetWebArg(req, "T", &webarglist, &webarglistsz)) show_info_return(1);
02265 if (SetWebArg(req, "v", &webarglist, &webarglistsz)) show_info_return(1);
02266 if (SetWebArg(req, "x", &webarglist, &webarglistsz)) show_info_return(1);
02267 if (SetWebArg(req, "z", &webarglist, &webarglistsz)) show_info_return(1);
02268 if (SetWebArg(req, "sunum", &webarglist, &webarglistsz)) show_info_return(1);
02269
02270 qEntryFree(req);
02271 }
02272
02273 free(webarglist);
02274 webarglist = NULL;
02275
02276 printf("Content-type: text/plain\n\n");
02277 }
02278
02279 if (web_query)
02280 {
02281 free(web_query);
02282 web_query = NULL;
02283 }
02284
02285
02286 if (nice_intro ()) return (0);
02287
02288 in = cmdparams_get_str (&cmdparams, "ds", NULL);
02289 keylist = strdup (cmdparams_get_str (&cmdparams, "key", NULL));
02290 seglist = strdup (cmdparams_get_str (&cmdparams, "seg", NULL));
02291 show_keys = strcmp (keylist, "Not Specified");
02292 show_segs = strcmp (seglist, "Not Specified");
02293
02294 max_recs = cmdparams_get_int (&cmdparams, "n", NULL);
02295 nsunum = cmdparams_get_int64arr(&cmdparams, "sunum", &given_sunum, &status);
02296
02297 if (status != CMDPARAMS_SUCCESS)
02298 {
02299 fprintf(stderr, "Invalid argument 'sunum=%s'.\n", cmdparams_get_str(&cmdparams, "sunum", NULL));
02300 return 1;
02301 }
02302
02303 show_all = cmdparams_get_int (&cmdparams, "a", NULL) != 0;
02304 show_all_segs = cmdparams_get_int (&cmdparams, "A", NULL) != 0;
02305 autobang = cmdparams_isflagset(&cmdparams, "b");
02306 want_count = cmdparams_get_int (&cmdparams, "c", NULL) != 0;
02307 want_dims = cmdparams_get_int (&cmdparams, "d", NULL) != 0;
02308 show_recordspec = cmdparams_get_int (&cmdparams, "i", NULL) != 0;
02309 show_session = cmdparams_get_int (&cmdparams, "I", NULL) != 0;
02310 jsd_list = cmdparams_get_int (&cmdparams, "j", NULL) != 0;
02311 keyword_list = cmdparams_get_int(&cmdparams, "k", NULL) != 0;
02312 list_keys = cmdparams_get_int (&cmdparams, "l", NULL) != 0;
02313 show_all_links = cmdparams_get_int (&cmdparams, "K", NULL) != 0;
02314 show_stats = cmdparams_get_int (&cmdparams, "s", NULL) != 0;
02315 show_online = cmdparams_get_int (&cmdparams, "o", NULL) != 0;
02316 disableTO = cmdparams_isflagset(&cmdparams, "O");
02317 want_path = cmdparams_get_int (&cmdparams, "p", NULL) != 0;
02318 want_path_noret = cmdparams_get_int (&cmdparams, "P", NULL) != 0;
02319 quiet = cmdparams_get_int (&cmdparams, "q", NULL) != 0;
02320 show_recnum = cmdparams_get_int(&cmdparams, "r", NULL) != 0;
02321 show_retention = cmdparams_get_int (&cmdparams, "R", NULL) != 0;
02322 show_sunum = cmdparams_get_int(&cmdparams, "S", NULL) != 0;
02323 show_tapeinfo = cmdparams_get_int(&cmdparams, "T", NULL) != 0;
02324 show_archive = cmdparams_get_int (&cmdparams, "x", NULL) != 0;
02325 show_size = cmdparams_get_int(&cmdparams, "z", NULL) != 0;
02326 show_types = cmdparams_get_int(&cmdparams, "t", NULL) != 0;
02327 parseRS = cmdparams_isflagset(&cmdparams, kArgParseRS);
02328 verbose = cmdparams_isflagset(&cmdparams, "v");
02329
02330 dorecs = (show_all || show_all_segs || want_dims || show_recordspec || want_path || want_path_noret || show_keys || show_segs || show_all_links || show_recnum || show_online || show_retention || show_archive || show_tapeinfo || show_size || show_session || show_types);
02331
02332
02333 if (autobang)
02334 {
02335 autobangstr = "[! 1=1 !]";
02336 }
02337
02338
02339
02340
02341 #ifndef DRMS_CLIENT
02342 if (!disableTO && drms_env->dbtimeout == INT_MIN)
02343 {
02344 if (db_settimeout(drms_env->session->db_handle, 600000))
02345 {
02346 fprintf(stderr, "Failed to modify db-statement time-out to %d.\n", 600000);
02347 }
02348 }
02349 #endif
02350
02351 if(want_path_noret) want_path = 1;
02352
02353 requireSUMinfo = show_online || show_retention || show_archive || show_tapeinfo || show_size || show_session;
02354
02355
02356
02357 if (given_sunum && given_sunum[0] >= 0)
02358 {
02359
02360 size_t querylen;
02361 SUM_info_t *onesuinfo = NULL;
02362 SUM_info_t *lastsuinfo = NULL;
02363 SUM_info_t **ponesuinfo = NULL;
02364 char intstr[256];
02365 int firstone;
02366 char key[128];
02367 int isunum;
02368 int newSeries;
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384 if ((status = GetSUMinfo(drms_env, &suinfo, given_sunum, nsunum)) != DRMS_SUCCESS)
02385 {
02386
02387 show_info_return(status);
02388 }
02389
02390
02391
02392 querylen = sizeof(char) * DRMS_MAXQUERYLEN;
02393 sunum_rs_query = malloc(querylen);
02394 *sunum_rs_query = '\0';
02395 newSeries = 0;
02396
02397 for (isunum = 0; isunum < nsunum; isunum++)
02398 {
02399 snprintf(key, sizeof(key), "%llu", (unsigned long long)given_sunum[isunum]);
02400 ponesuinfo = hcon_lookup(suinfo, key);
02401
02402 if (!ponesuinfo)
02403 {
02404
02405 printf("### show_info: Unexpected sunum '%s'.\n", key);
02406 break;
02407 }
02408
02409 onesuinfo = *ponesuinfo;
02410
02411
02412
02413 if (!onesuinfo)
02414 {
02415
02416 continue;
02417 }
02418 else if (*onesuinfo->online_loc == '\0')
02419 {
02420
02421 if (!bogusList)
02422 {
02423 bogusList = list_llcreate(sizeof(int64_t), NULL);
02424 if (!bogusList)
02425 {
02426 fprintf(stderr, "Out of memory.\n");
02427 show_info_return(1);
02428 }
02429 }
02430
02431 list_llinserttail(bogusList, &(given_sunum[isunum]));
02432 continue;
02433 }
02434
02435 if (!lastsuinfo || strcasecmp(onesuinfo->owning_series, lastsuinfo->owning_series) != 0)
02436 {
02437
02438 if (lastsuinfo)
02439 {
02440 sunum_rs_query = base_strcatalloc(sunum_rs_query, " !],", &querylen);
02441 newSeries = 0;
02442 }
02443
02444 snprintf(intstr, sizeof(intstr), "%s[! sunum=", onesuinfo->owning_series);
02445 sunum_rs_query = base_strcatalloc(sunum_rs_query, intstr, &querylen);
02446 lastsuinfo = onesuinfo;
02447 firstone = 1;
02448 newSeries = 1;
02449 }
02450
02451
02452 if (!firstone)
02453 {
02454 sunum_rs_query = base_strcatalloc(sunum_rs_query, "OR sunum=", &querylen);
02455 }
02456 else
02457 {
02458 firstone = 0;
02459 }
02460
02461 snprintf(intstr, sizeof(intstr), "%llu", (unsigned long long)onesuinfo->sunum);
02462 sunum_rs_query = base_strcatalloc(sunum_rs_query, intstr, &querylen);
02463 }
02464
02465 if (newSeries == 1)
02466 {
02467
02468 sunum_rs_query = base_strcatalloc(sunum_rs_query, " !]", &querylen);
02469 newSeries = 0;
02470 }
02471
02472 if (strlen(sunum_rs_query) == 0 && bogusList == NULL)
02473 {
02474 printf("### show_info: given sunum=%s invalid, must quit\n", cmdparams_get_str(&cmdparams, "sunum", NULL));
02475 free(sunum_rs_query);
02476 sunum_rs_query = NULL;
02477 show_info_return(1);
02478 }
02479
02480 if (sunum_rs_query && strlen(sunum_rs_query) > 0)
02481 {
02482 in = sunum_rs_query;
02483
02484
02485
02486 }
02487 else
02488 {
02489 in = "";
02490 }
02491 }
02492 else if (strcmp(in, "Not Specified") == 0)
02493 {
02494
02495 if (cmdparams_numargs(&cmdparams) < 1 || !(in=cmdparams_getarg (&cmdparams, 1)))
02496 {
02497 printf("### show_info: ds=<record_query> parameter is required, must quit\n");
02498 show_info_return(1);
02499 }
02500 }
02501 if (verbose)
02502 {
02503
02504 printf("show_info() query is %s.\n", in);
02505 }
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517 if (in && strlen(in) > 0)
02518 {
02519 char *allvers = NULL;
02520
02521
02522 char **sets = NULL;
02523 DRMS_RecordSetType_t *settypes = NULL;
02524 char **snames = NULL;
02525 char **filts = NULL;
02526 int nsets = 0;
02527
02528 DRMS_RecQueryInfo_t rsinfo;
02529 SIParts_t apart;
02530
02531 if (drms_record_parserecsetspec(in, &allvers, &sets, &settypes, &snames, &filts, &nsets, &rsinfo) != DRMS_SUCCESS)
02532 {
02533 show_info_return(2);
02534 }
02535
02536
02537
02538
02539
02540
02541
02542 if (nsets > 0)
02543 {
02544 if (settypes[0] == kRecordSetType_DRMS)
02545 {
02546 snprintf(seriesnameforheader, sizeof(seriesnameforheader), "%s", snames[0]);
02547 }
02548 else
02549 {
02550 *seriesnameforheader = '\0';
02551 }
02552 }
02553 else
02554 {
02555 snprintf(seriesnameforheader, sizeof(seriesnameforheader), "%s", "somecrazyname");
02556 }
02557
02558 inqry = ((rsinfo & kFilters) != 0);
02559 atfile = ((rsinfo & kAtFile) != 0);
02560
02561 if (autobangstr && !sunum_rs_query)
02562 {
02563
02564 char *filterbuf = NULL;
02565 size_t fbsz = 128;
02566 char *intermed = NULL;
02567
02568 filterbuf = malloc(fbsz);
02569 finalin = strdup(in);
02570 if (filterbuf && finalin)
02571 {
02572 memset(filterbuf, 0, sizeof(filterbuf));
02573 }
02574 else
02575 {
02576 show_info_return(3);
02577 }
02578
02579 for (iset = 0; iset < nsets; iset++)
02580 {
02581 if (settypes[iset] == kRecordSetType_DSDSPort || settypes[iset] == kRecordSetType_DRMS)
02582 {
02583 templrec = drms_template_record(drms_env, snames[iset], &drmsstat);
02584 if (DRMS_ERROR_UNKNOWNSERIES == drmsstat)
02585 {
02586 fprintf(stderr, "Unable to open template record for series '%s'; this series does not exist.\n", snames[iset]);
02587 err = 1;
02588 break;
02589 }
02590 else
02591 {
02592 filter = drms_recordset_extractfilter(templrec, sets[iset], &err);
02593
02594 if (!err)
02595 {
02596 *filterbuf = '\0';
02597 if (filter)
02598 {
02599 filterbuf = base_strcatalloc(filterbuf, filter, &fbsz);
02600 filterbuf = base_strcatalloc(filterbuf, autobangstr, &fbsz);
02601
02602
02603 intermed = base_strreplace(finalin, filter, filterbuf);
02604 free(finalin);
02605 finalin = intermed;
02606 }
02607 else
02608 {
02609 filterbuf = base_strcatalloc(filterbuf, snames[iset], &fbsz);
02610 filterbuf = base_strcatalloc(filterbuf, autobangstr, &fbsz);
02611
02612
02613 intermed = base_strreplace(finalin, snames[iset], filterbuf);
02614 free(finalin);
02615 finalin = intermed;
02616 }
02617
02618 if (parseRS && !dorecs)
02619 {
02620 if (!parsedrs)
02621 {
02622 parsedrs = list_llcreate(sizeof(SIParts_t), (ListFreeFn_t)FreeParts);
02623 }
02624
02625 apart.series = strdup(snames[iset]);
02626 if (filter)
02627 {
02628 size_t sz = strlen(filter) + 1;
02629
02630 apart.filter = strdup(filter);
02631 apart.filter = base_strcatalloc(apart.filter, autobangstr, &sz);
02632 }
02633 else
02634 {
02635 apart.filter = NULL;
02636 }
02637 list_llinserttail(parsedrs, &apart);
02638 }
02639 }
02640
02641 free(filter);
02642
02643 if (err)
02644 {
02645 break;
02646 }
02647 }
02648 }
02649 }
02650
02651 if (!err)
02652 {
02653 in = finalin;
02654 }
02655
02656 free(filterbuf);
02657 filterbuf = NULL;
02658 }
02659 else
02660 {
02661 if (parseRS && !dorecs)
02662 {
02663 for (iset = 0; iset < nsets; iset++)
02664 {
02665 if (settypes[iset] == kRecordSetType_DSDSPort || settypes[iset] == kRecordSetType_DRMS)
02666 {
02667 templrec = drms_template_record(drms_env, snames[iset], &drmsstat);
02668 if (DRMS_ERROR_UNKNOWNSERIES == drmsstat)
02669 {
02670 fprintf(stderr, "Unable to open template record for series '%s'; this series does not exist\
02671 .\n", snames[iset]);
02672 err = 1;
02673 break;
02674 }
02675 else
02676 {
02677 filter = drms_recordset_extractfilter(templrec, sets[iset], &err);
02678
02679 if (!err)
02680 {
02681 if (!parsedrs)
02682 {
02683 parsedrs = list_llcreate(sizeof(SIParts_t), (ListFreeFn_t)FreeParts);
02684 }
02685
02686 apart.series = strdup(snames[iset]);
02687 if (filter)
02688 {
02689 apart.filter = strdup(filter);
02690 }
02691 else
02692 {
02693 apart.filter = NULL;
02694 }
02695 list_llinserttail(parsedrs, &apart);
02696 }
02697
02698 free(filter);
02699
02700 if (err)
02701 {
02702 break;
02703 }
02704 }
02705 }
02706 }
02707 }
02708 }
02709
02710 drms_record_freerecsetspecarr(&allvers, &sets, &settypes, &snames, &filts, nsets);
02711 }
02712
02713 if (parsedrs)
02714 {
02715
02716 ListNode_t *node = NULL;
02717 SIParts_t *parts = NULL;
02718
02719 if (!quiet)
02720 {
02721 printf("SERIES\tFILTER\n");
02722 }
02723
02724 list_llreset(parsedrs);
02725
02726 while ((node = list_llnext(parsedrs)) != NULL)
02727 {
02728 parts = (SIParts_t *)(node->data);
02729 if (parts->filter)
02730 {
02731 printf("%s\t%s\n", parts->series, parts->filter);
02732 }
02733 else
02734 {
02735 printf("%s\t%s\n", parts->series, "NONE");
02736 }
02737 }
02738
02739 list_llfree(&parsedrs);
02740
02741 if (seglist)
02742 {
02743 free(seglist);
02744 }
02745
02746 if (keylist)
02747 {
02748 free(keylist);
02749 }
02750
02751 show_info_return(0);
02752 }
02753
02754 else if (list_keys || jsd_list || show_stats)
02755 {
02756
02757 char *p, *seriesname;
02758 int is_drms_series = 1;
02759
02760
02761
02762
02763
02764
02765
02766
02767 seriesname = strdup (in);
02768 if ((p = index(seriesname,'['))) *p = '\0';
02769 rec = drms_template_record (drms_env, seriesname, &status);
02770 if (status)
02771 {
02772
02773
02774
02775 recordset = drms_open_records (drms_env, in, &status);
02776
02777 if (status == DRMS_ERROR_QUERYFAILED)
02778 {
02779
02780 const char *emsg = DB_GetErrmsg(drms_env->session->db_handle);
02781
02782 if (emsg)
02783 {
02784 fprintf(stderr, "DB error message: %s\n", emsg);
02785 }
02786 }
02787
02788 if (!recordset)
02789 {
02790 fprintf(stderr,"### show_info: series %s not found.\n",seriesname);
02791 if (seriesname)
02792 free (seriesname);
02793 show_info_return(1);
02794 }
02795 if (recordset->n < 1)
02796 {
02797 fprintf(stderr,"### show_info: non-drms series '%s' found but is empty.\n",seriesname);
02798 if (seriesname)
02799 free (seriesname);
02800 if (recordset)
02801 {
02802 drms_close_records(recordset, DRMS_FREE_RECORD);
02803 recordset = NULL;
02804 }
02805 show_info_return(1);
02806 }
02807 rec = recordset->records[0];
02808 is_drms_series = 0;
02809 }
02810
02811 if (seriesname)
02812 free (seriesname);
02813
02814 if (list_keys)
02815 {
02816 list_series_info(rec);
02817 if (recordset)
02818 {
02819 drms_close_records(recordset, DRMS_FREE_RECORD);
02820 recordset = NULL;
02821 }
02822 show_info_return(0);
02823 }
02824 else if (jsd_list)
02825 {
02826 drms_jsd_print(drms_env, rec->seriesinfo->seriesname);
02827 if (recordset)
02828 {
02829 drms_close_records(recordset, DRMS_FREE_RECORD);
02830 recordset = NULL;
02831 }
02832 show_info_return(0);
02833 }
02834 if (show_stats)
02835 {
02836 if (is_drms_series)
02837 {
02838 DRMS_RecordSet_t *rs;
02839
02840 rs = drms_find_rec_first(rec, 1);
02841 if (!rs || rs->n < 1)
02842 printf("No records Present\n");
02843 else
02844 {
02845 printf("First Record: ");
02846 drms_print_rec_query(rs->records[0]);
02847 if (rs->n > 1) printf(" is first of %d records matching first keyword", rs->n);
02848 printf(", Recnum = %lld\n", rs->records[0]->recnum);
02849 drms_free_records(rs);
02850
02851 rs = drms_find_rec_last(rec, 1);
02852 printf("Last Record: ");
02853 drms_print_rec_query(rs->records[0]);
02854 if (rs->n > 1) printf(" is first of %d records matching first keyword", rs->n);
02855 printf(", Recnum = %lld\n", rs->records[0]->recnum);
02856 drms_free_records(rs);
02857
02858 rs = drms_find_rec_last(rec, 0);
02859 printf("Last Recnum: %lld", rs->records[0]->recnum);
02860 printf("\n");
02861 }
02862
02863
02864 int shadowStat;
02865 int hasShadow = drms_series_shadowexists(drms_env, rec->seriesinfo->seriesname, &shadowStat);
02866
02867 if (shadowStat)
02868 {
02869 printf("Has shadow table: ?");
02870 }
02871 else
02872 {
02873 printf("Has shadow table: %s", hasShadow ? "yes" : "no");
02874 }
02875
02876 printf("\n");
02877
02878 show_info_return(0);
02879 }
02880 else
02881 {
02882 printf("### Can not use '-s' flag for non-drms series. Sorry.\n");
02883 if (recordset)
02884 {
02885 drms_close_records(recordset, DRMS_FREE_RECORD);
02886 recordset = NULL;
02887 }
02888 show_info_return(1);
02889 }
02890 }
02891
02892 fflush(stdout);
02893 }
02894
02895
02896
02897
02898 if (want_count)
02899 {
02900 int count = drms_count_records(drms_env, (char *)in, &status);
02901 if (status)
02902 {
02903 fprintf(stderr,"### show_info: series %s not found.\n",in);
02904 show_info_return(1);
02905 }
02906 printf("%d", count);
02907 if (!quiet)
02908 printf(" records match the query");
02909 printf("\n");
02910 show_info_return(0);
02911 }
02912
02913
02914
02915
02916
02917 if (in && strlen(in) > 0 && !inqry && max_recs == 0 && !atfile)
02918 {
02919 fprintf(stderr, "### show_info - the query must contain a record-filter, or the n=num_records or @file argument must be present.\n");
02920 show_info_return(1);
02921 }
02922
02923
02924 if (in && strlen(in) > 0)
02925 {
02926 if (max_recs == 0)
02927 {
02928 cursoredQ = 1;
02929
02930
02931
02932 if (drms_recordset_setchunksize(4096) != DRMS_SUCCESS)
02933 {
02934 show_info_return(99);
02935 }
02936
02937 if (strcmp(keylist, "Not Specified") == 0)
02938 {
02939 recordset = drms_open_recordset (drms_env, in, &status);
02940 }
02941 else
02942 {
02943
02944
02945
02946
02947
02948 recordset = drms_open_recordset (drms_env, in, &status);
02949 }
02950 }
02951 else
02952 {
02953 cursoredQ = 0;
02954 recordset = drms_open_nrecords (drms_env, in, max_recs, &status);
02955 }
02956
02957
02958 if (status == DRMS_ERROR_QUERYFAILED)
02959 {
02960
02961 const char *emsg = DB_GetErrmsg(drms_env->session->db_handle);
02962
02963 if (emsg)
02964 {
02965 fprintf(stderr, "DB error message: %s\n", emsg);
02966 }
02967
02968 show_info_return(1);
02969 }
02970
02971 if (!recordset)
02972 {
02973 if (status == DRMS_ERROR_UNKNOWNSERIES)
02974 {
02975 fprintf(stderr,"### show_info: series %s not found.\n",in);
02976 }
02977
02978 show_info_return(1);
02979 }
02980 }
02981
02982
02983
02984
02985
02986
02987 if (recordset)
02988 {
02989 if (!cursoredQ)
02990 {
02991 if (recordset->n == 0)
02992 {
02993 if (!quiet)
02994 printf ("** No records in selected data set, query was %s **\n",in);
02995 if (recordset)
02996 {
02997 drms_close_records(recordset, DRMS_FREE_RECORD);
02998 recordset = NULL;
02999 }
03000
03001 show_info_return(0);
03002 }
03003 }
03004 else
03005 {
03006
03007
03008 }
03009 }
03010
03011
03012
03013
03014
03015
03016
03017
03018
03019
03020
03021
03022
03023
03024
03025
03026
03027 if (recordset)
03028 {
03029 if (requireSUMinfo)
03030 {
03031 if ((!given_sunum || given_sunum[0] < 0))
03032 {
03033
03034
03035 drms_record_getinfo(recordset);
03036 }
03037 }
03038 }
03039
03040
03041
03042
03043
03044
03045
03046
03047
03048
03049
03050
03051
03052
03053 if (recordset)
03054 {
03055 if (want_path_noret)
03056 {
03057
03058 drms_stage_records(recordset, 0, 0);
03059 }
03060 else if (want_path)
03061 {
03062
03063 drms_sortandstage_records(recordset, 1, 0, &suinfo);
03064 }
03065 }
03066
03067
03068
03069
03070
03071
03072 if (recordset)
03073 {
03074
03075
03076
03077
03078
03079
03080 char *keys[1024];
03081 int nkeys = 0;
03082 char *segs[1024];
03083 int nsegs = 0;
03084 int linked_segs = 0;
03085 char *links[1024];
03086 int nlinks = 0;
03087 int iSeg;
03088 int iKey;
03089
03090 if (cursoredQ)
03091 {
03092 int count = drms_count_records(drms_env, in, &status);
03093
03094 if (!status)
03095 {
03096 if (count > 0)
03097 {
03098 PrintHeader(drms_env, seriesnameforheader, keylist, seglist, show_all, show_keys, show_all_segs, show_segs, show_all_links, quiet, keyword_list, show_recnum, show_sunum, show_recordspec, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_dims, want_path, show_types, keys, &nkeys, segs, &nsegs, &linked_segs, links, &nlinks);
03099 status = RecordLoopCursor(drms_env, in, recordset, bogusList, requireSUMinfo, given_sunum, suinfo, want_path, want_path_noret, seriesnameforheader, keylist, seglist, show_all, show_keys, show_all_segs, show_segs, show_all_links, quiet, keyword_list, show_recnum, show_sunum, show_recordspec, parseRS, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_dims, show_types, sunum_rs_query, keys, nkeys, segs, nsegs, linked_segs, links, nlinks);
03100 }
03101 }
03102 }
03103 else
03104 {
03105 int count = recordset->n;
03106
03107 if (count > 0)
03108 {
03109 PrintHeader(drms_env, seriesnameforheader, keylist, seglist, show_all, show_keys, show_all_segs, show_segs, show_all_links, quiet, keyword_list, show_recnum, show_sunum, show_recordspec, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_dims, want_path, show_types, keys, &nkeys, segs, &nsegs, &linked_segs, links, &nlinks);
03110 status = RecordLoopNoCursor(drms_env, recordset, bogusList, requireSUMinfo, given_sunum, suinfo, want_path, want_path_noret, seriesnameforheader, keylist, seglist, show_all, show_keys, show_all_segs, show_segs, show_all_links, quiet, keyword_list, show_recnum, show_sunum, show_recordspec, parseRS, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_dims, show_types, sunum_rs_query, keys, nkeys, segs, nsegs, linked_segs, links, nlinks);
03111 }
03112 }
03113
03114 for (iSeg = 0; iSeg < nsegs; iSeg++)
03115 {
03116 if (segs[iSeg])
03117 {
03118 free(segs[iSeg]);
03119 segs[iSeg] = NULL;
03120 }
03121 }
03122
03123
03124 for (iKey = 0; iKey < nkeys; iKey++)
03125 {
03126 if (keys[iKey])
03127 {
03128 free(keys[iKey]);
03129 keys[iKey] = NULL;
03130 }
03131 }
03132 }
03133 else
03134 {
03135
03136
03137
03138
03139 int count = list_llgetnitems(bogusList);
03140
03141 if (count > 0)
03142 {
03143 PrintHeader(drms_env, NULL, keylist, seglist, show_all, show_keys, show_all_segs, show_segs, show_all_links, quiet, keyword_list, show_recnum, show_sunum, show_recordspec, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_dims, want_path, show_types, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
03144 status = RecordLoopNoCursor(drms_env, NULL, bogusList, requireSUMinfo, given_sunum, suinfo, want_path, want_path_noret, NULL, keylist, seglist, show_all, show_keys, show_all_segs, show_segs, show_all_links, quiet, keyword_list, show_recnum, show_sunum, show_recordspec, parseRS, show_online, show_retention, show_archive, show_tapeinfo, show_size, show_session, want_dims, show_types, sunum_rs_query, NULL, -1, NULL, -1, -1, NULL, -1);
03145 }
03146 }
03147
03148 if (bogusList)
03149 {
03150 list_llfree(&bogusList);
03151 bogusList = NULL;
03152 }
03153
03154 if (finalin)
03155 {
03156 free(finalin);
03157 finalin = NULL;
03158 }
03159
03160 if (seglist)
03161 {
03162 free(seglist);
03163 }
03164
03165 if (keylist)
03166 {
03167 free(keylist);
03168 }
03169
03170 drms_close_records(recordset, DRMS_FREE_RECORD);
03171 fflush(stdout);
03172 show_info_return(status);
03173 }