../Registry/libRegistry.la \
../Notification/libSalomeNotification.la \
../ResourcesManager/libSalomeResourcesManager.la \
+ ../ResourcesManager/libResourcesManager.la \
../NamingService/libSalomeNS.la \
../Utils/libOpUtil.la \
../SALOMELocalTrace/libSALOMELocalTrace.la \
MESSAGE("SALOME_ContainerManager::StartContainer " <<
possibleComputers.length());
+ vector<string> lm;
+ for(int i=0;i<possibleComputers.length();i++)
+ lm.push_back(string(possibleComputers[i]));
+
string theMachine;
try{
switch(policy){
case Engines::P_FIRST:
- theMachine=_ResManager->FindFirst(possibleComputers);
+ theMachine=_ResManager->GetImpl()->FindFirst(lm);
break;
case Engines::P_CYCL:
- theMachine=_ResManager->FindNext(possibleComputers);
+ theMachine=_ResManager->GetImpl()->FindNext(lm);
break;
case Engines::P_BEST:
- theMachine=_ResManager->FindBest(possibleComputers);
+ theMachine=_ResManager->GetImpl()->FindBest(lm);
break;
}
}
else
{
- const ParserResourcesType& resInfo = _ResManager->GetResourcesList(machine);
+ const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine);
if (params.isMPI)
{
_TmpFileName = BuildTemporaryFileName();
ofstream tempOutputFile;
tempOutputFile.open(_TmpFileName.c_str(), ofstream::out );
- const ParserResourcesType& resInfo = _ResManager->GetResourcesList(machine);
+ const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine);
tempOutputFile << "#! /bin/sh" << endl;
// --- set env vars
}
}
string msg;
- if( ((cmax-cmin) <= 2) && (fmax == 10/nbpmax) && !error ){
+ if( ((cmax-cmin) <= 1) && (fmax == 10/nbpmax) && !error ){
if(bestImplemented)
msg = "TEST OK";
else
# Libraries targets
# ===============================================================
#
-lib_LTLIBRARIES = libSalomeResourcesManager.la
+lib_LTLIBRARIES = libResourcesManager.la libSalomeResourcesManager.la
libSalomeResourcesManager_la_SOURCES =\
- SALOME_ResourcesCatalog_Parser.cxx \
- SALOME_ResourcesCatalog_Handler.cxx \
- SALOME_LoadRateManager.cxx \
SALOME_ResourcesManager.cxx
libSalomeResourcesManager_la_CPPFLAGS =\
$(COMMON_CPPFLAGS)
-
libSalomeResourcesManager_la_LDFLAGS = -no-undefined -version-info=0:0:0
libSalomeResourcesManager_la_LIBADD =\
- $(COMMON_LIBS)
+ $(COMMON_LIBS) libResourcesManager.la
+
+libResourcesManager_la_SOURCES =\
+ SALOME_ResourcesCatalog_Parser.cxx \
+ SALOME_ResourcesCatalog_Handler.cxx \
+ SALOME_LoadRateManager.cxx \
+ ResourcesManager.cxx
+
+libResourcesManager_la_CPPFLAGS =\
+ @LIBXML_INCLUDES@
+
+libResourcesManager_la_LDFLAGS = -no-undefined -version-info=0:0:0
+libResourcesManager_la_LIBADD =\
+ @LIBXML_LIBS@
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#include "ResourcesManager.hxx"
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <string.h>
+#include <map>
+#include <list>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <libxml/parser.h>
+
+#define MAX_SIZE_FOR_HOSTNAME 256;
+
+using namespace std;
+
+//=============================================================================
+/*!
+ * just for test
+ */
+//=============================================================================
+
+ResourcesManager_cpp::
+ResourcesManager_cpp(const char *xmlFilePath) :
+ _path_resources(xmlFilePath)
+{
+ cerr << "ResourcesManager_cpp constructor" << endl;
+}
+
+//=============================================================================
+/*!
+ * Standard constructor, parse resource file.
+ * - if ${APPLI} exists in environment,
+ * look for ${HOME}/${APPLI}/CatalogResources.xml
+ * - else look for default:
+ * ${KERNEL_ROOT_DIR}/share/salome/resources/kernel/CatalogResources.xml
+ * - parse XML resource file.
+ */
+//=============================================================================
+
+ResourcesManager_cpp::ResourcesManager_cpp()
+{
+ cerr << "ResourcesManager_cpp constructor" << endl;
+ _isAppliSalomeDefined = (getenv("APPLI") != 0);
+
+ if (_isAppliSalomeDefined)
+ {
+ _path_resources = getenv("HOME");
+ _path_resources += "/";
+ _path_resources += getenv("APPLI");
+ _path_resources += "/CatalogResources.xml";
+ }
+
+ else
+ {
+ _path_resources = getenv("KERNEL_ROOT_DIR");
+ _path_resources += "/share/salome/resources/kernel/CatalogResources.xml";
+ }
+
+ ParseXmlFile();
+ cerr << "ResourcesManager_cpp constructor end";
+}
+
+//=============================================================================
+/*!
+ * Standard Destructor
+ */
+//=============================================================================
+
+ResourcesManager_cpp::~ResourcesManager_cpp()
+{
+ cerr << "ResourcesManager_cpp destructor" << endl;
+}
+
+//=============================================================================
+/*!
+ * get the list of name of ressources fitting for the specified module.
+ * If hostname specified, check it is local or known in resources catalog.
+ *
+ * Else
+ * - select first machines with corresponding OS (all machines if
+ * parameter OS empty),
+ * - then select the sublist of machines on witch the module is known
+ * (if the result is empty, that probably means that the inventory of
+ * modules is probably not done, so give complete list from previous step)
+ */
+//=============================================================================
+
+std::vector<std::string>
+ResourcesManager_cpp::GetFittingResources(const machineParams& params,
+ const std::vector<std::string>& componentList) throw(ResourcesException)
+{
+// cerr << "ResourcesManager_cpp::GetFittingResources" << endl;
+ vector <std::string> vec;
+
+ ParseXmlFile();
+
+ const char *hostname = params.hostname.c_str();
+ cerr << "GetFittingResources " << hostname << " " << GetHostname().c_str() << endl;
+
+ if (hostname[0] != '\0'){
+ // cerr << "ResourcesManager_cpp::GetFittingResources : hostname specified" << endl;
+
+ if ( strcmp(hostname, "localhost") == 0 ||
+ strcmp(hostname, GetHostname().c_str()) == 0 )
+ {
+ // cerr << "ResourcesManager_cpp::GetFittingResources : localhost" << endl;
+ vec.push_back(GetHostname().c_str());
+ // cerr << "ResourcesManager_cpp::GetFittingResources : " << vec.size() << endl;
+ }
+
+ else if (_resourcesList.find(hostname) != _resourcesList.end())
+ {
+ // --- params.hostname is in the list of resources so return it.
+ vec.push_back(hostname);
+ }
+
+ else
+ {
+ // Cas d'un cluster: nombre de noeuds > 1
+ int cpt=0;
+ for (map<string, ParserResourcesType>::const_iterator iter = _resourcesList.begin(); iter != _resourcesList.end(); iter++){
+ if( (*iter).second.DataForSort._nbOfNodes > 1 ){
+ if( strncmp(hostname,(*iter).first.c_str(),strlen(hostname)) == 0 ){
+ vec.push_back((*iter).first.c_str());
+ //cerr << "SALOME_ResourcesManager_cpp::GetFittingResources vector["
+ // << cpt << "] = " << (*iter).first.c_str() << endl ;
+ cpt++;
+ }
+ }
+ }
+ if(cpt==0){
+ // --- user specified an unknown hostame so notify him.
+ cerr << "ResourcesManager_cpp::GetFittingResources : SALOME_Exception" << endl;
+ throw ResourcesException("unknown host");
+ }
+ }
+ }
+
+ else{
+ // --- Search for available resources sorted by priority
+ SelectOnlyResourcesWithOS(vec, params.OS.c_str());
+
+ KeepOnlyResourcesWithModule(vec, componentList);
+
+ if (vec.size() == 0)
+ SelectOnlyResourcesWithOS(vec, params.OS.c_str());
+
+ // --- set wanted parameters
+ ResourceDataToSort::_nbOfNodesWanted = params.nb_node;
+
+ ResourceDataToSort::_nbOfProcPerNodeWanted = params.nb_proc_per_node;
+
+ ResourceDataToSort::_CPUFreqMHzWanted = params.cpu_clock;
+
+ ResourceDataToSort::_memInMBWanted = params.mem_mb;
+
+ // --- end of set
+
+ list<ResourceDataToSort> li;
+
+ for (vector<string>::iterator iter = vec.begin();
+ iter != vec.end();
+ iter++)
+ li.push_back(_resourcesList[(*iter)].DataForSort);
+
+ li.sort();
+
+ unsigned int i = 0;
+
+ for (list<ResourceDataToSort>::iterator iter2 = li.begin();
+ iter2 != li.end();
+ iter2++)
+ vec[i++] = (*iter2)._hostName;
+ }
+
+ return vec;
+
+}
+
+//=============================================================================
+/*!
+ * add an entry in the ressources catalog xml file.
+ * Return 0 if OK (KERNEL found in new resources modules) else throw exception
+ */
+//=============================================================================
+
+int
+ResourcesManager_cpp::
+AddResourceInCatalog(const machineParams& paramsOfNewResources,
+ const vector<string>& modulesOnNewResources,
+ const char *alias,
+ const char *userName,
+ AccessModeType mode,
+ AccessProtocolType prot)
+throw(ResourcesException)
+{
+ vector<string>::const_iterator iter = find(modulesOnNewResources.begin(),
+ modulesOnNewResources.end(),
+ "KERNEL");
+
+ if (iter != modulesOnNewResources.end())
+ {
+ ParserResourcesType newElt;
+ newElt.DataForSort._hostName = paramsOfNewResources.hostname;
+ newElt.Alias = alias;
+ newElt.Protocol = prot;
+ newElt.Mode = mode;
+ newElt.UserName = userName;
+ newElt.ModulesList = modulesOnNewResources;
+ 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._hostName] = newElt;
+ return 0;
+ }
+
+ else
+ throw ResourcesException("KERNEL is not present in this resource");
+}
+
+//=============================================================================
+/*!
+ * Deletes a resource from the catalog
+ */
+//=============================================================================
+
+void ResourcesManager_cpp::DeleteResourceInCatalog(const char *hostname)
+{
+ _resourcesList.erase(hostname);
+}
+
+//=============================================================================
+/*!
+ * write the current data in memory in file.
+ */
+//=============================================================================
+
+void ResourcesManager_cpp::WriteInXmlFile()
+{
+ const char* aFilePath = _path_resources.c_str();
+
+ FILE* aFile = fopen(aFilePath, "w");
+
+ if (aFile == NULL)
+ {
+ cerr << "Error opening file !" << endl;
+ return;
+ }
+
+ xmlDocPtr aDoc = xmlNewDoc(BAD_CAST "1.0");
+ xmlNewDocComment(aDoc, BAD_CAST "ResourcesCatalog");
+
+ SALOME_ResourcesCatalog_Handler* handler =
+ new SALOME_ResourcesCatalog_Handler(_resourcesList);
+ handler->PrepareDocToXmlFile(aDoc);
+ delete handler;
+
+ int isOk = xmlSaveFile(aFilePath, aDoc);
+
+ if (!isOk)
+ cerr << "Error while XML file saving." << endl;
+
+ // Free the document
+ xmlFreeDoc(aDoc);
+
+ fclose(aFile);
+
+ cerr << "WRITING DONE!" << endl;
+}
+
+//=============================================================================
+/*!
+ * parse the data type catalog
+ */
+//=============================================================================
+
+const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFile()
+{
+ SALOME_ResourcesCatalog_Handler* handler =
+ new SALOME_ResourcesCatalog_Handler(_resourcesList);
+
+ const char* aFilePath = _path_resources.c_str();
+ FILE* aFile = fopen(aFilePath, "r");
+
+ if (aFile != NULL)
+ {
+ xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0);
+
+ if (aDoc != NULL)
+ handler->ProcessXmlDocument(aDoc);
+ else
+ cerr << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl;
+
+ // Free the document
+ xmlFreeDoc(aDoc);
+
+ fclose(aFile);
+ }
+ else
+ cerr << "ResourcesManager_cpp: file "<<aFilePath<<" is not readable." << endl;
+
+ delete handler;
+
+ return _resourcesList;
+}
+
+//=============================================================================
+/*!
+ * consult the content of the list
+ */
+//=============================================================================
+
+const MapOfParserResourcesType& ResourcesManager_cpp::GetList() const
+ {
+ return _resourcesList;
+ }
+
+
+//=============================================================================
+/*!
+ * dynamically obtains the first machines
+ */
+//=============================================================================
+
+string ResourcesManager_cpp::FindFirst(const std::vector<std::string>& listOfMachines)
+{
+ return _dynamicResourcesSelecter.FindFirst(listOfMachines);
+}
+
+//=============================================================================
+/*!
+ * dynamically obtains the best machines
+ */
+//=============================================================================
+
+string ResourcesManager_cpp::FindNext(const std::vector<std::string>& listOfMachines)
+{
+ return _dynamicResourcesSelecter.FindNext(listOfMachines,_resourcesList);
+}
+//=============================================================================
+/*!
+ * dynamically obtains the best machines
+ */
+//=============================================================================
+
+string ResourcesManager_cpp::FindBest(const std::vector<std::string>& listOfMachines)
+{
+ return _dynamicResourcesSelecter.FindBest(listOfMachines);
+}
+
+//=============================================================================
+/*!
+ * Gives a sublist of machines with matching OS.
+ * If parameter OS is empty, gives the complete list of machines
+ */
+//=============================================================================
+
+// Warning need an updated parsed list : _resourcesList
+void ResourcesManager_cpp::SelectOnlyResourcesWithOS( vector<string>& hosts, const char *OS) const
+throw(ResourcesException)
+{
+ string base(OS);
+
+ for (map<string, ParserResourcesType>::const_iterator iter =
+ _resourcesList.begin();
+ iter != _resourcesList.end();
+ iter++)
+ {
+ if ( (*iter).second.OS == base || base.size() == 0)
+ hosts.push_back((*iter).first);
+ }
+}
+
+
+//=============================================================================
+/*!
+ * Gives a sublist of machines on which the module is known.
+ */
+//=============================================================================
+
+//Warning need an updated parsed list : _resourcesList
+void ResourcesManager_cpp::KeepOnlyResourcesWithModule( vector<string>& hosts, const vector<string>& componentList) const
+throw(ResourcesException)
+{
+ for (vector<string>::iterator iter = hosts.begin(); iter != hosts.end();)
+ {
+ MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter);
+ const vector<string>& mapOfModulesOfCurrentHost = (((*it).second).ModulesList);
+
+ bool erasedHost = false;
+ if( mapOfModulesOfCurrentHost.size() > 0 ){
+ for(int i=0;i<componentList.size();i++){
+ const char* compoi = componentList[i].c_str();
+ vector<string>::const_iterator itt = find(mapOfModulesOfCurrentHost.begin(),
+ mapOfModulesOfCurrentHost.end(),
+ compoi);
+// componentList[i]);
+ if (itt == mapOfModulesOfCurrentHost.end()){
+ erasedHost = true;
+ break;
+ }
+ }
+ }
+ if(erasedHost)
+ hosts.erase(iter);
+ else
+ iter++;
+ }
+}
+
+
+ParserResourcesType ResourcesManager_cpp::GetResourcesList(const std::string& machine)
+{
+ return _resourcesList[machine];
+}
+
+std::string ResourcesManager_cpp::GetHostname()
+{
+ int ls = 100, r = 1;
+ char *s;
+
+ while (ls < 10000 && r) {
+ ls *= 2;
+ s = new char[ls];
+ r = gethostname(s, ls-1);
+ switch (r)
+ {
+ case 0:
+ break;
+ default:
+#ifdef EINVAL
+ case EINVAL:
+#endif
+#ifdef ENAMETOOLONG
+ case ENAMETOOLONG:
+#endif
+ delete [] s;
+ continue;
+ }
+ }
+
+ if (r != 0) {
+ s = new char[50];
+ strcpy(s, "localhost");
+ }
+
+ // remove all after '.'
+ char *aDot = (strchr(s,'.'));
+ if (aDot) aDot[0] = '\0';
+
+ string p = s;
+ delete [] s;
+ return p;
+}
+
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#ifndef __RESOURCESMANAGER_HXX__
+#define __RESOURCESMANAGER_HXX__
+
+#include <string>
+#include <fstream>
+#include <vector>
+#include "SALOME_ResourcesCatalog_Parser.hxx"
+#include "SALOME_ResourcesCatalog_Handler.hxx"
+#include "SALOME_LoadRateManager.hxx"
+
+// --- WARNING ---
+// The call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done
+// in a critical section to be sure to be clean.
+// Only one thread should use the SALOME_ResourcesManager class in a SALOME
+// session.
+
+struct machineParams{
+ std::string hostname;
+ std::string OS;
+ unsigned int nb_node;
+ unsigned int nb_proc_per_node;
+ unsigned int cpu_clock;
+ unsigned int mem_mb;
+};
+
+class ResourcesException
+{
+public:
+ const std::string msg;
+
+ ResourcesException(const std::string m) : msg(m) {}
+};
+
+class ResourcesManager_cpp
+ {
+
+ public:
+
+ ResourcesManager_cpp(const char *xmlFilePath);
+ ResourcesManager_cpp();
+
+ ~ResourcesManager_cpp();
+
+ std::vector<std::string>
+ GetFittingResources(const machineParams& params,
+ const std::vector<std::string>& componentList) throw(ResourcesException);
+
+ std::string FindFirst(const std::vector<std::string>& listOfMachines);
+ std::string FindNext(const std::vector<std::string>& listOfMachines);
+ std::string FindBest(const std::vector<std::string>& listOfMachines);
+
+ int AddResourceInCatalog
+ (const machineParams& paramsOfNewResources,
+ const std::vector<std::string>& modulesOnNewResources,
+ const char *alias,
+ const char *userName,
+ AccessModeType mode,
+ AccessProtocolType prot) throw(ResourcesException);
+
+ void DeleteResourceInCatalog(const char *hostname);
+
+ void WriteInXmlFile();
+
+ const MapOfParserResourcesType& ParseXmlFile();
+
+ const MapOfParserResourcesType& GetList() const;
+
+ ParserResourcesType GetResourcesList(const std::string& machine);
+
+ protected:
+
+ void SelectOnlyResourcesWithOS(std::vector<std::string>& hosts,
+ const char *OS) const
+ throw(ResourcesException);
+
+ void KeepOnlyResourcesWithModule(std::vector<std::string>& hosts,
+ const std::vector<std::string>& componentList) const
+ throw(ResourcesException);
+
+ //! will contain the path to the ressources catalog
+ std::string _path_resources;
+
+ //! will contain the informations on the data type catalog(after parsing)
+ MapOfParserResourcesType _resourcesList;
+
+ SALOME_LoadRateManager _dynamicResourcesSelecter;
+
+ //! different behaviour if $APPLI exists (SALOME Application)
+ bool _isAppliSalomeDefined;
+
+ std::string GetHostname();
+ };
+
+#endif // __RESOURCESMANAGER_HXX__
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "SALOME_LoadRateManager.hxx"
-#include "utilities.h"
#include <iostream>
#include <map>
using namespace std;
-string SALOME_LoadRateManager::FindFirst(const Engines::MachineList& hosts)
+string SALOME_LoadRateManager::FindFirst(const vector<string>& hosts)
{
- MESSAGE("SALOME_LoadRateManager::FindFirst " << hosts.length());
-
- if (hosts.length() == 0)
+ if (hosts.size() == 0)
return string("");
return string(hosts[0]);
}
-string SALOME_LoadRateManager::FindNext(const Engines::MachineList& hosts,MapOfParserResourcesType& resList,SALOME_NamingService *ns)
+string SALOME_LoadRateManager::FindNext(const vector<string>& hosts,MapOfParserResourcesType& resList)
{
- MESSAGE("SALOME_LoadRateManager::FindNext " << hosts.length());
- map<string, int> machines;
+ static int imachine = 0;
+ static int iproc = 0;
- if (hosts.length() == 0)
+ // if empty list return empty string
+ if (hosts.size() == 0)
return string("");
-
- for(int i=0;i<hosts.length();i++)
- machines[string(hosts[i])] = 0;
-
- ns->Change_Directory("/Containers");
- vector<string> vec = ns->list_directory_recurs();
- Engines::Container_var cont;
- for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++){
- try
- {
- CORBA::Object_var obj=ns->Resolve((*iter).c_str());
- cont=Engines::Container::_narrow(obj);
- }
- catch(CORBA::SystemException& ex)
- {
- MESSAGE("SALOME_LoadRateManager::FindNext CORBA::SystemException ignore it");
- continue;
- }
- if(!CORBA::is_nil(cont)){
- try
- {
- CORBA::String_var hostname = cont->getHostName();
- std::string mach=(const char*)hostname;
- machines[mach]++;
- }
- catch(CORBA::SystemException& ex)
- {
- MESSAGE("SALOME_LoadRateManager::FindNext CORBA::SystemException ignore it");
- continue;
- }
+ else{
+ ParserResourcesType resource = resList[string(hosts[imachine])];
+ int nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes;
+ if( nbproc <= 0) nbproc = 1;
+ if( iproc < nbproc ){
+ iproc++;
+ return string(hosts[imachine]);
}
- }
-
- int imin = 0;
- ParserResourcesType resource = resList[string(hosts[0])];
- int nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes;
- int min = machines[string(hosts[0])]/nbproc;
- for(int i=1;i<hosts.length();i++){
- resource = resList[string(hosts[i])];
- nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes;
- if( machines[string(hosts[i])]/nbproc < min ){
- imin = i;
- min = machines[string(hosts[i])]/nbproc;
+ else{
+ iproc = 1;
+ imachine++;
+ if(imachine == hosts.size())
+ imachine = 0;
+ return string(hosts[imachine]);
}
}
-
- return string(hosts[imin]);
}
-string SALOME_LoadRateManager::FindBest(const Engines::MachineList& hosts) throw (SALOME_Exception)
+string SALOME_LoadRateManager::FindBest(const vector<string>& hosts)
{
// for the moment then "maui" will be used for dynamic selection ...
- MESSAGE("SALOME_LoadRateManager::FindBest " << hosts.length());
- throw(SALOME_Exception(LOCALIZED("not yet implemented")));
- return string("");
+ return FindFirst(hosts);
}
#ifndef __SALOME_LOADRATEMANAGER_HXX__
#define __SALOME_LOADRATEMANAGER_HXX__
-#include <SALOMEconfig.h>
-#include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
#include <string>
#include "SALOME_ResourcesCatalog_Parser.hxx"
-#include "SALOME_NamingService.hxx"
#if defined RESOURCESMANAGER_EXPORTS
#if defined WIN32
{
public:
- std::string FindFirst(const Engines::MachineList& hosts);
- std::string FindNext(const Engines::MachineList& hosts,MapOfParserResourcesType& resList,SALOME_NamingService *ns);
- std::string FindBest(const Engines::MachineList& hosts) throw (SALOME_Exception);
+ std::string FindFirst(const std::vector<std::string>& hosts);
+ std::string FindNext(const std::vector<std::string>& hosts,MapOfParserResourcesType& resList);
+ std::string FindBest(const std::vector<std::string>& hosts);
};
#endif
#include "SALOME_ResourcesCatalog_Handler.hxx"
#include <iostream>
#include <map>
-#include "utilities.h"
using namespace std;
SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):
_resources_list(listOfResources)
{
- MESSAGE("SALOME_ResourcesCatalog_Handler creation");
+ cout << "SALOME_ResourcesCatalog_Handler creation" << endl;
//XML tags initialisation
test_machine = "machine";
test_resources = "resources";
SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
{
- // MESSAGE("SALOME_ResourcesCatalog_Handler destruction");
+ // cout << "SALOME_ResourcesCatalog_Handler destruction") << endl;
}
//=============================================================================
void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
{
- if (MYDEBUG) MESSAGE("Begin parse document");
+ if (MYDEBUG) cout << "Begin parse document" << endl;
// Empty private elements
_resources_list.clear();
iter != _resources_list.end();
iter++)
{
- SCRUTE((*iter).second.Alias);
- SCRUTE((*iter).second.UserName);
- SCRUTE((*iter).second.AppliPath);
- SCRUTE((*iter).second.OS);
- SCRUTE((*iter).second.Protocol);
- SCRUTE((*iter).second.Mode);
+ cout << (*iter).second.Alias << endl;
+ cout << (*iter).second.UserName << endl;
+ cout << (*iter).second.AppliPath << endl;
+ cout << (*iter).second.OS << endl;
+ cout << (*iter).second.Protocol << endl;
+ cout << (*iter).second.Mode << endl;
}
- MESSAGE("This is the end of document");
+ cout << "This is the end of document" << endl;
}
}
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "SALOME_ResourcesCatalog_Parser.hxx"
-#include "utilities.h"
#include <iostream>
+#include <sstream>
#define NULL_VALUE 0
//! Method used for debug
void ResourceDataToSort::Print() const
{
- SCRUTE(_nbOfNodes);
- SCRUTE(_nbOfProcPerNode);
- SCRUTE(_CPUFreqMHz);
- SCRUTE(_memInMB);
+ cout << _nbOfNodes << endl;
+ cout << _nbOfProcPerNode << endl;
+ cout << _CPUFreqMHz << endl;
+ cout << _memInMB << endl;
}
void ParserResourcesType::Print() const
for(int i=0;i<ModulesList.size();i++)
oss << "Module " << i+1 << " called : " << ModulesList[i] << endl;
- MESSAGE(oss.str());
+ cout << oss.str() << endl;
}
SALOME_ResourcesManager(CORBA::ORB_ptr orb,
PortableServer::POA_var poa,
SALOME_NamingService *ns,
- const char *xmlFilePath) :
- _path_resources(xmlFilePath)
+ const char *xmlFilePath) : _rm(xmlFilePath)
{
- MESSAGE("constructor");
+ MESSAGE("SALOME_ResourcesManager constructor");
_NS = ns;
_orb = CORBA::ORB::_duplicate(orb) ;
_poa = PortableServer::POA::_duplicate(poa) ;
Engines::SalomeLauncher::_narrow(obj);
_NS->Register(refContMan,_ResourcesManagerNameInNS);
-// _MpiStarted = false;
- MESSAGE("constructor end");
+ MESSAGE("SALOME_ResourcesManager constructor end");
}
//=============================================================================
SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb,
PortableServer::POA_var poa,
- SALOME_NamingService *ns)
+ SALOME_NamingService *ns) : _rm()
{
- MESSAGE("constructor");
+ MESSAGE("SALOME_ResourcesManager constructor");
_NS = ns;
_orb = CORBA::ORB::_duplicate(orb) ;
_poa = PortableServer::POA::_duplicate(poa) ;
Engines::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj);
_NS->Register(refContMan,_ResourcesManagerNameInNS);
- _isAppliSalomeDefined = (getenv("APPLI") != 0);
-// _MpiStarted = false;
-
- if (_isAppliSalomeDefined)
- {
- _path_resources = getenv("HOME");
- _path_resources += "/";
- _path_resources += getenv("APPLI");
- _path_resources += "/CatalogResources.xml";
- }
-
- else
- {
- _path_resources = getenv("KERNEL_ROOT_DIR");
- _path_resources += "/share/salome/resources/kernel/CatalogResources.xml";
- }
-
- ParseXmlFile();
- MESSAGE("constructor end");
+ MESSAGE("SALOME_ResourcesManager constructor end");
}
//=============================================================================
SALOME_ResourcesManager::~SALOME_ResourcesManager()
{
- MESSAGE("destructor");
+ MESSAGE("SALOME_ResourcesManager destructor");
}
Engines::MachineList *
SALOME_ResourcesManager::GetFittingResources(const Engines::MachineParameters& params,
const Engines::CompoList& componentList)
-//throw(SALOME_Exception)
{
// MESSAGE("ResourcesManager::GetFittingResources");
- vector <std::string> vec;
+ machineParams p;
+ p.hostname = params.hostname;
+ p.OS = params.OS;
+ 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;
+
+ vector<string> cl;
+ for(int i=0;i<componentList.length();i++)
+ cl.push_back(string(componentList[i]));
+
Engines::MachineList *ret=new Engines::MachineList;
try{
- // --- To be sure that we search in a correct list.
- ParseXmlFile();
-
- const char *hostname = (const char *)params.hostname;
- MESSAGE("GetFittingResources " << hostname << " " << GetHostname().c_str());
-
- if (hostname[0] != '\0')
- {
-// MESSAGE("ResourcesManager::GetFittingResources : hostname specified" );
-
- if ( strcmp(hostname, "localhost") == 0 ||
- strcmp(hostname, GetHostname().c_str()) == 0 )
- {
- // MESSAGE("ResourcesManager::GetFittingResources : localhost" );
- vec.push_back(GetHostname().c_str());
- // MESSAGE("ResourcesManager::GetFittingResources : " << vec.size());
- }
-
- else if (_resourcesList.find(hostname) != _resourcesList.end())
- {
- // --- params.hostname is in the list of resources so return it.
- vec.push_back(hostname);
- }
-
- else
- {
- // Cas d'un cluster: nombre de noeuds > 1
- int cpt=0;
- for (map<string, ParserResourcesType>::const_iterator iter = _resourcesList.begin(); iter != _resourcesList.end(); iter++){
- if( (*iter).second.DataForSort._nbOfNodes > 1 ){
- if( strncmp(hostname,(*iter).first.c_str(),strlen(hostname)) == 0 ){
- vec.push_back((*iter).first.c_str());
- //cout << "SALOME_ResourcesManager::GetFittingResources vector["
- // << cpt << "] = " << (*iter).first.c_str() << endl ;
- cpt++;
- }
- }
- }
- if(cpt==0){
- // --- user specified an unknown hostame so notify him.
- MESSAGE("ResourcesManager::GetFittingResources : SALOME_Exception");
- throw SALOME_Exception("unknown host");
- }
- }
- }
-
- else
- // --- Search for available resources sorted by priority
- {
- SelectOnlyResourcesWithOS(vec, params.OS);
-
- KeepOnlyResourcesWithModule(vec, componentList);
-
- if (vec.size() == 0)
- SelectOnlyResourcesWithOS(vec, params.OS);
-
- // --- set wanted parameters
- ResourceDataToSort::_nbOfNodesWanted = params.nb_node;
-
- ResourceDataToSort::_nbOfProcPerNodeWanted = params.nb_proc_per_node;
-
- ResourceDataToSort::_CPUFreqMHzWanted = params.cpu_clock;
-
- ResourceDataToSort::_memInMBWanted = params.mem_mb;
-
- // --- end of set
-
- list<ResourceDataToSort> li;
-
- for (vector<string>::iterator iter = vec.begin();
- iter != vec.end();
- iter++)
- li.push_back(_resourcesList[(*iter)].DataForSort);
-
- li.sort();
-
- unsigned int i = 0;
-
- for (list<ResourceDataToSort>::iterator iter2 = li.begin();
- iter2 != li.end();
- iter2++)
- vec[i++] = (*iter2)._hostName;
- }
-
- // MESSAGE("ResourcesManager::GetFittingResources : return" << ret.size());
- ret->length(vec.size());
- for(unsigned int i=0;i<vec.size();i++)
- (*ret)[i]=(vec[i]).c_str();
-
+ vector <std::string> vec = _rm.GetFittingResources(p,cl);
+ ret->length(vec.size());
+ for(int i=0;i<vec.size();i++)
+ (*ret)[i] = (vec[i]).c_str();
}
- catch(const SALOME_Exception &ex)
- {
- INFOS("Caught exception.");
- THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::BAD_PARAM);
- //return ret;
- }
+ catch(const ResourcesException &ex){
+ INFOS("Caught exception.");
+ THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
+ }
return ret;
}
-//=============================================================================
-/*!
- * add an entry in the ressources catalog xml file.
- * Return 0 if OK (KERNEL found in new resources modules) else throw exception
- */
-//=============================================================================
-
-int
-SALOME_ResourcesManager::
-AddResourceInCatalog(const Engines::MachineParameters& paramsOfNewResources,
- const vector<string>& modulesOnNewResources,
- const char *alias,
- const char *userName,
- AccessModeType mode,
- AccessProtocolType prot)
-throw(SALOME_Exception)
-{
- vector<string>::const_iterator iter = find(modulesOnNewResources.begin(),
- modulesOnNewResources.end(),
- "KERNEL");
-
- if (iter != modulesOnNewResources.end())
- {
- ParserResourcesType newElt;
- newElt.DataForSort._hostName = paramsOfNewResources.hostname;
- newElt.Alias = alias;
- newElt.Protocol = prot;
- newElt.Mode = mode;
- newElt.UserName = userName;
- newElt.ModulesList = modulesOnNewResources;
- 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._hostName] = newElt;
- return 0;
- }
-
- else
- throw SALOME_Exception("KERNEL is not present in this resource");
-}
-
-//=============================================================================
-/*!
- * Deletes a resource from the catalog
- */
-//=============================================================================
-
-void SALOME_ResourcesManager::DeleteResourceInCatalog(const char *hostname)
-{
- _resourcesList.erase(hostname);
-}
-
-//=============================================================================
-/*!
- * write the current data in memory in file.
- */
-//=============================================================================
-
-void SALOME_ResourcesManager::WriteInXmlFile()
-{
- const char* aFilePath = _path_resources.c_str();
-
- FILE* aFile = fopen(aFilePath, "w");
-
- if (aFile == NULL)
- {
- INFOS("Error opening file !");
- return;
- }
-
- xmlDocPtr aDoc = xmlNewDoc(BAD_CAST "1.0");
- xmlNewDocComment(aDoc, BAD_CAST "ResourcesCatalog");
-
- SALOME_ResourcesCatalog_Handler* handler =
- new SALOME_ResourcesCatalog_Handler(_resourcesList);
- handler->PrepareDocToXmlFile(aDoc);
- delete handler;
-
- int isOk = xmlSaveFile(aFilePath, aDoc);
-
- if (!isOk)
- INFOS("Error while XML file saving.");
-
- // Free the document
- xmlFreeDoc(aDoc);
-
- fclose(aFile);
-
- MESSAGE("WRITING DONE!");
-}
-
-//=============================================================================
-/*!
- * parse the data type catalog
- */
-//=============================================================================
-
-const MapOfParserResourcesType& SALOME_ResourcesManager::ParseXmlFile()
-{
- SALOME_ResourcesCatalog_Handler* handler =
- new SALOME_ResourcesCatalog_Handler(_resourcesList);
-
- const char* aFilePath = _path_resources.c_str();
- FILE* aFile = fopen(aFilePath, "r");
-
- if (aFile != NULL)
- {
- xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0);
-
- if (aDoc != NULL)
- handler->ProcessXmlDocument(aDoc);
- else
- INFOS("ResourcesManager: could not parse file "<<aFilePath);
-
- // Free the document
- xmlFreeDoc(aDoc);
-
- fclose(aFile);
- }
- else
- INFOS("ResourcesManager: file "<<aFilePath<<" is not readable.");
-
- delete handler;
-
- return _resourcesList;
-}
-
-//=============================================================================
-/*!
- * consult the content of the list
- */
-//=============================================================================
-
-const MapOfParserResourcesType& SALOME_ResourcesManager::GetList() const
- {
- return _resourcesList;
- }
-
-
//=============================================================================
/*!
* dynamically obtains the first machines
char *
SALOME_ResourcesManager::FindFirst(const Engines::MachineList& listOfMachines)
{
- return CORBA::string_dup(_dynamicResourcesSelecter.FindFirst(listOfMachines).c_str());
-}
-
-//=============================================================================
-/*!
- * dynamically obtains the best machines
- */
-//=============================================================================
-
-string
-SALOME_ResourcesManager::FindNext(const Engines::MachineList& listOfMachines)
-{
- return _dynamicResourcesSelecter.FindNext(listOfMachines,_resourcesList,_NS);
-}
-//=============================================================================
-/*!
- * dynamically obtains the best machines
- */
-//=============================================================================
-
-string
-SALOME_ResourcesManager::FindBest(const Engines::MachineList& listOfMachines)
-{
- return _dynamicResourcesSelecter.FindBest(listOfMachines);
-}
+ vector<string> ml;
+ for(int i=0;i<listOfMachines.length();i++)
+ ml.push_back(string(listOfMachines[i]));
-//=============================================================================
-/*!
- * Gives a sublist of machines with matching OS.
- * If parameter OS is empty, gives the complete list of machines
- */
-//=============================================================================
-
-// Warning need an updated parsed list : _resourcesList
-void
-SALOME_ResourcesManager::SelectOnlyResourcesWithOS
-( vector<string>& hosts,
- const char *OS) const
-throw(SALOME_Exception)
-{
- string base(OS);
-
- for (map<string, ParserResourcesType>::const_iterator iter =
- _resourcesList.begin();
- iter != _resourcesList.end();
- iter++)
- {
- if ( (*iter).second.OS == base || base.size() == 0)
- hosts.push_back((*iter).first);
- }
+ return CORBA::string_dup(_rm.FindFirst(ml).c_str());
}
-
-//=============================================================================
-/*!
- * Gives a sublist of machines on which the module is known.
- */
-//=============================================================================
-
-//Warning need an updated parsed list : _resourcesList
-void
-SALOME_ResourcesManager::KeepOnlyResourcesWithModule
-( vector<string>& hosts,
- const Engines::CompoList& componentList) const
-throw(SALOME_Exception)
-{
- for (vector<string>::iterator iter = hosts.begin(); iter != hosts.end();)
- {
- MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter);
- const vector<string>& mapOfModulesOfCurrentHost = (((*it).second).ModulesList);
-
- bool erasedHost = false;
- if( mapOfModulesOfCurrentHost.size() > 0 ){
- for(int i=0;i<componentList.length();i++){
- const char* compoi = componentList[i];
- vector<string>::const_iterator itt = find(mapOfModulesOfCurrentHost.begin(),
- mapOfModulesOfCurrentHost.end(),
- compoi);
-// componentList[i]);
- if (itt == mapOfModulesOfCurrentHost.end()){
- erasedHost = true;
- break;
- }
- }
- }
- if(erasedHost)
- hosts.erase(iter);
- else
- iter++;
- }
-}
-
-
Engines::MachineParameters* SALOME_ResourcesManager::GetMachineParameters(const char *hostname)
{
- ParserResourcesType resource = _resourcesList[string(hostname)];
+ ParserResourcesType resource = _rm.GetResourcesList(string(hostname));
Engines::MachineParameters *p_ptr = new Engines::MachineParameters;
p_ptr->container_name = CORBA::string_dup("");
p_ptr->hostname = CORBA::string_dup("hostname");
return p_ptr;
}
-ParserResourcesType SALOME_ResourcesManager::GetResourcesList(const std::string& machine)
-{
- return _resourcesList[machine];
-}
#include <string>
#include <fstream>
#include <vector>
+#include "ResourcesManager.hxx"
#if defined RESOURCESMANAGER_EXPORTS
#if defined WIN32
Engines::MachineList *
GetFittingResources(const Engines::MachineParameters& params,
const Engines::CompoList& componentList);
-// throw(SALOME_Exception);
char* FindFirst(const Engines::MachineList& listOfMachines);
- std::string FindNext(const Engines::MachineList& listOfMachines);
- std::string FindBest(const Engines::MachineList& listOfMachines);
-
- int AddResourceInCatalog
- (const Engines::MachineParameters& paramsOfNewResources,
- const std::vector<std::string>& modulesOnNewResources,
- const char *alias,
- const char *userName,
- AccessModeType mode,
- AccessProtocolType prot)
- throw(SALOME_Exception);
-
- void DeleteResourceInCatalog(const char *hostname);
-
- void WriteInXmlFile();
-
- const MapOfParserResourcesType& ParseXmlFile();
-
- const MapOfParserResourcesType& GetList() const;
Engines::MachineParameters* GetMachineParameters(const char *hostname);
static const char *_ResourcesManagerNameInNS;
- ParserResourcesType GetResourcesList(const std::string& machine);
+ ResourcesManager_cpp *GetImpl() { return &_rm; }
protected:
CORBA::ORB_var _orb;
PortableServer::POA_var _poa;
- void SelectOnlyResourcesWithOS(std::vector<std::string>& hosts,
- const char *OS) const
- throw(SALOME_Exception);
-
- void KeepOnlyResourcesWithModule(std::vector<std::string>& hosts,
- const Engines::CompoList& componentList) const
- throw(SALOME_Exception);
-
- //! will contain the path to the ressources catalog
- std::string _path_resources;
-
- //! will contain the informations on the data type catalog(after parsing)
- MapOfParserResourcesType _resourcesList;
-
- SALOME_LoadRateManager _dynamicResourcesSelecter;
+ ResourcesManager_cpp _rm;
- //! different behaviour if $APPLI exists (SALOME Application)
- bool _isAppliSalomeDefined;
};
#endif // RESSOURCESCATALOG_IMPL_H