Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XrdCmsRedirLocal] Add localroot option for plug-in. Improve fault tolerance of RedirLocal plug-in #1523

Merged
merged 4 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 30 additions & 26 deletions src/XrdCms/XrdCmsRedirLocal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ extern "C" XrdCmsClient *XrdCmsGetClient(XrdSysLogger *Logger, int opMode,
//! Constructor
//------------------------------------------------------------------------------
XrdCmsRedirLocal::XrdCmsRedirLocal(XrdSysLogger *Logger, int opMode, int myPort,
XrdOss *theSS) : XrdCmsClient(amLocal) {
nativeCmsFinder = new XrdCmsFinderRMT(Logger, opMode, myPort);
this->theSS = theSS;
readOnlyredirect = true;
httpRedirect = true;
XrdOss *theSS) : XrdCmsClient(amLocal),
nativeCmsFinder(new XrdCmsFinderRMT(Logger, opMode, myPort)),
readOnlyredirect(true),
httpRedirect(false),
Say(0,"cms_") {
Say.logger(Logger);
}
//------------------------------------------------------------------------------
//! Destructor
Expand All @@ -48,9 +49,20 @@ XrdCmsRedirLocal::~XrdCmsRedirLocal() { delete nativeCmsFinder; }
//------------------------------------------------------------------------------
int XrdCmsRedirLocal::Configure(const char *cfn, char *Parms, XrdOucEnv *EnvInfo) {
loadConfig(cfn);
if(localroot.empty())
{
Say.Emsg("RedirLocal", "oss.localroot (replaced by xrdcmsredirlocal for localredirect) " \
"and xrdcmsredirlocal.localroot are undefined, define xrdcmsredirlocal.localroot");
return 0;
}
if(localroot[0] != '/')
{
Say.Emsg("RedirLocal", "oss.localroot or xrdcmsredirlocal.localroot needs to be an absolute path");
return 0;
}
if (nativeCmsFinder)
return nativeCmsFinder->Configure(cfn, Parms, EnvInfo);
return 0;
return 0; // means false
}

void XrdCmsRedirLocal::loadConfig(const char *filename) {
Expand All @@ -66,29 +78,22 @@ void XrdCmsRedirLocal::loadConfig(const char *filename) {
// search for readonlyredirect,
// which only allows read calls to be redirected to local
if (strcmp(word, "xrdcmsredirlocal.readonlyredirect") == 0){
std::string readWord = std::string(Config.GetWord(true));//to lower case
if (readWord.find("true") != std::string::npos){
readOnlyredirect = true;
}
else {
readOnlyredirect = false;
}
readOnlyredirect = std::string(Config.GetWord(true)).find("true") != std::string::npos;
}
// search for httpredirect,
// which allows http(s) calls to be redirected to local
else if (strcmp(word, "xrdcmsredirlocal.httpredirect") == 0){
std::string readWord = std::string(Config.GetWord(true));//to lower case
if(readWord.find("true") != std::string::npos){
httpRedirect = true;
}
else {
httpRedirect = false;
}
httpRedirect = std::string(Config.GetWord(true)).find("true") != std::string::npos;
}
// search for localroot,
// search for newer localroot, overwrite given oss.localroot if defined,
// which manually sets localroot to prepend
else if (strcmp(word, "xrdcmsredirlocal.localroot") == 0){
localroot = std::string(Config.GetWord(true));//to lower case
localroot = std::string(Config.GetWord(false));
}
// search for oss.localroot,
// which manually sets localroot to prepend
else if (strcmp(word, "oss.localroot") == 0 && localroot.empty()){
localroot = std::string(Config.GetWord(false));
}
}
Config.Close();
Expand Down Expand Up @@ -127,17 +132,16 @@ int XrdCmsRedirLocal::Locate(XrdOucErrInfo &Resp, const char *path, int flags,
// now check if localhost was tried before, to make sure we're handling
// the redirection loop
int param = 0; // need it to get Env
std::string envInfo(EnvInfo->Env(param)); // get already tried hosts
std::string searchPattern = "&tried=localhost"; //search for this pattern
if(strncmp(envInfo.c_str(), searchPattern.c_str(), searchPattern.size()) == 0)
//EnvInfo->Env(param) gets already tried hosts
if(strstr(EnvInfo->Env(param), "tried=localhost") != nullptr)
{
std::string newPath(path);
// remove localroot
newPath = "//" + newPath.substr(localroot.size());
// get regular target host
rcode = nativeCmsFinder->Locate(Resp, newPath.c_str(), flags, EnvInfo);
// set new error message to full url:port//newPath
auto errText = string(Resp.getErrText()) + ":" + to_string(Resp.getErrInfo()) + newPath;
const std::string errText { std::string(Resp.getErrText()) + ':' + to_string(Resp.getErrInfo()) + newPath};
Resp.setErrInfo(0, errText.c_str());
// now have normal redirection to dataserver at url:port
return rcode;
Expand Down
2 changes: 1 addition & 1 deletion src/XrdCms/XrdCmsRedirLocal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public:
//! used to forward requests to CmsFinder with regular implementation
//---------------------------------------------------------------------------
XrdCmsClient *nativeCmsFinder;
XrdOss *theSS;
bool readOnlyredirect;
bool httpRedirect;
std::string localroot;
XrdSysError Say;
};

#endif // XRDCMSREDIRPLUGIN_HH_