Back to index

salome-kernel  6.5.0
TestContainerManager.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  SALOME TestContainer : test of container creation and its life cycle
00021 //  File   : TestContainer.cxx
00022 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
00023 //  Module : SALOME
00024 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/LifeCycleCORBA/TestContainerManager.cxx,v 1.3.2.5.10.3.12.1 2012-04-12 14:05:16 vsr Exp $
00025 //
00026 #include "utilities.h"
00027 #include <iostream>
00028 #ifndef WNT
00029 #include <unistd.h>
00030 #endif
00031 #include <SALOMEconfig.h>
00032 #include "SALOME_NamingService.hxx"
00033 #include "SALOME_ContainerManager.hxx"
00034 #include "SALOME_LifeCycleCORBA.hxx"
00035 #include "NamingService_WaitForServerReadiness.hxx"
00036 #include "OpUtil.hxx"
00037 #include "Utils_ORB_INIT.hxx"
00038 #include "Utils_SINGLETON.hxx"
00039 #include "Utils_SALOME_Exception.hxx"
00040 #include "Utils_CommException.hxx"
00041 #include "Basics_DirUtils.hxx"
00042 
00043 int main (int argc, char * argv[])
00044 {
00045   std::map<std::string, int> cycle;
00046   std::map<std::string, int> first;
00047   Engines::Container_ptr cont;
00048   Engines::EngineComponent_ptr compo;
00049   bool error = false;
00050   bool bestImplemented;
00051   int status;
00052 
00053   // Initializing omniORB
00054   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
00055   CORBA::ORB_ptr orb = init( argc , argv ) ;
00056 
00057   SALOME_NamingService *_NS=new SALOME_NamingService(orb);
00058 
00059   CORBA::Object_var obj = _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
00060   ASSERT( !CORBA::is_nil(obj));
00061   Engines::ContainerManager_var _ContManager=Engines::ContainerManager::_narrow(obj);
00062   obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
00063   ASSERT( !CORBA::is_nil(obj));
00064   Engines::ResourcesManager_var _ResManager=Engines::ResourcesManager::_narrow(obj);
00065 
00066   Engines::ContainerParameters p;
00067   p.resource_params.componentList.length(2);
00068   p.resource_params.componentList[0] = "MED";
00069   p.resource_params.componentList[1] = "GEOM";
00070 
00071   p.resource_params.hostname = "";
00072   p.resource_params.OS = "LINUX";
00073   p.resource_params.mem_mb = 1000;
00074   p.resource_params.cpu_clock = 1000;
00075   p.resource_params.nb_proc_per_node = 1;
00076   p.resource_params.nb_node = 1;
00077   p.isMPI = false;
00078 
00079   char st[10];
00080   for(int i=0;i<10;i++){
00081     sprintf(st,"cycl_%d",i);
00082     p.container_name = CORBA::string_dup(st);
00083     p.resource_params.policy="cycl";
00084     cont = _ContManager->GiveContainer(p);
00085     if(CORBA::is_nil(cont)) error = true;
00086   }
00087 
00088   for(int i=0;i<10;i++){
00089     sprintf(st,"first_%d",i);
00090     p.container_name = CORBA::string_dup(st);
00091     p.resource_params.policy="first";
00092     cont = _ContManager->GiveContainer(p);
00093     if(CORBA::is_nil(cont)) error = true;
00094   }
00095 
00096   p.container_name = CORBA::string_dup("best");
00097   p.resource_params.policy="best";
00098   cont = _ContManager->GiveContainer(p);
00099   if(CORBA::is_nil(cont)) bestImplemented = false;
00100   else bestImplemented = true;
00101 
00102   SALOME_LifeCycleCORBA LCC(_NS);
00103   p.container_name = CORBA::string_dup("FactoryServer");
00104   compo = LCC.FindOrLoad_Component(p,"SMESH");
00105   if(CORBA::is_nil(compo)) error = true;
00106   compo = LCC.FindOrLoad_Component(p,"SMESH");
00107   if(CORBA::is_nil(compo)) error = true;
00108 
00109   _NS->Change_Directory("/Containers");
00110 
00111   std::vector<std::string> vec = _NS->list_directory_recurs();
00112   std::list<std::string> lstCont;
00113   for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++){
00114     CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
00115     Engines::Container_var cont=Engines::Container::_narrow(obj);
00116     if(!CORBA::is_nil(cont)){
00117       cycle[cont->getHostName()]=0;
00118       first[cont->getHostName()]=0;
00119       lstCont.push_back((*iter));
00120     }
00121   }
00122   for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
00123     CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
00124     Engines::Container_var cont=Engines::Container::_narrow(obj);
00125     if(!CORBA::is_nil(cont)){
00126       std::string basename = Kernel_Utils::GetBaseName(cont->name());
00127       if(basename.compare(0,4,"cycl")==0)
00128         cycle[cont->getHostName()]++;
00129       if(basename.compare(0,5,"first")==0)
00130         first[cont->getHostName()]++;
00131     }
00132   }
00133   _ContManager->ShutdownContainers();
00134 
00135   int cmin=10;
00136   int cmax=0;
00137   int fmin=10;
00138   int fmax=0;
00139   int nbpmax;
00140   for(std::map<std::string,int>::iterator iter=cycle.begin();iter!=cycle.end();iter++){
00141     if(strcmp((*iter).first.c_str(),"localhost")!=0){
00142       Engines::ResourceDefinition *p = _ResManager->GetResourceDefinition((*iter).first.c_str());
00143       int nbproc = p->nb_node * p->nb_proc_per_node;
00144       if(cycle[(*iter).first]/nbproc<cmin) cmin=cycle[(*iter).first]/nbproc;
00145       if(cycle[(*iter).first]/nbproc>cmax) cmax=cycle[(*iter).first]/nbproc;
00146       if(first[(*iter).first]/nbproc<fmin) fmin=first[(*iter).first]/nbproc;
00147       if(first[(*iter).first]/nbproc>fmax){
00148         fmax=first[(*iter).first]/nbproc;
00149         nbpmax = nbproc;
00150       }
00151     }
00152   }
00153   std::string msg;
00154   if( ((cmax-cmin) <= 1) && (fmax == 10/nbpmax) && !error ){
00155     if(bestImplemented)
00156       msg = "TEST OK";
00157     else
00158       msg = "TEST OK but FindBest not implemented!";
00159     status=0;
00160   }
00161   else{
00162     msg ="TEST KO";
00163     status=1;
00164   }
00165   std::cout << msg << std::endl;
00166 
00167   return status;
00168 }