EXPORT_HEADERS = \
SALOME_Component_i.hxx \
+ SALOME_ContainerManager.hxx \
SALOME_Container_i.hxx
# Libraries targets
LIB = libSalomeContainer.la
-LIB_SRC = Component_i.cxx Container_i.cxx
+LIB_SRC = Component_i.cxx Container_i.cxx SALOME_ContainerManager.cxx
LIB_SERVER_IDL = SALOME_Registry.idl SALOME_Component.idl
+LIB_CLIENT_IDL = SALOME_ContainerManager.idl
# Executables targets
-BIN = SALOME_Container
+BIN = SALOME_Container SALOME_ContainerManagerServer
BIN_SRC = SALOME_Container_SignalsHandler.cxx
-BIN_SERVER_IDL = SALOME_Component.idl
+BIN_SERVER_IDL = SALOME_Component.idl SALOME_ContainerManager.idl
-CPPFLAGS+= $(PYTHON_INCLUDES) $(MPI_INCLUDE) $(OCC_INCLUDES)
+CPPFLAGS+= $(PYTHON_INCLUDES) $(MPI_INCLUDE) $(OCC_INCLUDES) $(QT_MT_INCLUDES)
CXXFLAGS+=$(OCC_CXXFLAGS)
-LDFLAGS+= -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace
+LDFLAGS+= $(QT_MT_LIBS) -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace
LIBS += @LDEXPDYNFLAGS@ $(PYTHON_LIBS) $(MPI_LIBS) -lCASCatch
--- /dev/null
+#include "SALOME_ContainerManager.hxx"
+#include "SALOME_NamingService.hxx"
+#include "OpUtil.hxx"
+#include <sys/types.h>
+#include <unistd.h>
+#define TIME_OUT_TO_LAUNCH_CONT 21
+
+using namespace std;
+
+const char *SALOME_ContainerManager::_ContainerManagerNameInNS="ContainerManager";
+
+SALOME_ContainerManager::SALOME_ContainerManager(SALOME_NamingService *ns):_NS(ns)
+{
+}
+
+Engines::Container_ptr SALOME_ContainerManager::FindOrStartContainer(const char *containerName, const MachineList& possibleComputers)
+{
+ Engines::Container_ptr ret=DoesExistContainer(containerName,possibleComputers);
+ if(!CORBA::is_nil(ret))
+ return ret;
+ // Container doesn't exist try to launch it ...
+ vector<string> vector;
+ string theMachine=_LoadManager.FindBest(possibleComputers);
+ string command;
+ if(theMachine==GetHostname())
+ command=_ResManager.BuildCommandToLaunchLocalContainer(containerName);
+ else
+ command=_ResManager.BuildTempFileToLaunchRemoteContainer(theMachine,containerName);
+ _ResManager.RmTmpFile();
+ int status=system(command.c_str());
+ if (status == -1) {
+ MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status -1)");
+ return Engines::Container::_nil();
+ }
+ else if (status == 217) {
+ MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status 217)");
+ return Engines::Container::_nil();
+ }
+ else {
+ int count=TIME_OUT_TO_LAUNCH_CONT;
+ while ( CORBA::is_nil(ret) && count ) {
+ sleep( 1 ) ;
+ count-- ;
+ if ( count != 10 )
+ MESSAGE( count << ". Waiting for FactoryServer on " << theMachine);
+ string containerNameInNS=BuildContainerNameInNS(containerName,theMachine.c_str());
+ CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
+ ret=Engines::Container::_narrow(obj);
+ }
+ if ( CORBA::is_nil(ret) ) {
+ MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed");
+ }
+ return ret;
+ }
+}
+
+MachineList *SALOME_ContainerManager::GetResourcesFitting(const MachineParameters& params, const char *componentName)
+{
+ vector<string> vec=_ResManager.GetResourcesFitting(params,componentName);
+ MachineList *ret=new MachineList;
+ ret->length(vec.size());
+ for(unsigned int i=0;i<vec.size();i++)
+ {
+ (*ret)[i]=(vec[i]).c_str();
+ }
+ return ret;
+}
+
+char* SALOME_ContainerManager::FindBest(const MachineList& possibleComputers)
+ {
+ string theMachine=_LoadManager.FindBest(possibleComputers);
+ return CORBA::string_dup(theMachine.c_str());
+ }
+
+void SALOME_ContainerManager::ShutdownContainers()
+{
+}
+
+Engines::Container_ptr SALOME_ContainerManager::FindContainer(const char *containerName,const char *theMachine)
+{
+ string containerNameInNS(BuildContainerNameInNS(containerName,theMachine));
+ CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
+ if( !CORBA::is_nil(obj) )
+ return Engines::Container::_narrow(obj);
+ else
+ return Engines::Container::_nil();
+}
+
+Engines::Container_ptr SALOME_ContainerManager::DoesExistContainer(const char *containerName,const MachineList& possibleComputers)
+{
+ for(unsigned int i=0;i<possibleComputers.length();i++)
+ {
+ Engines::Container_ptr cont=FindContainer(containerName,possibleComputers[i]);
+ if( !CORBA::is_nil(cont) )
+ return cont;
+ }
+ return Engines::Container::_nil();
+}
+
+string SALOME_ContainerManager::BuildContainerNameInNS(const char *containerName,const char *machineName)
+{
+ string containerNameInNS("/Containers/");
+ containerNameInNS+=machineName;
+ containerNameInNS+="/";
+ containerNameInNS+=containerName;
+ return containerNameInNS;
+}
--- /dev/null
+#ifndef __SALOME_CONTAINERMANAGER_HXX__
+#define __SALOME_CONTAINERMANAGER_HXX__
+
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOME_Component)
+#include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
+#include "SALOME_ResourcesManager.hxx"
+#include "SALOME_LoadRateManager.hxx"
+
+#include <string>
+#include <vector>
+
+class SALOME_NamingService;
+
+class SALOME_ContainerManager: public POA_Engines::ContainerManager,
+ public PortableServer::RefCountServantBase {
+private:
+ SALOME_ResourcesManager _ResManager;
+ SALOME_LoadRateManager _LoadManager;
+ SALOME_NamingService *_NS;
+public:
+ SALOME_ContainerManager(SALOME_NamingService *ns);
+ Engines::Container_ptr FindOrStartContainer(const char *containerName, const MachineList& possibleComputer);
+ MachineList *GetResourcesFitting(const MachineParameters& params, const char *componentName);
+ char* FindBest(const MachineList& possibleComputers);
+ void ShutdownContainers();
+
+ static const char *_ContainerManagerNameInNS;
+private:
+ Engines::Container_ptr DoesExistContainer(const char *containerName,const MachineList& possibleComputers);
+ Engines::Container_ptr FindContainer(const char *containerName,const char *theMachine);
+ std::string BuildContainerNameInNS(const char *containerName,const char *machineName);
+};
+
+#endif
--- /dev/null
+#include "SALOME_ContainerManager.hxx"
+#include "SALOME_NamingService.hxx"
+#include "Utils_ORB_INIT.hxx"
+#include "Utils_SINGLETON.hxx"
+#include "LocalTraceCollector.hxx"
+
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+ ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
+ CORBA::ORB_var &orb = init( argc , argv ) ;
+ LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb);
+ try {
+ SALOME_NamingService *ns=new SALOME_NamingService(orb);
+ SALOME_ContainerManager *contManager=new SALOME_ContainerManager(ns);
+ Engines::ContainerManager_ptr contManagerServant=contManager->_this();
+ ns->Register(contManagerServant,SALOME_ContainerManager::_ContainerManagerNameInNS);
+ CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+ PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
+ PortableServer::POAManager_var pman = root_poa->the_POAManager();
+ pman->activate();
+ orb->run();
+ delete myThreadTrace;
+ }catch(CORBA::SystemException&){
+ INFOS("Caught CORBA::SystemException.");
+ }catch(PortableServer::POA::WrongPolicy&){
+ INFOS("Caught CORBA::WrongPolicyException.");
+ }catch(PortableServer::POA::ServantAlreadyActive&){
+ INFOS("Caught CORBA::ServantAlreadyActiveException");
+ }catch(CORBA::Exception&){
+ INFOS("Caught CORBA::Exception.");
+ }catch(std::exception& exc){
+ INFOS("Caught std::exception - "<<exc.what());
+ }catch(...){
+ INFOS("Caught unknown exception.");
+ }
+}
+