00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "Riostream.h"
00028 #include "TProofResourcesStatic.h"
00029 #include "TSystem.h"
00030 #include "TInetAddress.h"
00031 #include "TProofNodeInfo.h"
00032 #include "TProofDebug.h"
00033 #include "TUrl.h"
00034 #include "TList.h"
00035 #include "TObjArray.h"
00036 #include "TObjString.h"
00037 #include "TError.h"
00038
00039 ClassImp(TProofResourcesStatic)
00040
00041
00042
00043 TProofResourcesStatic::TProofResourcesStatic()
00044 {
00045
00046
00047
00048
00049 InitResources();
00050 }
00051
00052
00053 TProofResourcesStatic::TProofResourcesStatic(const char *confDir,
00054 const char *fileName)
00055 {
00056
00057
00058
00059
00060
00061 InitResources();
00062
00063
00064 if (!ReadConfigFile(confDir, fileName)) {
00065 PDB(kAll,1)
00066 Info("TProofResourcesStatic", "error encountered while reading config file");
00067 fValid = kFALSE;
00068 }
00069 }
00070
00071
00072 TProofResourcesStatic::~TProofResourcesStatic()
00073 {
00074
00075
00076 delete fSubmasterList;
00077 delete fWorkerList;
00078 delete fMaster;
00079 }
00080
00081
00082 void TProofResourcesStatic::InitResources()
00083 {
00084
00085
00086
00087
00088 fMaster = new TProofNodeInfo();
00089 fMaster->fNodeType = TProofNodeInfo::GetNodeType("master");
00090 fFoundMaster = kFALSE;
00091
00092
00093 fWorkerList = new TList();
00094 fWorkerList->SetOwner();
00095
00096
00097 fSubmasterList = new TList();
00098 fSubmasterList->SetOwner();
00099
00100
00101 fValid = kTRUE;
00102 }
00103
00104
00105 TProofNodeInfo *TProofResourcesStatic::GetMaster()
00106 {
00107
00108
00109
00110 if (fFoundMaster)
00111 return fMaster;
00112
00113 return 0;
00114 }
00115
00116
00117 TList *TProofResourcesStatic::GetSubmasters()
00118 {
00119
00120
00121 return fSubmasterList;
00122 }
00123
00124
00125 TList *TProofResourcesStatic::GetWorkers(void)
00126 {
00127
00128
00129 return fWorkerList;
00130 }
00131
00132
00133 Bool_t TProofResourcesStatic::ReadConfigFile(const char *confDir,
00134 const char *fileName)
00135 {
00136
00137
00138 Bool_t status = kTRUE;
00139
00140
00141 const char *p = (const char *) strstr(fileName,":");
00142 if (p)
00143 fileName = p+1;
00144
00145
00146 const char *cf = gSystem->Getenv("ROOTPROOFCONF");
00147 if (cf && !(gSystem->AccessPathName(cf, kReadPermission))) {
00148 fFileName = cf;
00149 } else {
00150 if (cf)
00151 PDB(kGlobal,1)
00152 Info("ReadConfigFile", "file %s cannot be read:"
00153 " check existence and/or permissions", cf);
00154 if (fileName && strlen(fileName) > 0) {
00155
00156
00157 fFileName.Form("%s/.%s", gSystem->HomeDirectory(), fileName);
00158 PDB(kGlobal,2)
00159 Info("ReadConfigFile", "checking PROOF config file %s", fFileName.Data());
00160 if (gSystem->AccessPathName(fFileName, kReadPermission)) {
00161 fFileName.Form("%s/etc/proof/%s", confDir, fileName);
00162 PDB(kGlobal,2)
00163 Info("ReadConfigFile", "checking PROOF config file %s", fFileName.Data());
00164 if (gSystem->AccessPathName(fFileName, kReadPermission)) {
00165 PDB(kAll,1)
00166 Info("ReadConfigFile", "no PROOF config file found");
00167 return kFALSE;
00168 }
00169 }
00170 } else {
00171 PDB(kAll,1)
00172 Info("ReadConfigFile", "no PROOF config file specified");
00173 return kFALSE;
00174 }
00175 }
00176 PDB(kGlobal,1)
00177 Info("ReadConfigFile", "using PROOF config file: %s", fFileName.Data());
00178
00179
00180 fstream infile(fFileName.Data(), std::ios::in);
00181 if (infile.is_open()) {
00182 Bool_t isMaster = kFALSE;
00183 Bool_t isSubmaster = kFALSE;
00184 Bool_t isWorker = kFALSE;
00185
00186
00187
00188
00189
00190
00191
00192 TString line = "";
00193 TString keyword = "";
00194
00195
00196 TString allLines = "";
00197 allLines.ReadString(infile);
00198 TObjArray *lines = allLines.Tokenize("\n");
00199 Int_t numberOfLines = lines->GetEntries();
00200
00201
00202 for (Int_t j = 0; j < numberOfLines; j++) {
00203 TObjString *objLine = (TObjString *)lines->At(j);
00204 line = objLine->GetString();
00205 line = line.Strip(TString::kBoth);
00206
00207
00208 if ( !((line(0,1) == "#") || (line == "")) ) {
00209 TProofNodeInfo *nodeinfo = 0;
00210
00211
00212 isMaster = kFALSE;
00213 isSubmaster = kFALSE;
00214 isWorker = kFALSE;
00215
00216
00217 TObjArray *tokens = line.Tokenize(" ");
00218 Int_t n = tokens->GetEntries();
00219 TString option;
00220 TString value;
00221 for (Int_t i = 0; i < n; i++) {
00222
00223
00224 keyword = ((TObjString *)tokens->At(i))->GetString();
00225
00226
00227 switch (GetInfoType(keyword)) {
00228 case kNodeType: {
00229 if (keyword == "master" || keyword == "node") {
00230 nodeinfo = CreateNodeInfo(keyword);
00231 isMaster = kTRUE;
00232 }
00233
00234 else if (keyword == "submaster") {
00235
00236 nodeinfo = CreateNodeInfo(keyword);
00237 isSubmaster = kTRUE;
00238 } else {
00239
00240 nodeinfo = CreateNodeInfo(keyword);
00241 isWorker = kTRUE;
00242 }
00243 break;
00244 }
00245 case kHost: {
00246
00247 if (nodeinfo) {
00248 nodeinfo->fNodeName = keyword;
00249
00250
00251 if (isMaster) {
00252 TString node = TUrl(nodeinfo->fNodeName).GetHost();
00253 nodeinfo->fImage = strstr(nodeinfo->fNodeName, node.Data());
00254 } else {
00255
00256
00257
00258 TString tmp = nodeinfo->fNodeName;
00259 const Ssiz_t equalPosition = tmp.Index("@", 1, 0, TString::kExact);
00260
00261
00262 nodeinfo->fImage = tmp(equalPosition + 1, tmp.Length());
00263 }
00264 } else {
00265 Error("ReadConfigFile","Command not recognized: %s (ignored)",
00266 keyword.Data());
00267 }
00268 break;
00269 }
00270 case kOption: {
00271
00272 const Ssiz_t equalPosition =
00273 keyword.Index("=", 1, 0, TString::kExact);
00274
00275
00276 TString tmp = keyword;
00277 option = tmp(0, equalPosition);
00278 value = tmp(equalPosition + 1, tmp.Length());
00279
00280
00281 SetOption(nodeinfo, option, value);
00282 break;
00283 }
00284 default:
00285 break;
00286 }
00287
00288 }
00289
00290
00291 if (isMaster) {
00292
00293 TString node = TUrl(nodeinfo->fNodeName).GetHost();
00294 TString host = gSystem->GetHostByName(gSystem->HostName()).GetHostName();
00295 TInetAddress inetaddr = gSystem->GetHostByName(node);
00296 if (!host.CompareTo(inetaddr.GetHostName()) || (node == "localhost")) {
00297 fFoundMaster = kTRUE;
00298 fMaster->Assign(*nodeinfo);
00299 }
00300 }
00301
00302
00303 if (isWorker) {
00304 fWorkerList->Add(nodeinfo);
00305 }
00306 else if (isSubmaster) {
00307 fSubmasterList->Add(nodeinfo);
00308 }
00309 }
00310
00311 }
00312 infile.close();
00313
00314
00315 if (!fFoundMaster) {
00316 Error("ReadConfigFile","No master info found in config file");
00317 status = kFALSE;
00318 }
00319 }
00320 else {
00321
00322 status = kFALSE;
00323 }
00324
00325 return status;
00326 }
00327
00328
00329
00330 void TProofResourcesStatic::SetOption(TProofNodeInfo *nodeinfo,
00331 const TString &option,
00332 const TString &value)
00333 {
00334
00335
00336 if (!nodeinfo) return;
00337
00338 if (option == "workdir") {
00339 nodeinfo->fWorkDir = value;
00340 } else if (option == "image") {
00341 nodeinfo->fImage = value;
00342 } else if (option == "perf") {
00343 nodeinfo->fPerfIndex = value.Atoi();
00344 } else if (option == "config") {
00345 nodeinfo->fConfig = value;
00346 } else if (option == "msd") {
00347 nodeinfo->fMsd = value;
00348 } else if (option == "port") {
00349 nodeinfo->fPort = value.Atoi();
00350 } else {
00351 ::Error("SetOption","No such option [%s=%s]",option.Data(),value.Data());
00352 }
00353 }
00354
00355
00356 TProofResourcesStatic::EInfoType TProofResourcesStatic::GetInfoType(const TString &word)
00357 {
00358
00359
00360 EInfoType type = kNodeType;
00361
00362 if ((word == "node") || (word == "master") || (word == "submaster") ||
00363 (word == "worker") || (word == "slave") ||
00364 (word == "condorworker") || (word == "condorslave")) {
00365 type = kNodeType;
00366 }
00367 else if (word.Contains("=", TString::kExact)) {
00368 type = kOption;
00369 } else {
00370 type = kHost;
00371 }
00372
00373 return type;
00374 }
00375
00376
00377 TProofNodeInfo *TProofResourcesStatic::CreateNodeInfo(const TString &name)
00378 {
00379
00380
00381 TProofNodeInfo *nodeInfo = new TProofNodeInfo();
00382 nodeInfo->fNodeType = TProofNodeInfo::GetNodeType(name);
00383 nodeInfo->fNodeName = name;
00384 nodeInfo->fPort = -1;
00385 nodeInfo->fPerfIndex = 100;
00386
00387 return nodeInfo;
00388 }