Ejemplo n.º 1
0
Archivo: ipc.py Proyecto: whaker/zato
    def start_connector(self, ipc_tcp_start_port, timeout=5):
        """ Starts an HTTP server acting as an connector process. Its port will be greater than ipc_tcp_start_port,
        which is the starting point to find a free port from.
        """
        if self.check_enabled:
            self._check_enabled()

        self.ipc_tcp_port = get_free_port(ipc_tcp_start_port)
        logger.info('Starting {} connector for server `%s` on `%s`'.format(self.connector_name),
            self.server.name, self.ipc_tcp_port)

        # Credentials for both servers and connectors
        username, password = self.get_credentials()

        # Employ IPC to exchange subprocess startup configuration
        self.server.connector_config_ipc.set_config(self.ipc_config_name, dumps({
            'port': self.ipc_tcp_port,
            'username': username,
            'password': password,
            'server_port': self.server.port,
            'server_name': self.server.name,
            'server_path': '/zato/internal/callback/{}'.format(self.callback_suffix),
            'base_dir': self.server.base_dir,
            'needs_pidfile': not self.server.has_fg,
            'pidfile_suffix': self.pidfile_suffix,
            'logging_conf_path': self.server.logging_conf_path
        }))

        # Start connector in a sub-process
        start_python_process('{} connector'.format(self.connector_name), False, self.connector_module, '', extra_options={
            'deployment_key': self.server.deployment_key,
            'shmem_size': self.server.shmem_size
        })

        # Wait up to timeout seconds for the connector to start as indicated by its responding to a PING request
        now = datetime.utcnow()
        warn_after = now + timedelta(seconds=3)
        should_warn = False
        until = now + timedelta(seconds=timeout)
        is_ok = False
        address = address_pattern.format(self.ipc_tcp_port, 'ping')
        auth = self.get_credentials()

        while not is_ok or now >= until:
            if not should_warn:
                if now >= warn_after:
                    should_warn = True
            is_ok = self._ping_connector(address, auth, should_warn)
            if is_ok:
                break
            else:
                sleep(2)
                now = datetime.utcnow()

        if not is_ok:
            logger.warn('{} connector (%s) could not be started after %s'.format(self.connector_name), address, timeout)
        else:
            return is_ok
Ejemplo n.º 2
0
    def start_websphere_mq_connector(self, ipc_tcp_start_port, timeout=5):
        """ Starts an HTTP server acting as a WebSphere MQ connector. Its port will be greater than ipc_tcp_start_port,
        which is the starting point to find a free port from.
        """
        self.wmq_ipc_tcp_port = get_free_port(ipc_tcp_start_port)
        logger.info('Starting WebSphere MQ connector for server `%s` on `%s`',
                    self.wmq_ipc_tcp_port, self.name)

        # Credentials for both servers and connectors
        username, password = self.get_wmq_credentials()

        # User kernel's facilities to store configuration
        self.keyutils.user_set(
            b'zato-wmq',
            dumps({
                'port': self.wmq_ipc_tcp_port,
                'username': username,
                'password': password,
                'server_port': self.port,
                'server_name': self.name,
                'server_path': '/zato/internal/callback/wmq',
                'base_dir': self.base_dir,
                'logging_conf_path': self.logging_conf_path
            }), self.pid)

        # Start WebSphere MQ connector in a sub-process
        start_python_process(False,
                             'zato.server.connection.jms_wmq.jms.container',
                             'WebSphere MQ connector', '')

        # Wait up to timeout seconds for the connector to start as indicated by its responding to a PING request
        now = datetime.utcnow()
        until = timedelta(seconds=timeout)
        is_ok = False
        address = address_pattern.format(self.wmq_ipc_tcp_port, 'ping')
        auth = self.get_wmq_credentials()

        while not is_ok or now >= until:
            is_ok = self._ping_connector(address, auth)
            if is_ok:
                break
            else:
                sleep(0.2)
                now = datetime.utcnow()

        if not is_ok:
            logger.warn(
                'WebSphere MQ connector (%s) could not be started after %s',
                address, timeout)
        else:
            return is_ok