Commit 50399af1 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

Removed tape capacity in bytes in the CRUD of TAPE

cta-admin tape add does not take a capacity anymore
parent 5dbeed40
......@@ -472,6 +472,7 @@ public:
/**
* Creates a tape which is assumed to have logical block protection (LBP)
* enabled and isFromCastor disabled.
* TODO THIS METHOD IS DEPRECATED AND SHOULD BE REMOVED. IT IS USED ONLY IN THE UNIT TESTS ! USE THE ONE THAT USES THE TAPE DATASTRUCTURE INSTEAD
*/
virtual void createTape(
const common::dataStructures::SecurityIdentity &admin,
......@@ -485,6 +486,14 @@ public:
const bool full,
const bool readOnly,
const std::string &comment) = 0;
/**
* Creates a tape which is assumed to have logical block protection (LBP)
* enabled and isFromCastor disabled.
*/
virtual void createTape(
const common::dataStructures::SecurityIdentity &admin,
const common::dataStructures::Tape & tape) = 0;
virtual void deleteTape(const std::string &vid) = 0;
......
......@@ -299,6 +299,10 @@ public:
void createTape(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &mediaType, const std::string &vendor, const std::string &logicalLibraryName, const std::string &tapePoolName, const uint64_t capacityInBytes, const bool disabled, const bool full, const bool readOnly, const std::string &comment) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->createTape(admin, vid, mediaType, vendor, logicalLibraryName, tapePoolName, capacityInBytes, disabled, full, readOnly, comment);}, m_maxTriesToConnect);
}
void createTape(const common::dataStructures::SecurityIdentity &admin, const common::dataStructures::Tape & tape) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->createTape(admin, tape);}, m_maxTriesToConnect);
}
void deleteTape(const std::string &vid) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->deleteTape(vid);}, m_maxTriesToConnect);
......
......@@ -1140,6 +1140,26 @@ TEST_P(cta_catalogue_CatalogueTest, createMediaType_emptyStringCartridge) {
catalogue::UserSpecifiedAnEmptyStringCartridge);
}
 
TEST_P(cta_catalogue_CatalogueTest, createMediaType_zeroCapacity) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getMediaTypes().empty());
catalogue::MediaType mediaType;
mediaType.name = "media_type";
mediaType.cartridge = "cartridge";
mediaType.capacityInBytes = 0;
mediaType.primaryDensityCode = 2;
mediaType.secondaryDensityCode = 3;
mediaType.nbWraps = 4;
mediaType.minLPos = 5;
mediaType.maxLPos = 6;
mediaType.comment = "Create media type";
ASSERT_THROW(m_catalogue->createMediaType(m_admin, mediaType),
catalogue::UserSpecifiedAZeroCapacity);
}
TEST_P(cta_catalogue_CatalogueTest, deleteMediaType) {
using namespace cta;
 
......@@ -4386,52 +4406,6 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_emptyStringTapePoolName) {
capacityInBytes, disabledValue, fullValue, readOnlyValue, comment), catalogue::UserSpecifiedAnEmptyStringTapePoolName);
}
 
TEST_P(cta_catalogue_CatalogueTest, createTape_zeroCapacity) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getTapes().empty());
const std::string vid = "vid";
ASSERT_FALSE(m_catalogue->tapeExists(vid));
const std::string mediaType = "media_type";
const std::string vendor = "vendor";
const std::string logicalLibraryName = "logical_library_name";
const bool logicalLibraryIsDisabled= false;
const std::string tapePoolName = "tape_pool_name";
const std::string vo = "vo";
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
const cta::optional<std::string> supply("value for the supply pool mechanism");
const uint64_t capacityInBytes = 0;
const bool disabledValue = true;
const bool fullValue = false;
const bool readOnlyValue = true;
const std::string comment = "Create tape";
createMediaType(mediaType);
m_catalogue->createLogicalLibrary(m_admin, logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
createVo(vo);
m_catalogue->createTapePool(m_admin, tapePoolName, vo, nbPartialTapes, isEncrypted, supply, "Create tape pool");
{
const auto pools = m_catalogue->getTapePools();
ASSERT_EQ(1, pools.size());
const auto &pool = pools.front();
ASSERT_EQ(tapePoolName, pool.name);
ASSERT_EQ(vo, pool.vo.name);
ASSERT_EQ(0, pool.nbTapes);
ASSERT_EQ(0, pool.capacityBytes);
ASSERT_EQ(0, pool.dataBytes);
ASSERT_EQ(0, pool.nbPhysicalFiles);
}
ASSERT_THROW(m_catalogue->createTape(m_admin, vid, mediaType, vendor, logicalLibraryName, tapePoolName,
capacityInBytes, disabledValue, fullValue, readOnlyValue, comment), catalogue::UserSpecifiedAZeroCapacity);
}
TEST_P(cta_catalogue_CatalogueTest, createTape_emptyStringComment) {
using namespace cta;
 
......
......@@ -43,6 +43,7 @@ public:
void createRequesterMountRule(const common::dataStructures::SecurityIdentity& admin, const std::string& mountPolicyName, const std::string& diskInstance, const std::string& requesterName, const std::string& comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void createStorageClass(const common::dataStructures::SecurityIdentity& admin, const common::dataStructures::StorageClass& storageClass) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void createTape(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const std::string &mediaType, const std::string &vendor, const std::string& logicalLibraryName, const std::string& tapePoolName, const uint64_t capacityInBytes, const bool disabled, const bool full, const bool readOnly, const std::string& comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void createTape(const common::dataStructures::SecurityIdentity& admin, const common::dataStructures::Tape & tape) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void createMediaType(const common::dataStructures::SecurityIdentity &admin, const MediaType &mediaType) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void deleteMediaType(const std::string &name) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
std::list<MediaTypeWithLogs> getMediaTypes() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......
......@@ -38,9 +38,7 @@ struct MediaType {
* member-variables are left as null.
*/
MediaType():
capacityInBytes(0),
primaryDensityCode(0),
secondaryDensityCode(0) {
capacityInBytes(0) {
}
/**
......
......@@ -1089,7 +1089,9 @@ void RdbmsCatalogue::createMediaType(
throw UserSpecifiedAnEmptyStringComment(std::string("Cannot create media type ") + mediaType.name +
" because the comment is an empty string");
}
if(mediaType.capacityInBytes == 0){
throw UserSpecifiedAZeroCapacity(std::string("Cannot create media type ") + mediaType.name + " because the capacity is zero");
}
auto conn = m_connPool.getConn();
if(mediaTypeExists(conn, mediaType.name)) {
throw exception::UserError(std::string("Cannot create media type ") + mediaType.name +
......@@ -2944,24 +2946,30 @@ void RdbmsCatalogue::setLogicalLibraryDisabled(const common::dataStructures::Sec
}
}
void RdbmsCatalogue::createTape(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const std::string& mediaType, const std::string& vendor, const std::string& logicalLibraryName, const std::string& tapePoolName, const uint64_t capacityInBytes, const bool disabled, const bool full, const bool readOnly, const std::string& comment){
auto tape = cta::common::dataStructures::Tape::TapeFactory::createTape(vid,mediaType,vendor,logicalLibraryName,tapePoolName, disabled,full,readOnly,comment);
createTape(admin,tape);
}
//------------------------------------------------------------------------------
// createTape
//------------------------------------------------------------------------------
void RdbmsCatalogue::createTape(
const common::dataStructures::SecurityIdentity &admin,
const std::string &vid,
const std::string &mediaTypeName,
const std::string &vendor,
const std::string &logicalLibraryName,
const std::string &tapePoolName,
const uint64_t capacityInBytes,
const bool disabled,
const bool full,
const bool readOnly,
const std::string &comment) {
const common::dataStructures::Tape & tape) {
// CTA hard code this field to FALSE
const bool isFromCastor = false;
try {
std::string vid = tape.vid;
std::string mediaTypeName = tape.mediaType;
std::string vendor = tape.vendor;
std::string logicalLibraryName = tape.logicalLibraryName;
std::string tapePoolName = tape.tapePoolName;
std::string comment = tape.comment;
bool disabled = tape.disabled;
bool full = tape.full;
bool readOnly = tape.readOnly;
if(vid.empty()) {
throw UserSpecifiedAnEmptyStringVid("Cannot create tape because the VID is an empty string");
}
......@@ -2986,11 +2994,7 @@ void RdbmsCatalogue::createTape(
if(comment.empty()) {
throw UserSpecifiedAnEmptyStringComment("Cannot create tape because the comment is an empty string");
}
if(0 == capacityInBytes) {
throw UserSpecifiedAZeroCapacity("Cannot create tape because the capacity is zero");
}
auto conn = m_connPool.getConn();
if(tapeExists(conn, vid)) {
throw exception::UserError(std::string("Cannot create tape ") + vid +
......@@ -3004,7 +3008,7 @@ void RdbmsCatalogue::createTape(
const auto tapePoolId = getTapePoolId(conn, tapePoolName);
if(!tapePoolId) {
throw exception::UserError(std::string("Cannot create tape ") + vid + " because tape pool " +
tapePoolName + " does not exist");
tapePoolName + " does not exist");
}
const auto mediaTypeId = getMediaTypeId(conn, mediaTypeName);
......@@ -3453,8 +3457,7 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
}
if(searchCriteria.diskFileIds) {
// When searching by diskFileId, results are not guaranteed to be in sorted order
using namespace common::dataStructures;
tapes.sort([](const Tape &a, const Tape &b) { return a.vid < b.vid; });
tapes.sort([](const common::dataStructures::Tape &a, const common::dataStructures::Tape &b) { return a.vid < b.vid; });
}
return tapes;
......
......@@ -451,7 +451,9 @@ public:
virtual void setLogicalLibraryDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const bool disabledValue) override;
/**
* Creates a tape.
* Creates a tape which is assumed to have logical block protection (LBP)
* enabled and isFromCastor disabled.
* TODO THIS METHOD IS DEPRECATED AND SHOULD BE REMOVED. IT IS USED ONLY IN THE UNIT TESTS ! USE THE ONE THAT USES THE TAPE DATASTRUCTURE INSTEAD
*/
void createTape(
const common::dataStructures::SecurityIdentity &admin,
......@@ -466,6 +468,14 @@ public:
const bool readOnly,
const std::string &comment) override;
/**
* Creates a tape which is assumed to have logical block protection (LBP)
* enabled and isFromCastor disabled.
*/
void createTape(
const common::dataStructures::SecurityIdentity &admin,
const common::dataStructures::Tape & tape) override;
void deleteTape(const std::string &vid) override;
/**
......
......@@ -452,12 +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_maxlpos { Option::OPT_UINT, "--maxlpos", "-m", " <maximum_longitudinal_position>" };
const Option opt_maxlpos { Option::OPT_UINT, "--maxlpos", "-maxl", " <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_minlpos { Option::OPT_UINT, "--minlpos", "-minl", " <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>",
......@@ -597,11 +597,11 @@ const std::map<cmd_key_t, cmd_val_t> cmdOptions = {
{{ AdminCmd::CMD_STORAGECLASS, AdminCmd::SUBCMD_LS }, { }},
/*----------------------------------------------------------------------------------------------------*/
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_ADD },
{ opt_vid, opt_mediatype, opt_vendor, opt_logicallibrary, opt_tapepool, opt_capacity, opt_disabled, opt_full, opt_readonly,
{ opt_vid, opt_mediatype, opt_vendor, opt_logicallibrary, opt_tapepool, opt_disabled, opt_full, opt_readonly,
opt_comment.optional() }},
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_CH },
{ opt_vid, opt_mediatype.optional(), opt_vendor.optional(), opt_logicallibrary.optional(),
opt_tapepool.optional(), opt_capacity.optional(), opt_encryptionkeyname.optional(), opt_disabled.optional(),
opt_tapepool.optional(), opt_encryptionkeyname.optional(), opt_disabled.optional(),
opt_full.optional(), opt_readonly.optional(), opt_comment.optional() }},
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_RM }, { opt_vid }},
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_RECLAIM }, { opt_vid }},
......
......@@ -88,8 +88,23 @@ std::ostream &operator<<(std::ostream &os, const Tape &obj) {
<< " lastWriteLog=" << obj.lastWriteLog
<< " lastReadLog=" << obj.lastReadLog << ")";
return os;
}
common::dataStructures::Tape Tape::TapeFactory::createTape(const std::string& vid, const std::string& mediaType, const std::string& vendor, const std::string& logicalLibraryName, const std::string& tapePoolName, bool disabledValue, bool fullValue, bool readOnlyValue, const std::string& comment) {
cta::common::dataStructures::Tape tape;
tape.vid = vid;
tape.mediaType = mediaType;
tape.vendor = vendor;
tape.logicalLibraryName = logicalLibraryName;
tape.tapePoolName = tapePoolName;
tape.disabled = disabledValue;
tape.full = fullValue;
tape.readOnly = readOnlyValue;
tape.comment = comment;
return tape;
}
} // namespace dataStructures
} // namespace common
} // namespace cta
......@@ -75,6 +75,13 @@ struct Tape {
optional<TapeLog> labelLog;
optional<TapeLog> lastWriteLog;
optional<TapeLog> lastReadLog;
struct TapeFactory {
static common::dataStructures::Tape createTape(const std::string & vid, const std::string & mediaType,
const std::string & vendor, const std::string & logicalLibraryName,
const std::string & tapePoolName, bool disabledValue, bool fullValue,
bool readOnlyValue, const std::string & comment);
};
}; // struct Tape
......
......@@ -130,7 +130,6 @@ kubectl --namespace ${NAMESPACE} exec ctacli -- cta-admin --json version | jq
--vendor vendor \
--logicallibrary ${TAPEDRIVES_IN_USE[${i}%${NB_TAPEDRIVES_IN_USE}]} \
--tapepool ctasystest \
--capacity 1000000000 \
--comment "ctasystest" \
--vid ${VID} \
--disabled false \
......
......@@ -1673,13 +1673,15 @@ void RequestMessage::processTape_Add(cta::xrd::Response &response)
auto &vendor = getRequired(OptionString::VENDOR);
auto &logicallibrary = getRequired(OptionString::LOGICAL_LIBRARY);
auto &tapepool = getRequired(OptionString::TAPE_POOL);
auto &capacity = getRequired(OptionUInt64::CAPACITY);
auto &disabled = getRequired(OptionBoolean::DISABLED);
auto &full = getRequired(OptionBoolean::FULL);
auto &readOnly = getRequired(OptionBoolean::READ_ONLY);
auto comment = getOptional(OptionString::COMMENT);
m_catalogue.createTape(m_cliIdentity, vid, mediaType, vendor, logicallibrary, tapepool, capacity, disabled, full, readOnly, comment ? comment.value() : "-");
auto tape = common::dataStructures::Tape::TapeFactory::createTape(vid,mediaType,vendor,logicallibrary,tapepool,
disabled,full,readOnly,comment ? comment.value() : "-");
m_catalogue.createTape(m_cliIdentity, tape);
response.set_type(cta::xrd::Response::RSP_SUCCESS);
}
......
Markdown is supported
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