typedef sequence<KeyValuePair> FieldsDict;
typedef sequence<double> vectorOfDouble;
+ typedef sequence<string> vectorOfString;
interface EngineComponent ;
interface fileRef ;
interface Container
{
+ void override_environment( in FieldsDict env );
+
+ FieldsDict get_os_environment();
+
/*! \brief Loads a new component class (dynamic library).
\param componentName like COMPONENT, (Python or C++ implementation)
ResourceParameters resource_params;
};
+struct KeyValPairString
+{
+ string key;
+ string val;
+};
+
+typedef sequence<KeyValPairString> KeyValDict;
+
/*! \brief Interface of the %containerManager
This interface is used for interaction with the unique instance
of ContainerManager
//! Shutdown all containers that have been launched by the container manager
void ShutdownContainers();
+
+ void SetOverrideEnvForContainers(in KeyValDict env);
+
+ KeyValDict GetOverrideEnvForContainers();
} ;
};
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
+#include <memory>
#ifndef WIN32
#include <sys/time.h>
#include <dlfcn.h>
#include <unistd.h>
#include <sys/wait.h>
+#include <errno.h>
+#include <stdlib.h>
#else
#include <signal.h>
#include <process.h>
//! Create a new component instance
/*!
* CORBA method: Creates a new servant instance of a component.
-* The servant registers itself to naming service and Registry.
+* The servant registers itself to naming service and Registry.tdlib
* \param genericRegisterName Name of the component instance to register
* in Registry & Name Service (without _inst_n suffix)
* \return a loaded component
return compo;
}
+void EffectiveOverrideEnvironment( const Engines::FieldsDict& env )
+{
+ MESSAGE("Positionning environment on container ");
+ for (CORBA::ULong i=0; i < env.length(); i++)
+ {
+ if (env[i].value.type()->kind() == CORBA::tk_string)
+ {
+ const char* value;
+ env[i].value >>= value;
+ MESSAGE( env[i].key << " = " << value);
+#ifndef WIN32
+ if( setenv(env[i].key,value,1) != 0 )
+ {
+ int errsv = errno;
+ std::string sErr( strerror( errsv) );
+ MESSAGE(sErr);
+ }
+#endif
+ }
+ }
+}
+
+std::vector< std::pair<std::string,std::string> > GetOSEnvironment()
+{
+ std::vector< std::pair<std::string,std::string> > ret;
+#ifndef WIN32
+ char **envPt( environ );
+ for(;*envPt != nullptr; ++envPt)
+ {
+ std::string s( *envPt );
+ auto pos = s.find_first_of('=');
+ std::string k( s.substr(0,pos) ),v( s.substr(pos+1) );
+ ret.emplace_back( std::pair<std::string,std::string>(k,v) );
+ }
+#endif
+ return ret;
+}
+
+void Abstract_Engines_Container_i::override_environment( const Engines::FieldsDict& env )
+{
+ EffectiveOverrideEnvironment(env);
+}
+
+Engines::FieldsDict *Abstract_Engines_Container_i::get_os_environment()
+{
+ std::unique_ptr<Engines::FieldsDict> ret( new Engines::FieldsDict );
+ std::vector< std::pair<std::string,std::string> > retCpp( GetOSEnvironment() );
+ auto sz = retCpp.size();
+ ret->length( sz );
+ for(auto i = 0 ; i < sz ; ++i)
+ {
+ (*ret)[i].key = CORBA::string_dup( retCpp[i].first.c_str() );
+ (*ret)[i].value <<= CORBA::string_dup( retCpp[i].second.c_str() );
+ }
+ return ret.release();
+}
+
//=============================================================================
//! Create a new component instance with environment variables specified
/*!
pid_t pid = fork();
if(pid == 0) // child
{
- for (CORBA::ULong i=0; i < env.length(); i++)
- {
- if (env[i].value.type()->kind() == CORBA::tk_string)
- {
- const char* value;
- env[i].value >>= value;
- std::string s(env[i].key);
- s+='=';
- s+=value;
- putenv(strdup(s.c_str()));
- }
- }
+ EffectiveOverrideEnvironment(env);
execl("/bin/sh", "sh", "-c", command.c_str() , (char *)0);
status=-1;
}
}
+void SALOME_ContainerManager::SetOverrideEnvForContainers(const Engines::KeyValDict& env)
+{
+ this->_override_env.clear();
+ auto sz = env.length();
+ for(auto i = 0 ; i < sz ; ++i)
+ _override_env.emplace_back( std::pair<std::string, std::string>(env[i].key,env[i].val) );
+}
+
+Engines::KeyValDict *SALOME_ContainerManager::GetOverrideEnvForContainers()
+{
+ std::unique_ptr<Engines::KeyValDict> ret( new Engines::KeyValDict );
+ auto sz = _override_env.size();
+ ret->length(sz);
+ for(auto i = 0 ; i < sz ; ++i)
+ {
+ (*ret)[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
+ (*ret)[i].val = CORBA::string_dup( _override_env[i].second.c_str() );
+ }
+ return ret.release();
+}
+
//=============================================================================
//! Give a suitable Container given constraints
/*! CORBA Method:
if (!CORBA::is_nil(cont))
{
INFOS("[GiveContainer] container " << containerNameInNS << " launched");
+ std::ostringstream envInfo;
+ std::for_each( _override_env.begin(), _override_env.end(), [&envInfo](const std::pair<std::string,std::string>& p) { envInfo << p.first << " = " << p.second << std::endl; } );
+ INFOS("[GiveContainer] container " << containerNameInNS << " override " << envInfo.str());
+ Engines::FieldsDict envCorba;
+ {
+ auto sz = _override_env.size();
+ envCorba.length(sz);
+ for(auto i = 0 ; i < sz ; ++i)
+ {
+ envCorba[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
+ envCorba[i].value <<= CORBA::string_dup( _override_env[i].second.c_str() );
+ }
+ }
+ cont->override_environment( envCorba );
return cont._retn();
}
else
#include "Utils_Mutex.hxx"
+#include <vector>
#include <string>
+#include <utility>
#include <set>
class SALOME_NamingService_Abstract;
~SALOME_ContainerManager();
// Corba Methods
- Engines::Container_ptr GiveContainer(const Engines::ContainerParameters& params);
+ Engines::Container_ptr GiveContainer(const Engines::ContainerParameters& params) override;
- void ShutdownContainers();
+ void ShutdownContainers() override;
+
+ void SetOverrideEnvForContainers(const Engines::KeyValDict& env) override;
+
+ Engines::KeyValDict *GetOverrideEnvForContainers() override;
// C++ Methods
void Shutdown();
static const int TIME_OUT_TO_LAUNCH_CONT;
static Utils_Mutex _getenvMutex;
static Utils_Mutex _systemMutex;
+private:
+ std::vector< std::pair<std::string, std::string> > _override_env;
};
#endif
virtual Engines::EngineComponent_ptr
create_component_instance(const char *componentName);
+ void override_environment( const Engines::FieldsDict& env ) override;
+
+ Engines::FieldsDict *get_os_environment() override;
+
virtual Engines::EngineComponent_ptr
create_component_instance_env(const char *componentName,
const Engines::FieldsDict &env,
global lcc,cm,dsm,esm,rm
import KernelLauncher
cm = KernelLauncher.myContainerManager()
+ type(cm).SetOverrideEnvForContainersSimple = ContainerManagerSetOverrideEnvForContainersSimple
rm = KernelLauncher.myResourcesManager()
from LifeCycleCORBA import LifeCycleCORBASSL
lcc = LifeCycleCORBASSL()
import SALOME
CM_NAME_IN_NS = "/ContainerManager"
cm = orb.string_to_object( nsAbroad.Resolve(CM_NAME_IN_NS).decode() )
+ type(cm).SetOverrideEnvForContainersSimple = ContainerManagerSetOverrideEnvForContainersSimple
naming_service.Register(cm,CM_NAME_IN_NS)
RM_NAME_IN_NS = "/ResourcesManager"
rm = orb.string_to_object( nsAbroad.Resolve(RM_NAME_IN_NS).decode() )
def __exit__(self, type, value, traceback):
salome_close()
+def ContainerManagerSetOverrideEnvForContainersSimple(self,env):
+ envEff = [ Engines.KeyValPairString(key=k,val=v) for k,v in env ]
+ return self.SetOverrideEnvForContainers( envEff )
+
#to expose all objects to pydoc
__all__=dir()