]> SALOME platform Git repositories - modules/kernel.git/blob - src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx
Salome HOME
Merge remote branch 'origin/bsr/resmgr'
[modules/kernel.git] / src / LifeCycleCORBA / SALOME_LifeCycleCORBA.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
24 //  File   : SALOME_LifeCycleCORBA.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SALOME
27
28 #include <iostream>
29 #include <fstream>
30 #include <sstream>
31 #include <iomanip>
32
33 #include <time.h>
34 #ifndef WIN32
35   #include <sys/time.h>
36   #include <unistd.h>
37 #endif
38
39 #include "Basics_Utils.hxx"
40 #include "utilities.h"
41
42 #include <ServiceUnreachable.hxx>
43
44 #include "SALOME_LifeCycleCORBA.hxx"
45 #include "SALOME_ResourcesManager.hxx"
46 #include "SALOMESDS_DataServerManager.hxx"
47
48 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
49 #include CORBA_CLIENT_HEADER(SALOME_Session)
50 #include CORBA_CLIENT_HEADER(DSC_Engines)
51 #include CORBA_CLIENT_HEADER(SALOME_Registry)
52 #include CORBA_CLIENT_HEADER(SALOMEDS)
53 #include CORBA_CLIENT_HEADER(SALOME_SDS)
54 #include CORBA_CLIENT_HEADER(Logger)
55 #include CORBA_CLIENT_HEADER(SALOME_Launcher)
56
57 #include "SALOME_ResourcesManager.hxx"
58 #include "SALOME_ContainerManager.hxx"
59 #include "SALOME_Component_i.hxx"
60 #include "SALOME_NamingService.hxx"
61 #include "SALOME_FileTransferCORBA.hxx"
62
63 IncompatibleComponent::IncompatibleComponent( void ):
64   SALOME_Exception( "IncompatibleComponent" )
65 {
66 }
67
68 IncompatibleComponent::IncompatibleComponent(const IncompatibleComponent &ex):
69   SALOME_Exception( ex )
70 {
71 }
72
73 /*! \class SALOME_LifeCycleCORBA
74     \brief A class to manage life cycle of SALOME components.
75
76 */
77
78 //=============================================================================
79 /*!
80  *  Constructor
81  */
82 //=============================================================================
83
84 SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns)
85 {
86   // be sure to have an instance of traceCollector, when used via SWIG
87   // in a Python module
88   int argc = 0;
89   char *xargv = (char*)"";
90   char **argv = &xargv;
91   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
92   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
93   _NSnew=0;
94   if (!ns)
95     {
96       _NS = new SALOME_NamingService(orb);
97       _NSnew=_NS;
98     }
99   else _NS = ns;
100   //add try catch
101   _NS->Change_Directory("/"); // mpv 250105: current directory may be not root
102                               // (in SALOMEDS for an example)
103   // not enough: set a current directory in naming service is not thread safe
104   // if naming service instance is shared among several threads...
105   // ==> always use absolute path and don't rely on current directory!
106
107   CORBA::Object_var obj =
108     _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
109   if (CORBA::is_nil(obj))
110     throw SALOME_Exception("Error: Cannot resolve ContainerManager in Naming Service");
111   _ContManager=Engines::ContainerManager::_narrow(obj);
112
113   obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
114   if (CORBA::is_nil(obj))
115     throw SALOME_Exception("Error: Cannot resolve ResourceManager in Naming Service");
116   _ResManager=Engines::ResourcesManager::_narrow(obj);
117 }
118
119 //=============================================================================
120 /*!
121  *  Destructor
122  */
123 //=============================================================================
124
125 SALOME_LifeCycleCORBA::~SALOME_LifeCycleCORBA()
126 {
127   if(_NSnew)delete _NSnew;
128 }
129
130 //=============================================================================
131 /*! \brief Find an already existing and registered component instance.
132  *
133  *  \param params         container parameters like type or name...
134  *  \param componentName  the name of component class
135  *  \return a CORBA reference of the component instance, or _nil if not found
136  */
137 //=============================================================================
138 Engines::EngineComponent_ptr
139 SALOME_LifeCycleCORBA::FindComponent(const Engines::ContainerParameters& params,
140                                      const char *componentName)
141 {
142   if (! isKnownComponentClass(componentName))
143     return Engines::EngineComponent::_nil();
144
145   Engines::ContainerParameters new_params(params);
146   new_params.resource_params.componentList.length(1);
147   new_params.resource_params.componentList[0] = componentName;
148   new_params.resource_params.can_run_containers = true;
149   Engines::ResourceList_var listOfResources;
150   try
151     {
152       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
153     }
154   catch( const SALOME::SALOME_Exception& ex )
155     {
156       return Engines::EngineComponent::_nil();
157     }
158
159   Engines::EngineComponent_var compo = _FindComponent(new_params,
160                                                 componentName,
161                                                 listOfResources);
162
163   return compo._retn();
164 }
165
166 //=============================================================================
167 /*! \brief Load a component instance on a container defined by its parameters
168  *
169  *  \param params         container parameters like type or name...
170  *  \param componentName  the name of component class
171  *  \return a CORBA reference of the component instance, or _nil if problem
172  */
173 //=============================================================================
174
175 Engines::EngineComponent_ptr
176 SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params,
177                                      const char *componentName)
178 {
179   // --- Check if Component Name is known in ModuleCatalog
180
181   if (! isKnownComponentClass(componentName))
182     return Engines::EngineComponent::_nil();
183
184   Engines::ContainerParameters new_params(params);
185   new_params.resource_params.componentList.length(1);
186   new_params.resource_params.componentList[0] = componentName;
187   new_params.resource_params.can_run_containers = true;
188
189   Engines::ResourceList_var listOfResources;
190   try
191     {
192       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
193     }
194   catch( const SALOME::SALOME_Exception& ex )
195     {
196       return Engines::EngineComponent::_nil();
197     }
198   new_params.resource_params.resList = listOfResources;
199
200   Engines::EngineComponent_var compo = _LoadComponent(new_params,
201                                                       componentName);
202
203   return compo._retn();
204 }
205
206 //=============================================================================
207 /*! \brief Find an already existing and registered component instance or load a new
208  *         component instance on a container defined by its parameters.
209  *
210  *  \param params         container parameters like type or name...
211  *  \param componentName  the name of component class
212  *  \return a CORBA reference of the component instance, or _nil if problem
213  */
214 //=============================================================================
215
216 Engines::EngineComponent_ptr
217 SALOME_LifeCycleCORBA::
218 FindOrLoad_Component(const Engines::ContainerParameters& params,
219                      const char *componentName)
220 {
221   // --- Check if Component Name is known in ModuleCatalog
222
223   if (! isKnownComponentClass(componentName))
224     return Engines::EngineComponent::_nil();
225
226   Engines::ContainerParameters new_params(params);
227   new_params.resource_params.componentList.length(1);
228   new_params.resource_params.componentList[0] = componentName;
229   new_params.resource_params.can_run_containers = true;
230
231   Engines::ResourceList_var listOfResources;
232   try
233     {
234       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
235     }
236   catch( const SALOME::SALOME_Exception& ex )
237     {
238       return Engines::EngineComponent::_nil();
239     }
240
241   Engines::EngineComponent_var compo = _FindComponent(new_params,
242                                                       componentName,
243                                                       listOfResources);
244
245   if(CORBA::is_nil(compo))
246   {
247     new_params.resource_params.resList = listOfResources;
248     compo = _LoadComponent(new_params,
249                            componentName);
250   }
251
252   return compo._retn();
253 }
254
255 //=============================================================================
256 /*! \brief Find an already existing and registered component instance or load a new
257  *         component instance on a container defined by name
258  *
259  *  \param containerName  the name of container, under one of the forms
260  *           - 1 aContainer (local container)
261  *           - 2 machine/aContainer (container on hostname = machine)
262  *  \param componentName  the name of component class
263  *  \return a CORBA reference of the component instance, or _nil if problem
264  */
265 //=============================================================================
266
267 Engines::EngineComponent_ptr
268 SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName,
269                                             const char *componentName)
270 {
271   MESSAGE("SALOME_LifeCycleCORBA::FindOrLoad_Component INTERACTIF " << containerName << " " << componentName ) ;
272
273   // --- Check if Component Name is known in ModuleCatalog
274   if (! isKnownComponentClass(componentName))
275     return Engines::EngineComponent::_nil();
276
277   // --- Check if containerName contains machine name (if yes: rg>0)
278   char *stContainer=strdup(containerName);
279   std::string st2Container(stContainer);
280   int rg=st2Container.find("/");
281
282   Engines::ContainerParameters params;
283   preSet(params);
284   if (rg<0)
285   {
286     // containerName doesn't contain "/" => Local container
287     params.container_name = CORBA::string_dup(stContainer);
288   }
289   else
290   {
291     stContainer[rg]='\0';
292     params.container_name = CORBA::string_dup(stContainer+rg+1);
293     params.resource_params.hostname = CORBA::string_dup(stContainer);
294   }
295   params.isMPI = false;
296   SCRUTE(params.container_name);
297   free(stContainer);
298   return FindOrLoad_Component(params, componentName);
299 }
300
301 //=============================================================================
302 /*! \brief Check if the component class is known in module catalog
303  *
304  *  \param componentName  the name of component class
305  *  \return true if found, false otherwise
306  */
307 //=============================================================================
308
309 bool SALOME_LifeCycleCORBA::isKnownComponentClass(const char *componentName)
310 {
311   try
312   {
313     CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
314     SALOME_ModuleCatalog::ModuleCatalog_var Catalog =
315       SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
316     ASSERT(! CORBA::is_nil(Catalog));
317     SALOME_ModuleCatalog::Acomponent_var compoInfo =
318       Catalog->GetComponent(componentName);
319     if (CORBA::is_nil (compoInfo))
320     {
321       MESSAGE("Catalog Error: Component not found in the catalog " << componentName);
322       return false;
323     }
324     else return true;
325   }
326   catch (ServiceUnreachable&)
327   {
328     INFOS("Caught exception: Naming Service Unreachable");
329   }
330   catch (...)
331   {
332     INFOS("Caught unknown exception.");
333   }
334   return false;
335 }
336
337 //=============================================================================
338 /*! \brief Initialisation of a given Engines::ResourceParameters with default values.
339  */
340 //=============================================================================
341
342 void
343 SALOME_LifeCycleCORBA::preSet(Engines::ResourceParameters& params)
344 {
345   params.name = "";
346   params.hostname = "";
347   params.OS = "";
348   params.nb_proc = 0;
349   params.mem_mb = 0;
350   params.cpu_clock = 0;
351   params.nb_node = 0;
352   params.nb_proc_per_node = 0;
353   params.policy = "";
354   params.can_launch_batch_jobs = false;
355   params.can_run_containers = false;
356 }
357
358 //=============================================================================
359 /*! \brief Initialisation of a given Engines::ContainerParameters with default values.
360  */
361 //=============================================================================
362
363 void SALOME_LifeCycleCORBA::preSet( Engines::ContainerParameters& params)
364 {
365   params.container_name = "";
366   params.mode = "";
367   params.workingdir = "";
368   params.nb_proc = 0;
369   params.isMPI = false;
370   params.parallelLib = "";
371   SALOME_LifeCycleCORBA::preSet(params.resource_params);
372 }
373
374 //=============================================================================
375 /*!
376  *  \return a number of processors not 0, only for MPI containers
377  */
378 //=============================================================================
379
380 int SALOME_LifeCycleCORBA::NbProc(const Engines::ContainerParameters& params)
381 {
382   if( !params.isMPI )
383     return 0;
384   else if( params.nb_proc <= 0 )
385     return 1;
386   else
387     return params.nb_proc;
388 }
389
390 //=============================================================================
391 /*! \brief Get the container manager
392  *
393  *  \return the container Manager
394  */
395 //=============================================================================
396
397 Engines::ContainerManager_ptr SALOME_LifeCycleCORBA::getContainerManager()
398 {
399  Engines::ContainerManager_var contManager =
400    Engines::ContainerManager::_duplicate(_ContManager);
401  return contManager._retn();
402 }
403
404 //=============================================================================
405 /*! \brief Get the resources manager
406  *
407  *  \return the container Manager
408  */
409 //=============================================================================
410
411 Engines::ResourcesManager_ptr SALOME_LifeCycleCORBA::getResourcesManager()
412 {
413  Engines::ResourcesManager_var resManager =
414    Engines::ResourcesManager::_duplicate(_ResManager);
415  return resManager._retn();
416 }
417
418 //=============================================================================
419 /*! \brief shutdown all the SALOME servers except SALOME_Session_Server and omniNames
420  */
421 //=============================================================================
422
423 void SALOME_LifeCycleCORBA::shutdownServers(bool shutdownLauncher)
424 {
425   // get each Container from NamingService => shutdown it
426   // (the order is inverse to the order of servers initialization)
427
428   SALOME::Session_var session = SALOME::Session::_nil();
429   CORBA::Long pid = 0;
430   CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
431   if (!CORBA::is_nil(objS))
432   {
433     session = SALOME::Session::_narrow(objS);
434     if (!CORBA::is_nil(session))
435     {
436       pid = session->getPID();
437       session->Shutdown();
438     }
439   }
440
441   std::string hostname = Kernel_Utils::GetHostname();
442
443   // 1) ConnectionManager
444   try
445     {
446       CORBA::Object_var objCnM=_NS->Resolve("/ConnectionManager");
447       Engines::ConnectionManager_var connMan=Engines::ConnectionManager::_narrow(objCnM);
448       if ( !CORBA::is_nil(connMan) && ( pid != connMan->getPID() ) )
449         connMan->ShutdownWithExit();
450     }
451   catch(const CORBA::Exception& e)
452     {
453        // ignore and continue
454     }
455
456   timespec ts_req;
457   ts_req.tv_nsec=100000000;
458   ts_req.tv_sec=0;
459
460 //Wait some time so that ConnectionManager be completely shutdown
461 #ifndef WIN32
462   nanosleep(&ts_req,0);
463 #endif
464
465   // 2) SALOMEDS
466   try
467     {
468       CORBA::Object_var objSDS = _NS->Resolve("/Study");
469       SALOMEDS::Study_var study = SALOMEDS::Study::_narrow(objSDS) ;
470       if ( !CORBA::is_nil(study) && ( pid != study->getPID() ) )
471         study->Shutdown();
472       _NS->Destroy_Name("/Study");
473     }
474   catch(const CORBA::Exception& e)
475     {
476        // ignore and continue
477     }
478
479 //Wait some time so that study be completely shutdown
480 #ifndef WIN32
481   nanosleep(&ts_req,0);
482 #endif
483
484   // 3) ModuleCatalog
485   try
486     {
487       CORBA::Object_var objMC=_NS->Resolve("/Kernel/ModulCatalog");
488       SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC);
489       if ( !CORBA::is_nil(catalog) && ( pid != catalog->getPID() ) )
490         catalog->shutdown();
491       _NS->Destroy_Name("/Kernel/ModulCatalog");
492     }
493   catch(const CORBA::Exception& e)
494     {
495        // ignore and continue
496     }
497
498 //Wait some time so that ModulCatalog be completely shutdown
499 #ifndef WIN32
500   nanosleep(&ts_req,0);
501 #endif
502   // 4 ) Remote ScopeServer (the DataServer is hosted by SalomeLauncher shutdown right after)
503   try
504     {
505       CORBA::Object_var objDSM(_NS->Resolve(SALOMESDS::DataServerManager::NAME_IN_NS));
506       SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(objDSM));
507       if ( !CORBA::is_nil(dsm) )
508         dsm->shutdownScopes();
509     }
510   catch(const CORBA::Exception& e)
511     {
512        // ignore and continue
513     }
514
515   // 5) SalomeLauncher
516   try
517     {
518       if(shutdownLauncher){
519         CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher");
520         Engines::SalomeLauncher_var launcher = Engines::SalomeLauncher::_narrow(objSL);
521         if (!CORBA::is_nil(launcher) && (pid != launcher->getPID()))
522           launcher->Shutdown();
523       }
524     }
525   catch(const CORBA::Exception& e)
526     {
527        // ignore and continue
528     }
529
530 //Wait some time so that launcher be completely shutdown
531 #ifndef WIN32
532   nanosleep(&ts_req,0);
533 #endif
534
535   // 6) Registry
536   try
537     {
538       CORBA::Object_var objR = _NS->Resolve("/Registry");
539       Registry::Components_var registry = Registry::Components::_narrow(objR);
540       if ( !CORBA::is_nil(registry) && ( pid != registry->getPID() ) )
541           registry->Shutdown();
542       _NS->Destroy_Name("/Registry");
543     }
544   catch(const CORBA::Exception& e)
545     {
546        // ignore and continue
547     }
548
549   // 7) Logger
550   int argc = 0;
551   char *xargv = (char*)"";
552   char **argv = &xargv;
553   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
554
555   CORBA::Object_var objLog = CORBA::Object::_nil();
556   CosNaming::NamingContext_var inc;
557   CORBA::Object_var theObj = CORBA::Object::_nil();
558   std::string stdname = "Logger";
559   CosNaming::Name name;
560   name.length(1);
561   name[0].id = CORBA::string_dup(stdname.c_str());
562   try
563   {
564     if(!CORBA::is_nil(orb))
565       theObj = orb->resolve_initial_references("NameService");
566     if (!CORBA::is_nil(theObj))
567       inc = CosNaming::NamingContext::_narrow(theObj);
568   }
569   catch(...)
570   {
571   }
572   if(!CORBA::is_nil(inc))
573   {
574     try
575     {
576       objLog = inc->resolve(name);
577       SALOME_Logger::Logger_var logger = SALOME_Logger::Logger::_narrow(objLog);
578       if ( !CORBA::is_nil(logger) )
579         logger->shutdown();
580     }
581     catch(...)
582     {
583     }
584   }
585 }
586
587 //=============================================================================
588 /*! \brief shutdown  omniNames
589  */
590 //=============================================================================
591
592 void SALOME_LifeCycleCORBA::killOmniNames()
593 {
594   std::string portNumber (::getenv ("NSPORT") );
595   std::string python_exe;
596
597   python_exe = std::string("python3");
598
599   if ( !portNumber.empty() )
600   {
601     std::string cmd;
602
603     cmd  = std::string("from salome_utils import killOmniNames; ");
604     cmd += std::string("killOmniNames(") + portNumber + "); ";
605     cmd  = python_exe + std::string(" -c \"") + cmd +"\"";
606     MESSAGE(cmd);
607     system( cmd.c_str() );
608
609     cmd  = std::string("from killSalomeWithPort import cleanApplication; ");
610     cmd += std::string("cleanApplication(") + portNumber + "); ";
611     cmd  = python_exe + std::string(" -c \"") + cmd +"\"";
612     MESSAGE(cmd);
613     system( cmd.c_str() );
614   }
615
616   // shutdown portmanager
617   if ( !portNumber.empty() )
618   {
619     std::string cmd;
620
621     cmd  = std::string("from PortManager import releasePort; ");
622     cmd += std::string("releasePort(") + portNumber + "); ";
623     cmd  = python_exe + std::string(" -c \"") + cmd +"\"";
624     MESSAGE(cmd);
625     system( cmd.c_str() );
626   }
627 }
628
629 //=============================================================================
630 /*! \brief Find an already existing and registered component instance.
631  *
632  * - build a list of machines on which an instance of the component is running,
633  * - find the best machine among the list
634  *
635  *  \param params         machine parameters like type or name...
636  *  \param componentName  the name of component class
637  *  \param listOfMachines list of machine address
638  *  \return a CORBA reference of the component instance, or _nil if not found
639  */
640 //=============================================================================
641
642 Engines::EngineComponent_ptr
643 SALOME_LifeCycleCORBA::
644 _FindComponent(const Engines::ContainerParameters& params,
645                const char *componentName,
646                const Engines::ResourceList& listOfResources)
647 {
648   // --- build the list of machines on which the component is already running
649   const char *containerName = params.container_name;
650   int nbproc = NbProc(params);
651
652   Engines::ResourceList_var resourcesOK = new Engines::ResourceList;
653
654   unsigned int lghtOfresourcesOK = 0;
655   resourcesOK->length(listOfResources.length());
656
657   for(unsigned int i=0; i < listOfResources.length(); i++)
658   {
659     const char * currentResource = listOfResources[i];
660     Engines::ResourceDefinition_var resource_definition =
661         _ResManager->GetResourceDefinition(currentResource);
662     CORBA::Object_var obj = _NS->ResolveComponent(resource_definition->hostname.in(),
663                                                   containerName,
664                                                   componentName,
665                                                   nbproc);
666     if (!CORBA::is_nil(obj))
667       resourcesOK[lghtOfresourcesOK++] = CORBA::string_dup(currentResource);
668   }
669
670   // --- find the best machine among the list
671   if(lghtOfresourcesOK != 0)
672   {
673     resourcesOK->length(lghtOfresourcesOK);
674     CORBA::String_var bestResource = _ResManager->FindFirst(resourcesOK);
675     Engines::ResourceDefinition_var resource_definition =
676         _ResManager->GetResourceDefinition(bestResource);
677     CORBA::Object_var obj = _NS->ResolveComponent(resource_definition->hostname.in(),
678                                                   containerName,
679                                                   componentName,
680                                                   nbproc);
681     return Engines::EngineComponent::_narrow(obj);
682   }
683   else
684     return Engines::EngineComponent::_nil();
685 }
686
687 //=============================================================================
688 /*! \brief  Load a component instance.
689  *
690  *  - Finds a container in the list of machine or start one.
691  *  - Try to load the component library in the container,
692  *  - then create an instance of the component.
693  *
694  *  \param params         machine parameters like type or name...
695  *  \param componentName  the name of component class
696  *  \return a CORBA reference of the component instance, or _nil if problem
697  */
698 //=============================================================================
699
700 Engines::EngineComponent_ptr
701 SALOME_LifeCycleCORBA::
702 _LoadComponent(const Engines::ContainerParameters& params,
703               const char *componentName)
704 {
705   MESSAGE("_LoadComponent, required " << params.container_name <<
706           " " << componentName << " " << NbProc(params));
707
708   Engines::ContainerParameters local_params(params);
709   local_params.mode = CORBA::string_dup("findorstart");
710   Engines::Container_var cont = _ContManager->GiveContainer(local_params);
711   if (CORBA::is_nil(cont)) return Engines::EngineComponent::_nil();
712
713   char* reason;
714   bool isLoadable = cont->load_component_Library(componentName,reason);
715   if (!isLoadable)
716     {
717       //std::cerr << reason << std::endl;
718       CORBA::string_free(reason);
719       return Engines::EngineComponent::_nil();
720     }
721   CORBA::string_free(reason);
722
723   Engines::EngineComponent_var myInstance =
724     cont->create_component_instance(componentName);
725   return myInstance._retn();
726 }
727
728 //=============================================================================
729 /*! \brief  Load a parallel component instance.
730  *
731  *  \param params         machine parameters like type or name...
732  *  \param componentName  the name of component class
733  *  \return a CORBA reference of the parallel component instance, or _nil if problem
734  */
735 //=============================================================================
736 Engines::EngineComponent_ptr
737 SALOME_LifeCycleCORBA::Load_ParallelComponent(const Engines::ContainerParameters& params,
738                                               const char *componentName)
739 {
740   MESSAGE("Entering LoadParallelComponent");
741
742 /*MESSAGE("Parameters : ");
743   MESSAGE("Container name : " << params.container_name);
744   MESSAGE("Number of component nodes : " << params.nb_component_nodes);
745   MESSAGE("Component Name : " << componentName);*/
746
747   Engines::ContainerParameters parms(params);
748   parms.resource_params.componentList.length(1);
749   parms.resource_params.componentList[0] = componentName;
750   parms.mode = CORBA::string_dup("findorstart");
751
752   MESSAGE("Starting Parallel Container");
753   Engines::Container_var cont = _ContManager->GiveContainer(parms);
754   if (CORBA::is_nil(cont)) {
755     INFOS("FindOrStartParallelContainer() returns a NULL container !");
756     return Engines::EngineComponent::_nil();
757   }
758
759   MESSAGE("Loading component library");
760   char* reason;
761   bool isLoadable = cont->load_component_Library(componentName,reason);
762   if (!isLoadable) {
763     INFOS(componentName <<" library is not loadable !");
764     //std::cerr << reason << std::endl;
765     CORBA::string_free(reason);
766     return Engines::EngineComponent::_nil();
767   }
768   CORBA::string_free(reason);
769
770   MESSAGE("Creating component instance");
771   // @PARALLEL@ permits to identify that the component requested
772   // is a parallel component.
773   std::string name = std::string(componentName);
774   Engines::EngineComponent_var myInstance = cont->create_component_instance(name.c_str());
775   if (CORBA::is_nil(myInstance))
776     INFOS("create_component_instance returns a NULL component !");
777   return myInstance._retn();
778 }
779
780 /*! \brief copy a file from a source host to a destination host
781  * \param hostSrc the source host
782  * \param fileSrc the file to copy from the source host to the destination host
783  * \param hostDest the destination host
784  * \param fileDest the destination file
785  */
786 void SALOME_LifeCycleCORBA::copyFile(const char* hostSrc, const char* fileSrc, const char* hostDest, const char* fileDest)
787 {
788   if(strcmp(hostDest,"localhost") == 0)
789     {
790       //if localhost use a shortcut
791       SALOME_FileTransferCORBA transfer(hostSrc,fileSrc);
792       transfer.getLocalFile(fileDest);
793       return;
794     }
795
796   Engines::ContainerManager_var contManager = getContainerManager();
797
798   Engines::ContainerParameters params;
799   preSet(params);
800
801   params.resource_params.hostname = hostDest;
802   params.mode = CORBA::string_dup("findorstart");
803   Engines::Container_var containerDest = contManager->GiveContainer(params);
804
805   params.resource_params.hostname = hostSrc;
806   Engines::Container_var containerSrc = contManager->GiveContainer(params);
807
808   containerDest->copyFile(containerSrc,fileSrc,fileDest);
809 }
810
811 /*! \brief get the naming service used by the life cycle
812  *
813  *  \return the naming service
814  */
815 SALOME_NamingService * SALOME_LifeCycleCORBA::namingService()
816 {
817   return _NS;
818 }
819
820 /*! \brief get the orb used by the life cycle
821  *
822  *  \return the orb
823  */
824 CORBA::ORB_ptr SALOME_LifeCycleCORBA::orb()
825 {
826   return _NS->orb();
827 }