Back to index

salome-kernel  6.5.0
SALOME_LifeCycleCORBA.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
00024 //  File   : SALOME_LifeCycleCORBA.cxx
00025 //  Author : Paul RASCLE, EDF
00026 //  Module : SALOME
00027 
00028 #include <iostream>
00029 #include <fstream>
00030 #include <sstream>
00031 #include <iomanip>
00032 
00033 #include <time.h>
00034 #ifndef WIN32
00035   #include <sys/time.h>
00036   #include <unistd.h>
00037 #endif
00038 
00039 #include "Basics_Utils.hxx"
00040 #include "utilities.h"
00041 
00042 #include <ServiceUnreachable.hxx>
00043 
00044 #include "SALOME_LifeCycleCORBA.hxx"
00045 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
00046 #include CORBA_CLIENT_HEADER(SALOME_Session)
00047 #include CORBA_CLIENT_HEADER(DSC_Engines)
00048 #include CORBA_CLIENT_HEADER(SALOME_Registry)
00049 #include CORBA_CLIENT_HEADER(SALOMEDS)
00050 #include CORBA_CLIENT_HEADER(Logger)
00051 
00052 #include "SALOME_ContainerManager.hxx"
00053 #include "SALOME_Component_i.hxx"
00054 #include "SALOME_NamingService.hxx"
00055 #include "SALOME_FileTransferCORBA.hxx"
00056 
00057 IncompatibleComponent::IncompatibleComponent( void ):
00058   SALOME_Exception( "IncompatibleComponent" )
00059 {
00060 }
00061 
00062 IncompatibleComponent::IncompatibleComponent(const IncompatibleComponent &ex):
00063   SALOME_Exception( ex ) 
00064 {
00065 }
00066 
00072 //=============================================================================
00076 //=============================================================================
00077 
00078 SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns)
00079 {
00080   // be sure to have an instance of traceCollector, when used via SWIG
00081   // in a Python module
00082   int argc = 0;
00083   char *xargv = (char*)"";
00084   char **argv = &xargv;
00085   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00086   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
00087   _NSnew=0;
00088   if (!ns)
00089     {
00090       _NS = new SALOME_NamingService(orb);
00091       _NSnew=_NS;
00092     }
00093   else _NS = ns;
00094   //add try catch
00095   _NS->Change_Directory("/"); // mpv 250105: current directory may be not root 
00096                               // (in SALOMEDS for an example)
00097   // not enough: set a current directory in naming service is not thread safe
00098   // if naming service instance is shared among several threads...
00099   // ==> allways use absolute path and dot rely on current directory!
00100 
00101   CORBA::Object_var obj =
00102     _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
00103   ASSERT( !CORBA::is_nil(obj));
00104   _ContManager=Engines::ContainerManager::_narrow(obj);
00105 
00106   obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
00107   ASSERT( !CORBA::is_nil(obj));
00108   _ResManager=Engines::ResourcesManager::_narrow(obj);
00109 }
00110 
00111 //=============================================================================
00115 //=============================================================================
00116 
00117 SALOME_LifeCycleCORBA::~SALOME_LifeCycleCORBA()
00118 {
00119   if(_NSnew)delete _NSnew;
00120 }
00121 
00122 //=============================================================================
00130 //=============================================================================
00131 Engines::EngineComponent_ptr
00132 SALOME_LifeCycleCORBA::FindComponent(const Engines::MachineParameters& params,
00133                                      const char *componentName,
00134                                      int studyId)
00135 {
00136   if (! isKnownComponentClass(componentName))
00137     return Engines::EngineComponent::_nil();
00138 
00139   Engines::ContainerParameters new_params;
00140   convert(params, new_params);
00141   new_params.resource_params.componentList.length(1);
00142   new_params.resource_params.componentList[0] = componentName;
00143   Engines::ResourceList_var listOfResources;
00144   try
00145     {
00146       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
00147     }
00148   catch( const SALOME::SALOME_Exception& ex )
00149     {
00150       return Engines::EngineComponent::_nil();
00151     }
00152 
00153   Engines::EngineComponent_var compo = _FindComponent(new_params,
00154                                                 componentName,
00155                                                 studyId,
00156                                                 listOfResources);
00157 
00158   return compo._retn();
00159 }
00160 
00161 //=============================================================================
00169 //=============================================================================
00170 
00171 Engines::EngineComponent_ptr
00172 SALOME_LifeCycleCORBA::LoadComponent(const Engines::MachineParameters& params,
00173                                      const char *componentName,
00174                                      int studyId)
00175 {
00176   // --- Check if Component Name is known in ModuleCatalog
00177 
00178   if (! isKnownComponentClass(componentName))
00179     return Engines::EngineComponent::_nil();
00180 
00181   Engines::ContainerParameters new_params;
00182   convert(params, new_params);
00183   new_params.resource_params.componentList.length(1);
00184   new_params.resource_params.componentList[0] = componentName;
00185 
00186   Engines::ResourceList_var listOfResources;
00187   try
00188     {
00189       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
00190     }
00191   catch( const SALOME::SALOME_Exception& ex )
00192     {
00193       return Engines::EngineComponent::_nil();
00194     }
00195   new_params.resource_params.resList = listOfResources;
00196 
00197   Engines::EngineComponent_var compo = _LoadComponent(new_params,
00198                                                 componentName,
00199                                                 studyId);
00200 
00201   return compo._retn();
00202 }
00203 
00204 //=============================================================================
00213 //=============================================================================
00214 
00215 Engines::EngineComponent_ptr
00216 SALOME_LifeCycleCORBA::
00217 FindOrLoad_Component(const Engines::MachineParameters& params,
00218                      const char *componentName,
00219                      int studyId)
00220 {
00221   // --- Check if Component Name is known in ModuleCatalog
00222 
00223   if (! isKnownComponentClass(componentName))
00224     return Engines::EngineComponent::_nil();
00225 
00226   Engines::ContainerParameters new_params;
00227   convert(params, new_params);
00228   new_params.resource_params.componentList.length(1);
00229   new_params.resource_params.componentList[0] = componentName;
00230 
00231   // For Compatibility -> if hostname == localhost put name == hostname
00232   if (std::string(new_params.resource_params.hostname.in()) == "localhost")
00233   {
00234     new_params.resource_params.hostname = CORBA::string_dup(Kernel_Utils::GetHostname().c_str());
00235     new_params.resource_params.name = CORBA::string_dup(Kernel_Utils::GetHostname().c_str());
00236   }
00237 
00238   Engines::ResourceList_var listOfResources;
00239   try
00240     {
00241       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
00242     }
00243   catch( const SALOME::SALOME_Exception& ex )
00244     {
00245       return Engines::EngineComponent::_nil();
00246     }
00247 
00248   Engines::EngineComponent_var compo = _FindComponent(new_params,
00249                                                 componentName,
00250                                                 studyId,
00251                                                 listOfResources);
00252 
00253   if(CORBA::is_nil(compo))
00254   {
00255     new_params.resource_params.resList = listOfResources;
00256     compo = _LoadComponent(new_params,
00257                            componentName,
00258                            studyId);
00259   }
00260 
00261   return compo._retn();
00262 }
00263 
00264 Engines::EngineComponent_ptr
00265 SALOME_LifeCycleCORBA::
00266 FindOrLoad_Component(const Engines::ContainerParameters& params,
00267                      const char *componentName,
00268                      int studyId)
00269 {
00270   // --- Check if Component Name is known in ModuleCatalog
00271 
00272   if (! isKnownComponentClass(componentName))
00273     return Engines::EngineComponent::_nil();
00274 
00275   Engines::ContainerParameters new_params(params);
00276   new_params.resource_params.componentList.length(1);
00277   new_params.resource_params.componentList[0] = componentName;
00278 
00279   Engines::ResourceList_var listOfResources;
00280   try
00281     {
00282       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
00283     }
00284   catch( const SALOME::SALOME_Exception& ex )
00285     {
00286       return Engines::EngineComponent::_nil();
00287     }
00288 
00289   Engines::EngineComponent_var compo = _FindComponent(new_params,
00290                                                 componentName,
00291                                                 studyId,
00292                                                 listOfResources);
00293 
00294   if(CORBA::is_nil(compo))
00295   {
00296     new_params.resource_params.resList = listOfResources;
00297     compo = _LoadComponent(new_params,
00298                            componentName,
00299                            studyId);
00300   }
00301 
00302   return compo._retn();
00303 }
00304 
00305 //=============================================================================
00315 //=============================================================================
00316 
00317 Engines::EngineComponent_ptr
00318 SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName,
00319                                             const char *componentName)
00320 {
00321   MESSAGE("SALOME_LifeCycleCORBA::FindOrLoad_Component INTERACTIF " << containerName << " " << componentName ) ;
00322 
00323   // --- Check if Component Name is known in ModuleCatalog
00324   if (! isKnownComponentClass(componentName))
00325     return Engines::EngineComponent::_nil();
00326 
00327   // --- Check if containerName contains machine name (if yes: rg>0)
00328   char *stContainer=strdup(containerName);
00329   std::string st2Container(stContainer);
00330   int rg=st2Container.find("/");
00331 
00332   Engines::MachineParameters_var params=new Engines::MachineParameters;
00333   preSet(params);
00334   if (rg<0)
00335   {
00336     // containerName doesn't contain "/" => Local container
00337     params->container_name=CORBA::string_dup(stContainer);
00338     params->hostname="";
00339   }
00340   else 
00341   {
00342     stContainer[rg]='\0';
00343     params->container_name=CORBA::string_dup(stContainer+rg+1);
00344     params->hostname=CORBA::string_dup(stContainer);
00345   }
00346   params->isMPI = false;
00347   SCRUTE(params->container_name);
00348   free(stContainer);
00349   return FindOrLoad_Component(params, componentName);
00350 }
00351 
00352 //=============================================================================
00358 //=============================================================================
00359 
00360 bool SALOME_LifeCycleCORBA::isKnownComponentClass(const char *componentName)
00361 {
00362   try
00363   {
00364     CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
00365     SALOME_ModuleCatalog::ModuleCatalog_var Catalog = 
00366       SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
00367     ASSERT(! CORBA::is_nil(Catalog));
00368     SALOME_ModuleCatalog::Acomponent_var compoInfo = 
00369       Catalog->GetComponent(componentName);
00370     if (CORBA::is_nil (compoInfo)) 
00371     {
00372       MESSAGE("Catalog Error: Component not found in the catalog " << componentName);
00373       return false;
00374     }
00375     else return true;
00376   }
00377   catch (ServiceUnreachable&)
00378   {
00379     INFOS("Caught exception: Naming Service Unreachable");
00380   }
00381   catch (...)
00382   {
00383     INFOS("Caught unknown exception.");
00384   }
00385   return false;
00386 }
00387 
00388 //=============================================================================
00392 //=============================================================================
00393 
00394 bool 
00395 SALOME_LifeCycleCORBA::isMpiContainer(const Engines::ContainerParameters& params)
00396   throw(IncompatibleComponent)
00397 {
00398   if( params.isMPI )
00399     return true;
00400   else
00401     return false;
00402 }
00403 
00404 
00405 //=============================================================================
00418 //=============================================================================
00419 
00420 void SALOME_LifeCycleCORBA::preSet(Engines::MachineParameters& params)
00421 {
00422   params.container_name = "";
00423   params.hostname = "";
00424   params.OS = "";
00425   params.mem_mb = 0;
00426   params.cpu_clock = 0;
00427   params.nb_proc_per_node = 0;
00428   params.nb_node = 0;
00429   params.isMPI = false;
00430   params.workingdir = "";
00431   params.mode = "";
00432   params.policy = "";
00433   params.parallelLib = "";
00434   params.nb_component_nodes = 0;
00435 }
00436 
00437 void 
00438 SALOME_LifeCycleCORBA::preSet(Engines::ResourceParameters& params)
00439 {
00440   params.name = "";
00441   params.hostname = "";
00442   params.OS = "";
00443   params.nb_proc = 0;
00444   params.mem_mb = 0;
00445   params.cpu_clock = 0;
00446   params.nb_node = 0;
00447   params.nb_proc_per_node = 0;
00448   params.policy = "";
00449 }
00450 
00451 void SALOME_LifeCycleCORBA::preSet( Engines::ContainerParameters& params)
00452 {
00453   params.container_name = "";
00454   params.mode = "";
00455   params.workingdir = "";
00456   params.nb_proc = 0;
00457   params.isMPI = false;
00458   params.parallelLib = "";
00459   SALOME_LifeCycleCORBA::preSet(params.resource_params);
00460 }
00461 
00462 void 
00463 SALOME_LifeCycleCORBA::convert(const Engines::MachineParameters& params_in, 
00464                                Engines::ContainerParameters& params_out)
00465 {
00466   SALOME_LifeCycleCORBA::preSet(params_out);
00467 
00468   // Container part
00469   params_out.container_name = params_in.container_name;
00470   params_out.mode = params_in.mode;
00471   params_out.workingdir = params_in.workingdir;
00472   params_out.isMPI = params_in.isMPI;
00473   params_out.parallelLib = params_in.parallelLib;
00474 
00475   // Resource part
00476   params_out.resource_params.hostname = params_in.hostname;
00477   params_out.resource_params.OS = params_in.OS;
00478   params_out.resource_params.mem_mb = params_in.mem_mb;
00479   params_out.resource_params.cpu_clock = params_in.cpu_clock;
00480   params_out.resource_params.nb_node = params_in.nb_node;
00481   params_out.resource_params.nb_proc_per_node = params_in.nb_proc_per_node;
00482   params_out.resource_params.policy = params_in.policy;
00483   params_out.resource_params.componentList = params_in.componentList;
00484 
00485   params_out.resource_params.resList.length(params_in.computerList.length());
00486   for (CORBA::ULong i = 0; i < params_in.computerList.length(); i++)
00487     params_out.resource_params.resList[i] = params_in.computerList[i];
00488 }
00489 
00490 //=============================================================================
00494 //=============================================================================
00495 
00496 int SALOME_LifeCycleCORBA::NbProc(const Engines::ContainerParameters& params)
00497 {
00498   if( !isMpiContainer(params) )
00499     return 0;
00500   else if( params.nb_proc <= 0 )
00501     return 1;
00502   else
00503     return params.nb_proc;
00504 }
00505 
00506 //=============================================================================
00511 //=============================================================================
00512 
00513 Engines::ContainerManager_ptr SALOME_LifeCycleCORBA::getContainerManager()
00514 {
00515  Engines::ContainerManager_var contManager =
00516    Engines::ContainerManager::_duplicate(_ContManager);
00517  return contManager._retn();
00518 }
00519 
00520 //=============================================================================
00525 //=============================================================================
00526 
00527 Engines::ResourcesManager_ptr SALOME_LifeCycleCORBA::getResourcesManager()
00528 {
00529  Engines::ResourcesManager_var resManager =
00530    Engines::ResourcesManager::_duplicate(_ResManager);
00531  return resManager._retn();
00532 }
00533 
00534 //=============================================================================
00537 //=============================================================================
00538 
00539 void SALOME_LifeCycleCORBA::shutdownServers()
00540 {
00541   // get each Container from NamingService => shutdown it
00542   // (the order is inverse to the order of servers initialization)
00543   
00544   SALOME::Session_var session = SALOME::Session::_nil();
00545   CORBA::Long pid = 0;
00546   CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
00547   if (!CORBA::is_nil(objS))
00548   {
00549     session = SALOME::Session::_narrow(objS);
00550     if (!CORBA::is_nil(session))
00551     {
00552       pid = session->getPID();
00553     }
00554   }
00555 
00556   std::string hostname = Kernel_Utils::GetHostname();
00557   
00558   // 1) ConnectionManager
00559   try
00560     {
00561       CORBA::Object_var objCnM=_NS->Resolve("/ConnectionManager");
00562       Engines::ConnectionManager_var connMan=Engines::ConnectionManager::_narrow(objCnM);
00563       if ( !CORBA::is_nil(connMan) && ( pid != connMan->getPID() ) )
00564         connMan->ShutdownWithExit();
00565     }
00566   catch(const CORBA::Exception& e)
00567     {
00568        // ignore and continue
00569     }
00570 
00571   timespec ts_req;
00572   ts_req.tv_nsec=100000000;
00573   ts_req.tv_sec=0;
00574 
00575 //Wait some time so that ConnectionManager be completely shutdown
00576 #ifndef WIN32
00577   nanosleep(&ts_req,0);
00578 #endif
00579 
00580   // 2) SALOMEDS
00581   try
00582     {
00583       CORBA::Object_var objSDS = _NS->Resolve("/myStudyManager");
00584       SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ;
00585       if ( !CORBA::is_nil(studyManager) && ( pid != studyManager->getPID() ) )
00586         studyManager->Shutdown();
00587     }
00588   catch(const CORBA::Exception& e)
00589     {
00590        // ignore and continue
00591     }
00592 
00593 //Wait some time so that study be completely shutdown
00594 #ifndef WIN32
00595   nanosleep(&ts_req,0);
00596 #endif
00597 
00598   // 3) ModuleCatalog
00599   try
00600     {
00601       CORBA::Object_var objMC=_NS->Resolve("/Kernel/ModulCatalog");
00602       SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC);
00603       if ( !CORBA::is_nil(catalog) && ( pid != catalog->getPID() ) )
00604         catalog->shutdown();
00605     }
00606   catch(const CORBA::Exception& e)
00607     {
00608        // ignore and continue
00609     }
00610 
00611 //Wait some time so that ModulCatalog be completely shutdown
00612 #ifndef WIN32
00613   nanosleep(&ts_req,0);
00614 #endif
00615 
00616   // 4) SalomeLauncher
00617   try
00618     {
00619       CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher");
00620       Engines::SalomeLauncher_var launcher = Engines::SalomeLauncher::_narrow(objSL);
00621       if (!CORBA::is_nil(launcher) && (pid != launcher->getPID()))
00622         launcher->Shutdown();
00623     }
00624   catch(const CORBA::Exception& e)
00625     {
00626        // ignore and continue
00627     }
00628   
00629 //Wait some time so that launcher be completely shutdown
00630 #ifndef WIN32
00631   nanosleep(&ts_req,0);
00632 #endif
00633 
00634   // 5) Registry
00635   try
00636     {
00637       CORBA::Object_var objR = _NS->Resolve("/Registry");
00638       Registry::Components_var registry = Registry::Components::_narrow(objR);
00639       if ( !CORBA::is_nil(registry) && ( pid != registry->getPID() ) )
00640           registry->Shutdown();
00641     }
00642   catch(const CORBA::Exception& e)
00643     {
00644        // ignore and continue
00645     }
00646 
00647   // 6) Session
00648   if ( !CORBA::is_nil( session ) ) {
00649     try
00650     {
00651       session->Shutdown();
00652     }
00653     catch(const CORBA::Exception& e)
00654     {
00655       // ignore and continue
00656     }
00657   }
00658 
00659   // 7) Logger
00660   int argc = 0;
00661   char *xargv = (char*)"";
00662   char **argv = &xargv;
00663   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00664 
00665   CORBA::Object_var objLog = CORBA::Object::_nil();
00666   CosNaming::NamingContext_var inc;
00667   CORBA::Object_var theObj = CORBA::Object::_nil();
00668   std::string stdname = "Logger";
00669   CosNaming::Name name;
00670   name.length(1);
00671   name[0].id = CORBA::string_dup(stdname.c_str());
00672   try
00673   { 
00674     if(!CORBA::is_nil(orb)) 
00675       theObj = orb->resolve_initial_references("NameService");
00676     if (!CORBA::is_nil(theObj))
00677       inc = CosNaming::NamingContext::_narrow(theObj);
00678   }
00679   catch(...)
00680   {
00681   }
00682   if(!CORBA::is_nil(inc)) 
00683   {
00684     try
00685     {
00686       objLog = inc->resolve(name);
00687       SALOME_Logger::Logger_var logger = SALOME_Logger::Logger::_narrow(objLog);
00688       if ( !CORBA::is_nil(logger) )
00689         logger->shutdown();
00690     }
00691     catch(...)
00692     {
00693     }
00694   }
00695 }
00696 
00697 //=============================================================================
00700 //=============================================================================
00701 
00702 void SALOME_LifeCycleCORBA::killOmniNames()
00703 {
00704   std::string portNumber (::getenv ("NSPORT") );
00705   if ( !portNumber.empty() ) 
00706   {
00707 #ifdef WNT
00708 #else
00709     std::string cmd ;
00710     cmd = std::string( "ps -eo pid,command | grep -v grep | grep -E \"omniNames.*")
00711       + portNumber
00712       + std::string("\" | awk '{cmd=sprintf(\"kill -9 %s\",$1); system(cmd)}'" );
00713     MESSAGE(cmd);
00714     try {
00715       system ( cmd.c_str() );
00716     }
00717     catch ( ... ) {
00718     }
00719 #endif
00720   }
00721   
00722   // NPAL 18309  (Kill Notifd)
00723   if ( !portNumber.empty() ) 
00724   {
00725     std::string cmd = ("from killSalomeWithPort import killNotifdAndClean; ");
00726     cmd += std::string("killNotifdAndClean(") + portNumber + "); ";
00727     cmd  = std::string("python -c \"") + cmd +"\" > /dev/null 2> /dev/null";
00728     MESSAGE(cmd);
00729     system( cmd.c_str() );
00730   }
00731 }
00732 
00733 //=============================================================================
00745 //=============================================================================
00746 
00747 Engines::EngineComponent_ptr
00748 SALOME_LifeCycleCORBA::
00749 _FindComponent(const Engines::ContainerParameters& params,
00750                const char *componentName,
00751                int studyId,
00752                const Engines::ResourceList& listOfResources)
00753 {
00754   // --- build the list of machines on which the component is already running
00755   const char *containerName = params.container_name;
00756   int nbproc = NbProc(params);
00757 
00758   Engines::ResourceList_var resourcesOK = new Engines::ResourceList;
00759 
00760   unsigned int lghtOfresourcesOK = 0;
00761   resourcesOK->length(listOfResources.length());
00762 
00763   for(unsigned int i=0; i < listOfResources.length(); i++)
00764   {
00765     const char * currentResource = listOfResources[i];
00766     CORBA::Object_var obj = _NS->ResolveComponent(currentResource,
00767                                                   containerName,
00768                                                   componentName,
00769                                                   nbproc);
00770     if (!CORBA::is_nil(obj))
00771       resourcesOK[lghtOfresourcesOK++] = CORBA::string_dup(currentResource);
00772   }
00773 
00774   // --- find the best machine among the list
00775   if(lghtOfresourcesOK != 0)
00776   {
00777     resourcesOK->length(lghtOfresourcesOK);
00778     CORBA::String_var bestResource = _ResManager->FindFirst(resourcesOK);
00779     CORBA::Object_var obj = _NS->ResolveComponent(bestResource,
00780                                                   containerName,
00781                                                   componentName,
00782                                                   nbproc);
00783     return Engines::EngineComponent::_narrow(obj);
00784   }
00785   else
00786     return Engines::EngineComponent::_nil();
00787 }
00788 
00789 //=============================================================================
00801 //=============================================================================
00802 
00803 Engines::EngineComponent_ptr 
00804 SALOME_LifeCycleCORBA::
00805 _LoadComponent(const Engines::ContainerParameters& params, 
00806               const char *componentName,
00807               int studyId)
00808 {
00809   MESSAGE("_LoadComponent, required " << params.container_name <<
00810           " " << componentName << " " << NbProc(params));
00811 
00812   Engines::ContainerParameters local_params(params);
00813   local_params.mode = CORBA::string_dup("findorstart");
00814   Engines::Container_var cont = _ContManager->GiveContainer(local_params);
00815   if (CORBA::is_nil(cont)) return Engines::EngineComponent::_nil();
00816 
00817   char* reason;
00818   bool isLoadable = cont->load_component_Library(componentName,reason);
00819   if (!isLoadable) 
00820     {
00821       //std::cerr << reason << std::endl;
00822       CORBA::string_free(reason);
00823       return Engines::EngineComponent::_nil();
00824     }
00825   CORBA::string_free(reason);
00826 
00827   Engines::EngineComponent_var myInstance =
00828     cont->create_component_instance(componentName, studyId);
00829   return myInstance._retn();
00830 }
00831 
00832 //=============================================================================
00840 //=============================================================================
00841 Engines::EngineComponent_ptr
00842 SALOME_LifeCycleCORBA::Load_ParallelComponent(const Engines::ContainerParameters& params,
00843                                               const char *componentName,
00844                                               int studyId)
00845 {
00846   MESSAGE("Entering LoadParallelComponent");
00847 
00848 /*MESSAGE("Parameters : ");
00849   MESSAGE("Container name : " << params.container_name);
00850   MESSAGE("Number of component nodes : " << params.nb_component_nodes);
00851   MESSAGE("Component Name : " << componentName);*/
00852 
00853   Engines::ContainerParameters parms(params);
00854   parms.resource_params.componentList.length(1);
00855   parms.resource_params.componentList[0] = componentName;
00856   parms.mode = CORBA::string_dup("findorstart");
00857 
00858   MESSAGE("Starting Parallel Container");
00859   Engines::Container_var cont = _ContManager->GiveContainer(parms);
00860   if (CORBA::is_nil(cont)) {
00861     INFOS("FindOrStartParallelContainer() returns a NULL container !");
00862     return Engines::EngineComponent::_nil();
00863   }
00864 
00865   MESSAGE("Loading component library");
00866   char* reason;
00867   bool isLoadable = cont->load_component_Library(componentName,reason);
00868   if (!isLoadable) {
00869     INFOS(componentName <<" library is not loadable !");
00870     //std::cerr << reason << std::endl;
00871     CORBA::string_free(reason);
00872     return Engines::EngineComponent::_nil();
00873   }
00874   CORBA::string_free(reason);
00875 
00876   MESSAGE("Creating component instance");
00877   // @PARALLEL@ permits to identify that the component requested
00878   // is a parallel component.
00879   std::string name = std::string(componentName);
00880   Engines::EngineComponent_var myInstance = cont->create_component_instance(name.c_str(), studyId);
00881   if (CORBA::is_nil(myInstance))
00882     INFOS("create_component_instance returns a NULL component !");
00883   return myInstance._retn();
00884 }
00885 
00892 void SALOME_LifeCycleCORBA::copyFile(const char* hostSrc, const char* fileSrc, const char* hostDest, const char* fileDest)
00893 {
00894   if(strcmp(hostDest,"localhost") == 0)
00895     {
00896       //if localhost use a shortcut
00897       SALOME_FileTransferCORBA transfer(hostSrc,fileSrc);
00898       transfer.getLocalFile(fileDest);
00899       return;
00900     }
00901 
00902   Engines::ContainerManager_var contManager = getContainerManager();
00903 
00904   Engines::ContainerParameters params;
00905   preSet(params);
00906 
00907   params.resource_params.hostname = hostDest;
00908   params.mode = CORBA::string_dup("findorstart");
00909   Engines::Container_var containerDest = contManager->GiveContainer(params);
00910 
00911   params.resource_params.hostname = hostSrc;
00912   Engines::Container_var containerSrc = contManager->GiveContainer(params);
00913 
00914   containerDest->copyFile(containerSrc,fileSrc,fileDest);
00915 }
00916 
00921 SALOME_NamingService * SALOME_LifeCycleCORBA::namingService()
00922 {
00923   return _NS;
00924 }
00925 
00930 CORBA::ORB_ptr SALOME_LifeCycleCORBA::orb()
00931 {
00932   return _NS->orb();
00933 }