Skip to content
Snippets Groups Projects
Commit c210458c authored by Cedric CAFFY's avatar Cedric CAFFY
Browse files

Renamed StatisticsCmd in StatisticsSaveCmd

Added the enty in the cta.spec.in
parent 6dcd624b
No related branches found
No related tags found
No related merge requests found
......@@ -318,6 +318,7 @@ Scripts and utilities to faciliate working with the CTA catalogue
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-drop
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-verify
%attr(0755,root,root) %{_bindir}/cta-database-poll
%attr(0755,root,root) %{_bindir}/cta-statistics-save
%attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-admin-user-create.1cta.gz
%attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-schema-create.1cta.gz
%attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-schema-drop.1cta.gz
......
......@@ -23,9 +23,9 @@ include_directories (${ORACLE-INSTANTCLIENT_INCLUDE_DIRS})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
set (STATISTICS_LIB_SRC_FILES
StatisticsCmd.cpp
StatisticsCmdLineArgs.cpp
StatisticsCmdMain.cpp
StatisticsSaveCmd.cpp
StatisticsSaveCmdLineArgs.cpp
StatisticsSaveCmdMain.cpp
StatisticsSchema.cpp
)
......@@ -68,27 +68,16 @@ install (FILES ${CMAKE_SOURCE_DIR}/catalogue/cta-catalogue.conf.example
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/cta
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
add_executable(cta-statistics
StatisticsCmd.cpp
StatisticsCmdLineArgs.cpp
StatisticsCmdMain.cpp
add_executable(cta-statistics-save
StatisticsSaveCmd.cpp
StatisticsSaveCmdLineArgs.cpp
StatisticsSaveCmdMain.cpp
MysqlStatisticsSchema.cpp
)
target_link_libraries (cta-statistics ctastatistics ctacatalogue ctaschemachecker)
target_link_libraries (cta-statistics-save ctastatistics ctacatalogue ctaschemachecker)
set_property(TARGET cta-statistics APPEND PROPERTY INSTALL_RPATH ${PROTOBUF3_RPATH})
set_property(TARGET cta-catalogue-schema-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
set_property(TARGET cta-statistics-save APPEND PROPERTY INSTALL_RPATH ${PROTOBUF3_RPATH})
set_property(TARGET cta-statistics-save APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-statistics DESTINATION /usr/bin)
set (STATISTICS_CMD_LINE_UNIT_TESTS_LIB_SRC_FILES
StatisticsCmdLineArgsTest.cpp
)
add_library (ctastatisticscmdlineunittests SHARED
${STATISTICS_CMD_LINE_UNIT_TESTS_LIB_SRC_FILES})
set_property(TARGET ctastatisticscmdlineunittests PROPERTY SOVERSION "${CTA_SOVERSION}")
set_property(TARGET ctastatisticscmdlineunittests PROPERTY VERSION "${CTA_LIBVERSION}")
install (TARGETS ctastatisticscmdlineunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
install (TARGETS cta-statistics-save DESTINATION /usr/bin)
\ No newline at end of file
/*
* 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/VerifySchemaCmdLineArgs.hpp"
#include <gtest/gtest.h>
#include <list>
namespace unitTests {
class cta_catalogue_VerifySchemaCmdLineArgsTest : 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_VerifySchemaCmdLineArgsTest, 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-verify");
args->argv[1] = dupString("-h");
args->argv[2] = NULL;
VerifySchemaCmdLineArgs cmdLine(args->argc, args->argv);
ASSERT_TRUE(cmdLine.help);
ASSERT_TRUE(cmdLine.dbConfigPath.empty());
}
TEST_F(cta_catalogue_VerifySchemaCmdLineArgsTest, 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-verify");
args->argv[1] = dupString("--help");
args->argv[2] = NULL;
VerifySchemaCmdLineArgs cmdLine(args->argc, args->argv);
ASSERT_TRUE(cmdLine.help);
ASSERT_TRUE(cmdLine.dbConfigPath.empty());
}
TEST_F(cta_catalogue_VerifySchemaCmdLineArgsTest, 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-verify");
args->argv[1] = dupString("dbConfigPath");
args->argv[2] = NULL;
VerifySchemaCmdLineArgs cmdLine(args->argc, args->argv);
ASSERT_FALSE(cmdLine.help);
ASSERT_EQ(std::string("dbConfigPath"), cmdLine.dbConfigPath);
}
} // namespace unitTests
......@@ -18,7 +18,7 @@
#include "rdbms/ConnPool.hpp"
#include "rdbms/AutocommitMode.hpp"
#include "StatisticsCmd.hpp"
#include "StatisticsSaveCmd.hpp"
#include "StatisticsSchema.hpp"
#include "catalogue/SchemaChecker.hpp"
#include "MysqlStatisticsSchema.hpp"
......@@ -30,22 +30,22 @@ namespace statistics {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
StatisticsCmd::StatisticsCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream):
StatisticsSaveCmd::StatisticsSaveCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream):
CmdLineTool(inStream, outStream, errStream) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
StatisticsCmd::~StatisticsCmd() noexcept {
StatisticsSaveCmd::~StatisticsSaveCmd() noexcept {
}
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
int StatisticsCmd::exceptionThrowingMain(const int argc, char *const *const argv) {
int StatisticsSaveCmd::exceptionThrowingMain(const int argc, char *const *const argv) {
using namespace cta::catalogue;
const StatisticsCmdLineArgs cmdLineArgs(argc, argv);
const StatisticsSaveCmdLineArgs cmdLineArgs(argc, argv);
if(cmdLineArgs.help) {
printUsage(m_out);
......@@ -87,7 +87,7 @@ int StatisticsCmd::exceptionThrowingMain(const int argc, char *const *const argv
//------------------------------------------------------------------------------
// tableExists
//------------------------------------------------------------------------------
bool StatisticsCmd::tableExists(const std::string tableName, rdbms::Conn &conn) const {
bool StatisticsSaveCmd::tableExists(const std::string tableName, rdbms::Conn &conn) const {
const auto names = conn.getTableNames();
for(const auto &name : names) {
if(tableName == name) {
......@@ -100,8 +100,8 @@ bool StatisticsCmd::tableExists(const std::string tableName, rdbms::Conn &conn)
//------------------------------------------------------------------------------
// printUsage
//------------------------------------------------------------------------------
void StatisticsCmd::printUsage(std::ostream &os) {
StatisticsCmdLineArgs::printUsage(os);
void StatisticsSaveCmd::printUsage(std::ostream &os) {
StatisticsSaveCmdLineArgs::printUsage(os);
}
......
......@@ -22,7 +22,7 @@
#include "catalogue/CatalogueSchema.hpp"
#include "rdbms/Conn.hpp"
#include "rdbms/Login.hpp"
#include "StatisticsCmdLineArgs.hpp"
#include "StatisticsSaveCmdLineArgs.hpp"
namespace cta {
namespace statistics {
......@@ -30,7 +30,7 @@ namespace statistics {
/**
* Command-line tool for verifying the catalogue schema.
*/
class StatisticsCmd: public cta::catalogue::CmdLineTool {
class StatisticsSaveCmd: public cta::catalogue::CmdLineTool {
public:
/**
......@@ -40,12 +40,12 @@ public:
* @param outStream Standard output stream.
* @param errStream Standard error stream.
*/
StatisticsCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream);
StatisticsSaveCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream);
/**
* Destructor.
*/
~StatisticsCmd() noexcept;
~StatisticsSaveCmd() noexcept;
enum class VerifyStatus { OK, INFO, ERROR, UNKNOWN };
......
......@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StatisticsCmdLineArgs.hpp"
#include "StatisticsSaveCmdLineArgs.hpp"
#include "common/exception/CommandLineNotParsed.hpp"
#include <getopt.h>
......@@ -29,7 +29,7 @@ namespace statistics {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
StatisticsCmdLineArgs::StatisticsCmdLineArgs(const int argc, char *const *const argv):
StatisticsSaveCmdLineArgs::StatisticsSaveCmdLineArgs(const int argc, char *const *const argv):
help(false) {
static struct option longopts[] = {
......@@ -101,10 +101,10 @@ StatisticsCmdLineArgs::StatisticsCmdLineArgs(const int argc, char *const *const
//------------------------------------------------------------------------------
// printUsage
//------------------------------------------------------------------------------
void StatisticsCmdLineArgs::printUsage(std::ostream &os) {
void StatisticsSaveCmdLineArgs::printUsage(std::ostream &os) {
os <<
"Usage:" << std::endl <<
" cta-statistics --catalogueconf catalogueDbConnectionFile --statisticsconf statisticsDbConnectionFile [options]" << std::endl <<
" cta-statistics-save --catalogueconf catalogueDbConnectionFile --statisticsconf statisticsDbConnectionFile [options]" << std::endl <<
"Where:" << std::endl <<
" catalogueDbConnectionFile" << std::endl <<
" The path to the file containing the connection details of the CTA" << std::endl <<
......
......@@ -27,7 +27,7 @@ namespace statistics {
* Structure to store the command-line arguments of the command-line tool
* named cta-statistics
*/
struct StatisticsCmdLineArgs {
struct StatisticsSaveCmdLineArgs {
/**
* True if the usage message should be printed.
*/
......@@ -52,7 +52,7 @@ struct StatisticsCmdLineArgs {
* executable.
* @param argv The vector of command-line arguments.
*/
StatisticsCmdLineArgs(const int argc, char *const *const argv);
StatisticsSaveCmdLineArgs(const int argc, char *const *const argv);
/**
* Prints the usage message of the command-line tool.
......
......@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StatisticsCmd.hpp"
#include "StatisticsSaveCmd.hpp"
#include <iostream>
......@@ -24,6 +24,6 @@
// main
//------------------------------------------------------------------------------
int main(const int argc, char *const *const argv) {
cta::statistics::StatisticsCmd cmd(std::cin, std::cout, std::cerr);
cta::statistics::StatisticsSaveCmd cmd(std::cin, std::cout, std::cerr);
return cmd.main(argc, argv);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment