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
6eecfd06
Commit
6eecfd06
authored
5 years ago
by
Victor Kotlyar
Browse files
Options
Downloads
Patches
Plain Diff
Add try catch to verification procedures
parent
844d4d48
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
catalogue/VerifySchemaCmd.cpp
+109
-97
109 additions, 97 deletions
catalogue/VerifySchemaCmd.cpp
with
109 additions
and
97 deletions
catalogue/VerifySchemaCmd.cpp
+
109
−
97
View file @
6eecfd06
...
...
@@ -166,27 +166,31 @@ void VerifySchemaCmd::printUsage(std::ostream &os) {
//------------------------------------------------------------------------------
VerifySchemaCmd
::
VerifyStatus
VerifySchemaCmd
::
verifySchemaVersion
(
const
std
::
map
<
std
::
string
,
uint64_t
>
&
schemaVersion
,
const
std
::
map
<
std
::
string
,
uint64_t
>
&
schemaDbVersion
)
const
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
for
(
const
auto
&
schemaInfo
:
schemaVersion
)
{
if
(
schemaDbVersion
.
count
(
schemaInfo
.
first
))
{
if
(
schemaInfo
.
second
!=
schemaDbVersion
.
at
(
schemaInfo
.
first
))
{
std
::
cerr
<<
" ERROR: the schema version mismatch: SCHEMA["
<<
schemaInfo
.
first
<<
"] = "
<<
schemaInfo
.
second
<<
", DB["
<<
schemaInfo
.
first
<<
"] = "
<<
schemaDbVersion
.
at
(
schemaInfo
.
first
)
<<
std
::
endl
;
try
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
for
(
const
auto
&
schemaInfo
:
schemaVersion
)
{
if
(
schemaDbVersion
.
count
(
schemaInfo
.
first
))
{
if
(
schemaInfo
.
second
!=
schemaDbVersion
.
at
(
schemaInfo
.
first
))
{
std
::
cerr
<<
" ERROR: the schema version mismatch: SCHEMA["
<<
schemaInfo
.
first
<<
"] = "
<<
schemaInfo
.
second
<<
", DB["
<<
schemaInfo
.
first
<<
"] = "
<<
schemaDbVersion
.
at
(
schemaInfo
.
first
)
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
}
}
else
{
std
::
cerr
<<
" ERROR: the schema version value for "
<<
schemaInfo
.
first
<<
" not found in the Catalogue DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
}
}
else
{
std
::
cerr
<<
" ERROR: the schema version value for "
<<
schemaInfo
.
first
<<
" not found in the Catalogue DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
//------------------------------------------------------------------------------
...
...
@@ -194,30 +198,32 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifySchemaVersion(const std::ma
//------------------------------------------------------------------------------
VerifySchemaCmd
::
VerifyStatus
VerifySchemaCmd
::
verifyTableNames
(
const
std
::
list
<
std
::
string
>
&
schemaTableNames
,
const
std
::
list
<
std
::
string
>
&
dbTableNames
)
const
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
// check for schema tables
for
(
auto
&
tableName
:
schemaTableNames
)
{
const
bool
schemaTableIsNotInDb
=
dbTableNames
.
end
()
==
std
::
find
(
dbTableNames
.
begin
(),
dbTableNames
.
end
(),
tableName
);
if
(
schemaTableIsNotInDb
)
{
std
::
cerr
<<
" ERROR: the schema table "
<<
tableName
<<
" not found in the DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
try
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
for
(
auto
&
tableName
:
schemaTableNames
)
{
const
bool
schemaTableIsNotInDb
=
dbTableNames
.
end
()
==
std
::
find
(
dbTableNames
.
begin
(),
dbTableNames
.
end
(),
tableName
);
if
(
schemaTableIsNotInDb
)
{
std
::
cerr
<<
" ERROR: the schema table "
<<
tableName
<<
" not found in the DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
}
}
}
// check for extra tables in DB
for
(
auto
&
tableName
:
dbTableNames
)
{
const
bool
dbTableIsNotInSchema
=
schemaTableNames
.
end
()
==
std
::
find
(
schemaTableNames
.
begin
(),
schemaTableNames
.
end
(),
tableName
);
if
(
dbTableIsNotInSchema
)
{
std
::
cerr
<<
" INFO: the database table "
<<
tableName
<<
" not found in the schema"
<<
std
::
endl
;
if
(
VerifyStatus
::
ERROR
!=
status
)
{
status
=
VerifyStatus
::
INFO
;
for
(
auto
&
tableName
:
dbTableNames
)
{
const
bool
dbTableIsNotInSchema
=
schemaTableNames
.
end
()
==
std
::
find
(
schemaTableNames
.
begin
(),
schemaTableNames
.
end
(),
tableName
);
if
(
dbTableIsNotInSchema
)
{
std
::
cerr
<<
" INFO: the database table "
<<
tableName
<<
" not found in the schema"
<<
std
::
endl
;
if
(
VerifyStatus
::
ERROR
!=
status
)
{
status
=
VerifyStatus
::
INFO
;
}
}
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
//------------------------------------------------------------------------------
...
...
@@ -225,30 +231,32 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifyTableNames(const std::list<
//------------------------------------------------------------------------------
VerifySchemaCmd
::
VerifyStatus
VerifySchemaCmd
::
verifyIndexNames
(
const
std
::
list
<
std
::
string
>
&
schemaIndexNames
,
const
std
::
list
<
std
::
string
>
&
dbIndexNames
)
const
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
// check for schema tables
for
(
auto
&
indexName
:
schemaIndexNames
)
{
const
bool
schemaIndexIsNotInDb
=
dbIndexNames
.
end
()
==
std
::
find
(
dbIndexNames
.
begin
(),
dbIndexNames
.
end
(),
indexName
);
if
(
schemaIndexIsNotInDb
)
{
std
::
cerr
<<
" ERROR: the schema index "
<<
indexName
<<
" not found in the DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
try
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
for
(
auto
&
indexName
:
schemaIndexNames
)
{
const
bool
schemaIndexIsNotInDb
=
dbIndexNames
.
end
()
==
std
::
find
(
dbIndexNames
.
begin
(),
dbIndexNames
.
end
(),
indexName
);
if
(
schemaIndexIsNotInDb
)
{
std
::
cerr
<<
" ERROR: the schema index "
<<
indexName
<<
" not found in the DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
}
}
}
// check for extra tables in DB
for
(
auto
&
indexName
:
dbIndexNames
)
{
const
bool
dbIndexIsNotInSchema
=
schemaIndexNames
.
end
()
==
std
::
find
(
schemaIndexNames
.
begin
(),
schemaIndexNames
.
end
(),
indexName
);
if
(
dbIndexIsNotInSchema
)
{
std
::
cerr
<<
" INFO: the database index "
<<
indexName
<<
" not found in the schema"
<<
std
::
endl
;
if
(
VerifyStatus
::
ERROR
!=
status
)
{
status
=
VerifyStatus
::
INFO
;
for
(
auto
&
indexName
:
dbIndexNames
)
{
const
bool
dbIndexIsNotInSchema
=
schemaIndexNames
.
end
()
==
std
::
find
(
schemaIndexNames
.
begin
(),
schemaIndexNames
.
end
(),
indexName
);
if
(
dbIndexIsNotInSchema
)
{
std
::
cerr
<<
" INFO: the database index "
<<
indexName
<<
" not found in the schema"
<<
std
::
endl
;
if
(
VerifyStatus
::
ERROR
!=
status
)
{
status
=
VerifyStatus
::
INFO
;
}
}
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
//------------------------------------------------------------------------------
...
...
@@ -256,30 +264,32 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifyIndexNames(const std::list<
//------------------------------------------------------------------------------
VerifySchemaCmd
::
VerifyStatus
VerifySchemaCmd
::
verifySequenceNames
(
const
std
::
list
<
std
::
string
>
&
schemaSequenceNames
,
const
std
::
list
<
std
::
string
>
&
dbSequenceNames
)
const
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
// check for schema tables
for
(
auto
&
sequenceName
:
schemaSequenceNames
)
{
const
bool
schemaSequenceIsNotInDb
=
dbSequenceNames
.
end
()
==
std
::
find
(
dbSequenceNames
.
begin
(),
dbSequenceNames
.
end
(),
sequenceName
);
if
(
schemaSequenceIsNotInDb
)
{
std
::
cerr
<<
" ERROR: the schema sequence "
<<
sequenceName
<<
" not found in the DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
try
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
for
(
auto
&
sequenceName
:
schemaSequenceNames
)
{
const
bool
schemaSequenceIsNotInDb
=
dbSequenceNames
.
end
()
==
std
::
find
(
dbSequenceNames
.
begin
(),
dbSequenceNames
.
end
(),
sequenceName
);
if
(
schemaSequenceIsNotInDb
)
{
std
::
cerr
<<
" ERROR: the schema sequence "
<<
sequenceName
<<
" not found in the DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
}
}
}
// check for extra tables in DB
for
(
auto
&
sequenceName
:
dbSequenceNames
)
{
const
bool
dbSequenceIsNotInSchema
=
schemaSequenceNames
.
end
()
==
std
::
find
(
schemaSequenceNames
.
begin
(),
schemaSequenceNames
.
end
(),
sequenceName
);
if
(
dbSequenceIsNotInSchema
)
{
std
::
cerr
<<
" INFO: the database sequence "
<<
sequenceName
<<
" not found in the schema"
<<
std
::
endl
;
if
(
VerifyStatus
::
ERROR
!=
status
)
{
status
=
VerifyStatus
::
INFO
;
for
(
auto
&
sequenceName
:
dbSequenceNames
)
{
const
bool
dbSequenceIsNotInSchema
=
schemaSequenceNames
.
end
()
==
std
::
find
(
schemaSequenceNames
.
begin
(),
schemaSequenceNames
.
end
(),
sequenceName
);
if
(
dbSequenceIsNotInSchema
)
{
std
::
cerr
<<
" INFO: the database sequence "
<<
sequenceName
<<
" not found in the schema"
<<
std
::
endl
;
if
(
VerifyStatus
::
ERROR
!=
status
)
{
status
=
VerifyStatus
::
INFO
;
}
}
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
//------------------------------------------------------------------------------
...
...
@@ -287,30 +297,32 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifySequenceNames(const std::li
//------------------------------------------------------------------------------
VerifySchemaCmd
::
VerifyStatus
VerifySchemaCmd
::
verifyTriggerNames
(
const
std
::
list
<
std
::
string
>
&
schemaTriggerNames
,
const
std
::
list
<
std
::
string
>
&
dbTriggerNames
)
const
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
// check for schema tables
for
(
auto
&
triggerName
:
schemaTriggerNames
)
{
const
bool
schemaTriggerIsNotInDb
=
dbTriggerNames
.
end
()
==
std
::
find
(
dbTriggerNames
.
begin
(),
dbTriggerNames
.
end
(),
triggerName
);
if
(
schemaTriggerIsNotInDb
)
{
std
::
cerr
<<
" ERROR: the schema trigger "
<<
triggerName
<<
" not found in the DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
try
{
VerifyStatus
status
=
VerifyStatus
::
UNKNOWN
;
for
(
auto
&
triggerName
:
schemaTriggerNames
)
{
const
bool
schemaTriggerIsNotInDb
=
dbTriggerNames
.
end
()
==
std
::
find
(
dbTriggerNames
.
begin
(),
dbTriggerNames
.
end
(),
triggerName
);
if
(
schemaTriggerIsNotInDb
)
{
std
::
cerr
<<
" ERROR: the schema trigger "
<<
triggerName
<<
" not found in the DB"
<<
std
::
endl
;
status
=
VerifyStatus
::
ERROR
;
}
}
}
// check for extra tables in DB
for
(
auto
&
triggerName
:
dbTriggerNames
)
{
const
bool
dbTriggerIsNotInSchema
=
schemaTriggerNames
.
end
()
==
std
::
find
(
schemaTriggerNames
.
begin
(),
schemaTriggerNames
.
end
(),
triggerName
);
if
(
dbTriggerIsNotInSchema
)
{
std
::
cerr
<<
" INFO: the database trigger "
<<
triggerName
<<
" not found in the schema"
<<
std
::
endl
;
if
(
VerifyStatus
::
ERROR
!=
status
)
{
status
=
VerifyStatus
::
INFO
;
for
(
auto
&
triggerName
:
dbTriggerNames
)
{
const
bool
dbTriggerIsNotInSchema
=
schemaTriggerNames
.
end
()
==
std
::
find
(
schemaTriggerNames
.
begin
(),
schemaTriggerNames
.
end
(),
triggerName
);
if
(
dbTriggerIsNotInSchema
)
{
std
::
cerr
<<
" INFO: the database trigger "
<<
triggerName
<<
" not found in the schema"
<<
std
::
endl
;
if
(
VerifyStatus
::
ERROR
!=
status
)
{
status
=
VerifyStatus
::
INFO
;
}
}
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
if
(
status
!=
VerifyStatus
::
INFO
&&
status
!=
VerifyStatus
::
ERROR
)
{
std
::
cerr
<<
" OK"
<<
std
::
endl
;
status
=
VerifyStatus
::
OK
;
}
return
status
;
}
}
// namespace catalogue
...
...
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