*/
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 FindOrStartParallelContainer( in MachineParameters params,
in MachineList possibleComputers);
- string FindBest(in MachineList possibleComputers);
+ Container StartContainer( in MachineParameters params,
+ in ResPolicy policy);
+
+ string FindFirst(in MachineList possibleComputers);
MachineList GetFittingResources( in MachineParameters params,
in string componentName )
SALOME_ContainerManagerServer_LDADD =\
libSalomeContainer.la \
$(COMMON_LIBS) \
- ../Basics/libSALOMEBasics.la
-
-
+ ../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);
}
#ifdef WITH_PACO_PARALLEL
char*
SALOME_ContainerManager::
-FindBest(const Engines::MachineList& possibleComputers)
+FindFirst(const Engines::MachineList& possibleComputers)
{
- string theMachine=_ResManager->FindBest(possibleComputers);
+ string theMachine=_ResManager->FindFirst(possibleComputers);
return CORBA::string_dup(theMachine.c_str());
}
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);
- char* FindBest(const Engines::MachineList& possibleComputers);
+ char* FindFirst(const Engines::MachineList& possibleComputers);
void Shutdown();
void ShutdownContainers();
--- /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 "SALOME_LifeCycleCORBA.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;
+ Engines::Container_ptr cont;
+ Engines::Component_ptr compo;
+ bool error = false;
+ bool bestImplemented;
+
+ // 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);
+ cont = _ContManager->StartContainer(p,Engines::P_CYCL);
+ if(CORBA::is_nil(cont)) error = true;
+ }
+
+ for(int i=0;i<10;i++){
+ sprintf(st,"first_%d",i);
+ p.container_name = CORBA::string_dup(st);
+ cont = _ContManager->StartContainer(p,Engines::P_FIRST);
+ if(CORBA::is_nil(cont)) error = true;
+ }
+
+ p.container_name = CORBA::string_dup("best");
+ cont = _ContManager->StartContainer(p,Engines::P_BEST);
+ if(CORBA::is_nil(cont)) bestImplemented = false;
+ else bestImplemented = true;
+
+ SALOME_LifeCycleCORBA LCC(_NS);
+ compo = LCC.FindOrLoad_Component("FactoryServer","GEOM");
+ if(CORBA::is_nil(compo)) error = true;
+ compo = LCC.FindOrLoad_Component("FactoryServer","GEOM");
+ if(CORBA::is_nil(compo)) error = true;
+
+ _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) && !error ){
+ string msg;
+ if(bestImplemented)
+ msg = "TEST OK";
+ else
+ msg = "TEST OK but FindBest not implemented!";
+ MESSAGE(msg);
+ return 0;
+ }
+ else{
+ MESSAGE("TEST KO");
+ return 1;
+ }
+}
pass
pass
if len(machinesOK)!=0:
- bestMachine=self._contManager.FindBest(machinesOK)
+ bestMachine=self._contManager.FindFirst(machinesOK)
componentNameForNS= [CosNaming.NameComponent(bestMachine,"dir"),
CosNaming.NameComponent(containerName,"dir"),
CosNaming.NameComponent(componentName,"object")]
else:
return None
else:
- bestMachine=self._contManager.FindBest(listOfMachines)
+ bestMachine=self._contManager.FindFirst(listOfMachines)
MESSAGE("Not implemented yet ...")
return None
pass
if(lghtOfmachinesOK != 0)
{
machinesOK->length(lghtOfmachinesOK);
- CORBA::String_var bestMachine = _ContManager->FindBest(machinesOK);
+ CORBA::String_var bestMachine = _ContManager->FindFirst(machinesOK);
CORBA::Object_var obj = _NS->ResolveComponent(bestMachine,
containerName,
componentName,
#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