Esempio n. 1
0
    def __init__(self, services, number_threads, ssl=None):
        """Setup all protocol services.
        """
        Singleton.__init__(self)
        self.__services = services

        # XMLRPC
        self.__rpc_server = None
        if 'protocol.xmlrpc' in services:
            host, port = services['protocol.xmlrpc'].split(':')
            self.__rpc_server = _protocol.MyServer(host, int(port),
                                                   number_threads, ssl)

        # MySQL Protocol
        self.__mysql_server = None
        if 'protocol.mysql' in services:
            host, port = services['protocol.mysql'].split(':')
            self.__mysql_server = FabricMySQLServer(host, int(port),
                                                    number_threads, ssl)
Esempio n. 2
0
    def __init__(self, services, number_threads, ssl=None):
        """Setup all protocol services.
        """
        Singleton.__init__(self)
        self.__services = services

        # XMLRPC
        self.__rpc_server = None
        if 'protocol.xmlrpc' in services:
            host, port = services['protocol.xmlrpc'].split(':')
            self.__rpc_server = _protocol.MyServer(
                host, int(port), number_threads, ssl
            )

        # MySQL Protocol
        self.__mysql_server = None
        if 'protocol.mysql' in services:
            host, port = services['protocol.mysql'].split(':')
            self.__mysql_server = FabricMySQLServer(
                host, int(port), number_threads, ssl
            )
Esempio n. 3
0
class ServiceManager(Singleton):
    """This is the service manager, which processes service requests.

    The service manager supports XML-RPC and MySQL-RPC using the
    MySQL protocol.

    Services are not automatically loaded when the service manager is
    constructed, so the load_services have to be called explicitly to
    load the services in the package.
    """
    def __init__(self, services, number_threads, ssl=None):
        """Setup all protocol services.
        """
        Singleton.__init__(self)
        self.__services = services

        # XMLRPC
        self.__rpc_server = None
        if 'protocol.xmlrpc' in services:
            host, port = services['protocol.xmlrpc'].split(':')
            self.__rpc_server = _protocol.MyServer(
                host, int(port), number_threads, ssl
            )

        # MySQL Protocol
        self.__mysql_server = None
        if 'protocol.mysql' in services:
            host, port = services['protocol.mysql'].split(':')
            self.__mysql_server = FabricMySQLServer(
                host, int(port), number_threads, ssl
            )

    def address(self, protocol=None):
        """Return addresses in use by the service.

        :param protocol: Address in use by a protocol.
        :return: Address as host:port.
        :rtype: String.
        """
        services = self.__services.copy()

        if protocol is None:
            return services

        if protocol in services:
            return {protocol : services[protocol]}

        raise ServiceError("Protocol (%s) is not supported." % (protocol, ))

    def get_number_sessions(self):
        """Return the number of concurrent sessions.
        """
        return self.__rpc_server.get_number_sessions()

    def start(self):
        """Start all services managed by the service manager.
        """
        if self.__mysql_server:
            try:
                self.__mysql_server.start()
            except Exception as error:
                _LOGGER.error("Error starting thread: (%s).", error)
            finally:
                _LOGGER.debug("MySQL-RPC server thread created")

        if self.__rpc_server:
            try:
                self.__rpc_server.start()
            except Exception as error:
                _LOGGER.error("Error starting thread: (%s).", error)
            finally:
                _LOGGER.debug("XML-RPC server thread created")

    def shutdown(self):
        """Shut down all services managed by the service manager.
        """
        if self.__mysql_server:
            self.__mysql_server.shutdown()
        if self.__rpc_server:
            self.__rpc_server.shutdown()

    def wait(self):
        """Wait until all the sevices are properly finished.
        """
        if self.__rpc_server:
            self.__rpc_server.wait()

    def load_services(self, options, config):
        """Load services into each protocol server.

        :param options: The options for the commands that shall be
                        created.
        :param config: The configuration for the commands that shall
                       be created.
        """
        _LOGGER.info("Loading Services.")

        find_commands(config)

        for group_name in get_groups():
            for command_name in get_commands(group_name):
                command = get_command(group_name, command_name)
                if hasattr(command, "execute"):
                    _LOGGER.debug(
                        "Registering %s.", command.group_name + '.' + \
                        command.command_name
                        )
                    if self.__mysql_server:
                        cmd = command()
                        cmd.setup_server(self.__mysql_server, options, config)
                        self.__mysql_server.register_command(cmd)

                    if self.__rpc_server:
                        cmd = command()
                        cmd.setup_server(self.__rpc_server, options, config)
                        self.__rpc_server.register_command(cmd)
