Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
a667875d
Commit
a667875d
authored
5 years ago
by
Cedric CAFFY
Committed by
Cedric Caffy
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
cta-statistics-save --drop will delete all the tables that are located in its creation schema
parent
0f51c041
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
statistics/StatisticsSaveCmd.cpp
+20
-21
20 additions, 21 deletions
statistics/StatisticsSaveCmd.cpp
statistics/StatisticsSaveCmd.hpp
+20
-10
20 additions, 10 deletions
statistics/StatisticsSaveCmd.hpp
with
40 additions
and
31 deletions
statistics/StatisticsSaveCmd.cpp
+
20
−
21
View file @
a667875d
...
...
@@ -62,17 +62,22 @@ int StatisticsSaveCmd::exceptionThrowingMain(const int argc, char *const *const
auto
statisticsSchema
=
StatisticsSchemaFactory
::
create
(
loginStatistics
.
dbType
);
if
(
cmdLineArgs
.
buildDatabase
){
//Build the database
buildStatisticsDatabase
(
statisticsConn
,
*
statisticsSchema
);
return
EXIT_SUCCESS
;
}
if
(
cmdLineArgs
.
dropDatabase
){
//drop the database
if
(
userConfirmDropStatisticsSchemaFromDb
(
loginStatistics
)){
dropStatisticsDatabase
(
statisticsConn
);
dropStatisticsDatabase
(
statisticsConn
,
*
statisticsSchema
);
}
return
EXIT_SUCCESS
;
}
//Save the CTA statistics
//Check the content of the CTA catalogue
auto
loginCatalogue
=
rdbms
::
Login
::
parseFile
(
cmdLineArgs
.
catalogueDbConfigPath
);
rdbms
::
ConnPool
catalogueConnPool
(
loginCatalogue
,
maxNbConns
);
auto
catalogueConn
=
catalogueConnPool
.
getConn
();
...
...
@@ -87,6 +92,7 @@ int StatisticsSaveCmd::exceptionThrowingMain(const int argc, char *const *const
return
EXIT_FAILURE
;
}
//Check that the schema tables are in the statistics database
SchemaChecker
::
Builder
statisticsCheckerBuilder
(
"statistics"
,
loginStatistics
.
dbType
,
statisticsConn
);
std
::
unique_ptr
<
SchemaChecker
>
statisticsChecker
=
statisticsCheckerBuilder
.
useCppSchemaStatementsReader
(
*
statisticsSchema
)
...
...
@@ -94,20 +100,10 @@ int StatisticsSaveCmd::exceptionThrowingMain(const int argc, char *const *const
.
build
();
statisticsChecker
->
compareTablesLocatedInSchema
();
//Compute the statistics
return
EXIT_SUCCESS
;
}
//------------------------------------------------------------------------------
// tableExists
//------------------------------------------------------------------------------
bool
StatisticsSaveCmd
::
tableExists
(
const
std
::
string
tableName
,
rdbms
::
Conn
&
conn
)
const
{
const
auto
names
=
conn
.
getTableNames
();
for
(
const
auto
&
name
:
names
)
{
if
(
tableName
==
name
)
{
return
true
;
}
}
return
false
;
}
//------------------------------------------------------------------------------
// printUsage
...
...
@@ -117,21 +113,24 @@ void StatisticsSaveCmd::printUsage(std::ostream &os) {
}
void
StatisticsSaveCmd
::
verifyCmdLineArgs
(
const
StatisticsSaveCmdLineArgs
&
cmdLineArgs
)
const
{
bool
catalogueDbConfigPathEmpty
=
cmdLineArgs
.
catalogueDbConfigPath
.
empty
();
bool
statisticsDbConfigPathEmpty
=
cmdLineArgs
.
statisticsDbConfigPath
.
empty
();
if
(
cmdLineArgs
.
buildDatabase
&&
cmdLineArgs
.
dropDatabase
){
throw
cta
::
exception
::
Exception
(
"--build and --drop are mutually exclusive."
);
}
if
(
cmdLineArgs
.
buildDatabase
&&
!
cmdLineArgs
.
catalogueDbConfigPath
.
e
mpty
()
){
if
(
cmdLineArgs
.
buildDatabase
&&
!
catalogueDbConfigPath
E
mpty
){
throw
cta
::
exception
::
Exception
(
"The catalogue database configuration file should not be provided when --build flag is set."
);
}
if
(
cmdLineArgs
.
dropDatabase
&&
!
cmdLineArgs
.
catalogueDbConfigPath
.
e
mpty
()
){
if
(
cmdLineArgs
.
dropDatabase
&&
!
catalogueDbConfigPath
E
mpty
){
throw
cta
::
exception
::
Exception
(
"The catalogue database configuration file should not be provided when --drop flag is set."
);
}
if
(
cmdLineArgs
.
buildDatabase
&&
cmdLineArgs
.
statisticsDbConfigPath
.
empty
()){
throw
cta
::
exception
::
Exception
(
"The statistics database configuration file should be provided."
);
}
if
(
cmdLineArgs
.
dropDatabase
&&
cmdLineArgs
.
statisticsDbConfigPath
.
empty
()){
if
(
statisticsDbConfigPathEmpty
&&
(
cmdLineArgs
.
buildDatabase
||
cmdLineArgs
.
dropDatabase
)){
throw
cta
::
exception
::
Exception
(
"The statistics database configuration file should be provided."
);
}
if
((
!
cmdLineArgs
.
buildDatabase
&&
!
cmdLineArgs
.
dropDatabase
)
&&
(
catalogueDbConfigPathEmpty
||
statisticsDbConfigPathEmpty
)){
throw
cta
::
exception
::
Exception
(
"You should provide the catalogue database and the statistics database connection files."
);
}
}
void
StatisticsSaveCmd
::
buildStatisticsDatabase
(
cta
::
rdbms
::
Conn
&
statisticsDatabaseConn
,
const
StatisticsSchema
&
statisticsSchema
)
{
...
...
@@ -152,10 +151,10 @@ bool StatisticsSaveCmd::userConfirmDropStatisticsSchemaFromDb(const rdbms::Login
return
userResponse
==
"yes"
;
}
void
StatisticsSaveCmd
::
dropStatisticsDatabase
(
cta
::
rdbms
::
Conn
&
statisticsDatabaseConn
)
{
void
StatisticsSaveCmd
::
dropStatisticsDatabase
(
cta
::
rdbms
::
Conn
&
statisticsDatabaseConn
,
const
StatisticsSchema
&
statisticsSchema
)
{
try
{
std
::
list
<
std
::
string
>
tablesInDb
=
statisticsDatabaseConn
.
getTableNames
();
std
::
list
<
std
::
string
>
statisticsTables
=
{
"CTA_STATISTICS"
}
;
std
::
list
<
std
::
string
>
statisticsTables
=
statisticsSchema
.
getSchemaTableNames
()
;
for
(
auto
&
tableToDrop
:
statisticsTables
){
const
bool
tableToDropIsInDb
=
(
tablesInDb
.
end
()
!=
std
::
find
(
tablesInDb
.
begin
(),
tablesInDb
.
end
(),
tableToDrop
));
if
(
tableToDropIsInDb
)
{
...
...
This diff is collapsed.
Click to expand it.
statistics/StatisticsSaveCmd.hpp
+
20
−
10
View file @
a667875d
...
...
@@ -65,24 +65,34 @@ private:
* @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.
* Verifies the user input
* throws an exception if the command line args
* are not correct
* @param cmdLineArgs the command line arguments provided by the user
*/
bool
tableExists
(
const
std
::
string
tableName
,
rdbms
::
Conn
&
conn
)
const
;
void
verifyCmdLineArgs
(
const
StatisticsSaveCmdLineArgs
&
cmdLineArgs
)
const
;
/**
* Create the tables needed to fill the CTA statistics database
* @param statisticsDatabaseConn the database where the CTA statistics will be stored
* @param statisticsSchema the schema that will be used to insert the CTA statistics tables
*/
void
buildStatisticsDatabase
(
cta
::
rdbms
::
Conn
&
statisticsDatabaseConn
,
const
StatisticsSchema
&
statisticsSchema
);
/**
* Asks the user if he really wants to drop the CTA statistics tables from the database
* @param dbLogin the CTA statistics database
* @return true if the user confirmed, false otherwise
*/
bool
userConfirmDropStatisticsSchemaFromDb
(
const
rdbms
::
Login
&
dbLogin
);
void
dropStatisticsDatabase
(
cta
::
rdbms
::
Conn
&
statisticsDatabaseConn
);
/**
* Drop the tables associated to the CTA statistics
* @param statisticsDatabaseConn the database where the CTA statistics tables will be deleted
*/
void
dropStatisticsDatabase
(
cta
::
rdbms
::
Conn
&
statisticsDatabaseConn
,
const
StatisticsSchema
&
statisticsSchema
);
};
// class VerifySchemaCmd
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment