Commit 3e9c3fa0 authored by Steven Murray's avatar Steven Murray
Browse files

Catalogue::createTape() now uses the CreateTapeAttributes struct.

parent 3f54c34c
......@@ -19,6 +19,7 @@
#pragma once
#include "catalogue/ArchiveFileItor.hpp"
#include "catalogue/CreateTapeAttributes.hpp"
#include "catalogue/MediaType.hpp"
#include "catalogue/MediaTypeWithLogs.hpp"
#include "catalogue/TapeFileSearchCriteria.hpp"
......@@ -500,12 +501,14 @@ public:
virtual void setLogicalLibraryDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const bool disabledValue) = 0;
/**
* Creates a tape which is assumed to have logical block protection (LBP)
* enabled and isFromCastor disabled.
* Creates a tape which is assumed to have isFromCastor disabled.
*
* @param admin The administrator.
* @param tape The attributes of the tape to be created.
*/
virtual void createTape(
const common::dataStructures::SecurityIdentity &admin,
const common::dataStructures::Tape & tape) = 0;
const CreateTapeAttributes &tape) = 0;
virtual void deleteTape(const std::string &vid) = 0;
......
......@@ -296,7 +296,7 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->setLogicalLibraryDisabled(admin, name, disabledValue);}, m_maxTriesToConnect);
}
void createTape(const common::dataStructures::SecurityIdentity &admin, const common::dataStructures::Tape & tape) override {
void createTape( const common::dataStructures::SecurityIdentity &admin, const CreateTapeAttributes & tape) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->createTape(admin, tape);}, m_maxTriesToConnect);
}
......
This diff is collapsed.
......@@ -20,6 +20,7 @@
#include "catalogue/ArchiveFileRow.hpp"
#include "catalogue/CatalogueFactory.hpp"
#include "catalogue/CreateTapeAttributes.hpp"
#include "common/exception/Exception.hpp"
#include "common/log/DummyLogger.hpp"
......@@ -41,9 +42,9 @@ protected:
std::unique_ptr<cta::catalogue::Catalogue> m_catalogue;
cta::common::dataStructures::SecurityIdentity m_localAdmin;
cta::common::dataStructures::SecurityIdentity m_admin;
const cta::common::dataStructures::Tape m_tape1;
const cta::common::dataStructures::Tape m_tape2;
const cta::catalogue::MediaType m_mediaType;
const cta::catalogue::CreateTapeAttributes m_tape1;
const cta::catalogue::CreateTapeAttributes m_tape2;
virtual void SetUp();
......@@ -114,12 +115,6 @@ protected:
* @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, const uint64_t capacityInBytes = (uint64_t)10 * 1000 * 1000 * 1000 * 1000);
}; // cta_catalogue_CatalogueTest
} // namespace unitTests
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common/optional.hpp"
#include <string>
namespace cta {
namespace catalogue {
/**
* The tape attributes required to create a new tape entry in the CTA catalogue.
*/
struct CreateTapeAttributes {
/**
* The volume identifier of the tape.
*/
std::string vid;
/**
* The media type of the tape.
*/
std::string mediaType;
/**
* The vendor of the tape.
*/
std::string vendor;
/**
* The logical library in which the tape is located.
*/
std::string logicalLibraryName;
/**
* The tape pool to which the tape belongs.
*/
std::string tapePoolName;
/**
* True if the tape is full.
*/
bool full;
/**
* True if the tape is disabled.
*/
bool disabled;
/**
* True if the tape is read-only.
*/
bool readOnly;
/**
* Optional comment about the tape.
*/
optional<std::string> comment;
/**
* Constructor.
*
* Sets the value of all boolean member-variables to false.
*/
CreateTapeAttributes():
full(false),
disabled(false),
readOnly(false) {
}
}; // struct CreateTapeAttributes
} // namespace catalogue
} // namespace cta
......@@ -42,7 +42,7 @@ public:
void createRequesterGroupMountRule(const common::dataStructures::SecurityIdentity& admin, const std::string& mountPolicyName, const std::string& diskInstanceName, const std::string& requesterGroupName, const std::string& comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
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 common::dataStructures::Tape & tape) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void createTape(const common::dataStructures::SecurityIdentity &admin, const CreateTapeAttributes & 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"); }
......
......@@ -2921,7 +2921,7 @@ void RdbmsCatalogue::setLogicalLibraryDisabled(const common::dataStructures::Sec
//------------------------------------------------------------------------------
void RdbmsCatalogue::createTape(
const common::dataStructures::SecurityIdentity &admin,
const common::dataStructures::Tape & tape) {
const CreateTapeAttributes &tape) {
// CTA hard code this field to FALSE
const bool isFromCastor = false;
try {
......@@ -2930,10 +2930,11 @@ void RdbmsCatalogue::createTape(
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;
// Translate an empty comment string to a NULL database value
const optional<std::string> tapeComment = tape.comment && tape.comment->empty() ? nullopt : tape.comment;
if(vid.empty()) {
throw UserSpecifiedAnEmptyStringVid("Cannot create tape because the VID is an empty string");
......@@ -2955,7 +2956,7 @@ void RdbmsCatalogue::createTape(
if(tapePoolName.empty()) {
throw UserSpecifiedAnEmptyStringTapePoolName("Cannot create tape because the tape pool name is an empty string");
}
auto conn = m_connPool.getConn();
if(tapeExists(conn, vid)) {
throw exception::UserError(std::string("Cannot create tape ") + vid +
......@@ -3038,9 +3039,7 @@ void RdbmsCatalogue::createTape(
stmt.bindBool(":IS_READ_ONLY", readOnly);
stmt.bindBool(":IS_FROM_CASTOR", isFromCastor);
cta::optional<std::string> optionalComment;
if(!comment.empty()) optionalComment = comment;
stmt.bindString(":USER_COMMENT", optionalComment);
stmt.bindString(":USER_COMMENT", tapeComment);
stmt.bindString(":CREATION_LOG_USER_NAME", admin.username);
stmt.bindString(":CREATION_LOG_HOST_NAME", admin.host);
......@@ -3063,7 +3062,7 @@ void RdbmsCatalogue::createTape(
.add("isFull", full ? 1 : 0)
.add("isReadOnly", readOnly ? 1 : 0)
.add("isFromCastor", isFromCastor ? 1 : 0)
.add("userComment", comment)
.add("userComment", tape.comment ? tape.comment.value() : "")
.add("creationLogUserName", admin.username)
.add("creationLogHostName", admin.host)
.add("creationLogTime", now);
......
......@@ -451,12 +451,14 @@ public:
virtual void setLogicalLibraryDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const bool disabledValue) override;
/**
* Creates a tape which is assumed to have logical block protection (LBP)
* enabled and isFromCastor disabled.
* Creates a tape which is assumed to have isFromCastor disabled.
*
* @param admin The administrator.
* @param tape The attributes of the tape to be created.
*/
void createTape(
const common::dataStructures::SecurityIdentity &admin,
const common::dataStructures::Tape & tape) override;
const CreateTapeAttributes & tape) override;
void deleteTape(const std::string &vid) override;
......
......@@ -90,21 +90,6 @@ std::ostream &operator<<(std::ostream &os, const Tape &obj) {
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
......@@ -76,13 +76,6 @@ struct Tape {
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
std::ostream &operator<<(std::ostream &os, const Tape &obj);
......
This diff is collapsed.
......@@ -399,20 +399,18 @@ TEST_P(DataTransferSessionTest, DataTransferSessionGooddayRecall) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::common::dataStructures::Tape tape;
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.capacityInBytes = capacityInBytes;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
......@@ -596,20 +594,18 @@ TEST_P(DataTransferSessionTest, DataTransferSessionWrongRecall) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::common::dataStructures::Tape tape;
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.capacityInBytes = capacityInBytes;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
......@@ -803,20 +799,18 @@ TEST_P(DataTransferSessionTest, DataTransferSessionRAORecall) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::common::dataStructures::Tape tape;
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.capacityInBytes = capacityInBytes;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
......@@ -1034,20 +1028,18 @@ TEST_P(DataTransferSessionTest, DataTransferSessionNoSuchDrive) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::common::dataStructures::Tape tape;
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.capacityInBytes = capacityInBytes;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
......@@ -1197,20 +1189,18 @@ TEST_P(DataTransferSessionTest, DataTransferSessionFailtoMount) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::common::dataStructures::Tape tape;
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.capacityInBytes = capacityInBytes;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
......@@ -1370,20 +1360,18 @@ TEST_P(DataTransferSessionTest, DataTransferSessionGooddayMigration) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::common::dataStructures::Tape tape;
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.capacityInBytes = capacityInBytes;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
......@@ -1531,20 +1519,18 @@ TEST_P(DataTransferSessionTest, DataTransferSessionMissingFilesMigration) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::common::dataStructures::Tape tape;
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.capacityInBytes = capacityInBytes;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
......@@ -1706,20 +1692,18 @@ TEST_P(DataTransferSessionTest, DataTransferSessionTapeFullMigration) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::common::dataStructures::Tape tape;
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.capacityInBytes = capacityInBytes;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
......@@ -1881,20 +1865,18 @@ TEST_P(DataTransferSessionTest, DataTransferSessionTapeFullOnFlushMigration) {
ASSERT_EQ(s_libraryName, libraries.front().name);
ASSERT_EQ(libraryComment, libraries.front().comment);
}
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
bool notDisabled = false;
bool notFull = false;
bool notReadOnly = false;
{
cta::common::dataStructures::Tape tape;
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.capacityInBytes = capacityInBytes;
tape.full = notFull;
tape.disabled = notDisabled;
tape.readOnly = notReadOnly;
......
......@@ -131,7 +131,6 @@ const uint32_t TEST_GROUP_2 = 9754;
const bool logicalLibraryIsDisabled = false;
const std::string tapePoolName = "tape_pool_name";
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 = false;
......@@ -148,13 +147,12 @@ const uint32_t TEST_GROUP_2 = 9754;
createMediaType(mediaType);
{
cta::common::dataStructures::Tape tape;
cta::catalogue::CreateTapeAttributes tape;
tape.vid = vid1;
tape.mediaType = mediaType;
tape.vendor = vendor;
tape.logicalLibraryName = logicalLibraryName;
tape.tapePoolName = tapePoolName;
tape.capacityInBytes = capacityInBytes;
tape.full = fullValue;
tape.disabled = disabledValue;
tape.readOnly = readOnlyValue;
......@@ -297,7 +295,6 @@ const uint32_t TEST_GROUP_2 = 9754;
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 = false;
......@@ -315,13 +312,12 @@ const uint32_t TEST_GROUP_2 = 9754;
createMediaType(mediaType);
{
cta::common::dataStructures::Tape tape;
cta::catalogue::CreateTapeAttributes tape;
tape.vid = vid1;
tape.mediaType = mediaType;
tape.vendor = vendor;
tape.logicalLibraryName = logicalLibraryName;
tape.tapePoolName = tapePoolName;
tape.capacityInBytes = capacityInBytes;
tape.full = fullValue;
tape.disabled = disabledValue;
tape.readOnly = readOnlyValue;
......
......@@ -1693,10 +1693,17 @@ void RequestMessage::processTape_Add(cta::xrd::Response &response)
auto &full = getRequired(OptionBoolean::FULL);
auto &readOnly = getRequired(OptionBoolean::READ_ONLY);
auto comment = getOptional(OptionString::COMMENT);
auto tape = common::dataStructures::Tape::TapeFactory::createTape(vid,mediaType,vendor,logicallibrary,tapepool,
disabled,full,readOnly,comment ? comment.value() : "");
cta::catalogue::CreateTapeAttributes tape;
tape.vid = vid;
tape.mediaType = mediaType;
tape.vendor = vendor;
tape.logicalLibraryName = logicallibrary;
tape.tapePoolName = tapepool;
tape.full = full;
tape.disabled = disabled;
tape.readOnly = readOnly;
tape.comment = 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