Esempio n. 4
0
class ServiceManager(Singleton):
    """This is the service manager, which processes service requests.

    The service manager supports XML-RPC and MySQL-RPC using the
    MySQL protocol.

    Services are not automatically loaded when the service manager is
    constructed, so the load_services have to be called explicitly to
    load the services in the package.
    """
    def __init__(self, services, number_threads, ssl=None):
        """Setup all protocol services.
        """
        Singleton.__init__(self)
        self.__services = services

        # XMLRPC
        self.__rpc_server = None
        if 'protocol.xmlrpc' in services:
            host, port = services['protocol.xmlrpc'].split(':')
            self.__rpc_server = _protocol.MyServer(host, int(port),
                                                   number_threads, ssl)

        # MySQL Protocol
        self.__mysql_server = None
        if 'protocol.mysql' in services:
            host, port = services['protocol.mysql'].split(':')
            self.__mysql_server = FabricMySQLServer(host, int(port),
                                                    number_threads, ssl)

    def address(self, protocol=None):
        """Return addresses in use by the service.

        :param protocol: Address in use by a protocol.
        :return: Address as host:port.
        :rtype: String.
        """
        services = self.__services.copy()

        if protocol is None:
            return services

        if protocol in services:
            return {protocol: services[protocol]}

        raise ServiceError("Protocol (%s) is not supported." % (protocol, ))

    def get_number_sessions(self):
        """Return the number of concurrent sessions.
        """
        return self.__rpc_server.get_number_sessions()

    def start(self):
        """Start all services managed by the service manager.
        """
        if self.__mysql_server:
            try:
                self.__mysql_server.start()
            except Exception as error:
                _LOGGER.error("Error starting thread: (%s).", error)
            finally:
                _LOGGER.debug("MySQL-RPC server thread created")

        if self.__rpc_server:
            try:
                self.__rpc_server.start()
            except Exception as error:
                _LOGGER.error("Error starting thread: (%s).", error)
            finally:
                _LOGGER.debug("XML-RPC server thread created")

    def shutdown(self):
        """Shut down all services managed by the service manager.
        """
        if self.__mysql_server:
            self.__mysql_server.shutdown()
        if self.__rpc_server:
            self.__rpc_server.shutdown()

    def wait(self):
        """Wait until all the sevices are properly finished.
        """
        if self.__rpc_server:
            self.__rpc_server.wait()

    def load_services(self, options, config):
        """Load services into each protocol server.

        :param options: The options for the commands that shall be
                        created.
        :param config: The configuration for the commands that shall
                       be created.
        """
        _LOGGER.info("Loading Services.")

        find_commands(config)

        for group_name in get_groups():
            for command_name in get_commands(group_name):
                command = get_command(group_name, command_name)
                if hasattr(command, "execute"):
                    _LOGGER.debug(
                        "Registering %s.", command.group_name + '.' + \
                        command.command_name
                        )
                    if self.__mysql_server:
                        cmd = command()
                        cmd.setup_server(self.__mysql_server, options, config)
                        self.__mysql_server.register_command(cmd)

                    if self.__rpc_server:
                        cmd = command()
                        cmd.setup_server(self.__rpc_server, options, config)
                        self.__rpc_server.register_command(cmd)