Commit d7ec9d21 authored by Steven Murray's avatar Steven Murray Committed by Cedric Caffy
Browse files

Added draft version of the 'cta-admin mediatype' command.

parent c2a82a65
......@@ -197,6 +197,8 @@ const cmdLookup_t cmdLookup = {
{ "lpr", AdminCmd::CMD_LISTPENDINGRETRIEVES },
{ "logicallibrary", AdminCmd::CMD_LOGICALLIBRARY },
{ "ll", AdminCmd::CMD_LOGICALLIBRARY },
{ "mediatype", AdminCmd::CMD_MEDIATYPE },
{ "mt", AdminCmd::CMD_MEDIATYPE },
{ "mountpolicy", AdminCmd::CMD_MOUNTPOLICY },
{ "mp", AdminCmd::CMD_MOUNTPOLICY },
{ "repack", AdminCmd::CMD_REPACK },
......@@ -281,12 +283,17 @@ const std::map<std::string, OptionUInt64::Key> uint64Options = {
{ "--id", OptionUInt64::ARCHIVE_FILE_ID },
{ "--lastfseq", OptionUInt64::LAST_FSEQ },
{ "--maxdrivesallowed", OptionUInt64::MAX_DRIVES_ALLOWED },
{ "--maxlpos", OptionUInt64::MAX_LPOS },
{ "--minarchiverequestage", OptionUInt64::MIN_ARCHIVE_REQUEST_AGE },
{ "--minlpos", OptionUInt64::MIN_LPOS },
{ "--minretrieverequestage", OptionUInt64::MIN_RETRIEVE_REQUEST_AGE },
{ "--nbfiles", OptionUInt64::NUMBER_OF_FILES },
{ "--nbwraps", OptionUInt64::NUMBER_OF_WRAPS },
{ "--partial", OptionUInt64::PARTIAL },
{ "--partialtapesnumber", OptionUInt64::PARTIAL_TAPES_NUMBER },
{ "--primarydensitycode", OptionUInt64::PRIMARY_DENSITY_CODE },
{ "--retrievepriority", OptionUInt64::RETRIEVE_PRIORITY },
{ "--secondarydensitycode", OptionUInt64::SECONDARY_DENSITY_CODE },
{ "--size", OptionUInt64::FILE_SIZE },
{ "--refreshinterval", OptionUInt64::REFRESH_INTERVAL },
{ "--targetedfreespace", OptionUInt64::TARGETED_FREE_SPACE },
......@@ -301,6 +308,7 @@ const std::map<std::string, OptionUInt64::Key> uint64Options = {
*/
const std::map<std::string, OptionString::Key> strOptions = {
{ "--bufferurl", OptionString::BUFFERURL },
{ "--cartridge", OptionString::CARTRIDGE },
{ "--comment", OptionString::COMMENT },
{ "--diskid", OptionString::DISKID },
{ "--drive", OptionString::DRIVE },
......@@ -357,6 +365,7 @@ const std::map<AdminCmd::Cmd, CmdHelp> cmdHelp = {
{ AdminCmd::CMD_LISTPENDINGARCHIVES, { "listpendingarchives", "lpa", { } }},
{ AdminCmd::CMD_LISTPENDINGRETRIEVES, { "listpendingretrieves", "lpr", { } }},
{ AdminCmd::CMD_LOGICALLIBRARY, { "logicallibrary", "ll", { "add", "ch", "rm", "ls" } }},
{ AdminCmd::CMD_MEDIATYPE, { "mediatype", "mt", { "add", "ch", "rm", "ls" } }},
{ AdminCmd::CMD_MOUNTPOLICY, { "mountpolicy", "mp", { "add", "ch", "rm", "ls" } }},
{ AdminCmd::CMD_REPACK, { "repack", "re", { "add", "rm", "ls", "err" },
"\n This command allows to manage repack requests.\n\n"
......@@ -411,6 +420,7 @@ const Option opt_archivefileid { Option::OPT_UINT, "--id",
const Option opt_archivepriority { Option::OPT_UINT, "--archivepriority", "--ap", " <priority_value>" };
const Option opt_bufferurl { Option::OPT_STR, "--bufferurl", "-b", " <buffer URL>" };
const Option opt_capacity { Option::OPT_UINT, "--capacity", "-c", " <capacity_in_bytes>" };
const Option opt_cartridge { Option::OPT_STR, "--cartridge", "-t", " <cartridge>" };
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_UINT, "--copynb", "-c", " <copy_number>" };
......@@ -442,8 +452,12 @@ const Option opt_logicallibrary_alias { Option::OPT_STR, "--name",
"--logicallibrary" };
const Option opt_lookupns { Option::OPT_FLAG, "--lookupnamespace", "-l", "" };
const Option opt_maxdrivesallowed { Option::OPT_UINT, "--maxdrivesallowed", "-d", " <max_drives_allowed>" };
const Option opt_mediatype { Option::OPT_STR, "--mediatype", "--mt", " <media_type>" };
const Option opt_maxlpos { Option::OPT_UINT, "--maxlpos", "-m", " <maximum_longitudinal_position>" };
const Option opt_mediatype { Option::OPT_STR, "--mediatype", "--mt", " <media_type_name>" };
const Option opt_mediatype_alias { Option::OPT_STR, "--name", "-n", " <media_type_name>",
"--mediatype" };
const Option opt_minarchiverequestage { Option::OPT_UINT, "--minarchiverequestage", "--aa", " <min_request_age>" };
const Option opt_minlpos { Option::OPT_UINT, "--minlpos", "-m", " <minimum_longitudinal_position>" };
const Option opt_minretrieverequestage{ Option::OPT_UINT, "--minretrieverequestage", "--ra", " <min_request_age>" };
const Option opt_mountpolicy { Option::OPT_STR, "--mountpolicy", "-u", " <mount_policy_name>" };
const Option opt_mountpolicy_alias { Option::OPT_STR, "--name", "-n", " <mount_policy_name>",
......@@ -451,12 +465,15 @@ const Option opt_mountpolicy_alias { Option::OPT_STR, "--name",
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_number_of_wraps { Option::OPT_UINT, "--nbwraps", "-w", " <number_of_wraps>" };
const Option opt_output { Option::OPT_STR, "--output", "-o", " <\"null\" or output_dir>" };
const Option opt_owner_uid { Option::OPT_UINT, "--uid", "-u", " <owner_uid>" };
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", " <full_path>" };
const Option opt_primarydensitycode { Option::OPT_UINT, "--primarydensitycode", "-p", " <primary_density_code>" };
const Option opt_retrievepriority { Option::OPT_UINT, "--retrievepriority", "--rp", " <priority_value>" };
const Option opt_secondarydensitycode { Option::OPT_UINT, "--secondarydensitycode", "-s", " <secondary_density_code>" };
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>",
......@@ -540,6 +557,13 @@ const std::map<cmd_key_t, cmd_val_t> cmdOptions = {
{{ AdminCmd::CMD_LOGICALLIBRARY, AdminCmd::SUBCMD_RM }, { opt_logicallibrary_alias }},
{{ AdminCmd::CMD_LOGICALLIBRARY, AdminCmd::SUBCMD_LS }, { }},
/*----------------------------------------------------------------------------------------------------*/
{{ AdminCmd::CMD_MEDIATYPE, AdminCmd::SUBCMD_ADD },
{ opt_mediatype_alias, opt_cartridge, opt_capacity, opt_primarydensitycode.optional(), opt_secondarydensitycode.optional(), opt_number_of_wraps.optional(), opt_minlpos.optional(), opt_maxlpos.optional(), opt_comment }},
{{ AdminCmd::CMD_MEDIATYPE, AdminCmd::SUBCMD_CH },
{ opt_mediatype_alias, opt_cartridge.optional(), opt_capacity.optional(), opt_primarydensitycode.optional(), opt_secondarydensitycode.optional(), opt_number_of_wraps.optional(), opt_minlpos.optional(), opt_maxlpos.optional(),opt_comment.optional() }},
{{ AdminCmd::CMD_MEDIATYPE, AdminCmd::SUBCMD_RM }, { opt_mediatype_alias }},
{{ AdminCmd::CMD_MEDIATYPE, AdminCmd::SUBCMD_LS }, { }},
/*----------------------------------------------------------------------------------------------------*/
{{ AdminCmd::CMD_MOUNTPOLICY, AdminCmd::SUBCMD_ADD },
{ opt_mountpolicy_alias, opt_archivepriority, opt_minarchiverequestage, opt_retrievepriority,
opt_minretrieverequestage, opt_maxdrivesallowed, opt_comment }},
......
/*!
* @project The CERN Tape Archive (CTA)
* @brief CTA Media Type Ls stream implementation
* @copyright Copyright 2019 CERN
* @license This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <xroot_plugins/XrdCtaStream.hpp>
#include <xroot_plugins/XrdSsiCtaRequestMessage.hpp>
namespace cta { namespace xrd {
/*!
* Stream object which implements the "mediatype ls" command
*/
class MediaTypeLsStream: public XrdCtaStream{
public:
/*!
* Constructor
*
* @param[in] requestMsg RequestMessage containing command-line arguments
* @param[in] catalogue CTA Catalogue
* @param[in] scheduler CTA Scheduler
*/
MediaTypeLsStream(const RequestMessage &requestMsg, cta::catalogue::Catalogue &catalogue, cta::Scheduler &scheduler);
private:
/*!
* Can we close the stream?
*/
virtual bool isDone() const {
return m_mediaTypeList.empty();
}
/*!
* Fill the buffer
*/
virtual int fillBuffer(XrdSsiPb::OStreamBuffer<Data> *streambuf);
std::list<cta::catalogue::MediaTypeWithLogs> m_mediaTypeList; //!< List of tape media types from the catalogue
static constexpr const char* const LOG_SUFFIX = "MediaTypeLsStream"; //!< Identifier for log messages
};
MediaTypeLsStream::MediaTypeLsStream(const RequestMessage &requestMsg, cta::catalogue::Catalogue &catalogue, cta::Scheduler &scheduler) :
XrdCtaStream(catalogue, scheduler),
m_mediaTypeList(catalogue.getMediaTypes())
{
using namespace cta::admin;
XrdSsiPb::Log::Msg(XrdSsiPb::Log::DEBUG, LOG_SUFFIX, "MediaTypeLsStream() constructor");
}
int MediaTypeLsStream::fillBuffer(XrdSsiPb::OStreamBuffer<Data> *streambuf) {
for(bool is_buffer_full = false; !m_mediaTypeList.empty() && !is_buffer_full; m_mediaTypeList.pop_front()) {
Data record;
auto &mt = m_mediaTypeList.front();
auto mt_item = record.mutable_mtls_item();
mt_item->set_name(mt.name);
mt_item->set_cartridge(mt.cartridge);
mt_item->set_capacity(mt.capacityInBytes);
mt_item->set_primary_density_code(mt.primaryDensityCode);
mt_item->set_secondary_density_code(mt.secondaryDensityCode);
if (mt.nbWraps) mt_item->set_number_of_wraps(mt.nbWraps.value());
if (mt.minLPos) mt_item->set_min_lpos(mt.minLPos.value());
if (mt.maxLPos) mt_item->set_max_lpos(mt.maxLPos.value());
mt_item->set_comment(mt.comment);
mt_item->mutable_creation_log()->set_username(mt.creationLog.username);
mt_item->mutable_creation_log()->set_host(mt.creationLog.host);
mt_item->mutable_creation_log()->set_time(mt.creationLog.time);
mt_item->mutable_last_modification_log()->set_username(mt.lastModificationLog.username);
mt_item->mutable_last_modification_log()->set_host(mt.lastModificationLog.host);
mt_item->mutable_last_modification_log()->set_time(mt.lastModificationLog.time);
is_buffer_full = streambuf->Push(record);
}
return streambuf->Size();
}
}} // namespace cta::xrd
......@@ -30,6 +30,7 @@ using XrdSsiPb::PbException;
#include "XrdCtaListPendingQueue.hpp"
#include "XrdCtaLogicalLibraryLs.hpp"
#include "XrdCtaMountPolicyLs.hpp"
#include "XrdCtaMediaTypeLs.hpp"
#include "XrdCtaRepackLs.hpp"
#include "XrdCtaRequesterMountRuleLs.hpp"
#include "XrdCtaShowQueues.hpp"
......@@ -41,6 +42,9 @@ using XrdSsiPb::PbException;
#include "XrdCtaVirtualOrganizationLs.hpp"
#include "XrdCtaVersion.hpp"
#include <limits>
#include <sstream>
namespace cta {
namespace xrd {
......@@ -160,6 +164,18 @@ void RequestMessage::process(const cta::xrd::Request &request, cta::xrd::Respons
case cmd_pair(AdminCmd::CMD_LOGICALLIBRARY, AdminCmd::SUBCMD_LS):
processLogicalLibrary_Ls(response, stream);
break;
case cmd_pair(AdminCmd::CMD_MEDIATYPE, AdminCmd::SUBCMD_ADD):
processMediaType_Add(response);
break;
case cmd_pair(AdminCmd::CMD_MEDIATYPE, AdminCmd::SUBCMD_CH):
processMediaType_Ch(response);
break;
case cmd_pair(AdminCmd::CMD_MEDIATYPE, AdminCmd::SUBCMD_RM):
processMediaType_Rm(response);
break;
case cmd_pair(AdminCmd::CMD_MEDIATYPE, AdminCmd::SUBCMD_LS):
processMediaType_Ls(response, stream);
break;
case cmd_pair(AdminCmd::CMD_MOUNTPOLICY, AdminCmd::SUBCMD_ADD):
processMountPolicy_Add(response);
break;
......@@ -1171,6 +1187,101 @@ void RequestMessage::processLogicalLibrary_Ls(cta::xrd::Response &response, XrdS
void RequestMessage::processMediaType_Add(cta::xrd::Response &response)
{
using namespace cta::admin;
// Bounds check unsigned integer options less than 64-bits in width
const uint64_t nbWraps = getRequired(OptionUInt64::NUMBER_OF_WRAPS);
const uint64_t primaryDensityCode = getRequired(OptionUInt64::PRIMARY_DENSITY_CODE);
const uint64_t secondaryDensityCode = getRequired(OptionUInt64::SECONDARY_DENSITY_CODE);
if(nbWraps > std::numeric_limits<uint32_t>::max()) {
exception::UserError ex;
ex.getMessage() << "Number of wraps cannot be larger than " << std::numeric_limits<uint32_t>::max() << ": value="
<< nbWraps;
throw ex;
}
if(primaryDensityCode > std::numeric_limits<uint8_t>::max()) {
exception::UserError ex;
ex.getMessage() << "Primary density code cannot be larger than " << (uint16_t)(std::numeric_limits<uint8_t>::max())
<< ": value=" << primaryDensityCode;
throw ex;
}
if(secondaryDensityCode > std::numeric_limits<uint8_t>::max()) {
exception::UserError ex;
ex.getMessage() << "Secondary density code cannot be larger than " << (uint16_t)(std::numeric_limits<uint8_t>::max())
<< ": value=" << secondaryDensityCode;
throw ex;
}
catalogue::MediaType mediaType;
mediaType.name = getRequired(OptionString::STORAGE_CLASS);
mediaType.cartridge = getRequired(OptionString::CARTRIDGE);
mediaType.capacityInBytes = getRequired(OptionUInt64::CAPACITY);
mediaType.primaryDensityCode = getRequired(OptionUInt64::PRIMARY_DENSITY_CODE);
mediaType.secondaryDensityCode = getRequired(OptionUInt64::SECONDARY_DENSITY_CODE);
mediaType.nbWraps = getRequired(OptionUInt64::NUMBER_OF_WRAPS);
mediaType.minLPos = getRequired(OptionUInt64::MIN_LPOS);
mediaType.maxLPos = getRequired(OptionUInt64::MAX_LPOS);
mediaType.comment = getRequired(OptionString::COMMENT);
m_catalogue.createMediaType(m_cliIdentity, mediaType);
response.set_type(cta::xrd::Response::RSP_SUCCESS);
}
void RequestMessage::processMediaType_Ch(cta::xrd::Response &response)
{
throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
using namespace cta::admin;
auto &scn = getRequired(OptionString::STORAGE_CLASS);
auto comment = getOptional(OptionString::COMMENT);
auto cn = getOptional(OptionUInt64::COPY_NUMBER);
auto vo = getOptional(OptionString::VO);
if(comment) {
m_catalogue.modifyStorageClassComment(m_cliIdentity, scn, comment.value());
}
if(cn) {
m_catalogue.modifyStorageClassNbCopies(m_cliIdentity, scn, cn.value());
}
if(vo){
m_catalogue.modifyStorageClassVo(m_cliIdentity,scn,vo.value());
}
response.set_type(cta::xrd::Response::RSP_SUCCESS);
}
void RequestMessage::processMediaType_Rm(cta::xrd::Response &response)
{
using namespace cta::admin;
const auto &mtn = getRequired(OptionString::MEDIA_TYPE);
m_catalogue.deleteMediaType(mtn);
response.set_type(cta::xrd::Response::RSP_SUCCESS);
}
void RequestMessage::processMediaType_Ls(cta::xrd::Response &response, XrdSsiStream* &stream)
{
using namespace cta::admin;
// Create a XrdSsi stream object to return the results
stream = new MediaTypeLsStream(*this, m_catalogue, m_scheduler);
response.set_show_header(HeaderType::MEDIATYPE_LS);
response.set_type(cta::xrd::Response::RSP_SUCCESS);
}
void RequestMessage::processMountPolicy_Add(cta::xrd::Response &response)
{
using namespace cta::admin;
......
......@@ -178,6 +178,9 @@ private:
void processLogicalLibrary_Add (cta::xrd::Response &response);
void processLogicalLibrary_Ch (cta::xrd::Response &response);
void processLogicalLibrary_Rm (cta::xrd::Response &response);
void processMediaType_Add (cta::xrd::Response &response);
void processMediaType_Ch (cta::xrd::Response &response);
void processMediaType_Rm (cta::xrd::Response &response);
void processMountPolicy_Add (cta::xrd::Response &response);
void processMountPolicy_Ch (cta::xrd::Response &response);
void processMountPolicy_Rm (cta::xrd::Response &response);
......@@ -223,6 +226,7 @@ private:
admincmdstream_t processListPendingArchives;
admincmdstream_t processListPendingRetrieves;
admincmdstream_t processLogicalLibrary_Ls;
admincmdstream_t processMediaType_Ls;
admincmdstream_t processMountPolicy_Ls;
admincmdstream_t processRequesterMountRule_Ls;
admincmdstream_t processShowQueues;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment