Commit 82b9c779 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

Removed NOT NULL constraint on TAPE USER_COMMENT column

Modified cta-admin to allow a user to not specify a comment
parent 4b4b6b4e
......@@ -194,7 +194,7 @@ CREATE TABLE TAPE(
LAST_WRITE_TIME BIGINT UNSIGNED ,
READ_MOUNT_COUNT BIGINT UNSIGNED DEFAULT 0 CONSTRAINT TAPE_RMC_NN NOT NULL,
WRITE_MOUNT_COUNT BIGINT UNSIGNED DEFAULT 0 CONSTRAINT TAPE_WMC_NN NOT NULL,
USER_COMMENT VARCHAR(1000) CONSTRAINT TAPE_UC_NN NOT NULL,
USER_COMMENT VARCHAR(1000),
CREATION_LOG_USER_NAME VARCHAR(100) CONSTRAINT TAPE_CLUN_NN NOT NULL,
CREATION_LOG_HOST_NAME VARCHAR(100) CONSTRAINT TAPE_CLHN_NN NOT NULL,
CREATION_LOG_TIME BIGINT UNSIGNED CONSTRAINT TAPE_CLT_NN NOT NULL,
......
......@@ -223,7 +223,7 @@ CREATE TABLE TAPE(
LAST_WRITE_TIME NUMERIC(20, 0) ,
READ_MOUNT_COUNT NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_RMC_NN NOT NULL,
WRITE_MOUNT_COUNT NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_WMC_NN NOT NULL,
USER_COMMENT VARCHAR2(1000) CONSTRAINT TAPE_UC_NN NOT NULL,
USER_COMMENT VARCHAR2(1000),
CREATION_LOG_USER_NAME VARCHAR2(100) CONSTRAINT TAPE_CLUN_NN NOT NULL,
CREATION_LOG_HOST_NAME VARCHAR2(100) CONSTRAINT TAPE_CLHN_NN NOT NULL,
CREATION_LOG_TIME NUMERIC(20, 0) CONSTRAINT TAPE_CLT_NN NOT NULL,
......
......@@ -206,7 +206,7 @@ CREATE TABLE TAPE(
LAST_WRITE_TIME NUMERIC(20, 0) ,
READ_MOUNT_COUNT NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_RMC_NN NOT NULL,
WRITE_MOUNT_COUNT NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_WMC_NN NOT NULL,
USER_COMMENT VARCHAR(1000) CONSTRAINT TAPE_UC_NN NOT NULL,
USER_COMMENT VARCHAR(1000),
CREATION_LOG_USER_NAME VARCHAR(100) CONSTRAINT TAPE_CLUN_NN NOT NULL,
CREATION_LOG_HOST_NAME VARCHAR(100) CONSTRAINT TAPE_CLHN_NN NOT NULL,
CREATION_LOG_TIME NUMERIC(20, 0) CONSTRAINT TAPE_CLT_NN NOT NULL,
......
......@@ -182,7 +182,7 @@ CREATE TABLE TAPE(
LAST_WRITE_TIME INTEGER ,
READ_MOUNT_COUNT INTEGER DEFAULT 0 CONSTRAINT TAPE_RMC_NN NOT NULL,
WRITE_MOUNT_COUNT INTEGER DEFAULT 0 CONSTRAINT TAPE_WMC_NN NOT NULL,
USER_COMMENT VARCHAR(1000) CONSTRAINT TAPE_UC_NN NOT NULL,
USER_COMMENT VARCHAR(1000),
CREATION_LOG_USER_NAME VARCHAR(100) CONSTRAINT TAPE_CLUN_NN NOT NULL,
CREATION_LOG_HOST_NAME VARCHAR(100) CONSTRAINT TAPE_CLHN_NN NOT NULL,
CREATION_LOG_TIME INTEGER CONSTRAINT TAPE_CLT_NN NOT NULL,
......
......@@ -4027,7 +4027,7 @@ namespace catalogue{
" LAST_WRITE_TIME NUMERIC(20, 0) ,"
" READ_MOUNT_COUNT NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_RMC_NN NOT NULL,"
" WRITE_MOUNT_COUNT NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_WMC_NN NOT NULL,"
" USER_COMMENT VARCHAR2(1000) CONSTRAINT TAPE_UC_NN NOT NULL,"
" USER_COMMENT VARCHAR2(1000),"
" CREATION_LOG_USER_NAME VARCHAR2(100) CONSTRAINT TAPE_CLUN_NN NOT NULL,"
" CREATION_LOG_HOST_NAME VARCHAR2(100) CONSTRAINT TAPE_CLHN_NN NOT NULL,"
" CREATION_LOG_TIME NUMERIC(20, 0) CONSTRAINT TAPE_CLT_NN NOT NULL,"
......@@ -4413,7 +4413,7 @@ namespace catalogue{
" LAST_WRITE_TIME BIGINT UNSIGNED ,"
" READ_MOUNT_COUNT BIGINT UNSIGNED DEFAULT 0 CONSTRAINT TAPE_RMC_NN NOT NULL,"
" WRITE_MOUNT_COUNT BIGINT UNSIGNED DEFAULT 0 CONSTRAINT TAPE_WMC_NN NOT NULL,"
" USER_COMMENT VARCHAR(1000) CONSTRAINT TAPE_UC_NN NOT NULL,"
" USER_COMMENT VARCHAR(1000),"
" CREATION_LOG_USER_NAME VARCHAR(100) CONSTRAINT TAPE_CLUN_NN NOT NULL,"
" CREATION_LOG_HOST_NAME VARCHAR(100) CONSTRAINT TAPE_CLHN_NN NOT NULL,"
" CREATION_LOG_TIME BIGINT UNSIGNED CONSTRAINT TAPE_CLT_NN NOT NULL,"
......@@ -4786,7 +4786,7 @@ namespace catalogue{
" LAST_WRITE_TIME INTEGER ,"
" READ_MOUNT_COUNT INTEGER DEFAULT 0 CONSTRAINT TAPE_RMC_NN NOT NULL,"
" WRITE_MOUNT_COUNT INTEGER DEFAULT 0 CONSTRAINT TAPE_WMC_NN NOT NULL,"
" USER_COMMENT VARCHAR(1000) CONSTRAINT TAPE_UC_NN NOT NULL,"
" USER_COMMENT VARCHAR(1000),"
" CREATION_LOG_USER_NAME VARCHAR(100) CONSTRAINT TAPE_CLUN_NN NOT NULL,"
" CREATION_LOG_HOST_NAME VARCHAR(100) CONSTRAINT TAPE_CLHN_NN NOT NULL,"
" CREATION_LOG_TIME INTEGER CONSTRAINT TAPE_CLT_NN NOT NULL,"
......@@ -5181,7 +5181,7 @@ namespace catalogue{
" LAST_WRITE_TIME NUMERIC(20, 0) ,"
" READ_MOUNT_COUNT NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_RMC_NN NOT NULL,"
" WRITE_MOUNT_COUNT NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_WMC_NN NOT NULL,"
" USER_COMMENT VARCHAR(1000) CONSTRAINT TAPE_UC_NN NOT NULL,"
" USER_COMMENT VARCHAR(1000),"
" CREATION_LOG_USER_NAME VARCHAR(100) CONSTRAINT TAPE_CLUN_NN NOT NULL,"
" CREATION_LOG_HOST_NAME VARCHAR(100) CONSTRAINT TAPE_CLHN_NN NOT NULL,"
" CREATION_LOG_TIME NUMERIC(20, 0) CONSTRAINT TAPE_CLT_NN NOT NULL,"
......
......@@ -4406,52 +4406,6 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_emptyStringTapePoolName) {
capacityInBytes, disabledValue, fullValue, readOnlyValue, comment), catalogue::UserSpecifiedAnEmptyStringTapePoolName);
}
 
TEST_P(cta_catalogue_CatalogueTest, createTape_emptyStringComment) {
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 = (uint64_t)10 * 1000 * 1000 * 1000 * 1000;
const bool disabledValue = true;
const bool fullValue = false;
const bool readOnlyValue = true;
const std::string comment = "";
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::UserSpecifiedAnEmptyStringComment);
}
TEST_P(cta_catalogue_CatalogueTest, createTape_non_existent_logical_library) {
using namespace cta;
 
......
......@@ -2990,10 +2990,6 @@ void RdbmsCatalogue::createTape(
if(tapePoolName.empty()) {
throw UserSpecifiedAnEmptyStringTapePoolName("Cannot create tape because the tape pool name is an empty string");
}
if(comment.empty()) {
throw UserSpecifiedAnEmptyStringComment("Cannot create tape because the comment is an empty string");
}
auto conn = m_connPool.getConn();
if(tapeExists(conn, vid)) {
......@@ -3077,7 +3073,9 @@ void RdbmsCatalogue::createTape(
stmt.bindBool(":IS_READ_ONLY", readOnly);
stmt.bindBool(":IS_FROM_CASTOR", isFromCastor);
stmt.bindString(":USER_COMMENT", comment);
cta::optional<std::string> optionalComment;
if(!comment.empty()) optionalComment = comment;
stmt.bindString(":USER_COMMENT", optionalComment);
stmt.bindString(":CREATION_LOG_USER_NAME", admin.username);
stmt.bindString(":CREATION_LOG_HOST_NAME", admin.host);
......@@ -3444,7 +3442,8 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
tape.readMountCount = rset.columnUint64("READ_MOUNT_COUNT");
tape.writeMountCount = rset.columnUint64("WRITE_MOUNT_COUNT");
tape.comment = rset.columnString("USER_COMMENT");
auto optionalComment = rset.columnOptionalString("USER_COMMENT");
tape.comment = optionalComment ? optionalComment.value() : "";
tape.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME");
tape.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME");
tape.creationLog.time = rset.columnUint64("CREATION_LOG_TIME");
......@@ -3577,7 +3576,8 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getTapesByVid(const std::se
tape.readMountCount = rset.columnUint64("READ_MOUNT_COUNT");
tape.writeMountCount = rset.columnUint64("WRITE_MOUNT_COUNT");
tape.comment = rset.columnString("USER_COMMENT");
auto optionalComment = rset.columnOptionalString("USER_COMMENT");
tape.comment = optionalComment ? optionalComment.value() : "";
tape.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME");
tape.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME");
tape.creationLog.time = rset.columnUint64("CREATION_LOG_TIME");
......@@ -3685,7 +3685,8 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getAllTapes() const {
tape.readMountCount = rset.columnUint64("READ_MOUNT_COUNT");
tape.writeMountCount = rset.columnUint64("WRITE_MOUNT_COUNT");
tape.comment = rset.columnString("USER_COMMENT");
auto optionalComment = rset.columnOptionalString("USER_COMMENT");
tape.comment = optionalComment ? optionalComment.value() : "";
tape.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME");
tape.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME");
tape.creationLog.time = rset.columnUint64("CREATION_LOG_TIME");
......
......@@ -164,7 +164,7 @@ CREATE TABLE TAPE(
LAST_WRITE_TIME UINT64TYPE ,
READ_MOUNT_COUNT UINT64TYPE DEFAULT 0 CONSTRAINT TAPE_RMC_NN NOT NULL,
WRITE_MOUNT_COUNT UINT64TYPE DEFAULT 0 CONSTRAINT TAPE_WMC_NN NOT NULL,
USER_COMMENT VARCHAR(1000) CONSTRAINT TAPE_UC_NN NOT NULL,
USER_COMMENT VARCHAR(1000),
CREATION_LOG_USER_NAME VARCHAR(100) CONSTRAINT TAPE_CLUN_NN NOT NULL,
CREATION_LOG_HOST_NAME VARCHAR(100) CONSTRAINT TAPE_CLHN_NN NOT NULL,
CREATION_LOG_TIME UINT64TYPE CONSTRAINT TAPE_CLT_NN NOT NULL,
......
......@@ -1673,7 +1673,7 @@ void RequestMessage::processTape_Add(cta::xrd::Response &response)
auto comment = getOptional(OptionString::COMMENT);
auto tape = common::dataStructures::Tape::TapeFactory::createTape(vid,mediaType,vendor,logicallibrary,tapepool,
disabled,full,readOnly,comment ? comment.value() : "-");
disabled,full,readOnly,comment ? comment.value() : "");
m_catalogue.createTape(m_cliIdentity, tape);
......
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