2015-08-20 17:27:15 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
|
2015-09-08 21:42:56 +02:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-07-22 00:34:59 +02:00
|
|
|
class BlobAvailabilityHandlerFactory:
|
2018-07-22 03:12:33 +02:00
|
|
|
# implements(IQueryHandlerFactory)
|
2015-08-20 17:27:15 +02:00
|
|
|
|
|
|
|
def __init__(self, blob_manager):
|
|
|
|
self.blob_manager = blob_manager
|
|
|
|
|
|
|
|
######### IQueryHandlerFactory #########
|
|
|
|
|
|
|
|
def build_query_handler(self):
|
|
|
|
q_h = BlobAvailabilityHandler(self.blob_manager)
|
|
|
|
return q_h
|
|
|
|
|
|
|
|
def get_primary_query_identifier(self):
|
|
|
|
return 'requested_blobs'
|
|
|
|
|
|
|
|
def get_description(self):
|
|
|
|
return "Blob Availability - blobs that are available to be uploaded"
|
|
|
|
|
|
|
|
|
2018-07-22 00:34:59 +02:00
|
|
|
class BlobAvailabilityHandler:
|
2018-07-22 03:12:33 +02:00
|
|
|
#implements(IQueryHandler)
|
2015-08-20 17:27:15 +02:00
|
|
|
|
|
|
|
def __init__(self, blob_manager):
|
|
|
|
self.blob_manager = blob_manager
|
|
|
|
self.query_identifiers = ['requested_blobs']
|
|
|
|
|
|
|
|
######### IQueryHandler #########
|
|
|
|
|
|
|
|
def register_with_request_handler(self, request_handler, peer):
|
|
|
|
request_handler.register_query_handler(self, self.query_identifiers)
|
|
|
|
|
|
|
|
def handle_queries(self, queries):
|
|
|
|
if self.query_identifiers[0] in queries:
|
2016-09-27 19:52:44 +02:00
|
|
|
log.info("Received the client's list of requested blobs")
|
2019-01-07 08:52:53 +01:00
|
|
|
available_blobs = self._get_available_blobs(queries[self.query_identifiers[0]])
|
|
|
|
log.debug("available blobs: %s", str(available_blobs))
|
|
|
|
return {'available_blobs': available_blobs}
|
|
|
|
return {}
|
2015-08-20 17:27:15 +02:00
|
|
|
|
|
|
|
######### internal #########
|
|
|
|
|
|
|
|
def _get_available_blobs(self, requested_blobs):
|
2019-01-07 08:52:53 +01:00
|
|
|
return self.blob_manager.completed_blobs(requested_blobs)
|