def init_service(ctxt=None,
                 service_name=None,
                 service_id=None,
                 discovery_addr='localhost:5555',
                 mgmt_addr='localhost:6666',
                 inproc_addr_list=None,
                 inproc_shutdown_event_list=None,
                 update_interval=10,
                 poll_timeout=5000,
                 log_cfg='../../../../conf/logconf_service.json'):
    func_name = init_service.__name__
    try:
        logger = logging.getLogger()
        initraw()
        if(log_cfg is not None):
            logconf.init_logging(log_cfg)
        shutdown_event = threading.Event()
        args = (shutdown_event, ctxt, service_name,
                service_id, discovery_addr,
                mgmt_addr, inproc_addr_list,
                inproc_shutdown_event_list,
                update_interval, poll_timeout)
        service_thread = threading.Thread(target=service_loop, args=args)
        service_thread.start()
        return service_thread, shutdown_event
    except:
        logger.exception('%s : Service Initialization Failed...', func_name)
def init_service_mgr(ctxt=None,
                     service_mgr_name='Service Manager',
                     service_mgr_id=None,
                     discovery_addr='*:5555',
                     mgmt_addr='*:6666',
                     discovery_interval=5,
                     poll_timeout=5000,
                     log_cfg='../../../../conf/logconf_servicemgr.json'):
    func_name = init_service_mgr.__name__
    try:
        initraw()
        if(log_cfg is not None):
            logconf.init_logging(log_cfg)
        logger = logging.getLogger()
        shutdown_event = threading.Event()
        args = (shutdown_event, ctxt, service_mgr_name,
                service_mgr_id, discovery_addr,
                mgmt_addr, discovery_interval, poll_timeout)
        service_mgr_thread = threading.Thread(target=service_mgr_loop,
                                              args=args)
        service_mgr_thread.start()
        return service_mgr_thread, shutdown_event
    except:
        logger.exception('%s : Service Manager Initialization Failed...',
                         func_name)
Ejemplo n.º 3
0
    def test_log_message(self):
        init_logging('./conf/logconf_template.json')
        with LogCapture() as l:
            logger = logging.getLogger()
            logger.info('a info message')
            logger.error('a error message')
            logger.debug('a debug message')
            logger.critical('a critical message')
            logger.warn('a warning message')
            exc_msg = 'the if statement throws an exception'\
                      'in the python3 world(as it should)'\
                      'but gets executed in the python2 world'
            try:
                if ('hello' > 3):
                    logger.exception(exc_msg)
            except:
                logger.exception(exc_msg)

            l.check(
                ('root', 'INFO', 'a info message'),
                ('root', 'ERROR', 'a error message'),
                ('root', 'DEBUG', 'a debug message'),
                ('root', 'CRITICAL', 'a critical message'),
                ('root', 'WARNING', 'a warning message'),
                ('root', 'ERROR', exc_msg),
            )
Ejemplo n.º 4
0
    def test_log_message(self):
        init_logging('./conf/logconf_template.json')
        with LogCapture() as l:
            logger = logging.getLogger()
            logger.info('a info message')
            logger.error('a error message')
            logger.debug('a debug message')
            logger.critical('a critical message')
            logger.warn('a warning message')
            exc_msg = 'the if statement throws an exception'\
                      'in the python3 world(as it should)'\
                      'but gets executed in the python2 world'
            try:
                if('hello' > 3):
                    logger.exception(exc_msg)
            except:
                logger.exception(exc_msg)

            l.check(
                ('root', 'INFO', 'a info message'),
                ('root', 'ERROR', 'a error message'),
                ('root', 'DEBUG', 'a debug message'),
                ('root', 'CRITICAL', 'a critical message'),
                ('root', 'WARNING', 'a warning message'),
                ('root', 'ERROR', exc_msg),
                )
def init_cmd_proc(ctxt=None,
                  cmd_proc_name='Command Processor',
                  cmd_proc_id=None,
                  discovery_addr='localhost:5555',
                  mgmt_addr='localhost:6666',
                  discovery_interval=5,
                  poll_timeout=5000,
                  log_cfg='../../../../conf/logconf_cmdproc.json'):
    func_name = init_cmd_proc.__name__
    try:
        initraw()
        if(log_cfg is not None):
            logconf.init_logging(log_cfg)
        logger = logging.getLogger()
        shutdown_event = threading.Event()
        args = (shutdown_event, ctxt, cmd_proc_name,
                cmd_proc_id, discovery_addr,
                mgmt_addr, discovery_interval, poll_timeout)
        cmd_proc_thread = threading.Thread(target=cmd_proc_loop, args=args)
        cmd_proc_thread.start()
        return cmd_proc_thread, shutdown_event
    except:
        logger.exception('%s : Command Processor Initialization Failed...',
                         func_name)
