21 #include "SALOME_LifeCycleCORBA.hxx"
22 #include "SALOME_NamingService.hxx"
23 #include "SALOME_ResourcesManager.hxx"
24 #include "SALOME_ContainerManager.hxx"
40 #define getpid _getpid
43 using namespace YACS::ENGINE;
48 SALOME_LifeCycleCORBA::preSet(
_params);
58 _params=Engines::ContainerParameters();
63 std::map<std::string,std::string>::const_iterator it(
_propertyMap.find(name));
74 if (name ==
"container_name")
75 _params.container_name = CORBA::string_dup(value.c_str());
76 else if (name ==
"workingdir")
77 _params.workingdir = CORBA::string_dup(value.c_str());
78 else if (name ==
"nb_parallel_procs")
80 std::istringstream iss(value);
82 throw Exception(
"salomecontainer::setproperty : params.nb_proc value not correct : " + value);
84 else if (name ==
"isMPI")
88 else if (value ==
"false")
91 throw Exception(
"SalomeContainer::setProperty : params.isMPI value not correct : " + value);
93 else if (name ==
"parallelLib")
94 _params.parallelLib = CORBA::string_dup(value.c_str());
97 else if (name ==
"name")
98 _params.resource_params.name = CORBA::string_dup(value.c_str());
99 else if (name ==
"hostname")
100 _params.resource_params.hostname = CORBA::string_dup(value.c_str());
101 else if (name ==
"OS")
102 _params.resource_params.OS = CORBA::string_dup(value.c_str());
103 else if (name ==
"nb_resource_procs")
105 std::istringstream iss(value);
106 if (!(iss >>
_params.resource_params.nb_proc))
107 throw Exception(
"salomecontainer::setproperty : params.resource_params.nb_proc value not correct : " + value);
109 else if (name ==
"mem_mb")
111 std::istringstream iss(value);
112 if (!(iss >>
_params.resource_params.mem_mb))
113 throw Exception(
"salomecontainer::setproperty : params.resource_params.mem_mb value not correct : " + value);
115 else if (name ==
"cpu_clock")
117 std::istringstream iss(value);
118 if (!(iss >>
_params.resource_params.cpu_clock))
119 throw Exception(
"salomecontainer::setproperty : params.resource_params.cpu_clock value not correct : " + value);
121 else if (name ==
"nb_node")
123 std::istringstream iss(value);
124 if (!(iss >>
_params.resource_params.nb_node))
125 throw Exception(
"salomecontainer::setproperty : params.nb_node value not correct : " + value);
127 else if (name ==
"nb_proc_per_node")
129 std::istringstream iss(value);
130 if (!(iss >>
_params.resource_params.nb_proc_per_node))
131 throw Exception(
"salomecontainer::setproperty : params.nb_proc_per_node value not correct : " + value);
133 else if (name ==
"policy")
134 _params.resource_params.policy = CORBA::string_dup(value.c_str());
135 else if (name ==
"component_list")
137 std::string clean_value(value);
140 while(clean_value.find(
" ") != std::string::npos)
141 clean_value = clean_value.erase(clean_value.find(
" "), 1);
144 while(!clean_value.empty())
146 std::string result(
"");
147 std::string::size_type loc = clean_value.find(
",", 0);
148 if (loc != std::string::npos)
150 result = clean_value.substr(0, loc);
151 clean_value = clean_value.erase(0, loc+1);
155 result = clean_value;
158 if (result !=
"," && result !=
"")
165 else if (name ==
"resource_list")
167 std::string clean_value(value);
170 while(clean_value.find(
" ") != std::string::npos)
171 clean_value = clean_value.erase(clean_value.find(
" "), 1);
174 while(!clean_value.empty())
176 std::string result(
"");
177 std::string::size_type loc = clean_value.find(
",", 0);
178 if (loc != std::string::npos)
180 result = clean_value.substr(0, loc);
181 clean_value = clean_value.erase(0, loc+1);
185 result = clean_value;
188 if (result !=
"," && result !=
"")
201 for (CORBA::ULong
i = 0;
i <
_params.resource_params.componentList.length();
i++)
203 std::string component_name =
_params.resource_params.componentList[
i].in();
204 if (component_name == name)
208 CORBA::ULong lgth =
_params.resource_params.componentList.length();
209 _params.resource_params.componentList.length(lgth + 1);
210 _params.resource_params.componentList[lgth] = CORBA::string_dup(name.c_str());
216 for (CORBA::ULong
i = 0;
i <
_params.resource_params.resList.length();
i++)
218 std::string component_name =
_params.resource_params.resList[
i].in();
219 if (component_name == name)
223 CORBA::ULong lgth =
_params.resource_params.resList.length();
224 _params.resource_params.resList.length(lgth + 1);
225 _params.resource_params.resList[lgth] = CORBA::string_dup(name.c_str());
230 return std::string(
_params.container_name);
241 std::string name(
_params.container_name);
250 std::ostringstream stream;
262 return std::string(
_params.resource_params.hostname);
267 params.container_name=CORBA::string_dup(name.c_str());
272 std::map<std::string,std::string> properties;
276 if (!orb)
return properties;
277 SALOME_NamingService namingService(orb);
278 SALOME_LifeCycleCORBA lcc(&namingService);
279 CORBA::Object_var obj = namingService.Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
280 if (CORBA::is_nil(obj))
282 Engines::ResourcesManager_var resManager = Engines::ResourcesManager::_narrow(obj);
283 if (CORBA::is_nil(resManager))
286 std::ostringstream value;
287 Engines::ResourceDefinition_var resource_definition = resManager->GetResourceDefinition(name.c_str());
288 properties[
"hostname"]=resource_definition->hostname.in();
289 properties[
"OS"]=resource_definition->OS.in();
290 value.str(
""); value << resource_definition->mem_mb;
291 properties[
"mem_mb"]=value.str();
292 value.str(
""); value << resource_definition->cpu_clock;
293 properties[
"cpu_clock"]=value.str();
294 value.str(
""); value << resource_definition->nb_node;
295 properties[
"nb_node"]=value.str();
296 value.str(
""); value << resource_definition->nb_proc_per_node;
297 properties[
"nb_proc_per_node"]=value.str();
317 SALOME_NamingService ns;
322 catch(SALOME_Exception& e)
324 throw Exception(
"SalomeContainer::start : Unable to contact the SALOME Naming Service");
326 CORBA::Object_var obj(ns.Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS));
327 Engines::ContainerManager_var contManager(Engines::ContainerManager::_narrow(obj));
331 DEBTRACE(
"SalomeContainer::start " << str <<
";"<< _sct.getHostName() <<
";"<<_type);
335 for(std::vector<std::string>::const_iterator iter=compoNames.begin();iter!=compoNames.end();iter++)
341 myparams.mode=CORBA::string_dup(dftLauchMode.c_str());
346 if (dynamic_cast<SalomeContainerMonoHelper *>(schelp) && !isEmptyName)
348 myparams.mode=CORBA::string_dup(
"getorstart");
357 Engines::Container_var trueCont(Engines::Container::_nil());
358 if(!isEmptyName && shutdownLevel==999)
367 trueCont=contManager->GiveContainer(myparams);
369 catch(
const SALOME::SALOME_Exception& ex )
371 std::string msg=
"SalomeContainer::start : no existing container : ";
373 msg += ex.details.text.in();
380 if(!CORBA::is_nil(trueCont))
383 DEBTRACE(
"container found: " << str <<
" " << _shutdownLevel );
388 myparams.mode=
"start";
389 DEBTRACE(
"container not found: " << str <<
" " << _shutdownLevel);
393 if(CORBA::is_nil(trueCont))
398 trueCont=contManager->GiveContainer(myparams);
400 catch(
const SALOME::SALOME_Exception& ex )
402 std::string msg=
"SalomeContainer::start : Unable to launch container in Salome : ";
404 msg += ex.details.text.in();
407 catch(CORBA::COMM_FAILURE&)
409 throw Exception(
"SalomeContainer::start : Unable to launch container in Salome : CORBA Comm failure detected");
411 catch(CORBA::Exception&)
413 throw Exception(
"SalomeContainer::start : Unable to launch container in Salome : Unexpected CORBA failure detected");
416 if(CORBA::is_nil(trueCont))
417 throw Exception(
"SalomeContainer::start : Unable to launch container in Salome. Check your CatalogResources.xml file");
421 CORBA::String_var containerName(trueCont->name()),hostName(trueCont->getHostName());
422 std::cerr <<
"SalomeContainer launched : " << containerName <<
" " << hostName <<
" " << trueCont->getPID() << std::endl;
427 DEBTRACE(
"SalomeContainer::loadComponent ");
432 cont->
start(askingNode);
435 throw Exception(
"SalomeContainerTools::LoadComponent : no instance of component in the task requesting for a load of its component !");
436 CORBA::Object_ptr objComponent=CORBA::Object::_nil();
439 std::string compoName(inst->getCompoName());
440 Engines::Container_var container(launchModeType->
getContainer(askingNode));
443 bool isLoadable(container->load_component_Library(compoName.c_str(), reason));
453 throw Exception(
"SalomeContainerTools::CreateComponentInstance : no instance of component in the task requesting for a load of its component !");
456 CORBA::Object_ptr objComponent=CORBA::Object::_nil();
463 studyid= atoi(value.c_str());
466 Engines::FieldsDict_var env(
new Engines::FieldsDict);
467 std::map<std::string, std::string> properties(inst->
getProperties());
471 properties.insert(procMap.begin(),procMap.end());
474 std::map<std::string, std::string>::const_iterator itm;
475 env->length(properties.size());
477 for(itm = properties.begin(); itm != properties.end(); ++itm, item++)
479 DEBTRACE(
"envname="<<itm->first<<
" envvalue="<< itm->second);
480 env[item].key= CORBA::string_dup(itm->first.c_str());
481 env[item].value <<= itm->second.c_str();
484 objComponent=contPtr->create_component_instance_env(compoName.c_str(), studyid, env, reason);
485 if(CORBA::is_nil(objComponent))
487 std::string text=
"Error while trying to create a new component: component '"+ compoName;
488 text=text+
"' is not installed or it's a wrong name";
491 CORBA::string_free(reason);
501 Engines::Container_var container(launchModeType->
getContainer(askingNode));
502 const char *what=
"/";
503 CORBA::String_var corbaStr(container->name());
504 std::string
ret(corbaStr);
507 std::string::size_type
i=ret.find_first_of(what,0);
508 i=ret.find_first_of(what, i==std::string::npos ? i:i+1);
509 if(i!=std::string::npos)
510 return ret.substr(i+1);
514 return "Not placed yet !!!";
521 Engines::Container_var container(launchModeType->
getContainer(askingNode));
524 CORBA::String_var corbaStr(container->name());
525 std::string
ret(corbaStr);
530 return "Unknown_placement";
534 return "Not_placed_yet";