Ejemplo n.º 1
0
 def _make_response_packet(
     request_id: str,
     from_id: str,
     entity: str,
     result: object,
     error: object,
     failed: bool,
     old_api=None,
     replacement_api=None,
 ):
     if error:
         payload = {"request_id": request_id, "error": error, "failed": failed}
     else:
         payload = {"request_id": request_id, "result": result}
     if old_api:
         payload["old_api"] = old_api
         if replacement_api:
             payload["replacement_api"] = replacement_api
     packet = {
         "pid": unique_hex(),
         "to": from_id,
         "entity": entity,
         "type": _Service._RES_PKT_STR,
         "payload": payload,
     }
     return packet
Ejemplo n.º 2
0
 def _make_response_packet(request_id: str,
                           from_id: str,
                           entity: str,
                           result: object,
                           error: object,
                           failed: bool,
                           old_api=None,
                           replacement_api=None):
     if error:
         payload = {
             'request_id': request_id,
             'error': error,
             'failed': failed
         }
     else:
         payload = {'request_id': request_id, 'result': result}
     if old_api:
         payload['old_api'] = old_api
         if replacement_api:
             payload['replacement_api'] = replacement_api
     packet = {
         'pid': unique_hex(),
         'to': from_id,
         'entity': entity,
         'type': _Service._RES_PKT_STR,
         'payload': payload
     }
     return packet
Ejemplo n.º 3
0
 def register(self, ip, port, service, version, vendors, service_type):
     self._service_host = ip
     self._service_port = port
     self._service = service
     self._version = version
     self._node_id = '{}_{}_{}'.format(service, version, unique_hex())
     packet = ControlPacket.registration(ip, port, self._node_id, service, version, vendors, service_type)
     self._protocol.send(packet)
Ejemplo n.º 4
0
 def register(self, ip, port, service, version, vendors, service_type):
     self._service_host = ip
     self._service_port = port
     self._service = service
     self._version = version
     self._node_id = '{}_{}_{}'.format(service, version, unique_hex())
     packet = ControlPacket.registration(ip, port, self._node_id, service,
                                         version, vendors, service_type)
     self._protocol.send(packet)
Ejemplo n.º 5
0
 def fun(fut):
     for node in fut.result():
         packet['to'] = node['node_id']
         pid = unique_hex()
         packet['pid'] = pid
         self._unacked_publish[pid] = packet
         coro = asyncio.get_event_loop().create_connection(self._host_factory, node['ip'], node['port'])
         connect_future = asyncio.async(coro)
         connect_future.add_done_callback(partial(send_publish_packet, packet))
Ejemplo n.º 6
0
 def _make_registration_packet(self, ip: str, port: str, service: str,
                               version: str, vendors, type: str):
     vendors_list = []
     for vendor in vendors:
         vendor_dict = {'service': vendor.name, 'version': vendor.version}
         vendors_list.append(vendor_dict)
     self._node_id = '{}_{}_{}'.format(service, version, unique_hex())
     params = {
         'service': service,
         'version': version,
         'host': ip,
         'port': port,
         'node_id': self._node_id,
         'vendors': vendors_list,
         'type': type
     }
     packet = {'pid': unique_hex(), 'type': 'register', 'params': params}
     return packet
Ejemplo n.º 7
0
 def wrapper(self, *args, **kwargs):
     params = func(self, *args, **kwargs)
     self = params.pop('self', None)
     entity = params.pop('entity', None)
     app_name = params.pop('app_name', None)
     request_id = unique_hex()
     params['request_id'] = request_id
     future = self._send_request(app_name, endpoint=func.__name__, entity=entity, params=params)
     return future
Ejemplo n.º 8
0
 def resolve_publication(self, service, version, endpoint):
     future = Future()
     request_id = unique_hex()
     packet = {'type': 'resolve_publication', 'request_id': request_id}
     params = {'service': service, 'version': version, 'endpoint': endpoint}
     packet['params'] = params
     self._pending_requests[request_id] = future
     self._protocol.send(packet)
     return future
Ejemplo n.º 9
0
 def _make_get_instance_packet(self, service, version):
     params = {'service': service,
               'version': version}
     packet = {'pid': unique_hex(),
               'type': 'get_instances',
               'service': self._service,
               'version': self._version,
               'params': params}
     return packet
