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
nomad-lab
nomad-FAIR
Commits
af03670b
Commit
af03670b
authored
Dec 23, 2018
by
Markus Scheidgen
Browse files
Fixed exception on resetting repository db without existing schema.
parent
1f362c58
Pipeline
#41901
canceled with stages
in 38 seconds
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
nomad/infrastructure.py
View file @
af03670b
...
...
@@ -164,27 +164,27 @@ def reset():
This function just attempts to remove everything, there is no exception handling
or any warranty it will succeed.
"""
logger
.
info
(
'reset mongodb'
)
try
:
if
not
mongo_client
:
setup_mongo
()
mongo_client
.
drop_database
(
config
.
mongo
.
db_name
)
logger
.
info
(
'mongodb resetted'
)
except
Exception
as
e
:
logger
.
error
(
'exception reset mongodb'
,
exc_info
=
e
)
logger
.
info
(
'reset elastic search'
)
try
:
if
not
elastic_client
:
setup_elastic
()
elastic_client
.
indices
.
delete
(
index
=
config
.
elastic
.
index_name
)
from
nomad.repo
import
RepoCalc
RepoCalc
.
init
()
logger
.
info
(
'elastic index resetted'
)
except
Exception
as
e
:
logger
.
error
(
'exception resetting elastic'
,
exc_info
=
e
)
logger
.
info
(
'reset repository db'
)
try
:
reset_repository_db
()
logger
.
info
(
'repository db resetted'
)
except
Exception
as
e
:
logger
.
error
(
'exception resetting repository db'
,
exc_info
=
e
)
...
...
@@ -202,23 +202,22 @@ def remove():
This function just attempts to remove everything, there is no exception handling
or any warranty it will succeed.
"""
logger
.
info
(
'delete mongodb'
)
try
:
if
not
mongo_client
:
setup_mongo
()
mongo_client
.
drop_database
(
config
.
mongo
.
db_name
)
logger
.
info
(
'mongodb deleted'
)
except
Exception
as
e
:
logger
.
error
(
'exception deleting mongodb'
,
exc_info
=
e
)
logger
.
info
(
'delete elastic search'
)
try
:
if
not
elastic_client
:
setup_elastic
()
elastic_client
.
indices
.
delete
(
index
=
config
.
elastic
.
index_name
)
logger
.
info
(
'elastic index'
)
except
Exception
as
e
:
logger
.
error
(
'exception deleting elastic'
,
exc_info
=
e
)
logger
.
info
(
'delete repository db'
)
try
:
if
repository_db
is
not
None
:
repository_db
.
expunge_all
()
...
...
@@ -228,6 +227,7 @@ def remove():
with
repository_db_connection
(
dbname
=
'postgres'
,
with_trans
=
False
)
as
con
:
with
con
.
cursor
()
as
cur
:
cur
.
execute
(
'DROP DATABASE IF EXISTS %s'
%
config
.
repository_db
.
dbname
)
logger
.
info
(
'repository db deleted'
)
except
Exception
as
e
:
logger
.
error
(
'exception deleting repository db'
,
exc_info
=
e
)
...
...
@@ -270,17 +270,23 @@ def repository_db_connection(dbname=None, with_trans=True):
def
reset_repository_db
():
""" Drops the existing NOMAD-coe repository postgres schema and creates a new minimal one. """
old_repository_db
=
repository_db
# invalidate and close all connections and sessions
if
repository_db
is
not
None
:
repository_db
.
expunge_all
()
repository_db
.
invalidate
()
if
repository_db_conn
is
not
None
:
repository_db_conn
.
close
()
# perform the reset
with
repository_db_connection
(
with_trans
=
False
)
as
conn
:
with
conn
.
cursor
()
as
cur
:
try
:
cur
.
execute
(
"DROP SCHEMA public CASCADE;"
)
except
psycopg2
.
ProgrammingError
:
pass
cur
.
execute
(
"DROP SCHEMA public CASCADE;"
"CREATE SCHEMA public;"
"GRANT ALL ON SCHEMA public TO postgres;"
"GRANT ALL ON SCHEMA public TO public;"
)
...
...
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