Skip to content

Commit f85a452

Browse files
author
Pedro Crespo
committed
Replaced main.disable_services by "enabled" flags in every service
1 parent 376f652 commit f85a452

File tree

13 files changed

+35
-24
lines changed

13 files changed

+35
-24
lines changed

services/web/server/src/simcore_service_webserver/application_config.py

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def create_schema():
4242
"client_outdir": T.String(),
4343
"log_level": T.Enum(*logging._nameToLevel.keys()), # pylint: disable=protected-access
4444
"testing": T.Bool(),
45-
T.Key("disable_services", default=[], optional=True): T.List(T.String()), # TODO: optional enable function in every section
4645
}),
4746
db_config.CONFIG_SECTION_NAME: db_config.schema,
4847
director_config.CONFIG_SECTION_NAME: director_config.schema,

services/web/server/src/simcore_service_webserver/computation.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
def setup(app: web.Application):
2222
log.debug("Setting up %s [service: %s] ...", __name__, SERVICE_NAME)
2323

24-
disable_services = app[APP_CONFIG_KEY].get("main", {}).get("disable_services",[])
25-
if SERVICE_NAME in disable_services:
24+
cfg = app[APP_CONFIG_KEY][CONFIG_SECTION_NAME]
25+
26+
if not cfg["enabled"]:
2627
log.warning("Service '%s' explicitly disabled in config", SERVICE_NAME)
2728
return
2829

29-
assert CONFIG_SECTION_NAME in app[APP_CONFIG_KEY]
30-
3130
# subscribe to rabbit upon startup
3231
# TODO: REmoved temporarily!
3332
# TODO: Define connection policies (e.g. {on-startup}, lazy). Could be defined in config-file