Ejemplo n.º 10
0
 def _make_registration_packet(self, ip:str, port:str, service:str, version:str, vendors, type:str):
     vendors_list = []
     for vendor in vendors:
         vendor_dict = {'service': vendor.name,
                        'version': vendor.version}
         vendors_list.append(vendor_dict)
     self._node_id = unique_hex()
     params = {'service': service,
               'version': version,
               'host': ip,
               'port': port,
               'node_id': self._node_id,
               'vendors': vendors_list,
               'type': type}
     packet = {'pid': unique_hex(),
               'type': 'register',
               'params': params}
     return packet
Ejemplo n.º 11
0
 def _make_get_instance_packet(self, service, version):
     params = {'service': service, 'version': version}
     packet = {
         'pid': unique_hex(),
         'type': 'get_instances',
         'service': self._service,
         'version': self._version,
         'params': params
     }
     return packet
Ejemplo n.º 12
0
 def _make_death_subscription_packet(self, service:str, version:str, node_id:str):
     params = {'service': service,
               'version': version}
     packet = {'pid': unique_hex(),
               'type': 'service_death_sub',
               'service': self._service,
               'version': self._version,
               'params': params,
               'node': node_id}
     return packet
Ejemplo n.º 13
0
 def _make_packet(self, app_name, packet_type, endpoint, params, entity):
     packet = {'pid': unique_hex(),
               'app': app_name,
               'service': self.name,
               'version': self.version,
               'entity': entity,
               'endpoint': endpoint,
               'type': packet_type,
               'payload': params}
     return packet
Ejemplo n.º 14
0
 def __init__(self, registry_client):
     self._registry_client = registry_client
     self._client_protocols = {}
     self._pingers = {}
     self._node_clients = {}
     self._service_clients = []
     self._pending_requests = []
     self.tcp_host = None
     self.http_host = None
     self._host_id = unique_hex()
     self._ronin = False
     self._registered = False
Ejemplo n.º 15
0
    def _make_response_packet(self, request_id: str, from_id: str, entity: str, result: object, error: object):
        if error:
            payload = {'request_id': request_id, 'error': error}
        else:
            payload = {'request_id': request_id, 'result': result}

        packet = {'pid': unique_hex(),
                  'to': from_id,
                  'entity': entity,
                  'type': _Service._RES_PKT_STR,
                  'payload': payload}
        return packet
Ejemplo n.º 16
0
 def _make_packet(self, app_name, packet_type, endpoint, params, entity):
     packet = {
         'pid': unique_hex(),
         'app': app_name,
         'service': self.name,
         'version': self.version,
         'entity': entity,
         'endpoint': endpoint,
         'type': packet_type,
         'payload': params
     }
     return packet
Ejemplo n.º 17
0
 def __init__(self, registry_client):
     self._registry_client = registry_client
     self._client_protocols = {}
     self._pingers = {}
     self._node_clients = {}
     self._service_clients = []
     self._pending_requests = []
     self.tcp_host = None
     self.http_host = None
     self._host_id = unique_hex()
     self._ronin = False
     self._registered = False
Ejemplo n.º 18
0
 def wrapper(self, *args, **kwargs):
     params = func(self, *args, **kwargs)
     self = params.pop('self')
     entity = params.pop('entity', None)
     try:
         app_name = params.pop('app_name')
     except KeyError:
         raise RuntimeError('App name must be specified')
     request_id = unique_hex()
     params['request_id'] = request_id
     future = self._send_request(app_name, endpoint=func.__name__, entity=entity, params=params)
     return future
Ejemplo n.º 19
0
 def _make_death_subscription_packet(self, service: str, version: str,
                                     node_id: str):
     params = {'service': service, 'version': version}
     packet = {
         'pid': unique_hex(),
         'type': 'service_death_sub',
         'service': self._service,
         'version': self._version,
         'params': params,
         'node': node_id
     }
     return packet
Ejemplo n.º 20
0
 def wrapper(self, *args, **kwargs):
     params = func(self, *args, **kwargs)
     self = params.pop('self', None)
     entity = params.pop('entity', None)
     app_name = params.pop('app_name', None)
     request_id = unique_hex()
     params['request_id'] = request_id
     future = self._send_request(app_name,
                                 endpoint=func.__name__,
                                 entity=entity,
                                 params=params)
     return future
