Skip to content

Commit 3336a94

Browse files
authored
Merge pull request #135 from EGA-archive/schema-versions
New release v2.0-1d0a6ea
2 parents 83bd1d1 + d882aaa commit 3336a94

File tree

9 files changed

+83
-25
lines changed

9 files changed

+83
-25
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Please, go to [B2RI/B2PI docs website](https://b2ri-documentation-demo.ega-archi
1515
* Validation on the fly per framework and model(s).
1616
* Configuration of the entities of each entry type now done by .yml files.
1717
* Restart of the app when conf files or generic conf is modified (no need to rebuild).
18-
* Other bug fixes
18+
* OR Filters (in test approach, as it is still not approved officially by GA4GH).
19+
* Other bug fixes.
1920
* Unit tests expanded, with a total of 313 now.
2021

2122
## Main changes from B2RI

beacon/auth/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from beacon.logs.logs import LOG
1010

1111
# for keycloak, create aud in mappers, with custom, aud and beacon for audience
12-
mock_access_token = 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJreS1tUXNxZ0ZYeHdSUVRfRUhuQlJJUGpmbVhfRXZuUTVEbzZWUTJCazdZIn0.eyJleHAiOjE3NjU5MDU0OTgsImlhdCI6MTc2NTkwNTE5OCwianRpIjoiMGRmYjhlNWYtMGQ4My00Njk3LTkzYTEtYWI4MTI3NzZhYjU4IiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL2F1dGgvcmVhbG1zL0JlYWNvbiIsImF1ZCI6ImJlYWNvbiIsInN1YiI6IjQ3ZWZmMWIxLTc2MjEtNDU3MC1hMGJiLTAxYTcxOWZiYTBhMiIsInR5cCI6IkJlYXJlciIsImF6cCI6ImJlYWNvbiIsInNlc3Npb25fc3RhdGUiOiI0YjUyMjI3Zi0wZjEyLTRmYjYtOWQ0YS0yY2E5OGU4MDg5NmYiLCJhY3IiOiIxIiwic2NvcGUiOiJvcGVuaWQg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vbiIsImF1ZCI6ImJlYWNvbiIsInN1YiI6IjQ3ZWZmMWIxLTc2MjEtNDU3MC1hMGJiLTAxYTcxOWZiYTBhMiIsInR5cCI6IkJlYXJlciIsImF6cCI6ImJlYWNvbiIsInNlc3Npb25fc3RhdGUiOiJkYjk4YzE1OC1mOTAxLTQ5YTctODRkNS04MzQxNjVmYzMxYTMiLCJhY3IiOiIxIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCBtaWNyb3Byb2ZpbGUtand0Iiwic2lkIjoiZGI5OGMxNTgtZjkwMS00OWE3LTg0ZDUtODM0MTY1ZmMzMWEzIiwidXBuIjoiamFuZSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwibmFtZSI6IkphbmUgU21pdGgiLCJncm91cHMiOlsib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiIsIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXSwicHJlZmVycmVkX3VzZXJuYW1lIjoiamFuZSIsImdpdmVuX25hbWUiOiJKYW5lIiwiZmFtaWx5X25hbWUiOiJTbWl0aCIsImVtYWlsIjoiamFuZS5zbWl0aEBiZWFjb24uZ2E0Z2gifQ.cboOLVmGnqR8BE8i71aVzwSite9aeTpujvGStx8yutosl80_4V_usLeqTI2pHRP9YEbgNLDFCBHXACJ0zL2SLGeuWYpj1OtOqk_49Vvh9wXVoIkv3DH0FrNMuWadtnZYtDViAOdvOyWK8dwsk8xptbcu4wS5EaiNKuOLXG8VneGYZ_GQ03gMocvSq4SORmzGjNo8hZ9NR5_JudoNOLbzftOXjY5smKItp7dsyrwWVOcFd09LKdkxgzf2OeHybjdso_S4U-Af47crrZ0XiLwfsVS535c2RNfJVHwImtrK_5li4A8n15mAGYRqXMqC2cRSl_cbqL8pYzjIBS_ECcAJ8g'
1313
mock_access_token_false = 'public'
1414
#dummy test anonymous
1515
#dummy test login

beacon/conf/api_version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
api_version: v2.0-2aba4a4
1+
api_version: v2.0-1d0a6ea

beacon/conf/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
beacon_id = 'org.ega-archive.beacon-ri-demo' # ID of the Beacon
1515
beacon_name = 'Beacon Production Implementation demo' # Name of the Beacon service
1616
api_version = 'v2.2.0' # Version of the Beacon implementation
17-
uri = 'http://localhost:5050'
17+
uri = 'http://localhost:50510'
1818
uri_subpath = '/api'
1919
complete_url = uri + uri_subpath
2020
environment = 'test'

beacon/conf/models/models_conf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ ga4gh/beacon_v2_default_model:
22
model_enabled: True
33

44
EUCAIM:
5-
model_enabled: True
5+
model_enabled: False

beacon/models/ga4gh/beacon_v2_default_model/connections/mongo/non_collections.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def get_phenotypic_endpoint_with_id(self, dataset: SingleDatasetResponse):
7171
def get_variants_of_phenotypic_endpoint(self, dataset: SingleDatasetResponse):
7272
analysis_confile=import_analysis_confile()
7373
run_confile=import_run_confile()
74+
new_entry_id = RequestAttributes.entry_id
7475
# Check which is the queried initial entry type of the cross query and process and get the ids to convert to the final entry type response.
7576
if RequestAttributes.pre_entry_type == analysis_confile["analysis"]["endpoint_name"] or RequestAttributes.pre_entry_type == run_confile["run"]["endpoint_name"]:
7677
query = {"$and": [{"id": RequestAttributes.entry_id}]}
@@ -82,8 +83,8 @@ def get_variants_of_phenotypic_endpoint(self, dataset: SingleDatasetResponse):
8283
initial_ids = runs \
8384
.find_one(query, {"biosampleId": 1, "_id": 0})
8485
try:
85-
RequestAttributes.entry_id = initial_ids["biosampleId"]
86-
except Exception:
86+
new_entry_id = initial_ids["biosampleId"]
87+
except Exception as e:
8788
return dataset
8889
try:
8990
# Retrieve the ids per dataset.
@@ -95,7 +96,7 @@ def get_variants_of_phenotypic_endpoint(self, dataset: SingleDatasetResponse):
9596
return dataset
9697
# Map the ids and check which is the position fo the id found in the array of ids.
9798
for bioid in bioids:
98-
if bioid == RequestAttributes.entry_id:
99+
if bioid == new_entry_id:
99100
break
100101
position+=1
101102
if position == len(bioids):

beacon/utils/modules.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def load_class(script_name, className):
2525
return klass
2626

2727
def load_types_of_results(response_type):
28+
with open("/beacon/conf/models/models_conf.yml", 'r') as pfile:
29+
models_confile= yaml.safe_load(pfile)
30+
pfile.close()
2831
list_of_results_classes_accepted=[]
2932
version_catch = re.search(r"(v\d+(\.\d+)*)", RequestAttributes.returned_schema[0]["schema"])
3033
if version_catch:
@@ -34,6 +37,9 @@ def load_types_of_results(response_type):
3437
dirs = os.listdir("/beacon/models")
3538
for folder in dirs:
3639
subdirs = os.listdir("/beacon/models/"+folder)
40+
if folder in models_confile:
41+
if models_confile[folder]["model_enabled"] == False:
42+
continue
3743
if "validator" in subdirs:
3844
validatordirs = os.listdir("/beacon/models/"+folder+"/validator/"+response_type)
3945
for validatorfolder in validatordirs:
@@ -48,6 +54,9 @@ def load_types_of_results(response_type):
4854
list_of_results_classes_accepted.append(klass)
4955
for subfolder in subdirs:
5056
underdirs = os.listdir("/beacon/models/"+folder+"/"+subfolder)
57+
if folder+'/'+subfolder in models_confile:
58+
if models_confile[folder+'/'+subfolder ]["model_enabled"] == False:
59+
continue
5160
if "validator" in underdirs:
5261
try:
5362
validatordirs = os.listdir("/beacon/models/"+folder+"/"+subfolder+"/validator/"+response_type)
@@ -67,10 +76,16 @@ def load_types_of_results(response_type):
6776
return union_type
6877

6978
def load_routes():
79+
with open("/beacon/conf/models/models_conf.yml", 'r') as pfile:
80+
models_confile= yaml.safe_load(pfile)
81+
pfile.close()
7082
dirs = os.listdir("/beacon/models")
7183
routes_to_add={}
7284
for folder in dirs:
7385
subdirs = os.listdir("/beacon/models/"+folder)
86+
if folder in models_confile:
87+
if models_confile[folder]["model_enabled"] == False:
88+
continue
7489
if "conf" in subdirs:
7590
confiles = os.listdir("/beacon/models/"+folder+"/conf/entry_types/")
7691
for confile in confiles:
@@ -90,6 +105,9 @@ def load_routes():
90105
else:
91106
for subfolder in subdirs:
92107
underdirs = os.listdir("/beacon/models/"+folder+"/"+subfolder)
108+
if folder+'/'+subfolder in models_confile:
109+
if models_confile[folder+'/'+subfolder ]["model_enabled"] == False:
110+
continue
93111
if "conf" in underdirs:
94112
confiles = os.listdir("/beacon/models/"+folder+"/"+subfolder+"/conf/entry_types/")
95113
for confile in confiles:
@@ -191,12 +209,18 @@ def get_one_module_conf(entry_type):
191209
return entry_type_confile
192210

193211
def get_modules_confiles():
212+
with open("/beacon/conf/models/models_conf.yml", 'r') as pfile:
213+
models_confile= yaml.safe_load(pfile)
214+
pfile.close()
194215
dirs = os.listdir("/beacon/models")
195216
list_of_confiles=[]
196217
for folder in dirs:
197218
subdirs = os.listdir("/beacon/models/"+folder)
198219
if "conf" in subdirs:
199220
confiles = os.listdir("/beacon/models/"+folder+"/conf/entry_types/")
221+
if folder in models_confile:
222+
if models_confile[folder]["model_enabled"] == False:
223+
continue
200224
for confile in confiles:
201225
if confile != '__pycache__':
202226
with open("/beacon/models/"+folder+"/conf/entry_types/" + confile, 'r') as pfile:
@@ -206,6 +230,9 @@ def get_modules_confiles():
206230
else:
207231
for subfolder in subdirs:
208232
underdirs = os.listdir("/beacon/models/"+folder+"/"+subfolder)
233+
if folder+'/'+subfolder in models_confile:
234+
if models_confile[folder+'/'+subfolder ]["model_enabled"] == False:
235+
continue
209236
if "conf" in underdirs:
210237
confiles = os.listdir("/beacon/models/"+folder+"/"+subfolder+"/conf/entry_types/")
211238
for confile in confiles:

beacon/utils/shutters.py

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,67 @@ def graceful_shutdown_sigterm_handler():
4444

4545
PATHS_TO_RESTART = [
4646
"/beacon/conf/conf.py",
47-
"/beacon/models"
47+
"/beacon/models",
48+
"/beacon/conf/models"
4849
]
50+
async def config_test_watcher(app):
51+
pass
52+
4953

5054
async def config_watcher(app):
51-
def snapshot():
52-
times = {}
55+
initial_times = {}
56+
57+
# Let's add all the snapshot times for the folders to restart when changed
58+
for path in PATHS_TO_RESTART:
59+
if os.path.isfile(path):
60+
initial_times[path] = os.path.getmtime(path)
61+
elif os.path.isdir(path):
62+
for root, _, files in os.walk(path):
63+
for f in files:
64+
full = os.path.join(root, f)
65+
initial_times[full] = os.path.getmtime(full)
66+
# We give a time to the server to start
67+
await asyncio.sleep(5)
68+
69+
while True:
70+
await asyncio.sleep(2)
71+
72+
new_initial_times = {}
73+
74+
# We check again for any change
5375
for path in PATHS_TO_RESTART:
5476
if os.path.isfile(path):
55-
times[path] = os.path.getmtime(path)
77+
new_initial_times[path] = os.path.getmtime(path)
5678
elif os.path.isdir(path):
5779
for root, _, files in os.walk(path):
5880
if "__pycache__" in root:
5981
continue
82+
if not (f.endswith(".py") or f.endswith(".yml")):
83+
continue
6084
for f in files:
61-
if not f.endswith(".py"):
62-
continue
85+
86+
6387
full = os.path.join(root, f)
64-
times[full] = os.path.getmtime(full)
65-
return times
88+
new_initial_times[full] = os.path.getmtime(full)
89+
90+
91+
92+
6693

67-
initial_times = snapshot()
68-
await asyncio.sleep(5)
6994

70-
while True:
71-
await asyncio.sleep(2)
72-
new_times = snapshot()
7395

74-
for file_path, new_m in new_times.items():
96+
97+
98+
# If there is a change then, restart again the app
99+
for file_path, new_m in new_initial_times.items():
75100
old_m = initial_times.get(file_path)
76-
if old_m is None or new_m > old_m:
101+
if old_m is None or new_m != old_m:
77102
os._exit(0)
78103

79-
initial_times = new_times
104+
initial_times = new_initial_times
105+
106+
async def on_startup(app):
107+
app["config_watcher"] = asyncio.create_task(config_watcher(app))
80108

81109
async def on_startup(app):
82110
app["config_watcher"] = asyncio.create_task(config_watcher(app))

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ networks:
66

77
services:
88
beaconprod:
9-
restart: always
9+
restart: unless-stopped
1010
build:
1111
context: .
1212
container_name: beaconprod
@@ -18,6 +18,7 @@ services:
1818
- ./beacon/conf/conf.py:/beacon/conf/conf.py
1919
- ./beacon/permissions:/beacon/permissions
2020
- ./beacon/models:/beacon/models
21+
- ./beacon/conf/models:/beacon/conf/models
2122
networks:
2223
- pub
2324

0 commit comments

Comments
 (0)