From 78a1e5c683f7441cb14d3408fa961d3b66ea7067 Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Fri, 28 Apr 2017 15:33:59 +0200 Subject: [PATCH] cta/CTA#87 cta-catalogue-delete-all-data and cta-catalogue-schema-drop should require interactive confirmation Removed the now redundant locking commands for the catalogue schema. These commands were made redundant when the cta-catalogue-schema-drop command was made interactive. --- catalogue/CMakeLists.txt | 41 +----- catalogue/Catalogue.hpp | 23 ---- catalogue/CatalogueTest.cpp | 11 -- catalogue/DropSchemaCmd.cpp | 96 +++++++++----- catalogue/DropSchemaCmd.hpp | 23 +++- catalogue/LockSchemaCmd.cpp | 67 ---------- catalogue/LockSchemaCmd.hpp | 68 ---------- catalogue/LockSchemaCmdLineArgs.cpp | 111 ---------------- catalogue/LockSchemaCmdLineArgs.hpp | 60 --------- catalogue/LockSchemaCmdLineArgsTest.cpp | 121 ------------------ catalogue/LockSchemaCmdMain.cpp | 29 ----- catalogue/RdbmsCatalogue.cpp | 90 ------------- catalogue/RdbmsCatalogue.hpp | 21 --- catalogue/SchemaStatusCmd.cpp | 67 ---------- catalogue/SchemaStatusCmd.hpp | 67 ---------- catalogue/SchemaStatusCmdLineArgs.cpp | 111 ---------------- catalogue/SchemaStatusCmdLineArgs.hpp | 60 --------- catalogue/SchemaStatusCmdLineArgsTest.cpp | 121 ------------------ catalogue/SchemaStatusCmdMain.cpp | 29 ----- catalogue/UnlockSchemaCmd.cpp | 66 ---------- catalogue/UnlockSchemaCmd.hpp | 68 ---------- catalogue/UnlockSchemaCmdLineArgs.cpp | 112 ---------------- catalogue/UnlockSchemaCmdLineArgs.hpp | 60 --------- catalogue/UnlockSchemaCmdLineArgsTest.cpp | 121 ------------------ catalogue/UnlockSchemaCmdMain.cpp | 29 ----- catalogue/catalogue_common_schema.sql | 8 +- catalogue/cta-catalogue-schema-lock.1cta | 43 ------- catalogue/cta-catalogue-schema-status.1cta | 40 ------ catalogue/cta-catalogue-schema-unlock.1cta | 43 ------- .../buildtree_runner/cc7/opt/run/bin/init.sh | 2 - .../cc7/opt/run/bin/mkSymlinks.sh | 3 - .../ctafrontend/cc7/opt/run/bin/init.sh | 2 - cta.spec.in | 6 - rdbms/OcciConn.cpp | 25 ++++ rdbms/OcciConn.hpp | 9 ++ 35 files changed, 118 insertions(+), 1735 deletions(-) delete mode 100644 catalogue/LockSchemaCmd.cpp delete mode 100644 catalogue/LockSchemaCmd.hpp delete mode 100644 catalogue/LockSchemaCmdLineArgs.cpp delete mode 100644 catalogue/LockSchemaCmdLineArgs.hpp delete mode 100644 catalogue/LockSchemaCmdLineArgsTest.cpp delete mode 100644 catalogue/LockSchemaCmdMain.cpp delete mode 100644 catalogue/SchemaStatusCmd.cpp delete mode 100644 catalogue/SchemaStatusCmd.hpp delete mode 100644 catalogue/SchemaStatusCmdLineArgs.cpp delete mode 100644 catalogue/SchemaStatusCmdLineArgs.hpp delete mode 100644 catalogue/SchemaStatusCmdLineArgsTest.cpp delete mode 100644 catalogue/SchemaStatusCmdMain.cpp delete mode 100644 catalogue/UnlockSchemaCmd.cpp delete mode 100644 catalogue/UnlockSchemaCmd.hpp delete mode 100644 catalogue/UnlockSchemaCmdLineArgs.cpp delete mode 100644 catalogue/UnlockSchemaCmdLineArgs.hpp delete mode 100644 catalogue/UnlockSchemaCmdLineArgsTest.cpp delete mode 100644 catalogue/UnlockSchemaCmdMain.cpp delete mode 100644 catalogue/cta-catalogue-schema-lock.1cta delete mode 100644 catalogue/cta-catalogue-schema-status.1cta delete mode 100644 catalogue/cta-catalogue-schema-unlock.1cta diff --git a/catalogue/CMakeLists.txt b/catalogue/CMakeLists.txt index babd970cad..17f1479f65 100644 --- a/catalogue/CMakeLists.txt +++ b/catalogue/CMakeLists.txt @@ -113,39 +113,6 @@ install (FILES cta_catalogue_db.conf.example DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/cta PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) -add_executable(cta-catalogue-schema-lock - LockSchemaCmd.cpp - LockSchemaCmdLineArgs.cpp - LockSchemaCmdMain.cpp) - -target_link_libraries (cta-catalogue-schema-lock - ctacatalogue) - -install (TARGETS cta-catalogue-schema-lock DESTINATION /usr/bin) -install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-schema-lock.1cta DESTINATION /usr/share/man/man1) - -add_executable(cta-catalogue-schema-unlock - UnlockSchemaCmd.cpp - UnlockSchemaCmdLineArgs.cpp - UnlockSchemaCmdMain.cpp) - -target_link_libraries (cta-catalogue-schema-unlock - ctacatalogue) - -install (TARGETS cta-catalogue-schema-unlock DESTINATION /usr/bin) -install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-schema-unlock.1cta DESTINATION /usr/share/man/man1) - -add_executable(cta-catalogue-schema-status - SchemaStatusCmd.cpp - SchemaStatusCmdLineArgs.cpp - SchemaStatusCmdMain.cpp) - -target_link_libraries (cta-catalogue-schema-status - ctacatalogue) - -install (TARGETS cta-catalogue-schema-status DESTINATION /usr/bin) -install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-schema-status.1cta DESTINATION /usr/share/man/man1) - add_custom_command(OUTPUT oracle_catalogue_schema.cpp COMMAND sed 's/^/\ \ \"/' oracle_catalogue_schema.sql | sed 's/$$/\"/' > oracle_catalogue_schema.cpp DEPENDS oracle_catalogue_schema.sql) @@ -238,14 +205,8 @@ set (CATALOGUE_CMD_LINE_UNIT_TESTS_LIB_SRC_FILES CreateSchemaCmdLineArgsTest.cpp DropSchemaCmdLineArgs.cpp DropSchemaCmdLineArgsTest.cpp - LockSchemaCmdLineArgs.cpp - LockSchemaCmdLineArgsTest.cpp PollDatabaseCmdLineArgs.cpp - PollDatabaseCmdLineArgsTest.cpp - SchemaStatusCmdLineArgs.cpp - SchemaStatusCmdLineArgsTest.cpp - UnlockSchemaCmdLineArgs.cpp - UnlockSchemaCmdLineArgsTest.cpp) + PollDatabaseCmdLineArgsTest.cpp) add_library (ctacataloguecmdlineunittests SHARED ${CATALOGUE_CMD_LINE_UNIT_TESTS_LIB_SRC_FILES}) diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index b5e911cdb1..9ab3019951 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -518,29 +518,6 @@ public: */ virtual bool isAdmin(const common::dataStructures::SecurityIdentity &admin) const = 0; - /** - * Returns true if SCHEMA_STATUS column of the CTA_TABLE contains the value - * LOCKED. - * - * @return True if SCHEMA_STATUS column of the CTA_TABLE contains the value - * LOCKED. - */ - virtual bool schemaIsLocked() const = 0; - - /** - * Sets the value of the SCHEMA_STATUS column of the CTA_TABLE to LOCKED. - * - * Please note that this method is idempotent. - */ - virtual void lockSchema() = 0; - - /** - * Sets the value of the SCHEMA_STATUS column of the CTA_TABLE to UNLOCKED. - * - * Please note that this method is idempotent. - */ - virtual void unlockSchema() = 0; - /** * Checks that the most trivial query goes through. Throws an exception if not. */ diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index 9a00884d62..d5e4152254 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -7316,17 +7316,6 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_one_tape_file) { ASSERT_THROW(m_catalogue->reclaimTape(m_admin, vid1), exception::UserError); } -TEST_P(cta_catalogue_CatalogueTest, lockSchema_unlockSchema_lockSchema) { - using namespace cta; - - m_catalogue->lockSchema(); - ASSERT_TRUE(m_catalogue->schemaIsLocked()); - m_catalogue->unlockSchema(); - ASSERT_FALSE(m_catalogue->schemaIsLocked()); - m_catalogue->lockSchema(); - ASSERT_TRUE(m_catalogue->schemaIsLocked()); -} - TEST_P(cta_catalogue_CatalogueTest, ping) { using namespace cta; diff --git a/catalogue/DropSchemaCmd.cpp b/catalogue/DropSchemaCmd.cpp index f4a7965351..523f8f2ecf 100644 --- a/catalogue/DropSchemaCmd.cpp +++ b/catalogue/DropSchemaCmd.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <rdbms/OcciConn.hpp> #include "catalogue/CatalogueFactory.hpp" #include "catalogue/DropOracleCatalogueSchema.hpp" #include "catalogue/DropSchemaCmd.hpp" @@ -23,6 +24,7 @@ #include "catalogue/DropSqliteCatalogueSchema.hpp" #include "common/exception/Exception.hpp" #include "rdbms/ConnFactoryFactory.hpp" +#include "rdbms/OcciConn.hpp" namespace cta { namespace catalogue { @@ -55,37 +57,45 @@ int DropSchemaCmd::exceptionThrowingMain(const int argc, char *const *const argv } const rdbms::Login dbLogin = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath); + auto factory = rdbms::ConnFactoryFactory::create(dbLogin); + auto conn = factory->create(); // Abort if the schema is already dropped - { - auto factory = rdbms::ConnFactoryFactory::create(dbLogin); - auto conn = factory->create(); - - if(conn->getTableNames().empty()) { - m_out << "Database contains no tables. Assuming the schema has already been dropped." << std::endl; + switch(dbLogin.dbType) { + case rdbms::Login::DBTYPE_IN_MEMORY: + case rdbms::Login::DBTYPE_SQLITE: + if (conn->getTableNames().empty()) { + m_out << "Database contains no tables." << std::endl << + "Assuming the schema has already been dropped." << std::endl; return 0; } - } - - // Abort if the schema is not locked - { - const uint64_t nbDbConns = 1; - auto catalogue = CatalogueFactory::create(dbLogin, nbDbConns); - if(catalogue->schemaIsLocked()) { - m_err << - "Cannot drop the schema of the catalogue database because the schema is locked.\n" - "\n" - "Please see the following command-line tools:\n" - " cta-catalogue-schema-lock\n" - " cta-catalogue-schema-status\n" - " cta-catalogue-schema-unlock" << std::endl; - return 1; + break; + case rdbms::Login::DBTYPE_ORACLE: + { + rdbms::OcciConn *const occiConn = dynamic_cast<rdbms::OcciConn *>(conn.get()); + if(nullptr == occiConn) { + throw exception::Exception("Failed to down cast rdbms::conn to rdbms::OcciConn"); + } + if(occiConn->getTableNames().empty() && occiConn->getSequenceNames().empty()) { + m_out << "Database contains no tables and no sequences." << std::endl << + "Assuming the schema has already been dropped." << std::endl; + return 0; + } + } + break; + case rdbms::Login::DBTYPE_NONE: + throw exception::Exception("Cannot delete the schema of catalogue database without a database type"); + default: + { + exception::Exception ex; + ex.getMessage() << "Unknown database type: value=" << dbLogin.dbType; + throw ex; } } if(userConfirmsDropOfSchema(dbLogin)) { m_out << "DROPPING the schema of the CTA calalogue database" << std::endl; - dropCatalogueSchema(dbLogin); + dropCatalogueSchema(dbLogin.dbType, *conn); } else { m_out << "Aborting" << std::endl; } @@ -114,30 +124,22 @@ bool DropSchemaCmd::userConfirmsDropOfSchema(const rdbms::Login &dbLogin) { //------------------------------------------------------------------------------ // dropCatalogueSchema //------------------------------------------------------------------------------ -void DropSchemaCmd::dropCatalogueSchema(const rdbms::Login &dbLogin) { - auto factory = rdbms::ConnFactoryFactory::create(dbLogin); - auto conn = factory->create(); +void DropSchemaCmd::dropCatalogueSchema(const rdbms::Login::DbType &dbType, rdbms::Conn &conn) { try { - switch(dbLogin.dbType) { + switch(dbType) { case rdbms::Login::DBTYPE_IN_MEMORY: case rdbms::Login::DBTYPE_SQLITE: - { - DropSqliteCatalogueSchema dropSchema; - conn->executeNonQueries(dropSchema.sql); - } + dropSqliteCatalogueSchema(conn); break; case rdbms::Login::DBTYPE_ORACLE: - { - DropOracleCatalogueSchema dropSchema; - conn->executeNonQueries(dropSchema.sql); - } + dropOracleCatalogueSchema(conn); break; case rdbms::Login::DBTYPE_NONE: throw exception::Exception("Cannot delete the schema of catalogue database without a database type"); default: { exception::Exception ex; - ex.getMessage() << "Unknown database type: value=" << dbLogin.dbType; + ex.getMessage() << "Unknown database type: value=" << dbType; throw ex; } } @@ -146,6 +148,30 @@ void DropSchemaCmd::dropCatalogueSchema(const rdbms::Login &dbLogin) { } } +//------------------------------------------------------------------------------ +// dropSqliteCatalogueSchema +//------------------------------------------------------------------------------ +void DropSchemaCmd::dropSqliteCatalogueSchema(rdbms::Conn &conn) { + try { + DropSqliteCatalogueSchema dropSchema; + conn.executeNonQueries(dropSchema.sql); + } catch(exception::Exception &ex) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); + } +} + +//------------------------------------------------------------------------------ +// dropOracleCatalogueSchema +//------------------------------------------------------------------------------ +void DropSchemaCmd::dropOracleCatalogueSchema(rdbms::Conn &conn) { + try { + DropOracleCatalogueSchema dropSchema; + conn.executeNonQueries(dropSchema.sql); + } catch(exception::Exception &ex) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); + } +} + //------------------------------------------------------------------------------ // printUsage //------------------------------------------------------------------------------ diff --git a/catalogue/DropSchemaCmd.hpp b/catalogue/DropSchemaCmd.hpp index 1687aae2b1..9a6a67b88d 100644 --- a/catalogue/DropSchemaCmd.hpp +++ b/catalogue/DropSchemaCmd.hpp @@ -75,11 +75,28 @@ private: /** * Unconditionally drops the schema of the catalogue database associated with - * the specified database login. + * the specified database connection. * - * @param dbLogin The database login. + * @param dbType The database type. + * @param conn The database connection. + */ + void dropCatalogueSchema(const rdbms::Login::DbType &dbType, rdbms::Conn &conn); + + /** + * Unconditionally drops the schema of the catalogue database associated with + * the specified database connection. + * + * @param conn The database connection. + */ + void dropSqliteCatalogueSchema(rdbms::Conn &conn); + + /** + * Unconditionally drops the schema of the catalogue database associated with + * the specified database connection. + * + * @param conn The database connection. */ - void dropCatalogueSchema(const rdbms::Login &dbLogin); + void dropOracleCatalogueSchema(rdbms::Conn &conn); }; // class DropSchemaCmd diff --git a/catalogue/LockSchemaCmd.cpp b/catalogue/LockSchemaCmd.cpp deleted file mode 100644 index a01541f4ef..0000000000 --- a/catalogue/LockSchemaCmd.cpp +++ /dev/null @@ -1,67 +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/>. - */ - -#include "catalogue/CatalogueFactory.hpp" -#include "catalogue/LockSchemaCmd.hpp" -#include "catalogue/LockSchemaCmdLineArgs.hpp" - -namespace cta { -namespace catalogue { - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -LockSchemaCmd::LockSchemaCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream): -CmdLineTool(inStream, outStream, errStream) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -LockSchemaCmd::~LockSchemaCmd() noexcept { -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -int LockSchemaCmd::exceptionThrowingMain(const int argc, char *const *const argv) { - const LockSchemaCmdLineArgs cmdLineArgs(argc, argv); - - if(cmdLineArgs.help) { - printUsage(m_out); - return 0; - } - - const auto dbLogin = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath); - const uint64_t nbDbConns = 1; - auto catalogue = CatalogueFactory::create(dbLogin, nbDbConns); - catalogue->lockSchema(); - - return 0; -} - -//------------------------------------------------------------------------------ -// printUsage -//------------------------------------------------------------------------------ -void LockSchemaCmd::printUsage(std::ostream &os) { - LockSchemaCmdLineArgs::printUsage(os); -} - - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/LockSchemaCmd.hpp b/catalogue/LockSchemaCmd.hpp deleted file mode 100644 index 1e999a9e5a..0000000000 --- a/catalogue/LockSchemaCmd.hpp +++ /dev/null @@ -1,68 +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 "catalogue/CmdLineTool.hpp" - -namespace cta { -namespace catalogue { - -/** - * Command-line tool for locking the catalogue schema in order to help - * protect it from accidental deletion. - */ -class LockSchemaCmd: public CmdLineTool { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - */ - LockSchemaCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream); - - /** - * Destructor. - */ - ~LockSchemaCmd() noexcept; - -private: - - /** - * An exception throwing version of main(). - * - * @param argc The number of command-line arguments including the program name. - * @param argv The command-line arguments. - * @return The exit value of the program. - */ - int exceptionThrowingMain(const int argc, char *const *const argv) override; - - /** - * Prints the usage message of the command-line tool. - * - * @param os The output stream to which the usage message is to be printed. - */ - void printUsage(std::ostream &os) override; - -}; // class LockSchemaCmd - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/LockSchemaCmdLineArgs.cpp b/catalogue/LockSchemaCmdLineArgs.cpp deleted file mode 100644 index ccd8dafc15..0000000000 --- a/catalogue/LockSchemaCmdLineArgs.cpp +++ /dev/null @@ -1,111 +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/>. - */ - -#include "catalogue/LockSchemaCmdLineArgs.hpp" -#include "common/exception/CommandLineNotParsed.hpp" - -#include <getopt.h> -#include <ostream> - -namespace cta { -namespace catalogue { - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -LockSchemaCmdLineArgs::LockSchemaCmdLineArgs(const int argc, char *const *const argv): - help(false) { - - static struct option longopts[] = { - {"help", no_argument, NULL, 'h'}, - {NULL , 0, NULL, 0} - }; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - - int opt = 0; - while((opt = getopt_long(argc, argv, ":h", longopts, NULL)) != -1) { - switch(opt) { - case 'h': - help = true; - break; - case ':': // Missing parameter - { - exception::CommandLineNotParsed ex; - ex.getMessage() << "The -" << (char)opt << " option requires a parameter"; - throw ex; - } - case '?': // Unknown option - { - exception::CommandLineNotParsed ex; - if(0 == optopt) { - ex.getMessage() << "Unknown command-line option"; - } else { - ex.getMessage() << "Unknown command-line option: -" << (char)optopt; - } - throw ex; - } - default: - { - exception::CommandLineNotParsed ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)opt; - throw ex; - } - } // switch(opt) - } // while getopt_long() - - // There is no need to continue parsing when the help option is set - if(help) { - return; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc - optind; - - // Check the number of arguments - if(nbArgs != 1) { - exception::CommandLineNotParsed ex; - ex.getMessage() << "Wrong number of command-line arguments: excepted=1 actual=" << nbArgs; - throw ex; - } - - dbConfigPath = argv[optind]; -} - -//------------------------------------------------------------------------------ -// printUsage -//------------------------------------------------------------------------------ -void LockSchemaCmdLineArgs::printUsage(std::ostream &os) { - os << - "Usage:" << std::endl << - " cta-catalogue-schema-lock databaseConnectionFile" << std::endl << - "Where:" << std::endl << - " databaseConnectionFile" << std::endl << - " The path to the file containing the connection details of the CTA" << std::endl << - " catalogue database" << std::endl << - "Options:" << std::endl << - " -h,--help" << std::endl << - " Prints this usage message" << std::endl; -} - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/LockSchemaCmdLineArgs.hpp b/catalogue/LockSchemaCmdLineArgs.hpp deleted file mode 100644 index f18c0286f8..0000000000 --- a/catalogue/LockSchemaCmdLineArgs.hpp +++ /dev/null @@ -1,60 +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 <string> - -namespace cta { -namespace catalogue { - -/** - * Structure to store the command-line arguments of the command-line tool - * named cta-catalogue-schema-lock. - */ -struct LockSchemaCmdLineArgs { - /** - * True if the usage message should be printed. - */ - bool help; - - /** - * Path to the file containing the connection details of the catalogue - * database. - */ - std::string dbConfigPath; - - /** - * Constructor that parses the specified command-line arguments. - * - * @param argc The number of command-line arguments including the name of the - * executable. - * @param argv The vector of command-line arguments. - */ - LockSchemaCmdLineArgs(const int argc, char *const *const argv); - - /** - * Prints the usage message of the command-line tool. - * - * @param os The output stream to which the usage message is to be printed. - */ - static void printUsage(std::ostream &os); -}; - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/LockSchemaCmdLineArgsTest.cpp b/catalogue/LockSchemaCmdLineArgsTest.cpp deleted file mode 100644 index 9ad909eee4..0000000000 --- a/catalogue/LockSchemaCmdLineArgsTest.cpp +++ /dev/null @@ -1,121 +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/>. - */ - -#include "common/exception/Exception.hpp" -#include "catalogue/LockSchemaCmdLineArgs.hpp" - -#include <gtest/gtest.h> -#include <list> - -namespace unitTests { - -class cta_catalogue_LockSchemaCmdLineArgsTest : public ::testing::Test { -protected: - - struct Argcv { - int argc; - char **argv; - Argcv(): argc(0), argv(NULL) { - } - }; - typedef std::list<Argcv*> ArgcvList; - ArgcvList m_argsList; - - /** - * Creates a duplicate string using the new operator. - */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; - } - - virtual void SetUp() { - // Allow getopt_long to be called again - optind = 0; - } - - virtual void TearDown() { - // Allow getopt_long to be called again - optind = 0; - - for(ArgcvList::const_iterator itor = m_argsList.begin(); - itor != m_argsList.end(); itor++) { - for(int i=0; i < (*itor)->argc; i++) { - delete[] (*itor)->argv[i]; - } - delete[] (*itor)->argv; - delete *itor; - } - } -}; - -TEST_F(cta_catalogue_LockSchemaCmdLineArgsTest, help_short) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-lock"); - args->argv[1] = dupString("-h"); - args->argv[2] = NULL; - - LockSchemaCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_TRUE(cmdLine.help); - ASSERT_TRUE(cmdLine.dbConfigPath.empty()); -} - -TEST_F(cta_catalogue_LockSchemaCmdLineArgsTest, help_long) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-lock"); - args->argv[1] = dupString("--help"); - args->argv[2] = NULL; - - LockSchemaCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_TRUE(cmdLine.help); - ASSERT_TRUE(cmdLine.dbConfigPath.empty()); -} - -TEST_F(cta_catalogue_LockSchemaCmdLineArgsTest, dbConfigPath) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-lock"); - args->argv[1] = dupString("dbConfigPath"); - args->argv[2] = NULL; - - LockSchemaCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_FALSE(cmdLine.help); - ASSERT_EQ(std::string("dbConfigPath"), cmdLine.dbConfigPath); -} - -} // namespace unitTests diff --git a/catalogue/LockSchemaCmdMain.cpp b/catalogue/LockSchemaCmdMain.cpp deleted file mode 100644 index 672888db66..0000000000 --- a/catalogue/LockSchemaCmdMain.cpp +++ /dev/null @@ -1,29 +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/>. - */ - -#include "catalogue/LockSchemaCmd.hpp" - -#include <iostream> - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - cta::catalogue::LockSchemaCmd cmd(std::cin, std::cout, std::cerr); - return cmd.main(argc, argv); -} diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 43b63b1119..845b9ac2a3 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -4580,96 +4580,6 @@ std::unique_ptr<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveF } } -//------------------------------------------------------------------------------ -// schemaIsLocked -//------------------------------------------------------------------------------ -bool RdbmsCatalogue::schemaIsLocked() const { - try { - const char *const sql = "SELECT SCHEMA_STATUS FROM CTA_CATALOGUE"; - auto conn = m_connPool.getConn(); - auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); - auto rset = stmt->executeQuery(); - if(!rset->next()) { - throw exception::Exception("The CTA_CATALOGUE table does not contain any rows when it should contain exactly " - "one"); - } - const bool locked = rset->columnString("SCHEMA_STATUS") == "LOCKED"; - if(rset->next()) { - throw exception::Exception("The CTA_CATALOGUE table contains more than one rows when it should contain exactly " - "one"); - } - return locked; - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - -//------------------------------------------------------------------------------ -// lockSchema -//------------------------------------------------------------------------------ -void RdbmsCatalogue::lockSchema() { - try { - const char *const sql = "UPDATE CTA_CATALOGUE SET SCHEMA_STATUS = 'LOCKED'"; - auto conn = m_connPool.getConn(); - rdbms::AutoRollback autoRollback(conn); - auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); - stmt->executeNonQuery(); - const uint64_t nbAffectedRows = stmt->getNbAffectedRows(); - switch(nbAffectedRows) { - case 0: - throw exception::Exception("Failed to lock CTA catalogue schema: " - "The CTA_CATALOGUE table does not contain any rows when it should contain exactly one"); - case 1: - // Successfully locked the CTA catalogue schema - break; - default: - { - exception::Exception ex; - ex.getMessage() << "Failed to lock CTA catalogue schema: " << "The CTA_CATALOGUE tables contains " << - nbAffectedRows << " rows when it should contain exactly one"; - throw ex; - } - } - conn.commit(); - - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - -//------------------------------------------------------------------------------ -// unlockSchema -//------------------------------------------------------------------------------ -void RdbmsCatalogue::unlockSchema() { - try { - const char *const sql = "UPDATE CTA_CATALOGUE SET SCHEMA_STATUS = 'UNLOCKED'"; - auto conn = m_connPool.getConn(); - rdbms::AutoRollback autoRollback(conn); - auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); - stmt->executeNonQuery(); - const uint64_t nbAffectedRows = stmt->getNbAffectedRows(); - switch(nbAffectedRows) { - case 0: - throw exception::Exception("Failed to unlock CTA catalogue schema: " - "The CTA_CATALOGUE table does not contain any rows when it should contain exactly one"); - case 1: - // Successfully locked the CTA catalogue schema - break; - default: - { - exception::Exception ex; - ex.getMessage() << "Failed to unlock CTA catalogue schema: " << "The CTA_CATALOGUE tables contains " << - nbAffectedRows << " rows when it should contain exactly one"; - throw ex; - } - } - conn.commit(); - - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // ping //------------------------------------------------------------------------------ diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index 92d1c63162..f67112108c 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -489,27 +489,6 @@ public: */ bool isAdmin(const common::dataStructures::SecurityIdentity &admin) const override; - /** - * Returns true if SCHEMA_STATUS column of the CTA_TABLE contains the value LOCKED. - * - * @return True if SCHEMA_STATUS column of the CTA_TABLE contains the value LOCKED. - */ - bool schemaIsLocked() const override; - - /** - * Sets the value of the SCHEMA_STATUS column of the CTA_TABLE to LOCKED. - * - * Please note that this method is idempotent. - */ - void lockSchema() override; - - /** - * Sets the value of the SCHEMA_STATUS column of the CTA_TABLE to UNLOCKED. - * - * Please note that this method is idempotent. - */ - void unlockSchema() override; - /** * Checks that the most trivial query goes through. Returns true on success, * false on failure. diff --git a/catalogue/SchemaStatusCmd.cpp b/catalogue/SchemaStatusCmd.cpp deleted file mode 100644 index f6a0b3cb2c..0000000000 --- a/catalogue/SchemaStatusCmd.cpp +++ /dev/null @@ -1,67 +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/>. - */ - -#include "catalogue/CatalogueFactory.hpp" -#include "catalogue/SchemaStatusCmd.hpp" -#include "catalogue/SchemaStatusCmdLineArgs.hpp" - -namespace cta { -namespace catalogue { - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -SchemaStatusCmd::SchemaStatusCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream): -CmdLineTool(inStream, outStream, errStream) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -SchemaStatusCmd::~SchemaStatusCmd() noexcept { -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -int SchemaStatusCmd::exceptionThrowingMain(const int argc, char *const *const argv) { - const SchemaStatusCmdLineArgs cmdLineArgs(argc, argv); - - if(cmdLineArgs.help) { - printUsage(m_out); - return 0; - } - - const auto dbLogin = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath); - const uint64_t nbDbConns = 1; - auto catalogue = CatalogueFactory::create(dbLogin, nbDbConns); - - m_out << (catalogue->schemaIsLocked() ? "LOCKED" : "UNLOCKED") << std::endl; - - return 0; -} - -//------------------------------------------------------------------------------ -// printUsage -//------------------------------------------------------------------------------ -void SchemaStatusCmd::printUsage(std::ostream &os) { - SchemaStatusCmdLineArgs::printUsage(os); -} - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/SchemaStatusCmd.hpp b/catalogue/SchemaStatusCmd.hpp deleted file mode 100644 index 0bcd538a6c..0000000000 --- a/catalogue/SchemaStatusCmd.hpp +++ /dev/null @@ -1,67 +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 "catalogue/CmdLineTool.hpp" - -namespace cta { -namespace catalogue { - -/** - * Command-line tool for printing the current status of the catalogue schema. - */ -class SchemaStatusCmd: public CmdLineTool { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - */ - SchemaStatusCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream); - - /** - * Destructor. - */ - ~SchemaStatusCmd() noexcept; - -private: - - /** - * An exception throwing version of main(). - * - * @param argc The number of command-line arguments including the program name. - * @param argv The command-line arguments. - * @return The exit value of the program. - */ - int exceptionThrowingMain(const int argc, char *const *const argv) override; - - /** - * Prints the usage message of the command-line tool. - * - * @param os The output stream to which the usage message is to be printed. - */ - void printUsage(std::ostream &os) override; - -}; // class SchemaStatusCmd - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/SchemaStatusCmdLineArgs.cpp b/catalogue/SchemaStatusCmdLineArgs.cpp deleted file mode 100644 index a47a1602ab..0000000000 --- a/catalogue/SchemaStatusCmdLineArgs.cpp +++ /dev/null @@ -1,111 +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/>. - */ - -#include "catalogue/SchemaStatusCmdLineArgs.hpp" -#include "common/exception/CommandLineNotParsed.hpp" - -#include <getopt.h> -#include <ostream> - -namespace cta { -namespace catalogue { - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -SchemaStatusCmdLineArgs::SchemaStatusCmdLineArgs(const int argc, char *const *const argv): - help(false) { - - static struct option longopts[] = { - {"help", no_argument, NULL, 'h'}, - {NULL , 0, NULL, 0} - }; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - - int opt = 0; - while((opt = getopt_long(argc, argv, ":h", longopts, NULL)) != -1) { - switch(opt) { - case 'h': - help = true; - break; - case ':': // Missing parameter - { - exception::CommandLineNotParsed ex; - ex.getMessage() << "The -" << (char)opt << " option requires a parameter"; - throw ex; - } - case '?': // Unknown option - { - exception::CommandLineNotParsed ex; - if(0 == optopt) { - ex.getMessage() << "Unknown command-line option"; - } else { - ex.getMessage() << "Unknown command-line option: -" << (char)optopt; - } - throw ex; - } - default: - { - exception::CommandLineNotParsed ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)opt; - throw ex; - } - } // switch(opt) - } // while getopt_long() - - // There is no need to continue parsing when the help option is set - if(help) { - return; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc - optind; - - // Check the number of arguments - if(nbArgs != 1) { - exception::CommandLineNotParsed ex; - ex.getMessage() << "Wrong number of command-line arguments: excepted=1 actual=" << nbArgs; - throw ex; - } - - dbConfigPath = argv[optind]; -} - -//------------------------------------------------------------------------------ -// printUsage -//------------------------------------------------------------------------------ -void SchemaStatusCmdLineArgs::printUsage(std::ostream &os) { - os << - "Usage:" << std::endl << - " cta-catalogue-schema-status databaseConnectionFile" << std::endl << - "Where:" << std::endl << - " databaseConnectionFile" << std::endl << - " The path to the file containing the connection details of the CTA" << std::endl << - " catalogue database" << std::endl << - "Options:" << std::endl << - " -h,--help" << std::endl << - " Prints this usage message" << std::endl; -} - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/SchemaStatusCmdLineArgs.hpp b/catalogue/SchemaStatusCmdLineArgs.hpp deleted file mode 100644 index a138771057..0000000000 --- a/catalogue/SchemaStatusCmdLineArgs.hpp +++ /dev/null @@ -1,60 +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 <string> - -namespace cta { -namespace catalogue { - -/** - * Structure to store the command-line arguments of the command-line tool - * named cta-catalogue-schema-status. - */ -struct SchemaStatusCmdLineArgs { - /** - * True if the usage message should be printed. - */ - bool help; - - /** - * Path to the file containing the connection details of the catalogue - * database. - */ - std::string dbConfigPath; - - /** - * Constructor that parses the specified command-line arguments. - * - * @param argc The number of command-line arguments including the name of the - * executable. - * @param argv The vector of command-line arguments. - */ - SchemaStatusCmdLineArgs(const int argc, char *const *const argv); - - /** - * Prints the usage message of the command-line tool. - * - * @param os The output stream to which the usage message is to be printed. - */ - static void printUsage(std::ostream &os); -}; - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/SchemaStatusCmdLineArgsTest.cpp b/catalogue/SchemaStatusCmdLineArgsTest.cpp deleted file mode 100644 index 2cf962c920..0000000000 --- a/catalogue/SchemaStatusCmdLineArgsTest.cpp +++ /dev/null @@ -1,121 +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/>. - */ - -#include "common/exception/Exception.hpp" -#include "catalogue/SchemaStatusCmdLineArgs.hpp" - -#include <gtest/gtest.h> -#include <list> - -namespace unitTests { - -class cta_catalogue_SchemaStatusCmdLineArgsTest : public ::testing::Test { -protected: - - struct Argcv { - int argc; - char **argv; - Argcv(): argc(0), argv(NULL) { - } - }; - typedef std::list<Argcv*> ArgcvList; - ArgcvList m_argsList; - - /** - * Creates a duplicate string using the new operator. - */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; - } - - virtual void SetUp() { - // Allow getopt_long to be called again - optind = 0; - } - - virtual void TearDown() { - // Allow getopt_long to be called again - optind = 0; - - for(ArgcvList::const_iterator itor = m_argsList.begin(); - itor != m_argsList.end(); itor++) { - for(int i=0; i < (*itor)->argc; i++) { - delete[] (*itor)->argv[i]; - } - delete[] (*itor)->argv; - delete *itor; - } - } -}; - -TEST_F(cta_catalogue_SchemaStatusCmdLineArgsTest, help_short) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-status"); - args->argv[1] = dupString("-h"); - args->argv[2] = NULL; - - SchemaStatusCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_TRUE(cmdLine.help); - ASSERT_TRUE(cmdLine.dbConfigPath.empty()); -} - -TEST_F(cta_catalogue_SchemaStatusCmdLineArgsTest, help_long) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-status"); - args->argv[1] = dupString("--help"); - args->argv[2] = NULL; - - SchemaStatusCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_TRUE(cmdLine.help); - ASSERT_TRUE(cmdLine.dbConfigPath.empty()); -} - -TEST_F(cta_catalogue_SchemaStatusCmdLineArgsTest, dbConfigPath) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-status"); - args->argv[1] = dupString("dbConfigPath"); - args->argv[2] = NULL; - - SchemaStatusCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_FALSE(cmdLine.help); - ASSERT_EQ(std::string("dbConfigPath"), cmdLine.dbConfigPath); -} - -} // namespace unitTests diff --git a/catalogue/SchemaStatusCmdMain.cpp b/catalogue/SchemaStatusCmdMain.cpp deleted file mode 100644 index e3f363293a..0000000000 --- a/catalogue/SchemaStatusCmdMain.cpp +++ /dev/null @@ -1,29 +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/>. - */ - -#include "catalogue/SchemaStatusCmd.hpp" - -#include <iostream> - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - cta::catalogue::SchemaStatusCmd cmd(std::cin, std::cout, std::cerr); - return cmd.main(argc, argv); -} diff --git a/catalogue/UnlockSchemaCmd.cpp b/catalogue/UnlockSchemaCmd.cpp deleted file mode 100644 index e4bce86ad5..0000000000 --- a/catalogue/UnlockSchemaCmd.cpp +++ /dev/null @@ -1,66 +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/>. - */ - -#include "catalogue/CatalogueFactory.hpp" -#include "catalogue/UnlockSchemaCmd.hpp" -#include "catalogue/UnlockSchemaCmdLineArgs.hpp" - -namespace cta { -namespace catalogue { - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -UnlockSchemaCmd::UnlockSchemaCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream): -CmdLineTool(inStream, outStream, errStream) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -UnlockSchemaCmd::~UnlockSchemaCmd() noexcept { -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -int UnlockSchemaCmd::exceptionThrowingMain(const int argc, char *const *const argv) { - const UnlockSchemaCmdLineArgs cmdLineArgs(argc, argv); - - if(cmdLineArgs.help) { - printUsage(m_out); - return 0; - } - - const auto dbLogin = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath); - const uint64_t nbDbConns = 1; - auto catalogue = CatalogueFactory::create(dbLogin, nbDbConns); - catalogue->unlockSchema(); - - return 0; -} - -//------------------------------------------------------------------------------ -// printUsage -//------------------------------------------------------------------------------ -void UnlockSchemaCmd::printUsage(std::ostream &os) { - UnlockSchemaCmdLineArgs::printUsage(os); -} - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/UnlockSchemaCmd.hpp b/catalogue/UnlockSchemaCmd.hpp deleted file mode 100644 index 72a1faa98b..0000000000 --- a/catalogue/UnlockSchemaCmd.hpp +++ /dev/null @@ -1,68 +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 "catalogue/CmdLineTool.hpp" - -namespace cta { -namespace catalogue { - -/** - * Command-line tool for unlocking the catalogue schema. The locking mechanism - * helps prevent the schema from being accidentally deleted. - */ -class UnlockSchemaCmd: public CmdLineTool { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - */ - UnlockSchemaCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream); - - /** - * Destructor. - */ - ~UnlockSchemaCmd() noexcept; - -private: - - /** - * An exception throwing version of main(). - * - * @param argc The number of command-line arguments including the program name. - * @param argv The command-line arguments. - * @return The exit value of the program. - */ - int exceptionThrowingMain(const int argc, char *const *const argv) override; - - /** - * Prints the usage message of the command-line tool. - * - * @param os The output stream to which the usage message is to be printed. - */ - void printUsage(std::ostream &os) override; - -}; // class UnlockSchemaCmd - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/UnlockSchemaCmdLineArgs.cpp b/catalogue/UnlockSchemaCmdLineArgs.cpp deleted file mode 100644 index 7e2a9f59b9..0000000000 --- a/catalogue/UnlockSchemaCmdLineArgs.cpp +++ /dev/null @@ -1,112 +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/>. - */ - -#include "catalogue/UnlockSchemaCmdLineArgs.hpp" -#include "common/exception/Exception.hpp" -#include "common/exception/CommandLineNotParsed.hpp" - -#include <getopt.h> -#include <ostream> - -namespace cta { -namespace catalogue { - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -UnlockSchemaCmdLineArgs::UnlockSchemaCmdLineArgs(const int argc, char *const *const argv): - help(false) { - - static struct option longopts[] = { - {"help", no_argument, NULL, 'h'}, - {NULL , 0, NULL, 0} - }; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - - int opt = 0; - while((opt = getopt_long(argc, argv, ":h", longopts, NULL)) != -1) { - switch(opt) { - case 'h': - help = true; - break; - case ':': // Missing parameter - { - exception::CommandLineNotParsed ex; - ex.getMessage() << "The -" << (char)opt << " option requires a parameter"; - throw ex; - } - case '?': // Unknown option - { - exception::CommandLineNotParsed ex; - if(0 == optopt) { - ex.getMessage() << "Unknown command-line option"; - } else { - ex.getMessage() << "Unknown command-line option: -" << (char)optopt; - } - throw ex; - } - default: - { - exception::CommandLineNotParsed ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)opt; - throw ex; - } - } // switch(opt) - } // while getopt_long() - - // There is no need to continue parsing when the help option is set - if(help) { - return; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc - optind; - - // Check the number of arguments - if(nbArgs != 1) { - exception::CommandLineNotParsed ex; - ex.getMessage() << "Wrong number of command-line arguments: excepted=1 actual=" << nbArgs; - throw ex; - } - - dbConfigPath = argv[optind]; -} - -//------------------------------------------------------------------------------ -// printUsage -//------------------------------------------------------------------------------ -void UnlockSchemaCmdLineArgs::printUsage(std::ostream &os) { - os << - "Usage:" << std::endl << - " cta-catalogue-schema-unlock databaseConnectionFile" << std::endl << - "Where:" << std::endl << - " databaseConnectionFile" << std::endl << - " The path to the file containing the connection details of the CTA" << std::endl << - " catalogue database" << std::endl << - "Options:" << std::endl << - " -h,--help" << std::endl << - " Prints this usage message" << std::endl; -} - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/UnlockSchemaCmdLineArgs.hpp b/catalogue/UnlockSchemaCmdLineArgs.hpp deleted file mode 100644 index c6a34d7d99..0000000000 --- a/catalogue/UnlockSchemaCmdLineArgs.hpp +++ /dev/null @@ -1,60 +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 <string> - -namespace cta { -namespace catalogue { - -/** - * Structure to store the command-line arguments of the command-line tool - * named cta-catalogue-schema-unlock. - */ -struct UnlockSchemaCmdLineArgs { - /** - * True if the usage message should be printed. - */ - bool help; - - /** - * Path to the file containing the connection details of the catalogue - * database. - */ - std::string dbConfigPath; - - /** - * Constructor that parses the specified command-line arguments. - * - * @param argc The number of command-line arguments including the name of the - * executable. - * @param argv The vector of command-line arguments. - */ - UnlockSchemaCmdLineArgs(const int argc, char *const *const argv); - - /** - * Prints the usage message of the command-line tool. - * - * @param os The output stream to which the usage message is to be printed. - */ - static void printUsage(std::ostream &os); -}; - -} // namespace catalogue -} // namespace cta diff --git a/catalogue/UnlockSchemaCmdLineArgsTest.cpp b/catalogue/UnlockSchemaCmdLineArgsTest.cpp deleted file mode 100644 index b9897d4104..0000000000 --- a/catalogue/UnlockSchemaCmdLineArgsTest.cpp +++ /dev/null @@ -1,121 +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/>. - */ - -#include "common/exception/Exception.hpp" -#include "catalogue/UnlockSchemaCmdLineArgs.hpp" - -#include <gtest/gtest.h> -#include <list> - -namespace unitTests { - -class cta_catalogue_UnlockSchemaCmdLineArgsTest : public ::testing::Test { -protected: - - struct Argcv { - int argc; - char **argv; - Argcv(): argc(0), argv(NULL) { - } - }; - typedef std::list<Argcv*> ArgcvList; - ArgcvList m_argsList; - - /** - * Creates a duplicate string using the new operator. - */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; - } - - virtual void SetUp() { - // Allow getopt_long to be called again - optind = 0; - } - - virtual void TearDown() { - // Allow getopt_long to be called again - optind = 0; - - for(ArgcvList::const_iterator itor = m_argsList.begin(); - itor != m_argsList.end(); itor++) { - for(int i=0; i < (*itor)->argc; i++) { - delete[] (*itor)->argv[i]; - } - delete[] (*itor)->argv; - delete *itor; - } - } -}; - -TEST_F(cta_catalogue_UnlockSchemaCmdLineArgsTest, help_short) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-unlock"); - args->argv[1] = dupString("-h"); - args->argv[2] = NULL; - - UnlockSchemaCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_TRUE(cmdLine.help); - ASSERT_TRUE(cmdLine.dbConfigPath.empty()); -} - -TEST_F(cta_catalogue_UnlockSchemaCmdLineArgsTest, help_long) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-unlock"); - args->argv[1] = dupString("--help"); - args->argv[2] = NULL; - - UnlockSchemaCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_TRUE(cmdLine.help); - ASSERT_TRUE(cmdLine.dbConfigPath.empty()); -} - -TEST_F(cta_catalogue_UnlockSchemaCmdLineArgsTest, dbConfigPath) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-unlock"); - args->argv[1] = dupString("dbConfigPath"); - args->argv[2] = NULL; - - UnlockSchemaCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_FALSE(cmdLine.help); - ASSERT_EQ(std::string("dbConfigPath"), cmdLine.dbConfigPath); -} - -} // namespace unitTests diff --git a/catalogue/UnlockSchemaCmdMain.cpp b/catalogue/UnlockSchemaCmdMain.cpp deleted file mode 100644 index 17e552b72a..0000000000 --- a/catalogue/UnlockSchemaCmdMain.cpp +++ /dev/null @@ -1,29 +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/>. - */ - -#include "catalogue/UnlockSchemaCmd.hpp" - -#include <iostream> - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - cta::catalogue::UnlockSchemaCmd cmd(std::cin, std::cout, std::cerr); - return cmd.main(argc, argv); -} diff --git a/catalogue/catalogue_common_schema.sql b/catalogue/catalogue_common_schema.sql index 4065dbf84b..662ef891e7 100644 --- a/catalogue/catalogue_common_schema.sql +++ b/catalogue/catalogue_common_schema.sql @@ -1,8 +1,6 @@ CREATE TABLE CTA_CATALOGUE( - SCHEMA_STATUS VARCHAR2(100) NOT NULL, - SCHEMA_VERSION_MAJOR INTEGER NOT NULL, - SCHEMA_VERSION_MINOR INTEGER NOT NULL, - CONSTRAINT CTA_SCHEMA_STATUS_CK CHECK(SCHEMA_STATUS IN ('LOCKED', 'UNLOCKED')) + SCHEMA_VERSION_MAJOR INTEGER NOT NULL, + SCHEMA_VERSION_MINOR INTEGER NOT NULL ); CREATE TABLE ADMIN_USER( ADMIN_USER_NAME VARCHAR2(100) NOT NULL, @@ -196,10 +194,8 @@ CREATE TABLE TAPE_FILE( CONSTRAINT TAPE_FILE_VID_ARCH_FILE_ID_UN UNIQUE(VID, ARCHIVE_FILE_ID) ); INSERT INTO CTA_CATALOGUE( - SCHEMA_STATUS, SCHEMA_VERSION_MAJOR, SCHEMA_VERSION_MINOR) VALUES( - 'LOCKED', 0, 0); diff --git a/catalogue/cta-catalogue-schema-lock.1cta b/catalogue/cta-catalogue-schema-lock.1cta deleted file mode 100644 index a505fc3086..0000000000 --- a/catalogue/cta-catalogue-schema-lock.1cta +++ /dev/null @@ -1,43 +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/>. -.TH CTA-CATALOGUE-SCHEMA-LOCK 1CTA "August 2016" CTA CTA -.SH NAME -cta-catalogue-schema-lock \- Lock the CTA catalogue schema -.SH SYNOPSIS -.BI "cta-catalogue-schema-lock databaseConnectionFile [options]" - -.SH DESCRIPTION -\fBcta-catalogue-schema-lock\fP is a command-line tool that locks the CTA -catalogue database schema in order to help prevent the cta-catalogue-schema-drop -command-line tool from accidently dropping it. -.P -This command-line tool sets the contents of the SCHEMA_STATUS column of the -CTA_CATALOGUE database table to LOCKED. -.SH ARGUMENTS -.TP -\fBdatabaseConnectionFile -The path to the configuration file containing the connection details of the -CTA catalogue database. -.TP -\fB\-h, \-\-help -Prints the usage message. -.SH RETURN VALUE -Zero on success and non-zero on failure. -.SH EXAMPLES -cta-catalogue-schema-lock /etc/cta/cta_catalogue_db.conf - -.SH AUTHOR -\fBCTA\fP Team diff --git a/catalogue/cta-catalogue-schema-status.1cta b/catalogue/cta-catalogue-schema-status.1cta deleted file mode 100644 index 8d18bfcb99..0000000000 --- a/catalogue/cta-catalogue-schema-status.1cta +++ /dev/null @@ -1,40 +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/>. -.TH CTA-CATALOGUE-SCHEMA-STATUS 1CTA "August 2016" CTA CTA -.SH NAME -cta-catalogue-schema-status \- Lock the CTA catalogue schema -.SH SYNOPSIS -.BI "cta-catalogue-schema-status databaseConnectionFile [options]" - -.SH DESCRIPTION -\fBcta-catalogue-schema-status\fP is a command-line tool that prints status of -the CTA catalogue database schema. -.P -.SH ARGUMENTS -.TP -\fBdatabaseConnectionFile -The path to the configuration file containing the connection details of the -CTA catalogue database. -.TP -\fB\-h, \-\-help -Prints the usage message. -.SH RETURN VALUE -Zero on success and non-zero on failure. -.SH EXAMPLES -cta-catalogue-schema-status /etc/cta/cta_catalogue_db.conf - -.SH AUTHOR -\fBCTA\fP Team diff --git a/catalogue/cta-catalogue-schema-unlock.1cta b/catalogue/cta-catalogue-schema-unlock.1cta deleted file mode 100644 index f63185930b..0000000000 --- a/catalogue/cta-catalogue-schema-unlock.1cta +++ /dev/null @@ -1,43 +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/>. -.TH CTA-CATALOGUE-SCHEMA-UNLOCK 1CTA "August 2016" CTA CTA -.SH NAME -cta-catalogue-schema-unlock \- Unlock the CTA catalogue schema -.SH SYNOPSIS -.BI "cta-catalogue-schema-unlock databaseConnectionFile [options]" - -.SH DESCRIPTION -\fBcta-catalogue-schema-unlock\fP is a command-line tool that unlocks the CTA -catalogue database schema so that it can be deleted by the -cta-catalogue-schema-drop command-line tool. -.P -This command-line tool sets the contents of the SCHEMA_STATUS column of the -CTA_CATALOGUE database table to UNLOCKED. -.SH ARGUMENTS -.TP -\fBdatabaseConnectionFile -The path to the configuration file containing the connection details of the -CTA catalogue database. -.TP -\fB\-h, \-\-help -Prints the usage message. -.SH RETURN VALUE -Zero on success and non-zero on failure. -.SH EXAMPLES -cta-catalogue-schema-unlock /etc/cta/cta_catalogue_db.conf - -.SH AUTHOR -\fBCTA\fP Team diff --git a/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/init.sh b/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/init.sh index c02ca69045..8213b6adf4 100755 --- a/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/init.sh +++ b/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/init.sh @@ -39,8 +39,6 @@ echo ${DATABASEURL} >/etc/cta/cta_catalogue_db.conf if [ "$KEEP_DATABASE" == "0" ]; then echo "Wiping database" - cta-catalogue-schema-unlock /etc/cta/cta_catalogue_db.conf - cta-catalogue-schema-status /etc/cta/cta_catalogue_db.conf echo yes | cta-catalogue-schema-drop /etc/cta/cta_catalogue_db.conf if [ "$DATABASETYPE" == "sqlite" ]; then diff --git a/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/mkSymlinks.sh b/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/mkSymlinks.sh index 09bc2186eb..1aabd39bba 100755 --- a/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/mkSymlinks.sh +++ b/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/mkSymlinks.sh @@ -8,13 +8,10 @@ echo Creating symlinks for CTA binaries and symlinks. ln -s -v -t /usr/bin \ ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/catalogue/cta-catalogue-admin-host-create \ - ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/catalogue/cta-catalogue-schema-lock \ - ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/catalogue/cta-catalogue-schema-status \ ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/catalogue/cta-database-poll \ ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/catalogue/cta-catalogue-admin-user-create \ ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/catalogue/cta-catalogue-schema-create \ ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/catalogue/cta-catalogue-schema-drop \ - ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/catalogue/cta-catalogue-schema-unlock \ ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/cmdline/cta \ ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/objectstore/dumpObject \ ${BUILDTREE_BASE}/${BUILDTREE_SUBDIR}/objectstore/listObjectStore \ diff --git a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh index f707f79d7b..6a9143eae8 100755 --- a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh +++ b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh @@ -47,8 +47,6 @@ echo ${DATABASEURL} >/etc/cta/cta_catalogue_db.conf if [ "$KEEP_DATABASE" == "0" ]; then echo "Wiping database" - cta-catalogue-schema-unlock /etc/cta/cta_catalogue_db.conf - cta-catalogue-schema-status /etc/cta/cta_catalogue_db.conf echo yes | cta-catalogue-schema-drop /etc/cta/cta_catalogue_db.conf if [ "$DATABASETYPE" == "sqlite" ]; then diff --git a/cta.spec.in b/cta.spec.in index 6ed5fa76f2..7b82a1412f 100644 --- a/cta.spec.in +++ b/cta.spec.in @@ -248,17 +248,11 @@ Scripts and utilities to faciliate working with the CTA catalogue %attr(0755,root,root) %{_bindir}/cta-catalogue-admin-host-create %attr(0755,root,root) %{_bindir}/cta-catalogue-schema-create %attr(0755,root,root) %{_bindir}/cta-catalogue-schema-drop -%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-lock -%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-status -%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-unlock %attr(0755,root,root) %{_bindir}/cta-database-poll %attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-admin-host-create.1cta.gz %attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-admin-user-create.1cta.gz %attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-schema-create.1cta.gz %attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-schema-drop.1cta.gz -%attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-schema-lock.1cta.gz -%attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-schema-status.1cta.gz -%attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-schema-unlock.1cta.gz %attr(0644,root,bin) %doc /usr/share/man/man1/cta-database-poll.1cta.gz %package -n cta-mediachangerutils diff --git a/rdbms/OcciConn.cpp b/rdbms/OcciConn.cpp index 0bbccfd95f..99172a7e06 100644 --- a/rdbms/OcciConn.cpp +++ b/rdbms/OcciConn.cpp @@ -150,6 +150,31 @@ std::list<std::string> OcciConn::getTableNames() { } } +//------------------------------------------------------------------------------ +// getSequenceNames +//------------------------------------------------------------------------------ +std::list<std::string> OcciConn::getSequenceNames() { + try { + std::list<std::string> names; + const char *const sql = + "SELECT " + "SEQUENCE_NAME " + "FROM " + "USER_SEQUENCES " + "ORDER BY " + "SEQUENCE_NAME"; + auto stmt = createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); + auto rset = stmt->executeQuery(); + while (rset->next()) { + names.push_back(rset->columnString("SEQUENCE_NAME")); + } + + return names; + } catch(exception::Exception &ex) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); + } +} + //------------------------------------------------------------------------------ // isOpen //------------------------------------------------------------------------------ diff --git a/rdbms/OcciConn.hpp b/rdbms/OcciConn.hpp index 72cb1026e8..3b65e0c7b2 100644 --- a/rdbms/OcciConn.hpp +++ b/rdbms/OcciConn.hpp @@ -92,6 +92,15 @@ public: */ bool isOpen() const override; + /** + * Returns the names of all the sequences in the database schema in + * alphabetical order. + * + * @return The names of all the sequences in the database schema in + * alphabetical order. + */ + std::list<std::string> getSequenceNames(); + private: friend OcciStmt; -- GitLab