diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index dea47dc6b696d8ba0baeab538112f1f0c2a91e13..14b7091e215731b242eafb9e2130cd9ab5445783 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -91,6 +91,7 @@ CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedANonEmptyLogicalLibrary); CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedANonEmptyTape); CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedANonExistentLogicalLibrary); CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedANonExistentTape); +CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedANonExistentTapePool); CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedAnEmptyStringComment); CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedAnEmptyStringDiskSystemName); CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedAnEmptyStringFileRegexp); @@ -580,6 +581,8 @@ public: * * @param searchCriteria The search criteria. * @return The list of tapes. + * @throw UserSpecifiedANonExistentTapePool if the user specified a + * non-existent tape pool. */ virtual std::list<common::dataStructures::Tape> getTapes( const TapeSearchCriteria &searchCriteria = TapeSearchCriteria()) const = 0; diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index 96056b61be64850d6a7beea3f0980e4f71d4cee8..4987884735597ab9fcd7d91f843881d9767e4410 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -1136,6 +1136,28 @@ TEST_P(cta_catalogue_CatalogueTest, deleteMediaType_usedByTapes) { ASSERT_THROW(m_catalogue->deleteMediaType(m_tape1.mediaType), exception::UserError); } +TEST_P(cta_catalogue_CatalogueTest, getTapes_non_existent_tape_pool) { + using namespace cta; + + log::LogContext dummyLc(m_dummyLog); + 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"); + m_catalogue->createTape(m_admin, m_tape1); + + { + cta::catalogue::TapeSearchCriteria criteria; + criteria.tapePool = "non_existent"; + ASSERT_THROW(m_catalogue->getTapes(criteria), catalogue::UserSpecifiedANonExistentTapePool); + } +} + TEST_P(cta_catalogue_CatalogueTest, createTape_deleteStorageClass) { // TO BE DONE } diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 8897028818bd0183c6d46fc8327837a58bbb6014..903451754f91ed09632bea5b245933527f2695c4 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -3667,6 +3667,12 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co if(isSetAndEmpty(searchCriteria.diskFileIds)) throw exception::UserError("Disk file ID list cannot be empty"); try { + if(searchCriteria.tapePool && !tapePoolExists(conn, searchCriteria.tapePool.value())) { + UserSpecifiedANonExistentTapePool ex; + ex.getMessage() << "Cannot list tapes because tape pool " + searchCriteria.tapePool.value() + " does not exist"; + throw ex; + } + std::list<common::dataStructures::Tape> tapes; std::string sql = "SELECT "