Commit 8ab646f4 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[catalogue] Modified Catalogue::createTape() for being able to add a tape with a STATE

parent 2297e6f8
......@@ -118,6 +118,9 @@ CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedStorageClassUsedByArchiveFiles);
CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedStorageClassUsedByArchiveRoutes);
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
......@@ -608,6 +611,13 @@ public:
virtual void modifyTapeLogicalLibraryName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &logicalLibraryName) = 0;
virtual void modifyTapeTapePoolName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &tapePoolName) = 0;
virtual void modifyTapeEncryptionKeyName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &encryptionKeyName) = 0;
/**
* Modify the state of the specified tape
* @param vid the VID of the tape to change the state
* @param state the new state
* @param stateReason the reason why the state changes, if the state is ACTIVE and the stateReason is nullopt, the state will be reset to null
* @param stateModifiedBy who modified the state of the tape (operator, tapeserver...)
*/
virtual void modifyTapeState(const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason, const std::string & stateModifiedBy) = 0;
/**
* Sets the full status of the specified tape.
......
......@@ -128,6 +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.comment = "Creation of tape one";
 
return tape;
......@@ -4241,6 +4242,69 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_same_twice) {
}
}
 
TEST_P(cta_catalogue_CatalogueTest, createTape_NoStateProvided) {
using namespace cta;
const bool logicalLibraryIsDisabled= false;
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
const cta::optional<std::string> supply("value for the supply pool mechanism");
m_catalogue->createMediaType(m_admin, m_mediaType);
m_catalogue->createLogicalLibrary(m_admin, m_tape1.logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
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);
}
TEST_P(cta_catalogue_CatalogueTest, createTape_StateDoesNotExist) {
using namespace cta;
const bool logicalLibraryIsDisabled= false;
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
const cta::optional<std::string> supply("value for the supply pool mechanism");
m_catalogue->createMediaType(m_admin, m_mediaType);
m_catalogue->createLogicalLibrary(m_admin, m_tape1.logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
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 = "DOES_NOT_EXIST";
ASSERT_THROW(m_catalogue->createTape(m_admin, tape),cta::catalogue::UserSpecifiedANonExistentTapeState);
}
TEST_P(cta_catalogue_CatalogueTest, createTape_StateNotActiveWithoutReasonShouldThrow) {
using namespace cta;
const bool logicalLibraryIsDisabled= false;
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
const cta::optional<std::string> supply("value for the supply pool mechanism");
m_catalogue->createMediaType(m_admin, m_mediaType);
m_catalogue->createLogicalLibrary(m_admin, m_tape1.logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
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 = cta::common::dataStructures::Tape::STATE_TO_STRING_MAP.at(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);
ASSERT_THROW(m_catalogue->createTape(m_admin, tape),cta::catalogue::UserSpecifiedAnEmptyStringReasonWhenTapeStateNotActive);
tape.stateReason = "Tape broken";
ASSERT_NO_THROW(m_catalogue->createTape(m_admin, tape));
}
TEST_P(cta_catalogue_CatalogueTest, createTape_many_tapes) {
using namespace cta;
 
......
......@@ -19,6 +19,7 @@
#pragma once
#include "common/optional.hpp"
#include "common/dataStructures/Tape.hpp"
#include <string>
......@@ -75,6 +76,16 @@ struct CreateTapeAttributes {
*/
optional<std::string> comment;
/**
* State of the tape
*/
std::string state;
/**
* Optional reason for the state
*/
cta::optional<std::string> stateReason;
/**
* Constructor.
*
......
......@@ -3187,6 +3187,23 @@ void RdbmsCatalogue::createTape(
if(tapePoolName.empty()) {
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");
}
try {
tapeState = common::dataStructures::Tape::STRING_TO_STATE_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."));
}
if(tapeState != common::dataStructures::Tape::ACTIVE){
if(!tape.stateReason){
throw UserSpecifiedAnEmptyStringReasonWhenTapeStateNotActive("Cannot create tape because no reason has been provided for the state " + tape.state);
}
}
auto conn = m_connPool.getConn();
if(tapeExists(conn, vid)) {
......@@ -3225,6 +3242,11 @@ void RdbmsCatalogue::createTape(
"IS_FROM_CASTOR," "\n"
"USER_COMMENT," "\n"
"TAPE_STATE," "\n"
"STATE_REASON," "\n"
"STATE_UPDATE_TIME," "\n"
"STATE_MODIFIED_BY," "\n"
"CREATION_LOG_USER_NAME," "\n"
"CREATION_LOG_HOST_NAME," "\n"
......@@ -3247,6 +3269,11 @@ void RdbmsCatalogue::createTape(
":IS_FROM_CASTOR," "\n"
":USER_COMMENT," "\n"
":TAPE_STATE," "\n"
":STATE_REASON," "\n"
":STATE_UPDATE_TIME," "\n"
":STATE_MODIFIED_BY," "\n"
":CREATION_LOG_USER_NAME," "\n"
":CREATION_LOG_HOST_NAME," "\n"
......@@ -3271,6 +3298,12 @@ void RdbmsCatalogue::createTape(
stmt.bindBool(":IS_FROM_CASTOR", isFromCastor);
stmt.bindString(":USER_COMMENT", tapeComment);
std::string stateModifiedBy = admin.username + "@" + admin.host;
stmt.bindString(":TAPE_STATE",tape.state);
stmt.bindString(":STATE_REASON",tape.stateReason);
stmt.bindUint64(":STATE_UPDATE_TIME",now);
stmt.bindString(":STATE_MODIFIED_BY", stateModifiedBy);
stmt.bindString(":CREATION_LOG_USER_NAME", admin.username);
stmt.bindString(":CREATION_LOG_HOST_NAME", admin.host);
......@@ -3294,6 +3327,10 @@ 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("stateReason",tape.stateReason ? tape.stateReason.value() : "")
.add("stateUpdateTime",now)
.add("stateModifiedBy",stateModifiedBy)
.add("creationLogUserName", admin.username)
.add("creationLogHostName", admin.host)
.add("creationLogTime", now);
......@@ -3483,6 +3520,11 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
"TAPE.WRITE_MOUNT_COUNT AS WRITE_MOUNT_COUNT,"
"TAPE.USER_COMMENT AS USER_COMMENT,"
"TAPE.TAPE_STATE AS TAPE_STATE,"
"TAPE.STATE_REASON AS TAPE_REASON,"
"TAPE.STATE_UPDATE_TIME AS STATE_UPDATE_TIME,"
"TAPE.STATE_MODIFIED_BY AS STATE_MODIFIED_BY,"
"TAPE.CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"TAPE.CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME,"
......
......@@ -26,6 +26,7 @@
#include <map>
#include <stdint.h>
#include <string>
#include <vector>
namespace cta {
namespace common {
......@@ -37,9 +38,9 @@ namespace dataStructures {
struct Tape {
enum State {
ACTIVE,
BROKEN,
DISABLED
ACTIVE = 1,
BROKEN = 2,
DISABLED = 3
};
static const std::map<State,std::string> STATE_TO_STRING_MAP;
......
This diff is collapsed.
......@@ -239,6 +239,21 @@ public:
return *ptr;
}
cta::catalogue::CreateTapeAttributes getDefaultTape(){
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
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.comment = "Comment";
return tape;
}
void setupDefaultCatalogue() {
using namespace cta;
auto & catalogue=getCatalogue();
......@@ -427,22 +442,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionGooddayRecall) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -624,22 +626,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionWrongRecall) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -830,22 +819,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionRAORecall) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -1031,22 +1007,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionRAORecallLinearAlgorithm) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -1229,22 +1192,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionRAORecallRAOAlgoDoesNotExistS
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -1429,22 +1379,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionRAORecallSLTFRAOAlgorithm) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -1632,22 +1569,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionNoSuchDrive) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -1794,22 +1718,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionFailtoMount) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -1966,22 +1877,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionGooddayMigration) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -2126,22 +2024,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionMissingFilesMigration) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -2301,21 +2186,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionTapeFullMigration) {
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......@@ -2443,7 +2316,6 @@ TEST_P(DataTransferSessionTest, DataTransferSessionTapeFullOnFlushMigration) {
setupDefaultCatalogue();
// 1) prepare the fake scheduler
std::string vid = s_vid;
// cta::MountType::Enum mountType = cta::MountType::RETRIEVE;
// 3) Prepare the necessary environment (logger, plus system wrapper),
......@@ -2474,22 +2346,9 @@ TEST_P(DataTransferSessionTest, DataTransferSessionTapeFullOnFlushMigration) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::catalogue::CreateTapeAttributes tape;
tape.vid = s_vid;
tape.mediaType = s_mediaType;
tape.vendor = s_vendor;
tape.logicalLibraryName = s_libraryName;
tape.tapePoolName = s_tapePoolName;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
tape.comment = tapeComment;
auto tape = getDefaultTape();
catalogue.createTape(s_adminOnAdminHost, tape);
}
......
......@@ -157,6 +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);
m_catalogue->createTape(admin, tape);
}
......@@ -322,6 +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);
m_catalogue->createTape(admin, tape);
}
......
......@@ -1745,6 +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);
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