Commit 6e7ae7bc authored by Cedric Caffy's avatar Cedric Caffy
Browse files

Hooked up the MEDIA_TYPE table to the TAPE table

parent d83673f8
......@@ -164,7 +164,7 @@ CREATE TABLE LOGICAL_LIBRARY(
);
CREATE TABLE TAPE(
VID VARCHAR(100) CONSTRAINT TAPE_V_NN NOT NULL,
MEDIA_TYPE VARCHAR(100) CONSTRAINT TAPE_MT_NN NOT NULL,
MEDIA_TYPE_ID BIGINT UNSIGNED CONSTRAINT TAPE_MTID_NN NOT NULL,
VENDOR VARCHAR(100) CONSTRAINT TAPE_V2_NN NOT NULL,
LOGICAL_LIBRARY_ID BIGINT UNSIGNED CONSTRAINT TAPE_LLI_NN NOT NULL,
TAPE_POOL_ID BIGINT UNSIGNED CONSTRAINT TAPE_TPI_NN NOT NULL,
......@@ -209,7 +209,8 @@ CREATE TABLE TAPE(
CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1')),
CONSTRAINT TAPE_IS_ARCHVIED_BOOL_CK CHECK(IS_ARCHIVED IN ('0', '1')),
CONSTRAINT TAPE_IS_EXPORTED_BOOL_CK CHECK(IS_EXPORTED IN ('0', '1')),
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1'))
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1')),
CONSTRAINT TAPE_MEDIA_TYPE_FK FOREIGN KEY(MEDIA_TYPE_ID) REFERENCES MEDIA_TYPE(MEDIA_TYPE_ID)
);
CREATE INDEX TAPE_TAPE_POOL_ID_IDX ON TAPE(TAPE_POOL_ID);
CREATE TABLE MOUNT_POLICY(
......
......@@ -193,7 +193,7 @@ CREATE TABLE LOGICAL_LIBRARY(
);
CREATE TABLE TAPE(
VID VARCHAR2(100) CONSTRAINT TAPE_V_NN NOT NULL,
MEDIA_TYPE VARCHAR2(100) CONSTRAINT TAPE_MT_NN NOT NULL,
MEDIA_TYPE_ID NUMERIC(20, 0) CONSTRAINT TAPE_MTID_NN NOT NULL,
VENDOR VARCHAR2(100) CONSTRAINT TAPE_V2_NN NOT NULL,
LOGICAL_LIBRARY_ID NUMERIC(20, 0) CONSTRAINT TAPE_LLI_NN NOT NULL,
TAPE_POOL_ID NUMERIC(20, 0) CONSTRAINT TAPE_TPI_NN NOT NULL,
......@@ -238,7 +238,8 @@ CREATE TABLE TAPE(
CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1')),
CONSTRAINT TAPE_IS_ARCHVIED_BOOL_CK CHECK(IS_ARCHIVED IN ('0', '1')),
CONSTRAINT TAPE_IS_EXPORTED_BOOL_CK CHECK(IS_EXPORTED IN ('0', '1')),
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1'))
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1')),
CONSTRAINT TAPE_MEDIA_TYPE_FK FOREIGN KEY(MEDIA_TYPE_ID) REFERENCES MEDIA_TYPE(MEDIA_TYPE_ID)
);
CREATE INDEX TAPE_TAPE_POOL_ID_IDX ON TAPE(TAPE_POOL_ID);
CREATE TABLE MOUNT_POLICY(
......
......@@ -176,7 +176,7 @@ CREATE TABLE LOGICAL_LIBRARY(
);
CREATE TABLE TAPE(
VID VARCHAR(100) CONSTRAINT TAPE_V_NN NOT NULL,
MEDIA_TYPE VARCHAR(100) CONSTRAINT TAPE_MT_NN NOT NULL,
MEDIA_TYPE_ID NUMERIC(20, 0) CONSTRAINT TAPE_MTID_NN NOT NULL,
VENDOR VARCHAR(100) CONSTRAINT TAPE_V2_NN NOT NULL,
LOGICAL_LIBRARY_ID NUMERIC(20, 0) CONSTRAINT TAPE_LLI_NN NOT NULL,
TAPE_POOL_ID NUMERIC(20, 0) CONSTRAINT TAPE_TPI_NN NOT NULL,
......@@ -221,7 +221,8 @@ CREATE TABLE TAPE(
CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1')),
CONSTRAINT TAPE_IS_ARCHVIED_BOOL_CK CHECK(IS_ARCHIVED IN ('0', '1')),
CONSTRAINT TAPE_IS_EXPORTED_BOOL_CK CHECK(IS_EXPORTED IN ('0', '1')),
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1'))
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1')),
CONSTRAINT TAPE_MEDIA_TYPE_FK FOREIGN KEY(MEDIA_TYPE_ID) REFERENCES MEDIA_TYPE(MEDIA_TYPE_ID)
);
CREATE INDEX TAPE_TAPE_POOL_ID_IDX ON TAPE(TAPE_POOL_ID);
CREATE TABLE MOUNT_POLICY(
......
......@@ -152,7 +152,7 @@ CREATE TABLE LOGICAL_LIBRARY(
);
CREATE TABLE TAPE(
VID VARCHAR(100) CONSTRAINT TAPE_V_NN NOT NULL,
MEDIA_TYPE VARCHAR(100) CONSTRAINT TAPE_MT_NN NOT NULL,
MEDIA_TYPE_ID INTEGER CONSTRAINT TAPE_MTID_NN NOT NULL,
VENDOR VARCHAR(100) CONSTRAINT TAPE_V2_NN NOT NULL,
LOGICAL_LIBRARY_ID INTEGER CONSTRAINT TAPE_LLI_NN NOT NULL,
TAPE_POOL_ID INTEGER CONSTRAINT TAPE_TPI_NN NOT NULL,
......@@ -197,7 +197,8 @@ CREATE TABLE TAPE(
CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1')),
CONSTRAINT TAPE_IS_ARCHVIED_BOOL_CK CHECK(IS_ARCHIVED IN ('0', '1')),
CONSTRAINT TAPE_IS_EXPORTED_BOOL_CK CHECK(IS_EXPORTED IN ('0', '1')),
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1'))
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1')),
CONSTRAINT TAPE_MEDIA_TYPE_FK FOREIGN KEY(MEDIA_TYPE_ID) REFERENCES MEDIA_TYPE(MEDIA_TYPE_ID)
);
CREATE INDEX TAPE_TAPE_POOL_ID_IDX ON TAPE(TAPE_POOL_ID);
CREATE TABLE MOUNT_POLICY(
......
......@@ -3997,7 +3997,7 @@ namespace catalogue{
");"
"CREATE TABLE TAPE("
" VID VARCHAR2(100) CONSTRAINT TAPE_V_NN NOT NULL,"
" MEDIA_TYPE VARCHAR2(100) CONSTRAINT TAPE_MT_NN NOT NULL,"
" MEDIA_TYPE_ID NUMERIC(20, 0) CONSTRAINT TAPE_MTID_NN NOT NULL,"
" VENDOR VARCHAR2(100) CONSTRAINT TAPE_V2_NN NOT NULL,"
" LOGICAL_LIBRARY_ID NUMERIC(20, 0) CONSTRAINT TAPE_LLI_NN NOT NULL,"
" TAPE_POOL_ID NUMERIC(20, 0) CONSTRAINT TAPE_TPI_NN NOT NULL,"
......@@ -4042,7 +4042,8 @@ namespace catalogue{
" CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1')),"
" CONSTRAINT TAPE_IS_ARCHVIED_BOOL_CK CHECK(IS_ARCHIVED IN ('0', '1')),"
" CONSTRAINT TAPE_IS_EXPORTED_BOOL_CK CHECK(IS_EXPORTED IN ('0', '1')),"
" CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1'))"
" CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1')),"
" CONSTRAINT TAPE_MEDIA_TYPE_FK FOREIGN KEY(MEDIA_TYPE_ID) REFERENCES MEDIA_TYPE(MEDIA_TYPE_ID)"
");"
"CREATE INDEX TAPE_TAPE_POOL_ID_IDX ON TAPE(TAPE_POOL_ID);"
"CREATE TABLE MOUNT_POLICY("
......@@ -4397,7 +4398,7 @@ namespace catalogue{
");"
"CREATE TABLE TAPE("
" VID VARCHAR(100) CONSTRAINT TAPE_V_NN NOT NULL,"
" MEDIA_TYPE VARCHAR(100) CONSTRAINT TAPE_MT_NN NOT NULL,"
" MEDIA_TYPE_ID BIGINT UNSIGNED CONSTRAINT TAPE_MTID_NN NOT NULL,"
" VENDOR VARCHAR(100) CONSTRAINT TAPE_V2_NN NOT NULL,"
" LOGICAL_LIBRARY_ID BIGINT UNSIGNED CONSTRAINT TAPE_LLI_NN NOT NULL,"
" TAPE_POOL_ID BIGINT UNSIGNED CONSTRAINT TAPE_TPI_NN NOT NULL,"
......@@ -4442,7 +4443,8 @@ namespace catalogue{
" CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1')),"
" CONSTRAINT TAPE_IS_ARCHVIED_BOOL_CK CHECK(IS_ARCHIVED IN ('0', '1')),"
" CONSTRAINT TAPE_IS_EXPORTED_BOOL_CK CHECK(IS_EXPORTED IN ('0', '1')),"
" CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1'))"
" CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1')),"
" CONSTRAINT TAPE_MEDIA_TYPE_FK FOREIGN KEY(MEDIA_TYPE_ID) REFERENCES MEDIA_TYPE(MEDIA_TYPE_ID)"
");"
"CREATE INDEX TAPE_TAPE_POOL_ID_IDX ON TAPE(TAPE_POOL_ID);"
"CREATE TABLE MOUNT_POLICY("
......@@ -4784,7 +4786,7 @@ namespace catalogue{
");"
"CREATE TABLE TAPE("
" VID VARCHAR(100) CONSTRAINT TAPE_V_NN NOT NULL,"
" MEDIA_TYPE VARCHAR(100) CONSTRAINT TAPE_MT_NN NOT NULL,"
" MEDIA_TYPE_ID INTEGER CONSTRAINT TAPE_MTID_NN NOT NULL,"
" VENDOR VARCHAR(100) CONSTRAINT TAPE_V2_NN NOT NULL,"
" LOGICAL_LIBRARY_ID INTEGER CONSTRAINT TAPE_LLI_NN NOT NULL,"
" TAPE_POOL_ID INTEGER CONSTRAINT TAPE_TPI_NN NOT NULL,"
......@@ -4829,7 +4831,8 @@ namespace catalogue{
" CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1')),"
" CONSTRAINT TAPE_IS_ARCHVIED_BOOL_CK CHECK(IS_ARCHIVED IN ('0', '1')),"
" CONSTRAINT TAPE_IS_EXPORTED_BOOL_CK CHECK(IS_EXPORTED IN ('0', '1')),"
" CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1'))"
" CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1')),"
" CONSTRAINT TAPE_MEDIA_TYPE_FK FOREIGN KEY(MEDIA_TYPE_ID) REFERENCES MEDIA_TYPE(MEDIA_TYPE_ID)"
");"
"CREATE INDEX TAPE_TAPE_POOL_ID_IDX ON TAPE(TAPE_POOL_ID);"
"CREATE TABLE MOUNT_POLICY("
......@@ -5193,7 +5196,7 @@ namespace catalogue{
");"
"CREATE TABLE TAPE("
" VID VARCHAR(100) CONSTRAINT TAPE_V_NN NOT NULL,"
" MEDIA_TYPE VARCHAR(100) CONSTRAINT TAPE_MT_NN NOT NULL,"
" MEDIA_TYPE_ID NUMERIC(20, 0) CONSTRAINT TAPE_MTID_NN NOT NULL,"
" VENDOR VARCHAR(100) CONSTRAINT TAPE_V2_NN NOT NULL,"
" LOGICAL_LIBRARY_ID NUMERIC(20, 0) CONSTRAINT TAPE_LLI_NN NOT NULL,"
" TAPE_POOL_ID NUMERIC(20, 0) CONSTRAINT TAPE_TPI_NN NOT NULL,"
......@@ -5238,7 +5241,8 @@ namespace catalogue{
" CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1')),"
" CONSTRAINT TAPE_IS_ARCHVIED_BOOL_CK CHECK(IS_ARCHIVED IN ('0', '1')),"
" CONSTRAINT TAPE_IS_EXPORTED_BOOL_CK CHECK(IS_EXPORTED IN ('0', '1')),"
" CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1'))"
" CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1')),"
" CONSTRAINT TAPE_MEDIA_TYPE_FK FOREIGN KEY(MEDIA_TYPE_ID) REFERENCES MEDIA_TYPE(MEDIA_TYPE_ID)"
");"
"CREATE INDEX TAPE_TAPE_POOL_ID_IDX ON TAPE(TAPE_POOL_ID);"
"CREATE TABLE MOUNT_POLICY("
......
This diff is collapsed.
......@@ -106,7 +106,17 @@ protected:
std::map<std::string, cta::catalogue::TapePool> tapePoolListToMap(
const std::list<cta::catalogue::TapePool> &listOfTapePools);
/**
* Creates a VO in the catalogue
* @param voName the vo to create
*/
void createVo(const std::string &voName);
/**
* Creates a media type in the catalogue
* @param mediaTypeName
*/
void createMediaType(const std::string & mediaTypeName);
}; // cta_catalogue_CatalogueTest
} // namespace unitTests
......@@ -724,9 +724,6 @@ void RdbmsCatalogue::deleteStorageClass(const std::string &storageClassName) {
// MediaTypeIsUsedByTapes
//------------------------------------------------------------------------------
bool RdbmsCatalogue::mediaTypeIsUsedByTapes(rdbms::Conn &conn, const std::string &name) const {
return false;
// TO BE DONE
/*
try {
const char *const sql =
"SELECT" "\n"
......@@ -749,7 +746,6 @@ bool RdbmsCatalogue::mediaTypeIsUsedByTapes(rdbms::Conn &conn, const std::string
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
*/
}
//------------------------------------------------------------------------------
......@@ -2952,7 +2948,7 @@ 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 &mediaTypeName,
const std::string &vendor,
const std::string &logicalLibraryName,
const std::string &tapePoolName,
......@@ -2968,7 +2964,7 @@ void RdbmsCatalogue::createTape(
throw UserSpecifiedAnEmptyStringVid("Cannot create tape because the VID is an empty string");
}
if(mediaType.empty()) {
if(mediaTypeName.empty()) {
throw UserSpecifiedAnEmptyStringMediaType("Cannot create tape because the media type is an empty string");
}
......@@ -3008,11 +3004,17 @@ void RdbmsCatalogue::createTape(
throw exception::UserError(std::string("Cannot create tape ") + vid + " because tape pool " +
tapePoolName + " does not exist");
}
const auto mediaTypeId = getMediaTypeId(conn, mediaTypeName);
if(!mediaTypeId) {
throw exception::UserError(std::string("Cannot create tape ") + vid + " because media type " +
mediaTypeName + " does not exist");
}
const time_t now = time(nullptr);
const char *const sql =
"INSERT INTO TAPE(" "\n"
"VID," "\n"
"MEDIA_TYPE," "\n"
"MEDIA_TYPE_ID," "\n"
"VENDOR," "\n"
"LOGICAL_LIBRARY_ID," "\n"
"TAPE_POOL_ID," "\n"
......@@ -3035,7 +3037,7 @@ void RdbmsCatalogue::createTape(
"LAST_UPDATE_TIME)" "\n"
"VALUES(" "\n"
":VID," "\n"
":MEDIA_TYPE," "\n"
":MEDIA_TYPE_ID," "\n"
":VENDOR," "\n"
":LOGICAL_LIBRARY_ID," "\n"
":TAPE_POOL_ID," "\n"
......@@ -3060,7 +3062,7 @@ void RdbmsCatalogue::createTape(
auto stmt = conn.createStmt(sql);
stmt.bindString(":VID", vid);
stmt.bindString(":MEDIA_TYPE", mediaType);
stmt.bindUint64(":MEDIA_TYPE_ID", mediaTypeId.value());
stmt.bindString(":VENDOR", vendor);
stmt.bindUint64(":LOGICAL_LIBRARY_ID", logicalLibraryId.value());
stmt.bindUint64(":TAPE_POOL_ID", tapePoolId.value());
......@@ -3087,7 +3089,7 @@ void RdbmsCatalogue::createTape(
log::LogContext lc(m_log);
log::ScopedParamContainer spc(lc);
spc.add("vid", vid)
.add("mediaType", mediaType)
.add("mediaType", mediaTypeName)
.add("vendor", vendor)
.add("logicalLibraryName", logicalLibraryName)
.add("tapePoolName", tapePoolName)
......@@ -3255,7 +3257,7 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
std::string sql =
"SELECT "
"TAPE.VID AS VID,"
"TAPE.MEDIA_TYPE AS MEDIA_TYPE,"
"MEDIA_TYPE.MEDIA_TYPE_NAME AS MEDIA_TYPE,"
"TAPE.VENDOR AS VENDOR,"
"LOGICAL_LIBRARY.LOGICAL_LIBRARY_NAME AS LOGICAL_LIBRARY_NAME,"
"TAPE_POOL.TAPE_POOL_NAME AS TAPE_POOL_NAME,"
......@@ -3298,6 +3300,8 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
"TAPE.TAPE_POOL_ID = TAPE_POOL.TAPE_POOL_ID "
"INNER JOIN LOGICAL_LIBRARY ON "
"TAPE.LOGICAL_LIBRARY_ID = LOGICAL_LIBRARY.LOGICAL_LIBRARY_ID "
"INNER JOIN MEDIA_TYPE ON "
"TAPE.MEDIA_TYPE_ID = MEDIA_TYPE.MEDIA_TYPE_ID "
"INNER JOIN VIRTUAL_ORGANIZATION ON "
"TAPE_POOL.VIRTUAL_ORGANIZATION_ID = VIRTUAL_ORGANIZATION.VIRTUAL_ORGANIZATION_ID";
......@@ -3323,7 +3327,7 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
}
if(searchCriteria.mediaType) {
if(addedAWhereConstraint) sql += " AND ";
sql += " TAPE.MEDIA_TYPE = :MEDIA_TYPE";
sql += " MEDIA_TYPE.MEDIA_TYPE_NAME = :MEDIA_TYPE";
addedAWhereConstraint = true;
}
if(searchCriteria.vendor) {
......@@ -3473,7 +3477,7 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getTapesByVid(const std::se
std::string sql =
"SELECT "
"TAPE.VID AS VID,"
"TAPE.MEDIA_TYPE AS MEDIA_TYPE,"
"MEDIA_TYPE.MEDIA_TYPE_NAME AS MEDIA_TYPE,"
"TAPE.VENDOR AS VENDOR,"
"LOGICAL_LIBRARY.LOGICAL_LIBRARY_NAME AS LOGICAL_LIBRARY_NAME,"
"TAPE_POOL.TAPE_POOL_NAME AS TAPE_POOL_NAME,"
......@@ -3514,6 +3518,8 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getTapesByVid(const std::se
"TAPE.TAPE_POOL_ID = TAPE_POOL.TAPE_POOL_ID "
"INNER JOIN LOGICAL_LIBRARY ON "
"TAPE.LOGICAL_LIBRARY_ID = LOGICAL_LIBRARY.LOGICAL_LIBRARY_ID "
"INNER JOIN MEDIA_TYPE ON "
"TAPE.MEDIA_TYPE_ID = MEDIA_TYPE.MEDIA_TYPE_ID "
"INNER JOIN VIRTUAL_ORGANIZATION ON "
"TAPE_POOL.VIRTUAL_ORGANIZATION_ID = VIRTUAL_ORGANIZATION.VIRTUAL_ORGANIZATION_ID";
......@@ -3603,7 +3609,7 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getAllTapes() const {
std::string sql =
"SELECT "
"TAPE.VID AS VID,"
"TAPE.MEDIA_TYPE AS MEDIA_TYPE,"
"MEDIA_TYPE.MEDIA_TYPE_NAME AS MEDIA_TYPE,"
"TAPE.VENDOR AS VENDOR,"
"LOGICAL_LIBRARY.LOGICAL_LIBRARY_NAME AS LOGICAL_LIBRARY_NAME,"
"TAPE_POOL.TAPE_POOL_NAME AS TAPE_POOL_NAME,"
......@@ -3644,6 +3650,8 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getAllTapes() const {
"TAPE.TAPE_POOL_ID = TAPE_POOL.TAPE_POOL_ID "
"INNER JOIN LOGICAL_LIBRARY ON "
"TAPE.LOGICAL_LIBRARY_ID = LOGICAL_LIBRARY.LOGICAL_LIBRARY_ID "
"INNER JOIN MEDIA_TYPE ON "
"TAPE.MEDIA_TYPE_ID = MEDIA_TYPE.MEDIA_TYPE_ID "
"INNER JOIN VIRTUAL_ORGANIZATION ON "
"TAPE_POOL.VIRTUAL_ORGANIZATION_ID = VIRTUAL_ORGANIZATION.VIRTUAL_ORGANIZATION_ID";
......@@ -3966,16 +3974,20 @@ optional<common::dataStructures::TapeLog> RdbmsCatalogue::getTapeLogFromRset(con
void RdbmsCatalogue::modifyTapeMediaType(const common::dataStructures::SecurityIdentity &admin,
const std::string &vid, const std::string &mediaType) {
try {
auto conn = m_connPool.getConn();
if(!mediaTypeExists(conn, mediaType)){
throw exception::UserError(std::string("Cannot modify tape ") + vid + " because the media type " + mediaType + " does not exist");
}
const time_t now = time(nullptr);
const char *const sql =
"UPDATE TAPE SET "
"MEDIA_TYPE = :MEDIA_TYPE,"
"MEDIA_TYPE_ID = (SELECT MEDIA_TYPE_ID FROM MEDIA_TYPE WHERE MEDIA_TYPE.MEDIA_TYPE_NAME = :MEDIA_TYPE),"
"LAST_UPDATE_USER_NAME = :LAST_UPDATE_USER_NAME,"
"LAST_UPDATE_HOST_NAME = :LAST_UPDATE_HOST_NAME,"
"LAST_UPDATE_TIME = :LAST_UPDATE_TIME "
"WHERE "
"VID = :VID";
auto conn = m_connPool.getConn();
auto stmt = conn.createStmt(sql);
stmt.bindString(":MEDIA_TYPE", mediaType);
stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username);
......@@ -4065,6 +4077,9 @@ void RdbmsCatalogue::modifyTapeLogicalLibraryName(const common::dataStructures::
"WHERE "
"VID = :VID";
auto conn = m_connPool.getConn();
if(!logicalLibraryExists(conn,logicalLibraryName)){
throw exception::UserError(std::string("Cannot modify tape ") + vid + " because the logical library " + logicalLibraryName + " does not exist");
}
auto stmt = conn.createStmt(sql);
stmt.bindString(":LOGICAL_LIBRARY_NAME", logicalLibraryName);
stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username);
......@@ -4110,6 +4125,9 @@ void RdbmsCatalogue::modifyTapeTapePoolName(const common::dataStructures::Securi
"WHERE "
"VID = :VID";
auto conn = m_connPool.getConn();
if(!tapePoolExists(conn,tapePoolName)){
throw exception::UserError(std::string("Cannot modify tape ") + vid + " because the tape pool " + tapePoolName + " does not exist");
}
auto stmt = conn.createStmt(sql);
stmt.bindString(":TAPE_POOL_NAME", tapePoolName);
stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username);
......@@ -7344,7 +7362,7 @@ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string &
const char *const sql =
"SELECT "
"TAPE.VID AS VID,"
"TAPE.MEDIA_TYPE AS MEDIA_TYPE,"
"MEDIA_TYPE.MEDIA_TYPE_NAME AS MEDIA_TYPE,"
"TAPE.VENDOR AS VENDOR,"
"LOGICAL_LIBRARY.LOGICAL_LIBRARY_NAME AS LOGICAL_LIBRARY_NAME,"
"TAPE_POOL.TAPE_POOL_NAME AS TAPE_POOL_NAME,"
......@@ -7358,6 +7376,8 @@ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string &
"TAPE.TAPE_POOL_ID = TAPE_POOL.TAPE_POOL_ID "
"INNER JOIN LOGICAL_LIBRARY ON "
"TAPE.LOGICAL_LIBRARY_ID = LOGICAL_LIBRARY.LOGICAL_LIBRARY_ID "
"INNER JOIN MEDIA_TYPE ON "
"TAPE.MEDIA_TYPE_ID = MEDIA_TYPE.MEDIA_TYPE_ID "
"INNER JOIN VIRTUAL_ORGANIZATION ON "
"TAPE_POOL.VIRTUAL_ORGANIZATION_ID = VIRTUAL_ORGANIZATION.VIRTUAL_ORGANIZATION_ID "
"WHERE "
......@@ -8175,6 +8195,33 @@ optional<uint64_t> RdbmsCatalogue::getTapePoolId(rdbms::Conn &conn, const std::s
}
}
//------------------------------------------------------------------------------
// getMediaTypeId
//------------------------------------------------------------------------------
optional<uint64_t> RdbmsCatalogue::getMediaTypeId(rdbms::Conn &conn, const std::string &name) const {
try {
const char *const sql =
"SELECT" "\n"
"MEDIA_TYPE.MEDIA_TYPE_ID AS MEDIA_TYPE_ID" "\n"
"FROM" "\n"
"MEDIA_TYPE" "\n"
"WHERE" "\n"
"MEDIA_TYPE.MEDIA_TYPE_NAME = :MEDIA_TYPE_NAME";
auto stmt = conn.createStmt(sql);
stmt.bindString(":MEDIA_TYPE_NAME", name);
auto rset = stmt.executeQuery();
if(!rset.next()) {
return nullopt;
}
return rset.columnUint64("MEDIA_TYPE_ID");
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// updateDiskFileId
//------------------------------------------------------------------------------
......
......@@ -1756,6 +1756,16 @@ protected:
* @return the ID of the specified tape pool.
*/
optional<uint64_t> getTapePoolId(rdbms::Conn &conn, const std::string &name) const;
/**
* Returns the ID of the specified media type or nullopt if it the media type
* does not exist.
*
* @param conn The database connection.
* @param name The name of the media type.
* @return the ID of the specified tape pool.
*/
optional<uint64_t> getMediaTypeId(rdbms::Conn &conn, const std::string &name) const;
/**
* Updates the disk file ID of the specified archive file.
......
......@@ -134,7 +134,7 @@ CREATE TABLE LOGICAL_LIBRARY(
);
CREATE TABLE TAPE(
VID VARCHAR(100) CONSTRAINT TAPE_V_NN NOT NULL,
MEDIA_TYPE VARCHAR(100) CONSTRAINT TAPE_MT_NN NOT NULL,
MEDIA_TYPE_ID UINT64TYPE CONSTRAINT TAPE_MTID_NN NOT NULL,
VENDOR VARCHAR(100) CONSTRAINT TAPE_V2_NN NOT NULL,
LOGICAL_LIBRARY_ID UINT64TYPE CONSTRAINT TAPE_LLI_NN NOT NULL,
TAPE_POOL_ID UINT64TYPE CONSTRAINT TAPE_TPI_NN NOT NULL,
......@@ -179,7 +179,8 @@ CREATE TABLE TAPE(
CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1')),
CONSTRAINT TAPE_IS_ARCHVIED_BOOL_CK CHECK(IS_ARCHIVED IN ('0', '1')),
CONSTRAINT TAPE_IS_EXPORTED_BOOL_CK CHECK(IS_EXPORTED IN ('0', '1')),
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1'))
CONSTRAINT TAPE_DIRTY_BOOL_CK CHECK(DIRTY IN ('0','1')),
CONSTRAINT TAPE_MEDIA_TYPE_FK FOREIGN KEY(MEDIA_TYPE_ID) REFERENCES MEDIA_TYPE(MEDIA_TYPE_ID)
);
CREATE INDEX TAPE_TAPE_POOL_ID_IDX ON TAPE(TAPE_POOL_ID);
CREATE TABLE MOUNT_POLICY(
......
......@@ -114,12 +114,19 @@ kubectl --namespace ${NAMESPACE} exec ctacli -- cta-admin --json version | jq
--vo vo \
--partialtapesnumber 5 \
--encrypted false \
--comment "ctasystest"
--comment "ctasystest"
# add the media type of the tapes
kubectl --namespace ${NAMESPACE} exec ctacli -- cta-admin mediatype add \
--name "T10K-500G" \
--capacity 500000000000 \
--primarydensitycode 74 \
--cartridge "T10000" \
--comment "T10000A"
# add all tapes
for ((i=0; i<${#TAPES[@]}; i++)); do
VID=${TAPES[${i}]}
kubectl --namespace ${NAMESPACE} exec ctacli -- cta-admin tape add \
--mediatype mediatype \
--mediatype "T10K-500G" \
--vendor vendor \
--logicallibrary ${TAPEDRIVES_IN_USE[${i}%${NB_TAPEDRIVES_IN_USE}]} \
--tapepool ctasystest \
......
......@@ -230,6 +230,13 @@ public:
const std::string archiveRouteComment = "Archive-route comment";
catalogue.createArchiveRoute(s_adminOnAdminHost, s_storageClassName, copyNb, s_tapePoolName,
archiveRouteComment);
cta::catalogue::MediaType mediaType;
mediaType.name = s_mediaType;
mediaType.capacityInBytes = 10;
mediaType.cartridge = "cartridge";
mediaType.comment = "comment";
catalogue.createMediaType(s_adminOnAdminHost,mediaType);
}
private:
......@@ -914,7 +921,7 @@ TEST_P(SchedulerTest, archive_and_retrieve_report_failure) {
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
catalogue.createTape(s_adminOnAdminHost, s_vid, "mediatype", "vendor", s_libraryName, s_tapePoolName,
catalogue.createTape(s_adminOnAdminHost, s_vid, s_mediaType, s_vendor, s_libraryName, s_tapePoolName,
capacityInBytes, notDisabled, notFull, notReadOnly, tapeComment);
const std::string driveName = "tape_drive";
......@@ -1288,7 +1295,7 @@ TEST_P(SchedulerTest, repack) {
std::string tape1 = "Tape";
const bool notReadOnly = false;
catalogue.createTape(cliId,tape1,"mediaType","vendor",s_libraryName,s_tapePoolName,500,false,false, notReadOnly, "Comment");
catalogue.createTape(cliId,tape1,s_mediaType,s_vendor,s_libraryName,s_tapePoolName,500,false,false, notReadOnly, "Comment");
//The queueing of a repack request should fail if the tape to repack is not full
ASSERT_THROW(scheduler.queueRepack(cliId, tape1, "file://"+tempDirectory.path(), common::dataStructures::RepackInfo::Type::MoveOnly, common::dataStructures::MountPolicy::s_defaultMountPolicyForRepack,s_defaultRepackDisabledTapeFlag,lc),cta::exception::UserError);
......@@ -1309,7 +1316,7 @@ TEST_P(SchedulerTest, repack) {
ASSERT_EQ(0, scheduler.getRepacks().size());
// Recreate a repack and get it moved to ToExpand
std::string tape2 = "Tape2";
catalogue.createTape(cliId,tape2,"mediaType","vendor",s_libraryName,s_tapePoolName,500,false,true, notReadOnly, "Comment");
catalogue.createTape(cliId,tape2,s_mediaType,s_vendor,s_libraryName,s_tapePoolName,500,false,true, notReadOnly, "Comment");
scheduler.queueRepack(cliId, tape2, "file://"+tempDirectory.path(), common::dataStructures::RepackInfo::Type::MoveOnly, common::dataStructures::MountPolicy::s_defaultMountPolicyForRepack,s_defaultRepackDisabledTapeFlag, lc);
{
auto repacks = scheduler.getRepacks();
......@@ -1348,13 +1355,13 @@ TEST_P(SchedulerTest, getNextRepackRequestToExpand) {
cliId.username = s_userName;
std::string tape1 = "Tape";
const bool notReadOnly = false;
catalogue.createTape(cliId,tape1,"mediaType","vendor",s_libraryName,s_tapePoolName,500,false,true, notReadOnly, "Comment");
catalogue.createTape(cliId,tape1,s_mediaType,s_vendor,s_libraryName,s_tapePoolName,500,false,true, notReadOnly, "Comment");
//Queue the first repack request
scheduler.queueRepack(cliId, tape1, "file://"+tempDirectory.path(), common::dataStructures::RepackInfo::Type::MoveOnly,common::dataStructures::MountPolicy::s_defaultMountPolicyForRepack,s_defaultRepackDisabledTapeFlag, lc);
std::string tape2 = "Tape2";
catalogue.createTape(cliId,tape2,"mediaType","vendor",s_libraryName,s_tapePoolName,500,false,true, notReadOnly, "Comment");
catalogue.createTape(cliId,tape2,s_mediaType,s_vendor,s_libraryName,s_tapePoolName,500,false,true, notReadOnly, "Comment");
//Queue the second repack request
scheduler.queueRepack(cliId,tape2,"file://"+tempDirectory.path(),common::dataStructures::RepackInfo::Type::AddCopiesOnly,common::dataStructures::MountPolicy::s_defaultMountPolicyForRepack, s_defaultRepackDisabledTapeFlag,lc);
......
......@@ -311,6 +311,13 @@ public:
const std::string archiveRouteComment = "Archive-route comment";
catalogue.createArchiveRoute(s_adminOnAdminHost, s_storageClassName, copyNb, s_tapePoolName,
archiveRouteComment);
cta::catalogue::MediaType mediaType;
mediaType.name = s_mediaType;
mediaType.capacityInBytes = 10;
mediaType.cartridge = "cartridge";
mediaType.comment = "comment";
catalogue.createMediaType(s_adminOnAdminHost,mediaType);
}
private:
......
......@@ -60,6 +60,16 @@ const uint32_t TEST_GROUP_2 = 9754;
nbArchiveFileListingConns);
m_catalogue = catalogueFactory->create();
}
void createMediaType(const std::string & name){
cta::common::dataStructures::SecurityIdentity admin = cta::common::dataStructures::SecurityIdentity("admin","localhost");
cta::catalogue::MediaType mediaType;
mediaType.name = name;
mediaType.capacityInBytes = 10;
mediaType.cartridge = "cartridge";
mediaType.comment = "comment";
m_catalogue->createMediaType(admin,mediaType);
}
void TearDown() {
m_catalogue.reset();
......@@ -135,6 +145,7 @@ const uint32_t TEST_GROUP_2 = 9754;
m_catalogue->createLogicalLibrary(admin, logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
m_catalogue->createTapePool(admin, tapePoolName, vo.name, 2, true, supply, "Create tape pool");
createMediaType(mediaType);
m_catalogue->createTape(admin, vid1, mediaType, vendor, logicalLibraryName, tapePoolName, capacityInBytes,
disabledValue, fullValue, readOnlyValue, createTapeComment);
......@@ -288,6 +299,7 @@ const uint32_t TEST_GROUP_2 = 9754;
m_catalogue->createLogicalLibrary(admin, logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
m_catalogue->createTapePool(admin, tapePoolName, vo.name, nbPartialTapes, isEncrypted, supply, "Create tape pool");
createMediaType(mediaType);
m_catalogue->createTape(admin, vid1, mediaType, vendor, logicalLibraryName, tapePoolName, capacityInBytes,
disabledValue, fullValue, readOnlyValue, createTapeComment);
......
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