Пример #1
0
Файл: api.py Проект: ziq211/hue
 def decorator(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except StructuredThriftTransportException as e:
         if not is_ha_enabled():
             raise PopupException(_(
                 'Failed to connect to Sentry server %s, and Sentry HA is not enabled.'
             ) % args[0].client.host,
                                  detail=e)
         else:
             LOG.warn(
                 "Failed to connect to Sentry server %s, will attempt to find next available host."
                 % args[0].client.host)
             server, attempts = get_next_available_server(
                 SentryClient, args[0].client.username, args[0].client.host)
             if server is not None:
                 args[0].client = create_client(SentryClient,
                                                args[0].client.username,
                                                server)
                 set_api_cache(server)
                 return func(*args, **kwargs)
             else:
                 raise PopupException(
                     _('Failed to find an available Sentry server.'))
     except (SentryException, PopupException) as e:
         raise e
     except Exception as e:
         raise PopupException(
             _('Encountered unexpected error in SentryApi.'), detail=e)
Пример #2
0
def get_api(user, component):
    if component == 'solr':
        component = component.upper()

    server = get_cached_server()
    client = create_client(SentryClient, user.username, server, component)
    return SentryApi(client)
Пример #3
0
 def decorator(*args, **kwargs):
   try:
     return func(*args, **kwargs)
   except StructuredThriftTransportException, e:
     if not is_ha_enabled():
       raise PopupException(_('Failed to connect to Sentry server %s, and Sentry HA is not enabled.') % args[0].client.host, detail=e)
     else:
       LOG.warn("Failed to connect to Sentry server %s, will attempt to find next available host." % args[0].client.host)
       server, attempts = get_next_available_server(client_class=SentryClient, username=args[0].client.username, failed_host=args[0].client.host, component=args[0].client.component)
       if server is not None:
         args[0].client = create_client(SentryClient, args[0].client.username, server, args[0].client.component)
         set_api_cache(server)
         return func(*args, **kwargs)
       else:
         raise PopupException(_('Failed to find an available Sentry server.'))
Пример #4
0
Файл: api.py Проект: ziq211/hue
def get_api(user):
    server = get_cached_server()
    client = create_client(SentryClient, user.username, server)
    return SentryApi(client)