Exemplo n.º 1
0
 def cancelled(failure):
     failure.trap(CancelledError)
     raise exceptions.NoConnectionsAvailable(
         "Unable to connect to rack controller %s; no connections "
         "available." % system_id,
         uuid=system_id,
     )
Exemplo n.º 2
0
 def getRandomClient(self):
     """Return a random connected :class:`RackClient`."""
     connections = list(self.connections.values())
     if len(connections) == 0:
         raise exceptions.NoConnectionsAvailable(
             "Unable to connect to any rack controller; no connections "
             "available.")
     else:
         connection = random.choice(connections)
         # The connection object is a set of RegionServer objects.
         # Make sure a sane set was returned.
         assert len(connection) > 0, "Connection set empty."
         connection = random.choice(list(connection))
         return RackClient(connection, self.connectionsCache[connection])
Exemplo n.º 3
0
def getClientFromIdentifiers(identifiers, timeout=0):
    """Get a client with which to make RPCs to any one of the `identifiers`.

    :param timeout: The number of seconds to wait before giving up on
        getting a connection. By default, `timeout` is 0.
    :raises: :py:class:`~.exceptions.NoConnectionsAvailable` when there
        are no open connections to any rack controllers.
    """
    try:
        service = eventloop.services.getServiceNamed("rpc")
    except KeyError:
        raise exceptions.NoConnectionsAvailable(
            "Unable to connect to any rack controller %s; no connections "
            "available." % ",".join(identifiers))
    else:
        return service.getClientFromIdentifiers(identifiers, timeout=timeout)
Exemplo n.º 4
0
def getRegionClient():
    """getRegionClient()

    Get a client with which to make RPCs to the region.

    :raises: :py:class:`~.exceptions.NoConnectionsAvailable` when there
        are no open connections to the region controller.
    """
    # TODO: retry a couple of times before giving up if the service is
    # not running or if exceptions.NoConnectionsAvailable gets raised.
    try:
        rpc_service = provisioningserver.services.getServiceNamed("rpc")
    except KeyError:
        raise exceptions.NoConnectionsAvailable(
            "Cluster services are unavailable.")
    else:
        return rpc_service.getClient()
Exemplo n.º 5
0
def getClientFor(uuid, timeout=0):
    """Get a client with which to make RPCs to the specified rack controller.

    :param timeout: The number of seconds to wait before giving up on
        getting a connection. By default, `timeout` is 0.
    :raises: :py:class:`~.exceptions.NoConnectionsAvailable` when there
        are no open connections to the specified cluster controller.
    """
    try:
        service = eventloop.services.getServiceNamed("rpc")
    except KeyError:
        raise exceptions.NoConnectionsAvailable(
            "Unable to connect to rack controller %s; no connections "
            "available." % uuid,
            uuid=uuid)
    else:
        return service.getClientFor(uuid, timeout=timeout)
Exemplo n.º 6
0
 def cancelled(failure):
     failure.trap(CancelledError)
     raise exceptions.NoConnectionsAvailable(
         "Unable to connect to any rack controller %s; no connections "
         "available." % ",".join(identifiers))
Exemplo n.º 7
0
 def getClientNow(self):
     raise exceptions.NoConnectionsAvailable()