#include "OpUtil.hxx"
#include <stdlib.h>
+#include <stdio.h>
#ifndef WIN32
#include <unistd.h>
#else
SALOME_ResourcesManager::
SALOME_ResourcesManager(CORBA::ORB_ptr orb,
- PortableServer::POA_var poa,
- SALOME_NamingService *ns,
+ PortableServer::POA_var poa,
+ SALOME_NamingService *ns,
const char *xmlFilePath) : _rm(xmlFilePath)
{
MESSAGE("SALOME_ResourcesManager constructor");
//=============================================================================
SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb,
- PortableServer::POA_var poa,
- SALOME_NamingService *ns) : _rm()
+ PortableServer::POA_var poa,
+ SALOME_NamingService *ns) : _rm()
{
MESSAGE("SALOME_ResourcesManager constructor");
_NS = ns;
*/
//=============================================================================
-Engines::MachineList *
-SALOME_ResourcesManager::GetFittingResources(const Engines::MachineParameters& params)
+Engines::ResourceList *
+SALOME_ResourcesManager::GetFittingResources(const Engines::ResourceParameters& params)
{
-// MESSAGE("ResourcesManager::GetFittingResources");
- machineParams p;
+ MESSAGE("ResourcesManager::GetFittingResources");
+ Engines::ResourceList * ret = new Engines::ResourceList;
+
+ // CORBA -> C++
+ resourceParams p;
+ p.name = params.name;
p.hostname = params.hostname;
p.OS = params.OS;
+ p.nb_proc = params.nb_proc;
p.nb_node = params.nb_node;
p.nb_proc_per_node = params.nb_proc_per_node;
p.cpu_clock = params.cpu_clock;
p.mem_mb = params.mem_mb;
-
- for(unsigned int i=0;i<params.componentList.length();i++)
+ for(unsigned int i=0; i<params.componentList.length(); i++)
p.componentList.push_back(string(params.componentList[i]));
-
- for(unsigned int i=0;i<params.computerList.length();i++)
- p.computerList.push_back(string(params.computerList[i]));
+ for(unsigned int i=0; i<params.resList.length(); i++)
+ p.resourceList.push_back(string(params.resList[i]));
- Engines::MachineList *ret=new Engines::MachineList;
- try{
- vector <std::string> vec = _rm.GetFittingResources(p);
- ret->length(vec.size());
- for(unsigned int i=0;i<vec.size();i++)
- (*ret)[i] = (vec[i]).c_str();
+ try
+ {
+ // Call C++ ResourceManager
+ vector <std::string> vec = _rm.GetFittingResources(p);
+
+ // C++ -> CORBA
+ ret->length(vec.size());
+ for(unsigned int i=0;i<vec.size();i++)
+ (*ret)[i] = (vec[i]).c_str();
}
- catch(const ResourcesException &ex){
- INFOS("Caught exception.");
+ catch(const ResourcesException &ex)
+ {
+ INFOS("Caught exception in GetFittingResources C++: " << ex.msg);
THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
}
//=============================================================================
char *
-SALOME_ResourcesManager::FindFirst(const Engines::MachineList& listOfMachines)
+SALOME_ResourcesManager::FindFirst(const Engines::ResourceList& listOfResources)
{
- vector<string> ml;
- for(unsigned int i=0;i<listOfMachines.length();i++)
- ml.push_back(string(listOfMachines[i]));
+ // CORBA -> C++
+ vector<string> rl;
+ for(unsigned int i=0; i<listOfResources.length(); i++)
+ rl.push_back(string(listOfResources[i]));
- return CORBA::string_dup(_rm.Find("first",ml).c_str());
+ return CORBA::string_dup(_rm.Find("first", rl).c_str());
}
char *
-SALOME_ResourcesManager::Find(const char* policy, const Engines::MachineList& listOfMachines)
+SALOME_ResourcesManager::Find(const char* policy, const Engines::ResourceList& listOfResources)
{
- vector<string> ml;
- for(unsigned int i=0;i<listOfMachines.length();i++)
- ml.push_back(string(listOfMachines[i]));
- return CORBA::string_dup(_rm.Find(policy,ml).c_str());
+ // CORBA -> C++
+ vector<string> rl;
+ for(unsigned int i=0; i<listOfResources.length(); i++)
+ rl.push_back(string(listOfResources[i]));
+
+ return CORBA::string_dup(_rm.Find(policy, rl).c_str());
}
-Engines::MachineDefinition* SALOME_ResourcesManager::GetMachineParameters(const char *hostname)
+Engines::ResourceDefinition*
+SALOME_ResourcesManager::GetResourceDefinition(const char * name)
{
- ParserResourcesType resource = _rm.GetResourcesList(string(hostname));
- Engines::MachineDefinition *p_ptr = new Engines::MachineDefinition;
+ ParserResourcesType resource = _rm.GetResourcesDescr(name);
+ Engines::ResourceDefinition *p_ptr = new Engines::ResourceDefinition;
+
+ p_ptr->name = CORBA::string_dup(resource.Name.c_str());
p_ptr->hostname = CORBA::string_dup(resource.HostName.c_str());
- p_ptr->alias = CORBA::string_dup(resource.Alias.c_str());
if( resource.Protocol == rsh )
p_ptr->protocol = "rsh";
else if( resource.Protocol == ssh )
p_ptr->protocol = "ssh";
+ if( resource.ClusterInternalProtocol == rsh )
+ p_ptr->iprotocol = "rsh";
+ else if( resource.ClusterInternalProtocol == ssh )
+ p_ptr->iprotocol = "ssh";
p_ptr->username = CORBA::string_dup(resource.UserName.c_str());
p_ptr->applipath = CORBA::string_dup(resource.AppliPath.c_str());
p_ptr->componentList.length(resource.ComponentsList.size());
p_ptr->batch = "lsf";
else if( resource.Batch == sge )
p_ptr->batch = "sge";
-
- p_ptr->nb_component_nodes=1;
+ else if( resource.Batch == ssh_batch )
+ p_ptr->batch = "ssh";
return p_ptr;
}
+void
+SALOME_ResourcesManager::AddResource(const Engines::ResourceDefinition& new_resource,
+ CORBA::Boolean write,
+ const char * xml_file)
+{
+ ParserResourcesType resource;
+ resource.Name = new_resource.name.in();
+ resource.HostName = new_resource.hostname.in();
+ resource.OS = new_resource.OS.in();
+ resource.DataForSort._memInMB = new_resource.mem_mb;
+ resource.DataForSort._CPUFreqMHz = new_resource.cpu_clock;
+ resource.DataForSort._nbOfNodes = new_resource.nb_node;
+ resource.DataForSort._nbOfProcPerNode = new_resource.nb_proc_per_node;
+ resource.UserName = new_resource.username.in();
+
+ std::string aBatch = new_resource.batch.in();
+ if (aBatch == "pbs")
+ resource.Batch = pbs;
+ else if (aBatch == "lsf")
+ resource.Batch = lsf;
+ else if (aBatch == "sge")
+ resource.Batch = sge;
+ else if (aBatch == "ssh_batch")
+ resource.Batch = ssh_batch;
+ else if (aBatch == "")
+ resource.Batch = none;
+ else {
+ INFOS("Bad Batch definition in AddResource: " << aBatch);
+ std::string message("Bad Batch definition in AddResource: ");
+ message += aBatch;
+ THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM);
+ }
+
+ std::string anMpi = new_resource.mpiImpl.in();
+ if (anMpi == "lam")
+ resource.mpi = lam;
+ else if (anMpi == "mpich1")
+ resource.mpi = mpich1;
+ else if (anMpi == "mpich2")
+ resource.mpi = mpich2;
+ else if (anMpi == "openmpi")
+ resource.mpi = openmpi;
+ else if (anMpi == "slurm")
+ resource.mpi = slurm;
+ else if (anMpi == "prun")
+ resource.mpi = prun;
+ else if (anMpi == "")
+ resource.mpi = nompi;
+ else {
+ INFOS("Bad MPI definition in AddResource: " << anMpi);
+ std::string message("Bad MPI definition in AddResource: ");
+ message += anMpi;
+ THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM);
+ }
+
+ std::string mode_str = new_resource.mode.in();
+ if (mode_str == "interactive")
+ resource.Mode = interactive;
+ else if (mode_str == "batch")
+ resource.Mode = batch;
+ else if (mode_str == "")
+ resource.Mode = interactive;
+ else {
+ INFOS("Bad mode definition in AddResource: " << mode_str);
+ std::string message("Bad mode definition in AddResource: ");
+ message += mode_str;
+ THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM);
+ }
+
+ std::string protocol = new_resource.protocol.in();
+ if (protocol == "rsh")
+ resource.Protocol = rsh;
+ else if (protocol == "ssh")
+ resource.Protocol = ssh;
+ else if (protocol == "")
+ resource.Protocol = rsh;
+ else {
+ INFOS("Bad protocol definition in AddResource: " << protocol);
+ std::string message("Bad protocol definition in AddResource: ");
+ message += protocol;
+ THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM);
+ }
+
+ std::string iprotocol = new_resource.iprotocol.in();
+ if (iprotocol == "rsh")
+ resource.ClusterInternalProtocol = rsh;
+ else if (iprotocol == "ssh")
+ resource.ClusterInternalProtocol = ssh;
+ else if (iprotocol == "")
+ resource.ClusterInternalProtocol = rsh;
+ else {
+ INFOS("Bad iprotocol definition in AddResource: " << iprotocol);
+ std::string message("Bad iprotocol definition in AddResource: ");
+ message += iprotocol;
+ THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM);
+ }
+
+ for (CORBA::ULong i = 0; i < new_resource.componentList.length(); i++)
+ resource.ComponentsList.push_back(new_resource.componentList[i].in());
+
+ _rm.AddResourceInCatalog(resource);
+
+ if (write)
+ {
+ _rm.WriteInXmlFile(std::string(xml_file));
+ _rm.ParseXmlFiles();
+ }
+}
+
+std::string
+SALOME_ResourcesManager::getMachineFile(std::string hostname,
+ CORBA::Long nb_procs,
+ std::string parallelLib)
+{
+ std::string machine_file_name("");
+
+ if (parallelLib == "Dummy")
+ {
+ MESSAGE("[getMachineFile] parallelLib is Dummy");
+ MapOfParserResourcesType resourcesList = _rm.GetList();
+ if (resourcesList.find(hostname) != resourcesList.end())
+ {
+ ParserResourcesType resource = resourcesList[hostname];
+
+ // Check if resource is cluster or not
+ if (resource.ClusterMembersList.empty())
+ {
+ //It is not a cluster so we create a cluster with one machine
+ ParserResourcesClusterMembersType fake_node;
+ fake_node.HostName = resource.HostName;
+ fake_node.Protocol = resource.Protocol;
+ fake_node.ClusterInternalProtocol = resource.ClusterInternalProtocol;
+ fake_node.UserName = resource.UserName;
+ fake_node.AppliPath = resource.AppliPath;
+ fake_node.DataForSort = resource.DataForSort;
+
+ resource.ClusterMembersList.push_front(fake_node);
+ }
+
+ // Creating list of machines for creating the machine file
+ std::list<std::string> list_of_machines;
+ std::list<ParserResourcesClusterMembersType>::iterator cluster_it =
+ resource.ClusterMembersList.begin();
+ while (cluster_it != resource.ClusterMembersList.end())
+ {
+ // For each member of the cluster we add a nbOfNodes * nbOfProcPerNode in the list
+ unsigned int number_of_proc = (*cluster_it).DataForSort._nbOfNodes *
+ (*cluster_it).DataForSort._nbOfProcPerNode;
+ for (unsigned int i = 0; i < number_of_proc; i++)
+ list_of_machines.push_back((*cluster_it).HostName);
+ cluster_it++;
+ }
+
+ // Creating machine file
+ machine_file_name = tmpnam(NULL);
+ std::ofstream machine_file(machine_file_name.c_str(), ios_base::out);
+
+ CORBA::Long machine_number = 0;
+ std::list<std::string>::iterator it = list_of_machines.begin();
+ while (machine_number != nb_procs)
+ {
+ // Adding a new node to the machine file
+ machine_file << *it << endl;
+
+ // counting...
+ it++;
+ if (it == list_of_machines.end())
+ it = list_of_machines.begin();
+ machine_number++;
+ }
+ }
+ else
+ INFOS("[getMachineFile] Error hostname not found in resourcesList -> " << hostname);
+ }
+ else if (parallelLib == "Mpi")
+ {
+ MESSAGE("[getMachineFile] parallelLib is Mpi");
+
+ MapOfParserResourcesType resourcesList = _rm.GetList();
+ if (resourcesList.find(hostname) != resourcesList.end())
+ {
+ ParserResourcesType resource = resourcesList[hostname];
+ // Check if resource is cluster or not
+ if (resource.ClusterMembersList.empty())
+ {
+ //It is not a cluster so we create a cluster with one machine
+ ParserResourcesClusterMembersType fake_node;
+ fake_node.HostName = resource.HostName;
+ fake_node.Protocol = resource.Protocol;
+ fake_node.ClusterInternalProtocol = resource.ClusterInternalProtocol;
+ fake_node.UserName = resource.UserName;
+ fake_node.AppliPath = resource.AppliPath;
+ fake_node.DataForSort = resource.DataForSort;
+
+ resource.ClusterMembersList.push_front(fake_node);
+ }
+
+ // Choose mpi implementation -> each MPI implementation has is own machinefile...
+ if (resource.mpi == lam)
+ {
+ // Creating machine file
+ machine_file_name = tmpnam(NULL);
+ std::ofstream machine_file(machine_file_name.c_str(), ios_base::out);
+
+ // We add all cluster machines to the file
+ std::list<ParserResourcesClusterMembersType>::iterator cluster_it =
+ resource.ClusterMembersList.begin();
+ while (cluster_it != resource.ClusterMembersList.end())
+ {
+ unsigned int number_of_proc = (*cluster_it).DataForSort._nbOfNodes *
+ (*cluster_it).DataForSort._nbOfProcPerNode;
+ machine_file << (*cluster_it).HostName << " cpu=" << number_of_proc << endl;
+ cluster_it++;
+ }
+ }
+ else if (resource.mpi == nompi)
+ {
+ INFOS("[getMachineFile] Error hostname MPI implementation was defined for " << hostname);
+ }
+ else
+ INFOS("[getMachineFile] Error hostname MPI implementation not currenly handled for " << hostname);
+ }
+ else
+ INFOS("[getMachineFile] Error hostname not found in resourcesList -> " << hostname);
+ }
+ else
+ INFOS("[getMachineFile] Error parallelLib is not handled -> " << parallelLib);
+
+ return machine_file_name;
+}