Пример #1
0
 def setChannel():
     """Sets the gRPC channel connection"""
     # gRPC must specify a single host. Randomize host list to balance load across cuebots.
     hosts = list(Cuebot.Hosts)
     shuffle(hosts)
     maxMessageBytes = config.get('cuebot.max_message_bytes',
                                  DEFAULT_MAX_MESSAGE_BYTES)
     for host in hosts:
         if ':' in host:
             connectStr = host
         else:
             connectStr = '%s:%s' % (
                 host, config.get('cuebot.grpc_port', DEFAULT_GRPC_PORT))
         logger.debug('connecting to gRPC at %s', connectStr)
         # TODO(bcipriano) Configure gRPC TLS. (Issue #150)
         try:
             Cuebot.RpcChannel = grpc.insecure_channel(
                 connectStr,
                 options=[('grpc.max_send_message_length', maxMessageBytes),
                          ('grpc.max_receive_message_length',
                           maxMessageBytes)])
             # Test the connection
             Cuebot.getStub('cue').GetSystemStats(
                 cue_pb2.CueGetSystemStatsRequest(), timeout=Cuebot.Timeout)
         # pylint: disable=broad-except
         except Exception:
             logger.warning('Could not establish grpc channel with %s',
                            connectStr)
             continue
         atexit.register(Cuebot.closeChannel)
         return None
     raise ConnectionException('No grpc connection could be established. ' +
                               'Please check configured cuebot hosts.')
Пример #2
0
 def setChannel():
     """Sets the gRPC channel connection"""
     # gRPC must specify a single host. Randomize host list to balance load across cuebots.
     hosts = list(Cuebot.Hosts)
     shuffle(hosts)
     for host in hosts:
         if ':' in host:
             connect_str = host
         else:
             connect_str = '%s:%s' % (host,
                                      config.get('cuebot.grpc_port', 8443))
         logger.debug('connecting to gRPC at %s', connect_str)
         # TODO(bcipriano) Configure gRPC TLS. (Issue #150)
         try:
             Cuebot.RpcChannel = grpc.insecure_channel(connect_str)
             # Test the connection
             Cuebot.getStub('cue').GetSystemStats(
                 cue_pb2.CueGetSystemStatsRequest(), timeout=Cuebot.Timeout)
         except Exception:
             logger.warning(
                 'Could not establish grpc channel with {}.'.format(
                     connect_str))
             continue
         atexit.register(Cuebot.closeChannel)
         return None
     raise CueException('No grpc connection could be established. ' +
                        'Please check configured cuebot hosts.')
Пример #3
0
    def testGetHost(self, getStubMock):
        stubMock = mock.Mock()
        stubMock.GetSystemStats.return_value = cue_pb2.CueGetSystemStatsResponse()
        getStubMock.return_value = stubMock

        opencue.api.getSystemStats()

        stubMock.GetSystemStats.assert_called_with(
            cue_pb2.CueGetSystemStatsRequest(), timeout=mock.ANY)
Пример #4
0
def getSystemStats():
    """Returns the system stats for a random
    OpenCue server in the cluster. This is used
    mainly by admins for troubleshooting OpenCue
    problems.
    @rtype: SystemStats
    @return: a struct of OpenCue application information."""
    return Cuebot.getStub('cue').GetSystemStats(
        cue_pb2.CueGetSystemStatsRequest(), timeout=Cuebot.Timeout).stats
Пример #5
0
    def setChannel():
        """Sets the gRPC channel connection"""
        # gRPC must specify a single host. Randomize host list to balance load across cuebots.
        hosts = list(Cuebot.Hosts)
        shuffle(hosts)
        maxMessageBytes = Cuebot.Config.get('cuebot.max_message_bytes',
                                            DEFAULT_MAX_MESSAGE_BYTES)

        # create interceptors
        interceptors = (RetryOnRpcErrorClientInterceptor(
            max_attempts=4,
            sleeping_policy=ExponentialBackoff(init_backoff_ms=100,
                                               max_backoff_ms=1600,
                                               multiplier=2),
            status_for_retry=(grpc.StatusCode.UNAVAILABLE, ),
        ), )

        for host in hosts:
            if ':' in host:
                connectStr = host
            else:
                connectStr = '%s:%s' % (
                    host,
                    Cuebot.Config.get('cuebot.grpc_port', DEFAULT_GRPC_PORT))
            # pylint: disable=logging-not-lazy
            logger.debug('connecting to gRPC at %s' % connectStr)
            # pylint: enable=logging-not-lazy
            # TODO(bcipriano) Configure gRPC TLS. (Issue #150)
            try:
                Cuebot.RpcChannel = grpc.intercept_channel(
                    grpc.insecure_channel(
                        connectStr,
                        options=[('grpc.max_send_message_length',
                                  maxMessageBytes),
                                 ('grpc.max_receive_message_length',
                                  maxMessageBytes)]), *interceptors)
                # Test the connection
                Cuebot.getStub('cue').GetSystemStats(
                    cue_pb2.CueGetSystemStatsRequest(), timeout=Cuebot.Timeout)
            # pylint: disable=broad-except
            except Exception:
                logger.warning('Could not establish grpc channel with %s',
                               connectStr)
                continue
            atexit.register(Cuebot.closeChannel)
            return None
        raise ConnectionException('No grpc connection could be established. ' +
                                  'Please check configured cuebot hosts.')