]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Draft
authorageay <ageay>
Fri, 7 Jan 2005 13:24:55 +0000 (13:24 +0000)
committerageay <ageay>
Fri, 7 Jan 2005 13:24:55 +0000 (13:24 +0000)
src/Container/Makefile.in
src/Container/SALOME_ContainerManager.cxx [new file with mode: 0644]
src/Container/SALOME_ContainerManager.hxx [new file with mode: 0644]
src/Container/SALOME_ContainerManagerServer.cxx [new file with mode: 0644]

index 30881439020ec773099f02f82b04a34c1591c2d3..729ee66791fee3f82b830c0d8054e023aa13af9f 100644 (file)
@@ -38,23 +38,25 @@ EXPORT_PYSCRIPTS = SALOME_ComponentPy.py SALOME_ContainerPy.py
 
 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
 
diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx
new file mode 100644 (file)
index 0000000..66d2e2e
--- /dev/null
@@ -0,0 +1,107 @@
+#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;
+}
diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx
new file mode 100644 (file)
index 0000000..818d06b
--- /dev/null
@@ -0,0 +1,35 @@
+#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
diff --git a/src/Container/SALOME_ContainerManagerServer.cxx b/src/Container/SALOME_ContainerManagerServer.cxx
new file mode 100644 (file)
index 0000000..d1a5a07
--- /dev/null
@@ -0,0 +1,41 @@
+#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.");
+  }
+}
+