#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);
if (vec.size() == 0)
vec = vec_save;
+ // Step 7 : Filter on possible usage
+ vector<string> prev_list(vec);
+ vec.clear();
+ for (vector<string>::iterator iter = prev_list.begin() ; iter != prev_list.end() ; iter++)
+ {
+ MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter);
+ if (it != _resourcesList.end() &&
+ (!params.can_launch_batch_jobs || it->second.can_launch_batch_jobs) &&
+ (!params.can_run_containers || it->second.can_run_containers))
+ vec.push_back(*iter);
+ }
+
// End
// Send an exception if return list is empty...
if (vec.size() == 0)
//=============================================================================
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.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";
+ resource.can_launch_batch_jobs = true;
+ resource.can_run_containers = true;
+ _resourcesList[resource.Name] = resource;
+}