diff --git a/api/api.py b/api/api.py index 4e1233f6dd9343ff88f2effbb21c5e308427de77..e4bbff369a60f1d977308bfacc7e1eb2605ef51f 100644 --- a/api/api.py +++ b/api/api.py @@ -27,7 +27,7 @@ routing_regexes = { # site id regex # length less than 24 characters # allowed characters are [0-9a-z] - 'site_re': '[0-9a-z]{0,24}', + 'site_id_re': '[0-9a-z]{0,24}', # user id regex # any length, allowed chars are [0-9a-z.@_-] 'user_id_re': '[0-9a-z.@_-]*', @@ -76,7 +76,7 @@ routes = [ webapp2.Route(_format(r'/api/groups/<_id:{group_id_re}>'), grouphandler.GroupHandler, name='group'), webapp2.Route(_format(r'/api/<cont_name:groups>/<cid:{group_id_re}>/<list_name:roles>'), listhandler.ListHandler, name='group'), - webapp2.Route(_format(r'/api/<cont_name:groups>/<cid:{group_id_re}>/<list_name:roles>/<site:{site_re}>/<_id:{user_id_re}>'), listhandler.ListHandler, name='group', methods=['GET', 'PUT', 'DELETE']), + webapp2.Route(_format(r'/api/<cont_name:groups>/<cid:{group_id_re}>/<list_name:roles>/<site:{site_id_re}>/<_id:{user_id_re}>'), listhandler.ListHandler, name='group', methods=['GET', 'PUT', 'DELETE']), webapp2.Route(_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:tags>'), listhandler.ListHandler, methods=['POST'], name='tags_post'), webapp2.Route(_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:tags>/<value:{tag_re}>'), listhandler.ListHandler, name='tags'), @@ -85,7 +85,7 @@ routes = [ webapp2.Route(_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:files>/<filename:{filename_re}>'), listhandler.FileListHandler, name='files'), webapp2.Route(_format(r'/api/<cont_name:collections|projects>/<cid:{cid_re}>/<list_name:permissions>'), listhandler.PermissionsListHandler, name='perms_post', methods=['POST']), - webapp2.Route(_format(r'/api/<cont_name:collections|projects>/<cid:{cid_re}>/<list_name:permissions>/<site:{site_re}>/<_id:{user_id_re}>'), listhandler.PermissionsListHandler, name='perms'), + webapp2.Route(_format(r'/api/<cont_name:collections|projects>/<cid:{cid_re}>/<list_name:permissions>/<site:{site_id_re}>/<_id:{user_id_re}>'), listhandler.PermissionsListHandler, name='perms'), webapp2.Route(_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:notes>'), listhandler.NotesListHandler, name='notes_post', methods=['POST']), webapp2.Route(_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:notes>/<_id:{note_id_re}>'), listhandler.NotesListHandler, name='notes'), diff --git a/api/mongo.py b/api/mongo.py index fd6ef7e283f0593c4470a135e0f4208bac7ae2a6..fe962a26bce6ff26ea01a0bb9d31bfbeb741868e 100644 --- a/api/mongo.py +++ b/api/mongo.py @@ -1,13 +1,16 @@ +import time +import logging import pymongo import datetime -import time + +log = logging.getLogger('scitran.api') db = None def configure_db(db_uri, site_id, site_name, api_uri): global db - for i in range(0,3): + for i in range(3): try: db = pymongo.MongoClient(db_uri).get_default_database() # TODO jobs indexes @@ -28,5 +31,6 @@ def configure_db(db_uri, site_id, site_name, api_uri): return except Exception as e: db = None - time.sleep(5) + log.warning('DB not available...trying again in {} seconds'.format((i + 1) * 2)) + time.sleep((i + 1) * 2) raise e diff --git a/api/validators.py b/api/validators.py index ed70826aba57fa2ea58a0609521b485c8ca99775..1f868ae90eb7ba9ccc993749292f999d0b914aee 100644 --- a/api/validators.py +++ b/api/validators.py @@ -108,7 +108,10 @@ def key_check(handler, schema_file): for sublists of mongo container there is no automatic key check when creating, updating or deleting an object. We are adding a custom array field to the json schemas ("key_fields"). The uniqueness is checked on the combination of all the elements of "key_fields". - For an example check api/schemas/input/permission.json + + For an example check api/schemas/input/permission.json: + The key fields are the _id and the site. Uniqueness is checked on the combination + of the values of the _id and the site of the permissions. So this method ensures that: 1. after a POST and PUT request we don't have two items with the same values for the key set