Example #1
0
    def wrapper(*args, **kwargs):
      invalid_params = []

      for key in bottle.request.query:
        if key not in params:
          invalid_params.append(key)

      if len(invalid_params) > 0:
        bottle.abort(400, 'Invalid parameters: %s' % ', '.join(invalid_params))

      return fn(*args, **kwargs)
Example #2
0
def HandlePostCompressed():
  """Request handler for posting events to the Taba Server.
  """
  with instrumentation_util.Timer('taba_post_zip') as tm:
    body = misc_util.StreamingDecompressor(bottle.request.body)

    try:
      events = model_provider.GetFrontend().ReceiveEventsStreaming(body)
    except CapacityException:
      bottle.abort(503, "Service is temporarily at capacity. Retry later.")

  LOG.info("Finished request %f, (%f) (%d) (%f)" % \
      (tm.Start, tm.ElapsedSec, events, tm.ElapsedMs / events if events else 0))
Example #3
0
def HandlePostDirect():
  """Request handler for posting events directly form the Taba Client (instead
  of the Taba Agent) to the Taba Server.
  """
  with instrumentation_util.Timer('taba_post_direct') as tm:
    body_buffer = bottle.request.body

    try:
      events = model_provider.GetFrontend().ReceiveEventsStreaming(body_buffer)
    except CapacityException:
      bottle.abort(503, "Service is temporarily at capacity. Retry later.")

  LOG.info("Finished direct request %f, (%f) (%d)" \
      % (tm.Start, tm.ElapsedSec, events))
Example #4
0
def HandlePost():
  """Request handler for receiving posted Events from a 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 Events.
  body = bottle.request.body
  try:
    client_to_names_to_events = transport.Decode(body, decode_events=False)

  except Exception:
    LOG.error("Error decoding posted data")
    LOG.error(traceback.format_exc())
    bottle.abort(400, "Could not parse document body")

  if not client_to_names_to_events:
    bottle.abort(400, "No events in POST document")

  # Add the events to the Taba Agent buffer.
  try:
    for client_id, name_events_map in client_to_names_to_events.iteritems():
      _GLOBAL_TABA_AGENT.Buffer(client_id, name_events_map)

  except Exception:
    LOG.error("Error buffering events")
    LOG.error(traceback.format_exc())
    bottle.abort(500, "Error buffering events")