#include "Riostream.h"
#include "TProofResourcesStatic.h"
#include "TSystem.h"
#include "TInetAddress.h"
#include "TProofNodeInfo.h"
#include "TProofDebug.h"
#include "TUrl.h"
#include "TObjArray.h"
#include "TObjString.h"
#include "TError.h"
ClassImp(TProofResourcesStatic)
TProofResourcesStatic::TProofResourcesStatic()
{
InitResources();
}
TProofResourcesStatic::TProofResourcesStatic(const char *confDir,
const char *fileName)
{
InitResources();
if (!ReadConfigFile(confDir, fileName)) {
Error("TProofResourcesStatic", "error encountered while reading config file");
fValid = kFALSE;
}
}
TProofResourcesStatic::~TProofResourcesStatic()
{
delete fSubmasterList;
delete fWorkerList;
delete fMaster;
}
void TProofResourcesStatic::InitResources()
{
fMaster = new TProofNodeInfo();
fMaster->fNodeType = TProofNodeInfo::GetNodeType("master");
fFoundMaster = kFALSE;
fWorkerList = new TList();
fWorkerList->SetOwner();
fSubmasterList = new TList();
fSubmasterList->SetOwner();
fValid = kTRUE;
}
TProofNodeInfo *TProofResourcesStatic::GetMaster()
{
if (fFoundMaster)
return fMaster;
return 0;
}
TList *TProofResourcesStatic::GetSubmasters()
{
return fSubmasterList;
}
TList *TProofResourcesStatic::GetWorkers(void)
{
return fWorkerList;
}
Bool_t TProofResourcesStatic::ReadConfigFile(const char *confDir,
const char *fileName)
{
Bool_t status = kTRUE;
const char *cf = gSystem->Getenv("ROOTPROOFCONF");
if (cf && !(gSystem->AccessPathName(cf, kReadPermission))) {
fFileName = cf;
} else {
if (cf)
PDB(kGlobal,1)
Info("ReadConfigFile", "file %s cannot be read:"
" check existence and/or permissions", (cf ? cf : ""));
fFileName.Form("%s/.%s", gSystem->HomeDirectory(), fileName);
PDB(kGlobal,2)
Info("ReadConfigFile", "checking PROOF config file %s", fFileName.Data());
if (gSystem->AccessPathName(fFileName, kReadPermission)) {
fFileName.Form("%s/etc/proof/%s", confDir, fileName);
PDB(kGlobal,2)
Info("ReadConfigFile", "checking PROOF config file %s", fFileName.Data());
if (gSystem->AccessPathName(fFileName, kReadPermission)) {
Error("ReadConfigFile", "no PROOF config file found");
return kFALSE;
}
}
}
PDB(kGlobal,1)
Info("ReadConfigFile", "using PROOF config file: %s", fFileName.Data());
fstream infile(fFileName.Data(), std::ios::in);
if (infile.is_open()) {
Bool_t isMaster = kFALSE;
Bool_t isSubmaster = kFALSE;
Bool_t isWorker = kFALSE;
TString line = "";
TString keyword = "";
TString allLines = "";
allLines.ReadString(infile);
TObjArray *lines = allLines.Tokenize("\n");
Int_t numberOfLines = lines->GetEntries();
for (Int_t j = 0; j < numberOfLines; j++) {
TObjString *objLine = (TObjString *)lines->At(j);
line = objLine->GetString();
line = line.Strip(TString::kBoth);
if ( !((line(0,1) == "#") || (line == "")) ) {
TProofNodeInfo *nodeinfo = 0;
isMaster = kFALSE;
isSubmaster = kFALSE;
isWorker = kFALSE;
TObjArray *tokens = line.Tokenize(" ");
Int_t n = tokens->GetEntries();
TString option;
TString value;
for (Int_t i = 0; i < n; i++) {
keyword = ((TObjString *)tokens->At(i))->GetString();
switch (GetInfoType(keyword)) {
case kNodeType: {
if (keyword == "master" || keyword == "node") {
nodeinfo = CreateNodeInfo(keyword);
isMaster = kTRUE;
}
else if (keyword == "submaster") {
nodeinfo = CreateNodeInfo(keyword);
isSubmaster = kTRUE;
} else {
nodeinfo = CreateNodeInfo(keyword);
isWorker = kTRUE;
}
break;
}
case kHost: {
if (nodeinfo) {
nodeinfo->fNodeName = keyword;
if (isMaster) {
TString node = TUrl(nodeinfo->fNodeName).GetHost();
nodeinfo->fImage = strstr(nodeinfo->fNodeName, node.Data());
} else {
TString tmp = nodeinfo->fNodeName;
const Ssiz_t equalPosition = tmp.Index("@", 1, 0, TString::kExact);
nodeinfo->fImage = tmp(equalPosition + 1, tmp.Length());
}
} else {
Error("ReadConfigFile","Command not recognized: %s (ignored)",
keyword.Data());
}
break;
}
case kOption: {
const Ssiz_t equalPosition =
keyword.Index("=", 1, 0, TString::kExact);
TString tmp = keyword;
option = tmp(0, equalPosition);
value = tmp(equalPosition + 1, tmp.Length());
SetOption(nodeinfo, option, value);
break;
}
default:
break;
}
}
if (isMaster) {
TString node = TUrl(nodeinfo->fNodeName).GetHost();
TString host = gSystem->GetHostByName(gSystem->HostName()).GetHostName();
TInetAddress inetaddr = gSystem->GetHostByName(node);
if (!host.CompareTo(inetaddr.GetHostName()) || (node == "localhost")) {
fFoundMaster = kTRUE;
fMaster->Assign(*nodeinfo);
}
}
if (isWorker) {
fWorkerList->Add(nodeinfo);
}
else if (isSubmaster) {
fSubmasterList->Add(nodeinfo);
}
}
}
infile.close();
if (!fFoundMaster) {
Error("ReadConfigFile","No master info found in config file");
status = kFALSE;
}
}
else {
status = kFALSE;
}
return status;
}
void TProofResourcesStatic::SetOption(TProofNodeInfo *nodeinfo,
const TString &option,
const TString &value)
{
if (option == "workdir") {
nodeinfo->fWorkDir = value;
} else if (option == "image") {
nodeinfo->fImage = value;
} else if (option == "perf") {
nodeinfo->fPerfIndex = value.Atoi();
} else if (option == "config") {
nodeinfo->fConfig = value;
} else if (option == "msd") {
if (nodeinfo->fNodeType == TProofNodeInfo::GetNodeType("submaster")) {
nodeinfo->fMsd = value;
} else {
::Error("SetOption","msd only valid for submasters [ignored]");
}
} else if (option == "port") {
nodeinfo->fPort = value.Atoi();
} else {
::Error("SetOption","No such option [%s=%s]",option.Data(),value.Data());
}
}
TProofResourcesStatic::EInfoType TProofResourcesStatic::GetInfoType(const TString &word)
{
EInfoType type = kNodeType;
if ((word == "node") || (word == "master") || (word == "submaster") ||
(word == "worker") || (word == "slave") ||
(word == "condorworker") || (word == "condorslave")) {
type = kNodeType;
}
else if (word.Contains("=", TString::kExact)) {
type = kOption;
} else {
type = kHost;
}
return type;
}
TProofNodeInfo *TProofResourcesStatic::CreateNodeInfo(const TString &name)
{
TProofNodeInfo *nodeInfo = new TProofNodeInfo();
nodeInfo->fNodeType = TProofNodeInfo::GetNodeType(name);
nodeInfo->fNodeName = name;
nodeInfo->fPort = -1;
nodeInfo->fPerfIndex = 100;
return nodeInfo;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.