diff options
author | jai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2004-07-01 20:50:32 +0000 |
---|---|---|
committer | jai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2004-07-01 20:50:32 +0000 |
commit | 0b0bf48b0a2ff7fbe00769ac257511f8a175d119 (patch) | |
tree | 92ff49c4e955668965a2cb70e6c7989cd1089cb4 | |
parent | 9b0f2409db24a92dc2ebcfd47f514832e0f99c3e (diff) | |
download | ATCD-0b0bf48b0a2ff7fbe00769ac257511f8a175d119.tar.gz |
Thu Jul 1 15:47:45 2004 Jaiganesh B <jai@dre.vanderbilt.edu>
17 files changed, 1784 insertions, 0 deletions
diff --git a/TAO/CIAO/ChangeLog b/TAO/CIAO/ChangeLog index 8ecf8a8ac64..7ced955a2d6 100644 --- a/TAO/CIAO/ChangeLog +++ b/TAO/CIAO/ChangeLog @@ -1,3 +1,25 @@ +Thu Jul 1 15:47:45 2004 Jaiganesh B <jai@dre.vanderbilt.edu> + + * DAnCE/NodeApplication/NodeApplication.cpp: + * DAnCE/NodeApplication/NodeApplication.mpc: + * DAnCE/NodeApplicationManager/CIAO_NAM_Export.h: + * DAnCE/NodeApplicationManager/ImplementationInfo.cpp: + * DAnCE/NodeApplicationManager/ImplementationInfo.h: + * DAnCE/NodeApplicationManager/NodeApplicationManager.mpc: + * DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.cpp: + * DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.h: + * DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.inl: + * DAnCE/NodeManager/NodeDaemon.idl: + * DAnCE/NodeManager/NodeDaemon.mpc: + * DAnCE/NodeManager/NodeDaemon_Impl.cpp: + * DAnCE/NodeManager/NodeDaemon_Impl.h: + * DAnCE/NodeManager/NodeDaemon_Impl.inl: + * DAnCE/NodeManager/NodeDaemon_stub_export.h: + * DAnCE/NodeManager/Node_Daemon.cpp: + + Checked in the NodeApplication, NodeApplicationManager + and NodeManager code. + Thu Jul 1 15:45:48 2004 Jaiganesh B <jai@dre.vanderbilt.edu> * DAnCE/RepositoryManager/RepositoryManager.idl: diff --git a/TAO/CIAO/DAnCE/NodeApplication/NodeApplication.cpp b/TAO/CIAO/DAnCE/NodeApplication/NodeApplication.cpp new file mode 100644 index 00000000000..945f8312f2a --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeApplication/NodeApplication.cpp @@ -0,0 +1,231 @@ +// $Id$ + +/** + * @file NodeApplication.cpp + * + * @brief CIAO's NodeApplication implementation + * + */ + +#include "NodeApplication_Impl.h" +#include "NodeApplication_CallBackC.h" +#include "ciao/Server_init.h" +#include "ciao/CIAO_common.h" +#include "ace/SString.h" +#include "ace/Get_Opt.h" +#include "ace/Env_Value_T.h" +#include "ace/Sched_Params.h" +#include "ace/OS_NS_errno.h" + +char *ior_file_name_ = 0; +char *callback_ior_ = 0; +int use_callback = 1; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "nk:o:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'n': + use_callback = 0; + break; + + case 'o': // get the file name to write to + ior_file_name_ = get_opts.opt_arg (); + break; + + case 'k': // get the activator callback IOR + callback_ior_ = get_opts.opt_arg (); + break; + + case '?': // display help for use of the server. + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s\n" + "-n Do not use Callback (for testing)\n" + "-o <ior_output_file>\n" + "-k <NodeApplicationManager_callback_ior>\n" + "\n", + argv [0]), + -1); + } + + if (use_callback && callback_ior_ == 0) + ACE_ERROR_RETURN ((LM_ERROR, "Callback IOR to NodeApplicationManager is required.\n"), + -1); + + return 0; +} + +int +main (int argc, char *argv[]) +{ + //@@ I will ignor this config done at WashU for now. --Tao + // Define CIAO_FIFO_SCHED=1 to run component server in FIFO_SCHED class + /* ACE_Env_Value<int> envar ("CIAO_FIFO_SCHED", 0); + if (envar != 0) + { + int priority = + (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO) + + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2; + priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO, + priority); + // Enable FIFO scheduling, e.g., RT scheduling class on Solaris. + + if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO, + priority, + ACE_SCOPE_PROCESS)) != 0) + { + if (ACE_OS::last_error () == EPERM) + { + ACE_DEBUG ((LM_DEBUG, + "ComponentServer (%P|%t): user is not superuser, " + "test runs in time-shared class\n")); + } + else + ACE_ERROR ((LM_ERROR, + "ComponentServer (%P|%t): sched_params failed\n")); + } + }*/ + + ACE_TRY_NEW_ENV + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init (argc, + argv, + "" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CIAO::Server_init (orb.in ()); + + if (parse_args (argc, argv) != 0) + return -1; + + // Get reference to Root POA. + CORBA::Object_var obj + = orb->resolve_initial_references ("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POA_var poa + = PortableServer::POA::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Activate POA manager + PortableServer::POAManager_var mgr + = poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + mgr->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + CIAO::NodeApplication_Impl *nodeapp_servant; + + ACE_NEW_RETURN (nodeapp_servant, + CIAO::NodeApplication_Impl (orb.in (), + poa.in ()), + -1); + + PortableServer::ServantBase_var safe_servant (nodeapp_servant); + + // CONFIGURING NodeApplication + PortableServer::ObjectId_var nodeapp_oid + = poa->activate_object (nodeapp_servant + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + obj = poa->id_to_reference (nodeapp_oid.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Deployment::NodeApplication_var nodeapp_obj = + Deployment::NodeApplication::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (nodeapp_obj.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to activate NodeApplication object\n"), + -1); + + + Deployment::NodeApplicationManager_var nodeapp_man; + Deployment::Properties_var prop = new Deployment::Properties; + + if (use_callback) + { + obj = orb->string_to_object (callback_ior_ + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CIAO::NodeApplication_Callback_var nam_callback + = CIAO::NodeApplication_Callback::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Deployment::Properties_out properties_out (prop.out ()); + + nodeapp_man + = nam_callback->register_node_application (nodeapp_obj.in (), + properties_out + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + + /** @@ We need to call NodeApplication servant's init method. + * But it's not sure to me where exactly we can get the + * Properties needed by the init method at this moment. There are two + * ways to set the property of the NodeApplication: + * 1. call init remotely from NodeApplicationManager + * 2. call init locally on the servant of NodeApplication. + */ + + if (nodeapp_servant->init (ACE_ENV_SINGLE_ARG_PARAMETER)) + { + ACE_DEBUG ((LM_DEBUG, "NodeApplication Failed on creating and\ + initializing the session container!")); + return 1; + } + ACE_TRY_CHECK; + + CORBA::String_var str = orb->object_to_string (nodeapp_obj.in () + ACE_ENV_ARG_PARAMETER); + + CIAO::Utility::write_IOR (ior_file_name_, str.in ()); + + // End Deployment part + if (CIAO::debug_level () > 10) + { + ACE_DEBUG ((LM_INFO, "NodeApplication IOR: %s\n", str.in ())); + + ACE_DEBUG ((LM_DEBUG, + "Running NodeApplication...\n")); + } + + // Run the main event loop for the ORB. + orb->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + orb->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "NodeApp::main\t\n"); + return 1; + } + ACE_ENDTRY; + + ACE_DEBUG ((LM_DEBUG, "This NodeApplication is quitting now!\n")); + return 0; +} diff --git a/TAO/CIAO/DAnCE/NodeApplication/NodeApplication.mpc b/TAO/CIAO/DAnCE/NodeApplication/NodeApplication.mpc new file mode 100644 index 00000000000..ab573cf44d0 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeApplication/NodeApplication.mpc @@ -0,0 +1,13 @@ +// -*- MPC -*- +// $Id$ + +project(NodeApplication): ciao_server_dnc, ciao_deployment_stub { + exename = NodeApplication + + IDL_Files { + } + + Source_Files { + NodeApplication.cpp + } +} diff --git a/TAO/CIAO/DAnCE/NodeApplicationManager/CIAO_NAM_Export.h b/TAO/CIAO/DAnCE/NodeApplicationManager/CIAO_NAM_Export.h new file mode 100644 index 00000000000..bdeb544afc4 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeApplicationManager/CIAO_NAM_Export.h @@ -0,0 +1,54 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_NAM +// ------------------------------ +#ifndef CIAO_NAM_EXPORT_H +#define CIAO_NAM_EXPORT_H + +#include "ace/config-all.h" + +#if !defined (CIAO_NAM_HAS_DLL) +# define CIAO_NAM_HAS_DLL 1 +#endif /* ! CIAO_NAM_HAS_DLL */ + +#if defined (CIAO_NAM_HAS_DLL) && (CIAO_NAM_HAS_DLL == 1) +# if defined (CIAO_NAM_BUILD_DLL) +# define CIAO_NAM_Export ACE_Proper_Export_Flag +# define CIAO_NAM_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_NAM_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_NAM_BUILD_DLL */ +# define CIAO_NAM_Export ACE_Proper_Import_Flag +# define CIAO_NAM_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_NAM_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_NAM_BUILD_DLL */ +#else /* CIAO_NAM_HAS_DLL == 1 */ +# define CIAO_NAM_Export +# define CIAO_NAM_SINGLETON_DECLARATION(T) +# define CIAO_NAM_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_NAM_HAS_DLL == 1 */ + +// Set CIAO_NAM_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_NAM_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_NAM_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_NAM_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_NAM_NTRACE */ + +#if (CIAO_NAM_NTRACE == 1) +# define CIAO_NAM_TRACE(X) +#else /* (CIAO_NAM_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_NAM_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_NAM_NTRACE == 1) */ + +#endif /* CIAO_NAM_EXPORT_H */ + +// End of auto generated file. diff --git a/TAO/CIAO/DAnCE/NodeApplicationManager/ImplementationInfo.cpp b/TAO/CIAO/DAnCE/NodeApplicationManager/ImplementationInfo.cpp new file mode 100644 index 00000000000..e3393d17f61 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeApplicationManager/ImplementationInfo.cpp @@ -0,0 +1,126 @@ +//$Id$ +#ifndef CIAO_IMPLEMENTATION_INFO_C +#define CIAO_IMPLEMENTATION_INFO_C + +#include "ImplementationInfo.h" + +// Specialized operation that we will use for now. +namespace CIAO +{ + bool operator<< (Deployment::ImplementationInfos & info, + const Deployment::DeploymentPlan & plan) + { + // @@ (OO) Since leng is a constant, please declare it as such, + // i.e. "const CORBA::ULong len = ...", to improve "const + // correctness". + const CORBA::ULong len = plan.instance.length (); + info.length (len); + + for (CORBA::ULong i = 0; i < len; ++i) + { + const Deployment::InstanceDeploymentDescription & inst = + plan.instance[i]; + + // Get the component instance name. + info[i].component_instance_name = inst.name.in (); + + const Deployment::MonolithicDeploymentDescription & impl = + plan.implementation[inst.implementationRef]; + + const CORBA::ULong artifact_num = impl.artifactRef.length (); + + // Copy Component instance related Properties if there is any. + if (inst.configProperty.length () > 0) + { + info[i].component_config = inst.configProperty; + } + + // For svnt artifact + for (CORBA::ULong j = 0; j < artifact_num; ++j) + { + const Deployment::ArtifactDeploymentDescription & arti = + plan.artifact[ impl.artifactRef[j] ]; + + ACE_CString tmp = arti.name.in (); + ssize_t pos; + + //@@ Note: I am not checking for redundancy here. Maybe + // the modeling tool should make sure of + // uniqueness. + if ((pos = tmp.find ("_svnt")) != ACE_CString::npos || + (pos = tmp.find ("_Svnt")) != ACE_CString::npos) + { + if (arti.location.length() < 1 ) + { + ACE_DEBUG ((LM_DEBUG, "Servant Artifact must have a location!\n")); + return 0; + } + // Cpoy the servant dll/so name. + // @@ Note: I ignore all the other locations except the first one. + info[i].servant_dll = CORBA::string_dup (arti.location[0].in ()); + + // Get the entry point. + const CORBA::ULong prop_length = arti.execParameter.length (); + for (CORBA::ULong prop_num = 0; + prop_num < prop_length; + ++prop_num) + { + ACE_CString name (arti.execParameter[prop_num].name.in ()); + if (name == ACE_CString ("entryPoint")) + { + const char * entry; + (arti.execParameter[prop_num].value) >>= entry; + info[i].servant_entrypt = CORBA::string_dup (entry); + } + else + { + ACE_DEBUG ((LM_DEBUG, "Found unknown property in the artifact!\n")); + ACE_DEBUG ((LM_DEBUG, "We only support entrypoint at this point in CIAO.\n")); + } + } + } + // As one can see, code is duplicated here. I will come back for this later. + // For exec artifact + if ((pos = tmp.find ("_exec")) != ACE_CString::npos || + (pos = tmp.find ("_Exec")) != ACE_CString::npos) + { + if (arti.location.length() < 1 ) + { + ACE_DEBUG ((LM_DEBUG, "Executor Artifact must have a location!\n")); + return 0; + } + // Cpoy the servant dll/so name. + // @@ Note: I ignore all the other locations except the first one. + info[i].executor_dll = CORBA::string_dup (arti.location[0].in ()); + + // Get the entry point. + const CORBA::ULong prop_length = arti.execParameter.length (); + for (CORBA::ULong prop_num = 0; + prop_num < prop_length; + ++prop_num) + { + ACE_CString name (arti.execParameter[prop_num].name.in ()); + if (name == ACE_CString ("entryPoint")) + { + const char * entry; + (arti.execParameter[prop_num].value) >>= entry; + info[i].executor_entrypt = CORBA::string_dup (entry); + } + else + { + ACE_DEBUG ((LM_DEBUG, "Found unknown property in the artifact!\n")); + ACE_DEBUG ((LM_DEBUG, "We only support entrypoint at this point in CIAO.\n")); + } + } + } + + else + // We see artifact other than servant/executor and we ignore them. + continue; + } + } + return 1; + } +} + +#endif /* CIAO_IMPLEMENTATION_INFO_C */ diff --git a/TAO/CIAO/DAnCE/NodeApplicationManager/ImplementationInfo.h b/TAO/CIAO/DAnCE/NodeApplicationManager/ImplementationInfo.h new file mode 100644 index 00000000000..5bd6c8022ca --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeApplicationManager/ImplementationInfo.h @@ -0,0 +1,73 @@ +//$Id$ +/* -*- C++ -*- */ +/*************************************************************** + * @file ImplementationInfo.h + * + * @brief This file defines some helper functions for paring the + * Component ImplementationInfo and properties from + * the plan. + * + * @author Tao Lu <lu@dre.vanderbilt.edu> + ***************************************************************/ + +#ifndef IMPLEMENTATIONIFO_H +#define IMPLEMENTATIONIFO_H +#include /**/ "ace/pre.h" + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +//#include "Deployment_CoreS.h" +//#include "ace/os_types.h" +#include "ciao/DeploymentC.h" + +//@@ I wish we could have precompiled header support soon!!! + +// This mthod is a helper function to parse the plan into the +// ImplementationInfo struct. + +namespace CIAO +{ + bool operator<<(Deployment::ImplementationInfos & info, + const Deployment::DeploymentPlan & plan); +} + +/* +// Helper function to parse the property. +template < typename OUTPUT> +bool operator<< (OUTPUT & info, + const Deployment::Property & property); + +// Sepcialized for the entry point property +template < > +bool operator<< < TAO_String_Manager> + (TAO_String_Manager & info, + const Deployment::Property & property) +{ + const char * tmp; + if (property.value >>= tmp) + info = CORBA::string_duplicate (tmp); + else + { + ACE_DEBUG ((LM_DEBUG, "Property::value >>= TAO_String_Manager failed!\n")); + return 0; + } + + return 1; +} +*/ + +//#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +//#include "ImplementationInfo.cpp" +//#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +//#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +//#pragma implementation ("ImplementationInfo.cpp") +//#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + + +#include /**/ "ace/post.h" +#endif /* IMPLEMENTATIONIFO_H */ diff --git a/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager.mpc b/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager.mpc new file mode 100644 index 00000000000..0adbadae578 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager.mpc @@ -0,0 +1,14 @@ +// -*- MPC -*- +// $Id$ + +project(NodeApplicationManager): ciao_server_dnc, ciao_deployment_svnt, ciao_deployment_stub { + + sharedname = NodeApplicationManager + idlflags += -Wb,export_include=CIAO_NAM_Export.h -Wb,export_macro=CIAO_NAM_Export + dynamicflags = CIAO_NAM_BUILD_DLL + + Source_Files { + NodeApplicationManager_Impl.cpp + ImplementationInfo.cpp + } +} diff --git a/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.cpp b/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.cpp new file mode 100644 index 00000000000..f0abf616576 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.cpp @@ -0,0 +1,367 @@ +// $Id$ + +#include "NodeApplicationManager_Impl.h" +#include "ace/Process.h" +#include "ace/OS_NS_stdio.h" + +#if !defined (__ACE_INLINE__) +# include "NodeApplicationManager_Impl.inl" +#endif /* __ACE_INLINE__ */ +CIAO::NodeApplicationManager_Impl::~NodeApplicationManager_Impl () +{ +} + +Deployment::NodeApplicationManager_ptr +CIAO::NodeApplicationManager_Impl:: +init (const char *nodeapp_location, + const CORBA::ULong delay, + const Deployment::DeploymentPlan & plan, + const PortableServer::POA_ptr callback_poa + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::InvalidProperty)) +{ + ACE_TRY + { + if (nodeapp_location == 0) + ACE_THROW (CORBA::BAD_PARAM ()); + + if (spawn_delay_ == 0) + ACE_THROW (CORBA::BAD_PARAM ()); + + this->nodeapp_path_.set (nodeapp_location); + this->spawn_delay_ = delay; + + // Make a copy of the plan for later usage. + this->plan_ = plan; + + // Cache the call back POA for callback object. + this->callback_poa_ = PortableServer::POA::_duplicate (callback_poa); + + // Activate the ourself. + PortableServer::ObjectId_var oid + = this->poa_->activate_object (this + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var obj = this->poa_->id_to_reference (oid.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // And cache the object reference. + this->objref_ = Deployment::NodeApplicationManager::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + //return this object reference + return Deployment::NodeApplicationManager::_duplicate (this->objref_.in ()); + + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "NodeApplicationManager_Impl::init\t\n"); + ACE_RE_THROW; + } + + ACE_ENDTRY; +} + +void +CIAO::NodeApplicationManager_Impl:: +parse_config_value (ACE_CString & str + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::InvalidProperty)) +{ + // The unused arg is for future improvemnts. + ACE_UNUSED_ARG (str); + + ACE_THROW ( CORBA::NO_IMPLEMENT() ); +} + +Deployment::NodeApplication_ptr +CIAO::NodeApplicationManager_Impl:: +create_node_application (const ACE_CString & options + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::StartError, + Deployment::InvalidProperty)) +{ + Deployment::NodeApplication_var retval; + Deployment::Properties_var prop; + + ACE_NEW_THROW_EX (prop, + Deployment::Properties, + CORBA::INTERNAL ()); + ACE_CHECK_RETURN (Deployment::NodeApplication::_nil()); + + // @@ Create a new callback servant. + CIAO::NodeApplication_Callback_Impl * callback_servant = 0; + ACE_NEW_THROW_EX (callback_servant, + CIAO::NodeApplication_Callback_Impl (this->orb_.in (), + this->callback_poa_.in (), + this->objref_.in (), + prop.in ()), + CORBA::INTERNAL ()); + ACE_CHECK_RETURN (Deployment::NodeApplication::_nil()); + + PortableServer::ServantBase_var servant_var (callback_servant); + PortableServer::ObjectId_var cb_id + = this->callback_poa_->activate_object (callback_servant + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (Deployment::NodeApplication::_nil()); + + ACE_Process node_application; + ACE_Process_Options p_options; + + ACE_TRY + { + CORBA::Object_var cb_obj = + this->callback_poa_->id_to_reference (cb_id.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CIAO::NodeApplication_Callback_var cb = + CIAO::NodeApplication_Callback::_narrow (cb_obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::String_var cb_ior = + this->orb_->object_to_string (cb.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // spawn the new NodeApplication. + p_options.command_line ("%s -k %s" + "%s", + this->nodeapp_path_.c_str (), + cb_ior.in (), + options.c_str ()); + + p_options.avoid_zombies (1); + + if (node_application.spawn (p_options) == -1) + { + if (CIAO::debug_level () > 1) + ACE_DEBUG ((LM_ERROR, "Fail to spawn a NodeApplication process\n")); + + ACE_TRY_THROW (Components::CreateFailure ()); + } + + // wait for nodeApp to pass back its object reference. with a + // timeout value. using perform_work and stuff. + + int looping = 1; + + ACE_Time_Value timeout (this->spawn_delay_, 0); + + while (looping) + { + this->orb_->perform_work (timeout + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + retval = callback_servant->get_nodeapp_ref (); + + if (timeout == ACE_Time_Value::zero || !CORBA::is_nil (retval.in ())) + looping = 0; + } + + if (CORBA::is_nil (retval.in ())) + { + if (CIAO::debug_level () > 1) + ACE_DEBUG ((LM_ERROR, "Fail to acquire the NodeApplication object\n")); + + ACE_TRY_THROW (Components::CreateFailure ()); + } + + { + //ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0); + this->nodeapp_ = Deployment::NodeApplication::_duplicate (retval.in ()); + } + } + ACE_CATCHANY + { + this->callback_poa_->deactivate_object (cb_id.in ()); + ACE_TRY_CHECK; + + ACE_RE_THROW; + } + ACE_ENDTRY; + ACE_CHECK_RETURN (Deployment::NodeApplication::_nil ()); + + this->callback_poa_->deactivate_object (cb_id.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (Deployment::NodeApplication::_nil ()); + + if (CIAO::debug_level () > 1) + ACE_DEBUG ((LM_DEBUG, "CIAO::NodeApplicationManager_Impl::NodeApplication spawned!\n")); + + return retval._retn (); +} + +Deployment::Connections * +CIAO::NodeApplicationManager_Impl:: +create_connections (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::ResourceNotAvailable, + Deployment::StartError, + Deployment::InvalidProperty)) +{ + Deployment::Connections_var retv; + + ACE_NEW_THROW_EX (retv, + Deployment::Connections (), + CORBA::INTERNAL ()); + ACE_CHECK_RETURN (0); + + CORBA::ULong len = retv->length (); + + const Component_Iterator end (this->component_map_.end ()); + for (Component_Iterator iter (this->component_map_.begin ()); + iter != end; + ++iter) + { + // Get all the facets first + Components::FacetDescriptions_var facets = + ((*iter).int_id_)->get_all_facets (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + // Get all the event consumers + Components::ConsumerDescriptions_var consumers = + ((*iter).int_id_)->get_all_consumers (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + const CORBA::ULong facet_len = facets->length (); + const CORBA::ULong consumer_len = consumers->length (); + + retv->length (facet_len + consumer_len); + + CORBA::ULong i = 0; + for (i = 0; i < facet_len; ++i) + { + Deployment::Connection & conn = retv[len]; + conn.instanceName = (*iter).ext_id_.c_str (); + conn.portName = facets[i]->name (); + conn.kind = Deployment::Facet; + conn.endpoint = CORBA::Object::_duplicate (facets[i]->facet_ref ()); + ++len; + } + + for (i = 0; i < consumer_len; ++i) + { + Deployment::Connection & conn = retv[len]; + conn.instanceName = (*iter).ext_id_.c_str (); + conn.portName = consumers[i]->name (); + conn.kind = Deployment::EventConsumer; + conn.endpoint = CORBA::Object::_duplicate (consumers[i]->consumer ()); + ++len; + } + } + return retv._retn (); +} + +Deployment::Application_ptr +CIAO::NodeApplicationManager_Impl:: +startLaunch (const Deployment::Properties & configProperty, + Deployment::Connections_out providedReference, + CORBA::Boolean start + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::ResourceNotAvailable, + Deployment::StartError, + Deployment::InvalidProperty)) +{ + ACE_UNUSED_ARG (configProperty); + ACE_UNUSED_ARG (start); + /** + * 1. First Map properties to TAO/CIAO specific property/configurations + * 2. Necessary property checking (needed?) + * 3. Call create_nade_application to spawn new process. + * 4. Initialize the NodeApplication. + * 5. get the provided connection endpoints back and return them. + */ + + Deployment::ImplementationInfos infos; + + if (!(infos << (this->plan_))) + { + if (CIAO::debug_level () > 1) + ACE_DEBUG ((LM_DEBUG, "Failed to create Component Implementation Infos!\n")); + + ACE_THROW_RETURN (Deployment::StartError (), + Deployment::Application::_nil()); + } //@@ I am not sure about which exception to throw. I will come back to this. + + // Now spawn the NodeApplication process. + ACE_CString cmd_option (""); + Deployment::NodeApplication_var tmp = + create_node_application (cmd_option.c_str () ACE_ENV_ARG_PARAMETER); + + ACE_CHECK_RETURN (Deployment::Application::_nil()); + + // This is what we will get back, a sequence of compoent object refs. + Deployment::ComponentInfos_var comp_info; + + // For debugging. + if (CIAO::debug_level () > 1) + { + const CORBA::ULong info_len = infos.length (); + for (CORBA::ULong i = 0; i < info_len; ++i) + { + ACE_DEBUG ((LM_DEBUG, "The info for installation: \n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n", + infos[i].component_instance_name.in (), + infos[i].executor_dll.in (), + infos[i].executor_entrypt.in (), + infos[i].servant_dll.in (), + infos[i].servant_entrypt.in () )); + } + } + + // This will install all homes and components. + comp_info = this->nodeapp_->install (infos ACE_ENV_ARG_PARAMETER); + + ACE_CHECK_RETURN (Deployment::Application::_nil()); + + // Now fill in the map we have for the components. + const CORBA::ULong comp_len = comp_info->length (); + for (CORBA::ULong len = 0; + len < comp_len; + ++len) + { + //Since we know the type ahead of time...narrow is omitted here. + if (this->component_map_. + bind (comp_info[len].component_instance_name.in(), + Components::CCMObject::_duplicate (comp_info[len].component_ref.in()))) + ACE_THROW_RETURN (Deployment::StartError (), 0); + } + + providedReference = this->create_connections (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (Deployment::Application::_nil()); + + if (providedReference == 0) + ACE_THROW_RETURN (Deployment::StartError () , + Deployment::Application::_nil()); + + return Deployment::NodeApplication::_duplicate (this->nodeapp_.in ()); +} + + +void +CIAO::NodeApplicationManager_Impl:: +destroyApplication (Deployment::Application_ptr app + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException + , Deployment::StopError)) +{ + ACE_UNUSED_ARG (app); + + //ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_); + //@@ Since we know there is only 1 nodeapp so the passed in + // parameter is ignored for now. + if (CORBA::is_nil (this->nodeapp_.in () )) + ACE_THROW (Deployment::StopError ()); + + this->nodeapp_->remove (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; +} diff --git a/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.h b/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.h new file mode 100644 index 00000000000..a9fd79bde39 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.h @@ -0,0 +1,182 @@ +//$Id$ +// -*- C++ -*- + +//============================================================================= +/** + * @file NodeApplicationManager_Impl.h + * + * @author Tao Lu <lu@dre.vanderbilt.edu> + * + * This file contains implementation for the servant of + * Deployment::NodeApplicationManager. + */ +//============================================================================= + + +#ifndef CIAO_NODEAPPLICATIONMANAGER_IMPL_H +#define CIAO_NODEAPPLICATIONMANAGER_IMPL_H +#include /**/ "ace/pre.h" + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ciao/DeploymentS.h" +#include "CIAO_NAM_Export.h" +#include "ciao/NodeApp_CB_Impl.h" +#include "ImplementationInfo.h" +#include "ciao/CIAO_common.h" + +namespace CIAO +{ + /** + * @class NodeApplicationManager_Impl + */ + class CIAO_NAM_Export NodeApplicationManager_Impl + : public virtual POA_Deployment::NodeApplicationManager, + public virtual PortableServer::RefCountServantBase + { + public: + /// Constructor + NodeApplicationManager_Impl (CORBA::ORB_ptr o, + PortableServer::POA_ptr p); + + /*=========================================================== + * Below are operations from the NodeApplicationManager + * + *============================================================*/ + + //@@ The return type is NodeApplication_ptr actually. + virtual Deployment::Application_ptr + startLaunch (const Deployment::Properties & configProperty, + Deployment::Connections_out providedReference, + CORBA::Boolean start + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::ResourceNotAvailable, + Deployment::StartError, + Deployment::InvalidProperty)); + + //@@ Destroy the whole applicaton. + virtual void destroyApplication (Deployment::Application_ptr + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::StopError)); + + /** + * Initialize the NodeApplicationManager. The currently implementation + * of CIAO_NodeApplicationManager can only activate CIAO's own + * NodeApplication processes. You should specify the location + * (pathname) of the NodeApplication and the delay + * CIAO_NodeApplicationManager should wait (in second) for NodeApplication to + * call back. + * + * @param nodeapp_location A null-termiated char * string pointing + * to the pathname of a NodeApplication executable. + * + * @param delay instructs how long (in second) a CIAO_NodeApplicationManager + * should wait for a newly spawned NodeApplication to pass back + * its IOR. + * + * @param plan has all the information needed for the NodeAppManager to + * construct the application locally. Note, this includes the properties + * of the NodeApplication. For example, ORB config options etc. + * + * @param callback_poa contains child poa created for the callback interface. + * + * @return NodeApplicationManager_ptr. + **/ + virtual Deployment::NodeApplicationManager_ptr + init (const char *nodeapp_location, + const CORBA::ULong delay, + const Deployment::DeploymentPlan & plan, + const PortableServer::POA_ptr callback_poa + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::InvalidProperty)); + + //@@ Note: This method doesn't do duplicate. + Deployment::NodeApplicationManager_ptr get_nadeapp_manager (void); + + protected: + /// Destructor + virtual ~NodeApplicationManager_Impl (void); + + // Internal help function to create new NodeApplicationProcess + virtual Deployment::NodeApplication_ptr + create_node_application (const ACE_CString & options + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::StartError, + Deployment::InvalidProperty)); + + // Helper function to get the connection. + virtual Deployment::Connections * + create_connections (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::ResourceNotAvailable, + Deployment::StartError, + Deployment::InvalidProperty)); + + /** + * Find the configurations in the plan and prepare them to pass to the + * NodeApplication, from command line probably. + */ + void parse_config_value (ACE_CString & str + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::InvalidProperty)); + + protected: + // location of the Nodeapplication + ACE_CString nodeapp_path_; + + // Keep a pointer to the managing ORB serving this servant. + CORBA::ORB_var orb_; + + // Keep a pointer to the managing POA. + PortableServer::POA_var poa_; + + // ObjectRef of ourself which will be needed by the callback + Deployment::NodeApplicationManager_var objref_; + + // Child poa that uses active object map. + PortableServer::POA_var callback_poa_; + + // Cache a object reference of the underlying NodeApplication + // Since I have decided to have only 1 NA in NAM so no map is needed. + Deployment::NodeApplication_var nodeapp_; + + // Cached plan (This should be the part of the whole plan local to this node) + // The plan will be initialized when init is called. + Deployment::DeploymentPlan plan_; + + // Specify the time in second NodeApplicationManager will wait for a + // child NodeApplication to callback. Default is 5 second. + CORBA::ULong spawn_delay_; + + // Extracted commandline options to pass to the NodeApplication. + CORBA::String_var nodeapp_command_op_; + + // A map of the component created on this node. + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + Components::CCMObject_var, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> CCMComponent_Map; + typedef CCMComponent_Map::iterator Component_Iterator; + CCMComponent_Map component_map_; + + // Synchronize access to the object set. + TAO_SYNCH_MUTEX lock_; + }; +} + +#if defined (__ACE_INLINE__) +# include "NodeApplicationManager_Impl.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" +#endif /* CIAO_NODEAPPLICATIONMANAGER_IMPL_H */ diff --git a/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.inl b/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.inl new file mode 100644 index 00000000000..d11f60cb2c5 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeApplicationManager/NodeApplicationManager_Impl.inl @@ -0,0 +1,26 @@ +/* -*- C++ -*- */ +// $Id$ + +ACE_INLINE +CIAO::NodeApplicationManager_Impl:: +NodeApplicationManager_Impl (CORBA::ORB_ptr o, + PortableServer::POA_ptr p) + : orb_ (CORBA::ORB::_duplicate (o)), + poa_ (PortableServer::POA::_duplicate (p)), + callback_poa_ (PortableServer::POA::_nil ()), + spawn_delay_ (5) + // @@ (OO) The default size for an ACE_Hash_Map_Mapanger is quiet + // large. The maximum size of an ACE_Hash_Map_Manager is + // also fixed, i.e. it does not grow dynamically on demand. + // Make sure the default size of component_map_ is + // appropriate for your needs. You may also want to make + // the size configurable at compile-time, at least. +{ +} + +Deployment::NodeApplicationManager_ptr +CIAO::NodeApplicationManager_Impl:: +get_nadeapp_manager (void) +{ + return this->objref_; +} diff --git a/TAO/CIAO/DAnCE/NodeManager/NodeDaemon.idl b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon.idl new file mode 100644 index 00000000000..e2079d5f4ef --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon.idl @@ -0,0 +1,28 @@ +// $Id$ + +/** + * @file NodeDaemon.idl + * + * @brief Controling interface for managing and controling CIAO daemon. + */ + +#include "ciao/Deployment.idl" + +module CIAO +{ + /** + * @brief CIAO daemon process control program. + * + * @@The Inheritage might cause binary code bloating but + * it's an easy way of combining features. In the future we could + * move this definition into Deployment.idl. + */ + interface NodeDaemon : Deployment::NodeManager + { + // Canonical name of this daemon + readonly attribute string name; + + // Shutdown the daemon process. + oneway void shutdown (); + }; +}; diff --git a/TAO/CIAO/DAnCE/NodeManager/NodeDaemon.mpc b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon.mpc new file mode 100644 index 00000000000..39770cf0ef0 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon.mpc @@ -0,0 +1,32 @@ +// -*- MPC -*- +// $Id$ + +project (NodeDaemon_stub): ciao_deployment_stub, ciao_server_dnc { + sharedname = NodeDaemon_stub + idlflags += -Wb,stub_export_macro=NodeDaemon_stub_Export -Wb,stub_export_include=NodeDaemon_stub_export.h + dynamicflags = NODEDAEMON_STUB_BUILD_DLL + + libs += TAO_IFR_Client + IDL_Files { + NodeDaemon.idl + } + + Source_Files { + NodeDaemonC.cpp + } +} + +project(Node_Daemon): ciao_deployment_svnt, ciao_deployment_stub, iortable, naming { + after += NodeApplicationManager NodeDaemon_stub + libs += NodeApplicationManager NodeDaemon_stub TAO_IFR_Client CIAO_Server + exename = Node_Daemon + + IDL_Files { + } + + Source_Files { + NodeDaemonS.cpp + NodeDaemon_Impl.cpp + Node_Daemon.cpp + } +} diff --git a/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_Impl.cpp b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_Impl.cpp new file mode 100644 index 00000000000..1012a9bf4b3 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_Impl.cpp @@ -0,0 +1,174 @@ +// $Id$ + +#include "NodeDaemon_Impl.h" +#include "../NodeApplicationManager/NodeApplicationManager_Impl.h" + +// @@ (OO) Method definitions should never use "_WITH_DEFAULTS" +// versions of emulated exception parameters. Please remove +// the "_WITH_DEFAULTS" +CIAO::NodeDaemon_Impl::NodeDaemon_Impl (const char *name, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + const char * nodapp_loc, + int spawn_delay) + ACE_THROW_SPEC ((CORBA::SystemException)) + : orb_ (CORBA::ORB::_duplicate (orb)), + poa_ (PortableServer::POA::_duplicate (poa)), + name_ (CORBA::string_dup (name)), + nodeapp_location_ (CORBA::string_dup (nodapp_loc)), + callback_poa_ (PortableServer::POA::_nil ()), + spawn_delay_ (spawn_delay), + manager_ (Deployment::NodeApplicationManager::_nil ()) +{ + ACE_TRY + { + //create the call back poa for NAM. + PortableServer::POAManager_var mgr + = this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->callback_poa_ = + this->poa_->create_POA ("callback_poa", + mgr.in (), + 0 + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "NodeDaemon_Impl::constructor\t\n"); + ACE_RE_THROW; + } + ACE_ENDTRY; +} + +CIAO::NodeDaemon_Impl::~NodeDaemon_Impl () +{ + +} + +PortableServer::POA_ptr +CIAO::NodeDaemon_Impl::_default_POA (void) +{ + return PortableServer::POA::_duplicate (this->poa_.in ()); +} + + +char * +CIAO::NodeDaemon_Impl::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return CORBA::string_dup (this->name_.in ()); +} + +void +CIAO::NodeDaemon_Impl::shutdown (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + this->orb_->shutdown (0 ACE_ENV_ARG_PARAMETER); + ACE_CHECK; +} + +void +CIAO::NodeDaemon_Impl::joinDomain (const Deployment::Domain & , + Deployment::TargetManager_ptr , + Deployment::Logger_ptr) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + ACE_THROW (CORBA::NO_IMPLEMENT ()); +} + +void +CIAO::NodeDaemon_Impl::leaveDomain (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + //Implementation undefined. + ACE_THROW (CORBA::NO_IMPLEMENT ()); +} + + +Deployment::NodeApplicationManager_ptr +CIAO::NodeDaemon_Impl::preparePlan (const Deployment::DeploymentPlan &plan) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::StartError, + Deployment::PlanError)) +{ + // Return cached manager + ACE_TRY + { + if (CORBA::is_nil (this->manager_.in ())) + { + //Implementation undefined. + CIAO::NodeApplicationManager_Impl *app_mgr; + ACE_NEW_THROW_EX (app_mgr, + CIAO::NodeApplicationManager_Impl (this->orb_.in (), + this->poa_.in ()), + CORBA::NO_MEMORY ()); + ACE_TRY_CHECK; + + PortableServer::ServantBase_var safe (app_mgr); + + //@@ Note: after the init call the servant ref count would become 2. so + // we can leave the safeservant along and be dead. Also note that I added + this->manager_ = + app_mgr->init (this->nodeapp_location_, + this->spawn_delay_, + plan, + this->callback_poa_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Obtain the Object Reference + //CORBA::Object_var obj = + // this->poa_->servant_to_reference (app_mgr ACE_ENV_ARG_PARAMETER); + //ACE_TRY_CHECK; + + //this->manager_ = + // Deployment::NodeApplicationManager::_narrow (obj.in ()); + if (CORBA::is_nil (this->manager_.in ())) + { + ACE_DEBUG ((LM_DEBUG, "NodeDaemon_Impl:preparePlan: NodeApplicationManager ref is nil\n")); + ACE_THROW (Deployment::StartError ()); + } + } + + // Duplicate this reference to the caller + return + Deployment::NodeApplicationManager::_duplicate (this->manager_.in ()); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "NodeDaemon_Impl::preparePlan\t\n"); + ACE_RE_THROW; + } + ACE_ENDTRY; + ACE_CHECK_RETURN (0); +} + +void +CIAO::NodeDaemon_Impl::destroyManager (Deployment::NodeApplicationManager_ptr) + ACE_THROW_SPEC ((CORBA::SystemException, Deployment::StopError)) +{ + ACE_TRY + { + // Deactivate this object + PortableServer::ObjectId_var id = + this->poa_->reference_to_id (this->manager_.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->poa_->deactivate_object (id.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->manager_ = Deployment::NodeApplicationManager::_nil (); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "NodeDaemon_Impl::destroyManager\t\n"); + ACE_RE_THROW; + } + ACE_ENDTRY; +} diff --git a/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_Impl.h b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_Impl.h new file mode 100644 index 00000000000..7802f84f964 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_Impl.h @@ -0,0 +1,127 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Daemon_Impl.h + * + * $Id$ + * + * This file contains servant implementation for Deployment:NodeManager + * interface. In the current design of the NodeManager, as with the legacy + * implementation of CIAO, Each NodeManager corresponds to ONE NodeApplication + * Manager. Though, the name intuitively suggests that there be one NodeManager + * for every node, our design, allows the end-user to have multiple components + * run on the same node. + * + * @author Arvind S. Krishna <arvindk@dre.vanderbilt.edu> + */ +//============================================================================= + + +#ifndef CIAO_NODEDAEMON_IMPL_H +#define CIAO_NODEDAEMON_IMPL_H +#include /**/ "ace/pre.h" + +#include "NodeDaemonS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + + +namespace CIAO +{ + /** + * @class NodeDaemon_Impl + * + * @brief Servant implementation CIAO's daemon process control interface + * + * This class implements the CIAO:NodeDaemon interface. + * + */ + class NodeDaemon_Impl + : public virtual POA_CIAO::NodeDaemon, + public virtual PortableServer::RefCountServantBase + { + public: + + /// Constructor + NodeDaemon_Impl (const char *name, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr p, + const char * nodeapp_loc, + int spawn_delay) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Get the containing POA. This operation does *not* + /// increase the reference count of the POA. + virtual PortableServer::POA_ptr _default_POA (void); + + /// CIAO::Daemon defined attributes/operations. + virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void shutdown (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void joinDomain (const Deployment::Domain & domain, + Deployment::TargetManager_ptr manager, + Deployment::Logger_ptr log + ACE_ENV_ARG_DECL_WITH_DEFAULTS + ) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void leaveDomain (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual ::Deployment::NodeApplicationManager_ptr + preparePlan (const Deployment::DeploymentPlan &plan + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::StartError, + Deployment::PlanError)); + + virtual void + destroyManager (Deployment::NodeApplicationManager_ptr appManager + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + Deployment::StopError)); + + protected: + // Since this class is reference counted, making this + // destructor protected to enforce proper memory managment + // through the reference counting mechanism (i.e. to + // disallow calling operator delete() on an instance of + // this class. + /// Destructor + virtual ~NodeDaemon_Impl (void); + + // Keep a pointer to the managing ORB serving this servant. + CORBA::ORB_var orb_; + + // Keep a pointer to the managing POA. + PortableServer::POA_var poa_; + + // My Canonical name. + CORBA::String_var name_; + + // NodeApplication location + CORBA::String_var nodeapp_location_; + + // Cached callback POA. + PortableServer::POA_var callback_poa_; + + // Spawn delay for the NodeAppMgr + int spawn_delay_; + + // Cache reference of last NodeAppManager + Deployment::NodeApplicationManager_var manager_; + + }; +} +#if defined (__ACE_INLINE__) +# include "NodeDaemon_Impl.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" +#endif /* CIAO_NODEDAEMON_IMPL_H */ diff --git a/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_Impl.inl b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_Impl.inl new file mode 100644 index 00000000000..6318deb79a0 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_Impl.inl @@ -0,0 +1,2 @@ +/* -*- C++ -*- */ +// $Id$ diff --git a/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_stub_export.h b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_stub_export.h new file mode 100644 index 00000000000..346bdf5785c --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeManager/NodeDaemon_stub_export.h @@ -0,0 +1,54 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl NodeDaemon_stub +// ------------------------------ +#ifndef NODEDAEMON_STUB_EXPORT_H +#define NODEDAEMON_STUB_EXPORT_H + +#include "ace/config-all.h" + +#if !defined (NODEDAEMON_STUB_HAS_DLL) +# define NODEDAEMON_STUB_HAS_DLL 1 +#endif /* ! NODEDAEMON_STUB_HAS_DLL */ + +#if defined (NODEDAEMON_STUB_HAS_DLL) && (NODEDAEMON_STUB_HAS_DLL == 1) +# if defined (NODEDAEMON_STUB_BUILD_DLL) +# define NodeDaemon_stub_Export ACE_Proper_Export_Flag +# define NODEDAEMON_STUB_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define NODEDAEMON_STUB_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* NODEDAEMON_STUB_BUILD_DLL */ +# define NodeDaemon_stub_Export ACE_Proper_Import_Flag +# define NODEDAEMON_STUB_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define NODEDAEMON_STUB_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* NODEDAEMON_STUB_BUILD_DLL */ +#else /* NODEDAEMON_STUB_HAS_DLL == 1 */ +# define NodeDaemon_stub_Export +# define NODEDAEMON_STUB_SINGLETON_DECLARATION(T) +# define NODEDAEMON_STUB_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* NODEDAEMON_STUB_HAS_DLL == 1 */ + +// Set NODEDAEMON_STUB_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (NODEDAEMON_STUB_NTRACE) +# if (ACE_NTRACE == 1) +# define NODEDAEMON_STUB_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define NODEDAEMON_STUB_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !NODEDAEMON_STUB_NTRACE */ + +#if (NODEDAEMON_STUB_NTRACE == 1) +# define NODEDAEMON_STUB_TRACE(X) +#else /* (NODEDAEMON_STUB_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define NODEDAEMON_STUB_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (NODEDAEMON_STUB_NTRACE == 1) */ + +#endif /* NODEDAEMON_STUB_EXPORT_H */ + +// End of auto generated file. diff --git a/TAO/CIAO/DAnCE/NodeManager/Node_Daemon.cpp b/TAO/CIAO/DAnCE/NodeManager/Node_Daemon.cpp new file mode 100644 index 00000000000..f29c5d50922 --- /dev/null +++ b/TAO/CIAO/DAnCE/NodeManager/Node_Daemon.cpp @@ -0,0 +1,259 @@ +// $Id$ + +//============================================================== +/** + * @file Node_Daemon.cpp + * + * @brief CIAO's Node Daemon implementation + * + * NodeDaemon is the bootstraping mechanism to create new + * NodeApplication on the localhost. We currently depend on + * starting the NodeApplicationManager process on some port of all + * the hosts that have NodeApplication install to function properly. + * The port to run this daemon can be set by using the TAO ORB options + * command of -ORBEndpoint <port>. This replaces the earlier CIAO_Daemon + * implementation of CIAO as defined in the CCM specification. + * + * @author Arvind S. Krishna <arvindk@dre.vanderbilt.edu> + * @author Tao Lu <lu@dre.vanderbilt.edu> + */ +//=============================================================== + +#include "NodeDaemon_Impl.h" +#include "tao/IORTable/IORTable.h" + +// Include Name Service header +#include "orbsvcs/orbsvcs/CosNamingC.h" + +#include "ace/SString.h" +#include "ace/Read_Buffer.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_unistd.h" +#include "ciao/Server_init.h" +#include "ciao/CIAO_common.h" + +const char *ior_file_name_ = "nodedaemon.ior"; +char *default_svcconf_ = 0; +char *svcconf_config_ = 0; +char *nodeapp_location_ = 0; + +int write_to_ior_ = 0; +int register_with_ns_ = 0; +int nodeapp_loc_ = 0; +int spawn_delay = 1; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "o:c:m:s:d:n"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': // get the file name to write to + ior_file_name_ = get_opts.opt_arg (); + write_to_ior_ = 1; + break; + + case 'c': // get the default svc.conf filename + default_svcconf_ = get_opts.opt_arg (); + break; + + case 'm': // get the svc.conf map configuration filename + svcconf_config_ = get_opts.opt_arg (); + break; + + case 's': //get the location to spawn the NodeApplication + nodeapp_location_ = get_opts.opt_arg (); + nodeapp_loc_ = 1; + break; + + case 'd': //get the spawn delay argument + spawn_delay = ACE_OS::atoi (get_opts.opt_arg ()); + break; + + case 'n': + register_with_ns_ = 1; + break; + + case '?': // display help for use of the server. + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s\n" + "-o <ior_output_file>\n" + "-c <svc.conf file>\n" + "-n <use naming service>\n" + "-s <NodeApplication executable path>\n" + "\n", + argv [0]), + -1); + } + + return 0; +} + +int +write_IOR(const char* ior) +{ + FILE* ior_output_file_ = + ACE_OS::fopen (ior_file_name_, "w"); + + if (ior_output_file_) + { + ACE_OS::fprintf (ior_output_file_, + "%s", + ior); + ACE_OS::fclose (ior_output_file_); + } + + return 0; +} + +int +register_with_ns (const char * name_context, + CORBA::ORB_ptr orb, + CIAO::NodeDaemon_ptr obj) +{ + // Naming Service related operations + CORBA::Object_var naming_context_object = + orb->resolve_initial_references ("NameService"); + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow (naming_context_object.in ()); + + // Initialize the Naming Sequence + CosNaming::Name name (1); + name.length (1); + // Register the name with the NS + name[0].id = CORBA::string_dup (name_context); + + // Register the servant with the Naming Service + naming_context->bind (name, obj); + + return 0; +} + +int +main (int argc, char *argv[]) +{ + ACE_TRY_NEW_ENV + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init (argc, + argv, + "" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CIAO::Server_init (orb.in ()); + + if (parse_args (argc, argv) != 0) + return -1; + + // Check if NodeApplication executable location has been + // specified + if (! nodeapp_loc_) + { + ACE_DEBUG ((LM_DEBUG, "Use -s <NodeApplicationPath> to specify \ + executable path\n")); + exit (1); + } + + // Get reference to Root POA. + CORBA::Object_var obj + = orb->resolve_initial_references ("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POA_var poa + = PortableServer::POA::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var table_object = + orb->resolve_initial_references ("IORTable" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + IORTable::Table_var adapter = + IORTable::Table::_narrow (table_object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (adapter.in ())) + ACE_ERROR_RETURN ((LM_ERROR, "Nil IORTable\n"), -1); + + + // Create and install the CIAO Daemon servant + CIAO::NodeDaemon_Impl *daemon_servant = 0; + ACE_NEW_RETURN (daemon_servant, + CIAO::NodeDaemon_Impl("NodeDaemon", + orb.in (), + poa.in (), + nodeapp_location_, + spawn_delay), + -1); + PortableServer::ServantBase_var safe_daemon (daemon_servant); + // Implicit activation + + CIAO::NodeDaemon_var daemon = daemon_servant->_this (); + + CORBA::String_var str = orb->object_to_string (daemon.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + adapter->bind ("NodeManager", str.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (write_to_ior_) + write_IOR (str.in ()); + else if (register_with_ns_) + { + char name [100]; + if (ACE_OS::hostname (name, 100) == -1) + { + ACE_DEBUG ((LM_DEBUG, "gethostname call failed! \n")); + exit (1); + } + + // Register this name with the Naming Service + register_with_ns (name, orb.in (), daemon.in ()); + } + + ACE_DEBUG ((LM_INFO, "CIAO_NodeDaemon IOR: %s\n", str.in ())); + + // Activate POA manager + PortableServer::POAManager_var mgr + = poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + mgr->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // End Deployment part + ACE_DEBUG ((LM_DEBUG, + "CIAO_NodeDaemon is running...\n")); + + // Run the main event loop for the ORB. + orb->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + orb->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "CIAO_NodeDaemon::main\t\n"); + return 1; + } + ACE_ENDTRY; + + ACE_DEBUG ((LM_DEBUG, + "CIAO_NodeDaemon has closed\n")); + return 0; +} |