Skip to content
GitLab
Menu
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
a5056129
Commit
a5056129
authored
Nov 16, 2018
by
Markus Scheidgen
Browse files
Allow to reset the repository db.
parent
19e55027
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
nomad/api/__main__.py
0 → 100644
View file @
a5056129
# Copyright 2018 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
nomad.api
if
__name__
==
'__main__'
:
nomad
.
api
.
app
.
run
(
debug
=
True
,
port
=
8000
)
\ No newline at end of file
nomad/config.py
View file @
a5056129
...
...
@@ -31,6 +31,9 @@ CeleryConfig = namedtuple('Celery', ['broker_url'])
FSConfig
=
namedtuple
(
'FSConfig'
,
[
'tmp'
,
'objects'
])
""" Used to configure file stystem access. """
RepositoryDBConfig
=
namedtuple
(
'RepositoryDBConfig'
,
[
'host'
,
'port'
,
'dbname'
,
'user'
,
'password'
])
""" Used to configure access to NOMAD-coe repository db. """
ElasticConfig
=
namedtuple
(
'ElasticConfig'
,
[
'host'
,
'calc_index'
])
""" Used to configure elastic search. """
...
...
@@ -80,6 +83,13 @@ elastic = ElasticConfig(
host
=
os
.
environ
.
get
(
'NOMAD_ELASTIC_HOST'
,
'localhost'
),
calc_index
=
'calcs'
)
repository_db
=
RepositoryDBConfig
(
host
=
os
.
environ
.
get
(
'NOMAD_REPOSITORY_DB_HOST'
,
'localhost'
),
port
=
int
(
os
.
environ
.
get
(
'NOMAD_REPOSITORY_DB_PORT'
,
5432
)),
dbname
=
os
.
environ
.
get
(
'NOMAD_REPOSITORY_DB_NAME'
,
'nomad'
),
user
=
os
.
environ
.
get
(
'NOMAD_REPOSITORY_DB_USER'
,
'postgres'
),
password
=
os
.
environ
.
get
(
'NOMAD_REPOSITORY_DB_PASSWORD'
,
'nomad'
)
)
mongo
=
MongoConfig
(
host
=
os
.
environ
.
get
(
'NOMAD_MONGO_HOST'
,
'localhost'
),
port
=
int
(
os
.
environ
.
get
(
'NOMAD_MONGO_PORT'
,
27017
)),
...
...
@@ -98,5 +108,5 @@ services = NomadServicesConfig(
api_secret
=
os
.
environ
.
get
(
'NOMAD_API_SECRET'
,
'defaultApiSecret'
)
)
console_log_level
=
get_loglevel_from_env
(
'NOMAD_CONSOLE_LOGLEVEL'
,
default_level
=
logging
.
ERROR
)
console_log_level
=
get_loglevel_from_env
(
'NOMAD_CONSOLE_LOGLEVEL'
,
default_level
=
logging
.
INFO
)
service
=
os
.
environ
.
get
(
'NOMAD_SERVICE'
,
'unknown nomad service'
)
nomad/empty_repository_db.sql
0 → 100644
View file @
a5056129
This diff is collapsed.
Click to expand it.
nomad/infrastructure.py
View file @
a5056129
...
...
@@ -87,18 +87,62 @@ def setup_repository_db():
from
sqlalchemy.orm
import
sessionmaker
global
repository_db
engine
=
create_engine
(
'postgresql://postgres:nomad@localhost:5432/nomad'
,
echo
=
False
)
url
=
'postgresql://%s:%s@%s:%d/%s'
%
(
config
.
repository_db
.
user
,
config
.
repository_db
.
password
,
config
.
repository_db
.
host
,
config
.
repository_db
.
port
,
config
.
repository_db
.
dbname
)
engine
=
create_engine
(
url
,
echo
=
False
,
isolation_level
=
'AUTOCOMMIT'
)
repository_db
=
sessionmaker
(
bind
=
engine
)()
logger
.
info
(
'setup repository db'
)
def
reset
():
""" Resets the databases mongo and elastic/calcs. Be careful. """
logger
.
info
(
'reset mongodb'
)
mongo_client
.
drop_database
(
config
.
mongo
.
users_db
)
logger
.
info
(
'reset elastic search'
)
elastic_client
.
indices
.
delete
(
index
=
config
.
elastic
.
calc_index
)
from
nomad.repo
import
RepoCalc
RepoCalc
.
init
()
logger
.
info
(
'reset repository db'
)
reset_repository_db
()
logger
.
info
(
'reset files'
)
shutil
.
rmtree
(
config
.
fs
.
objects
,
ignore_errors
=
True
)
shutil
.
rmtree
(
config
.
fs
.
tmp
,
ignore_errors
=
True
)
def
reset_repository_db
():
import
psycopg2
logger
.
info
(
'reset repository db 1'
)
conn_str
=
"host='%s' port=%d dbname='%s' user='%s' password='%s'"
%
(
config
.
repository_db
.
host
,
config
.
repository_db
.
port
,
config
.
repository_db
.
dbname
,
config
.
repository_db
.
user
,
config
.
repository_db
.
password
)
logger
.
info
(
'reset repository db 2'
)
conn
=
psycopg2
.
connect
(
conn_str
)
logger
.
info
(
'reset repository db 3'
)
with
conn
.
cursor
()
as
cur
:
logger
.
info
(
'reset repository db 4'
)
cur
.
execute
(
"DROP SCHEMA public CASCADE;"
"CREATE SCHEMA public;"
"GRANT ALL ON SCHEMA public TO postgres;"
"GRANT ALL ON SCHEMA public TO public;"
)
logger
.
info
(
'reset repository db 5'
)
cur
.
execute
(
open
(
'nomad/empty_repository_db.sql'
,
'r'
).
read
())
logger
.
info
(
'reset repository db 6'
)
conn
.
close
()
logger
.
info
(
'reset repository db 7'
)
if
__name__
==
'__main__'
:
setup
()
reset
()
nomad/utils.py
View file @
a5056129
...
...
@@ -147,7 +147,7 @@ def configure_logging():
wrapper_class
=
structlog
.
stdlib
.
BoundLogger
)
# configure logging in general
logging
.
basicConfig
(
stream
=
sys
.
stdout
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
root
=
logging
.
getLogger
()
for
handler
in
root
.
handlers
:
if
not
isinstance
(
handler
,
logstash
.
TCPLogstashHandler
):
...
...
@@ -158,6 +158,8 @@ def configure_logging():
add_logstash_handler
(
root
)
root
.
info
(
'Structlog configured for logstash'
)
root
.
info
(
'Structlog configured'
)
def
create_uuid
()
->
str
:
""" Returns a web-save base64 encoded random uuid (type 4). """
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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