Commit 1a4f647c authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[catalogue] CreateTapeAttribute object takes an enum instead of a string for the state of a tape

parent 8ab646f4
......@@ -120,7 +120,6 @@ CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedStorageClassUsedByFileRecycleLogs
CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedTapePoolUsedInAnArchiveRoute);
CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedANonExistentTapeState);
CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedAnEmptyStringReasonWhenTapeStateNotActive);
CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedAnEmptyStringTapeState);
/**
* Abstract class defining the interface to the CTA catalogue responsible for
......
......@@ -128,7 +128,7 @@ namespace {
tape.full = false;
tape.disabled = false;
tape.readOnly = false;
tape.state = common::dataStructures::Tape::STATE_TO_STRING_MAP.at(common::dataStructures::Tape::ACTIVE);
tape.state = common::dataStructures::Tape::ACTIVE;
tape.comment = "Creation of tape one";
 
return tape;
......@@ -4256,9 +4256,18 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_NoStateProvided) {
m_catalogue->createVirtualOrganization(m_admin, m_vo);
m_catalogue->createTapePool(m_admin, m_tape1.tapePoolName, m_vo.name, nbPartialTapes, isEncrypted, supply, "Create tape pool");
 
auto tape = m_tape1;
tape.state = "";
ASSERT_THROW(m_catalogue->createTape(m_admin, tape),cta::catalogue::UserSpecifiedAnEmptyStringTapeState);
catalogue::CreateTapeAttributes tape;
tape.vid = "VIDONE";
tape.mediaType = getMediaType().name;
tape.vendor = "vendor";
tape.logicalLibraryName = "logical_library";
tape.tapePoolName = "tape_pool";
tape.full = false;
tape.disabled = false;
tape.readOnly = false;
tape.comment = "Creation of tape one";
ASSERT_THROW(m_catalogue->createTape(m_admin, tape),cta::catalogue::UserSpecifiedANonExistentTapeState);
}
 
TEST_P(cta_catalogue_CatalogueTest, createTape_StateDoesNotExist) {
......@@ -4276,7 +4285,7 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_StateDoesNotExist) {
m_catalogue->createTapePool(m_admin, m_tape1.tapePoolName, m_vo.name, nbPartialTapes, isEncrypted, supply, "Create tape pool");
 
auto tape = m_tape1;
tape.state = "DOES_NOT_EXIST";
tape.state = (cta::common::dataStructures::Tape::State)42;
ASSERT_THROW(m_catalogue->createTape(m_admin, tape),cta::catalogue::UserSpecifiedANonExistentTapeState);
}
 
......@@ -4295,10 +4304,10 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_StateNotActiveWithoutReasonShould
m_catalogue->createTapePool(m_admin, m_tape1.tapePoolName, m_vo.name, nbPartialTapes, isEncrypted, supply, "Create tape pool");
 
auto tape = m_tape1;
tape.state = cta::common::dataStructures::Tape::STATE_TO_STRING_MAP.at(cta::common::dataStructures::Tape::DISABLED);
tape.state = cta::common::dataStructures::Tape::DISABLED;
ASSERT_THROW(m_catalogue->createTape(m_admin, tape),cta::catalogue::UserSpecifiedAnEmptyStringReasonWhenTapeStateNotActive);
tape.state = cta::common::dataStructures::Tape::STATE_TO_STRING_MAP.at(cta::common::dataStructures::Tape::BROKEN);
tape.state = cta::common::dataStructures::Tape::BROKEN;
ASSERT_THROW(m_catalogue->createTape(m_admin, tape),cta::catalogue::UserSpecifiedAnEmptyStringReasonWhenTapeStateNotActive);
tape.stateReason = "Tape broken";
......
......@@ -79,7 +79,7 @@ struct CreateTapeAttributes {
/**
* State of the tape
*/
std::string state;
cta::common::dataStructures::Tape::State state;
/**
* Optional reason for the state
......
......@@ -3188,18 +3188,18 @@ void RdbmsCatalogue::createTape(
throw UserSpecifiedAnEmptyStringTapePoolName("Cannot create tape because the tape pool name is an empty string");
}
common::dataStructures::Tape::State tapeState;
if(cta::utils::trimString(tape.state).empty()){
throw UserSpecifiedAnEmptyStringTapeState("Cannot create tape because no state has been specified");
}
std::string tapeState;
try {
tapeState = common::dataStructures::Tape::STRING_TO_STATE_MAP.at(tape.state);
tapeState = common::dataStructures::Tape::STATE_TO_STRING_MAP.at(tape.state);
} catch(std::out_of_range &) {
throw UserSpecifiedANonExistentTapeState(std::string("Cannot create tape because the state specified " + tape.state + " does not exist."));
std::string errorMsg = "Cannot create tape because the state specified does not exist. Possible values for state are:";
for(const auto &kv: common::dataStructures::Tape::STRING_TO_STATE_MAP){
errorMsg += " " + kv.first;
}
throw UserSpecifiedANonExistentTapeState(std::string(errorMsg));
}
if(tapeState != common::dataStructures::Tape::ACTIVE){
if(tape.state != common::dataStructures::Tape::ACTIVE){
if(!tape.stateReason){
throw UserSpecifiedAnEmptyStringReasonWhenTapeStateNotActive("Cannot create tape because no reason has been provided for the state " + tape.state);
}
......@@ -3300,7 +3300,7 @@ void RdbmsCatalogue::createTape(
stmt.bindString(":USER_COMMENT", tapeComment);
std::string stateModifiedBy = admin.username + "@" + admin.host;
stmt.bindString(":TAPE_STATE",tape.state);
stmt.bindString(":TAPE_STATE",cta::common::dataStructures::Tape::STATE_TO_STRING_MAP.at(tape.state));
stmt.bindString(":STATE_REASON",tape.stateReason);
stmt.bindUint64(":STATE_UPDATE_TIME",now);
stmt.bindString(":STATE_MODIFIED_BY", stateModifiedBy);
......@@ -3327,7 +3327,7 @@ void RdbmsCatalogue::createTape(
.add("isReadOnly", readOnly ? 1 : 0)
.add("isFromCastor", isFromCastor ? 1 : 0)
.add("userComment", tape.comment ? tape.comment.value() : "")
.add("tapeState",tape.state)
.add("tapeState",cta::common::dataStructures::Tape::STATE_TO_STRING_MAP.at(tape.state))
.add("stateReason",tape.stateReason ? tape.stateReason.value() : "")
.add("stateUpdateTime",now)
.add("stateModifiedBy",stateModifiedBy)
......
......@@ -251,7 +251,7 @@ public:
tape.full = false;
tape.disabled = false;
tape.readOnly = false;
tape.state = common::dataStructures::Tape::STATE_TO_STRING_MAP.at(common::dataStructures::Tape::ACTIVE);
tape.state = common::dataStructures::Tape::ACTIVE;
tape.comment = "Comment";
return tape;
......
......@@ -249,7 +249,7 @@ public:
tape.full = false;
tape.disabled = false;
tape.readOnly = false;
tape.state = cta::common::dataStructures::Tape::STATE_TO_STRING_MAP.at(cta::common::dataStructures::Tape::ACTIVE);
tape.state = cta::common::dataStructures::Tape::ACTIVE;
tape.comment = "Comment";
return tape;
}
......
......@@ -157,7 +157,7 @@ const uint32_t TEST_GROUP_2 = 9754;
tape.disabled = disabledValue;
tape.readOnly = readOnlyValue;
tape.comment = createTapeComment;
tape.state = cta::common::dataStructures::Tape::STATE_TO_STRING_MAP.at(cta::common::dataStructures::Tape::ACTIVE);
tape.state = cta::common::dataStructures::Tape::ACTIVE;
m_catalogue->createTape(admin, tape);
}
......@@ -323,7 +323,7 @@ const uint32_t TEST_GROUP_2 = 9754;
tape.disabled = disabledValue;
tape.readOnly = readOnlyValue;
tape.comment = createTapeComment;
tape.state = cta::common::dataStructures::Tape::STATE_TO_STRING_MAP.at(cta::common::dataStructures::Tape::ACTIVE);
tape.state = cta::common::dataStructures::Tape::ACTIVE;
m_catalogue->createTape(admin, tape);
}
......
......@@ -1745,7 +1745,7 @@ void RequestMessage::processTape_Add(cta::xrd::Response &response)
tape.disabled = disabled;
tape.readOnly = readOnly;
tape.comment = comment ? comment.value() : "";
tape.state = tape.state = common::dataStructures::Tape::STATE_TO_STRING_MAP.at(common::dataStructures::Tape::ACTIVE);
tape.state = common::dataStructures::Tape::ACTIVE;
m_catalogue.createTape(m_cliIdentity, tape);
response.set_type(cta::xrd::Response::RSP_SUCCESS);
......
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