diff --git a/catalogue/ArchiveFileDoesNotExist.hpp b/catalogue/ArchiveFileDoesNotExist.hpp deleted file mode 100644 index e52dc634fd0701d23e3543320cf8c7baabf6fa75..0000000000000000000000000000000000000000 --- a/catalogue/ArchiveFileDoesNotExist.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/exception/UserError.hpp" - -namespace cta { - -namespace catalogue { - -/** - * Archive file does not exist in the CTA catalogue. - */ -class ArchiveFileDoesNotExist: public exception::UserError { -public: - /** - * The unique identifier of the archive file. - */ - uint64_t archiveFileId; -}; - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index f8a53c8e53230b24dd69e0ffb680627f7f6f4bc6..9f4b3e2608048aaeed0a007840f6a8763375a909 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -18,7 +18,6 @@ #pragma once -#include "catalogue/ArchiveFileDoesNotExist.hpp" #include "catalogue/ArchiveFileItor.hpp" #include "catalogue/TapeFileSearchCriteria.hpp" #include "catalogue/TapeFileWritten.hpp" @@ -493,16 +492,16 @@ public: * prevent a disk instance deleting an archive file that belongs to another * disk instance. * + * Please note that this method is idempotent. If the file to be deleted does + * not exist in the CTA catalogue then this method returns without error. + * * @param instanceName The name of the instance from where the deletion request * originated * @param archiveFileId The unique identifier of the archive file. * @return The metadata of the deleted archive file including the metadata of * the associated and also deleted tape copies. - * @throw catalogue::ArchiveFileDoesNotExist If the specified archive file - * does not exist in the catalogue. */ - virtual common::dataStructures::ArchiveFile deleteArchiveFile(const std::string &instanceName, - const uint64_t archiveFileId) = 0; + virtual void deleteArchiveFile(const std::string &instanceName, const uint64_t archiveFileId) = 0; /** * Returns true if the specified user running the CTA command-line tool on diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index ee176a84619270d7a223ee00f5332c705d282bc4..e239c84b26dabd913315e82e9f078153e3d8f40c 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -6187,46 +6187,7 @@ TEST_P(cta_catalogue_CatalogueTest, deleteArchiveFile) { ASSERT_EQ(file2Written.copyNb, tapeFile2.copyNb); } - { - const common::dataStructures::ArchiveFile archiveFile = m_catalogue->deleteArchiveFile("disk_instance", archiveFileId); - - ASSERT_EQ(file2Written.archiveFileId, archiveFile.archiveFileID); - ASSERT_EQ(file2Written.diskFileId, archiveFile.diskFileId); - ASSERT_EQ(file2Written.size, archiveFile.fileSize); - ASSERT_EQ(file2Written.checksumType, archiveFile.checksumType); - ASSERT_EQ(file2Written.checksumValue, archiveFile.checksumValue); - ASSERT_EQ(file2Written.storageClassName, archiveFile.storageClass); - - ASSERT_EQ(file2Written.diskInstance, archiveFile.diskInstance); - ASSERT_EQ(file2Written.diskFilePath, archiveFile.diskFileInfo.path); - ASSERT_EQ(file2Written.diskFileUser, archiveFile.diskFileInfo.owner); - ASSERT_EQ(file2Written.diskFileGroup, archiveFile.diskFileInfo.group); - ASSERT_EQ(file2Written.diskFileRecoveryBlob, archiveFile.diskFileInfo.recoveryBlob); - - ASSERT_EQ(2, archiveFile.tapeFiles.size()); - - auto copyNbToTapeFile1Itor = archiveFile.tapeFiles.find(1); - ASSERT_FALSE(copyNbToTapeFile1Itor == archiveFile.tapeFiles.end()); - const common::dataStructures::TapeFile &tapeFile1 = copyNbToTapeFile1Itor->second; - ASSERT_EQ(file1Written.vid, tapeFile1.vid); - ASSERT_EQ(file1Written.fSeq, tapeFile1.fSeq); - ASSERT_EQ(file1Written.blockId, tapeFile1.blockId); - ASSERT_EQ(file1Written.compressedSize, tapeFile1.compressedSize); - ASSERT_EQ(file1Written.checksumType, tapeFile1.checksumType); - ASSERT_EQ(file1Written.checksumValue, tapeFile1.checksumValue); - ASSERT_EQ(file1Written.copyNb, tapeFile1.copyNb); - - auto copyNbToTapeFile2Itor = archiveFile.tapeFiles.find(2); - ASSERT_FALSE(copyNbToTapeFile2Itor == archiveFile.tapeFiles.end()); - const common::dataStructures::TapeFile &tapeFile2 = copyNbToTapeFile2Itor->second; - ASSERT_EQ(file2Written.vid, tapeFile2.vid); - ASSERT_EQ(file2Written.fSeq, tapeFile2.fSeq); - ASSERT_EQ(file2Written.blockId, tapeFile2.blockId); - ASSERT_EQ(file2Written.compressedSize, tapeFile2.compressedSize); - ASSERT_EQ(file2Written.checksumType, tapeFile2.checksumType); - ASSERT_EQ(file2Written.checksumValue, tapeFile2.checksumValue); - ASSERT_EQ(file2Written.copyNb, tapeFile2.copyNb); - } + m_catalogue->deleteArchiveFile("disk_instance", archiveFileId); ASSERT_FALSE(m_catalogue->getArchiveFiles().hasMore()); } @@ -6543,7 +6504,7 @@ TEST_P(cta_catalogue_CatalogueTest, deleteArchiveFile_non_existant) { using namespace cta; ASSERT_FALSE(m_catalogue->getArchiveFiles().hasMore()); - ASSERT_THROW(m_catalogue->deleteArchiveFile("disk_instance", 12345678), catalogue::ArchiveFileDoesNotExist); + m_catalogue->deleteArchiveFile("disk_instance", 12345678); } TEST_P(cta_catalogue_CatalogueTest, getTapesByVid_non_existant_tape) { diff --git a/catalogue/OracleCatalogue.cpp b/catalogue/OracleCatalogue.cpp index a252f6dd46e608db84177d9f67abf86bdec2e3a3..96bb60295604de47b7193c85fbf27f8dda440c02 100644 --- a/catalogue/OracleCatalogue.cpp +++ b/catalogue/OracleCatalogue.cpp @@ -59,8 +59,7 @@ OracleCatalogue::~OracleCatalogue() { //------------------------------------------------------------------------------ // deleteArchiveFile //------------------------------------------------------------------------------ -common::dataStructures::ArchiveFile OracleCatalogue::deleteArchiveFile( - const std::string &diskInstanceName, const uint64_t archiveFileId) { +void OracleCatalogue::deleteArchiveFile(const std::string &diskInstanceName, const uint64_t archiveFileId) { try { const char *selectSql = "SELECT " @@ -132,11 +131,10 @@ common::dataStructures::ArchiveFile OracleCatalogue::deleteArchiveFile( } if(nullptr == archiveFile.get()) { - ArchiveFileDoesNotExist e; - e.archiveFileId = archiveFileId; - e.getMessage() << "Failed to delete archive file with ID " << archiveFileId << " from the catalogue because it" - " does not exist in the catalogue"; - throw e; + std::list<cta::log::Param> params; + params.push_back(cta::log::Param("fileId", std::to_string(archiveFileId))); + m_log(log::WARNING, "Ignoring request to delete Archive File because it does not exist in the catalogue", params); + return; } if(diskInstanceName != archiveFile->diskInstance) { @@ -164,7 +162,34 @@ common::dataStructures::ArchiveFile OracleCatalogue::deleteArchiveFile( conn.commit(); - return *archiveFile; + std::list<cta::log::Param> params; + params.push_back(cta::log::Param("fileId", std::to_string(archiveFile->archiveFileID))); + params.push_back(cta::log::Param("diskInstance", archiveFile->diskInstance)); + params.push_back(cta::log::Param("diskFileId", archiveFile->diskFileId)); + params.push_back(cta::log::Param("diskFileInfo.path", archiveFile->diskFileInfo.path)); + params.push_back(cta::log::Param("diskFileInfo.owner", archiveFile->diskFileInfo.owner)); + params.push_back(cta::log::Param("diskFileInfo.group", archiveFile->diskFileInfo.group)); + params.push_back(cta::log::Param("diskFileInfo.recoveryBlob", archiveFile->diskFileInfo.recoveryBlob)); + params.push_back(cta::log::Param("fileSize", std::to_string(archiveFile->fileSize))); + params.push_back(cta::log::Param("checksumType", archiveFile->checksumType)); + params.push_back(cta::log::Param("checksumValue", archiveFile->checksumValue)); + params.push_back(cta::log::Param("creationTime", std::to_string(archiveFile->creationTime))); + params.push_back(cta::log::Param("reconciliationTime", std::to_string(archiveFile->reconciliationTime))); + params.push_back(cta::log::Param("storageClass", archiveFile->storageClass)); + for(auto it=archiveFile->tapeFiles.begin(); it!=archiveFile->tapeFiles.end(); it++) { + std::stringstream tapeCopyLogStream; + tapeCopyLogStream << "copy number: " << it->first + << " vid: " << it->second.vid + << " fSeq: " << it->second.fSeq + << " blockId: " << it->second.blockId + << " creationTime: " << it->second.creationTime + << " compressedSize: " << it->second.compressedSize + << " checksumType: " << it->second.checksumType //this shouldn't be here: repeated field + << " checksumValue: " << it->second.checksumValue //this shouldn't be here: repeated field + << " copyNb: " << it->second.copyNb; //this shouldn't be here: repeated field + params.push_back(cta::log::Param("TAPE FILE", tapeCopyLogStream.str())); + } + m_log(log::INFO, "Archive File Deleted", params); } catch(exception::UserError &) { throw; } catch(exception::Exception &ex) { diff --git a/catalogue/OracleCatalogue.hpp b/catalogue/OracleCatalogue.hpp index ea7891e1135e104eba4b027ea90cd8ecf6b057f7..df5a46d72848e3b4347df0822b19dd3a15f40a07 100644 --- a/catalogue/OracleCatalogue.hpp +++ b/catalogue/OracleCatalogue.hpp @@ -71,15 +71,16 @@ public: * prevent a disk instance deleting an archive file that belongs to another * disk instance. * - * @param instanceName The name of the instance from where the deletion request originated + * Please note that this method is idempotent. If the file to be deleted does + * not exist in the CTA catalogue then this method returns without error. + * + * @param instanceName The name of the instance from where the deletion request + * originated * @param archiveFileId The unique identifier of the archive file. * @return The metadata of the deleted archive file including the metadata of * the associated and also deleted tape copies. - * @throw ArchiveFileDoesNotExistInCatalogue If the specified archive file - * does not exist in the catalogue. */ - common::dataStructures::ArchiveFile deleteArchiveFile(const std::string &diskInstanceName, - const uint64_t archiveFileId) override; + void deleteArchiveFile(const std::string &diskInstanceName, const uint64_t archiveFileId) override; /** * Returns a unique archive ID that can be used by a new archive file within diff --git a/catalogue/SqliteCatalogue.cpp b/catalogue/SqliteCatalogue.cpp index 914b5b84e9a44239333d8d0daa2cd1b566c1ac38..27c77f6871912a2419dd25b822f8969d9ca153b9 100644 --- a/catalogue/SqliteCatalogue.cpp +++ b/catalogue/SqliteCatalogue.cpp @@ -54,19 +54,17 @@ SqliteCatalogue::~SqliteCatalogue() { //------------------------------------------------------------------------------ // deleteArchiveFile //------------------------------------------------------------------------------ -common::dataStructures::ArchiveFile SqliteCatalogue::deleteArchiveFile(const std::string &diskInstanceName, - const uint64_t archiveFileId) { +void SqliteCatalogue::deleteArchiveFile(const std::string &diskInstanceName, const uint64_t archiveFileId) { try { auto conn = m_connPool.getConn(); rdbms::AutoRollback autoRollback(conn); const auto archiveFile = getArchiveFile(conn, archiveFileId); if(nullptr == archiveFile.get()) { - ArchiveFileDoesNotExist e; - e.archiveFileId = archiveFileId; - e.getMessage() << "Failed to delete archive file with ID " << archiveFileId << " from the catalogue because it" - " does not exist in the catalogue"; - throw e; + std::list<cta::log::Param> params; + params.push_back(cta::log::Param("fileId", std::to_string(archiveFileId))); + m_log(log::WARNING, "Ignoring request to delete Archive File because it does not exist in the catalogue", params); + return; } if(diskInstanceName != archiveFile->diskInstance) { @@ -94,7 +92,34 @@ common::dataStructures::ArchiveFile SqliteCatalogue::deleteArchiveFile(const std conn.commit(); - return *archiveFile; + std::list<cta::log::Param> params; + params.push_back(cta::log::Param("fileId", std::to_string(archiveFile->archiveFileID))); + params.push_back(cta::log::Param("diskInstance", archiveFile->diskInstance)); + params.push_back(cta::log::Param("diskFileId", archiveFile->diskFileId)); + params.push_back(cta::log::Param("diskFileInfo.path", archiveFile->diskFileInfo.path)); + params.push_back(cta::log::Param("diskFileInfo.owner", archiveFile->diskFileInfo.owner)); + params.push_back(cta::log::Param("diskFileInfo.group", archiveFile->diskFileInfo.group)); + params.push_back(cta::log::Param("diskFileInfo.recoveryBlob", archiveFile->diskFileInfo.recoveryBlob)); + params.push_back(cta::log::Param("fileSize", std::to_string(archiveFile->fileSize))); + params.push_back(cta::log::Param("checksumType", archiveFile->checksumType)); + params.push_back(cta::log::Param("checksumValue", archiveFile->checksumValue)); + params.push_back(cta::log::Param("creationTime", std::to_string(archiveFile->creationTime))); + params.push_back(cta::log::Param("reconciliationTime", std::to_string(archiveFile->reconciliationTime))); + params.push_back(cta::log::Param("storageClass", archiveFile->storageClass)); + for(auto it=archiveFile->tapeFiles.begin(); it!=archiveFile->tapeFiles.end(); it++) { + std::stringstream tapeCopyLogStream; + tapeCopyLogStream << "copy number: " << it->first + << " vid: " << it->second.vid + << " fSeq: " << it->second.fSeq + << " blockId: " << it->second.blockId + << " creationTime: " << it->second.creationTime + << " compressedSize: " << it->second.compressedSize + << " checksumType: " << it->second.checksumType //this shouldn't be here: repeated field + << " checksumValue: " << it->second.checksumValue //this shouldn't be here: repeated field + << " copyNb: " << it->second.copyNb; //this shouldn't be here: repeated field + params.push_back(cta::log::Param("TAPE FILE", tapeCopyLogStream.str())); + } + m_log(log::INFO, "Archive File Deleted", params); } catch(exception::UserError &) { throw; } catch(exception::Exception &ex) { diff --git a/catalogue/SqliteCatalogue.hpp b/catalogue/SqliteCatalogue.hpp index 9a3f4f3ca673cd293b6b9b168fda8385a8311f01..f54fdf0adee6fa65b083960710ab7e39335e2296 100644 --- a/catalogue/SqliteCatalogue.hpp +++ b/catalogue/SqliteCatalogue.hpp @@ -64,15 +64,16 @@ public: * prevent a disk instance deleting an archive file that belongs to another * disk instance. * - * @param instanceName The name of the instance from where the deletion request originated + * Please note that this method is idempotent. If the file to be deleted does + * not exist in the CTA catalogue then this method returns without error. + * + * @param instanceName The name of the instance from where the deletion request + * originated * @param archiveFileId The unique identifier of the archive file. * @return The metadata of the deleted archive file including the metadata of * the associated and also deleted tape copies. - * @throw ArchiveFileDoesNotExistInCatalogue If the specified archive file - * does not exist in the catalogue. */ - common::dataStructures::ArchiveFile deleteArchiveFile(const std::string &diskInstanceName, - const uint64_t archiveFileId) override; + void deleteArchiveFile(const std::string &diskInstanceName, const uint64_t archiveFileId) override; protected: diff --git a/scheduler/Scheduler.cpp b/scheduler/Scheduler.cpp index fcc50013f23280f29282a0663bfae6d8c265f3f3..681723f1d7a26e7968a11c37611cb286c4405f63 100644 --- a/scheduler/Scheduler.cpp +++ b/scheduler/Scheduler.cpp @@ -209,30 +209,27 @@ void Scheduler::queueRetrieve( //------------------------------------------------------------------------------ // deleteArchive //------------------------------------------------------------------------------ -common::dataStructures::ArchiveFile Scheduler::deleteArchive(const std::string &instanceName, const common::dataStructures::DeleteArchiveRequest &request) { +void Scheduler::deleteArchive(const std::string &instanceName, const common::dataStructures::DeleteArchiveRequest &request) { // We have different possible scenarios here. The file can be safe in the catalogue, // fully queued, or partially queued. // First, make sure the file is not queued anymore. - try { - m_db.deleteArchiveRequest(instanceName, request.archiveFileID); - } catch (exception::Exception &dbEx) { - // The file was apparently not queued. If we fail to remove it from the - // catalogue for any reason other than it does not exist in the catalogue, - // then it is an error. - try { - return m_catalogue.deleteArchiveFile(instanceName, request.archiveFileID); - } catch(catalogue::ArchiveFileDoesNotExist &e) { - return common::dataStructures::ArchiveFile(); - } catch(...) { - throw; - } - } +// TEMPORARILY commenting out SchedulerDatabase::deleteArchiveRequest() in order +// to reduce latency. PLEASE NOTE however that this means files "in-flight" to +// tape will not be deleted and they will appear in the CTA catalogue when they +// are finally written to tape. +//try { +// m_db.deleteArchiveRequest(instanceName, request.archiveFileID); +//} catch (exception::Exception &dbEx) { +// // The file was apparently not queued. If we fail to remove it from the +// // catalogue for any reason other than it does not exist in the catalogue, +// // then it is an error. +// m_catalogue.deleteArchiveFile(instanceName, request.archiveFileID); +//} // We did delete the file from the queue. It hence might be absent from the catalogue. // Errors are not fatal here (so we filter them out). try { - return m_catalogue.deleteArchiveFile(instanceName, request.archiveFileID); + m_catalogue.deleteArchiveFile(instanceName, request.archiveFileID); } catch (exception::UserError &) {} - return common::dataStructures::ArchiveFile(); } //------------------------------------------------------------------------------ diff --git a/scheduler/Scheduler.hpp b/scheduler/Scheduler.hpp index 1892e1b6e8177659dec7973faae4d4da5d6b37c8..cb17951313d3d2d24e0bc3335e96d9c494a2f6b9 100644 --- a/scheduler/Scheduler.hpp +++ b/scheduler/Scheduler.hpp @@ -107,12 +107,11 @@ public: log::LogContext &lc); /** - * Delete an archived file or a file which is in the process of being archived. Returns the information - * about the deleted file. + * Delete an archived file or a file which is in the process of being archived. * Throws a UserError exception in case of wrong request parameters (ex. unknown file id) * Throws a (Non)RetryableError exception in case something else goes wrong with the request */ - cta::common::dataStructures::ArchiveFile deleteArchive(const std::string &instanceName, + void deleteArchive(const std::string &instanceName, const cta::common::dataStructures::DeleteArchiveRequest &request); /** diff --git a/scheduler/SchedulerTest.cpp b/scheduler/SchedulerTest.cpp index e383a067cfa005dca3d921e4a50f2d8b1b00b56b..542b61343bda424a109f2ef841809def1d25a655 100644 --- a/scheduler/SchedulerTest.cpp +++ b/scheduler/SchedulerTest.cpp @@ -284,70 +284,75 @@ TEST_P(SchedulerTest, archive_to_new_file) { } } -TEST_P(SchedulerTest, delete_archive_request) { - using namespace cta; - - Scheduler &scheduler = getScheduler(); - - setupDefaultCatalogue(); - - cta::common::dataStructures::EntryLog creationLog; - creationLog.host="host2"; - creationLog.time=0; - creationLog.username="admin1"; - cta::common::dataStructures::DiskFileInfo diskFileInfo; - diskFileInfo.recoveryBlob="blob"; - diskFileInfo.group="group2"; - diskFileInfo.owner="cms_user"; - diskFileInfo.path="path/to/file"; - cta::common::dataStructures::ArchiveRequest request; - request.checksumType="ADLER32"; - request.checksumValue="1111"; - request.creationLog=creationLog; - request.diskFileInfo=diskFileInfo; - request.diskFileID="diskFileID"; - request.fileSize=100*1000*1000; - cta::common::dataStructures::UserIdentity requester; - requester.name = s_userName; - requester.group = "userGroup"; - request.requester = requester; - request.srcURL="srcURL"; - request.storageClass=s_storageClassName; - - log::DummyLogger dl(""); - log::LogContext lc(dl); - auto archiveFileId = scheduler.queueArchive(s_diskInstance, request, lc); - - // Check that we have the file in the queues - // TODO: for this to work all the time, we need an index of all requests - // (otherwise we miss the selected ones). - // Could also be limited to querying by ID (global index needed) - bool found=false; - for (auto & tp: scheduler.getPendingArchiveJobs()) { - for (auto & req: tp.second) { - if (req.archiveFileID == archiveFileId) - found = true; - } - } - ASSERT_TRUE(found); - - // Remove the request - cta::common::dataStructures::DeleteArchiveRequest dar; - dar.archiveFileID = archiveFileId; - dar.requester.group = "group1"; - dar.requester.name = "user1"; - scheduler.deleteArchive("disk_instance", dar); - - // Validate that the request is gone. - found=false; - for (auto & tp: scheduler.getPendingArchiveJobs()) { - for (auto & req: tp.second) { - if (req.archiveFileID == archiveFileId) - found = true; - } - } - ASSERT_FALSE(found); -} +// smurray commented this test out on Mon 17 Jul 2017. The test assumes that +// Scheduler::deleteArchive() calls SchedulerDatabase::deleteArchiveRequest(). +// This fact is currently not true as Scheduler::deleteArchive() has been +// temporarily modified to only call Catalogue::deleteArchiveFile(). +// +//TEST_P(SchedulerTest, delete_archive_request) { +// using namespace cta; +// +// Scheduler &scheduler = getScheduler(); +// +// setupDefaultCatalogue(); +// +// cta::common::dataStructures::EntryLog creationLog; +// creationLog.host="host2"; +// creationLog.time=0; +// creationLog.username="admin1"; +// cta::common::dataStructures::DiskFileInfo diskFileInfo; +// diskFileInfo.recoveryBlob="blob"; +// diskFileInfo.group="group2"; +// diskFileInfo.owner="cms_user"; +// diskFileInfo.path="path/to/file"; +// cta::common::dataStructures::ArchiveRequest request; +// request.checksumType="ADLER32"; +// request.checksumValue="1111"; +// request.creationLog=creationLog; +// request.diskFileInfo=diskFileInfo; +// request.diskFileID="diskFileID"; +// request.fileSize=100*1000*1000; +// cta::common::dataStructures::UserIdentity requester; +// requester.name = s_userName; +// requester.group = "userGroup"; +// request.requester = requester; +// request.srcURL="srcURL"; +// request.storageClass=s_storageClassName; +// +// log::DummyLogger dl(""); +// log::LogContext lc(dl); +// auto archiveFileId = scheduler.queueArchive(s_diskInstance, request, lc); +// +// // Check that we have the file in the queues +// // TODO: for this to work all the time, we need an index of all requests +// // (otherwise we miss the selected ones). +// // Could also be limited to querying by ID (global index needed) +// bool found=false; +// for (auto & tp: scheduler.getPendingArchiveJobs()) { +// for (auto & req: tp.second) { +// if (req.archiveFileID == archiveFileId) +// found = true; +// } +// } +// ASSERT_TRUE(found); +// +// // Remove the request +// cta::common::dataStructures::DeleteArchiveRequest dar; +// dar.archiveFileID = archiveFileId; +// dar.requester.group = "group1"; +// dar.requester.name = "user1"; +// scheduler.deleteArchive("disk_instance", dar); +// +// // Validate that the request is gone. +// found=false; +// for (auto & tp: scheduler.getPendingArchiveJobs()) { +// for (auto & req: tp.second) { +// if (req.archiveFileID == archiveFileId) +// found = true; +// } +// } +// ASSERT_FALSE(found); +//} TEST_P(SchedulerTest, archive_and_retrieve_new_file) { using namespace cta; diff --git a/xroot_plugins/XrdCtaFile.cpp b/xroot_plugins/XrdCtaFile.cpp index 561ef97440df14f662f688301d4cc60c65386cb4..71ec1f9664e4c8bf8c730ddc92fb1bc6fb41d783 100644 --- a/xroot_plugins/XrdCtaFile.cpp +++ b/xroot_plugins/XrdCtaFile.cpp @@ -2171,64 +2171,6 @@ std::string XrdCtaFile::xCom_retrieve() { //------------------------------------------------------------------------------ // xCom_deletearchive //------------------------------------------------------------------------------ -// IMPLEMENTATION THAT CALLS THE SCHEDULER -// This version is commented out because it tries to delete the archive ID from -// the object store which can possible take more than 15 seconds. -//std::string XrdCtaFile::xCom_deletearchive() { -// std::stringstream cmdlineOutput; -// std::stringstream help; -// help << m_requestTokens.at(0) << " da/deletearchive --user <user> --group <group> --id <CTA_ArchiveFileID>" << std::endl -// << "\tNote: apply the postfix \":base64\" to long option names whose values are base64 encoded" << std::endl; -// optional<std::string> user = getOptionStringValue("", "--user", true, false); -// optional<std::string> group = getOptionStringValue("", "--group", true, false); -// optional<uint64_t> id = getOptionUint64Value("", "--id", true, false); -// checkOptions(help.str()); -// cta::common::dataStructures::UserIdentity originator; -// originator.name=user.value(); -// originator.group=group.value(); -// cta::common::dataStructures::DeleteArchiveRequest request; -// request.archiveFileID=id.value(); -// request.requester=originator; -// const cta::common::dataStructures::ArchiveFile archiveFile = m_scheduler->deleteArchive(m_cliIdentity.username, request); -// std::list<cta::log::Param> params; -// params.push_back(cta::log::Param("USERNAME", m_cliIdentity.username)); -// params.push_back(cta::log::Param("HOST", m_cliIdentity.host)); -// params.push_back(cta::log::Param("fileId", std::to_string(archiveFile.archiveFileID))); -// params.push_back(cta::log::Param("diskInstance", archiveFile.diskInstance)); -// params.push_back(cta::log::Param("diskFileId", archiveFile.diskFileId)); -// params.push_back(cta::log::Param("diskFileInfo.path", archiveFile.diskFileInfo.path)); -// params.push_back(cta::log::Param("diskFileInfo.owner", archiveFile.diskFileInfo.owner)); -// params.push_back(cta::log::Param("diskFileInfo.group", archiveFile.diskFileInfo.group)); -// params.push_back(cta::log::Param("diskFileInfo.recoveryBlob", archiveFile.diskFileInfo.recoveryBlob)); -// params.push_back(cta::log::Param("fileSize", std::to_string(archiveFile.fileSize))); -// params.push_back(cta::log::Param("checksumType", archiveFile.checksumType)); -// params.push_back(cta::log::Param("checksumValue", archiveFile.checksumValue)); -// params.push_back(cta::log::Param("creationTime", std::to_string(archiveFile.creationTime))); -// params.push_back(cta::log::Param("reconciliationTime", std::to_string(archiveFile.reconciliationTime))); -// params.push_back(cta::log::Param("storageClass", archiveFile.storageClass)); -// for(auto it=archiveFile.tapeFiles.begin(); it!=archiveFile.tapeFiles.end(); it++) { -// std::stringstream tapeCopyLogStream; -// tapeCopyLogStream << "copy number: " << it->first -// << " vid: " << it->second.vid -// << " fSeq: " << it->second.fSeq -// << " blockId: " << it->second.blockId -// << " creationTime: " << it->second.creationTime -// << " compressedSize: " << it->second.compressedSize -// << " checksumType: " << it->second.checksumType //this shouldn't be here: repeated field -// << " checksumValue: " << it->second.checksumValue //this shouldn't be here: repeated field -// << " copyNb: " << it->second.copyNb; //this shouldn't be here: repeated field -// params.push_back(cta::log::Param("TAPE FILE", tapeCopyLogStream.str())); -// } -// m_log(log::INFO, "Archive File Deleted", params); -// return cmdlineOutput.str(); -//} - -//------------------------------------------------------------------------------ -// xCom_deletearchive -//------------------------------------------------------------------------------ -// THIS IS A TEMPORARY SOLUTION -// TODO - Decide whther or not xCom_deletearchive() needs to call the scheduler -// and then update this code accordingly. std::string XrdCtaFile::xCom_deletearchive() { std::stringstream help; help << m_requestTokens.at(0) << " da/deletearchive --user <user> --group <group> --id <CTA_ArchiveFileID>" << std::endl @@ -2243,50 +2185,8 @@ std::string XrdCtaFile::xCom_deletearchive() { cta::common::dataStructures::DeleteArchiveRequest request; request.archiveFileID=id.value(); request.requester=originator; - - try { - const std::string &instanceName = m_cliIdentity.username; - const cta::common::dataStructures::ArchiveFile archiveFile = - m_catalogue->deleteArchiveFile(instanceName, request.archiveFileID); - std::list<cta::log::Param> params; - params.push_back(cta::log::Param("USERNAME", m_cliIdentity.username)); - params.push_back(cta::log::Param("HOST", m_cliIdentity.host)); - params.push_back(cta::log::Param("fileId", std::to_string(archiveFile.archiveFileID))); - params.push_back(cta::log::Param("diskInstance", archiveFile.diskInstance)); - params.push_back(cta::log::Param("diskFileId", archiveFile.diskFileId)); - params.push_back(cta::log::Param("diskFileInfo.path", archiveFile.diskFileInfo.path)); - params.push_back(cta::log::Param("diskFileInfo.owner", archiveFile.diskFileInfo.owner)); - params.push_back(cta::log::Param("diskFileInfo.group", archiveFile.diskFileInfo.group)); - params.push_back(cta::log::Param("diskFileInfo.recoveryBlob", archiveFile.diskFileInfo.recoveryBlob)); - params.push_back(cta::log::Param("fileSize", std::to_string(archiveFile.fileSize))); - params.push_back(cta::log::Param("checksumType", archiveFile.checksumType)); - params.push_back(cta::log::Param("checksumValue", archiveFile.checksumValue)); - params.push_back(cta::log::Param("creationTime", std::to_string(archiveFile.creationTime))); - params.push_back(cta::log::Param("reconciliationTime", std::to_string(archiveFile.reconciliationTime))); - params.push_back(cta::log::Param("storageClass", archiveFile.storageClass)); - for(auto it=archiveFile.tapeFiles.begin(); it!=archiveFile.tapeFiles.end(); it++) { - std::stringstream tapeCopyLogStream; - tapeCopyLogStream << "copy number: " << it->first - << " vid: " << it->second.vid - << " fSeq: " << it->second.fSeq - << " blockId: " << it->second.blockId - << " creationTime: " << it->second.creationTime - << " compressedSize: " << it->second.compressedSize - << " checksumType: " << it->second.checksumType //this shouldn't be here: repeated field - << " checksumValue: " << it->second.checksumValue //this shouldn't be here: repeated field - << " copyNb: " << it->second.copyNb; //this shouldn't be here: repeated field - params.push_back(cta::log::Param("TAPE FILE", tapeCopyLogStream.str())); - } - m_log(log::INFO, "Archive File Deleted", params); - return ""; - } catch(catalogue::ArchiveFileDoesNotExist &) { - std::list<cta::log::Param> params; - params.push_back(cta::log::Param("USERNAME", m_cliIdentity.username)); - params.push_back(cta::log::Param("HOST", m_cliIdentity.host)); - params.push_back(cta::log::Param("fileId", std::to_string(request.archiveFileID))); - m_log(log::WARNING, "Ignoring request to delete Archive File because it does not exist in the catalogue", params); - return ""; - } + m_scheduler->deleteArchive(m_cliIdentity.username, request); + return ""; } //------------------------------------------------------------------------------