diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 81034c7eb6a336eaf95e26f5824e50e1ecb0176e..4335f77d3b82b488a1832771b0c46911094db75b 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,3 +1,8 @@ +# v4.NEXT +## Summary +### Features +- cta/CTA#201 - Improve error message when oracle configured without oracle support + # v4.7.13-1 ## Summary ### Features diff --git a/catalogue/CatalogueFactoryFactory.cpp b/catalogue/CatalogueFactoryFactory.cpp index d13e8a4a0132c0e01a14e5805bb1362bc092ea01..93121c2fa3dbf9fc81c553af8cfff287837fb0c8 100644 --- a/catalogue/CatalogueFactoryFactory.cpp +++ b/catalogue/CatalogueFactoryFactory.cpp @@ -21,6 +21,7 @@ #include "catalogue/InMemoryCatalogueFactory.hpp" #include "catalogue/PostgresqlCatalogueFactory.hpp" #include "common/exception/Exception.hpp" +#include "common/exception/NoSupportedDB.hpp" #include "common/log/Logger.hpp" #ifdef SUPPORT_OCCI @@ -44,10 +45,12 @@ std::unique_ptr<CatalogueFactory> CatalogueFactoryFactory::create( switch (login.dbType) { case rdbms::Login::DBTYPE_IN_MEMORY: return std::make_unique<InMemoryCatalogueFactory>(log, nbConns, nbArchiveFileListingConns, maxTriesToConnect); -#ifdef SUPPORT_OCCI case rdbms::Login::DBTYPE_ORACLE: +#ifdef SUPPORT_OCCI return std::make_unique<OracleCatalogueFactory>(log, login, nbConns, nbArchiveFileListingConns, maxTriesToConnect); +#else + throw exception::NoSupportedDB("Oracle Catalogue Schema is not supported. Compile CTA with Oracle support."); #endif case rdbms::Login::DBTYPE_POSTGRESQL: return std::make_unique<PostgresqlCatalogueFactory>(log, login, nbConns, nbArchiveFileListingConns, maxTriesToConnect); @@ -57,7 +60,7 @@ std::unique_ptr<CatalogueFactory> CatalogueFactoryFactory::create( throw exception::Exception("Cannot create a catalogue without a database type"); default: { - exception::Exception ex; + exception::NoSupportedDB ex; ex.getMessage() << "Unknown database type: value=" << login.dbType; throw ex; } diff --git a/catalogue/CreateSchemaCmd.cpp b/catalogue/CreateSchemaCmd.cpp index 65c0dbd497b4324f29774ff0822b820fa828af4e..27e3a3d00b59d028e5060bcf8335ab54956d08fb 100644 --- a/catalogue/CreateSchemaCmd.cpp +++ b/catalogue/CreateSchemaCmd.cpp @@ -24,6 +24,7 @@ #include "catalogue/SqliteCatalogueSchema.hpp" #include "catalogue/VersionedCatalogueSchemas.hpp" #include "common/exception/Exception.hpp" +#include "common/exception/NoSupportedDB.hpp" #include "common/utils/utils.hpp" #include "rdbms/ConnPool.hpp" #include "rdbms/Login.hpp" @@ -86,8 +87,8 @@ int CreateSchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar } } break; -#ifdef SUPPORT_OCCI case rdbms::Login::DBTYPE_ORACLE: +#ifdef SUPPORT_OCCI { if (cmdLineArgs.catalogueVersion) { OracleVersionedCatalogueSchema schema(cmdLineArgs.catalogueVersion.value()); @@ -98,12 +99,14 @@ int CreateSchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar } } break; +#else + throw exception::NoSupportedDB("Oracle Catalogue Schema is not supported. Compile CTA with Oracle support."); #endif case rdbms::Login::DBTYPE_NONE: throw exception::Exception("Cannot create a catalogue without a database type"); default: { - exception::Exception ex; + exception::NoSupportedDB ex; ex.getMessage() << "Unknown database type: value=" << login.dbType; throw ex; } diff --git a/catalogue/SchemaSqlStatementsReader.cpp b/catalogue/SchemaSqlStatementsReader.cpp index 91e79130bdd190655fbdfab56b101d8b08434a0b..06949eb13aad2ee800d3f279be1dddba0a4c5e4b 100644 --- a/catalogue/SchemaSqlStatementsReader.cpp +++ b/catalogue/SchemaSqlStatementsReader.cpp @@ -28,6 +28,7 @@ #include "OracleCatalogueSchema.hpp" #endif #include "common/exception/Exception.hpp" +#include "common/exception/NoSupportedDB.hpp" #include "common/utils/utils.hpp" #include "AllCatalogueSchema.hpp" @@ -64,7 +65,7 @@ std::list<std::string> SchemaSqlStatementsReader::getStatements() { #ifdef SUPPORT_OCCI schema.reset(new OracleCatalogueSchema); #else - throw exception::Exception("Oracle Catalogue Schema is not supported. Compile CTA with Oracle support."); + throw exception::NoSupportedDB("Oracle Catalogue Schema is not supported. Compile CTA with Oracle support."); #endif break; case rdbms::Login::DBTYPE_NONE: diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 0674e9d47090d65ea22ba755d210e78fd5386c2c..f2a2fe1eecf8c1607c8eca6d190bc7e549680d48 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -105,6 +105,7 @@ set (COMMON_LIB_SRC_FILES exception/NoEntry.cpp exception/NonRetryableError.cpp exception/NoPortInRange.cpp + exception/NoSupportedDB.cpp exception/NotAnOwner.cpp exception/OutOfMemory.cpp exception/QueryVolumeFailed.cpp diff --git a/common/exception/Exception.hpp b/common/exception/Exception.hpp index 5cdf07184d882b20cf5176d5ac82ac746719d7f5..d7f2e56b0f1b438239daeba8e5756ac37a25cf65 100644 --- a/common/exception/Exception.hpp +++ b/common/exception/Exception.hpp @@ -17,10 +17,11 @@ #pragma once -#include "Backtrace.hpp" - #include <exception> #include <sstream> +#include <string> + +#include "Backtrace.hpp" namespace cta { namespace exception { /** @@ -29,7 +30,6 @@ namespace cta { namespace exception { */ class Exception : public std::exception { public: - /** * Constructor. * @@ -55,7 +55,6 @@ public: * inheritance) */ virtual ~Exception(); - /** * Get the value of m_message * A message explaining why this exception was raised @@ -64,13 +63,13 @@ public: std::ostringstream& getMessage() { return m_message; } - + /** * Get the value of m_message * A message explaining why this exception was raised * @return the value of m_message */ - + const std::ostringstream& getMessage() const { return m_message; } @@ -78,7 +77,7 @@ public: * Get the value of m_message as a sting, for const-c orrectness * @return the value as a string. */ - + std::string getMessageValue() const { return m_message.str(); } diff --git a/common/exception/NoSupportedDB.cpp b/common/exception/NoSupportedDB.cpp new file mode 100644 index 0000000000000000000000000000000000000000..03621a99eeddb5d70c84d8558f5542293e9fff09 --- /dev/null +++ b/common/exception/NoSupportedDB.cpp @@ -0,0 +1,31 @@ +/* + * @project The CERN Tape Archive (CTA) + * @copyright Copyright © 2022 CERN + * @license This program is free software, distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can + * redistribute it and/or modify it under the terms of the GPL Version 3, 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. + * + * In applying this licence, CERN does not waive the privileges and immunities + * granted to it by virtue of its status as an Intergovernmental Organization or + * submit itself to any jurisdiction. + */ + +#include "common/exception/NoSupportedDB.hpp" + +namespace cta { +namespace exception { + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +NoSupportedDB::NoSupportedDB(const std::string &what): + Exception(what) { +} + +} // namespace exception +} // namespace cta diff --git a/common/exception/NoSupportedDB.hpp b/common/exception/NoSupportedDB.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0e483d8361498a1ca52e374b46be42a56edc0d02 --- /dev/null +++ b/common/exception/NoSupportedDB.hpp @@ -0,0 +1,40 @@ +/* + * @project The CERN Tape Archive (CTA) + * @copyright Copyright © 2022 CERN + * @license This program is free software, distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can + * redistribute it and/or modify it under the terms of the GPL Version 3, 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. + * + * In applying this licence, CERN does not waive the privileges and immunities + * granted to it by virtue of its status as an Intergovernmental Organization or + * submit itself to any jurisdiction. + */ + +#pragma once + +#include <string> + +#include "common/exception/Exception.hpp" + +namespace cta { +namespace exception { + +/** + * Failed to dismount volume. + */ +class NoSupportedDB : public cta::exception::Exception { +public: + /** + * Constructor + */ + explicit NoSupportedDB(const std::string& what = ""); +}; // class NoSupportedDB + +} // namespace exception +} // namespace cta + diff --git a/rdbms/wrapper/ConnFactoryFactory.cpp b/rdbms/wrapper/ConnFactoryFactory.cpp index ec8c4026e85b45db74596e9e0258bef9da32d018..b366fc886b698a84f28edbeec98b927774ac01e6 100644 --- a/rdbms/wrapper/ConnFactoryFactory.cpp +++ b/rdbms/wrapper/ConnFactoryFactory.cpp @@ -18,9 +18,10 @@ #include <string> #include "common/exception/Exception.hpp" +#include "common/exception/NoSupportedDB.hpp" #include "rdbms/wrapper/ConnFactoryFactory.hpp" -#include "rdbms/wrapper/SqliteConnFactory.hpp" #include "rdbms/wrapper/PostgresConnFactory.hpp" +#include "rdbms/wrapper/SqliteConnFactory.hpp" #ifdef SUPPORT_OCCI #include "rdbms/wrapper/OcciConnFactory.hpp" @@ -38,9 +39,11 @@ std::unique_ptr<ConnFactory> ConnFactoryFactory::create(const Login &login) { switch (login.dbType) { case Login::DBTYPE_IN_MEMORY: return std::make_unique<SqliteConnFactory>("file::memory:?cache=shared"); -#ifdef SUPPORT_OCCI case Login::DBTYPE_ORACLE: +#ifdef SUPPORT_OCCI return std::make_unique<OcciConnFactory>(login.username, login.password, login.database); +#else + throw exception::NoSupportedDB("Oracle Catalogue Schema is not supported. Compile CTA with Oracle support."); #endif case Login::DBTYPE_SQLITE: return std::make_unique<SqliteConnFactory>(login.database);