diff --git a/cmdline/CtaAdminCmd.cpp b/cmdline/CtaAdminCmd.cpp index 10743de74069dfbb2e9831a44f859aaff3f1f7a7..0dc6dad2b0dc84cf3cd2404ef8fa5d59b07d6699 100644 --- a/cmdline/CtaAdminCmd.cpp +++ b/cmdline/CtaAdminCmd.cpp @@ -21,7 +21,6 @@ #include <iostream> #include "CtaAdminCmd.hpp" - #include "XrdSsiPbDebug.hpp" @@ -144,12 +143,16 @@ void CtaAdminCmd::addOption(const Option &option, const std::string &value) } break; } - case Option::OPT_INT: { + case Option::OPT_UINT: try { auto key = uint64Options.at(option.get_key()); auto new_opt = admincmd_ptr->add_option_uint64(); new_opt->set_key(key); new_opt->set_value(std::stoul(value)); break; + } catch(std::invalid_argument &) { + throw std::runtime_error(value + " is not a valid uint64: " + option.help()); + } catch(std::out_of_range &) { + throw std::runtime_error(value + " is out of range: " + option.help()); } } } diff --git a/cmdline/CtaAdminCmdParse.hpp b/cmdline/CtaAdminCmdParse.hpp index 9e23673f6057deb3f2b9b32057d706ffd4448400..f0b046490eba0432a1fd70967055c80628b01d85 100644 --- a/cmdline/CtaAdminCmdParse.hpp +++ b/cmdline/CtaAdminCmdParse.hpp @@ -34,7 +34,7 @@ namespace admin { class Option { public: - enum option_t { OPT_CMD, OPT_FLAG, OPT_BOOL, OPT_INT, OPT_STR }; + enum option_t { OPT_CMD, OPT_FLAG, OPT_BOOL, OPT_UINT, OPT_STR }; /*! * Constructor @@ -224,20 +224,20 @@ const subcmdLookup_t subcmdLookup = { */ const std::map<std::string, OptionBoolean::Key> boolOptions = { // Boolean options - { "--all", OptionBoolean::BOOL_ALL }, - { "--disabled", OptionBoolean::BOOL_DISABLED }, - { "--encrypted", OptionBoolean::BOOL_ENCRYPTED }, - { "--force", OptionBoolean::BOOL_FORCE }, - { "--full", OptionBoolean::BOOL_FULL }, - { "--lbp", OptionBoolean::BOOL_LBP }, + { "--all", OptionBoolean::ALL }, + { "--disabled", OptionBoolean::DISABLED }, + { "--encrypted", OptionBoolean::ENCRYPTED }, + { "--force", OptionBoolean::FORCE }, + { "--full", OptionBoolean::FULL }, + { "--lbp", OptionBoolean::LBP }, // hasOption options - { "--checkchecksum", OptionBoolean::BOOL_CHECK_CHECKSUM }, - { "--extended", OptionBoolean::BOOL_EXTENDED }, - { "--header", OptionBoolean::BOOL_SHOW_HEADER }, - { "--justexpand", OptionBoolean::BOOL_JUSTEXPAND }, - { "--justrepack", OptionBoolean::BOOL_JUSTREPACK }, - { "--summary", OptionBoolean::BOOL_SUMMARY } + { "--checkchecksum", OptionBoolean::CHECK_CHECKSUM }, + { "--extended", OptionBoolean::EXTENDED }, + { "--header", OptionBoolean::SHOW_HEADER }, + { "--justexpand", OptionBoolean::JUSTEXPAND }, + { "--justrepack", OptionBoolean::JUSTREPACK }, + { "--summary", OptionBoolean::SUMMARY } }; @@ -246,20 +246,20 @@ const std::map<std::string, OptionBoolean::Key> boolOptions = { * Map integer options to Protocol Buffer enum values */ const std::map<std::string, OptionUInt64::Key> uint64Options = { - { "--archivepriority", OptionUInt64::UINT64_ARCHIVE_PRIORITY }, - { "--capacity", OptionUInt64::UINT64_CAPACITY }, - { "--copynb", OptionUInt64::UINT64_COPY_NUMBER }, - { "--firstfseq", OptionUInt64::UINT64_FIRST_FSEQ }, - { "--id", OptionUInt64::UINT64_ARCHIVE_FILE_ID }, - { "--lastfseq", OptionUInt64::UINT64_LAST_FSEQ }, - { "--maxdrivesallowed", OptionUInt64::UINT64_MAX_DRIVES_ALLOWED }, - { "--minarchiverequestage", OptionUInt64::UINT64_MIN_ARCHIVE_REQUEST_AGE }, - { "--minretrieverequestage", OptionUInt64::UINT64_MIN_RETRIEVE_REQUEST_AGE }, - { "--nbfiles", OptionUInt64::UINT64_NUMBER_OF_FILES }, - { "--partial", OptionUInt64::UINT64_PARTIAL }, - { "--partialtapesnumber", OptionUInt64::UINT64_PARTIAL_TAPES_NUMBER }, - { "--retrievepriority", OptionUInt64::UINT64_RETRIEVE_PRIORITY }, - { "--size", OptionUInt64::UINT64_FILE_SIZE } + { "--archivepriority", OptionUInt64::ARCHIVE_PRIORITY }, + { "--capacity", OptionUInt64::CAPACITY }, + { "--copynb", OptionUInt64::COPY_NUMBER }, + { "--firstfseq", OptionUInt64::FIRST_FSEQ }, + { "--id", OptionUInt64::ARCHIVE_FILE_ID }, + { "--lastfseq", OptionUInt64::LAST_FSEQ }, + { "--maxdrivesallowed", OptionUInt64::MAX_DRIVES_ALLOWED }, + { "--minarchiverequestage", OptionUInt64::MIN_ARCHIVE_REQUEST_AGE }, + { "--minretrieverequestage", OptionUInt64::MIN_RETRIEVE_REQUEST_AGE }, + { "--nbfiles", OptionUInt64::NUMBER_OF_FILES }, + { "--partial", OptionUInt64::PARTIAL }, + { "--partialtapesnumber", OptionUInt64::PARTIAL_TAPES_NUMBER }, + { "--retrievepriority", OptionUInt64::RETRIEVE_PRIORITY }, + { "--size", OptionUInt64::FILE_SIZE } }; @@ -268,25 +268,25 @@ const std::map<std::string, OptionUInt64::Key> uint64Options = { * Map string options to Protocol Buffer enum values */ const std::map<std::string, OptionString::Key> strOptions = { - { "--comment", OptionString::STR_COMMENT }, - { "--diskid", OptionString::STR_DISKID }, - { "--drive", OptionString::STR_DRIVE }, - { "--encryptionkey", OptionString::STR_ENCRYPTION_KEY }, - { "--file", OptionString::STR_FILENAME }, - { "--group", OptionString::STR_GROUP }, - { "--hostname", OptionString::STR_HOSTNAME }, - { "--input", OptionString::STR_INPUT }, - { "--instance", OptionString::STR_INSTANCE }, - { "--logicallibrary", OptionString::STR_LOGICAL_LIBRARY }, - { "--mountpolicy", OptionString::STR_MOUNT_POLICY }, - { "--output", OptionString::STR_OUTPUT }, - { "--owner", OptionString::STR_OWNER }, - { "--path", OptionString::STR_PATH }, - { "--storageclass", OptionString::STR_STORAGE_CLASS }, - { "--tag", OptionString::STR_TAG }, - { "--tapepool", OptionString::STR_TAPE_POOL }, - { "--username", OptionString::STR_USERNAME }, - { "--vid", OptionString::STR_VID } + { "--comment", OptionString::COMMENT }, + { "--diskid", OptionString::DISKID }, + { "--drive", OptionString::DRIVE }, + { "--encryptionkey", OptionString::ENCRYPTION_KEY }, + { "--file", OptionString::FILENAME }, + { "--group", OptionString::GROUP }, + { "--hostname", OptionString::HOSTNAME }, + { "--input", OptionString::INPUT }, + { "--instance", OptionString::INSTANCE }, + { "--logicallibrary", OptionString::LOGICAL_LIBRARY }, + { "--mountpolicy", OptionString::MOUNT_POLICY }, + { "--output", OptionString::OUTPUT }, + { "--owner", OptionString::OWNER }, + { "--path", OptionString::PATH }, + { "--storageclass", OptionString::STORAGE_CLASS }, + { "--tag", OptionString::TAG }, + { "--tapepool", OptionString::TAPE_POOL }, + { "--username", OptionString::USERNAME }, + { "--vid", OptionString::VID } }; @@ -331,12 +331,12 @@ const std::map<AdminCmd::Cmd, CmdHelp> cmdHelp = { * Enumerate options */ const Option opt_all { Option::OPT_FLAG, "--all", "-a", "" }; -const Option opt_archivefileid { Option::OPT_INT, "--id", "-I", " <archive_file_id>" }; -const Option opt_archivepriority { Option::OPT_INT, "--archivepriority", "--ap", " <priority_value>" }; -const Option opt_capacity { Option::OPT_INT, "--capacity", "-c", " <capacity_in_bytes>" }; +const Option opt_archivefileid { Option::OPT_UINT, "--id", "-I", " <archive_file_id>" }; +const Option opt_archivepriority { Option::OPT_UINT, "--archivepriority", "--ap", " <priority_value>" }; +const Option opt_capacity { Option::OPT_UINT, "--capacity", "-c", " <capacity_in_bytes>" }; const Option opt_checkchecksum { Option::OPT_FLAG, "--checkchecksum", "-c", "" }; const Option opt_comment { Option::OPT_STR, "--comment", "-m", " <\"comment\">" }; -const Option opt_copynb { Option::OPT_INT, "--copynb", "-c", " <copy_number>" }; +const Option opt_copynb { Option::OPT_UINT, "--copynb", "-c", " <copy_number>" }; const Option opt_disabled { Option::OPT_BOOL, "--disabled", "-d", " <\"true\" or \"false\">" }; const Option opt_diskid { Option::OPT_STR, "--diskid", "-d", " <disk_id>" }; const Option opt_drivename { Option::OPT_STR, "--drive", "-d", " <drive_name>" }; @@ -345,7 +345,7 @@ const Option opt_encrypted { Option::OPT_BOOL, "--encrypted", const Option opt_encryptionkey { Option::OPT_STR, "--encryptionkey", "-k", " <encryption_key>" }; const Option opt_extended { Option::OPT_FLAG, "--extended", "-x", "" }; const Option opt_filename { Option::OPT_STR, "--file", "-f", " <filename>" }; -const Option opt_firstfseq { Option::OPT_INT, "--firstfseq", "-f", " <first_fseq>" }; +const Option opt_firstfseq { Option::OPT_UINT, "--firstfseq", "-f", " <first_fseq>" }; const Option opt_force { Option::OPT_BOOL, "--force", "-f", " <\"true\" or \"false\">" }; const Option opt_force_flag { Option::OPT_FLAG, "--force", "-f", "" }; const Option opt_group { Option::OPT_STR, "--group", "-g", " <group>" }; @@ -356,27 +356,27 @@ const Option opt_input { Option::OPT_STR, "--input", const Option opt_instance { Option::OPT_STR, "--instance", "-i", " <instance_name>" }; const Option opt_justexpand { Option::OPT_FLAG, "--justexpand", "-e", "" }; const Option opt_justrepack { Option::OPT_FLAG, "--justrepack", "-r", "" }; -const Option opt_lastfseq { Option::OPT_INT, "--lastfseq", "-l", " <last_fseq>" }; +const Option opt_lastfseq { Option::OPT_UINT, "--lastfseq", "-l", " <last_fseq>" }; const Option opt_lbp { Option::OPT_BOOL, "--lbp", "-p", " <\"true\" or \"false\">" }; const Option opt_logicallibrary { Option::OPT_STR, "--logicallibrary", "-l", " <logical_library_name>" }; const Option opt_logicallibrary_alias { Option::OPT_STR, "--name", "-n", " <logical_library_name>", "--logicallibrary" }; -const Option opt_maxdrivesallowed { Option::OPT_INT, "--maxdrivesallowed", "-d", " <maxDrivesAllowed>" }; -const Option opt_minarchiverequestage { Option::OPT_INT, "--minarchiverequestage", "--aa", " <minRequestAge>" }; -const Option opt_minretrieverequestage{ Option::OPT_INT, "--minretrieverequestage", "--ra", " <minRequestAge>" }; +const Option opt_maxdrivesallowed { Option::OPT_UINT, "--maxdrivesallowed", "-d", " <maxDrivesAllowed>" }; +const Option opt_minarchiverequestage { Option::OPT_UINT, "--minarchiverequestage", "--aa", " <minRequestAge>" }; +const Option opt_minretrieverequestage{ Option::OPT_UINT, "--minretrieverequestage", "--ra", " <minRequestAge>" }; const Option opt_mountpolicy { Option::OPT_STR, "--mountpolicy", "-u", " <mountpolicy_name>" }; const Option opt_mountpolicy_alias { Option::OPT_STR, "--name", "-n", " <mountpolicy_name>", "--mountpolicy" }; -const Option opt_number_of_files { Option::OPT_INT, "--nbfiles", "-n", " <number_of_files_per_tape>" }; -const Option opt_number_of_files_alias{ Option::OPT_INT, "--number", "-n", " <number_of_files>", +const Option opt_number_of_files { Option::OPT_UINT, "--nbfiles", "-n", " <number_of_files_per_tape>" }; +const Option opt_number_of_files_alias{ Option::OPT_UINT, "--number", "-n", " <number_of_files>", "--nbfiles" }; const Option opt_output { Option::OPT_STR, "--output", "-o", " <\"null\" or output_dir>" }; const Option opt_owner { Option::OPT_STR, "--owner", "-o", " <owner>" }; -const Option opt_partialfiles { Option::OPT_INT, "--partial", "-p", " <number_of_files_per_tape>" }; -const Option opt_partialtapes { Option::OPT_INT, "--partialtapesnumber", "-p", " <number_of_partial_tapes>" }; +const Option opt_partialfiles { Option::OPT_UINT, "--partial", "-p", " <number_of_files_per_tape>" }; +const Option opt_partialtapes { Option::OPT_UINT, "--partialtapesnumber", "-p", " <number_of_partial_tapes>" }; const Option opt_path { Option::OPT_STR, "--path", "-p", " <fullpath>" }; -const Option opt_retrievepriority { Option::OPT_INT, "--retrievepriority", "--rp", " <priority_value>" }; -const Option opt_size { Option::OPT_INT, "--size", "-s", " <file_size>" }; +const Option opt_retrievepriority { Option::OPT_UINT, "--retrievepriority", "--rp", " <priority_value>" }; +const Option opt_size { Option::OPT_UINT, "--size", "-s", " <file_size>" }; const Option opt_storageclass { Option::OPT_STR, "--storageclass", "-s", " <storage_class_name>" }; const Option opt_storageclass_alias { Option::OPT_STR, "--name", "-n", " <storage_class_name>", "--storageclass" }; diff --git a/xroot_plugins/messages/cta_admin.proto b/xroot_plugins/messages/cta_admin.proto index c8e85320501950876e83740e60d4090f0d567dc4..88b8ee85bde9f2496ec2be60d0a48d66e7074c6d 100644 --- a/xroot_plugins/messages/cta_admin.proto +++ b/xroot_plugins/messages/cta_admin.proto @@ -23,20 +23,20 @@ package cta.admin; message OptionBoolean { enum Key { - BOOL_DISABLED = 0; - BOOL_ENCRYPTED = 1; - BOOL_FORCE = 2; - BOOL_FULL = 3; - BOOL_LBP = 4; + DISABLED = 0; + ENCRYPTED = 1; + FORCE = 2; + FULL = 3; + LBP = 4; // hasOption options - BOOL_ALL = 5; - BOOL_CHECK_CHECKSUM = 6; - BOOL_EXTENDED = 7; - BOOL_SHOW_HEADER = 8; - BOOL_JUSTEXPAND = 9; - BOOL_JUSTREPACK = 10; - BOOL_SUMMARY = 11; + ALL = 5; + CHECK_CHECKSUM = 6; + EXTENDED = 7; + SHOW_HEADER = 8; + JUSTEXPAND = 9; + JUSTREPACK = 10; + SUMMARY = 11; } Key key = 1; @@ -45,20 +45,20 @@ message OptionBoolean { message OptionUInt64 { enum Key { - UINT64_ARCHIVE_FILE_ID = 0; - UINT64_ARCHIVE_PRIORITY = 1; - UINT64_RETRIEVE_PRIORITY = 2; - UINT64_CAPACITY = 3; - UINT64_COPY_NUMBER = 4; - UINT64_FIRST_FSEQ = 5; - UINT64_FILE_SIZE = 6; - UINT64_LAST_FSEQ = 7; - UINT64_MAX_DRIVES_ALLOWED = 8; - UINT64_MIN_ARCHIVE_REQUEST_AGE = 9; - UINT64_MIN_RETRIEVE_REQUEST_AGE = 10; - UINT64_NUMBER_OF_FILES = 11; - UINT64_PARTIAL = 12; - UINT64_PARTIAL_TAPES_NUMBER = 13; + ARCHIVE_FILE_ID = 0; + ARCHIVE_PRIORITY = 1; + RETRIEVE_PRIORITY = 2; + CAPACITY = 3; + COPY_NUMBER = 4; + FIRST_FSEQ = 5; + FILE_SIZE = 6; + LAST_FSEQ = 7; + MAX_DRIVES_ALLOWED = 8; + MIN_ARCHIVE_REQUEST_AGE = 9; + MIN_RETRIEVE_REQUEST_AGE = 10; + NUMBER_OF_FILES = 11; + PARTIAL = 12; + PARTIAL_TAPES_NUMBER = 13; } Key key = 1; @@ -67,25 +67,25 @@ message OptionUInt64 { message OptionString { enum Key { - STR_COMMENT = 0; - STR_DISKID = 1; - STR_DRIVE = 2; - STR_ENCRYPTION_KEY = 3; - STR_FILENAME = 4; - STR_GROUP = 5; - STR_HOSTNAME = 6; - STR_INPUT = 7; - STR_INSTANCE = 8; - STR_LOGICAL_LIBRARY = 9; - STR_MOUNT_POLICY = 10; - STR_OUTPUT = 11; - STR_OWNER = 12; - STR_PATH = 13; - STR_STORAGE_CLASS = 14; - STR_TAG = 15; - STR_TAPE_POOL = 16; - STR_USERNAME = 17; - STR_VID = 18; + COMMENT = 0; + DISKID = 1; + DRIVE = 2; + ENCRYPTION_KEY = 3; + FILENAME = 4; + GROUP = 5; + HOSTNAME = 6; + INPUT = 7; + INSTANCE = 8; + LOGICAL_LIBRARY = 9; + MOUNT_POLICY = 10; + OUTPUT = 11; + OWNER = 12; + PATH = 13; + STORAGE_CLASS = 14; + TAG = 15; + TAPE_POOL = 16; + USERNAME = 17; + VID = 18; } Key key = 1;