]> SALOME platform Git repositories - modules/kernel.git/blob - src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx
Salome HOME
CCAR: remove bug in FindOrLoad_Component
[modules/kernel.git] / src / LifeCycleCORBA / SALOME_LifeCycleCORBA.cxx
1 //  Copyright (C) 2007-2008  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.
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 //  SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
23 //  File   : SALOME_LifeCycleCORBA.cxx
24 //  Author : Paul RASCLE, EDF
25 //  Module : SALOME
26 //  $Header$
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 #endif
37
38 #include "Basics_Utils.hxx"
39 #include "utilities.h"
40
41 #include <ServiceUnreachable.hxx>
42
43 #include "SALOME_LifeCycleCORBA.hxx"
44 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
45 #include CORBA_CLIENT_HEADER(SALOME_Session)
46 #include CORBA_CLIENT_HEADER(DSC_Engines)
47 #include CORBA_CLIENT_HEADER(SALOME_Registry)
48 #include CORBA_CLIENT_HEADER(SALOMEDS)
49 #include CORBA_CLIENT_HEADER(Logger)
50
51 #include "SALOME_ContainerManager.hxx"
52 #include "SALOME_Component_i.hxx"
53 #include "SALOME_NamingService.hxx"
54 #include "SALOME_FileTransferCORBA.hxx"
55
56 using namespace std;
57
58 IncompatibleComponent::IncompatibleComponent( void ):
59   SALOME_Exception( "IncompatibleComponent" )
60 {
61 }
62
63 IncompatibleComponent::IncompatibleComponent(const IncompatibleComponent &ex):
64   SALOME_Exception( ex ) 
65 {
66 }
67
68 /*! \class SALOME_LifeCycleCORBA
69     \brief A class to manage life cycle of SALOME components.
70
71 */
72
73 //=============================================================================
74 /*! 
75  *  Constructor
76  */
77 //=============================================================================
78
79 SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns)
80 {
81   // be sure to have an instance of traceCollector, when used via SWIG
82   // in a Python module
83   int argc = 0;
84   char *xargv = (char*)"";
85   char **argv = &xargv;
86   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
87   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
88   if (!ns)
89     {
90       _NS = new SALOME_NamingService(orb);
91     }
92   else _NS = ns;
93   //add try catch
94   _NS->Change_Directory("/"); // mpv 250105: current directory may be not root 
95                               // (in SALOMEDS for an example)
96   // not enough: set a current directory in naming service is not thread safe
97   // if naming service instance is shared among several threads...
98   // ==> allways use absolute path and dot rely on current directory!
99
100   CORBA::Object_var obj =
101     _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
102   ASSERT( !CORBA::is_nil(obj));
103   _ContManager=Engines::ContainerManager::_narrow(obj);
104
105   obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
106   ASSERT( !CORBA::is_nil(obj));
107   _ResManager=Engines::ResourcesManager::_narrow(obj);
108 }
109
110 //=============================================================================
111 /*! 
112  *  Destructor
113  */
114 //=============================================================================
115
116 SALOME_LifeCycleCORBA::~SALOME_LifeCycleCORBA()
117 {
118 }
119
120 //=============================================================================
121 /*! \brief Find an already existing and registered component instance.
122  *
123  *  \param params         machine parameters like type or name...
124  *  \param componentName  the name of component class
125  *  \param studyId        default = 0  : multistudy instance
126  *  \return a CORBA reference of the component instance, or _nil if not found
127  */
128 //=============================================================================
129 Engines::Component_ptr
130 SALOME_LifeCycleCORBA::FindComponent(const Engines::MachineParameters& params,
131                                      const char *componentName,
132                                      int studyId)
133 {
134   if (! isKnownComponentClass(componentName))
135     return Engines::Component::_nil();
136
137   Engines::MachineParameters parms(params);
138   parms.componentList.length(1);
139   parms.componentList[0] = componentName;
140   Engines::MachineList_var listOfMachines = _ResManager->GetFittingResources(parms);
141
142   Engines::Component_var compo = _FindComponent(parms,
143                                                 componentName,
144                                                 studyId,
145                                                 listOfMachines);
146
147   return compo._retn();
148 }
149
150 //=============================================================================
151 /*! \brief Load a component instance on a container defined by machine parameters
152  *
153  *  \param params         machine parameters like type or name...
154  *  \param componentName  the name of component class
155  *  \param studyId        default = 0  : multistudy instance
156  *  \return a CORBA reference of the component instance, or _nil if problem
157  */
158 //=============================================================================
159
160 Engines::Component_ptr
161 SALOME_LifeCycleCORBA::LoadComponent(const Engines::MachineParameters& params,
162                                      const char *componentName,
163                                      int studyId)
164 {
165   // --- Check if Component Name is known in ModuleCatalog
166
167   if (! isKnownComponentClass(componentName))
168     return Engines::Component::_nil();
169
170   Engines::MachineParameters parms(params);
171   parms.componentList.length(1);
172   parms.componentList[0] = componentName;
173
174   Engines::MachineList_var listOfMachines = _ResManager->GetFittingResources(parms);
175   parms.computerList=listOfMachines;
176
177   Engines::Component_var compo = _LoadComponent(parms,
178                                                 componentName,
179                                                 studyId);
180
181   return compo._retn();
182 }
183
184 //=============================================================================
185 /*! \brief Find an already existing and registered component instance or load a new
186  *         component instance on a container defined by machine parameters.
187  *
188  *  \param params         machine parameters like type or name...
189  *  \param componentName  the name of component class
190  *  \param studyId        default = 0  : multistudy instance
191  *  \return a CORBA reference of the component instance, or _nil if problem
192  */
193 //=============================================================================
194
195 Engines::Component_ptr
196 SALOME_LifeCycleCORBA::
197 FindOrLoad_Component(const Engines::MachineParameters& params,
198                      const char *componentName,
199                      int studyId)
200 {
201   // --- Check if Component Name is known in ModuleCatalog
202
203   if (! isKnownComponentClass(componentName))
204     return Engines::Component::_nil();
205
206   Engines::MachineParameters parms(params);
207   parms.componentList.length(1);
208   parms.componentList[0] = componentName;
209   Engines::MachineList_var listOfMachines = _ResManager->GetFittingResources(parms);
210
211   Engines::Component_var compo = _FindComponent(parms,
212                                                 componentName,
213                                                 studyId,
214                                                 listOfMachines);
215
216   if(CORBA::is_nil(compo))
217     {
218       parms.computerList=listOfMachines;
219       compo = _LoadComponent(parms,
220                            componentName,
221                            studyId);
222     }
223
224   return compo._retn();
225 }
226
227 //=============================================================================
228 /*! \brief Find an already existing and registered component instance or load a new
229  *         component instance on a container defined by name
230  *
231  *  \param containerName  the name of container, under one of the forms
232  *           - 1 aContainer (local container)
233  *           - 2 machine/aContainer (container on hostname = machine)
234  *  \param componentName  the name of component class
235  *  \return a CORBA reference of the component instance, or _nil if problem
236  */
237 //=============================================================================
238
239 Engines::Component_ptr
240 SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName,
241                                             const char *componentName)
242 {
243   char *valenv=getenv("SALOME_BATCH");
244   if(valenv)
245     if (strcmp(valenv,"1")==0)
246       {
247         MESSAGE("SALOME_LifeCycleCORBA::FindOrLoad_Component BATCH " << containerName << " " << componentName ) ;
248         _NS->Change_Directory("/Containers");
249         CORBA::Object_ptr obj=_NS->Resolve(containerName);
250         Engines::Container_var cont=Engines::Container::_narrow(obj);
251         bool isLoadable = cont->load_component_Library(componentName);
252         if (!isLoadable) return Engines::Component::_nil();
253         
254         Engines::Component_ptr myInstance =
255           cont->create_component_instance(componentName, 0);
256         return myInstance;
257       }
258   MESSAGE("SALOME_LifeCycleCORBA::FindOrLoad_Component INTERACTIF " << containerName << " " << componentName ) ;
259   //#if 0
260   // --- Check if Component Name is known in ModuleCatalog
261
262   if (! isKnownComponentClass(componentName))
263     return Engines::Component::_nil();
264
265   // --- Check if containerName contains machine name (if yes: rg>0)
266
267   char *stContainer=strdup(containerName);
268   string st2Container(stContainer);
269   int rg=st2Container.find("/");
270
271   Engines::MachineParameters_var params=new Engines::MachineParameters;
272   preSet(params);
273   if (rg<0)
274     {
275       // containerName doesn't contain "/" => Local container
276       params->container_name=CORBA::string_dup(stContainer);
277       params->hostname=CORBA::string_dup(Kernel_Utils::GetHostname().c_str());
278     }
279   else 
280     {
281       stContainer[rg]='\0';
282       params->container_name=CORBA::string_dup(stContainer+rg+1);
283       params->hostname=CORBA::string_dup(stContainer);
284     }
285   params->isMPI = false;
286   SCRUTE(params->container_name);
287 //   SCRUTE(params->hostname);
288 //   SCRUTE(params->OS);
289 //   SCRUTE(params->mem_mb);
290 //   SCRUTE(params->cpu_clock);
291 //   SCRUTE(params->nb_proc_per_node);
292 //   SCRUTE(params->nb_node);
293 //   SCRUTE(params->isMPI);
294   free(stContainer);
295   return FindOrLoad_Component(params,componentName);
296   //#endif  
297 }
298
299 //=============================================================================
300 /*! \brief Check if the component class is known in module catalog
301  *
302  *  \param componentName  the name of component class
303  *  \return true if found, false otherwise
304  */
305 //=============================================================================
306
307 bool SALOME_LifeCycleCORBA::isKnownComponentClass(const char *componentName)
308 {
309
310   try
311     {
312       CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
313       SALOME_ModuleCatalog::ModuleCatalog_var Catalog = 
314         SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
315       ASSERT(! CORBA::is_nil(Catalog));
316       SALOME_ModuleCatalog::Acomponent_var compoInfo = 
317         Catalog->GetComponent(componentName);
318       if (CORBA::is_nil (compoInfo)) 
319         {
320           INFOS("Catalog Error: Component not found in the catalog" );
321           INFOS( 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 /*! 
339  *  Not so complex... useful ?
340  */
341 //=============================================================================
342
343 bool 
344 SALOME_LifeCycleCORBA::isMpiContainer(const Engines::MachineParameters& params)
345   throw(IncompatibleComponent)
346 {
347   if( params.isMPI )
348     return true;
349   else
350     return false;
351 }
352
353
354 //=============================================================================
355 /*! \brief Initialisation of a given Engines::MachineParameters with default values.
356  *
357  *  - container_name = ""  : not relevant
358  *  - hostname = ""        : not relevant
359  *  - OS = ""              : not relevant
360  *  - mem_mb = 0           : not relevant
361  *  - cpu_clock = 0        : not relevant
362  *  - nb_proc_per_node = 0 : not relevant
363  *  - nb_node = 0          : not relevant
364  *  - isMPI = false        : standard components
365  */
366 //=============================================================================
367
368 void SALOME_LifeCycleCORBA::preSet( Engines::MachineParameters& params)
369 {
370   params.container_name = "";
371   params.hostname = "";
372   //param.componentList = 0;
373   //param.computerList = 0;
374   params.OS = "";
375   params.mem_mb = 0;
376   params.cpu_clock = 0;
377   params.nb_proc_per_node = 0;
378   params.nb_node = 0;
379   params.isMPI = false;
380   params.workingdir = "";
381   params.mode = "";
382   params.policy = "";
383   params.parallelLib = "";
384   params.nb_component_nodes = 0;
385 }
386
387 //=============================================================================
388 /*! 
389  *  \return a number of processors not 0, only for MPI containers
390  */
391 //=============================================================================
392
393 int SALOME_LifeCycleCORBA::NbProc(const Engines::MachineParameters& params)
394 {
395   if( !isMpiContainer(params) )
396     return 0;
397   else if( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
398     return 1;
399   else if( params.nb_node == 0 )
400     return params.nb_proc_per_node;
401   else if( params.nb_proc_per_node == 0 )
402     return params.nb_node;
403   else
404     return params.nb_node * params.nb_proc_per_node;
405 }
406
407 //=============================================================================
408 /*! \brief Get the container manager
409  *
410  *  \return the container Manager
411  */
412 //=============================================================================
413
414 Engines::ContainerManager_ptr SALOME_LifeCycleCORBA::getContainerManager()
415 {
416  Engines::ContainerManager_var contManager =
417    Engines::ContainerManager::_duplicate(_ContManager);
418  return contManager._retn();
419 }
420
421 //=============================================================================
422 /*! \brief Get the resources manager
423  *
424  *  \return the container Manager
425  */
426 //=============================================================================
427
428 Engines::ResourcesManager_ptr SALOME_LifeCycleCORBA::getResourcesManager()
429 {
430  Engines::ResourcesManager_var resManager =
431    Engines::ResourcesManager::_duplicate(_ResManager);
432  return resManager._retn();
433 }
434
435 //=============================================================================
436 /*! \brief shutdown all the SALOME servers except SALOME_Session_Server, omniNames and notifd
437  */
438 //=============================================================================
439
440 void SALOME_LifeCycleCORBA::shutdownServers()
441 {
442   // get each Container from NamingService => shutdown it
443   // (the order is inverse to the order of servers initialization)
444   
445   SALOME::Session_var session = SALOME::Session::_nil();
446   CORBA::Long pid = 0;
447   CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
448   if (!CORBA::is_nil(objS))
449     {
450       session = SALOME::Session::_narrow(objS);
451       if (!CORBA::is_nil(session))
452         {
453           pid = session->getPID();
454           session->ping();
455         }
456     }
457
458   string hostname = Kernel_Utils::GetHostname();
459   
460   // 1) SalomeLauncher
461   CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher");
462   Engines::SalomeLauncher_var launcher = Engines::SalomeLauncher::_narrow(objSL);
463   if (!CORBA::is_nil(launcher) && (pid != launcher->getPID()))
464     launcher->Shutdown();
465   
466   // 2) ConnectionManager
467   CORBA::Object_var objCnM=_NS->Resolve("/ConnectionManager");
468   Engines::ConnectionManager_var connMan=Engines::ConnectionManager::_narrow(objCnM);
469   if ( !CORBA::is_nil(connMan) && ( pid != connMan->getPID() ) )
470     connMan->ShutdownWithExit();
471   
472   // 3) SALOMEDS
473   CORBA::Object_var objSDS = _NS->Resolve("/myStudyManager");
474   SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ;
475   if ( !CORBA::is_nil(studyManager) && ( pid != studyManager->getPID() ) )
476     studyManager->Shutdown();
477   
478   // 4) ModuleCatalog
479   CORBA::Object_var objMC=_NS->Resolve("/Kernel/ModulCatalog");
480   SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC);
481   if ( !CORBA::is_nil(catalog) && ( pid != catalog->getPID() ) )
482     catalog->shutdown();
483   
484   // 5) Registry
485   CORBA::Object_var objR = _NS->Resolve("/Registry");
486   Registry::Components_var registry = Registry::Components::_narrow(objR);
487   if ( !CORBA::is_nil(registry) && ( pid != registry->getPID() ) )
488       registry->Shutdown();
489
490   // 6) Logger
491   int argc = 0;
492   char *xargv = (char*)"";
493   char **argv = &xargv;
494   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
495
496   CORBA::Object_var objLog = CORBA::Object::_nil();
497   CosNaming::NamingContext_var inc;
498   CORBA::Object_var theObj = CORBA::Object::_nil();
499   std::string stdname = "Logger";
500   CosNaming::Name name;
501   name.length(1);
502   name[0].id = CORBA::string_dup(stdname.c_str());
503   try
504     { 
505       if(!CORBA::is_nil(orb)) 
506         theObj = orb->resolve_initial_references("NameService");
507       if (!CORBA::is_nil(theObj))
508         inc = CosNaming::NamingContext::_narrow(theObj);
509     }
510   catch(...)
511     {
512     }
513   if(!CORBA::is_nil(inc)) {
514     try
515       {
516         objLog = inc->resolve(name);
517         SALOME_Logger::Logger_var logger = SALOME_Logger::Logger::_narrow(objLog);
518         if ( !CORBA::is_nil(logger) )
519           logger->shutdown();
520       }
521     catch(...)
522       {
523       }
524   }
525 }
526
527 //=============================================================================
528 /*! \brief shutdown  omniNames and notifd
529  */
530 //=============================================================================
531
532 void SALOME_LifeCycleCORBA::killOmniNames()
533 {
534   string portNumber (::getenv ("NSPORT") );
535   if ( !portNumber.empty() ) 
536     {
537       string cmd ;
538       cmd = string( "ps -eo pid,command | grep -v grep | grep -E \"omniNames.*")
539         + portNumber
540         + string("\" | awk '{cmd=sprintf(\"kill -9 %s\",$1); system(cmd)}'" );
541       MESSAGE(cmd);
542       try {
543         system ( cmd.c_str() );
544       }
545       catch ( ... ) {
546       }
547     }
548   
549   // NPAL 18309  (Kill Notifd)
550   if ( !portNumber.empty() ) 
551     {
552       string cmd = ("from killSalomeWithPort import killNotifdAndClean; ");
553       cmd += string("killNotifdAndClean(") + portNumber + "); ";
554       cmd  = string("python -c \"") + cmd +"\" >& /dev/null";
555       MESSAGE(cmd);
556       system( cmd.c_str() );
557     }
558 }
559
560 //=============================================================================
561 /*! \brief Find an already existing and registered component instance.
562  *
563  * - build a list of machines on which an instance of the component is running,
564  * - find the best machine among the list
565  *
566  *  \param params         machine parameters like type or name...
567  *  \param componentName  the name of component class
568  *  \param studyId        default = 0  : multistudy instance
569  *  \param listOfMachines list of machine address
570  *  \return a CORBA reference of the component instance, or _nil if not found
571  */
572 //=============================================================================
573
574 Engines::Component_ptr
575 SALOME_LifeCycleCORBA::
576 _FindComponent(const Engines::MachineParameters& params,
577                const char *componentName,
578                int studyId,
579                const Engines::MachineList& listOfMachines)
580 {
581   // --- build the list of machines on which the component is already running
582
583   const char *containerName = params.container_name;
584   int nbproc = NbProc(params);
585 //   MESSAGE("_FindComponent, required " << containerName <<
586 //        " " << componentName << " " << nbproc);
587
588   Engines::MachineList_var machinesOK = new Engines::MachineList;
589
590   unsigned int lghtOfmachinesOK = 0;
591   machinesOK->length(listOfMachines.length());
592
593   for(unsigned int i=0; i<listOfMachines.length(); i++)
594     {
595       const char *currentMachine=listOfMachines[i];
596 //       MESSAGE("_FindComponent, look at " << currentMachine);
597       CORBA::Object_var obj = _NS->ResolveComponent(currentMachine,
598                                                     containerName,
599                                                     componentName,
600                                                     nbproc);
601       if (!CORBA::is_nil(obj))
602         machinesOK[lghtOfmachinesOK++] = CORBA::string_dup(currentMachine);
603     }
604
605   // --- find the best machine among the list
606
607   if(lghtOfmachinesOK != 0)
608     {
609       machinesOK->length(lghtOfmachinesOK);
610       CORBA::String_var bestMachine = _ResManager->FindFirst(machinesOK);
611       CORBA::Object_var obj = _NS->ResolveComponent(bestMachine,
612                                                     containerName,
613                                                     componentName,
614                                                     nbproc);
615       return Engines::Component::_narrow(obj);
616     }
617   else
618     return Engines::Component::_nil();
619 }
620
621 //=============================================================================
622 /*! \brief  Load a component instance.
623  *
624  *  - Finds a container in the list of machine or start one.
625  *  - Try to load the component library in the container,
626  *  - then create an instance of the component.
627  *
628  *  \param params         machine parameters like type or name...
629  *  \param componentName  the name of component class
630  *  \param studyId        default = 0  : multistudy instance
631  *  \return a CORBA reference of the component instance, or _nil if problem
632  */
633 //=============================================================================
634
635 Engines::Component_ptr 
636 SALOME_LifeCycleCORBA::
637 _LoadComponent(const Engines::MachineParameters& params, 
638               const char *componentName,
639               int studyId)
640 {
641   MESSAGE("_LoadComponent, required " << params.container_name <<
642           " " << componentName << " " << NbProc(params));
643
644   Engines::Container_var cont = _ContManager->FindOrStartContainer(params);
645   if (CORBA::is_nil(cont)) return Engines::Component::_nil();
646
647   bool isLoadable = cont->load_component_Library(componentName);
648   if (!isLoadable) return Engines::Component::_nil();
649
650   Engines::Component_var myInstance =
651     cont->create_component_instance(componentName, studyId);
652   return myInstance._retn();
653 }
654
655 //=============================================================================
656 /*! \brief  Load a parallel component instance.
657  *
658  *  \param params         machine parameters like type or name...
659  *  \param componentName  the name of component class
660  *  \param studyId        default = 0  : multistudy instance
661  *  \return a CORBA reference of the parallel component instance, or _nil if problem
662  */
663 //=============================================================================
664 Engines::Component_ptr
665 SALOME_LifeCycleCORBA::Load_ParallelComponent(const Engines::MachineParameters& params,
666                                               const char *componentName,
667                                               int studyId)
668 {
669   MESSAGE("Entering LoadParallelComponent");
670
671 /*MESSAGE("Parameters : ");
672   MESSAGE("Container name : " << params.container_name);
673   MESSAGE("Number of component nodes : " << params.nb_component_nodes);
674   MESSAGE("Component Name : " << componentName);*/
675
676   Engines::MachineParameters parms(params);
677   parms.componentList.length(1);
678   parms.componentList[0] = componentName;
679
680   MESSAGE("Starting Parallel Container");
681   Engines::Container_var cont = _ContManager->FindOrStartParallelContainer(parms);
682   if (CORBA::is_nil(cont)) {
683     INFOS("FindOrStartParallelContainer() returns a NULL container !");
684     return Engines::Component::_nil();
685   }
686
687   MESSAGE("Loading component library");
688   bool isLoadable = cont->load_component_Library(componentName);
689   if (!isLoadable) {
690     INFOS(componentName <<" library is not loadable !");
691     return Engines::Component::_nil();
692   }
693
694   MESSAGE("Creating component instance");
695   // @PARALLEL@ permits to identify that the component requested
696   // is a parallel component.
697   string name = string(componentName) + string("@PARALLEL@");
698   Engines::Component_var myInstance = cont->create_component_instance(name.c_str(), studyId);
699   if (CORBA::is_nil(myInstance))
700     INFOS("create_component_instance returns a NULL component !");
701   return myInstance._retn();
702 }
703
704 /*! \brief copy a file from a source host to a destination host
705  * \param hostSrc the source host
706  * \param fileSrc the file to copy from the source host to the destination host
707  * \param hostDest the destination host
708  * \param fileDest the destination file
709  */
710 void SALOME_LifeCycleCORBA::copyFile(const char* hostSrc, const char* fileSrc, const char* hostDest, const char* fileDest)
711 {
712   if(strcmp(hostDest,"localhost") == 0)
713     {
714       //if localhost use a shortcut
715       SALOME_FileTransferCORBA transfer(hostSrc,fileSrc);
716       transfer.getLocalFile(fileDest);
717       return;
718     }
719
720   Engines::ContainerManager_var contManager = getContainerManager();
721
722   Engines::MachineParameters params;
723   preSet(params);
724
725   params.hostname = hostDest;
726   Engines::Container_var containerDest = contManager->FindOrStartContainer(params);
727
728   params.hostname = hostSrc;
729   Engines::Container_var containerSrc = contManager->FindOrStartContainer(params);
730
731   containerDest->copyFile(containerSrc,fileSrc,fileDest);
732 }
733