Ejemplo n.º 6
0
        while (self.__response is None and self.__timedout is not True):
            self.__connection.process_data_events()

        if self.__response is not None:
            self.__logger.debug('%r', self.__response)
            args = self.__response.split('\r\n')
            return args[2]
        else:
            return None


if __name__ == "__main__":
    import sys
    from com.goffersoft.logging import logconf

    logconf.init_logging(default_path='../../../../conf/logconf_rpcfind.json')

    logger = logging.getLogger(__name__)

    usage_string = """
    Usage : %s <method>
        """

    def print_usage_and_exit(reason):
        logger.error(reason)
        sys.exit(usage_string % sys.argv[0])

    if len(sys.argv) != 2:
        print_usage_and_exit('error : Need 1 arg')

    method = sys.argv[1]
Ejemplo n.º 7
0
        self.__channel.basic_publish(exchange=self.__exchange,
                                     routing_key=self.__method_route,
                                     properties=self.__properties,
                                     body=self.__message.encode())

        while (self.__response is None and self.__timedout is not True):
            self.__connection.process_data_events()

        return self.__response


if __name__ == "__main__":
    import sys
    from com.goffersoft.logging import logconf

    logconf.init_logging(default_path='../../../../\
                               conf/logconf_rpcclient.json')

    logger = logging.getLogger(__name__)

    usage_string = """
    Usage : %s <method [arg [arg]]>
               """

    def print_usage_and_exit(reason):
        logger.error(reason)
        sys.exit(usage_string % sys.argv[0])

    if len(sys.argv) < 2:
        print_usage_and_exit('error : Need at least 1 arg')

    method = sys.argv[1]
Ejemplo n.º 8
0
                    exchange=args[2],
                    routing_key=str(args[4]),
                    properties=pika.BasicProperties(
                        correlation_id=props.correlation_id),
                    body=message.encode())
        except:
            self.__logger.exception('Unexpected error:')

    def __call__(self):
        self.__channel.basic_consume(self.__on_request,
                                     queue=self.__queue,
                                     no_ack=True)
        self.__channel.start_consuming()

    def __del__(self):
        self.__channel.close()
        self.__connection.close()


if __name__ == "__main__":
    from com.goffersoft.logging import logconf

    logconf.init_logging(default_path='../../../../' +
                         'conf/logconf_rpcnameservice.json')

    logger = logging.getLogger(__name__)

    rpc = RpcNameService((len(sys.argv) > 1 and sys.argv[1])
                         or 'rpc_ns_exchange', ('localhost', ))
    rpc()
Ejemplo n.º 9
0
        self.__channel.basic_publish(
            exchange=self.__exchange,
            routing_key=self.__method_route,
            properties=self.__properties,
            body=self.__message.encode())

        while(self.__response is None and self.__timedout is not True):
            self.__connection.process_data_events()

        return self.__response

if __name__ == "__main__":
    import sys
    from com.goffersoft.logging import logconf

    logconf.init_logging(default_path='../../../../\
                               conf/logconf_rpcclient.json')

    logger = logging.getLogger(__name__)

    usage_string = """
    Usage : %s <method [arg [arg]]>
               """

    def print_usage_and_exit(reason):
        logger.error(reason)
        sys.exit(usage_string % sys.argv[0])

    if len(sys.argv) < 2:
        print_usage_and_exit('error : Need at least 1 arg')

    method = sys.argv[1]
        except:
            self.__logger.exception('Unexpected error:')

    def __call__(self):
        self.__channel.basic_consume(
            self.__on_request,
            queue=self.__queue,
            no_ack=True
            )
        self.__channel.start_consuming()

    def __del__(self):
        self.__channel.close()
        self.__connection.close()


if __name__ == "__main__":
    from com.goffersoft.logging import logconf

    logconf.init_logging(default_path='../../../../' +
                         'conf/logconf_rpcnameservice.json')

    logger = logging.getLogger(__name__)

    rpc = RpcNameService(
        (len(sys.argv) > 1 and
         sys.argv[1]) or
        'rpc_ns_exchange', ('localhost', )
        )
    rpc()
Ejemplo n.º 11
0
        while(self.__response is None and self.__timedout is not True):
            self.__connection.process_data_events()

        if self.__response is not None:
            self.__logger.debug('%r', self.__response)
            args = self.__response.split('\r\n')
            return args[2]
        else:
            return None


if __name__ == "__main__":
    import sys
    from com.goffersoft.logging import logconf

    logconf.init_logging(default_path='../../../../conf/logconf_rpcfind.json')

    logger = logging.getLogger(__name__)

    usage_string = """
    Usage : %s <method>
        """

    def print_usage_and_exit(reason):
        logger.error(reason)
        sys.exit(usage_string % sys.argv[0])

    if len(sys.argv) != 2:
        print_usage_and_exit('error : Need 1 arg')

    method = sys.argv[1]