*/
exception NotFound {};
+ enum policy {P_FIRST,P_CYCL,P_BEST};
+ typedef policy ResPolicy;
/*! \brief Interface of the %containerManager
This interface is used for interaction with the unique instance
Container FindOrStartContainer( in MachineParameters params,
in MachineList possibleComputers);
+ Container StartContainer( in MachineParameters params,
+ in ResPolicy policy);
+
string FindBest(in MachineList possibleComputers);
MachineList GetFittingResources( in MachineParameters params,
# Executables targets
# ===============================================================
#
-bin_PROGRAMS = SALOME_Container SALOME_ContainerManagerServer
+bin_PROGRAMS = SALOME_Container SALOME_ContainerManagerServer TestContainerManager
SALOME_Container_SOURCES =\
SALOME_Container.cxx \
SALOME_Container_SignalsHandler.cxx
libSalomeContainer.la \
$(COMMON_LIBS) \
../Basics/libSALOMEBasics.la
+
+TestContainerManager_SOURCES =\
+ TestContainerManager.cxx
+
+TestContainerManager_CPPFLAGS=\
+ $(COMMON_CPPFLAGS)
+
+TestContainerManager_LDADD =\
+ libSalomeContainer.la \
+ $(COMMON_LIBS) \
+ ../Basics/libSALOMEBasics.la
if(!CORBA::is_nil(ret))
return ret;
MESSAGE("Container doesn't exist try to launch it ...");
- MESSAGE("SALOME_ContainerManager::FindOrStartContainer " <<
+
+ return StartContainer(params,possibleComputers,Engines::P_FIRST);
+
+}
+
+//=============================================================================
+/*! CORBA Method:
+ * Start a suitable Container in a list of machines
+ * \param params Machine Parameters required for the container
+ * \param possibleComputers list of machines usable for start
+ */
+//=============================================================================
+
+Engines::Container_ptr
+SALOME_ContainerManager::
+StartContainer(const Engines::MachineParameters& params,
+ const Engines::MachineList& possibleComputers,
+ Engines::ResPolicy policy)
+{
+ long id;
+ string containerNameInNS;
+ char idc[3*sizeof(long)];
+ Engines::Container_ptr ret = Engines::Container::_nil();
+
+ MESSAGE("SALOME_ContainerManager::StartContainer " <<
possibleComputers.length());
- //vector<string> vector;
- string theMachine=_ResManager->FindBest(possibleComputers);
+
+ string theMachine;
+ try{
+ switch(policy){
+ case Engines::P_FIRST:
+ theMachine=_ResManager->FindFirst(possibleComputers);
+ break;
+ case Engines::P_CYCL:
+ theMachine=_ResManager->FindNext(possibleComputers);
+ break;
+ case Engines::P_BEST:
+ theMachine=_ResManager->FindBest(possibleComputers);
+ break;
+ }
+ }
+ catch( const SALOME_Exception &ex ){
+ MESSAGE(ex.what());
+ return Engines::Container::_nil();
+ }
+
MESSAGE("try to launch it on " << theMachine);
// Get Id for container: a parallel container registers in Naming Service
id = GetIdForContainer();
string command;
- if(theMachine=="")
- {
- MESSAGE("SALOME_ContainerManager::FindOrStartContainer : " <<
- "no possible computer");
- return Engines::Container::_nil();
- }
+ if(theMachine==""){
+ MESSAGE("SALOME_ContainerManager::StartContainer : " <<
+ "no possible computer");
+ return Engines::Container::_nil();
+ }
else if(theMachine==GetHostname())
- {
- command=_ResManager->BuildCommandToLaunchLocalContainer(params,id);
- }
+ command=_ResManager->BuildCommandToLaunchLocalContainer(params,id);
else
- command =
- _ResManager->BuildCommandToLaunchRemoteContainer(theMachine,params,id);
+ command = _ResManager->BuildCommandToLaunchRemoteContainer(theMachine,params,id);
_ResManager->RmTmpFile();
int status=system(command.c_str());
- if (status == -1)
- {
- MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed " <<
- "(system command status -1)");
- return Engines::Container::_nil();
- }
- else if (status == 217)
- {
- MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed " <<
- "(system command status 217)");
- return Engines::Container::_nil();
- }
- else
- {
- int count=TIME_OUT_TO_LAUNCH_CONT;
- while ( CORBA::is_nil(ret) && count )
- {
+ if (status == -1){
+ MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed " <<
+ "(system command status -1)");
+ return Engines::Container::_nil();
+ }
+ else if (status == 217){
+ MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed " <<
+ "(system command status 217)");
+ return Engines::Container::_nil();
+ }
+ else{
+ int count=TIME_OUT_TO_LAUNCH_CONT;
+ MESSAGE("count = "<<count);
+ while ( CORBA::is_nil(ret) && count ){
#ifndef WNT
- sleep( 1 ) ;
+ sleep( 1 ) ;
#else
- Sleep(1000);
+ Sleep(1000);
#endif
- count-- ;
- if ( count != 10 )
- MESSAGE( count << ". Waiting for FactoryServer on " << theMachine);
- if(params.isMPI)
- {
- containerNameInNS = "/ContainerManager/id";
- sprintf(idc,"%ld",id);
- containerNameInNS += idc;
- }
- else
- containerNameInNS =
- _NS->BuildContainerNameForNS(params,theMachine.c_str());
- SCRUTE(containerNameInNS);
- CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
- ret=Engines::Container::_narrow(obj);
- }
- if ( CORBA::is_nil(ret) )
- {
- MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed");
- }
- return ret;
+ count-- ;
+ if ( count != 10 )
+ MESSAGE( count << ". Waiting for FactoryServer on " << theMachine);
+
+ if(params.isMPI){
+ containerNameInNS = "/ContainerManager/id";
+ sprintf(idc,"%ld",id);
+ containerNameInNS += idc;
+ }
+ else
+ containerNameInNS = _NS->BuildContainerNameForNS(params,theMachine.c_str());
+
+ SCRUTE(containerNameInNS);
+ CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
+ ret=Engines::Container::_narrow(obj);
}
+
+ if ( CORBA::is_nil(ret) )
+ MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed");
+
+ return ret;
+ }
+}
+
+//=============================================================================
+/*! CORBA Method:
+ * Start a suitable Container in a list of machines
+ * \param params Machine Parameters required for the container
+ * \param possibleComputers list of machines usable for start
+ */
+//=============================================================================
+
+Engines::Container_ptr
+SALOME_ContainerManager::
+StartContainer(const Engines::MachineParameters& params,
+ Engines::ResPolicy policy)
+{
+ Engines::MachineList_var possibleComputers = GetFittingResources(params,"");
+ return StartContainer(params,possibleComputers,policy);
}
//=============================================================================
FindOrStartContainer(const Engines::MachineParameters& params,
const Engines::MachineList& possibleComputer);
+ Engines::Container_ptr
+ StartContainer(const Engines::MachineParameters& params,
+ const Engines::MachineList& possibleComputer,
+ Engines::ResPolicy policy);
+
+ Engines::Container_ptr
+ StartContainer(const Engines::MachineParameters& params,
+ Engines::ResPolicy policy);
+
Engines::MachineList *
GetFittingResources(const Engines::MachineParameters& params,
const char *componentName);
--- /dev/null
+// SALOME TestContainer : test of container creation and its life cycle
+//
+// Copyright (C) 2003 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
+//
+//
+//
+// File : TestContainer.cxx
+// Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
+// Module : SALOME
+// $Header$
+
+#include "utilities.h"
+#include <iostream>
+#include <unistd.h>
+#include <SALOMEconfig.h>
+#include "SALOME_NamingService.hxx"
+#include "SALOME_ContainerManager.hxx"
+#include "NamingService_WaitForServerReadiness.hxx"
+#include "OpUtil.hxx"
+#include "Utils_ORB_INIT.hxx"
+#include "Utils_SINGLETON.hxx"
+#include "Utils_SALOME_Exception.hxx"
+#include "Utils_CommException.hxx"
+using namespace std;
+
+int main (int argc, char * argv[])
+{
+ map<string, int> cycle;
+ map<string, int> first;
+
+ // Initializing omniORB
+ ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
+ CORBA::ORB_ptr orb = init( argc , argv ) ;
+
+ SALOME_NamingService *_NS=new SALOME_NamingService(orb);
+
+ CORBA::Object_var obj = _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
+ ASSERT( !CORBA::is_nil(obj));
+ Engines::ContainerManager_var _ContManager=Engines::ContainerManager::_narrow(obj);
+
+ Engines::MachineParameters p;
+
+ p.hostname = "";
+ p.OS = "LINUX";
+ p.mem_mb = 1000;
+ p.cpu_clock = 1000;
+ p.nb_proc_per_node = 1;
+ p.nb_node = 1;
+ p.isMPI = false;
+
+ char st[10];
+ for(int i=0;i<10;i++){
+ sprintf(st,"cycl_%d",i);
+ p.container_name = CORBA::string_dup(st);
+ _ContManager->StartContainer(p,Engines::P_CYCL);
+ }
+
+ for(int i=0;i<10;i++){
+ sprintf(st,"first_%d",i);
+ p.container_name = CORBA::string_dup(st);
+ _ContManager->StartContainer(p,Engines::P_FIRST);
+ }
+
+ p.container_name = CORBA::string_dup("best");
+ _ContManager->StartContainer(p,Engines::P_BEST);
+
+ _NS->Change_Directory("/Containers");
+
+ vector<string> vec = _NS->list_directory_recurs();
+ list<string> lstCont;
+ for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++){
+ CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
+ Engines::Container_var cont=Engines::Container::_narrow(obj);
+ if(!CORBA::is_nil(cont)){
+ cycle[cont->getHostName()]=0;
+ first[cont->getHostName()]=0;
+ lstCont.push_back((*iter));
+ }
+ }
+ for(list<string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
+ CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
+ Engines::Container_var cont=Engines::Container::_narrow(obj);
+ if(!CORBA::is_nil(cont)){
+ if(strncmp(basename(cont->name()),"cycl",4)==0)
+ cycle[cont->getHostName()]++;
+ if(strncmp(basename(cont->name()),"first",5)==0)
+ first[cont->getHostName()]++;
+ }
+ }
+ _ContManager->ShutdownContainers();
+
+ int cmin=10;
+ int cmax=0;
+ int fmin=10;
+ int fmax=0;
+ for(map<string,int>::iterator iter=cycle.begin();iter!=cycle.end();iter++){
+ if(strcmp((*iter).first.c_str(),"localhost")!=0){
+ if(cycle[(*iter).first]<cmin) cmin=cycle[(*iter).first];
+ if(cycle[(*iter).first]>cmax) cmax=cycle[(*iter).first];
+ if(first[(*iter).first]<fmin) fmin=first[(*iter).first];
+ if(first[(*iter).first]>fmax) fmax=first[(*iter).first];
+ }
+ }
+ if( ((cmax-cmin) <= 1) && (fmax == 10)){
+ MESSAGE("TEST OK");
+ return 0;
+ }
+ else{
+ MESSAGE("TEST KO");
+ return 1;
+ }
+}
#include "SALOME_LoadRateManager.hxx"
#include "utilities.h"
#include <iostream>
+#include <map>
using namespace std;
-string SALOME_LoadRateManager::FindBest(const Engines::MachineList& hosts)
+string SALOME_LoadRateManager::FindFirst(const Engines::MachineList& hosts)
{
- // for the moment then "maui" will be used for dynamic selection ...
- MESSAGE("SALOME_LoadRateManager::FindBest " << hosts.length());
+ MESSAGE("SALOME_LoadRateManager::FindFirst " << hosts.length());
if (hosts.length() == 0)
return string("");
return string(hosts[0]);
}
+
+string SALOME_LoadRateManager::FindNext(const Engines::MachineList& hosts,SALOME_NamingService *ns)
+{
+ MESSAGE("SALOME_LoadRateManager::FindNext " << hosts.length());
+ map<string, int> machines;
+
+ if (hosts.length() == 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();
+ list<string> lstCont;
+ for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++){
+ CORBA::Object_var obj=ns->Resolve((*iter).c_str());
+ Engines::Container_var cont=Engines::Container::_narrow(obj);
+ if(!CORBA::is_nil(cont)){
+ lstCont.push_back((*iter));
+ }
+ }
+ for(list<string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
+ CORBA::Object_var obj=ns->Resolve((*iter).c_str());
+ Engines::Container_var cont=Engines::Container::_narrow(obj);
+ if(!CORBA::is_nil(cont)){
+ string mach = cont->getHostName();
+ machines[mach]++;
+ }
+ }
+
+ int imin = 0;
+ int min = machines[string(hosts[0])];
+ for(int i=1;i<hosts.length();i++){
+ if( machines[string(hosts[i])] < min ){
+ imin = i;
+ min = machines[string(hosts[i])];
+ }
+ }
+
+ return string(hosts[imin]);
+}
+
+string SALOME_LoadRateManager::FindBest(const Engines::MachineList& hosts) throw (SALOME_Exception)
+{
+ // 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("");
+}
#include <SALOMEconfig.h>
#include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
#include <string>
-
+#include "SALOME_NamingService.hxx"
#if defined RESOURCESMANAGER_EXPORTS
#if defined WIN32
{
public:
- std::string FindBest(const Engines::MachineList& hosts);
+ std::string FindFirst(const Engines::MachineList& hosts);
+ std::string FindNext(const Engines::MachineList& hosts,SALOME_NamingService *ns);
+ std::string FindBest(const Engines::MachineList& hosts) throw (SALOME_Exception);
};
#endif
// MESSAGE("ResourcesManager::GetFittingResources");
vector <std::string> ret;
+
// --- To be sure that we search in a correct list.
ParseXmlFile();
}
+//=============================================================================
+/*!
+ * dynamically obtains the first machines
+ */
+//=============================================================================
+
+string
+SALOME_ResourcesManager::FindFirst(const Engines::MachineList& listOfMachines)
+{
+ return _dynamicResourcesSelecter.FindFirst(listOfMachines);
+}
+
+//=============================================================================
+/*!
+ * dynamically obtains the best machines
+ */
+//=============================================================================
+
+string
+SALOME_ResourcesManager::FindNext(const Engines::MachineList& listOfMachines)
+{
+ return _dynamicResourcesSelecter.FindNext(listOfMachines,_NS);
+}
//=============================================================================
/*!
* dynamically obtains the best machines
}
+
//=============================================================================
/*!
* This is no longer valid (C++ container are also python containers)
const char *moduleName)
throw(SALOME_Exception);
+ std::string FindFirst(const Engines::MachineList& listOfMachines);
+ std::string FindNext(const Engines::MachineList& listOfMachines);
std::string FindBest(const Engines::MachineList& listOfMachines);
std::string BuildCommandToLaunchRemoteContainer