00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "TGridJobStatus.h"
00021 #include "TAlienJobStatus.h"
00022 #include "TObjString.h"
00023 #include "TBrowser.h"
00024 #include "TNamed.h"
00025 #include "TAlienDirectory.h"
00026
00027 ClassImp(TAlienJobStatus)
00028
00029
00030 TAlienJobStatus::TAlienJobStatus(TMap *status)
00031 {
00032
00033
00034
00035 TObjString* key;
00036 TObjString* val;
00037
00038 if (status) {
00039 TMapIter next(status);
00040 while ( (key = (TObjString*)next())) {
00041 val = (TObjString*)status->GetValue(key->GetName());
00042 fStatus.Add(key->Clone(), val->Clone());
00043 }
00044 }
00045 }
00046
00047
00048 TAlienJobStatus::~TAlienJobStatus()
00049 {
00050
00051
00052 fStatus.DeleteAll();
00053 }
00054
00055
00056 void TAlienJobStatus::Browse(TBrowser* b)
00057 {
00058
00059
00060 if (b) {
00061 TIterator *iter = fStatus.MakeIterator();
00062 TObject *obj = 0;
00063 while ((obj = iter->Next()) != 0) {
00064 TObject* value = fStatus.GetValue(obj);
00065
00066 TObjString* keyStr = dynamic_cast<TObjString*>(obj);
00067 TObjString* valueStr = dynamic_cast<TObjString*>(value);
00068
00069 if (keyStr->GetString() == TString("jdl")) {
00070 TString valueParsed(valueStr->GetString());
00071 valueParsed.ReplaceAll("\n", 1);
00072 valueParsed.ReplaceAll(" ", 2);
00073 b->Add(new TPair(new TObjString("jdl"), new TObjString(valueParsed)));
00074
00075
00076 const char* outputdir = GetJdlKey("OutputDir");
00077
00078 TString sandbox;
00079 if (outputdir) {
00080 sandbox = outputdir;
00081 } else {
00082 sandbox = TString("/proc/") + TString(GetKey("user")) + TString("/") + TString(GetKey("queueId")) + TString("/job-output");
00083 }
00084
00085 b->Add(new TAlienDirectory(sandbox.Data(),"job-output"));
00086
00087 } else {
00088 if (keyStr && valueStr)
00089 b->Add(new TNamed(valueStr->GetString(), keyStr->GetString()));
00090 }
00091 }
00092 delete iter;
00093 }
00094 }
00095
00096
00097 const char *TAlienJobStatus::GetJdlKey(const char* key)
00098 {
00099
00100
00101 const char *jdl = GetKey("jdl");
00102 if (!jdl)
00103 return 0;
00104 const char* jdltagbegin = strstr(jdl,key);
00105 const char* jdltagquote = strchr(jdltagbegin,'"');
00106 const char* jdltagend = strchr(jdltagbegin,';');
00107
00108 if (!jdltagend) {
00109 return 0;
00110 }
00111 if (!jdltagquote) {
00112 return 0;
00113 }
00114 jdltagquote++;
00115 const char* jdltagquote2 = strchr(jdltagquote,'"');
00116 if (!jdltagquote2) {
00117 return 0;
00118 }
00119 fJdlTag = TString(jdltagquote);
00120 fJdlTag = fJdlTag(0,jdltagquote2-jdltagquote);
00121
00122 return fJdlTag.Data();
00123 }
00124
00125
00126 const char *TAlienJobStatus::GetKey(const char* key)
00127 {
00128
00129
00130 TObject* obj = fStatus.FindObject(key);
00131 TPair* pair = dynamic_cast<TPair*>(obj);
00132 if (pair) {
00133 TObjString* string = dynamic_cast<TObjString*> (pair->Value());
00134 return string->GetName();
00135 }
00136 return 0;
00137 }
00138
00139
00140 TGridJobStatus::EGridJobStatus TAlienJobStatus::GetStatus() const
00141 {
00142
00143
00144
00145 TObject* obj = fStatus.FindObject("status");
00146 TPair* pair = dynamic_cast<TPair*>(obj);
00147
00148 if (pair) {
00149 TObjString* string = dynamic_cast<TObjString*> (pair->Value());
00150
00151 if (string) {
00152 const char* status = string->GetString().Data();
00153
00154 if (strcmp(status, "INSERTING") == 0 ||
00155 strcmp(status, "WAITING") == 0 ||
00156 strcmp(status, "QUEUED") == 0 ||
00157 strcmp(status, "ASSIGNED") == 0)
00158 return kWAITING;
00159 else if (strcmp(status, "STARTED") == 0 ||
00160 strcmp(status, "SAVING") == 0 ||
00161 strcmp(status, "SPLITTING") == 0 ||
00162 strcmp(status, "RUNNING") == 0 ||
00163 strcmp(status, "SPLIT") == 0)
00164 return kRUNNING;
00165 else if (strcmp(status, "EXPIRED") == 0 ||
00166 string->GetString().BeginsWith("ERROR_") == kTRUE ||
00167 strcmp(status, "FAILED") == 0 ||
00168 strcmp(status, "ZOMBIE") == 0)
00169 return kFAIL;
00170 else if (strcmp(status, "KILLED") == 0)
00171 return kABORTED;
00172 else if (strcmp(status, "DONE") == 0)
00173 return kDONE;
00174 }
00175 }
00176 return kUNKNOWN;
00177 }
00178
00179
00180 void TAlienJobStatus::Print(Option_t *) const
00181 {
00182
00183
00184 PrintJob(kTRUE);
00185 }
00186
00187
00188 void TAlienJobStatus::PrintJob(Bool_t full) const
00189 {
00190
00191
00192
00193 TObject* obj = fStatus.FindObject("status");
00194 TPair* pair = dynamic_cast<TPair*>(obj);
00195
00196 if (pair) {
00197 TObjString* string = dynamic_cast<TObjString*> (pair->Value());
00198 if (string) {
00199 printf("The status of the job is %s\n", string->GetString().Data());
00200 }
00201 }
00202
00203 if (full != kTRUE)
00204 return;
00205
00206 printf("==================================================\n");
00207 printf("Detail Information:\n");
00208
00209 TIterator* iter = fStatus.MakeIterator();
00210
00211 while ((obj = iter->Next()) != 0) {
00212 TObject* value = fStatus.GetValue(obj);
00213
00214 TObjString* keyStr = dynamic_cast<TObjString*>(obj);
00215 TObjString* valueStr = dynamic_cast<TObjString*>(value);
00216
00217 printf("%s => %s\n", (keyStr) ? keyStr->GetString().Data() : "", (valueStr) ? valueStr->GetString().Data() : "");
00218 }
00219
00220 delete iter;
00221 }