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
7e5e51dd
Commit
7e5e51dd
authored
Dec 02, 2016
by
Steven Murray
Browse files
Added cta-database-poll for testing and debugging
parent
1434d52a
Changes
8
Hide whitespace changes
Inline
Side-by-side
catalogue/CMakeLists.txt
View file @
7e5e51dd
...
...
@@ -181,3 +181,14 @@ target_link_libraries (cta-catalogue-schema-drop
install
(
TARGETS cta-catalogue-schema-drop DESTINATION /usr/bin
)
install
(
FILES
${
CMAKE_CURRENT_SOURCE_DIR
}
/cta-catalogue-schema-drop.1cta DESTINATION /usr/share/man/man1
)
add_executable
(
cta-database-poll
PollDatabaseCmd.cpp
PollDatabaseCmdLineArgs.cpp
PollDatabaseCmdMain.cpp
)
target_link_libraries
(
cta-database-poll
ctacatalogue
)
install
(
TARGETS cta-database-poll DESTINATION /usr/bin
)
install
(
FILES
${
CMAKE_CURRENT_SOURCE_DIR
}
/cta-database-poll.1cta DESTINATION /usr/share/man/man1
)
catalogue/PollDatabaseCmd.cpp
0 → 100644
View file @
7e5e51dd
/*
* 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/PollDatabaseCmd.hpp"
#include
"catalogue/PollDatabaseCmdLineArgs.hpp"
#include
"rdbms/ConnFactoryFactory.hpp"
#include
<unistd.h>
namespace
cta
{
namespace
catalogue
{
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
PollDatabaseCmd
::
PollDatabaseCmd
(
std
::
istream
&
inStream
,
std
::
ostream
&
outStream
,
std
::
ostream
&
errStream
)
:
CmdLineTool
(
inStream
,
outStream
,
errStream
)
{
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
PollDatabaseCmd
::~
PollDatabaseCmd
()
noexcept
{
}
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
int
PollDatabaseCmd
::
exceptionThrowingMain
(
const
int
argc
,
char
*
const
*
const
argv
)
{
const
PollDatabaseCmdLineArgs
cmdLineArgs
(
argc
,
argv
);
const
auto
dbLogin
=
rdbms
::
Login
::
parseFile
(
cmdLineArgs
.
dbConfigPath
);
auto
factory
=
rdbms
::
ConnFactoryFactory
::
create
(
dbLogin
);
auto
conn
=
factory
->
create
();
uint32_t
elapsedSeconds
=
0
;
for
(
uint32_t
i
=
0
;
i
<
cmdLineArgs
.
numberOfSecondsToKeepPolling
;
i
++
)
{
m_out
<<
"Querying the database"
<<
std
::
endl
;
try
{
conn
->
getTableNames
();
}
catch
(
exception
::
Exception
&
ex
)
{
m_out
<<
"Database error: "
<<
ex
.
getMessage
().
str
()
<<
std
::
endl
;
}
m_out
<<
"Sleeping for 1 second"
<<
std
::
endl
;
elapsedSeconds
++
;
m_out
<<
"Elapsed seconds = "
<<
elapsedSeconds
<<
std
::
endl
;
sleep
(
1
);
}
return
0
;
}
}
// namespace catalogue
}
// namespace cta
catalogue/PollDatabaseCmd.hpp
0 → 100644
View file @
7e5e51dd
/*
* 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 that simply polls the database with a simple SQL SELECT
* statement.
*
* The purpose of this tool is to faciliate the development and testing of the
* reconnect logic of CTA database connections. The database server is
* configured to break some connections. If the reconnect logic is working
* correctly then the polling loop of this command should trigger automatic
* and successfull reconnects.
*/
class
PollDatabaseCmd
:
public
CmdLineTool
{
public:
/**
* Constructor.
*
* @param inStream Standard input stream.
* @param outStream Standard output stream.
* @param errStream Standard error stream.
*/
PollDatabaseCmd
(
std
::
istream
&
inStream
,
std
::
ostream
&
outStream
,
std
::
ostream
&
errStream
);
/**
* Destructor.
*/
~
PollDatabaseCmd
()
noexcept
;
/**
* 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
);
};
// class PollDatabaseCmd
}
// namespace catalogue
}
// namespace cta
catalogue/PollDatabaseCmdLineArgs.cpp
0 → 100644
View file @
7e5e51dd
/*
* 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/PollDatabaseCmdLineArgs.hpp"
#include
"common/exception/Exception.hpp"
#include
"common/utils/utils.hpp"
#include
<ostream>
namespace
cta
{
namespace
catalogue
{
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
PollDatabaseCmdLineArgs
::
PollDatabaseCmdLineArgs
(
const
int
argc
,
const
char
*
const
*
const
argv
)
{
if
(
argc
!=
3
)
{
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Wrong number of command-line arguments: excepted=2 actual="
<<
(
argc
-
1
)
<<
std
::
endl
<<
std
::
endl
;
printUsage
(
ex
.
getMessage
());
throw
ex
;
}
numberOfSecondsToKeepPolling
=
utils
::
toUint64
(
argv
[
1
]);
dbConfigPath
=
argv
[
2
];
}
//------------------------------------------------------------------------------
// printUsage
//------------------------------------------------------------------------------
void
PollDatabaseCmdLineArgs
::
printUsage
(
std
::
ostream
&
os
)
{
os
<<
"Usage:"
<<
std
::
endl
<<
" cta-database-poll numberOfSecondsToKeepPolling databaseConnectionFile"
<<
std
::
endl
<<
"Where:"
<<
std
::
endl
<<
" numberOfSecondsToKeepPolling"
<<
std
::
endl
<<
" The total number of seconds cta-database-poll should run before"
<<
std
::
endl
<<
" exiting."
<<
std
::
endl
<<
" databaseConnectionFile"
<<
std
::
endl
<<
" The path to the file containing the connection details of the CTA"
<<
std
::
endl
<<
" catalogue database."
<<
std
::
endl
;
}
}
// namespace catalogue
}
// namespace cta
catalogue/PollDatabaseCmdLineArgs.hpp
0 → 100644
View file @
7e5e51dd
/*
* 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
<stdint.h>
#include
<string>
namespace
cta
{
namespace
catalogue
{
/**
* Structure to store the command-line arguments of the command-line tool
* named cta-database-poll.
*/
struct
PollDatabaseCmdLineArgs
{
/**
* The total number of seconds the cta-database-pollshould run before exiting.
*/
uint64_t
numberOfSecondsToKeepPolling
;
/**
* 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.
*/
PollDatabaseCmdLineArgs
(
const
int
argc
,
const
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
catalogue/PollDatabaseCmdMain.cpp
0 → 100644
View file @
7e5e51dd
/*
* 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/PollDatabaseCmd.hpp"
#include
"common/exception/Exception.hpp"
#include
<iostream>
/**
* 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.
*/
static
int
exceptionThrowingMain
(
const
int
argc
,
char
*
const
*
const
argv
);
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int
main
(
const
int
argc
,
char
*
const
*
const
argv
)
{
using
namespace
cta
;
std
::
string
errorMessage
;
try
{
return
exceptionThrowingMain
(
argc
,
argv
);
}
catch
(
exception
::
Exception
&
ex
)
{
errorMessage
=
ex
.
getMessage
().
str
();
}
catch
(
std
::
exception
&
se
)
{
errorMessage
=
se
.
what
();
}
catch
(...)
{
errorMessage
=
"An unknown exception was thrown"
;
}
// Reaching this point means the command has failed, an exception was throw
// and errorMessage has been set accordingly
std
::
cerr
<<
"Aborting: "
<<
errorMessage
<<
std
::
endl
;
return
1
;
}
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
static
int
exceptionThrowingMain
(
const
int
argc
,
char
*
const
*
const
argv
)
{
using
namespace
cta
;
catalogue
::
PollDatabaseCmd
cmd
(
std
::
cin
,
std
::
cout
,
std
::
cerr
);
return
cmd
.
exceptionThrowingMain
(
argc
,
argv
);
}
catalogue/cta-database-poll.1cta
0 → 100644
View file @
7e5e51dd
.\" 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-DATABASE-POLL 1CTA "December 2016" CTA CTA
.SH NAME
cta-database-poll \- Polls the specified database every second
.SH SYNOPSIS
.BI "cta-database-poll numberOfSecondsToKeepPolling databaseConnectionFile"
.SH DESCRIPTION
\fBcta-database-poll\fP is a command-line tool that polls the specified database
every second for the specified total number of seconds.
.SH ARGUMENTS
.TP
\fBnumberOfSecondsToKeepPolling
The total number of seconds cta-database-poll should run before exiting.
.TP
\fBdatabaseConnectionFile
The path to the configuration file containing the connection details of the
CTA catalogue database.
.SH RETURN VALUE
Zero on success and non-zero on failure.
.SH EXAMPLES
cta-database-poll 5 /etc/cta/cta_catalogue_db.conf
.SH AUTHOR
\fBCTA\fP Team
cta.spec.in
View file @
7e5e51dd
...
...
@@ -228,12 +228,14 @@ Scripts and utilities to faciliate working with the CTA catalogue
%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-delete-all-data.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
Summary: Utilities to faciliate working with mediachangers
...
...
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