Ejemplo n.º 21
0
 def __init__(self, registry_client):
     registry_client.conn_handler = self
     self._registry_client = registry_client
     self._client_protocols = {}
     self._pingers = {}
     self._node_clients = {}
     self._service_clients = []
     self.tcp_host = None
     self.http_host = None
     self._host_id = unique_hex()
     self._ronin = False
     self._registered = False
     self._logger = logging.getLogger(__name__)
Ejemplo n.º 22
0
    def __init__(self):

        self._registry_client = None

        self._client_protocols = {}
        self._service_clients = []

        self._pending_requests = []
        self._unacked_publish = {}

        self._tcp_host = None
        self._http_host = None
        self._host_id = unique_hex()
Ejemplo n.º 23
0
 def resolve_publication(self, service, version, endpoint):
     future = Future()
     request_id = unique_hex()
     packet = {'type': 'resolve_publication', 'request_id': request_id}
     params = {
         'service': service,
         'version': version,
         'endpoint': endpoint
     }
     packet['params'] = params
     self._pending_requests[request_id] = future
     self._protocol.send(packet)
     return future
Ejemplo n.º 24
0
 def __init__(self, registry_client):
     registry_client.conn_handler = self
     self._registry_client = registry_client
     self._client_protocols = {}
     self._pingers = {}
     self._node_clients = {}
     self._service_clients = []
     self.tcp_host = None
     self.http_host = None
     self._host_id = unique_hex()
     self._ronin = False
     self._registered = False
     self._logger = logging.getLogger(__name__)
Ejemplo n.º 25
0
    def _make_response_packet(request_id: str, from_id: str, entity: str, result: object, error: object):
        if error:
            payload = {"request_id": request_id, "error": error}
        else:
            payload = {"request_id": request_id, "result": result}

        packet = {
            "pid": unique_hex(),
            "to": from_id,
            "entity": entity,
            "type": _Service._RES_PKT_STR,
            "payload": payload,
        }
        return packet
Ejemplo n.º 26
0
    def _make_response_packet(self, request_id: str, from_id: str, entity: str,
                              result: object, error: object):
        if error:
            payload = {'request_id': request_id, 'error': error}
        else:
            payload = {'request_id': request_id, 'result': result}

        packet = {
            'pid': unique_hex(),
            'to': from_id,
            'entity': entity,
            'type': _Service._RES_PKT_STR,
            'payload': payload
        }
        return packet
Ejemplo n.º 27
0
 def __init__(self, registry_host:str, registry_port:int):
     self._registry_host = registry_host
     self._registry_port = registry_port
     self._loop = asyncio.get_event_loop()
     self._client_protocols = {}
     self._service_clients = []
     self._death_listeners = set()
     self._pending_requests = []
     # TODO : replace with shelve
     self._unacked_publish = {}
     self._tcp_host = None
     self._http_host = None
     self._tcp_server = None
     self._http_server = None
     self._host_id = unique_hex()
Ejemplo n.º 28
0
 def _make_response_packet(request_id: str, from_id: str, entity: str, result: object, error: object,
                           old_api=None, replacement_api=None):
     if error:
         payload = {'request_id': request_id, 'error': error}
     else:
         payload = {'request_id': request_id, 'result': result}
     if (old_api):
         payload['old_api'] = old_api
         if (replacement_api):
             payload['replacement_api'] = replacement_api
     packet = {'pid': unique_hex(),
               'to': from_id,
               'entity': entity,
               'type': _Service._RES_PKT_STR,
               'payload': payload}
     return packet
Ejemplo n.º 29
0
 def _make_response_packet(request_id: str, from_id: str, entity: str, result: object, error: object,
                           failed: bool, old_api=None, replacement_api=None):
     from .services import _Service
     if failed:
         payload = {'request_id': request_id, 'error': error, 'failed': failed}
     else:
         payload = {'request_id': request_id, 'result': result}
     if old_api:
         payload['old_api'] = old_api
         if replacement_api:
             payload['replacement_api'] = replacement_api
     packet = {'pid': unique_hex(),
               'to': from_id,
               'entity': entity,
               'type': _Service._RES_PKT_STR,
               'payload': payload}
     return packet
