1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SALOME_ResourcesManager.hxx"
23 #include "Utils_ExceptHandlers.hxx"
24 #include "Utils_CorbaException.hxx"
41 #include <sys/types.h>
43 #include "utilities.h"
45 #define MAX_SIZE_FOR_HOSTNAME 256;
49 const char *SALOME_ResourcesManager::_ResourcesManagerNameInNS = "/ResourcesManager";
51 //=============================================================================
55 //=============================================================================
57 SALOME_ResourcesManager::
58 SALOME_ResourcesManager(CORBA::ORB_ptr orb,
59 PortableServer::POA_var poa,
60 SALOME_NamingService *ns,
61 const char *xmlFilePath) : _rm(xmlFilePath)
63 MESSAGE("SALOME_ResourcesManager constructor");
65 _orb = CORBA::ORB::_duplicate(orb) ;
66 _poa = PortableServer::POA::_duplicate(poa) ;
67 PortableServer::ObjectId_var id = _poa->activate_object(this);
68 CORBA::Object_var obj = _poa->id_to_reference(id);
69 Engines::SalomeLauncher_var refContMan =
70 Engines::SalomeLauncher::_narrow(obj);
72 _NS->Register(refContMan,_ResourcesManagerNameInNS);
73 MESSAGE("SALOME_ResourcesManager constructor end");
76 //=============================================================================
78 * Standard constructor, parse resource file.
79 * - if ${APPLI} exists in environment,
80 * look for ${HOME}/${APPLI}/CatalogResources.xml
81 * - else look for default:
82 * ${KERNEL_ROOT_DIR}/share/salome/resources/kernel/CatalogResources.xml
83 * - parse XML resource file.
85 //=============================================================================
87 SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb,
88 PortableServer::POA_var poa,
89 SALOME_NamingService *ns) : _rm()
91 MESSAGE("SALOME_ResourcesManager constructor");
93 _orb = CORBA::ORB::_duplicate(orb) ;
94 _poa = PortableServer::POA::_duplicate(poa) ;
95 PortableServer::ObjectId_var id = _poa->activate_object(this);
96 CORBA::Object_var obj = _poa->id_to_reference(id);
97 Engines::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj);
98 _NS->Register(refContMan,_ResourcesManagerNameInNS);
100 MESSAGE("SALOME_ResourcesManager constructor end");
103 //=============================================================================
105 * Standard Destructor
107 //=============================================================================
109 SALOME_ResourcesManager::~SALOME_ResourcesManager()
111 MESSAGE("SALOME_ResourcesManager destructor");
115 //=============================================================================
117 * shutdown all the containers, then the ContainerManager servant
119 //=============================================================================
121 void SALOME_ResourcesManager::Shutdown()
124 _NS->Destroy_Name(_ResourcesManagerNameInNS);
125 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
126 _poa->deactivate_object(oid);
130 //=============================================================================
132 * get the list of name of ressources fitting for the specified module.
133 * If hostname specified, check it is local or known in resources catalog.
136 * - select first machines with corresponding OS (all machines if
137 * parameter OS empty),
138 * - then select the sublist of machines on witch the module is known
139 * (if the result is empty, that probably means that the inventory of
140 * modules is probably not done, so give complete list from previous step)
142 //=============================================================================
144 Engines::MachineList *
145 SALOME_ResourcesManager::GetFittingResources(const Engines::MachineParameters& params,
146 const Engines::CompoList& componentList)
148 // MESSAGE("ResourcesManager::GetFittingResources");
150 p.hostname = params.hostname;
152 p.nb_node = params.nb_node;
153 p.nb_proc_per_node = params.nb_proc_per_node;
154 p.cpu_clock = params.cpu_clock;
155 p.mem_mb = params.mem_mb;
158 for(unsigned int i=0;i<componentList.length();i++)
159 cl.push_back(string(componentList[i]));
161 Engines::MachineList *ret=new Engines::MachineList;
163 vector <std::string> vec = _rm.GetFittingResources(p,cl);
164 ret->length(vec.size());
165 for(unsigned int i=0;i<vec.size();i++)
166 (*ret)[i] = (vec[i]).c_str();
168 catch(const ResourcesException &ex){
169 INFOS("Caught exception.");
170 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
176 //=============================================================================
178 * dynamically obtains the first machines
180 //=============================================================================
183 SALOME_ResourcesManager::FindFirst(const Engines::MachineList& listOfMachines)
186 for(unsigned int i=0;i<listOfMachines.length();i++)
187 ml.push_back(string(listOfMachines[i]));
189 return CORBA::string_dup(_rm.FindFirst(ml).c_str());
192 Engines::MachineParameters* SALOME_ResourcesManager::GetMachineParameters(const char *hostname)
194 ParserResourcesType resource = _rm.GetResourcesList(string(hostname));
195 Engines::MachineParameters *p_ptr = new Engines::MachineParameters;
196 p_ptr->container_name = CORBA::string_dup("");
197 p_ptr->hostname = CORBA::string_dup(resource.HostName.c_str());
198 p_ptr->alias = CORBA::string_dup(resource.Alias.c_str());
199 if( resource.Protocol == rsh )
200 p_ptr->protocol = "rsh";
201 else if( resource.Protocol == ssh )
202 p_ptr->protocol = "ssh";
203 p_ptr->username = CORBA::string_dup(resource.UserName.c_str());
204 p_ptr->applipath = CORBA::string_dup(resource.AppliPath.c_str());
205 p_ptr->modList.length(resource.ModulesList.size());
206 for(unsigned int i=0;i<resource.ModulesList.size();i++)
207 p_ptr->modList[i] = CORBA::string_dup(resource.ModulesList[i].c_str());
208 p_ptr->OS = CORBA::string_dup(resource.OS.c_str());
209 p_ptr->mem_mb = resource.DataForSort._memInMB;
210 p_ptr->cpu_clock = resource.DataForSort._CPUFreqMHz;
211 p_ptr->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode;
212 p_ptr->nb_node = resource.DataForSort._nbOfNodes;
214 if( resource.mpi == lam )
215 p_ptr->mpiImpl = "lam";
216 else if( resource.mpi == mpich1 )
217 p_ptr->mpiImpl = "mpich1";
218 else if( resource.mpi == mpich2 )
219 p_ptr->mpiImpl = "mpich2";
220 else if( resource.mpi == openmpi )
221 p_ptr->mpiImpl = "openmpi";
222 else if( resource.mpi == slurm )
223 p_ptr->mpiImpl = "slurm";
224 else if( resource.mpi == prun )
225 p_ptr->mpiImpl = "prun";
227 if( resource.Batch == pbs )
228 p_ptr->batch = "pbs";
229 else if( resource.Batch == lsf )
230 p_ptr->batch = "lsf";
231 else if( resource.Batch == sge )
232 p_ptr->batch = "sge";
234 p_ptr->nb_component_nodes=1;