- File CatalogResources.xml is no more generated by appli_gen.py.
- The default resource "localhost" is always generated by the ResourceManager. It can't be edited or deleted.
- This default resource can be used for local batch jobs.
f.write(command % ",".join(mods))
f.close()
- #Add default CatalogResources.xml file
- f =open(os.path.join(home_dir,'CatalogResources.xml'),'w')
- command="""<!DOCTYPE ResourcesCatalog>
-<resources>
- <machine name="localhost"
- hostname="localhost" />
-</resources>
-"""
- f.write(command)
- f.close()
-
#Add USERS directory with 777 permission to store users configuration files
users_dir=os.path.join(home_dir,'USERS')
makedirs(users_dir)
ResourceList GetFittingResources(in ResourceParameters params) raises (SALOME::SALOME_Exception);
//! Get definition of a resource
- ResourceDefinition GetResourceDefinition(in string name);
+ ResourceDefinition GetResourceDefinition(in string name) raises (SALOME::SALOME_Exception);
//! Add a new resource to the resource_manager
/*!
switch(params.Protocol)
{
+ case sh:
+ protocol = Batch::SH;
+ break;
case rsh:
protocol = Batch::RSH;
break;
if (std::string(new_params.resource_params.hostname.in()) == "localhost")
{
new_params.resource_params.hostname = CORBA::string_dup(Kernel_Utils::GetHostname().c_str());
- new_params.resource_params.name = CORBA::string_dup(Kernel_Utils::GetHostname().c_str());
+ new_params.resource_params.name = CORBA::string_dup("localhost");
}
Engines::ResourceList_var listOfResources;
#include <algorithm>
+#include "Utils_SALOME_Exception.hxx"
+
#define MAX_SIZE_FOR_HOSTNAME 256;
+using namespace std;
+
+const string ResourcesManager_cpp::DEFAULT_RESOURCE_NAME = "localhost";
+
static LoadRateManagerFirst first;
static LoadRateManagerCycl cycl;
static LoadRateManagerAltCycl altcycl;
_resourceManagerMap["altcycl"]=&altcycl;
_resourceManagerMap["best"]=&altcycl;
_resourceManagerMap[""]=&altcycl;
+
+ AddDefaultResourceInCatalog();
}
//=============================================================================
_resourceManagerMap["best"]=&altcycl;
_resourceManagerMap[""]=&altcycl;
+ AddDefaultResourceInCatalog();
+
bool default_catalog_resource = true;
if (getenv("USER_CATALOG_RESOURCES_FILE") != 0)
{
// Step 5
SelectOnlyResourcesWithOS(vec, params.OS.c_str());
-
+
// Step 6
std::vector<std::string> vec_save(vec);
KeepOnlyResourcesWithComponent(vec, params.componentList);
//=============================================================================
void
-ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource) throw(ResourcesException)
+ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource)
{
+ if (new_resource.Name == DEFAULT_RESOURCE_NAME)
+ throw SALOME_Exception((string("Cannot modify default local resource \"") +
+ DEFAULT_RESOURCE_NAME + "\"").c_str());
// TODO - Add minimal check
_resourcesList[new_resource.Name] = new_resource;
}
void ResourcesManager_cpp::DeleteResourceInCatalog(const char * name)
{
+ if (DEFAULT_RESOURCE_NAME == name)
+ throw SALOME_Exception((string("Cannot delete default local resource \"") +
+ DEFAULT_RESOURCE_NAME + "\"").c_str());
MapOfParserResourcesType_it it = _resourcesList.find(name);
if (it != _resourcesList.end())
_resourcesList.erase(name);
{
RES_MESSAGE("WriteInXmlFile : start");
+ MapOfParserResourcesType resourceListToSave(_resourcesList);
+ // We do not save default local resource because it is automatically created at startup
+ resourceListToSave.erase(DEFAULT_RESOURCE_NAME);
+ if (resourceListToSave.empty())
+ {
+ RES_MESSAGE("WriteInXmlFile: nothing to do, no resource except default \"" <<
+ DEFAULT_RESOURCE_NAME << "\"");
+ return;
+ }
+
if (xml_file == "")
{
_path_resources_it = _path_resources.begin();
xmlNewDocComment(aDoc, BAD_CAST "ResourcesCatalog");
SALOME_ResourcesCatalog_Handler* handler =
- new SALOME_ResourcesCatalog_Handler(_resourcesList);
+ new SALOME_ResourcesCatalog_Handler(resourceListToSave);
handler->PrepareDocToXmlFile(aDoc);
delete handler;
int result = stat((*_path_resources_it).c_str(), &statinfo);
if (result < 0)
{
- std::cerr << "Error in method stat for file : " << (*_path_resources_it).c_str() << " no new xml file is parsed" << std::endl;
+ RES_MESSAGE("Resource file " << *_path_resources_it << " does not exist");
return _resourcesList;
}
if (to_parse)
{
_resourcesList.clear();
+ AddDefaultResourceInCatalog();
// On parse tous les fichiers
for(_path_resources_it = _path_resources.begin(); _path_resources_it != _path_resources.end(); ++_path_resources_it)
{
for (MapOfParserResourcesType_it i = _resourcesList_tmp.begin(); i != _resourcesList_tmp.end(); ++i)
{
MapOfParserResourcesType_it j = _resourcesList.find(i->first);
- if (j == _resourcesList.end())
+ if (i->second.HostName == "localhost" || i->second.HostName == Kernel_Utils::GetHostname())
{
- _resourcesList[i->first] = i->second;
+ RES_MESSAGE("Resource " << i->first << " is not added because it is the same "
+ "machine as default local resource \"" << DEFAULT_RESOURCE_NAME << "\"");
+ }
+ else if (j != _resourcesList.end())
+ {
+ cerr << "ParseXmlFiles Warning, two resources with the same name were found, "
+ "taking the first declaration : " << i->first << endl;
}
else
{
- std::cerr << "ParseXmlFiles Warning, two resources with the same name were found, taking the first declaration : " << i->first << std::endl;
+ _resourcesList[i->first] = i->second;
}
}
}
throw ResourcesException(error);
}
}
+
+void ResourcesManager_cpp::AddDefaultResourceInCatalog()
+{
+ ParserResourcesType resource;
+ resource.Clear();
+ resource.Name = DEFAULT_RESOURCE_NAME;
+ // We can't use "localhost" for parameter hostname because the containers are registered in the
+ // naming service with the real hostname, not "localhost"
+ resource.HostName = Kernel_Utils::GetHostname();
+ resource.DataForSort._Name = DEFAULT_RESOURCE_NAME;
+ resource.Protocol = sh;
+ resource.Batch = ssh_batch;
+ if (getenv("HOME") != NULL && getenv("APPLI") != NULL)
+ {
+ resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI");
+ }
+ resource.working_directory = "/tmp/salome_localres_workdir";
+ _resourcesList[resource.Name] = resource;
+}
std::string Find(const std::string& policy,
const std::vector<std::string>& listOfResources);
- void AddResourceInCatalog (const ParserResourcesType & new_resource) throw(ResourcesException);
+ void AddResourceInCatalog (const ParserResourcesType & new_resource);
void DeleteResourceInCatalog(const char * name);
void KeepOnlyResourcesWithComponent(std::vector<std::string>& resources,
const std::vector<std::string>& componentList);
+ /**
+ * Add the default local resource in the catalog
+ */
+ void AddDefaultResourceInCatalog();
+
//! will contain the path to the ressources catalog
std::list<std::string> _path_resources;
std::list<std::string>::iterator _path_resources_it;
//! contain the time where resourcesList was created
time_t _lasttime;
+
+ //! the name of the default local resource
+ static const std::string DEFAULT_RESOURCE_NAME;
};
#endif // __RESOURCESMANAGER_HXX__
// Empty private elements
_resources_list.clear();
- //default resources
- _resource.Clear();
- _resource.HostName = Kernel_Utils::GetHostname();
- _resource.Name = Kernel_Utils::GetHostname();
- _resource.DataForSort._Name = Kernel_Utils::GetHostname();
- _resources_list[Kernel_Utils::GetHostname()] = _resource;
-
// Get the document root node
xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
{
switch (protocol)
{
+ case sh:
+ return "sh";
case rsh:
return "rsh";
case ssh:
AccessProtocolType ParserResourcesType::stringToProtocol(const std::string & protocolStr)
{
- if (protocolStr == "rsh")
+ if (protocolStr == "sh")
+ return sh;
+ else if (protocolStr == "rsh")
return rsh;
else if (protocolStr == "ssh")
return ssh;
#pragma warning(disable:4251) // Warning DLL Interface ...
#endif
-enum AccessProtocolType {rsh, ssh, srun, pbsdsh, blaunch};
+enum AccessProtocolType {sh, rsh, ssh, srun, pbsdsh, blaunch};
enum AccessModeType {interactive, batch};
#define MAX_SIZE_FOR_HOSTNAME 256;
+using namespace std;
+
const char *SALOME_ResourcesManager::_ResourcesManagerNameInNS = "/ResourcesManager";
//=============================================================================
Engines::ResourceDefinition*
SALOME_ResourcesManager::GetResourceDefinition(const char * name)
{
- 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->protocol = ParserResourcesType::protocolToString(resource.Protocol).c_str();
- p_ptr->iprotocol = ParserResourcesType::protocolToString(resource.ClusterInternalProtocol).c_str();
- 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());
- for(unsigned int i=0;i<resource.ComponentsList.size();i++)
- p_ptr->componentList[i] = CORBA::string_dup(resource.ComponentsList[i].c_str());
- p_ptr->OS = CORBA::string_dup(resource.OS.c_str());
- p_ptr->mem_mb = resource.DataForSort._memInMB;
- p_ptr->cpu_clock = resource.DataForSort._CPUFreqMHz;
- p_ptr->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode;
- p_ptr->nb_node = resource.DataForSort._nbOfNodes;
- p_ptr->is_cluster_head = resource.is_cluster_head;
- p_ptr->working_directory = CORBA::string_dup(resource.working_directory.c_str());
-
- if( resource.mpi == lam )
- p_ptr->mpiImpl = "lam";
- else if( resource.mpi == mpich1 )
- p_ptr->mpiImpl = "mpich1";
- else if( resource.mpi == mpich2 )
- p_ptr->mpiImpl = "mpich2";
- else if( resource.mpi == openmpi )
- p_ptr->mpiImpl = "openmpi";
- else if( resource.mpi == ompi )
- p_ptr->mpiImpl = "ompi";
- else if( resource.mpi == slurmmpi )
- p_ptr->mpiImpl = "slurmmpi";
- else if( resource.mpi == prun )
- p_ptr->mpiImpl = "prun";
-
- if( resource.Batch == pbs )
- p_ptr->batch = "pbs";
- else if( resource.Batch == lsf )
- p_ptr->batch = "lsf";
- else if( resource.Batch == sge )
- p_ptr->batch = "sge";
- else if( resource.Batch == ccc )
- p_ptr->batch = "ccc";
- else if( resource.Batch == slurm )
- p_ptr->batch = "slurm";
- else if( resource.Batch == ssh_batch )
- p_ptr->batch = "ssh";
- else if( resource.Batch == ll )
- p_ptr->batch = "ll";
- else if( resource.Batch == vishnu )
- p_ptr->batch = "vishnu";
+ Engines::ResourceDefinition * p_ptr = NULL;
+ try {
+ ParserResourcesType resource = _rm.GetResourcesDescr(name);
+ 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->protocol = ParserResourcesType::protocolToString(resource.Protocol).c_str();
+ p_ptr->iprotocol = ParserResourcesType::protocolToString(resource.ClusterInternalProtocol).c_str();
+ 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());
+ for(unsigned int i=0;i<resource.ComponentsList.size();i++)
+ p_ptr->componentList[i] = CORBA::string_dup(resource.ComponentsList[i].c_str());
+ p_ptr->OS = CORBA::string_dup(resource.OS.c_str());
+ p_ptr->mem_mb = resource.DataForSort._memInMB;
+ p_ptr->cpu_clock = resource.DataForSort._CPUFreqMHz;
+ p_ptr->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode;
+ p_ptr->nb_node = resource.DataForSort._nbOfNodes;
+ p_ptr->is_cluster_head = resource.is_cluster_head;
+ p_ptr->working_directory = CORBA::string_dup(resource.working_directory.c_str());
+
+ if( resource.mpi == lam )
+ p_ptr->mpiImpl = "lam";
+ else if( resource.mpi == mpich1 )
+ p_ptr->mpiImpl = "mpich1";
+ else if( resource.mpi == mpich2 )
+ p_ptr->mpiImpl = "mpich2";
+ else if( resource.mpi == openmpi )
+ p_ptr->mpiImpl = "openmpi";
+ else if( resource.mpi == ompi )
+ p_ptr->mpiImpl = "ompi";
+ else if( resource.mpi == slurmmpi )
+ p_ptr->mpiImpl = "slurmmpi";
+ else if( resource.mpi == prun )
+ p_ptr->mpiImpl = "prun";
+
+ if( resource.Batch == pbs )
+ p_ptr->batch = "pbs";
+ else if( resource.Batch == lsf )
+ p_ptr->batch = "lsf";
+ else if( resource.Batch == sge )
+ p_ptr->batch = "sge";
+ else if( resource.Batch == ccc )
+ p_ptr->batch = "ccc";
+ else if( resource.Batch == slurm )
+ p_ptr->batch = "slurm";
+ else if( resource.Batch == ssh_batch )
+ p_ptr->batch = "ssh";
+ else if( resource.Batch == ll )
+ p_ptr->batch = "ll";
+ else if( resource.Batch == vishnu )
+ p_ptr->batch = "vishnu";
+ } catch (const exception & ex) {
+ INFOS("Caught exception in GetResourceDefinition: " << ex.what());
+ THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::BAD_PARAM);
+ }
return p_ptr;
}
for (CORBA::ULong i = 0; i < new_resource.componentList.length(); i++)
resource.ComponentsList.push_back(new_resource.componentList[i].in());
- _rm.AddResourceInCatalog(resource);
+ try
+ {
+ _rm.AddResourceInCatalog(resource);
+ }
+ catch (const SALOME_Exception & e)
+ {
+ INFOS("Error in AddResourceInCatalog: " << e);
+ THROW_SALOME_CORBA_EXCEPTION(e.what(), SALOME::BAD_PARAM);
+ }
if (write)
{
CORBA::Boolean write,
const char * xml_file)
{
- _rm.DeleteResourceInCatalog(resource_name);
+ try
+ {
+ _rm.DeleteResourceInCatalog(resource_name);
+ }
+ catch (const SALOME_Exception & e)
+ {
+ INFOS("Error in DeleteResourceInCatalog: " << e);
+ THROW_SALOME_CORBA_EXCEPTION(e.what(), SALOME::BAD_PARAM);
+ }
+
if (write)
{
_rm.WriteInXmlFile(std::string(xml_file));