Ejemplo n.º 30
0
 def __init__(self, registry_client):
     registry_client.conn_handler = self
     self._registry_client = registry_client
     self._client_protocols = {}
     self._pingers = {}
     self._node_clients = {}
     self._service_clients = []
     self.tcp_host = None
     self.http_host = None
     self._host_id = unique_hex()
     self._ronin = False
     self._registered = False
     self.pubsub = None
     self._logger = logging.getLogger(__name__)
     tcp_connector = aiohttp.TCPConnector(
         conn_timeout=CONFIG.HTTP_TIMEOUT,
         keepalive_timeout=CONFIG.HTTP_KEEP_ALIVE_TIMEOUT)
     self._aiohttp_session = aiohttp.ClientSession(connector=tcp_connector)
Ejemplo n.º 31
0
    def __init__(self):

        self._registry_client = None

        self._client_protocols = {}
        self._pingers = {}
        self._service_clients = []
        self._node_clients = {}

        self._pending_requests = []
        self._unacked_publish = {}

        self._tcp_host = None
        self._http_host = None
        self._host_id = unique_hex()
        self._pubsub_handler = None
        self._ronin = False
        self._registered = False
Ejemplo n.º 32
0
    def __init__(self):

        self._registry_client = None

        self._client_protocols = {}
        self._service_clients = []

        self._death_listeners = set()

        self._pending_requests = []
        # TODO : replace with shelve
        self._unacked_publish = {}

        self._tcp_host = None
        self._http_host = None
        self._tcp_server = None
        self._http_server = None
        self._host_id = unique_hex()
Ejemplo n.º 33
0
 def _make_activated_packet(self, vendors):
     vendors_packet = []
     for vendor in vendors:
         vendor_packet = defaultdict(list)
         vendor_name = self._get_full_service_name(vendor['service'],
                                                   vendor['version'])
         for host, port, node, service_type in self._registered_services[
                 vendor_name]:
             vendor_node_packet = {
                 'host': host,
                 'port': port,
                 'node_id': node,
                 'type': service_type
             }
             vendor_packet['name'] = vendor_name
             vendor_packet['addresses'].append(vendor_node_packet)
         vendors_packet.append(vendor_packet)
     params = {'vendors': vendors_packet}
     packet = {'pid': unique_hex(), 'type': 'registered', 'params': params}
     return packet
Ejemplo n.º 34
0
 def _make_activated_packet(self, vendors):
     vendors_packet = []
     for vendor in vendors:
         vendor_packet = defaultdict(list)
         vendor_name = self._get_full_service_name(vendor['service'], vendor['version'])
         for host, port, node in self._registered_services[vendor_name]:
             vendor_node_packet = {
                 'host': host,
                 'port': port,
                 'node_id': node
             }
             vendor_packet['name'] = vendor_name
             vendor_packet['addresses'].append(vendor_node_packet)
         vendors_packet.append(vendor_packet)
     params = {
         'vendors': vendors_packet
     }
     packet = {'pid': unique_hex(),
               'type': 'registered',
               'params': params}
     return packet
Ejemplo n.º 35
0
 def _make_response_packet(request_id: str, from_id: str, entity: str, result: object, error: object,
                           failed: bool, old_api=None, replacement_api=None, 
                           host=socket.gethostbyname(socket.gethostname()), service_name='',
                           method=''):
     if error:
         payload = {'request_id': request_id, 'error': error, 'failed': failed}
     else:
         payload = {'request_id': request_id, 'result': result}
     if old_api:
         payload['old_api'] = old_api
         if replacement_api:
             payload['replacement_api'] = replacement_api
     packet = {'pid': unique_hex(),
               'from': service_name,
               'endpoint': method,
               'to': from_id,
               'host': host,
               'entity': entity,
               'type': _Service._RES_PKT_STR,
               'payload': payload}
     return packet
Ejemplo n.º 36
0
 def __init__(self, service_name, service_version, host_ip, host_port):
     super(_ServiceHost, self).__init__(service_name, service_version)
     self._node_id = unique_hex()
     self._ip = host_ip
     self._port = host_port
     self._clients = []
Ejemplo n.º 37
0
 def __init__(self, service_name, service_version, host_ip, host_port):
     super(_ServiceHost, self).__init__(service_name, service_version)
     self._node_id = unique_hex()
     self._ip = host_ip
     self._port = host_port
     self._clients = []