From: rnv Date: Tue, 13 Jun 2017 10:01:34 +0000 (+0300) Subject: Merge multi-study removal branch. X-Git-Tag: V9_0_0~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=49b47d59a19c61558557bf82d10b56264afa7af0;p=modules%2Fyacs.git Merge multi-study removal branch. --- 49b47d59a19c61558557bf82d10b56264afa7af0 diff --cc src/runtime/SalomeContainerTools.cxx index 204187820,aaf96813f..6f785c853 --- a/src/runtime/SalomeContainerTools.cxx +++ b/src/runtime/SalomeContainerTools.cxx @@@ -43,251 -42,23 +43,251 @@@ using namespace YACS::ENGINE; -SalomeContainerTools::SalomeContainerTools() +/*! + * \param [in] compoNames + * \param [in,out] shutdownLevel + */ +void SalomeContainerToolsBase::Start(const std::vector& compoNames, SalomeContainerHelper *schelp, SalomeContainerToolsBase& sct, int& shutdownLevel, const Container *cont, const Task *askingNode) { - /* Init ContainerParameters */ - SALOME_LifeCycleCORBA::preSet(_params); + CORBA::ORB_ptr orb(getSALOMERuntime()->getOrb()); + SALOME_NamingService ns; + try + { + ns.init_orb(orb); + } + catch(SALOME_Exception& e) + { + throw Exception("SalomeContainer::start : Unable to contact the SALOME Naming Service"); + } + CORBA::Object_var obj(ns.Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS)); + Engines::ContainerManager_var contManager(Engines::ContainerManager::_narrow(obj)); + + bool isEmptyName; + std::string str(sct.getNotNullContainerName(cont,askingNode,isEmptyName)); + DEBTRACE("SalomeContainer::start " << str <<";"<< sct.getHostName() <<";"<< schelp->getType()); + + // Finalize parameters with components found in the container + + for(std::vector::const_iterator iter=compoNames.begin();iter!=compoNames.end();iter++) + sct.addToComponentList(*iter); + + Engines::ContainerParameters myparams(sct.getParameters()); + { + std::string dftLauchMode(schelp->getDftLaunchMode()); + myparams.mode=CORBA::string_dup(dftLauchMode.c_str()); + } + + //If a container_name is given try to find an already existing container in naming service + //If not found start a new container with the given parameters + if (dynamic_cast(schelp) && !isEmptyName) + { + myparams.mode=CORBA::string_dup("getorstart"); + } + + if (isEmptyName) + { + shutdownLevel=1; + } + //sct.setContainerName(str); + SetContainerNameOf(myparams,str); + Engines::Container_var trueCont(Engines::Container::_nil()); + if(!isEmptyName && shutdownLevel==999) + { + //Make this only the first time start is called (_shutdownLevel==999) + //If the container is named, first try to get an existing container + //If there is an existing container use it and set the shutdown level to 3 + //If there is no existing container, try to launch a new one and set the shutdown level to 2 + myparams.mode="get"; + try + { + trueCont=contManager->GiveContainer(myparams); + } + catch( const SALOME::SALOME_Exception& ex ) + { + std::string msg="SalomeContainer::start : no existing container : "; + msg += '\n'; + msg += ex.details.text.in(); + DEBTRACE( msg ); + } + catch(...) + { + } + + if(!CORBA::is_nil(trueCont)) + { + shutdownLevel=3; + DEBTRACE( "container found: " << str << " " << _shutdownLevel ); + } + else + { + shutdownLevel=2; + myparams.mode="start"; + DEBTRACE( "container not found: " << str << " " << _shutdownLevel); + } + } + + if(CORBA::is_nil(trueCont)) + try + { + // --- GiveContainer is used in batch mode to retreive launched containers, + // and is equivalent to StartContainer when not in batch. + trueCont=contManager->GiveContainer(myparams); + } + catch( const SALOME::SALOME_Exception& ex ) + { + std::string msg="SalomeContainer::start : Unable to launch container in Salome : "; + msg += '\n'; + msg += ex.details.text.in(); + throw Exception(msg); + } + catch(CORBA::COMM_FAILURE&) + { + throw Exception("SalomeContainer::start : Unable to launch container in Salome : CORBA Comm failure detected"); + } + catch(CORBA::Exception&) + { + throw Exception("SalomeContainer::start : Unable to launch container in Salome : Unexpected CORBA failure detected"); + } + + if(CORBA::is_nil(trueCont)) + throw Exception("SalomeContainer::start : Unable to launch container in Salome. Check your CatalogResources.xml file"); + + schelp->setContainer(askingNode,trueCont); + + CORBA::String_var containerName(trueCont->name()),hostName(trueCont->getHostName()); + std::cerr << "SalomeContainer launched : " << containerName << " " << hostName << " " << trueCont->getPID() << std::endl; } -SalomeContainerTools::SalomeContainerTools(const SalomeContainerTools& other):_params(other._params),_propertyMap(other._propertyMap) +CORBA::Object_ptr SalomeContainerToolsBase::LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode) { + DEBTRACE("SalomeContainer::loadComponent "); + const ComponentInstance *inst(askingNode?askingNode->getComponent():0); + { + YACS::BASES::AutoLocker alck(cont);//To be sure + if(!cont->isAlreadyStarted(askingNode)) + cont->start(askingNode); + } + if(!inst) + throw Exception("SalomeContainerTools::LoadComponent : no instance of component in the task requesting for a load of its component !"); + CORBA::Object_ptr objComponent=CORBA::Object::_nil(); + { + YACS::BASES::AutoLocker alck(cont);//To be sure + std::string compoName(inst->getCompoName()); + Engines::Container_var container(launchModeType->getContainer(askingNode)); + + char *reason; + bool isLoadable(container->load_component_Library(compoName.c_str(), reason)); + if(isLoadable) + objComponent=CreateComponentInstance(cont,container,inst); + } + return objComponent; } -void SalomeContainerTools::clearProperties() +CORBA::Object_ptr SalomeContainerToolsBase::CreateComponentInstance(Container *cont, Engines::Container_ptr contPtr, const ComponentInstance *inst) +{ + if(!inst) + throw Exception("SalomeContainerTools::CreateComponentInstance : no instance of component in the task requesting for a load of its component !"); + char *reason(0); + std::string compoName(inst->getCompoName()); + CORBA::Object_ptr objComponent=CORBA::Object::_nil(); + int studyid(1); + Proc* p(cont->getProc()); + if(p) + { + std::string value(p->getProperty("DefaultStudyID")); + if(!value.empty()) + studyid= atoi(value.c_str()); + } + // prepare component instance properties + Engines::FieldsDict_var env(new Engines::FieldsDict); + std::map properties(inst->getProperties()); + if(p) + { + std::map procMap=p->getProperties(); + properties.insert(procMap.begin(),procMap.end()); + } + + std::map::const_iterator itm; + env->length(properties.size()); + int item=0; + for(itm = properties.begin(); itm != properties.end(); ++itm, item++) + { + DEBTRACE("envname="<first<<" envvalue="<< itm->second); + env[item].key= CORBA::string_dup(itm->first.c_str()); + env[item].value <<= itm->second.c_str(); + } + - objComponent=contPtr->create_component_instance_env(compoName.c_str(), studyid, env, reason); ++ objComponent=contPtr->create_component_instance_env(compoName.c_str(), env, reason); + if(CORBA::is_nil(objComponent)) + { + std::string text="Error while trying to create a new component: component '"+ compoName; + text=text+"' is not installed or it's a wrong name"; + text += '\n'; + text += reason; + CORBA::string_free(reason); + throw Exception(text); + } + return objComponent; +} + +std::string SalomeContainerToolsBase::GetPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode) +{ + if(cont->isAlreadyStarted(askingNode)) + { + Engines::Container_var container(launchModeType->getContainer(askingNode)); + const char *what="/"; + CORBA::String_var corbaStr(container->name()); + std::string ret(corbaStr); + + //Salome FOREVER ... + std::string::size_type i=ret.find_first_of(what,0); + i=ret.find_first_of(what, i==std::string::npos ? i:i+1); + if(i!=std::string::npos) + return ret.substr(i+1); + return ret; + } + else + return "Not placed yet !!!"; +} + +std::string SalomeContainerToolsBase::GetFullPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode) +{ + if(cont->isAlreadyStarted(askingNode)) + { + Engines::Container_var container(launchModeType->getContainer(askingNode)); + try + { + CORBA::String_var corbaStr(container->name()); + std::string ret(corbaStr); + return ret; + } + catch(...) + { + return "Unknown_placement"; + } + } + else + return "Not_placed_yet"; +} + +void SalomeContainerToolsBase::SetContainerNameOf(Engines::ContainerParameters& params, const std::string& name) +{ + params.container_name=CORBA::string_dup(name.c_str()); +} + + +///////////////////////////////// + +SalomeContainerToolsInter::SalomeContainerToolsInter(const SalomeContainerToolsInter& other):_propertyMap(other._propertyMap) +{ +} + +void SalomeContainerToolsInter::clearProperties() { _propertyMap.clear(); - _params=Engines::ContainerParameters(); } -std::string SalomeContainerTools::getProperty(const std::string& name) const +std::string SalomeContainerToolsInter::getProperty(const std::string& name) const { std::map::const_iterator it(_propertyMap.find(name)); if(it!=_propertyMap.end())