diff options
-rw-r--r-- | repoman_1/Repository_Manager_Admin_Export.h | 58 | ||||
-rw-r--r-- | repoman_1/repository_manager_admin.cpp | 232 | ||||
-rw-r--r-- | repoman_1/repository_manager_admin.h | 65 | ||||
-rw-r--r-- | repoman_1/repository_manager_admin_exec.cpp | 312 |
4 files changed, 667 insertions, 0 deletions
diff --git a/repoman_1/Repository_Manager_Admin_Export.h b/repoman_1/Repository_Manager_Admin_Export.h new file mode 100644 index 00000000000..a705cd0c2b7 --- /dev/null +++ b/repoman_1/Repository_Manager_Admin_Export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl DAnCE_RepositoryManager_Admin +// ------------------------------ +#ifndef DANCE_REPOSITORYMANAGER_ADMIN_EXPORT_H +#define DANCE_REPOSITORYMANAGER_ADMIN_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL) +# define DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL */ + +#if !defined (DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL) +# define DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL 1 +#endif /* ! DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL */ + +#if defined (DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL) && (DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL == 1) +# if defined (DANCE_REPOSITORYMANAGER_ADMIN_BUILD_DLL) +# define DAnCE_RepositoryManager_Admin_Export ACE_Proper_Export_Flag +# define DANCE_REPOSITORYMANAGER_ADMIN_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define DANCE_REPOSITORYMANAGER_ADMIN_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* DANCE_REPOSITORYMANAGER_ADMIN_BUILD_DLL */ +# define DAnCE_RepositoryManager_Admin_Export ACE_Proper_Import_Flag +# define DANCE_REPOSITORYMANAGER_ADMIN_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define DANCE_REPOSITORYMANAGER_ADMIN_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* DANCE_REPOSITORYMANAGER_ADMIN_BUILD_DLL */ +#else /* DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL == 1 */ +# define DAnCE_RepositoryManager_Admin_Export +# define DANCE_REPOSITORYMANAGER_ADMIN_SINGLETON_DECLARATION(T) +# define DANCE_REPOSITORYMANAGER_ADMIN_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* DANCE_REPOSITORYMANAGER_ADMIN_HAS_DLL == 1 */ + +// Set DANCE_REPOSITORYMANAGER_ADMIN_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (DANCE_REPOSITORYMANAGER_ADMIN_NTRACE) +# if (ACE_NTRACE == 1) +# define DANCE_REPOSITORYMANAGER_ADMIN_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define DANCE_REPOSITORYMANAGER_ADMIN_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !DANCE_REPOSITORYMANAGER_ADMIN_NTRACE */ + +#if (DANCE_REPOSITORYMANAGER_ADMIN_NTRACE == 1) +# define DANCE_REPOSITORYMANAGER_ADMIN_TRACE(X) +#else /* (DANCE_REPOSITORYMANAGER_ADMIN_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define DANCE_REPOSITORYMANAGER_ADMIN_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (DANCE_REPOSITORYMANAGER_ADMIN_NTRACE == 1) */ + +#endif /* DANCE_REPOSITORYMANAGER_ADMIN_EXPORT_H */ + +// End of auto generated file. diff --git a/repoman_1/repository_manager_admin.cpp b/repoman_1/repository_manager_admin.cpp new file mode 100644 index 00000000000..94426ec59c0 --- /dev/null +++ b/repoman_1/repository_manager_admin.cpp @@ -0,0 +1,232 @@ +// $Id$ +#include "repository_manager_admin.h" +#include "DAnCE/Logger/Log_Macros.h" +#include "RepositoryManagerDaemonC.h" + +namespace DAnCE +{ + namespace RepositoryManager + { + Admin::Admin (Deployment::RepositoryManager_ptr rm) + : rm_ (Deployment::RepositoryManager::_duplicate (rm)) + { + DANCE_TRACE ("Admin::Admin"); + } + + + /// Install a package at a provided filesystem path. + bool + Admin::install_package (const ACE_TCHAR *uri, + const ACE_TCHAR *name, + bool replace) + { + DANCE_TRACE ("Admin::install_package"); + + try + { + DANCE_DEBUG ((LM_TRACE, DLINFO "Admin::install_package - " + "Installing package with URI: %C, name: %C\n", + uri, name)); + this->rm_->installPackage (name, + uri, + replace); + DANCE_DEBUG ((LM_TRACE, DLINFO "Admin::install_package - " + "Package installed successfully\n")); + } + catch (Deployment::NameExists &ex) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::install_package - " + "Package with name %C already installed.\n", + name)); + return false; + } + catch (Deployment::PackageError &ex) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::install_package - " + "Internal error while installing package with name %C: %C - %C\n", + name, ex.source.in (), ex.reason.in ())); + return false; + } + catch (CORBA::Exception &ex) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::install_package - " + "Unexpected CORBA Exception while installing package with name: %C. Reason: %C\n", + name, + ex._info ().c_str ())); + return false; + } + catch (...) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::install_package - " + "Unexpected C++ exception while installing package with name: %C\n", + name)); + return false; + } + + return true; + } + + /// Create new package. + bool + Admin::create_package (const ACE_TCHAR *pc_path, + const ACE_TCHAR *name, + const ACE_TCHAR *baselocation, + bool replace) + { + DANCE_TRACE ("Admin::create_package"); + + return false; + } + + /// Uninstall a package with a provided UUID. + /// Fails if the NoSuchName exception was raised. + bool + Admin::uninstall_package (const ACE_TCHAR *uuid) + { + DANCE_TRACE ("Admin::uninstall_package"); + + try + { + this->rm_->deletePackage (uuid); + } + catch (Deployment::NoSuchName &ex) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::uninstall_package - " + "No package with the given UUID found: %C\n", + uuid)); + return false; + } + catch (CORBA::Exception &ex) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::uninstall_package - " + "Unexpected CORBA Exception while uninstalling package with uuid: %C. Reason: %C\n", + uuid, + ex._info ().c_str ())); + return false; + } + catch (...) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::uninstall_package - " + "Unexpected C++ exception while installing package with uuid: %C\n", + uuid)); + return false; + } + + return true; + } + + /// List all installed packages + ::CORBA::StringSeq * + Admin::list_packages (void) + { + DANCE_TRACE ("Admin::list_packages"); + + try + { + CORBA::StringSeq_var packages = this->rm_->getAllNames (); + return packages._retn (); + } + catch (CORBA::Exception &ex) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::list_packages - " + "Unexpected CORBA Exception while listing packages: %C\n", + ex._info ().c_str ())); + return 0; + } + catch (...) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::list_package - " + "Unexpected C++ exception while listing packages\n")); + return 0; + } + + return 0; + } + + /// List all installed package types + ::CORBA::StringSeq * + Admin::list_types (void) + { + DANCE_TRACE ("Admin::list_types"); + + try + { + CORBA::StringSeq_var packages = this->rm_->getAllTypes (); + return packages._retn (); + } + catch (CORBA::Exception &ex) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::list_types - " + "Unexpected CORBA Exception while listing package types: %C\n", + ex._info ().c_str ())); + return 0; + } + catch (...) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::list_types - " + "Unexpected C++ exception while listing package types\n")); + return 0; + } + + return 0; + } + + /// Find package names by type + ::CORBA::StringSeq * + Admin::find_by_type (const ACE_TCHAR *type) + { + DANCE_TRACE ("Admin::find_by_type"); + + if (type == 0) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::find_by_type - " + "Nill type passed to find_by_type\n")); + return 0; + } + + try + { + ::CORBA::StringSeq_var types = this->rm_->findNamesByType (type); + types._retn (); + } + catch (CORBA::Exception &ex) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::find_by_type - " + "Unexpected CORBA Exception while listing packages of type %C: %C\n", + type, + ex._info ().c_str ())); + return 0; + } + catch (...) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::find_by_type - " + "Unexpected C++ exception while listing packages by type %C\n", + type)); + return 0; + } + + return 0; + } + + /// Attempt to shutdown the server. + bool + Admin::shutdown (void) + { + DANCE_TRACE ("Admin::shutdown"); + + CIAO::RepositoryManagerDaemon_var rmd = + CIAO::RepositoryManagerDaemon::_narrow (this->rm_.in ()); + + if (CORBA::is_nil (rmd.in ())) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Admin::shutdown - " + "Unable to narrow provided RM reference to a CIAO::RepositoryManagerDaemon\n")); + return false; + } + + rmd->shutdown (); + + return true; + } + } +} diff --git a/repoman_1/repository_manager_admin.h b/repoman_1/repository_manager_admin.h new file mode 100644 index 00000000000..730a20c04b0 --- /dev/null +++ b/repoman_1/repository_manager_admin.h @@ -0,0 +1,65 @@ +/** + * @file repository_manager_admin.h + * @author William R. Otte <wotte@dre.vanderbilt.edu>? + * + * Class which implements most repository admin functions. + */ + +#ifndef REPOSITORY_MANAGER_ADMIN_H_ +#define REPOSITORY_MANAGER_ADMIN_H_ + +#include "ace/pre.h" +#include "Deployment/Deployment_RepositoryManagerC.h" + +#include "Repository_Manager_Admin_Export.h" + +namespace DAnCE +{ + namespace RepositoryManager + { + /** + * @class Admin + * @brief Implements administrative functions for the Repository Manager. + */ + class DAnCE_RepositoryManager_Admin_Export Admin + { + public: + Admin (Deployment::RepositoryManager_ptr rm); + + /// Install a package at a provided filesystem path. + bool install_package (const ACE_TCHAR *uri, + const ACE_TCHAR *name, + bool replace); + + /// Create new package. + bool create_package (const ACE_TCHAR *pc_path, + const ACE_TCHAR *name, + const ACE_TCHAR *baselocation, + bool replace); + + /// Uninstall a package with a provided UUID. + /// Fails if the NoSuchName exception was raised. + bool uninstall_package (const ACE_TCHAR *uuid); + + /// List all installed packages + ::CORBA::StringSeq * list_packages (void); + + /// List all installed package types + ::CORBA::StringSeq * list_types (void); + + /// Find package names by type + ::CORBA::StringSeq * find_by_type (const ACE_TCHAR *type); + + /// Attempt to shutdown the server. + bool shutdown (void); + + private: + Deployment::RepositoryManager_var rm_; + + }; + } +} + +#include "ace/post.h" + +#endif /* REPOSITORY_MANAGER_ADMIN_H_ */ diff --git a/repoman_1/repository_manager_admin_exec.cpp b/repoman_1/repository_manager_admin_exec.cpp new file mode 100644 index 00000000000..f9971622f0e --- /dev/null +++ b/repoman_1/repository_manager_admin_exec.cpp @@ -0,0 +1,312 @@ +/** + * @file repository_manager_admin.cpp + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * Simple administration program for the Repository Manager. + */ + +#include "ace/Get_Opt.h" +#include "ace/Unbounded_Set.h" +#include "ace/String_Base.h" +#include "DAnCE/Logger/Log_Macros.h" + +#include "repository_manager_admin.h" + +struct Options +{ + Options (void) + : rm_ior_ (""), + domain_nc_ (""), + list_ (false), + shutdown_ (false) + { + } + + struct Installation + { + Installation (void) + { + } + + bool init (const ACE_TCHAR *inst) + { + ACE_CString tmp (inst); + + size_t begin = 0; + size_t pos = tmp.find (',', begin); + + if (pos != ACE_CString::npos) + path_ = tmp.substring (begin, pos - begin); + else + { + ACE_ERROR ((LM_ERROR, DLINFO "Options::Installation::init - " + "Installation directive missing name and replace parameters, " + "must have form path,name,replace\n")); + return false; + } + + + begin = pos + 1; + pos = tmp.find (',', begin); + + if (pos != ACE_CString::npos) + name_ = tmp.substring (begin, pos - begin); + else + { + ACE_ERROR ((LM_ERROR, DLINFO "Options::Installation::init - " + "Installation directive mssing replace parameter, " + "must have form path,name,replace\n")); + return false; + } + + begin = pos + 1; + + if (tmp[begin] == '0') replace_ = false; + else if (tmp[begin] == '1') replace_ = true; + else + { + ACE_ERROR ((LM_ERROR, DLINFO "Options::Installation::init - " + "Replace directive muse be 1 or 0.\n")); + return false; + } + + return true; + } + + bool operator== (const Installation &rhs) const + { + return (replace_ == rhs.replace_) && + (path_ == rhs.path_) && + (name_ == rhs.name_); + } + + ACE_CString path_, name_; + bool replace_; + }; + + struct Creation + { + Creation (void) + { + } + + bool init (const ACE_TCHAR *inst) + { + ACE_CString tmp (inst); + + size_t begin = 0; + size_t pos = tmp.find (',', begin); + + if (pos != ACE_CString::npos) + path_ = tmp.substring (begin, pos - begin); + else + { + ACE_ERROR ((LM_ERROR, DLINFO "Options::Creation::init - " + "Creation directive missing name, base location, and replace parameters, " + "must have form path,name,base,replace\n")); + return false; + } + + + begin = pos + 1; + pos = tmp.find (',', begin); + + if (pos != ACE_CString::npos) + name_ = tmp.substring (begin, pos - begin); + else + { + ACE_ERROR ((LM_ERROR, DLINFO "Options::Creation::init - " + "Creation directive mssing base location and replace parameter, " + "must have form path,name,base,replace\n")); + return false; + } + + begin = pos + 1; + pos = tmp.find (',', begin); + + if (pos != ACE_CString::npos) + base_location_ = tmp.substring (begin, pos - begin); + else + { + ACE_ERROR ((LM_ERROR, DLINFO "Options::Creation::init - " + "Creation directive mssing replace parameter, " + "must have form path,name,base,replace\n")); + return false; + } + + begin = pos + 1; + + if (tmp[begin] == '0') replace_ = false; + else if (tmp[begin] == '1') replace_ = true; + else + { + ACE_ERROR ((LM_ERROR, DLINFO "Options::Creation::init - " + "Replace directive muse be 1 or 0.\n")); + return false; + } + + return true; + } + + bool operator== (const Creation &rhs) const + { + return (replace_ == rhs.replace_) && + (path_ == rhs.path_) && + (name_ == rhs.name_); + } + + ACE_CString path_, name_, base_location_; + bool replace_; + }; + + const ACE_TCHAR *rm_ior_; + const ACE_TCHAR *domain_nc_; + ACE_Unbounded_Set< Installation > install_; + ACE_Unbounded_Set< Creation > create_; + ACE_Unbounded_Set< ACE_CString > uninstall_; + bool list_; + bool shutdown_; + + void usage (void) + { + ACE_ERROR ((LM_EMERGENCY, "usage:\n" + "\t-h,--help\t\t\tThis message.\n" + "\t-r,--rm-ior <ior>\t\tIOR where the RM instance may be found\n" + "\t-i,--install <path>,<name>,<1|0>\t\tInstall package found at <path> into the RM, with <name>, <1> replacing or <0> not replacing an existing package. *\n" + "\t-c,--create <path>,<name>,<base location>,<1|0>\t\tInstall package found at <path> into the RM, with <name>, <base location>, <1> replacing or <0> not replacing an existing package. *\n" + "\t-u,--uninstall <uuid>\t\tUninstall package identified by UUID. *\n" + "\t-l,--list\t\t\tList all packages installed in the RM\n" + "\t-s,--shutdown\t\t\tShutdown the RM.\n" + "\t-d,--domain-nc <ior>\t\tProvide a reference to the domain naming context\n" + + "\n\n\tArguments with a * may be specified multiple times.\n")); + } + + + bool parse_args (int argc, ACE_TCHAR *argv[]) + { + ACE_Get_Opt get_opt (argc, argv, + ACE_TEXT ("hr:i:c:u:lsd:"), + 0, 0, + ACE_Get_Opt::RETURN_IN_ORDER, + 1); + + get_opt.long_option (ACE_TEXT("help"), 'h', ACE_Get_Opt::NO_ARG); + get_opt.long_option (ACE_TEXT("rm-ior"), 'r', ACE_Get_Opt::ARG_REQUIRED); + get_opt.long_option (ACE_TEXT("install"), 'i', ACE_Get_Opt::ARG_REQUIRED); + get_opt.long_option (ACE_TEXT("create"), 'c', ACE_Get_Opt::ARG_REQUIRED); + get_opt.long_option (ACE_TEXT("uninstall"), 'u', ACE_Get_Opt::ARG_REQUIRED); + get_opt.long_option (ACE_TEXT("list"), 'l', ACE_Get_Opt::NO_ARG); + get_opt.long_option (ACE_TEXT("shutdown"), 's', ACE_Get_Opt::NO_ARG); + get_opt.long_option (ACE_TEXT("domain-nc"), 'd', ACE_Get_Opt::ARG_REQUIRED); + + char c; + Installation inst; + Creation create; + + while ((c = get_opt ()) != -1) + { + switch (c) + { + case 'h': + this->usage (); + return false; + break; + + case 'r': + DANCE_DEBUG ((LM_DEBUG, DLINFO "Options::parse_args - " + "Using provided RM IOR: %C\n", + get_opt.opt_arg ())); + rm_ior_ = get_opt.opt_arg (); + break; + + case 'i': + if (!inst.init (get_opt.opt_arg ())) + { + this->usage (); + return false; + } + + if (inst.replace_) + DANCE_DEBUG ((LM_DEBUG, DLINFO "Options::parse_args - " + "Replacing installed package from path %C with name %C.\n", inst.path_.c_str (), + inst.name_.c_str ())); + else + DANCE_DEBUG ((LM_DEBUG, DLINFO "Options::parse_args - " + "Installing package from path %C with name %C.\n", inst.path_.c_str (), + inst.name_.c_str ())); + + this->install_.insert (inst); + break; + + case 'c': + if (!create.init (get_opt.opt_arg ())) + { + this->usage (); + return false; + } + + if (create.replace_) + DANCE_DEBUG ((LM_DEBUG, DLINFO "Options::parse_args - " + "Replacing installed package from path %C with name %C and base location %C.\n", create.path_.c_str (), + create.name_.c_str (), + create.base_location_.c_str ())); + else + DANCE_DEBUG ((LM_DEBUG, DLINFO "Options::parse_args - " + "Installing new package from path %C with name %C and base location %C.\n", create.path_.c_str (), + create.name_.c_str (), + create.base_location_.c_str ())); + + this->create_.insert (create); + break; + + case 'u': + DANCE_DEBUG ((LM_DEBUG, DLINFO "Options::parse_args - " + "Removing package with UUID %C\n", get_opt.opt_arg ())); + this->uninstall_.insert (get_opt.opt_arg ()); + break; + + case 'l': + DANCE_DEBUG ((LM_DEBUG, DLINFO "Options::parse_args - " + "Listing all packages.\n")); + this->list_ = true; + break; + + case 's': + DANCE_DEBUG ((LM_DEBUG, DLINFO "Options::parse_args - " + "Shutting down the RM instance.\n")); + this->shutdown_ = true; + break; + + case 'd': + DANCE_DEBUG ((LM_DEBUG, DLINFO "Options::parse_args - " + "Using provided Domain NC: %C\n", + get_opt.opt_arg ())); + domain_nc_ = get_opt.opt_arg (); + + case 0: + if (ACE_OS::strcmp (get_opt.long_option (), ACE_TEXT ("domain-nc")) == 0) + { + } + else + { + DANCE_ERROR ((LM_ERROR, DLINFO "Options::parse_args - " + "Unknown long option: %C\n", + get_opt.long_option ())); + this->usage (); + return false; + } + } + } + return true; + } +}; + +int ACE_TMAIN (int argc, ACE_TCHAR **argv) +{ + Options options; + + options.parse_args (argc, argv); + + return 0; +} |