2014-11-13 19:42:16 +03:00
|
|
|
#!/usr/bin/env python
|
2015-08-31 06:22:16 +03:00
|
|
|
"""Base class for protocols flavor.
|
|
|
|
|
|
|
|
Each set of protocols has a flavor name. Derived classes should call
|
|
|
|
register_flavor when they are imported.
|
|
|
|
"""
|
2014-11-13 19:42:16 +03:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2015-08-26 08:45:44 +03:00
|
|
|
|
2014-11-13 19:42:16 +03:00
|
|
|
class ProtocolsFlavor(object):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""Base class for protocols flavor."""
|
2014-11-13 19:42:16 +03:00
|
|
|
|
2015-06-24 23:01:06 +03:00
|
|
|
def binlog_player_protocol(self):
|
2015-10-20 01:45:44 +03:00
|
|
|
"""Tdthe binlog player protocol between vttablets, in go."""
|
2015-07-16 22:51:59 +03:00
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
|
|
|
|
|
|
|
def binlog_player_python_protocol(self):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""The binlog player protocol in for python connections.
|
|
|
|
|
|
|
|
This is for python connections to update_stream service.
|
|
|
|
"""
|
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-08-31 06:22:16 +03:00
|
|
|
"""The protocol to use for vtctl connections.
|
|
|
|
|
|
|
|
This is just for the go client.
|
|
|
|
"""
|
2015-07-06 21:54:04 +03:00
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
|
|
|
|
|
|
|
def vtctl_python_client_protocol(self):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""The protocol to use for vtctl connections.
|
|
|
|
|
|
|
|
This is just for the python client.
|
|
|
|
"""
|
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-30 16:05:05 +03:00
|
|
|
def vtworker_client_protocol(self):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""The protocol to use for vtworker connections."""
|
2015-06-30 16:05:05 +03:00
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
|
|
|
|
2015-06-27 01:17:35 +03:00
|
|
|
def tablet_manager_protocol(self):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""The protocol to use for 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):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""The protocol to use for connections from vtctl/vtgate to vttablet."""
|
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-07-21 19:07:34 +03:00
|
|
|
def vtgate_protocol(self):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""The protocol to use to talk to vtgate, in go."""
|
2015-07-28 01:36:30 +03:00
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
|
|
|
|
|
|
|
def vtgate_python_protocol(self):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""The protocol to use to talk to vtgate with python clients."""
|
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):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""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
|
|
|
|
2015-06-20 00:01:03 +03:00
|
|
|
def service_map(self):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""A list of entries to enable all relevant protocols in all servers."""
|
2015-06-20 00:01:03 +03:00
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
|
|
|
|
2015-10-09 23:47:41 +03:00
|
|
|
def vttest_protocol(self):
|
|
|
|
"""Python protocol to use to talk to a vttest client."""
|
|
|
|
raise NotImplementedError('Not implemented in the base class')
|
|
|
|
|
2015-06-20 00:01:03 +03:00
|
|
|
|
2015-07-15 20:48:06 +03:00
|
|
|
__knows_protocols_flavor_map = {}
|
2014-11-13 19:42:16 +03:00
|
|
|
__protocols_flavor = None
|
|
|
|
|
2015-08-26 04:54:04 +03:00
|
|
|
|
2014-11-13 19:42:16 +03:00
|
|
|
def protocols_flavor():
|
|
|
|
return __protocols_flavor
|
|
|
|
|
2015-08-26 04:54:04 +03:00
|
|
|
|
2014-11-13 19:42:16 +03:00
|
|
|
def set_protocols_flavor(flavor):
|
2015-08-31 06:22:16 +03:00
|
|
|
"""Set the protocols flavor by flavor name."""
|
2014-11-13 19:42:16 +03:00
|
|
|
global __protocols_flavor
|
|
|
|
|
|
|
|
if not flavor:
|
|
|
|
flavor = 'gorpc'
|
|
|
|
|
2015-08-31 06:22:16 +03:00
|
|
|
cls = __knows_protocols_flavor_map.get(flavor, None)
|
|
|
|
if not cls:
|
2014-11-13 19:42:16 +03:00
|
|
|
logging.error('Unknown protocols flavor %s', flavor)
|
|
|
|
exit(1)
|
2015-08-31 06:22:16 +03:00
|
|
|
__protocols_flavor = cls()
|
2014-11-13 19:42:16 +03:00
|
|
|
|
|
|
|
logging.debug('Using protocols flavor %s', flavor)
|
2015-08-30 19:32:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
def register_flavor(key, cls):
|
|
|
|
__knows_protocols_flavor_map[key] = cls
|