Salome HOME
Merge remote branch 'origin/V7_dev'
[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   // ==> allways use absolute path and dot 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 #ifdef WIN32
604   #ifdef _DEBUG_
605     python_exe += std::string("_d");
606   #endif
607 #endif
608
609   if ( !portNumber.empty() )
610   {
611     std::string cmd;
612
613     cmd  = std::string("from salome_utils import killOmniNames; ");
614     cmd += std::string("killOmniNames(") + portNumber + "); ";
615     cmd  = python_exe + std::string(" -c \"") + cmd +"\"";
616     MESSAGE(cmd);
617     system( cmd.c_str() );
618
619     cmd  = std::string("from killSalomeWithPort import cleanApplication; ");
620     cmd += std::string("cleanApplication(") + portNumber + "); ";
621     cmd  = python_exe + std::string(" -c \"") + cmd +"\"";
622     MESSAGE(cmd);
623     system( cmd.c_str() );
624   }
625
626   // shutdown portmanager
627   if ( !portNumber.empty() )
628   {
629     std::string cmd;
630
631     cmd  = std::string("from PortManager import releasePort; ");
632     cmd += std::string("releasePort(") + portNumber + "); ";
633     cmd  = python_exe + std::string(" -c \"") + cmd +"\"";
634     MESSAGE(cmd);
635     system( cmd.c_str() );
636   }
637 }
638
639 //=============================================================================
640 /*! \brief Find an already existing and registered component instance.
641  *
642  * - build a list of machines on which an instance of the component is running,
643  * - find the best machine among the list
644  *
645  *  \param params         machine parameters like type or name...
646  *  \param componentName  the name of component class
647  *  \param studyId        default = 0  : multistudy instance
648  *  \param listOfMachines list of machine address
649  *  \return a CORBA reference of the component instance, or _nil if not found
650  */
651 //=============================================================================
652
653 Engines::EngineComponent_ptr
654 SALOME_LifeCycleCORBA::
655 _FindComponent(const Engines::ContainerParameters& params,
656                const char *componentName,
657                int studyId,
658                const Engines::ResourceList& listOfResources)
659 {
660   // --- build the list of machines on which the component is already running
661   const char *containerName = params.container_name;
662   int nbproc = NbProc(params);
663
664   Engines::ResourceList_var resourcesOK = new Engines::ResourceList;
665
666   unsigned int lghtOfresourcesOK = 0;
667   resourcesOK->length(listOfResources.length());
668
669   for(unsigned int i=0; i < listOfResources.length(); i++)
670   {
671     const char * currentResource = listOfResources[i];
672     Engines::ResourceDefinition_var resource_definition =
673         _ResManager->GetResourceDefinition(currentResource);
674     CORBA::Object_var obj = _NS->ResolveComponent(resource_definition->hostname.in(),
675                                                   containerName,
676                                                   componentName,
677                                                   nbproc);
678     if (!CORBA::is_nil(obj))
679       resourcesOK[lghtOfresourcesOK++] = CORBA::string_dup(currentResource);
680   }
681
682   // --- find the best machine among the list
683   if(lghtOfresourcesOK != 0)
684   {
685     resourcesOK->length(lghtOfresourcesOK);
686     CORBA::String_var bestResource = _ResManager->FindFirst(resourcesOK);
687     Engines::ResourceDefinition_var resource_definition =
688         _ResManager->GetResourceDefinition(bestResource);
689     CORBA::Object_var obj = _NS->ResolveComponent(resource_definition->hostname.in(),
690                                                   containerName,
691                                                   componentName,
692                                                   nbproc);
693     return Engines::EngineComponent::_narrow(obj);
694   }
695   else
696     return Engines::EngineComponent::_nil();
697 }
698
699 //=============================================================================
700 /*! \brief  Load a component instance.
701  *
702  *  - Finds a container in the list of machine or start one.
703  *  - Try to load the component library in the container,
704  *  - then create an instance of the component.
705  *
706  *  \param params         machine parameters like type or name...
707  *  \param componentName  the name of component class
708  *  \param studyId        default = 0  : multistudy instance
709  *  \return a CORBA reference of the component instance, or _nil if problem
710  */
711 //=============================================================================
712
713 Engines::EngineComponent_ptr
714 SALOME_LifeCycleCORBA::
715 _LoadComponent(const Engines::ContainerParameters& params,
716               const char *componentName,
717               int studyId)
718 {
719   MESSAGE("_LoadComponent, required " << params.container_name <<
720           " " << componentName << " " << NbProc(params));
721
722   Engines::ContainerParameters local_params(params);
723   local_params.mode = CORBA::string_dup("findorstart");
724   Engines::Container_var cont = _ContManager->GiveContainer(local_params);
725   if (CORBA::is_nil(cont)) return Engines::EngineComponent::_nil();
726
727   char* reason;
728   bool isLoadable = cont->load_component_Library(componentName,reason);
729   if (!isLoadable)
730     {
731       //std::cerr << reason << std::endl;
732       CORBA::string_free(reason);
733       return Engines::EngineComponent::_nil();
734     }
735   CORBA::string_free(reason);
736
737   Engines::EngineComponent_var myInstance =
738     cont->create_component_instance(componentName, studyId);
739   return myInstance._retn();
740 }
741
742 //=============================================================================
743 /*! \brief  Load a parallel component instance.
744  *
745  *  \param params         machine parameters like type or name...
746  *  \param componentName  the name of component class
747  *  \param studyId        default = 0  : multistudy instance
748  *  \return a CORBA reference of the parallel component instance, or _nil if problem
749  */
750 //=============================================================================
751 Engines::EngineComponent_ptr
752 SALOME_LifeCycleCORBA::Load_ParallelComponent(const Engines::ContainerParameters& params,
753                                               const char *componentName,
754                                               int studyId)
755 {
756   MESSAGE("Entering LoadParallelComponent");
757
758 /*MESSAGE("Parameters : ");
759   MESSAGE("Container name : " << params.container_name);
760   MESSAGE("Number of component nodes : " << params.nb_component_nodes);
761   MESSAGE("Component Name : " << componentName);*/
762
763   Engines::ContainerParameters parms(params);
764   parms.resource_params.componentList.length(1);
765   parms.resource_params.componentList[0] = componentName;
766   parms.mode = CORBA::string_dup("findorstart");
767
768   MESSAGE("Starting Parallel Container");
769   Engines::Container_var cont = _ContManager->GiveContainer(parms);
770   if (CORBA::is_nil(cont)) {
771     INFOS("FindOrStartParallelContainer() returns a NULL container !");
772     return Engines::EngineComponent::_nil();
773   }
774
775   MESSAGE("Loading component library");
776   char* reason;
777   bool isLoadable = cont->load_component_Library(componentName,reason);
778   if (!isLoadable) {
779     INFOS(componentName <<" library is not loadable !");
780     //std::cerr << reason << std::endl;
781     CORBA::string_free(reason);
782     return Engines::EngineComponent::_nil();
783   }
784   CORBA::string_free(reason);
785
786   MESSAGE("Creating component instance");
787   // @PARALLEL@ permits to identify that the component requested
788   // is a parallel component.
789   std::string name = std::string(componentName);
790   Engines::EngineComponent_var myInstance = cont->create_component_instance(name.c_str(), studyId);
791   if (CORBA::is_nil(myInstance))
792     INFOS("create_component_instance returns a NULL component !");
793   return myInstance._retn();
794 }
795
796 /*! \brief copy a file from a source host to a destination host
797  * \param hostSrc the source host
798  * \param fileSrc the file to copy from the source host to the destination host
799  * \param hostDest the destination host
800  * \param fileDest the destination file
801  */
802 void SALOME_LifeCycleCORBA::copyFile(const char* hostSrc, const char* fileSrc, const char* hostDest, const char* fileDest)
803 {
804   if(strcmp(hostDest,"localhost") == 0)
805     {
806       //if localhost use a shortcut
807       SALOME_FileTransferCORBA transfer(hostSrc,fileSrc);
808       transfer.getLocalFile(fileDest);
809       return;
810     }
811
812   Engines::ContainerManager_var contManager = getContainerManager();
813
814   Engines::ContainerParameters params;
815   preSet(params);
816
817   params.resource_params.hostname = hostDest;
818   params.mode = CORBA::string_dup("findorstart");
819   Engines::Container_var containerDest = contManager->GiveContainer(params);
820
821   params.resource_params.hostname = hostSrc;
822   Engines::Container_var containerSrc = contManager->GiveContainer(params);
823
824   containerDest->copyFile(containerSrc,fileSrc,fileDest);
825 }
826
827 /*! \brief get the naming service used by the life cycle
828  *
829  *  \return the naming service
830  */
831 SALOME_NamingService * SALOME_LifeCycleCORBA::namingService()
832 {
833   return _NS;
834 }
835
836 /*! \brief get the orb used by the life cycle
837  *
838  *  \return the orb
839  */
840 CORBA::ORB_ptr SALOME_LifeCycleCORBA::orb()
841 {
842   return _NS->orb();
843 }