Beispiel #1
0
def on_every_second():
    '''
    @summary: function called by tornado/ioloop every second

    It's used to clear expired locks
    '''
    LOCK_MANAGER_INSTANCE.clean_expired_locks()
    print("chicking expired locks.\n")
Beispiel #2
0
 def get(self):
     '''
     @summary: deals with GET request (getting a JSON HAL of resources)
     '''
     resources = Resource(self.reverse_url("resources"))
     resources_names = LOCK_MANAGER_INSTANCE.get_resources_names()
     for resource_name in resources_names:
         tmp = LOCK_MANAGER_INSTANCE.get_resource_as_dict(resource_name)
         resource = Resource(self.reverse_url("resource", tmp['name']),
                             {"name": tmp['name']})
         resources.add_embedded_resource("resources", resource)
     self.set_header("Content-Type", "application/hal+json")
     self.finish(resources.to_json())
Beispiel #3
0
 def post(self, name):
     '''
     @summary: deals with POST request (acquiring locks on resource)
     @param name: name of the resource
     '''
     raw_body = self.request.body.decode('utf-8')
     if len(raw_body) == 0:
         self.send_error(status_code=400, message="empty body")
         return
     lock = Lock.from_json(name, raw_body)
     if not (lock):
         self.send_error(status_code=400, message="invalid json body")
         return
     lock.set_callbacks(
         functools.partial(self.on_active_wrapper, name, lock),
         self.on_delete_wrapper)
     LOCK_MANAGER_INSTANCE.add_lock(name, lock)
Beispiel #4
0
 def delete(self, name):
     '''
     @summary: deals with DELETE request (deleting the given resource)
     @param name: name of the resource
     '''
     res = LOCK_MANAGER_INSTANCE.remove_resource(name)
     if res:
         self.send_status(204)
     else:
         self.send_error(404, message="no resource (with locks) found")
 def delete(self, name, uid):
     '''
     @summary: deals with DELETE request (releasing a lock)
     @param name: name of the resource
     @param uid: uid of the lock
     '''
     res = LOCK_MANAGER_INSTANCE.delete_lock(name, uid)
     if res:
         self.send_status(204)
     else:
         self.send_error(status_code=404, message="lock not found")
         return
Beispiel #6
0
 def get(self, name):
     '''
     @summary: deals with GET request (getting a JSON HAL of the resource)
     @param name: name of the resource
     '''
     tmp = LOCK_MANAGER_INSTANCE.get_resource_as_dict(name)
     resource = Resource(self.reverse_url("resource", name), {"name": name})
     if tmp:
         for lock_dict in tmp['locks']:
             lock = Resource(
                 self.reverse_url("lock", name, lock_dict['uid']),
                 lock_dict)
             resource.add_embedded_resource("locks", lock)
     self.set_header("Content-Type", "application/hal+json")
     self.finish(resource.to_json())
 def get(self, name, uid):
     '''
     @summary: deals with GET request
     @param name: name of the resource
     @param uid: uid of the lock
     '''
     lock = LOCK_MANAGER_INSTANCE.get_lock(name, uid)
     if lock:
         self.set_header('Content-Type', 'application/hal+json')
         hal_lock = Resource(href=self.reverse_url("lock", name, lock.uid),
                             properties=lock.to_dict())
         hal_resource_link = Link(href=self.reverse_url("resource", name))
         hal_lock.add_link(rel="resource",
                           link=hal_resource_link,
                           multiple=False)
         self.write(hal_lock.to_json())
     else:
         self.send_error(status_code=404, message="lock not found")
         return
Beispiel #8
0
 def delete(self):
     '''
     @summary: deals with DELETE request (deleting all resources)
     '''
     LOCK_MANAGER_INSTANCE.remove_all_resources()
     self.send_status(204)