Salome HOME
cf181f04e194100de5915fd8a1f67dbe1a12acbc
[modules/kernel.git] / src / LifeCycleCORBA / SALOME_LifeCycleCORBA.cxx
1 // Copyright (C) 2007-2016  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  *  \param studyId        default = 0  : multistudy instance
136  *  \return a CORBA reference of the component instance, or _nil if not found
137  */
138 //=============================================================================
139 Engines::EngineComponent_ptr
140 SALOME_LifeCycleCORBA::FindComponent(const Engines::ContainerParameters& params,
141                                      const char *componentName,
142                                      int studyId)
143 {
144   if (! isKnownComponentClass(componentName))
145     return Engines::EngineComponent::_nil();
146
147   Engines::ContainerParameters new_params(params);
148   new_params.resource_params.componentList.length(1);
149   new_params.resource_params.componentList[0] = componentName;
150   new_params.resource_params.can_run_containers = true;
151   Engines::ResourceList_var listOfResources;
152   try
153     {
154       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
155     }
156   catch( const SALOME::SALOME_Exception& ex )
157     {
158       return Engines::EngineComponent::_nil();
159     }
160
161   Engines::EngineComponent_var compo = _FindComponent(new_params,
162                                                 componentName,
163                                                 studyId,
164                                                 listOfResources);
165
166   return compo._retn();
167 }
168
169 //=============================================================================
170 /*! \brief Load a component instance on a container defined by its parameters
171  *
172  *  \param params         container parameters like type or name...
173  *  \param componentName  the name of component class
174  *  \param studyId        default = 0  : multistudy instance
175  *  \return a CORBA reference of the component instance, or _nil if problem
176  */
177 //=============================================================================
178
179 Engines::EngineComponent_ptr
180 SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params,
181                                      const char *componentName,
182                                      int studyId)
183 {
184   // --- Check if Component Name is known in ModuleCatalog
185
186   if (! isKnownComponentClass(componentName))
187     return Engines::EngineComponent::_nil();
188
189   Engines::ContainerParameters new_params(params);
190   new_params.resource_params.componentList.length(1);
191   new_params.resource_params.componentList[0] = componentName;
192   new_params.resource_params.can_run_containers = true;
193
194   Engines::ResourceList_var listOfResources;
195   try
196     {
197       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
198     }
199   catch( const SALOME::SALOME_Exception& ex )
200     {
201       return Engines::EngineComponent::_nil();
202     }
203   new_params.resource_params.resList = listOfResources;
204
205   Engines::EngineComponent_var compo = _LoadComponent(new_params,
206                                                 componentName,
207                                                 studyId);
208
209   return compo._retn();
210 }
211
212 //=============================================================================
213 /*! \brief Find an already existing and registered component instance or load a new
214  *         component instance on a container defined by its parameters.
215  *
216  *  \param params         container parameters like type or name...
217  *  \param componentName  the name of component class
218  *  \param studyId        default = 0  : multistudy instance
219  *  \return a CORBA reference of the component instance, or _nil if problem
220  */
221 //=============================================================================
222
223 Engines::EngineComponent_ptr
224 SALOME_LifeCycleCORBA::
225 FindOrLoad_Component(const Engines::ContainerParameters& params,
226                      const char *componentName,
227                      int studyId)
228 {
229   // --- Check if Component Name is known in ModuleCatalog
230
231   if (! isKnownComponentClass(componentName))
232     return Engines::EngineComponent::_nil();
233
234   Engines::ContainerParameters new_params(params);
235   new_params.resource_params.componentList.length(1);
236   new_params.resource_params.componentList[0] = componentName;
237   new_params.resource_params.can_run_containers = true;
238
239   Engines::ResourceList_var listOfResources;
240   try
241     {
242       listOfResources = _ResManager->GetFittingResources(new_params.resource_params);
243     }
244   catch( const SALOME::SALOME_Exception& ex )
245     {
246       return Engines::EngineComponent::_nil();
247     }
248
249   Engines::EngineComponent_var compo = _FindComponent(new_params,
250                                                 componentName,
251                                                 studyId,
252                                                 listOfResources);
253
254   if(CORBA::is_nil(compo))
255   {
256     new_params.resource_params.resList = listOfResources;
257     compo = _LoadComponent(new_params,
258                            componentName,
259                            studyId);
260   }
261
262   return compo._retn();
263 }
264
265 //=============================================================================
266 /*! \brief Find an already existing and registered component instance or load a new
267  *         component instance on a container defined by name
268  *
269  *  \param containerName  the name of container, under one of the forms
270  *           - 1 aContainer (local container)
271  *           - 2 machine/aContainer (container on hostname = machine)
272  *  \param componentName  the name of component class
273  *  \return a CORBA reference of the component instance, or _nil if problem
274  */
275 //=============================================================================
276
277 Engines::EngineComponent_ptr
278 SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName,
279                                             const char *componentName)
280 {
281   MESSAGE("SALOME_LifeCycleCORBA::FindOrLoad_Component INTERACTIF " << containerName << " " << componentName ) ;
282
283   // --- Check if Component Name is known in ModuleCatalog
284   if (! isKnownComponentClass(componentName))
285     return Engines::EngineComponent::_nil();
286
287   // --- Check if containerName contains machine name (if yes: rg>0)
288   char *stContainer=strdup(containerName);
289   std::string st2Container(stContainer);
290   int rg=st2Container.find("/");
291
292   Engines::ContainerParameters params;
293   preSet(params);
294   if (rg<0)
295   {
296     // containerName doesn't contain "/" => Local container
297     params.container_name = CORBA::string_dup(stContainer);
298   }
299   else
300   {
301     stContainer[rg]='\0';
302     params.container_name = CORBA::string_dup(stContainer+rg+1);
303     params.resource_params.hostname = CORBA::string_dup(stContainer);
304   }
305   params.isMPI = false;
306   SCRUTE(params.container_name);
307   free(stContainer);
308   return FindOrLoad_Component(params, componentName);
309 }
310
311 //=============================================================================
312 /*! \brief Check if the component class is known in module catalog
313  *
314  *  \param componentName  the name of component class
315  *  \return true if found, false otherwise
316  */
317 //=============================================================================
318
319 bool SALOME_LifeCycleCORBA::isKnownComponentClass(const char *componentName)
320 {
321   try
322   {
323     CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
324     SALOME_ModuleCatalog::ModuleCatalog_var Catalog =
325       SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
326     ASSERT(! CORBA::is_nil(Catalog));
327     SALOME_ModuleCatalog::Acomponent_var compoInfo =
328       Catalog->GetComponent(componentName);
329     if (CORBA::is_nil (compoInfo))
330     {
331       MESSAGE("Catalog Error: Component not found in the catalog " << componentName);
332       return false;
333     }
334     else return true;
335   }
336   catch (ServiceUnreachable&)
337   {
338     INFOS("Caught exception: Naming Service Unreachable");
339   }
340   catch (...)
341   {
342     INFOS("Caught unknown exception.");
343   }
344   return false;
345 }
346
347 //=============================================================================
348 /*! \brief Initialisation of a given Engines::ResourceParameters with default values.
349  */
350 //=============================================================================
351
352 void
353 SALOME_LifeCycleCORBA::preSet(Engines::ResourceParameters& params)
354 {
355   params.name = "";
356   params.hostname = "";
357   params.OS = "";
358   params.nb_proc = 0;
359   params.mem_mb = 0;
360   params.cpu_clock = 0;
361   params.nb_node = 0;
362   params.nb_proc_per_node = 0;
363   params.policy = "";
364   params.can_launch_batch_jobs = false;
365   params.can_run_containers = false;
366 }
367
368 //=============================================================================
369 /*! \brief Initialisation of a given Engines::ContainerParameters with default values.
370  */
371 //=============================================================================
372
373 void SALOME_LifeCycleCORBA::preSet( Engines::ContainerParameters& params)
374 {
375   params.container_name = "";
376   params.mode = "";
377   params.workingdir = "";
378   params.nb_proc = 0;
379   params.isMPI = false;
380   params.parallelLib = "";
381   SALOME_LifeCycleCORBA::preSet(params.resource_params);
382 }
383
384 //=============================================================================
385 /*!
386  *  \return a number of processors not 0, only for MPI containers
387  */
388 //=============================================================================
389
390 int SALOME_LifeCycleCORBA::NbProc(const Engines::ContainerParameters& params)
391 {
392   if( !params.isMPI )
393     return 0;
394   else if( params.nb_proc <= 0 )
395     return 1;
396   else
397     return params.nb_proc;
398 }
399
400 //=============================================================================
401 /*! \brief Get the container manager
402  *
403  *  \return the container Manager
404  */
405 //=============================================================================
406
407 Engines::ContainerManager_ptr SALOME_LifeCycleCORBA::getContainerManager()
408 {
409  Engines::ContainerManager_var contManager =
410    Engines::ContainerManager::_duplicate(_ContManager);
411  return contManager._retn();
412 }
413
414 //=============================================================================
415 /*! \brief Get the resources manager
416  *
417  *  \return the container Manager
418  */
419 //=============================================================================
420
421 Engines::ResourcesManager_ptr SALOME_LifeCycleCORBA::getResourcesManager()
422 {
423  Engines::ResourcesManager_var resManager =
424    Engines::ResourcesManager::_duplicate(_ResManager);
425  return resManager._retn();
426 }
427
428 //=============================================================================
429 /*! \brief shutdown all the SALOME servers except SALOME_Session_Server and omniNames
430  */
431 //=============================================================================
432
433 void SALOME_LifeCycleCORBA::shutdownServers()
434 {
435   // get each Container from NamingService => shutdown it
436   // (the order is inverse to the order of servers initialization)
437
438   SALOME::Session_var session = SALOME::Session::_nil();
439   CORBA::Long pid = 0;
440   CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
441   if (!CORBA::is_nil(objS))
442   {
443     session = SALOME::Session::_narrow(objS);
444     if (!CORBA::is_nil(session))
445     {
446       pid = session->getPID();
447       session->Shutdown();
448     }
449   }
450
451   std::string hostname = Kernel_Utils::GetHostname();
452
453   // 1) ConnectionManager
454   try
455     {
456       CORBA::Object_var objCnM=_NS->Resolve("/ConnectionManager");
457       Engines::ConnectionManager_var connMan=Engines::ConnectionManager::_narrow(objCnM);
458       if ( !CORBA::is_nil(connMan) && ( pid != connMan->getPID() ) )
459         connMan->ShutdownWithExit();
460     }
461   catch(const CORBA::Exception& e)
462     {
463        // ignore and continue
464     }
465
466   timespec ts_req;
467   ts_req.tv_nsec=100000000;
468   ts_req.tv_sec=0;
469
470 //Wait some time so that ConnectionManager be completely shutdown
471 #ifndef WIN32
472   nanosleep(&ts_req,0);
473 #endif
474
475   // 2) SALOMEDS
476   try
477     {
478       CORBA::Object_var objSDS = _NS->Resolve("/myStudyManager");
479       SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ;
480       if ( !CORBA::is_nil(studyManager) && ( pid != studyManager->getPID() ) )
481         studyManager->Shutdown();
482     }
483   catch(const CORBA::Exception& e)
484     {
485        // ignore and continue
486     }
487
488 //Wait some time so that study be completely shutdown
489 #ifndef WIN32
490   nanosleep(&ts_req,0);
491 #endif
492
493   // 3) ModuleCatalog
494   try
495     {
496       CORBA::Object_var objMC=_NS->Resolve("/Kernel/ModulCatalog");
497       SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC);
498       if ( !CORBA::is_nil(catalog) && ( pid != catalog->getPID() ) )
499         catalog->shutdown();
500     }
501   catch(const CORBA::Exception& e)
502     {
503        // ignore and continue
504     }
505
506 //Wait some time so that ModulCatalog be completely shutdown
507 #ifndef WIN32
508   nanosleep(&ts_req,0);
509 #endif
510   // 4 ) Remote ScopeServer (the DataServer is hosted by SalomeLauncher shutdown right after)
511   try
512     {
513       CORBA::Object_var objDSM(_NS->Resolve(SALOMESDS::DataServerManager::NAME_IN_NS));
514       SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(objDSM));
515       if ( !CORBA::is_nil(dsm) )
516         dsm->shutdownScopes();
517     }
518   catch(const CORBA::Exception& e)
519     {
520        // ignore and continue
521     }
522
523   // 5) SalomeLauncher
524   try
525     {
526       CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher");
527       Engines::SalomeLauncher_var launcher = Engines::SalomeLauncher::_narrow(objSL);
528       if (!CORBA::is_nil(launcher) && (pid != launcher->getPID()))
529         launcher->Shutdown();
530     }
531   catch(const CORBA::Exception& e)
532     {
533        // ignore and continue
534     }
535
536 //Wait some time so that launcher be completely shutdown
537 #ifndef WIN32
538   nanosleep(&ts_req,0);
539 #endif
540
541   // 6) Registry
542   try
543     {
544       CORBA::Object_var objR = _NS->Resolve("/Registry");
545       Registry::Components_var registry = Registry::Components::_narrow(objR);
546       if ( !CORBA::is_nil(registry) && ( pid != registry->getPID() ) )
547           registry->Shutdown();
548     }
549   catch(const CORBA::Exception& e)
550     {
551        // ignore and continue
552     }
553
554   // 7) Logger
555   int argc = 0;
556   char *xargv = (char*)"";
557   char **argv = &xargv;
558   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
559
560   CORBA::Object_var objLog = CORBA::Object::_nil();
561   CosNaming::NamingContext_var inc;
562   CORBA::Object_var theObj = CORBA::Object::_nil();
563   std::string stdname = "Logger";
564   CosNaming::Name name;
565   name.length(1);
566   name[0].id = CORBA::string_dup(stdname.c_str());
567   try
568   {
569     if(!CORBA::is_nil(orb))
570       theObj = orb->resolve_initial_references("NameService");
571     if (!CORBA::is_nil(theObj))
572       inc = CosNaming::NamingContext::_narrow(theObj);
573   }
574   catch(...)
575   {
576   }
577   if(!CORBA::is_nil(inc))
578   {
579     try
580     {
581       objLog = inc->resolve(name);
582       SALOME_Logger::Logger_var logger = SALOME_Logger::Logger::_narrow(objLog);
583       if ( !CORBA::is_nil(logger) )
584         logger->shutdown();
585     }
586     catch(...)
587     {
588     }
589   }
590 }
591
592 //=============================================================================
593 /*! \brief shutdown  omniNames
594  */
595 //=============================================================================
596
597 void SALOME_LifeCycleCORBA::killOmniNames()
598 {
599   std::string portNumber (::getenv ("NSPORT") );
600   std::string python_exe;
601
602   python_exe = std::string("python");
603
604   if ( !portNumber.empty() )
605   {
606     std::string cmd;
607
608     cmd  = std::string("from salome_utils import killOmniNames; ");
609     cmd += std::string("killOmniNames(") + portNumber + "); ";
610     cmd  = python_exe + std::string(" -c \"") + cmd +"\"";
611     MESSAGE(cmd);
612     system( cmd.c_str() );
613
614     cmd  = std::string("from killSalomeWithPort import cleanApplication; ");
615     cmd += std::string("cleanApplication(") + portNumber + "); ";
616     cmd  = python_exe + std::string(" -c \"") + cmd +"\"";
617     MESSAGE(cmd);
618     system( cmd.c_str() );
619   }
620
621   // shutdown portmanager
622   if ( !portNumber.empty() )
623   {
624     std::string cmd;
625
626     cmd  = std::string("from PortManager import releasePort; ");
627     cmd += std::string("releasePort(") + portNumber + "); ";
628     cmd  = python_exe + std::string(" -c \"") + cmd +"\"";
629     MESSAGE(cmd);
630     system( cmd.c_str() );
631   }
632 }
633
634 //=============================================================================
635 /*! \brief Find an already existing and registered component instance.
636  *
637  * - build a list of machines on which an instance of the component is running,
638  * - find the best machine among the list
639  *
640  *  \param params         machine parameters like type or name...
641  *  \param componentName  the name of component class
642  *  \param studyId        default = 0  : multistudy instance
643  *  \param listOfMachines list of machine address
644  *  \return a CORBA reference of the component instance, or _nil if not found
645  */
646 //=============================================================================
647
648 Engines::EngineComponent_ptr
649 SALOME_LifeCycleCORBA::
650 _FindComponent(const Engines::ContainerParameters& params,
651                const char *componentName,
652                int studyId,
653                const Engines::ResourceList& listOfResources)
654 {
655   // --- build the list of machines on which the component is already running
656   const char *containerName = params.container_name;
657   int nbproc = NbProc(params);
658
659   Engines::ResourceList_var resourcesOK = new Engines::ResourceList;
660
661   unsigned int lghtOfresourcesOK = 0;
662   resourcesOK->length(listOfResources.length());
663
664   for(unsigned int i=0; i < listOfResources.length(); i++)
665   {
666     const char * currentResource = listOfResources[i];
667     Engines::ResourceDefinition_var resource_definition =
668         _ResManager->GetResourceDefinition(currentResource);
669     CORBA::Object_var obj = _NS->ResolveComponent(resource_definition->hostname.in(),
670                                                   containerName,
671                                                   componentName,
672                                                   nbproc);
673     if (!CORBA::is_nil(obj))
674       resourcesOK[lghtOfresourcesOK++] = CORBA::string_dup(currentResource);
675   }
676
677   // --- find the best machine among the list
678   if(lghtOfresourcesOK != 0)
679   {
680     resourcesOK->length(lghtOfresourcesOK);
681     CORBA::String_var bestResource = _ResManager->FindFirst(resourcesOK);
682     Engines::ResourceDefinition_var resource_definition =
683         _ResManager->GetResourceDefinition(bestResource);
684     CORBA::Object_var obj = _NS->ResolveComponent(resource_definition->hostname.in(),
685                                                   containerName,
686                                                   componentName,
687                                                   nbproc);
688     return Engines::EngineComponent::_narrow(obj);
689   }
690   else
691     return Engines::EngineComponent::_nil();
692 }
693
694 //=============================================================================
695 /*! \brief  Load a component instance.
696  *
697  *  - Finds a container in the list of machine or start one.
698  *  - Try to load the component library in the container,
699  *  - then create an instance of the component.
700  *
701  *  \param params         machine parameters like type or name...
702  *  \param componentName  the name of component class
703  *  \param studyId        default = 0  : multistudy instance
704  *  \return a CORBA reference of the component instance, or _nil if problem
705  */
706 //=============================================================================
707
708 Engines::EngineComponent_ptr
709 SALOME_LifeCycleCORBA::
710 _LoadComponent(const Engines::ContainerParameters& params,
711               const char *componentName,
712               int studyId)
713 {
714   MESSAGE("_LoadComponent, required " << params.container_name <<
715           " " << componentName << " " << NbProc(params));
716
717   Engines::ContainerParameters local_params(params);
718   local_params.mode = CORBA::string_dup("findorstart");
719   Engines::Container_var cont = _ContManager->GiveContainer(local_params);
720   if (CORBA::is_nil(cont)) return Engines::EngineComponent::_nil();
721
722   char* reason;
723   bool isLoadable = cont->load_component_Library(componentName,reason);
724   if (!isLoadable)
725     {
726       //std::cerr << reason << std::endl;
727       CORBA::string_free(reason);
728       return Engines::EngineComponent::_nil();
729     }
730   CORBA::string_free(reason);
731
732   Engines::EngineComponent_var myInstance =
733     cont->create_component_instance(componentName, studyId);
734   return myInstance._retn();
735 }
736
737 //=============================================================================
738 /*! \brief  Load a parallel component instance.
739  *
740  *  \param params         machine parameters like type or name...
741  *  \param componentName  the name of component class
742  *  \param studyId        default = 0  : multistudy instance
743  *  \return a CORBA reference of the parallel component instance, or _nil if problem
744  */
745 //=============================================================================
746 Engines::EngineComponent_ptr
747 SALOME_LifeCycleCORBA::Load_ParallelComponent(const Engines::ContainerParameters& params,
748                                               const char *componentName,
749                                               int studyId)
750 {
751   MESSAGE("Entering LoadParallelComponent");
752
753 /*MESSAGE("Parameters : ");
754   MESSAGE("Container name : " << params.container_name);
755   MESSAGE("Number of component nodes : " << params.nb_component_nodes);
756   MESSAGE("Component Name : " << componentName);*/
757
758   Engines::ContainerParameters parms(params);
759   parms.resource_params.componentList.length(1);
760   parms.resource_params.componentList[0] = componentName;
761   parms.mode = CORBA::string_dup("findorstart");
762
763   MESSAGE("Starting Parallel Container");
764   Engines::Container_var cont = _ContManager->GiveContainer(parms);
765   if (CORBA::is_nil(cont)) {
766     INFOS("FindOrStartParallelContainer() returns a NULL container !");
767     return Engines::EngineComponent::_nil();
768   }
769
770   MESSAGE("Loading component library");
771   char* reason;
772   bool isLoadable = cont->load_component_Library(componentName,reason);
773   if (!isLoadable) {
774     INFOS(componentName <<" library is not loadable !");
775     //std::cerr << reason << std::endl;
776     CORBA::string_free(reason);
777     return Engines::EngineComponent::_nil();
778   }
779   CORBA::string_free(reason);
780
781   MESSAGE("Creating component instance");
782   // @PARALLEL@ permits to identify that the component requested
783   // is a parallel component.
784   std::string name = std::string(componentName);
785   Engines::EngineComponent_var myInstance = cont->create_component_instance(name.c_str(), studyId);
786   if (CORBA::is_nil(myInstance))
787     INFOS("create_component_instance returns a NULL component !");
788   return myInstance._retn();
789 }
790
791 /*! \brief copy a file from a source host to a destination host
792  * \param hostSrc the source host
793  * \param fileSrc the file to copy from the source host to the destination host
794  * \param hostDest the destination host
795  * \param fileDest the destination file
796  */
797 void SALOME_LifeCycleCORBA::copyFile(const char* hostSrc, const char* fileSrc, const char* hostDest, const char* fileDest)
798 {
799   if(strcmp(hostDest,"localhost") == 0)
800     {
801       //if localhost use a shortcut
802       SALOME_FileTransferCORBA transfer(hostSrc,fileSrc);
803       transfer.getLocalFile(fileDest);
804       return;
805     }
806
807   Engines::ContainerManager_var contManager = getContainerManager();
808
809   Engines::ContainerParameters params;
810   preSet(params);
811
812   params.resource_params.hostname = hostDest;
813   params.mode = CORBA::string_dup("findorstart");
814   Engines::Container_var containerDest = contManager->GiveContainer(params);
815
816   params.resource_params.hostname = hostSrc;
817   Engines::Container_var containerSrc = contManager->GiveContainer(params);
818
819   containerDest->copyFile(containerSrc,fileSrc,fileDest);
820 }
821
822 /*! \brief get the naming service used by the life cycle
823  *
824  *  \return the naming service
825  */
826 SALOME_NamingService * SALOME_LifeCycleCORBA::namingService()
827 {
828   return _NS;
829 }
830
831 /*! \brief get the orb used by the life cycle
832  *
833  *  \return the orb
834  */
835 CORBA::ORB_ptr SALOME_LifeCycleCORBA::orb()
836 {
837   return _NS->orb();
838 }