Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TAlienJobStatus.cxx
Go to the documentation of this file.
1 // @(#)root/alien:$Id$
2 // Author: Jan Fiete Grosse-Oetringhaus 06/10/2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TAlienJobStatus //
15 // //
16 // Alien implementation of TGridJobStatus //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 
20 #include "TGridJobStatus.h"
21 #include "TAlienJobStatus.h"
22 #include "TObjString.h"
23 #include "TBrowser.h"
24 #include "TNamed.h"
25 #include "TAlienDirectory.h"
26 
27 ClassImp(TAlienJobStatus);
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Creates a TAlienJobStatus object.
31 /// If a status map is provided it is copied to the status information.
32 
33 TAlienJobStatus::TAlienJobStatus(TMap *status)
34 {
35  TObjString* key;
36  TObjString* val;
37 
38  if (status) {
39  TMapIter next(status);
40  while ( (key = (TObjString*)next())) {
41  val = (TObjString*)status->GetValue(key->GetName());
42  fStatus.Add(key->Clone(), val->Clone());
43  }
44  }
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Cleanup.
49 
50 TAlienJobStatus::~TAlienJobStatus()
51 {
52  fStatus.DeleteAll();
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Browser interface to ob status.
57 
58 void TAlienJobStatus::Browse(TBrowser* b)
59 {
60  if (b) {
61  TIterator *iter = fStatus.MakeIterator();
62  TObject *obj = 0;
63  while ((obj = iter->Next()) != 0) {
64  TObject* value = fStatus.GetValue(obj);
65 
66  TObjString* keyStr = dynamic_cast<TObjString*>(obj);
67  TObjString* valueStr = dynamic_cast<TObjString*>(value);
68 
69  if (keyStr->GetString() == TString("jdl")) {
70  TString valueParsed(valueStr->GetString());
71  valueParsed.ReplaceAll("\n", 1);
72  valueParsed.ReplaceAll(" ", 2);
73  b->Add(new TPair(new TObjString("jdl"), new TObjString(valueParsed)));
74 
75  // list sandboxes
76  const char* outputdir = GetJdlKey("OutputDir");
77 
78  TString sandbox;
79  if (outputdir) {
80  sandbox = outputdir;
81  } else {
82  sandbox = TString("/proc/") + TString(GetKey("user")) + TString("/") + TString(GetKey("queueId")) + TString("/job-output");
83  }
84 
85  b->Add(new TAlienDirectory(sandbox.Data(),"job-output"));
86 
87  } else {
88  b->Add(new TNamed(valueStr->GetString(), keyStr->GetString()));
89  }
90  }
91  delete iter;
92  }
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Return the JDL key.
97 
98 const char *TAlienJobStatus::GetJdlKey(const char* key)
99 {
100  const char *jdl = GetKey("jdl");
101  if (!jdl)
102  return 0;
103  const char* jdltagbegin = strstr(jdl,key);
104  const char* jdltagquote = strchr(jdltagbegin,'"');
105  const char* jdltagend = strchr(jdltagbegin,';');
106 
107  if (!jdltagend) {
108  return 0;
109  }
110  if (!jdltagquote) {
111  return 0;
112  }
113  jdltagquote++;
114  const char* jdltagquote2 = strchr(jdltagquote,'"');
115  if (!jdltagquote2) {
116  return 0;
117  }
118  fJdlTag = TString(jdltagquote);
119  fJdlTag = fJdlTag(0,jdltagquote2-jdltagquote);
120 
121  return fJdlTag.Data();
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Return a key.
126 
127 const char *TAlienJobStatus::GetKey(const char* key)
128 {
129  TObject* obj = fStatus.FindObject(key);
130  TPair* pair = dynamic_cast<TPair*>(obj);
131  if (pair) {
132  TObjString* string = dynamic_cast<TObjString*> (pair->Value());
133  return string->GetName();
134  }
135  return 0;
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Gets the status of the job reduced to the subset defined
140 /// in TGridJobStatus.
141 
142 TGridJobStatus::EGridJobStatus TAlienJobStatus::GetStatus() const
143 {
144  TObject* obj = fStatus.FindObject("status");
145  TPair* pair = dynamic_cast<TPair*>(obj);
146 
147  if (pair) {
148  TObjString* string = dynamic_cast<TObjString*> (pair->Value());
149 
150  if (string) {
151  const char* status = string->GetString().Data();
152 
153  if (strcmp(status, "INSERTING") == 0 ||
154  strcmp(status, "WAITING") == 0 ||
155  strcmp(status, "QUEUED") == 0 ||
156  strcmp(status, "ASSIGNED") == 0)
157  return kWAITING;
158  else if (strcmp(status, "STARTED") == 0 ||
159  strcmp(status, "SAVING") == 0 ||
160  strcmp(status, "SPLITTING") == 0 ||
161  strcmp(status, "RUNNING") == 0 ||
162  strcmp(status, "SPLIT") == 0)
163  return kRUNNING;
164  else if (strcmp(status, "EXPIRED") == 0 ||
165  string->GetString().BeginsWith("ERROR_") == kTRUE ||
166  strcmp(status, "FAILED") == 0 ||
167  strcmp(status, "ZOMBIE") == 0)
168  return kFAIL;
169  else if (strcmp(status, "KILLED") == 0)
170  return kABORTED;
171  else if (strcmp(status, "DONE") == 0)
172  return kDONE;
173  }
174  }
175  return kUNKNOWN;
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Prints the job information.
180 
181 void TAlienJobStatus::Print(Option_t *) const
182 {
183  PrintJob(kTRUE);
184 }
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Prints this job.
188 /// If full is kFALSE only the status is printed, otherwise all information.
189 
190 void TAlienJobStatus::PrintJob(Bool_t full) const
191 {
192  TObject* obj = fStatus.FindObject("status");
193  TPair* pair = dynamic_cast<TPair*>(obj);
194 
195  if (pair) {
196  TObjString* string = dynamic_cast<TObjString*> (pair->Value());
197  if (string) {
198  printf("The status of the job is %s\n", string->GetString().Data());
199  }
200  }
201 
202  if (full != kTRUE)
203  return;
204 
205  printf("==================================================\n");
206  printf("Detail Information:\n");
207 
208  TIterator* iter = fStatus.MakeIterator();
209 
210  while ((obj = iter->Next()) != 0) {
211  TObject* value = fStatus.GetValue(obj);
212 
213  TObjString* keyStr = dynamic_cast<TObjString*>(obj);
214  TObjString* valueStr = dynamic_cast<TObjString*>(value);
215 
216  printf("%s => %s\n", (keyStr) ? keyStr->GetString().Data() : "", (valueStr) ? valueStr->GetString().Data() : "");
217  }
218 
219  delete iter;
220 }