2014-11-13 19:42:16 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
class ProtocolsFlavor(object):
|
|
|
|
"""Base class for protocols"""
|
|
|
|
|
|
|
|
def binlog_player_protocol_flags(self):
|
|
|
|
"""Returns the flags to pass to process to set the binlog player protocol."""
|
2015-06-18 18:14:01 +03:00
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
2014-11-13 19:42:16 +03:00
|
|
|
|
|
|
|
def vtctl_client_protocol(self):
|
2015-06-18 18:14:01 +03:00
|
|
|
"""Returns the protocol to use for vtctl connections.
|
|
|
|
Needs to be supported both in python and go."""
|
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
2014-11-13 19:42:16 +03:00
|
|
|
|
|
|
|
def tablet_manager_protocol_flags(self):
|
|
|
|
"""Returns the flags to use for specifying the tablet manager protocol."""
|
2015-06-18 18:14:01 +03:00
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
2014-11-13 19:42:16 +03:00
|
|
|
|
2015-06-18 18:14:01 +03:00
|
|
|
def tabletconn_protocol(self):
|
|
|
|
"""Returns the protocol to use for connections from vtctl/vtgate to
|
|
|
|
vttablet."""
|
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
2014-11-13 19:42:16 +03:00
|
|
|
|
2015-05-28 23:00:25 +03:00
|
|
|
def vtgate_protocol_flags(self):
|
|
|
|
"""Returns the flags to use for specifying the vtgate protocol."""
|
2015-06-18 18:14:01 +03:00
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
2015-05-28 23:00:25 +03:00
|
|
|
|
2014-11-18 18:09:11 +03:00
|
|
|
def rpc_timeout_message(self):
|
|
|
|
"""Returns the error message used by the protocol to indicate a timeout."""
|
2015-06-18 18:14:01 +03:00
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
2014-11-18 18:09:11 +03:00
|
|
|
|
2014-11-14 12:22:06 +03:00
|
|
|
class GoRpcProtocolsFlavor(ProtocolsFlavor):
|
2014-11-13 19:42:16 +03:00
|
|
|
"""Overrides to use go rpc everywhere"""
|
|
|
|
|
|
|
|
def binlog_player_protocol_flags(self):
|
|
|
|
return ['-binlog_player_protocol', 'gorpc']
|
|
|
|
|
|
|
|
def vtctl_client_protocol(self):
|
|
|
|
return 'gorpc'
|
|
|
|
|
|
|
|
def tablet_manager_protocol_flags(self):
|
|
|
|
return ['-tablet_manager_protocol', 'bson']
|
|
|
|
|
2015-06-18 18:14:01 +03:00
|
|
|
def tabletconn_protocol(self):
|
|
|
|
return 'gorpc'
|
2014-11-13 19:42:16 +03:00
|
|
|
|
2015-05-28 23:00:25 +03:00
|
|
|
def vtgate_protocol_flags(self):
|
|
|
|
return ['-vtgate_protocol', 'gorpc']
|
|
|
|
|
2014-11-18 18:09:11 +03:00
|
|
|
def rpc_timeout_message(self):
|
2014-12-15 22:17:25 +03:00
|
|
|
return 'timeout waiting for'
|
2014-11-18 18:09:11 +03:00
|
|
|
|
2015-02-28 01:24:04 +03:00
|
|
|
class GRpcProtocolsFlavor(ProtocolsFlavor):
|
|
|
|
"""Overrides to use gRPC everywhere where it is supported.
|
|
|
|
If not supported yet, use GoRPC."""
|
|
|
|
|
|
|
|
def binlog_player_protocol_flags(self):
|
|
|
|
return ['-binlog_player_protocol', 'gorpc']
|
|
|
|
|
|
|
|
def vtctl_client_protocol(self):
|
|
|
|
return 'grpc'
|
|
|
|
|
|
|
|
def tablet_manager_protocol_flags(self):
|
|
|
|
return ['-tablet_manager_protocol', 'bson']
|
|
|
|
|
2015-06-18 18:14:01 +03:00
|
|
|
def tabletconn_protocol(self):
|
|
|
|
return 'grpc'
|
2015-02-28 01:24:04 +03:00
|
|
|
|
2015-05-28 23:00:25 +03:00
|
|
|
def vtgate_protocol_flags(self):
|
|
|
|
return ['-vtgate_protocol', 'gorpc']
|
|
|
|
|
2015-02-28 01:24:04 +03:00
|
|
|
def rpc_timeout_message(self):
|
|
|
|
return 'timeout waiting for'
|
|
|
|
|
2014-11-13 19:42:16 +03:00
|
|
|
__knows_protocols_flavor_map = {
|
|
|
|
'gorpc': GoRpcProtocolsFlavor,
|
2015-02-28 01:24:04 +03:00
|
|
|
'grpc': GRpcProtocolsFlavor,
|
2014-11-13 19:42:16 +03:00
|
|
|
}
|
|
|
|
__protocols_flavor = None
|
|
|
|
|
|
|
|
def protocols_flavor():
|
|
|
|
return __protocols_flavor
|
|
|
|
|
|
|
|
def set_protocols_flavor(flavor):
|
|
|
|
global __protocols_flavor
|
|
|
|
|
|
|
|
if not flavor:
|
|
|
|
flavor = 'gorpc'
|
|
|
|
|
|
|
|
klass = __knows_protocols_flavor_map.get(flavor, None)
|
|
|
|
if not klass:
|
|
|
|
logging.error('Unknown protocols flavor %s', flavor)
|
|
|
|
exit(1)
|
|
|
|
__protocols_flavor = klass()
|
|
|
|
|
|
|
|
logging.debug('Using protocols flavor %s', flavor)
|