async def list_statuses(self, request): """Fetches the committed status of batches by either a POST or GET. Request: body: A JSON array of one or more id strings (if POST) query: - id: A comma separated list of up to 15 ids (if GET) - wait: Request should not return until all batches committed Response: data: A JSON object, with batch ids as keys, and statuses as values link: The /batch_status link queried (if GET) """ error_traps = [error_handlers.StatusResponseMissing] # Parse batch ids from POST body, or query paramaters if request.method == 'POST': if request.headers['Content-Type'] != 'application/json': LOGGER.debug( 'Request headers had wrong Content-Type: %s', request.headers['Content-Type']) raise errors.StatusWrongContentType() ids = await request.json() if (not ids or not isinstance(ids, list) or not all(isinstance(i, str) for i in ids)): LOGGER.debug('Request body was invalid: %s', ids) raise errors.StatusBodyInvalid() else: ids = self._get_filter_ids(request) if not ids: LOGGER.debug('Request for statuses missing id query') raise errors.StatusIdQueryInvalid() # Query validator validator_query = client_pb2.ClientBatchStatusRequest(batch_ids=ids) self._set_wait(request, validator_query) response = await self._query_validator( Message.CLIENT_BATCH_STATUS_REQUEST, client_pb2.ClientBatchStatusResponse, validator_query, error_traps) # Send response if request.method != 'POST': metadata = self._get_metadata(request, response) else: metadata = None return self._wrap_response( data=response.get('batch_statuses'), metadata=metadata)
async def list_statuses(self, request): """Fetches the committed status of batches by either a POST or GET. Request: body: A JSON array of one or more id strings (if POST) query: - id: A comma separated list of up to 15 ids (if GET) - wait: Request should not return until all batches committed Response: data: A JSON object, with batch ids as keys, and statuses as values link: The /batch_status link queried (if GET) """ error_traps = [error_handlers.StatusesNotReturned()] # Parse batch ids from POST body, or query paramaters if request.method == 'POST': if request.headers['Content-Type'] != 'application/json': return errors.BadStatusBody() ids = await request.json() if not isinstance(ids, list): return errors.BadStatusBody() if len(ids) == 0: return errors.MissingStatusId() if not isinstance(ids[0], str): return errors.BadStatusBody() else: try: ids = request.url.query['id'].split(',') except KeyError: return errors.MissingStatusId() # Query validator validator_query = client_pb2.ClientBatchStatusRequest(batch_ids=ids) self._set_wait(request, validator_query) response = await self._query_validator( Message.CLIENT_BATCH_STATUS_REQUEST, client_pb2.ClientBatchStatusResponse, validator_query, error_traps) # Send response if request.method != 'POST': metadata = self._get_metadata(request, response) else: metadata = None return self._wrap_response( data=response.get('batch_statuses'), metadata=metadata)
def status_list(self, request): error_traps = [error_handlers.MissingStatus()] try: batch_ids = request.url.query['id'].split(',') except KeyError: return errors.MissingStatusId() response = self._query_validator( Message.CLIENT_BATCH_STATUS_REQUEST, client.ClientBatchStatusResponse, client.ClientBatchStatusRequest(batch_ids=batch_ids), error_traps) return RouteHandler._wrap_response(data=response.get('batch_statuses'), metadata=RouteHandler._get_metadata( request, response))
def status_list(self, request): """ Fetches the status of a set of batches submitted to the validator. Batch ids can be submitted by query string (GET request), or by a POST body with a JSON formatted list of id strings. Will wait for batches to commit if the `wait` parameter is set """ error_traps = [error_handlers.MissingStatus()] if request.method == 'POST': if request.headers['Content-Type'] != 'application/json': return errors.BadStatusBody() batch_ids = yield from request.json() if not isinstance(batch_ids, list): return errors.BadStatusBody() if len(batch_ids) == 0: return errors.MissingStatusId() if not isinstance(batch_ids[0], str): return errors.BadStatusBody() else: try: batch_ids = request.url.query['id'].split(',') except KeyError: return errors.MissingStatusId() validator_query = client.ClientBatchStatusRequest(batch_ids=batch_ids) self._set_wait(request, validator_query) response = self._query_validator( Message.CLIENT_BATCH_STATUS_REQUEST, client.ClientBatchStatusResponse, validator_query, error_traps) if request.method != 'POST': metadata = RouteHandler._get_metadata(request, response) else: metadata = None return RouteHandler._wrap_response( data=response.get('batch_statuses'), metadata=metadata)
def status_list(self, request): """ Fetches the status of a set of batches submitted to the validator Will wait for batches to commit if the `wait` parameter is set """ error_traps = [error_handlers.MissingStatus()] try: batch_ids = request.url.query['id'].split(',') except KeyError: return errors.MissingStatusId() validator_query = client.ClientBatchStatusRequest(batch_ids=batch_ids) self._set_wait(request, validator_query) response = self._query_validator(Message.CLIENT_BATCH_STATUS_REQUEST, client.ClientBatchStatusResponse, validator_query, error_traps) return RouteHandler._wrap_response(data=response.get('batch_statuses'), metadata=RouteHandler._get_metadata( request, response))