00001
00026 #include "drms.h"
00027 #include "jsoc_main.h"
00028
00029 ModuleArgs_t module_args[] = {
00030 {ARG_FLAG, "p", "0", "list the record\'s log storage_unit path"},
00031 {ARG_FLAG, "P", "0", "list the record\'s log storage_unit path but no retrieve"},
00032 {ARG_FLAG, "t", "0", "list the infomation as a table"},
00033 {ARG_FLAG, "q", "0", "list the record query"},
00034 {ARG_END}
00035 };
00036
00037 char *module_name = "drms_log";
00038
00039
00040 int DoIt(void)
00041 {
00042 int status = 0;
00043 int i = 1;
00044 const char *rsname = NULL;
00045 char query[DRMS_MAXQUERYLEN];
00046 int want_path = cmdparams_get_int (&cmdparams, "P", NULL) != 0;
00047 int retrieve = cmdparams_get_int (&cmdparams, "p", NULL) != 0;
00048 int as_table = cmdparams_get_int (&cmdparams, "t", NULL) != 0;
00049 int as_query = cmdparams_get_int (&cmdparams, "q", NULL) != 0;
00050 if (as_table)
00051 {
00052 if (as_query) printf("RecordQuery\t");
00053 printf("recnum\tjsoc_version\thost\tuser\tstarttime\tendtime\tsessionid\tLogSU");
00054 if (want_path || retrieve)
00055 printf("\tLogPath");
00056 printf("\n");
00057 }
00058 while ((rsname = cmdparams_getarg (&cmdparams,i++)))
00059 {
00060 DRMS_RecordSet_t *rs = drms_open_records (drms_env, rsname, &status);
00061 if (!status)
00062 {
00063 for (int j = 0; j < rs->n; j++)
00064 {
00065 DRMS_Record_t *rec = rs->records[j];
00066
00067 if (as_query)
00068 {
00069 if (!as_table)
00070 printf("query: ");
00071 drms_print_rec_query(rec);
00072 printf((as_table ? "\t" : "\n"));
00073 }
00074
00075 if (!as_table)
00076 printf("recnum: ");
00077 printf("%lld", rec->recnum);
00078 printf((as_table ? "\t" : "\n"));
00079
00080 sprintf(query, "select jsoc_version, hostname, username, starttime, endtime, sessionid, sunum from %s.drms_session where sessionid=%lld", rec->sessionns, rec->sessionid);
00081 DB_Text_Result_t *qres;
00082 if ((qres = drms_query_txt(drms_env->session, query)) && qres->num_rows>0)
00083 {
00084 if (!as_table)
00085 printf("jsoc version: ");
00086 if (qres->field[0][0][0])
00087 printf("%s", qres->field[0][0]);
00088 else
00089 printf("Undefined");
00090 printf((as_table ? "\t" : "\n"));
00091
00092 if (!as_table)
00093 printf("host: ");
00094 if (qres->field[0][1][0])
00095 printf("%s", qres->field[0][1]);
00096 else
00097 printf("Undefined");
00098 printf((as_table ? "\t" : "\n"));
00099
00100 if (!as_table)
00101 printf("user: ");
00102 if (qres->field[0][2][0])
00103 printf("%s", qres->field[0][2]);
00104 else
00105 printf("Undefined");
00106 printf((as_table ? "\t" : "\n"));
00107
00108 if (!as_table)
00109 printf("session starttime: ");
00110 if (qres->field[0][3][0])
00111 printf("%s", qres->field[0][3]);
00112 else
00113 printf("Unavailable");
00114 printf((as_table ? "\t" : "\n"));
00115
00116 if (!as_table)
00117 printf("session endtime: ");
00118 if (qres->field[0][4][0])
00119 printf("%s", qres->field[0][4]);
00120 else
00121 printf("Unavailable");
00122 printf((as_table ? "\t" : "\n"));
00123
00124 if (!as_table)
00125 printf("sessionid: ");
00126 if (qres->field[0][5][0])
00127 printf("%s", qres->field[0][5]);
00128 else
00129 printf("%lld", rec->sessionid);
00130 printf((as_table ? "\t" : "\n"));
00131
00132 if (!as_table)
00133 printf("logSU: ");
00134 if (qres->field[0][6][0])
00135 {
00136 printf("%s", qres->field[0][6]);
00137 if (want_path || retrieve)
00138 {
00139 DRMS_StorageUnit_t *su;
00140 printf((as_table ? "\t" : "\n"));
00141 if (!as_table)
00142 printf("logPath: ");
00143 su = malloc(sizeof(DRMS_StorageUnit_t));
00144 XASSERT(su);
00145 su->sunum = atoll(qres->field[0][6]);
00146 drms_env->retention = DRMS_LOG_RETENTION;
00147 status = drms_getsudir(drms_env, su, retrieve);
00148 if (!status)
00149 printf("%s", su->sudir);
00150 else
00151 printf("No log avaliable");
00152 free(su);
00153 }
00154 }
00155 else
00156 printf("No log sunum avaliable");
00157 printf((as_table ? "" : "\n"));
00158 db_free_text_result(qres);
00159 }
00160 else
00161 printf("session query failed");
00162 printf("\n");
00163 }
00164 }
00165 else
00166 printf("query failed: %s\n", rsname);
00167 }
00168 return status;
00169 }
00170