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::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj);
70 _NS->Register(refContMan,_ResourcesManagerNameInNS);
71 MESSAGE("SALOME_ResourcesManager constructor end");
74 //=============================================================================
76 * Standard constructor, parse resource file.
77 * - if ${APPLI} exists in environment,
78 * look for ${HOME}/${APPLI}/CatalogResources.xml
79 * - else look for default:
80 * ${KERNEL_ROOT_DIR}/share/salome/resources/kernel/CatalogResources.xml
81 * - parse XML resource file.
83 //=============================================================================
85 SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb,
86 PortableServer::POA_var poa,
87 SALOME_NamingService *ns) : _rm()
89 MESSAGE("SALOME_ResourcesManager constructor");
91 _orb = CORBA::ORB::_duplicate(orb) ;
92 _poa = PortableServer::POA::_duplicate(poa) ;
93 PortableServer::ObjectId_var id = _poa->activate_object(this);
94 CORBA::Object_var obj = _poa->id_to_reference(id);
95 Engines::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj);
96 _NS->Register(refContMan,_ResourcesManagerNameInNS);
98 MESSAGE("SALOME_ResourcesManager constructor end");
101 //=============================================================================
103 * Standard Destructor
105 //=============================================================================
107 SALOME_ResourcesManager::~SALOME_ResourcesManager()
109 MESSAGE("SALOME_ResourcesManager destructor");
113 //=============================================================================
115 * shutdown all the containers, then the ContainerManager servant
117 //=============================================================================
119 void SALOME_ResourcesManager::Shutdown()
122 _NS->Destroy_Name(_ResourcesManagerNameInNS);
123 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
124 _poa->deactivate_object(oid);
127 //=============================================================================
129 * get the list of name of ressources fitting for the specified component.
130 * If hostname specified, check it is local or known in resources catalog.
133 * - select first machines with corresponding OS (all machines if
134 * parameter OS empty),
135 * - then select the sublist of machines on witch the component is known
136 * (if the result is empty, that probably means that the inventory of
137 * components is probably not done, so give complete list from previous step)
139 //=============================================================================
141 Engines::MachineList *
142 SALOME_ResourcesManager::GetFittingResources(const Engines::MachineParameters& params,
143 const Engines::CompoList& componentList)
145 // MESSAGE("ResourcesManager::GetFittingResources");
147 p.hostname = params.hostname;
149 p.nb_node = params.nb_node;
150 p.nb_proc_per_node = params.nb_proc_per_node;
151 p.cpu_clock = params.cpu_clock;
152 p.mem_mb = params.mem_mb;
155 for(unsigned int i=0;i<componentList.length();i++)
156 cl.push_back(string(componentList[i]));
158 Engines::MachineList *ret=new Engines::MachineList;
160 vector <std::string> vec = _rm.GetFittingResources(p,cl);
161 ret->length(vec.size());
162 for(unsigned int i=0;i<vec.size();i++)
163 (*ret)[i] = (vec[i]).c_str();
165 catch(const ResourcesException &ex){
166 INFOS("Caught exception.");
167 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
173 //=============================================================================
175 * dynamically obtains the first machines
177 //=============================================================================
180 SALOME_ResourcesManager::FindFirst(const Engines::MachineList& listOfMachines)
183 for(unsigned int i=0;i<listOfMachines.length();i++)
184 ml.push_back(string(listOfMachines[i]));
186 return CORBA::string_dup(_rm.Find("first",ml).c_str());
190 SALOME_ResourcesManager::Find(const char* policy, const Engines::MachineList& listOfMachines)
193 for(unsigned int i=0;i<listOfMachines.length();i++)
194 ml.push_back(string(listOfMachines[i]));
195 return CORBA::string_dup(_rm.Find(policy,ml).c_str());
198 Engines::MachineDefinition* SALOME_ResourcesManager::GetMachineParameters(const char *hostname)
200 ParserResourcesType resource = _rm.GetResourcesList(string(hostname));
201 Engines::MachineDefinition *p_ptr = new Engines::MachineDefinition;
202 p_ptr->hostname = CORBA::string_dup(resource.HostName.c_str());
203 p_ptr->alias = CORBA::string_dup(resource.Alias.c_str());
204 if( resource.Protocol == rsh )
205 p_ptr->protocol = "rsh";
206 else if( resource.Protocol == ssh )
207 p_ptr->protocol = "ssh";
208 p_ptr->username = CORBA::string_dup(resource.UserName.c_str());
209 p_ptr->applipath = CORBA::string_dup(resource.AppliPath.c_str());
210 p_ptr->componentList.length(resource.ComponentsList.size());
211 for(unsigned int i=0;i<resource.ComponentsList.size();i++)
212 p_ptr->componentList[i] = CORBA::string_dup(resource.ComponentsList[i].c_str());
213 p_ptr->OS = CORBA::string_dup(resource.OS.c_str());
214 p_ptr->mem_mb = resource.DataForSort._memInMB;
215 p_ptr->cpu_clock = resource.DataForSort._CPUFreqMHz;
216 p_ptr->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode;
217 p_ptr->nb_node = resource.DataForSort._nbOfNodes;
219 if( resource.mpi == lam )
220 p_ptr->mpiImpl = "lam";
221 else if( resource.mpi == mpich1 )
222 p_ptr->mpiImpl = "mpich1";
223 else if( resource.mpi == mpich2 )
224 p_ptr->mpiImpl = "mpich2";
225 else if( resource.mpi == openmpi )
226 p_ptr->mpiImpl = "openmpi";
227 else if( resource.mpi == slurm )
228 p_ptr->mpiImpl = "slurm";
229 else if( resource.mpi == prun )
230 p_ptr->mpiImpl = "prun";
232 if( resource.Batch == pbs )
233 p_ptr->batch = "pbs";
234 else if( resource.Batch == lsf )
235 p_ptr->batch = "lsf";
236 else if( resource.Batch == sge )
237 p_ptr->batch = "sge";
239 p_ptr->nb_component_nodes=1;