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