def HandleGetAggregate(request): """Juno request handler to retrieve Aggregate Projections. Get Parameters: taba - Taba Name to retrieve Aggregates for, or blank for all Taba Names. block - Taba Name Block ID to retrieve Aggregates for, or blank for all. Response: Aggregate Projections, serialized depending on the Accept MIME type. Accept Types: text/plain (default) - Human readable new-line separated. text/json - JSON serialized. """ # Parse and validate query parameters. name = request.input('taba') block = request.input('block') if name and block: juno.status(400) juno.append('Cannot specify both "taba" and "block"') return names = [name] if name else None blocks = block.split(',') if block else None return _AggregateResponse(names, blocks, _GetAccept(request))
def HandleGetRawBatch(request): """Juno request handler to retrieve a batch of raw States from the DB by Name. Post Body - a JSON dictionary with the following fields: client - Client ID to get State objects or, or blank for all. taba - List of Taba Names to get State objects for, or blank for all. block - List of Taba Name Block IDs to get State objects, or blank for all. Response: State objects, serialized depending on the Accept MIME type. Accept Types: text/plain (default) - Human readable new-line separated. text/json - JSON serialized. """ # Parse and validate query parameters. body_enc = request.raw['request_body_bytes'].read() params = cjson.decode(body_enc) client_id = params['client'] if 'client' in params else None names = params['taba'] if 'taba' in params else None blocks = params['block'] if 'block' in params else None if names and blocks: juno.status(400) juno.append('Cannot specify both "names" and "block"') return return _RawResponse(client_id, names, blocks, _GetAccept(request))
def HandleGetProjection(request): """Juno request handler to retrieve raw Projection(s) from the DB. Get Parameters: client - Client ID to get Projection(s) for, or blank for all Clients IDs. taba - Taba Name to get Projection(s) for, or blank for all Taba Names. block - Taba Name Block to get Projections for, or blank for all. Response: Projection objects, serialized depending on the Accept MIME type. Accept Types: text/plain (default) - Human readable new-line separated. text/json - JSON serialized. """ # Parse and validate query parameters. client_id = request.input('client') name = request.input('taba') block = request.input('block') if name and block: juno.status(400) juno.append('Cannot specify both "taba" and "block"') return blocks = block.split(',') if block else None names = [name] if name else None return _ProjectionResponse(client_id, names, blocks, _GetAccept(request))
def HandleGetAggretateBatch(request): """Juno request handler to retrieve a batch of Aggregates from the DB. Post Body - a JSON dictionary with the following fields: taba - List of Taba Name to retrieve Aggregates for, or blank for all. block - List of Taba Name Block IDs to retrieve, or blank for all. Response: Aggregate Projections, serialized depending on the Accept MIME type. Accept Types: text/plain (default) - Human readable new-line separated. text/json - JSON serialized. """ # Parse and validate query parameters. body_enc = request.raw['request_body_bytes'].read() params = cjson.decode(body_enc) names = params['taba'] if 'taba' in params else None blocks = params['block'] if 'block' in params else None if names and blocks: juno.status(400) juno.append('Cannot specify both "taba" and "block"') return return _AggregateResponse(names, blocks, _GetAccept(request))
def HandleGetTaba(request): """Juno Request handler to retrieve Rendered Tabs. Get Parameter: client - Client ID to retrieve Rendered Tabs for. If a Client ID is specified, this handler retrieves Rendered Projections. Otherwise it retrieved Rendered Aggregates. taba - Taba Name to retrieve Rendered Tabs for, or blank to retrieve all. block - Taba Name Block to retrieve Rendered Tabs for, or blank for all. Response: Rendered Tabs, serialized depending on the Accept MIME type. Accept Types: text/plain (default) - Human readable new-line separated. text/json - JSON serialized. """ # Parse and validate query parameters. client_id = request.input('client') name = request.input('taba') block = request.input('block') if name and block: juno.status(400) juno.append('Cannot specify both "taba" and "block"') return LOG.info("Starting Get Taba (%s, %s, %s)" % (client_id, name, block)) start = time.time() blocks = block.split(',') if block else None names = [name] if name else None renders = global_taba_server.GetRendered(client_id, names, blocks) # Render the Projection objects according to the requested format. accept = request.raw.get('HTTP_ACCEPT') or 'text/plain' accept = accept.lower() if accept == 'text/json': juno.append(cjson.encode([r for r in renders])) else: for render in renders: juno.append(render).append('\n') LOG.info("Finished Get Taba (%s, %s, %s) (%.2f)" % \ (client_id, name, block, time.time() - start))
def HandleDeleteName(request): """Juno request handler to delete all States for a Taba Name. Get Parameters: taba - (Required) The Taba Name to delete States for. """ name = request.input('taba') if not name: juno.status(400) juno.append('Must specify "taba" parameter') return client_id = request.input('client') LOG.info("Starting Delete Taba (%s, %s)" % (client_id, name)) global_taba_server.DeleteTaba(name, client_id)
def HandleGetType(request): """Juno request handler to retrieve the Taba Type for a Taba Name. Get Parameters: taba - The Taba Name to retrieve the Taba Type for. taba_glob - Glob for the Taba Name (One of the above is required) Response: Taba Type, serialized depending on the Accept MIME type. Accept Types: text/plain (default) - Human readable. text/json - JSON serialized. """ name = request.input('taba') name_glob = request.input('taba_glob') if name and name_glob: juno.status(400) juno.append('Cannot specify both "taba_glob" and "taba"') return if name: names = [name] elif name_glob: names = fnmatch.filter(global_taba_server.GetNames(), name_glob) else: names = None types = global_taba_server.GetTabaTypes(names) # Render the types depending on the Accept header. accept = request.raw.get('HTTP_ACCEPT') or 'text/plain' accept = accept.lower() if accept == 'text/json': juno.append(cjson.encode(dict(types))) else: for type in types: juno.append('%s: %s\n' % type)
def HandleGetProjection(request): """Juno request handler to retrieve raw Projection(s) from the DB. Get Parameters: client - Client ID to get Projection(s) for, or blank for all Clients IDs. client_glob - Client ID to get Projection(s) for. taba - Taba Name to get Projection(s) for, or blank for all Taba Names. taba_glob - Taba Glob to get Projection(s) for. block - Taba Name Block to get Projections for, or blank for all. Response: Projection objects, serialized depending on the Accept MIME type. Accept Types: text/plain (default) - Human readable new-line separated. text/json - JSON serialized. """ # Parse and validate query parameters. client_id = request.input('client') name = request.input('taba') block = request.input('block') # add glob params for taba and client name_glob = request.input('taba_glob') client_glob = request.input('client_glob') if (name or name_glob) and block: juno.status(400) juno.append('Cannot specify both "taba" and "block"') return # add rule.. only one of taba or taba_glob if name and name_glob: juno.status(400) juno.append('Cannot specify both "taba_glob" and "taba"') return # add rule.. only one of client_id or client_glob if client_id and client_glob: juno.status(400) juno.append('Cannot specify both "client_glob" and "client"') return blocks = block.split(',') if block else None names = [name] if name else None names_param = Param(name_glob, True) if name_glob else Param(names, False) clients_param = Param(client_glob, True) if client_glob \ else Param(client_id, False) return _ProjectionResponse(clients_param, names_param, blocks, _GetAccept(request))
def HandlePost(request): """Juno request handler for receiving posted Taba Events from a Taba Client. The request is expected to be a POST where the body follows the protocol: client_id\n[serialized_event\n]*\n The request is expected to be in plain-text. Only one client should be present in the request. The client_id and serialized events cannot contain '\n' characters. """ # Extract the Client ID and encoded Taba Events. body = request.raw['request_body_bytes'] try: client_id = body.readline().strip() events = [l.strip() for l in body.readlines() if l.strip()] except Exception: juno.status(400) juno.append("Could not parse document body") return # Check that the parameters are at least present. if not client_id: juno.status(400) juno.append("Client ID must be the first line of the POST document") return if not events: juno.status(400) juno.append("No events in POST document") return # Add the events to the Taba Agent buffer. try: global_taba_agent.Buffer(client_id, events) except Exception: LOG.error("Error buffering events") LOG.error(traceback.format_exc()) juno.status(500) juno.append("Error buffering events") return
def ServerError(error='Unspecified error', file=None): juno.status(500) return juno._response.response
def NotFound(error='Unspecified error', file=None): juno.status(404) return juno._response.response