services/web/server/src/simcore_service_webserver/computation_config.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
"""
66
from simcore_sdk.config.rabbit import CONFIG_SCHEMA as _RABBIT_SCHEMA
77

8-
#import trafaret as T
8+
import trafaret as T
99

1010
SERVICE_NAME = 'rabbit'
1111
CONFIG_SECTION_NAME = SERVICE_NAME
1212

1313

14-
schema = _RABBIT_SCHEMA
14+
schema = _RABBIT_SCHEMA.merge(T.Dict({
15+
T.Key("enabled", default=True, optional=True): T.Bool()
16+
}))

services/web/server/src/simcore_service_webserver/config/host-dev-config.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ main:
55
log_level: INFO
66
port: 8080
77
testing: true
8-
disable_services: []
98
db:
9+
enabled: True
1010
init_tables: True
1111
postgres:
1212
database: simcoredb
@@ -21,6 +21,7 @@ director:
2121
host: director
2222
port: 8001
2323
rabbit:
24+
enabled: True
2425
channels:
2526
log: comp.backend.channels.log
2627
progress: comp.backend.channels.progress

services/web/server/src/simcore_service_webserver/config/server-defaults.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ main:
55
log_level: DEBUG
66
port: 8080
77
testing: true
8-
disable_services: []
98
director:
109
host: director
1110
port: 8001

services/web/server/src/simcore_service_webserver/db.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,15 @@ async def is_service_responsive(app:web.Application):
9393
return False
9494

9595
def setup(app: web.Application):
96+
log.debug("Setting up %s [service: %s] ...", __name__, THIS_SERVICE_NAME)
9697

97-
disable_services = app[APP_CONFIG_KEY]["main"]["disable_services"]
98+
cfg = app[APP_CONFIG_KEY][CONFIG_SECTION_NAME]
9899

99-
if THIS_SERVICE_NAME in disable_services:
100+
if not cfg["enabled"]:
100101
app[APP_DB_ENGINE_KEY] = app[APP_DB_SESSION_KEY] = None
101-
log.warning("Service '%s' explicitly disabled in cfgig", THIS_SERVICE_NAME)
102+
log.warning("Service '%s' explicitly disabled in config", THIS_SERVICE_NAME)
102103
return
103104

104-
# app is created at this point but not yet started
105-
log.debug("Setting up %s [service: %s] ...", __name__, THIS_SERVICE_NAME)
106-
107105
# ensures keys exist
108106
app[APP_DB_ENGINE_KEY] = None
109107
app[APP_DB_SESSION_KEY] = None

services/web/server/src/simcore_service_webserver/db_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
schema = T.Dict({
1414
T.Key("postgres"): _PG_SCHEMA,
1515
T.Key("init_tables", default=False): T.Bool(),
16-
T.Key("disable", default=False, optional=True): T.Bool()
16+
T.Key("enabled", default=True, optional=True): T.Bool()
1717
})

services/web/server/src/simcore_service_webserver/director/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
def setup(app: web.Application):
1717
logger.debug("Setting up %s ...", __name__)
1818

19-
assert CONFIG_SECTION_NAME in app[APP_CONFIG_KEY]
19+
cfg = app[APP_CONFIG_KEY][CONFIG_SECTION_NAME]
20+
21+
if not cfg["enabled"]:
22+
logger.warning("'%s' explicitly disabled in config", __name__)
23+
return
2024

2125

2226
# TODO: implement!!!

services/web/server/src/simcore_service_webserver/director/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
CONFIG_SECTION_NAME = 'director'
1010

1111
schema = T.Dict({
12+
T.Key("enabled", default=True, optional=True): T.Bool(),
1213
"host": T.String(),
1314
"port": T.Int()
1415
})

services/web/server/src/simcore_service_webserver/login/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424

2525
async def pg_pool(app: web.Application):
26+
2627
smtp_config = app[APP_CONFIG_KEY][SMTP_SECTION]
2728
config = {"SMTP_{}".format(k.upper()): v for k, v in smtp_config.items()}
2829
#'SMTP_SENDER': None,
@@ -50,6 +51,13 @@ def setup(app: web.Application):
5051

5152
# TODO: requires rest ready!
5253
assert SMTP_SECTION in app[APP_CONFIG_KEY]
54+
assert DB_SECTION in app[APP_CONFIG_KEY]
55+
56+
# TODO: automatize dependencies
57+
enabled = all( app[APP_CONFIG_KEY].get(mod, {}).get("enabled", True) for mod in (SMTP_SECTION, DB_SECTION) )
58+
if not enabled:
59+
log.warning("Disabling '%s' since %s or %s were explictily disabled in config", __name__, SMTP_SECTION, DB_SECTION)
60+
return
5361

5462
# routes
5563
specs = app[APP_OPENAPI_SPECS_KEY]

services/web/server/tests/login/config.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ main:
55
log_level: DEBUG
66
port: 8080
77
testing: true
8-
disable_services: ['rabbit', 'director', 's3']
98
director:
9+
enabled: False
1010
host: director
1111
port: 8001
1212
db:
@@ -21,12 +21,14 @@ db:
2121
minsize: 1
2222
endpoint: postgres:5432
2323
rabbit:
24+
enabled: False
2425
channels:
2526
log: comp.backend.channels.log
2627
progress: comp.backend.channels.progress
2728
password: simcore
2829
user: simcore
2930
# s3:
31+
# enabled: False
3032
# access_key: 'Q3AM3UQ867SPQQA43P2F'
3133
# bucket_name: simcore
3234
# endpoint: play.minio.io:9000

services/web/server/tests/unit/mock/configs/light-test.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ main:
77
client_outdir: ../../../client/source-output
88
log_level: DEBUG
99
testing: True
10-
disable_services:
11-
- postgres
12-
- rabbit
1310
director:
1411
host: localhost
1512
port: 8001
1613
db:
14+
enabled: False
1715
postgres:
1816
database: test_db
1917
user: test_user
@@ -23,6 +21,7 @@ db:
2321
# DEPRECATE OR add postgresql+psycopg2:// otherwise will fail sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string 'localhost:5432'
2422
endpoint: localhost:5432
2523
rabbit:
24+
enabled: False
2625
host: ${RABBIT_HOST}
2726
password: simcore
2827
user: simcore

services/web/server/tests/unit/mock/configs/minimum.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ main:
77
client_outdir: client/source-output
88
log_level: DEBUG
99
testing: True
10-
disable_services:
11-
- postgres
12-
- rabbit
1310
director:
1411
host: localhost
1512
port: 8001
1613
db:
14+
enabled: False
1715
postgres:
1816
database: test_db
1917
user: test_user
@@ -23,6 +21,7 @@ db:
2321
# DEPRECATE OR add postgresql+psycopg2:// otherwise will fail sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string 'localhost:5432'
2422
endpoint: localhost:5432
2523
rabbit:
24+
enabled: False
2625
host: foo
2726
password: simcore
2827
user: simcore

0 commit comments

Comments
 (0)