Skip to content

Commit

Permalink
XrdCl: extend plug-inconfiguration to support defining up to 5 plug-i…
Browse files Browse the repository at this point in the history
…ns in

single line environment variables:
export XRD_PLUGIN_1="lib=libXrdClRecorder-5.so,enable=true,url=*"
export XRD_PLUGIN_2="lib=libXrdClJCache-5.so,enable=true,url=root://*"
...
export XRD_PLUGIN_5="..."
  • Loading branch information
Andreas Joachim Peters committed Jun 11, 2024
1 parent 0d9ba69 commit 70d6b45
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/XrdCl/XrdClDefaultEnv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ namespace XrdCl
REGISTER_VAR_STR( varsStr, "ClientMonitorParam", DefaultClientMonitorParam );
REGISTER_VAR_STR( varsStr, "NetworkStack", DefaultNetworkStack );
REGISTER_VAR_STR( varsStr, "PlugIn", DefaultPlugIn );
REGISTER_VAR_STR( varsStr, "PlugIn_1", DefaultPlugIn );
REGISTER_VAR_STR( varsStr, "PlugIn_2", DefaultPlugIn );
REGISTER_VAR_STR( varsStr, "PlugIn_3", DefaultPlugIn );
REGISTER_VAR_STR( varsStr, "PlugIn_4", DefaultPlugIn );
REGISTER_VAR_STR( varsStr, "PlugIn_5", DefaultPlugIn );
REGISTER_VAR_STR( varsStr, "PlugIn_6", DefaultPlugIn );
REGISTER_VAR_STR( varsStr, "PlugInConfDir", DefaultPlugInConfDir );
REGISTER_VAR_STR( varsStr, "ReadRecovery", DefaultReadRecovery );
REGISTER_VAR_STR( varsStr, "WriteRecovery", DefaultWriteRecovery );
Expand Down
54 changes: 52 additions & 2 deletions src/XrdCl/XrdClPlugInManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,42 @@ namespace XrdCl
if( !customPlugIns.empty() )
ProcessConfigDir( customPlugIns );
}

//--------------------------------------------------------------------------
// Support for loading plugins accoring to environment setting
// First plugin XRD_PLUGIN_1 ="key1=val1,key2=val2,key3=val3"
// Second plugin XRD_PLUGIN_2="key1=val1,key2=val2,key3=val3"
// ...
// Fifth plugin XRD_PLUGIN_5="key1=val1,key2=val2,key3=val3"
//--------------------------------------------------------------------------
std::string envprefix = "XRD_PLUGIN";
const std::array<std::string, 5> ENVS = {"_1", "_2", "_3", "_4", "_5"};

for (const auto& penv : ENVS) {
std::string pluginenv = envprefix + penv;
std::string envString;
if ( env->GetString(pluginenv, envString) && envString.length() ) {
std::map<std::string, std::string> envMap;
std::stringstream ss(envString);
std::string item;

// Split the environment variable string by commas
while (std::getline(ss, item, ',')) {
Log *log = DefaultEnv::GetLog();
std::stringstream itemStream(item);
std::string key, value;

// Split each key-value pair by the equal sign
if (std::getline(itemStream, key, '=') && std::getline(itemStream, value)) {
envMap[key] = value;
log->Debug( PlugInMgrMsg, "Processing plug-in definitions from environment %s->%s...",
key.c_str(), value.c_str());
}
}
std::string origin = std::string("env{") + pluginenv + std::string("}");
ProcessConfig(envMap,origin);
}
}
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -298,13 +334,27 @@ namespace XrdCl
return;
}

return this->ProcessConfig(config, confFile);
}

//----------------------------------------------------------------------------
// Process a plug-in config map and load the plug-in if possible
//----------------------------------------------------------------------------

void PlugInManager::ProcessConfig(std::map<std::string, std::string>& config, const std::string& confOrigin)
{
Log *log = DefaultEnv::GetLog();

for (auto i:config) {
log->Debug( PlugInMgrMsg, "'%s'=>'%s'", i.first.c_str(), i.second.c_str());
}
const char *keys[] = { "url", "lib", "enable", 0 };
for( int i = 0; keys[i]; ++i )
{
if( config.find( keys[i] ) == config.end() )
{
log->Debug( PlugInMgrMsg, "Unable to find '%s' key in the config file "
"%s, ignoring this config", keys[i], confFile.c_str() );
"%s, ignoring this config", keys[i], confOrigin.c_str() );
return;
}
}
Expand All @@ -317,7 +367,7 @@ namespace XrdCl
std::string enable = config["enable"];

log->Dump( PlugInMgrMsg, "Settings from '%s': url='%s', lib='%s', "
"enable='%s'", confFile.c_str(), url.c_str(), lib.c_str(),
"enable='%s'", confOrigin.c_str(), url.c_str(), lib.c_str(),
enable.c_str() );

std::pair<XrdOucPinLoader*, PlugInFactory *> pg;
Expand Down
5 changes: 5 additions & 0 deletions src/XrdCl/XrdClPlugInManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ namespace XrdCl
//------------------------------------------------------------------------
void ProcessPlugInConfig( const std::string &confFile );

//------------------------------------------------------------------------
//! Process a plug-in config file and load the plug-in if possible
//------------------------------------------------------------------------
void ProcessConfig(std::map<std::string, std::string>& config, const std::string& configOrigin);

//------------------------------------------------------------------------
//! Load the plug-in and create the factory
//------------------------------------------------------------------------
Expand Down

0 comments on commit 70d6b45

Please sign in to comment.