Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
1f85d70e
Commit
1f85d70e
authored
Feb 04, 2020
by
Cedric CAFFY
Browse files
Added cta-statistics-save command line tool
parent
762a76b7
Changes
9
Hide whitespace changes
Inline
Side-by-side
cta.spec.in
View file @
1f85d70e
...
...
@@ -222,6 +222,7 @@ The shared libraries
%{_libdir}/libctardbms.so*
%{_libdir}/libctardbmswrapper.so*
%{_libdir}/libctadisk.so*
%{_libdir}/libctastatistics.so*
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cta/cta-catalogue.conf.example
#CTA-lib installs libraries so we need ldconfig.
...
...
@@ -319,6 +320,7 @@ Scripts and utilities to faciliate working with the CTA catalogue
%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(0755,root,root) %{_bindir}/cta-statistics-update
%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
...
...
statistics/CMakeLists.txt
View file @
1f85d70e
...
...
@@ -23,9 +23,6 @@ include_directories (${ORACLE-INSTANTCLIENT_INCLUDE_DIRS})
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wshadow"
)
set
(
STATISTICS_LIB_SRC_FILES
StatisticsSaveCmd.cpp
StatisticsSaveCmdLineArgs.cpp
StatisticsSaveCmdMain.cpp
StatisticsSchema.cpp
)
...
...
@@ -80,4 +77,17 @@ target_link_libraries (cta-statistics-save ctastatistics ctacatalogue ctaschemac
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-save DESTINATION /usr/bin
)
\ No newline at end of file
install
(
TARGETS cta-statistics-save DESTINATION /usr/bin
)
add_executable
(
cta-statistics-update
StatisticsUpdateCmd.cpp
StatisticsUpdateCmdLineArgs.cpp
StatisticsUpdateCmdMain.cpp
)
target_link_libraries
(
cta-statistics-update ctacatalogue ctaschemachecker
)
set_property
(
TARGET cta-statistics-update APPEND PROPERTY INSTALL_RPATH
${
PROTOBUF3_RPATH
}
)
set_property
(
TARGET cta-statistics-update APPEND PROPERTY INSTALL_RPATH
${
ORACLE-INSTANTCLIENT_RPATH
}
)
install
(
TARGETS cta-statistics-update DESTINATION /usr/bin
)
\ No newline at end of file
statistics/StatisticsSaveCmd.cpp
View file @
1f85d70e
...
...
@@ -105,5 +105,5 @@ void StatisticsSaveCmd::printUsage(std::ostream &os) {
}
}
// namespace
catalogue
}
// namespace
statistics
}
// namespace cta
statistics/StatisticsSaveCmd.hpp
View file @
1f85d70e
...
...
@@ -46,8 +46,6 @@ public:
* Destructor.
*/
~
StatisticsSaveCmd
()
noexcept
;
enum
class
VerifyStatus
{
OK
,
INFO
,
ERROR
,
UNKNOWN
};
private:
...
...
statistics/StatisticsUpdateCmd.cpp
0 → 100644
View file @
1f85d70e
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2019 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
"rdbms/ConnPool.hpp"
#include
"rdbms/AutocommitMode.hpp"
#include
"statistics/StatisticsUpdateCmd.hpp"
#include
"catalogue/SchemaChecker.hpp"
#include
"statistics/StatisticsUpdateCmdLineArgs.hpp"
namespace
cta
{
namespace
statistics
{
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
StatisticsUpdateCmd
::
StatisticsUpdateCmd
(
std
::
istream
&
inStream
,
std
::
ostream
&
outStream
,
std
::
ostream
&
errStream
)
:
CmdLineTool
(
inStream
,
outStream
,
errStream
)
{
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
StatisticsUpdateCmd
::~
StatisticsUpdateCmd
()
noexcept
{
}
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
int
StatisticsUpdateCmd
::
exceptionThrowingMain
(
const
int
argc
,
char
*
const
*
const
argv
)
{
using
namespace
cta
::
catalogue
;
const
StatisticsUpdateCmdLineArgs
cmdLineArgs
(
argc
,
argv
);
if
(
cmdLineArgs
.
help
)
{
printUsage
(
m_out
);
return
0
;
}
const
uint64_t
maxNbConns
=
1
;
auto
loginCatalogue
=
rdbms
::
Login
::
parseFile
(
cmdLineArgs
.
catalogueDbConfigPath
);
rdbms
::
ConnPool
catalogueConnPool
(
loginCatalogue
,
maxNbConns
);
auto
catalogueConn
=
catalogueConnPool
.
getConn
();
/*auto loginStatistics = rdbms::Login::parseFile(cmdLineArgs.statisticsDbConfigPath);
rdbms::ConnPool statisticsConnPool(loginStatistics, maxNbConns);
auto statisticsConn = statisticsConnPool.getConn();*/
SchemaChecker
::
Builder
catalogueCheckerBuilder
(
"catalogue"
,
loginCatalogue
.
dbType
,
catalogueConn
);
std
::
unique_ptr
<
cta
::
catalogue
::
SchemaChecker
>
catalogueChecker
;
catalogueChecker
=
catalogueCheckerBuilder
.
build
();
SchemaChecker
::
Status
tapeTableStatus
=
catalogueChecker
->
checkTableContainsColumns
(
"TAPE"
,{
"VID"
});
SchemaChecker
::
Status
tapeFileTableStatus
=
catalogueChecker
->
checkTableContainsColumns
(
"TAPE_FILE"
,{
"ARCHIVE_FILE_ID"
});
SchemaChecker
::
Status
archiveFileTableStatus
=
catalogueChecker
->
checkTableContainsColumns
(
"ARCHIVE_FILE"
,{
"SIZE_IN_BYTES"
});
if
(
tapeTableStatus
==
SchemaChecker
::
Status
::
FAILURE
||
tapeFileTableStatus
==
SchemaChecker
::
Status
::
FAILURE
||
archiveFileTableStatus
==
SchemaChecker
::
Status
::
FAILURE
){
return
EXIT_FAILURE
;
}
/*SchemaChecker::Builder statisticsCheckerBuilder("statistics",loginStatistics.dbType,statisticsConn);
cta::statistics::MysqlStatisticsSchema mysqlSchema;
std::unique_ptr<SchemaChecker> statisticsChecker =
statisticsCheckerBuilder.useCppSchemaStatementsReader(mysqlSchema)
.useSQLiteSchemaComparer()
.build();
statisticsChecker->compareTablesLocatedInSchema();*/
return
EXIT_SUCCESS
;
}
//------------------------------------------------------------------------------
// printUsage
//------------------------------------------------------------------------------
void
StatisticsUpdateCmd
::
printUsage
(
std
::
ostream
&
os
)
{
StatisticsUpdateCmd
::
printUsage
(
os
);
}
}
// namespace statistics
}
// namespace cta
statistics/StatisticsUpdateCmd.hpp
0 → 100644
View file @
1f85d70e
/*
* 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"
#include
"catalogue/CatalogueSchema.hpp"
#include
"rdbms/Conn.hpp"
#include
"rdbms/Login.hpp"
#include
"StatisticsUpdateCmdLineArgs.hpp"
namespace
cta
{
namespace
statistics
{
/**
* Command-line tool for verifying the catalogue schema.
*/
class
StatisticsUpdateCmd
:
public
cta
::
catalogue
::
CmdLineTool
{
public:
/**
* Constructor.
*
* @param inStream Standard input stream.
* @param outStream Standard output stream.
* @param errStream Standard error stream.
*/
StatisticsUpdateCmd
(
std
::
istream
&
inStream
,
std
::
ostream
&
outStream
,
std
::
ostream
&
errStream
);
/**
* Destructor.
*/
~
StatisticsUpdateCmd
()
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
;
/**
* Returns true if the table with the specified name exists in the database
* schema of the specified database connection.
*
* @param tableName The name of the database table.
* @param conn The database connection.
* @return True if the table exists.
*/
bool
tableExists
(
const
std
::
string
tableName
,
rdbms
::
Conn
&
conn
)
const
;
};
// class VerifySchemaCmd
}
// namespace statistics
}
// namespace cta
statistics/StatisticsUpdateCmdLineArgs.cpp
0 → 100644
View file @
1f85d70e
/*
* 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
"StatisticsUpdateCmdLineArgs.hpp"
#include
"common/exception/CommandLineNotParsed.hpp"
#include
<getopt.h>
#include
<ostream>
namespace
cta
{
namespace
statistics
{
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
StatisticsUpdateCmdLineArgs
::
StatisticsUpdateCmdLineArgs
(
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
)
optopt
<<
" 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: expected=1 actual="
<<
nbArgs
;
throw
ex
;
}
catalogueDbConfigPath
=
argv
[
optind
];
}
//------------------------------------------------------------------------------
// printUsage
//------------------------------------------------------------------------------
void
StatisticsUpdateCmdLineArgs
::
printUsage
(
std
::
ostream
&
os
)
{
os
<<
"Usage:"
<<
std
::
endl
<<
" cta-statistics-update databaseConnectionFile [options]"
<<
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 statistics
}
// namespace cta
statistics/StatisticsUpdateCmdLineArgs.hpp
0 → 100644
View file @
1f85d70e
/*
* 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
statistics
{
/**
* Structure to store the command-line arguments of the command-line tool
* named cta-statistics-update.
*/
struct
StatisticsUpdateCmdLineArgs
{
/**
* True if the usage message should be printed.
*/
bool
help
;
/**
* Path to the file containing the connection details of the catalogue
* database.
*/
std
::
string
catalogueDbConfigPath
;
/**
* 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.
*/
StatisticsUpdateCmdLineArgs
(
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 statistics
}
// namespace cta
statistics/StatisticsUpdateCmdMain.cpp
0 → 100644
View file @
1f85d70e
/*
* 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
"StatisticsUpdateCmd.hpp"
#include
<iostream>
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int
main
(
const
int
argc
,
char
*
const
*
const
argv
)
{
cta
::
statistics
::
StatisticsUpdateCmd
cmd
(
std
::
cin
,
std
::
cout
,
std
::
cerr
);
return
cmd
.
main
(
argc
,
argv
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment