diff --git a/cmdline/CtaAdminCmd.cpp b/cmdline/CtaAdminCmd.cpp index 12cadeb70f343df13e4e67996b06e71415b360ea..05af4d27d1f33299c101e3872e57fad95b4915eb 100644 --- a/cmdline/CtaAdminCmd.cpp +++ b/cmdline/CtaAdminCmd.cpp @@ -35,27 +35,128 @@ #include <cryptopp/base64.h> #include <cryptopp/osrng.h> #include <iomanip> -#include <iostream> #include <memory> #include <pwd.h> -#include <sstream> #include <string> #include <time.h> #endif +#include <iostream> // for debug output +#include <sstream> + #include "CtaAdminCmd.hpp" CtaAdminCmd::CtaAdminCmd(int argc, const char *const *const argv) { + // Check we have at least one parameter + + if(argc < 2) throw std::runtime_error(getGenericHelp(argv[0])); + + // Tokenize the command + for(int i = 0; i < argc; ++i) { m_requestTokens.push_back(argv[i]); } + + // Parse the command + + std::string &command = m_requestTokens.at(1); + + if ("ad" == command || "admin" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_admin();} + else if("ah" == command || "adminhost" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_adminhost();} + else if("tp" == command || "tapepool" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_tapepool();} + else if("ar" == command || "archiveroute" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_archiveroute();} + else if("ll" == command || "logicallibrary" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_logicallibrary();} + else if("ta" == command || "tape" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_tape();} + else if("sc" == command || "storageclass" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_storageclass();} + else if("rmr" == command || "requestermountrule" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_requestermountrule();} + else if("gmr" == command || "groupmountrule" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_groupmountrule();} + else if("mp" == command || "mountpolicy" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_mountpolicy();} + else if("re" == command || "repack" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_repack();} + else if("sh" == command || "shrink" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_shrink();} + else if("ve" == command || "verify" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_verify();} + else if("af" == command || "archivefile" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_archivefile();} + else if("te" == command || "test" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_test();} + else if("dr" == command || "drive" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_drive();} + else if("lpa" == command || "listpendingarchives" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_listpendingarchives();} + else if("lpr" == command || "listpendingretrieves" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_listpendingretrieves();} + else if("sq" == command || "showqueues" == command) xCom_notimpl(); //{authorizeAdmin(); return xCom_showqueues();} + + else if("a" == command || "archive" == command) xCom_notimpl(); //{return xCom_archive();} + else if("r" == command || "retrieve" == command) xCom_notimpl(); //{return xCom_retrieve();} + else if("da" == command || "deletearchive" == command) xCom_notimpl(); //{return xCom_deletearchive();} + else if("cr" == command || "cancelretrieve" == command) xCom_notimpl(); //{return xCom_cancelretrieve();} + else if("ufi" == command || "updatefileinfo" == command) xCom_notimpl(); //{return xCom_updatefileinfo();} + else if("ufsc" == command || "updatefilestorageclass" == command) xCom_notimpl(); //{return xCom_updatefilestorageclass();} + else if("lsc" == command || "liststorageclass" == command) xCom_notimpl(); //{return xCom_liststorageclass();} + + else { + throw std::runtime_error(getGenericHelp(m_requestTokens.at(0))); + } } + +std::string CtaAdminCmd::getGenericHelp(const std::string &programName) const +{ + std::stringstream help; + + help << "CTA ADMIN commands:" << std::endl + << std::endl + << "For each command there is a short version and a long one. " + << "Subcommands (add/rm/ls/ch/reclaim) do not have short versions." << std::endl + << std::endl; + + help << programName << " admin/ad add/ch/rm/ls" << std::endl + << programName << " adminhost/ah add/ch/rm/ls" << std::endl + << programName << " archivefile/af ls" << std::endl + << programName << " archiveroute/ar add/ch/rm/ls" << std::endl + << programName << " drive/dr up/down/ls" << std::endl + << programName << " groupmountrule/gmr add/rm/ls/err" << std::endl + << programName << " listpendingarchives/lpa" << std::endl + << programName << " listpendingretrieves/lpr" << std::endl + << programName << " logicallibrary/ll add/ch/rm/ls" << std::endl + << programName << " mountpolicy/mp add/ch/rm/ls" << std::endl + << programName << " repack/re add/rm/ls/err" << std::endl + << programName << " requestermountrule/rmr add/rm/ls/err" << std::endl + << programName << " shrink/sh" << std::endl + << programName << " storageclass/sc add/ch/rm/ls" << std::endl + << programName << " tape/ta add/ch/rm/reclaim/ls/label" << std::endl + << programName << " tapepool/tp add/ch/rm/ls" << std::endl + << programName << " test/te read/write" << std::endl + << programName << " verify/ve add/rm/ls/err" << std::endl + << std::endl; + + help << "CTA EOS commands: [NOT IMPLEMENTED]" << std::endl + << std::endl + << "For each command there is a short version and a long one." << std::endl + << std::endl + << programName << " archive/a" << std::endl + << programName << " cancelretrieve/cr" << std::endl + << programName << " deletearchive/da" << std::endl + << programName << " liststorageclass/lsc" << std::endl + << programName << " retrieve/r" << std::endl + << programName << " updatefileinfo/ufi" << std::endl + << programName << " updatefilestorageclass/ufsc" << std::endl + << std::endl + << "Special option for running " << programName + << " within the EOS workflow engine:" << std::endl + << std::endl + << programName << " ... --stderr" << std::endl + << std::endl + << "The option tells " << programName + << " to write results to both standard out and standard error." << std::endl + << "The option must be specified as the very last command-line argument of " + << programName << "." << std::endl; + + return help.str(); +} + + + #if 0 /*! * checkOptions @@ -123,46 +224,6 @@ void CtaAdminCmd::logRequestAndSetCmdlineResult(const cta::common::dataStructure -/*! - * commandDispatcher - */ -std::string CtaAdminCmd::dispatchCommand() { - std::string command(m_requestTokens.at(1)); - - if ("ad" == command || "admin" == command) {authorizeAdmin(); return xCom_admin();} - else if("ah" == command || "adminhost" == command) {authorizeAdmin(); return xCom_adminhost();} - else if("tp" == command || "tapepool" == command) {authorizeAdmin(); return xCom_tapepool();} - else if("ar" == command || "archiveroute" == command) {authorizeAdmin(); return xCom_archiveroute();} - else if("ll" == command || "logicallibrary" == command) {authorizeAdmin(); return xCom_logicallibrary();} - else if("ta" == command || "tape" == command) {authorizeAdmin(); return xCom_tape();} - else if("sc" == command || "storageclass" == command) {authorizeAdmin(); return xCom_storageclass();} - else if("rmr" == command || "requestermountrule" == command) {authorizeAdmin(); return xCom_requestermountrule();} - else if("gmr" == command || "groupmountrule" == command) {authorizeAdmin(); return xCom_groupmountrule();} - else if("mp" == command || "mountpolicy" == command) {authorizeAdmin(); return xCom_mountpolicy();} - else if("re" == command || "repack" == command) {authorizeAdmin(); return xCom_repack();} - else if("sh" == command || "shrink" == command) {authorizeAdmin(); return xCom_shrink();} - else if("ve" == command || "verify" == command) {authorizeAdmin(); return xCom_verify();} - else if("af" == command || "archivefile" == command) {authorizeAdmin(); return xCom_archivefile();} - else if("te" == command || "test" == command) {authorizeAdmin(); return xCom_test();} - else if("dr" == command || "drive" == command) {authorizeAdmin(); return xCom_drive();} - else if("lpa" == command || "listpendingarchives" == command) {authorizeAdmin(); return xCom_listpendingarchives();} - else if("lpr" == command || "listpendingretrieves" == command) {authorizeAdmin(); return xCom_listpendingretrieves();} - else if("sq" == command || "showqueues" == command) {authorizeAdmin(); return xCom_showqueues();} - - else if("a" == command || "archive" == command) {return xCom_archive();} - else if("r" == command || "retrieve" == command) {return xCom_retrieve();} - else if("da" == command || "deletearchive" == command) {return xCom_deletearchive();} - else if("cr" == command || "cancelretrieve" == command) {return xCom_cancelretrieve();} - else if("ufi" == command || "updatefileinfo" == command) {return xCom_updatefileinfo();} - else if("ufsc" == command || "updatefilestorageclass" == command) {return xCom_updatefilestorageclass();} - else if("lsc" == command || "liststorageclass" == command) {return xCom_liststorageclass();} - - else { - throw cta::exception::UserError(getGenericHelp(m_requestTokens.at(0))); - } -} - - /*! * open @@ -2276,57 +2337,5 @@ std::string CtaAdminCmd::xCom_liststorageclass() { m_scheduler->listStorageClass(m_cliIdentity.username, request); return cmdlineOutput.str(); } - - - -/*! - * getGenericHelp - */ -std::string CtaAdminCmd::getGenericHelp(const std::string &programName) const { - std::stringstream help; - help << "CTA ADMIN commands:" << std::endl; - help << "" << std::endl; - help << "For each command there is a short version and a long one. Subcommands (add/rm/ls/ch/reclaim) do not have short versions." << std::endl; - help << "" << std::endl; - help << programName << " admin/ad add/ch/rm/ls" << std::endl; - help << programName << " adminhost/ah add/ch/rm/ls" << std::endl; - help << programName << " archivefile/af ls" << std::endl; - help << programName << " archiveroute/ar add/ch/rm/ls" << std::endl; - help << programName << " drive/dr up/down/ls" << std::endl; - help << programName << " groupmountrule/gmr add/rm/ls/err" << std::endl; - help << programName << " listpendingarchives/lpa" << std::endl; - help << programName << " listpendingretrieves/lpr" << std::endl; - help << programName << " logicallibrary/ll add/ch/rm/ls" << std::endl; - help << programName << " mountpolicy/mp add/ch/rm/ls" << std::endl; - help << programName << " repack/re add/rm/ls/err" << std::endl; - help << programName << " requestermountrule/rmr add/rm/ls/err" << std::endl; - help << programName << " shrink/sh" << std::endl; - help << programName << " storageclass/sc add/ch/rm/ls" << std::endl; - help << programName << " tape/ta add/ch/rm/reclaim/ls/label" << std::endl; - help << programName << " tapepool/tp add/ch/rm/ls" << std::endl; - help << programName << " test/te read/write" << std::endl; - help << programName << " verify/ve add/rm/ls/err" << std::endl; - help << "" << std::endl; - help << "CTA EOS commands:" << std::endl; - help << "" << std::endl; - help << "For each command there is a short version and a long one." << std::endl; - help << "" << std::endl; - help << programName << " archive/a" << std::endl; - help << programName << " cancelretrieve/cr" << std::endl; - help << programName << " deletearchive/da" << std::endl; - help << programName << " liststorageclass/lsc" << std::endl; - help << programName << " retrieve/r" << std::endl; - help << programName << " updatefileinfo/ufi" << std::endl; - help << programName << " updatefilestorageclass/ufsc" << std::endl; - help << "" << std::endl; - help << "Special option for running " << programName << " within the EOS worflow engine:" << std::endl; - help << "" << std::endl; - help << programName << " ... --stderr" << std::endl; - help << "" << std::endl; - help << "The option tells " << programName << " to write results to both standard out and standard error." << - std::endl; - help << "The option must be specified as the very last command-line argument of " << programName << "." << std::endl; - return help.str(); -} #endif - + diff --git a/cmdline/CtaAdminCmd.hpp b/cmdline/CtaAdminCmd.hpp index 1a80970e74dbccc548979beed7ce701124023fd6..37d692897e37b34e191d956b267f029be1229ec3 100644 --- a/cmdline/CtaAdminCmd.hpp +++ b/cmdline/CtaAdminCmd.hpp @@ -20,6 +20,7 @@ #ifndef __CTA_ADMIN_CMD_HPP #define __CTA_ADMIN_CMD_HPP +#include <stdexcept> #include <string> #include <vector> @@ -32,8 +33,22 @@ public: private: /*! - * The command line parameters represented as a vector of strings + * Returns the help string + * + * @param programName The name of the client program + * + * @returns the help string */ + std::string getGenericHelp(const std::string &programName) const; + + /*! + * Placeholder for admin commands which have not been implemented yet + */ + void xCom_notimpl() const { + throw std::runtime_error("Command not implemented."); + } + + //! The command line parameters represented as a vector of strings std::vector<std::string> m_requestTokens; }; @@ -411,14 +426,6 @@ protected: */ void addLogInfoToResponseRow(std::vector<std::string> &responseRow, const cta::common::dataStructures::EntryLog &creationLog, const cta::common::dataStructures::EntryLog &lastModificationLog); - /** - * Returns the help string - * - * @param programName The name of the client program - * @return the help string - */ - std::string getGenericHelp(const std::string &programName) const; - /** * Converts a parameter string into a uint64_t (throws a cta::exception if it fails) * diff --git a/cmdline/CtaAdminCmdMain.cpp b/cmdline/CtaAdminCmdMain.cpp index 96697bbf2f7a9c0952fb5e832edeebc8ed6fde6c..2ae41adbad1c341b889a2a2798374ed0fca42369 100644 --- a/cmdline/CtaAdminCmdMain.cpp +++ b/cmdline/CtaAdminCmdMain.cpp @@ -68,9 +68,10 @@ const std::runtime_error Usage("Usage: cta_admin [command] [options]"); int exceptionThrowingMain(int argc, const char *const *const argv) { - // Tokenize the command line arguments + // Tokenize and parse the command line arguments CtaAdminCmd cmd(argc, argv); + #if 0 // Verify that the Google Protocol Buffer header and linked library versions are compatible