diff options
Diffstat (limited to 'modules/CIAO/ciao/Deployment/Handlers/Home_Handler.cpp')
-rw-r--r-- | modules/CIAO/ciao/Deployment/Handlers/Home_Handler.cpp | 377 |
1 files changed, 377 insertions, 0 deletions
diff --git a/modules/CIAO/ciao/Deployment/Handlers/Home_Handler.cpp b/modules/CIAO/ciao/Deployment/Handlers/Home_Handler.cpp new file mode 100644 index 00000000000..877b88a137b --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Home_Handler.cpp @@ -0,0 +1,377 @@ +// $Id$ + +#include "Home_Handler.h" +#include "ciao/Logger/Log_Macros.h" +#include "ciao/ComponentServer/CIAO_PropertiesC.h" +#include "ciao/Containers/Container_BaseC.h" +#include "CIAO_State.h" + +namespace CIAO +{ + Home_Handler_i::Home_Handler_i (void) + { + CIAO_TRACE ("Home_Handler_i::Home_Handler_i"); + } + + // Destructor + Home_Handler_i::~Home_Handler_i (void) + { + CIAO_TRACE ("Home_Handler_i::~Home_Handler_i"); + } + + + char * + Home_Handler_i::instance_type (void) + { + CIAO_TRACE ("Home_Handler_i::instance_type"); + return CORBA::string_dup ("edu.dre.vanderbilt.dre.CCM.Home"); + } + + + void + Home_Handler_i::install_instance (const ::Deployment::DeploymentPlan &plan, + ::CORBA::ULong instanceRef, + ::CORBA::Any_out instance_reference) + { + CIAO_TRACE ("Home_Handler_i::install_instance"); + + const ::Deployment::InstanceDeploymentDescription &idd (plan.instance[instanceRef]); + const ::Deployment::MonolithicDeploymentDescription &mdd (plan.implementation[idd.implementationRef]); + + DAnCE::Utility::PROPERTY_MAP *pmap; + + ACE_NEW_THROW_EX (pmap, + DAnCE::Utility::PROPERTY_MAP (idd.configProperty.length () + + mdd.execParameter.length ()), + CORBA::NO_MEMORY ()); + + Deployment_Common::Instance_Info info; + info.name = idd.name.in (); + info.pmap.reset (pmap); + + + DAnCE::Utility::build_property_map (*pmap, + mdd.execParameter); + DAnCE::Utility::build_property_map (*pmap, + idd.configProperty); + + CORBA::String_var exec_art, exec_entry, svnt_art, svnt_entry, cont_id; + + using namespace CIAO::Deployment; + CORBA::Any val; + const char *tmp; + + if ((pmap->find (SVNT_ENTRYPT, val)) == 0) + { + val >>= tmp; + svnt_entry = tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found Servant entrypoint %C\n", svnt_entry.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Error: No Servant entrypoint (%C) provided, aborting installation\n", + SVNT_ENTRYPT)); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "No servant entrypoint identified."); + } + + if (pmap->find (SVNT_ARTIFACT, val) == 0) + { + val >>= tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found Servant artifact %C\n", tmp)); + svnt_art = Deployment_Common::get_implementation (tmp, plan); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Error: No Servant artifact provided, aborting installation\n")); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "No servant artifact identified."); + } + + + if (pmap->find (EXEC_ARTIFACT, val) == 0) + { + val >>= tmp; + exec_art = Deployment_Common::get_implementation (tmp, plan); + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found executor artifact: %C\n", exec_art.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Error: No Executor artifact provided, aborting installation\n")); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "No executory artifact identified.\n"); + } + + if (pmap->find (HOME_FACTORY, val) == 0) + { + val >>= tmp; + exec_entry = tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found executor entrypoint: %C\n", exec_entry.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Error: No Executor artifact provided, aborting installation\n")); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "No executor entrypoint provided\n"); + } + + if (pmap->find (CONTAINER_ID, val) == 0) + { + val >>= tmp; + cont_id = tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found executor entrypoint: %C\n", exec_entry.in ())); + } + else + { + CIAO_ERROR (4, (LM_INFO, CLINFO + "Home_Handler_i::install_instance - " + "No container provided, using default container for instance <%C>\n", + idd.name.in ())); + cont_id = ""; + } + + ::CIAO::Container_var container = DEPLOYMENT_STATE::instance ()->fetch_container (cont_id); + + if (CORBA::is_nil (container)) + { + CIAO_ERROR (1, (LM_INFO, CLINFO + "Home_Handler_i::install_instance - " + "Container with Id <%C> not installed, aborting.\n", + cont_id.in ())); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "Invalid container\n"); + } + + Components::CCMHome_var home_ref; + + try + { + home_ref = container->install_home (exec_art, + exec_entry, + svnt_art, + svnt_entry, + idd.name.in ()); + } + catch (::CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Caught CORBA exception <%C>\n", + ex._info ().c_str ())); + throw ::Deployment::StartError (idd.name.in (), + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Caught unknown C++ exception\n")); + throw ::Deployment::StartError (idd.name.in (), + "Unknown C++ exception\n"); + } + + if (CORBA::is_nil (home_ref)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Container provided nil object reference for home.\n")); + throw ::Deployment::StartError (idd.name.in (), + "Container provided nil object reference"); + } + + this->instances_[idd.name.in ()] = info; + + DEPLOYMENT_STATE::instance ()->add_home (idd.name.in (), cont_id, home_ref.in ()); + + CORBA::Any *retval; + ACE_NEW_THROW_EX (retval, + CORBA::Any (), + CORBA::NO_MEMORY ()); + + (*retval) <<= home_ref; + instance_reference = retval; + } + + + void + Home_Handler_i::activate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &) + { + CIAO_TRACE ("Home_Handler_i::activate_instance"); + // no activation needed. + } + + void + Home_Handler_i::passivate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &) + { + CIAO_TRACE ("Home_Handler_i::passivate_instance"); + // no passivation needed. + } + + void + Home_Handler_i::remove_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any & instance_reference) + { + CIAO_TRACE ("Home_Handler_i::remove_instance"); + + const char *name = plan.instance[instanceRef].name.in (); + Deployment_Common::INSTANCES::iterator instance + = this->instances_.find (name); + + if (instance == this->instances_.end ()) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::remove_instance - " + "Instructed to remove unknown home instance <%C>\n", + name)); + throw ::Deployment::StopError (name, + "Wrong instance handler for home instance\n"); + } + + CIAO_DEBUG (8, (LM_DEBUG, CLINFO + "Home_Handler_i::remove_instance - " + "Attempting removal of home instance <%C>\n", + name)); + + Components::CCMHome_var ref; + + if (!(instance_reference >>= ref) || + CORBA::is_nil (ref)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::remove_instance - " + "Unable to convert provided instance reference to CCMHome " + "while removing instance <%C>\n", + name)); + throw ::Deployment::StopError (name, + "Unable to narrow reference to CCMHome"); + } + + CORBA::Any val; + const char *cont_id; + + if (instance->second.pmap->find (Deployment::CONTAINER_ID, val) == 0) + { + val >>= cont_id; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::remove_instance - " + "Found home container: %C\n", cont_id)); + } + else + { + CIAO_ERROR (4, (LM_INFO, CLINFO + "Home_Handler_i::remove_instance - " + "No container provided, using default container for instance <%C>\n", + name)); + cont_id = ""; + } + + ::CIAO::Container_var container = DEPLOYMENT_STATE::instance ()->fetch_container (cont_id); + + if (CORBA::is_nil (container)) + { + CIAO_ERROR (1, (LM_INFO, CLINFO + "Home_Handler_i::remove_instance - " + "Container with Id <%C> not installed, aborting.\n", + cont_id)); + throw ::Deployment::StopError (name, + "Invalid container\n"); + } + + try + { + container->uninstall_home (ref); + } + catch (CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::remove_instance - " + "Caught CORBA exception <%C>\n", + ex._info ().c_str ())); + throw ::Deployment::StopError (name, + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::remove_instance - " + "Caught unknown C++ exception\n")); + throw ::Deployment::StopError (name, + "Unknown C++ exception\n"); + } + + this->instances_.erase (instance); + + CIAO_DEBUG (4, (LM_INFO, CLINFO + "Home_Handler_i::remove_instance - " + "Instance <%C> successfully removed\n", + name)); + } + + void + Home_Handler_i::provide_endpoint_reference (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong, + ::CORBA::Any_out) + { + CIAO_TRACE ("Home_Handler_i::provide_endpoint_reference"); + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::provide_endpoint_reference - " + "Unable to provide any endpoints.\n")); + throw CORBA::NO_IMPLEMENT (); + } + + void + Home_Handler_i::connect_instance (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong, + const ::CORBA::Any &) + { + CIAO_TRACE ("Home_Handler_i::connect_instance"); + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::connect_instance - ", + "No connections allowed for homes.\n")); + throw CORBA::NO_IMPLEMENT (); + } + + + void + Home_Handler_i::disconnect_instance (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + { + CIAO_TRACE ("Home_Handler_i::disconnect_instance"); + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::disconnect_instance - ", + "No connections allowed for homes.\n")); + throw CORBA::NO_IMPLEMENT (); + } + + + void + Home_Handler_i::instance_configured (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + { + CIAO_TRACE ("Home_Handler_i::instance_configured"); + // nothing to be done + } +} |