-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
#include "ResourcesManager.hxx"
#include <Basics_Utils.hxx>
#include <fstream>
#define MAX_SIZE_FOR_HOSTNAME 256;
-using namespace std;
-
static LoadRateManagerFirst first;
static LoadRateManagerCycl cycl;
static LoadRateManagerAltCycl altcycl;
{
_path_resources.push_back(xmlFilePath);
#if defined(_DEBUG_) || defined(_DEBUG)
- cerr << "ResourcesManager_cpp constructor" << endl;
+ std::cerr << "ResourcesManager_cpp constructor" << std::endl;
#endif
_resourceManagerMap["first"]=&first;
_resourceManagerMap["cycl"]=&cycl;
else
{
if(!getenv("KERNEL_ROOT_DIR"))
- throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!! -> cannot load a CatalogResources.xml");
+ throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!! -> cannot load a CatalogResources.xml");
default_file = getenv("KERNEL_ROOT_DIR");
default_file += "/share/salome/resources/kernel/CatalogResources.xml";
_path_resources.push_back(default_file);
for (unsigned int i=0; i < sz; i++)
{
if (_resourcesList.find(params.resourceList[i]) != _resourcesList.end())
- local_resourcesList[params.resourceList[i]] = _resourcesList[params.resourceList[i]];
+ local_resourcesList[params.resourceList[i]] = _resourcesList[params.resourceList[i]];
}
}
for (; iter != _resourcesList.end(); iter++)
{
if ((*iter).second.HostName == hostname)
- vec.push_back((*iter).first);
+ vec.push_back((*iter).first);
}
}
ResourceDataToSort::_CPUFreqMHzWanted = params.cpu_clock;
ResourceDataToSort::_memInMBWanted = params.mem_mb;
// --- end of set
-
+
// Sort
std::list<ResourceDataToSort> li;
std::vector<std::string>::iterator iter = vec.begin();
li.sort();
vec.clear();
- for (list<ResourceDataToSort>::iterator iter2 = li.begin(); iter2 != li.end(); iter2++)
+ for (std::list<ResourceDataToSort>::iterator iter2 = li.begin(); iter2 != li.end(); iter2++)
vec.push_back((*iter2)._Name);
}
// Send an exception if return list is empty...
if (vec.size() == 0)
{
- std::string error("[GetFittingResources] ResourcesManager doesn't find any resource that feets to your parameters");
+ std::string error("[GetFittingResources] ResourcesManager doesn't find any resource that fits to your parameters");
throw ResourcesException(error);
}
//=============================================================================
/*!
- * add an entry in the ressources catalog xml file.
- * Return 0 if OK (KERNEL found in new resources components) else throw exception
+ * add an entry in the ressources catalog xml file.
*/
//=============================================================================
-int
-ResourcesManager_cpp::AddResourceInCatalog(const resourceParams& paramsOfNewResources,
- const vector<string>& componentsOnNewResources,
- const char *userName,
- AccessModeType mode,
- AccessProtocolType prot,
- AccessProtocolType iprot) throw(ResourcesException)
+void
+ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource) throw(ResourcesException)
{
- vector<string>::const_iterator iter = find(componentsOnNewResources.begin(),
- componentsOnNewResources.end(),
- "KERNEL");
-
- if (iter != componentsOnNewResources.end())
- {
- ParserResourcesType newElt;
- newElt.DataForSort._Name = paramsOfNewResources.name;
- newElt.HostName = paramsOfNewResources.hostname;
- newElt.Protocol = prot;
- newElt.ClusterInternalProtocol = iprot;
- newElt.Mode = mode;
- newElt.UserName = userName;
- newElt.ComponentsList = componentsOnNewResources;
- newElt.OS = paramsOfNewResources.OS;
- newElt.DataForSort._memInMB = paramsOfNewResources.mem_mb;
- newElt.DataForSort._CPUFreqMHz = paramsOfNewResources.cpu_clock;
- newElt.DataForSort._nbOfNodes = paramsOfNewResources.nb_node;
- newElt.DataForSort._nbOfProcPerNode =
- paramsOfNewResources.nb_proc_per_node;
- _resourcesList[newElt.DataForSort._Name] = newElt;
- return 0;
- }
- else
- throw ResourcesException("KERNEL is not present in this resource");
+ // TODO - Add minimal check
+ _resourcesList[new_resource.Name] = new_resource;
}
//=============================================================================
void ResourcesManager_cpp::DeleteResourceInCatalog(const char * name)
{
- _resourcesList.erase(name);
+ MapOfParserResourcesType_it it = _resourcesList.find(name);
+ if (it != _resourcesList.end())
+ _resourcesList.erase(name);
+ else
+ RES_INFOS("You try to delete a resource that does not exist... : " << name);
}
//=============================================================================
*/
//=============================================================================
-void ResourcesManager_cpp::WriteInXmlFile(std::string & xml_file)
+void ResourcesManager_cpp::WriteInXmlFile(std::string xml_file)
{
RES_MESSAGE("WriteInXmlFile : start");
+ if (xml_file == "")
+ {
+ _path_resources_it = _path_resources.begin();
+ xml_file = *_path_resources_it;
+ }
+
const char* aFilePath = xml_file.c_str();
FILE* aFile = fopen(aFilePath, "w");
handler->PrepareDocToXmlFile(aDoc);
delete handler;
- int isOk = xmlSaveFile(aFilePath, aDoc);
+ int isOk = xmlSaveFormatFile(aFilePath, aDoc, 1);
if (!isOk)
std::cerr << "Error while XML file saving : " << xml_file << std::endl;
MapOfParserResourcesType _resourcesList_tmp;
MapOfParserResourcesType _resourcesBatchList_tmp;
SALOME_ResourcesCatalog_Handler* handler =
- new SALOME_ResourcesCatalog_Handler(_resourcesList_tmp);
+ new SALOME_ResourcesCatalog_Handler(_resourcesList_tmp);
const char* aFilePath = (*_path_resources_it).c_str();
FILE* aFile = fopen(aFilePath, "r");
if (aFile != NULL)
{
- xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0);
- if (aDoc != NULL)
- {
- handler->ProcessXmlDocument(aDoc);
-
- // adding new resources to the file
- for (MapOfParserResourcesType_it i = _resourcesList_tmp.begin(); i != _resourcesList_tmp.end(); ++i)
- {
- MapOfParserResourcesType_it j = _resourcesList.find(i->first);
- if (j == _resourcesList.end())
- {
- _resourcesList[i->first] = i->second;
- }
- else
- {
- std::cerr << "ParseXmlFiles Warning, to resource with the same name was found, taking the first declaration : " << i->first << std::endl;
- }
- }
- }
- else
- std::cerr << "ResourcesManager_cpp: could not parse file " << aFilePath << std::endl;
- // Free the document
- xmlFreeDoc(aDoc);
- fclose(aFile);
+ xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0);
+ if (aDoc != NULL)
+ {
+ handler->ProcessXmlDocument(aDoc);
+
+ // adding new resources to the file
+ for (MapOfParserResourcesType_it i = _resourcesList_tmp.begin(); i != _resourcesList_tmp.end(); ++i)
+ {
+ MapOfParserResourcesType_it j = _resourcesList.find(i->first);
+ if (j == _resourcesList.end())
+ {
+ _resourcesList[i->first] = i->second;
+ }
+ else
+ {
+ std::cerr << "ParseXmlFiles Warning, two resources with the same name were found, taking the first declaration : " << i->first << std::endl;
+ }
+ }
+ }
+ else
+ std::cerr << "ResourcesManager_cpp: could not parse file " << aFilePath << std::endl;
+ // Free the document
+ xmlFreeDoc(aDoc);
+ fclose(aFile);
}
else
- std::cerr << "ResourcesManager_cpp: file " << aFilePath << " is not readable." << std::endl;
+ std::cerr << "ResourcesManager_cpp: file " << aFilePath << " is not readable." << std::endl;
delete handler;
}
return _resourcesList;
}
-string ResourcesManager_cpp::Find(const std::string& policy, const std::vector<std::string>& listOfResources)
+std::string ResourcesManager_cpp::Find(const std::string& policy, const std::vector<std::string>& listOfResources)
{
if(_resourceManagerMap.count(policy)==0)
return _resourceManagerMap[""]->Find(listOfResources, _resourcesList);
// a computer list is given : take only resources with OS on those computers
std::vector<std::string> vec_tmp = resources;
resources.clear();
- vector<string>::iterator iter = vec_tmp.begin();
+ std::vector<std::string>::iterator iter = vec_tmp.begin();
for (; iter != vec_tmp.end(); iter++)
{
MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter);
if(it != _resourcesList.end())
- if ( (*it).second.OS == OS)
- resources.push_back(*iter);
+ if ( (*it).second.OS == OS)
+ resources.push_back(*iter);
}
}
}
//=============================================================================
void
ResourcesManager_cpp::KeepOnlyResourcesWithComponent(std::vector<std::string>& resources,
- const vector<string>& componentList)
+ const std::vector<std::string>& componentList)
{
std::vector<std::string>::iterator iter = resources.begin();
for (; iter != resources.end(); iter++)
{
MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter);
- const vector<string>& mapOfComponentsOfCurrentHost = (*it).second.ComponentsList;
+ const std::vector<std::string>& mapOfComponentsOfCurrentHost = (*it).second.ComponentsList;
bool erasedHost = false;
if( mapOfComponentsOfCurrentHost.size() > 0 )
{
for(unsigned int i=0; i<componentList.size(); i++)
{
- const char* compoi = componentList[i].c_str();
- vector<string>::const_iterator itt = find(mapOfComponentsOfCurrentHost.begin(),
- mapOfComponentsOfCurrentHost.end(),
- compoi);
- if (itt == mapOfComponentsOfCurrentHost.end())
- {
- erasedHost = true;
- break;
- }
+ const char* compoi = componentList[i].c_str();
+ std::vector<std::string>::const_iterator itt = find(mapOfComponentsOfCurrentHost.begin(),
+ mapOfComponentsOfCurrentHost.end(),
+ compoi);
+ if (itt == mapOfComponentsOfCurrentHost.end())
+ {
+ erasedHost = true;
+ break;
+ }
}
}
if(erasedHost)