예제 #1
0
    def on_start(self):
        super(WebServiceInterface, self).on_start()
        setup_logger('werkzeug')
        setup_logger('gevent')
        if self.uses_static_port:
            try:
                socket_fd = self.container.get_shared_socket_fd(self.http_port)
            except NoSharedSockets:
                pass
            except SocketNotCreated:
                logger.warning(
                    "socket for port %s wasn't created by node, binding from instance instead",
                    self.http_port)
            else:
                self.http_socket = sockets.create_socket('fd://%s' % socket_fd)
        if not self.http_socket:
            address = '%s:%s' % (self.container.server.ip, self.http_port)
            self.http_socket = sockets.create_socket(address)
        self.wsgi_server = LymphWSGIServer(self.http_socket,
                                           self.application,
                                           spawn=Group(self.pool_size))
        self.wsgi_server.start()

        web_instance = ServiceInstance(
            identity=self.container.identity,
            hostname=socket.gethostname(),
            ip=self.container.server.ip,
            http_port=self.http_port,
        )
        self.container.service_registry.register(self.name,
                                                 web_instance,
                                                 namespace='http')
예제 #2
0
 def lookup(self, address, version=None):
     if '://' not in address:
         service = self.service_registry.get(address)
     else:
         instance = ServiceInstance(address)
         service = Service(address, instances=[instance])
     if version:
         service = service.match_version(version)
     return service
예제 #3
0
 def register(self):
     for interface in self.iter_interfaces():
         if not interface.should_register():
             continue
         instance = ServiceInstance(
             **self.get_instance_description(interface))
         try:
             self.service_registry.register(interface.name, instance)
         except RegistrationFailure:
             logger.error("registration failed %s, %s", interface.name,
                          interface)
             self.stop()
예제 #4
0
파일: container.py 프로젝트: lnenov/lymph
    def start(self, register=True):
        logger.info('starting %s (%s) at %s (pid=%s)', self.service_name,
                    ', '.join(self.service_types), self.endpoint, os.getpid())

        self.on_start()
        self.metrics_aggregator.add_tags(identity=self.identity)

        if register:
            for interface_name, interface in six.iteritems(
                    self.installed_interfaces):
                if not interface.register_with_coordinator:
                    continue
                instance = ServiceInstance(
                    **self.get_instance_description(interface))
                try:
                    self.service_registry.register(interface_name, instance)
                except RegistrationFailure:
                    logger.error("registration failed %s, %s", interface_name,
                                 interface)
                    self.stop()
예제 #5
0
파일: container.py 프로젝트: lnenov/lymph
 def lookup(self, address):
     if '://' not in address:
         return self.service_registry.get(address)
     instance = ServiceInstance(address)
     return Service(address, instances=[instance])
예제 #6
0
 def lookup(self, address):
     if address.startswith('lymph://'):
         service_type = address[8:]
         return self.service_registry.get(self, service_type)
     return ServiceInstance(self, address)