Пример #1
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        processor = TransactionProcessor(url=opts.connect)
        log_config = get_log_config(filename="snarkcoin_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="snarkcoin_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(log_dir=log_dir,
                              name="snarkcoin-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        handler = SnarkcoinHandler()

        processor.add_handler(handler)

        processor.start()
    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except, invalid-name
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        if processor is not None:
            processor.stop()
Пример #2
0
def main(args = None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        arg_config = create_transfer_config(opts)
        transfer_config = load_transfer_config(arg_config)
        processor = TransactionProcessor(url=transfer_config.connect)
        log_config = get_log_config(filename="transfer_log_config.toml")


        if log_config is None:
            log_config = get_log_config(filename="transfer_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            log_configuration(
                log_dir=log_dir,
                name="transfer" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        handler = TransferHandler()
        processor.add_handler(handler)
        processor.start()
    except KeyboardInterrupt:
        pass
    except Exception as e:
        print("Error: {}".format(e))
    finally:
        if processor is not None:
            processor.stop()
Пример #3
0
def main(args=None):
    if args is None:
        args = sys.argv[3:]  # considering the starting command is `python3 main.py` and then additional arguments

    opts = parse_args(args)
    processor = None

    try:
        processor = TransactionProcessor(url=opts.connect)
        log_config = get_log_config(filename=tp_config_name+"_log_config.toml")
        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename=tp_config_name+"_log_config.yaml")
        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(
                log_dir=log_dir,
                name=tp_config_name+"-" + str(processor.zmq_id)[2:-1])
        init_console_logging(verbose_level=opts.verbose)
        # The prefix should eventually be looked up from the
        # validator's namespace registry.
        handler = Manufacturing()
        processor.add_handler(handler)
        processor.start()

    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        if processor is not None:
            processor.stop()
Пример #4
0
def main(args=None):
    """
    Main.

    Raises:
    RunTimeException, connection error
    """

    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        processor = TransactionProcessor(url=opts.connect)

        log_dir = get_log_dir()
        #use the transaction processor zmq idenity for filename
        log_configuration(log_dir=log_dir,
                          name="code_smell-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        handler = CodeSmellTransactionHandler()

        processor.add_handler(handler)

        processor.start()
    except KeyboardInterrupt:
        pass
    except RuntimeError as err:
        raise CodeSmellException("Error: {}".format(err))
    finally:
        if processor is not None:
            processor.stop()
Пример #5
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        processor = TransactionProcessor(url=opts.endpoint)
        log_config = get_log_config(filename="part_log_config.toml")

        if log_config is None:
            log_config = get_log_config(filename="part_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(log_dir=log_dir,
                              name="part-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        part_prefix = hashlib.sha512('pt'.encode("utf-8")).hexdigest()[0:6]
        handler = PartTransactionHandler(namespace_prefix=part_prefix)

        processor.add_handler(handler)

        processor.start()
    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e))
    finally:
        if processor is not None:
            processor.stop()
Пример #6
0
def main(args=None):

    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None

    try:
        # In docker, the url would be the validator's container name with
        # port 4004
        processor = TransactionProcessor(url=opts.connect)

        log_dir = get_log_dir()
        # use the transaction processor zmq identity for filename
        log_configuration(log_dir=log_dir,
                          name="ca-bc-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=2)

        handler = CAHandler('ca_1')
        processor.add_handler(handler)
        processor.start()
    except KeyboardInterrupt:
        pass
    except Exception as e:
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        if processor is not None:
            processor.stop()
Пример #7
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    #print(opts)
    processor = None

    try:
        processor = TransactionProcessor(url=opts.connect)
        log_config = get_log_config(filename="bcmcs_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            print('None', processor.zmq_id, get_log_dir())
            log_config = get_log_config(filename="bcmcs_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(log_dir=log_dir,
                              name="bcmcs-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        # The prefix should eventually be looked up from the
        # validator's namespace registry.
        handler = BCMCSTransactionHandler()

        processor.add_handler(handler)

        processor.start()

    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        if processor is not None:
            processor.stop()
Пример #8
0
def setup_logging(name, verbosity=2):
    log_config = get_log_config(filename='{}_log_config.toml'.format(name))

    if log_config is None:
        log_config = get_log_config(filename='{}_log_config.yaml'.format(name))

    if log_config is not None:
        log_configuration(log_config=log_config)
    else:
        log_dir = get_log_dir()
        log_configuration(log_dir=log_dir, name=name)

    init_console_logging(verbose_level=verbosity)
Пример #9
0
    def set_log_config(self):
        log_config = get_log_config(filename="rest_api_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="rest_api_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            log_configuration(log_dir=log_dir, name="rest_api")
        init_console_logging(verbose_level=0)
Пример #10
0
def main(args=None):
    try:
        path_config = load_path_config()
    except LocalConfigurationError as local_config_err:
        LOGGER.error(str(local_config_err))
        sys.exit(1)

    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)

    try:
        arg_config = create_pbft_config(opts)
        pbft_config = load_pbft_config(arg_config)

        log_config = get_log_config('bgx-pbft-engine-log-config.toml')
        if log_config is None:
            log_config = get_log_config('bgx-pbft-engine-log-config.yaml')

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            log_configuration(
                log_dir=log_dir,
                name='pbft-engine')

        init_console_logging(verbose_level=opts.verbose)

        driver = ZmqDriver(
            PbftEngine(
                path_config=path_config,
                component_endpoint=opts.component,
                pbft_config=pbft_config))
        LOGGER.debug('Start driver=%s endpoint=%s component=%s',driver,opts.connect,opts.component)
        attemps = 0
        while attemps < MAX_CONNECT_ATTEMPTS:
            try:
                driver.start(endpoint=opts.connect)
                break
            except FutureTimeoutError:
                attemps += 1
                LOGGER.debug('Start driver=%s endpoint=%s AGAIN=%s',driver,opts.connect,attemps)

    except KeyboardInterrupt:
        pass
    except Exception:  # pylint: disable=broad-except
        LOGGER.exception("Error starting PBFT Engine")
    finally:
        pass
Пример #11
0
def setup_logging(name, verbosity=2):
    Path('/var/log/sawtooth').mkdir(parents=True, exist_ok=True)
    Path('/var/log/sawtooth/{}-debug.log'.format(name)).touch(exist_ok=True)

    log_config = get_log_config(filename='{}_log_config.toml'.format(name))

    if log_config is None:
        log_config = get_log_config(filename='{}_log_config.yaml'.format(name))

    if log_config is not None:
        log_configuration(log_config=log_config)
    else:
        log_dir = get_log_dir()
        log_configuration(log_dir=log_dir, name=name)

    init_console_logging(verbose_level=verbosity)
Пример #12
0
def setup_loggers(verbose_level, processor):
    log_config = get_log_config(filename="setting_log_config.toml")

    # If no toml, try loading yaml
    if log_config is None:
        log_config = get_log_config(filename="setting_log_config.yaml")

    if log_config is not None:
        log_configuration(log_config=log_config)
    else:
        log_dir = get_log_dir()
        # use the transaction processor zmq identity for filename
        log_configuration(log_dir=log_dir,
                          name="setting-" + str(processor.zmq_id)[2:-1])

    init_console_logging(verbose_level=verbose_level)
Пример #13
0
def main():
    try:
        url = env("SAWTOOTH_VALIDATOR_ENDPOINT", "tcp://validator:4004")
        processor = TransactionProcessor(url=url)
        log_configuration(log_dir=get_log_dir(), name="petition_tp")
        create_console_handler(5)
        init_console_logging(5)
        handler = PetitionTransactionHandler()  # url=rest_api)
        processor.add_handler(handler)
        processor.start()
    except KeyboardInterrupt:
        pass
    except Exception as e:
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        if processor is not None:
            processor.stop()
Пример #14
0
def setup_loggers(verbose_level, processor):
    log_config = get_log_config(filename="identity_log_config.toml")

    # If no toml, try loading yaml
    if log_config is None:
        log_config = get_log_config(filename="identity_log_config.yaml")

    if log_config is not None:
        log_configuration(log_config=log_config)
    else:
        log_dir = get_log_dir()
        # use the transaction processor zmq identity for filename
        log_configuration(
            log_dir=log_dir,
            name="identity-" + str(processor.zmq_id)[2:-1])

    init_console_logging(verbose_level=verbose_level)
Пример #15
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)

    try:
        log_dir = get_log_dir()
        log_configuration(log_dir=log_dir, name='poet-engine')

        init_console_logging(verbose_level=opts.verbose)

        driver = ZmqDriver(PoetEngine())
        driver.start(endpoint=opts.connect)
    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        pass
Пример #16
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        processor = TransactionProcessor(url=opts.connect)
        log_config = get_log_config(filename="battleship_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="battleship_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(
                log_dir=log_dir,
                name="battleship-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        # The prefix should eventually be looked up from the
        # validator's namespace registry.
        battle_ship_prefix = \
            hashlib.sha512('battleship'.encode("utf-8")).hexdigest()[0:6]
        handler = \
            BattleshipTransactionHandler(namespace_prefix=battle_ship_prefix)

        processor.add_handler(handler)

        processor.start()
    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e))
    finally:
        if processor is not None:
            processor.stop()
Пример #17
0
def main():

    processor = None
    try:
        processor = TransactionProcessor(url='tcp://127.0.0.1:4004')
        log_dir = get_log_dir()
        log_configuration(log_dir=log_dir,
                          name="barcode-" + str(processor.zmq_id)[2:-1])
        init_console_logging(verbose_level=2)
        barcode_prefix = hashlib.sha512(
            'barcode'.encode("utf-8")).hexdigest()[0:6]
        handler = BarcodeTransactionHandler(namespace_prefix=barcode_prefix)
        processor.add_handler(handler)
        processor.start()
    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e))
    finally:
        if processor is not None:
            processor.stop()
Пример #18
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)

    try:
        log_dir = get_log_dir()
        log_configuration(
            log_dir=log_dir,
            name='poet-engine')

        init_console_logging(verbose_level=opts.verbose)

        driver = ZmqDriver(PoetEngine())
        driver.start(endpoint=opts.connect)
    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        pass
Пример #19
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        print("here 1")
        arg_config = create_identity_config(opts)
        identity_config = load_identity_config(arg_config)
        processor = TransactionProcessor(url=identity_config.connect)
        log_config = get_log_config(filename="identity_log_config.toml")
        print("here 2")
        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="identity_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(
                log_dir=log_dir,
                name="identity-" + str(processor.zmq_id)[2:-1])
        print('here 3')
        init_console_logging(verbose_level=opts.verbose)
        print('here 4')
        handler = IdentityTransactionHandler()
        print('here 5')
        processor.add_handler(handler)
        print('here 6')
        processor.start()
        print('here 7')
    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e))
    finally:
        if processor is not None:
            processor.stop()
Пример #20
0
def main():
    try:
        url = env("ZTP_VALIDATOR_ENDPOINT", "tcp://validator:4004")
        rest_api = env("ZTP_REST_ENDPOINT", "http://rest-api:8090")
        processor = TransactionProcessor(url=url)
        log_dir = get_log_dir()
        # use the transaction processor zmq identity for filename
        log_configuration(log_dir=log_dir,
                          name="zenroom-" + str(processor.zmq_id)[2:-1])

        init_console_logging()
        handler = ZenroomTransactionHandler(url=rest_api)
        processor.add_handler(handler)
        processor.start()

    except KeyboardInterrupt:
        pass
    except Exception as e:
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        if processor is not None:
            processor.stop()
Пример #21
0
def main(args=None):
    try:
        path_config = load_path_config()
    except LocalConfigurationError as local_config_err:
        LOGGER.error(str(local_config_err))
        sys.exit(1)

    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)

    try:
        log_config = get_log_config('poet-engine-log-config.toml')
        if log_config is None:
            log_config = get_log_config('poet-engine-log-config.yaml')

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            log_configuration(
                log_dir=log_dir,
                name='poet-engine')

        init_console_logging(verbose_level=opts.verbose)

        driver = ZmqDriver(
            PoetEngine(
                path_config=path_config,
                component_endpoint=opts.component))

        driver.start(endpoint=opts.connect)

    except KeyboardInterrupt:
        pass
    except Exception:  # pylint: disable=broad-except
        LOGGER.exception("Error starting PoET Engine")
    finally:
        pass
Пример #22
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        arg_config = create_xo_config(opts)
        xo_config = load_xo_config(arg_config)
        processor = TransactionProcessor(url=xo_config.connect)
        log_config = get_log_config(filename="xo_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="xo_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(
                log_dir=log_dir,
                name="xo-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        handler = XoTransactionHandler()

        processor.add_handler(handler)

        processor.start()
    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e))
    finally:
        if processor is not None:
            processor.stop()
Пример #23
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        arg_config = create_soce_config(opts)
        soce_config = load_soce_config(arg_config)
        #URL of the validator's container tcp://127.0.0.1:4004
        processor = TransactionProcessor(url=soce_config.connect)
        log_config = get_log_config(filename="soce_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="soce_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(log_dir=log_dir,
                              name="soce-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        handler = SoceTransactionHandler()

        processor.add_handler(handler)

        processor.start()
    except KeyboardInterrupt:
        pass
#    except Exception as e:  # pylint: disable=broad-except
#        print("Error: {}".format(e))
    finally:
        if processor is not None:
            processor.stop()
Пример #24
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        processor = TransactionProcessor(url=opts.connect)
        log_config = get_log_config(filename="intkey_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="intkey_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(
                log_dir=log_dir,
                name="intkey-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        # The prefix should eventually be looked up from the
        # validator's namespace registry.
        handler = SimpleTransactionHandler()

        processor.add_handler(handler)

        processor.start()
    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        if processor is not None:
            processor.stop()
Пример #25
0
def main(args=sys.argv[1:]):
    opts = parse_args(args)

    processor = TransactionProcessor(url=opts.endpoint)
    log_config = get_log_config(filename="lisp_log_config.toml")
    if log_config is not None:
        log_configuration(log_config=log_config)
    else:
        log_dir = get_log_dir()
        # use the transaction processor zmq identity for filename
        log_configuration(log_dir=log_dir,
                          name="lisp-" + str(processor.zmq_id)[2:-1])

    init_console_logging(verbose_level=opts.verbose)

    processor.add_handler(LispHandler())

    try:
        processor.start()
    except KeyboardInterrupt:
        pass
    finally:
        processor.stop()
Пример #26
0
def main():
    loop = ZMQEventLoop()
    asyncio.set_event_loop(loop)

    connection = None
    try:
        opts = parse_args(sys.argv[1:])
        opts_config = RestApiConfig(bind=opts.bind,
                                    connect=opts.connect,
                                    timeout=opts.timeout,
                                    opentsdb_url=opts.opentsdb_url,
                                    opentsdb_db=opts.opentsdb_db)
        rest_api_config = load_rest_api_config(opts_config)
        url = None
        if "tcp://" not in rest_api_config.connect:
            url = "tcp://" + rest_api_config.connect
        else:
            url = rest_api_config.connect

        connection = Connection(url)

        log_config = get_log_config(filename="rest_api_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="rest_api_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            log_configuration(log_dir=log_dir, name="rest_api")
        init_console_logging(verbose_level=opts.verbose)

        try:
            host, port = rest_api_config.bind[0].split(":")
            port = int(port)
        except ValueError as e:
            print("Unable to parse binding {}: Must be in the format"
                  " host:port".format(rest_api_config.bind[0]))
            sys.exit(1)

        wrapped_registry = None
        if rest_api_config.opentsdb_url:
            LOGGER.info("Adding metrics reporter: url=%s, db=%s",
                        rest_api_config.opentsdb_url,
                        rest_api_config.opentsdb_db)

            url = urlparse(rest_api_config.opentsdb_url)
            proto, db_server, db_port, = url.scheme, url.hostname, url.port

            registry = MetricsRegistry()
            wrapped_registry = MetricsRegistryWrapper(registry)

            reporter = InfluxReporter(
                registry=registry,
                reporting_interval=10,
                database=rest_api_config.opentsdb_db,
                prefix="sawtooth_rest_api",
                port=db_port,
                protocol=proto,
                server=db_server,
                username=rest_api_config.opentsdb_username,
                password=rest_api_config.opentsdb_password)
            reporter.start()

        start_rest_api(host, port, connection, int(rest_api_config.timeout),
                       wrapped_registry)
        # pylint: disable=broad-except
    except Exception as e:
        LOGGER.exception(e)
        sys.exit(1)
    finally:
        if connection is not None:
            connection.close()
Пример #27
0
def main():
    loop = ZMQEventLoop()
    asyncio.set_event_loop(loop)

    connection = None
    try:
        opts = parse_args(sys.argv[1:])
        opts_config = RestApiConfig(
            bind=opts.bind,
            connect=opts.connect,
            timeout=opts.timeout,
            opentsdb_url=opts.opentsdb_url,
            opentsdb_db=opts.opentsdb_db)
        rest_api_config = load_rest_api_config(opts_config)
        url = None
        if "tcp://" not in rest_api_config.connect:
            url = "tcp://" + rest_api_config.connect
        else:
            url = rest_api_config.connect

        connection = Connection(url)

        log_config = get_log_config(filename="rest_api_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="rest_api_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            log_configuration(log_dir=log_dir, name="rest_api")
        init_console_logging(verbose_level=opts.verbose)

        try:
            host, port = rest_api_config.bind[0].split(":")
            port = int(port)
        except ValueError as e:
            print("Unable to parse binding {}: Must be in the format"
                  " host:port".format(rest_api_config.bind[0]))
            sys.exit(1)

        wrapped_registry = None
        if rest_api_config.opentsdb_url:
            LOGGER.info("Adding metrics reporter: url=%s, db=%s",
                        rest_api_config.opentsdb_url,
                        rest_api_config.opentsdb_db)

            url = urlparse(rest_api_config.opentsdb_url)
            proto, db_server, db_port, = url.scheme, url.hostname, url.port

            registry = MetricsRegistry()
            wrapped_registry = MetricsRegistryWrapper(registry)

            reporter = InfluxReporter(
                registry=registry,
                reporting_interval=10,
                database=rest_api_config.opentsdb_db,
                prefix="sawtooth_rest_api",
                port=db_port,
                protocol=proto,
                server=db_server,
                username=rest_api_config.opentsdb_username,
                password=rest_api_config.opentsdb_password)
            reporter.start()

        start_rest_api(
            host,
            port,
            connection,
            int(rest_api_config.timeout),
            wrapped_registry)
        # pylint: disable=broad-except
    except Exception as e:
        LOGGER.exception(e)
        sys.exit(1)
    finally:
        if connection is not None:
            connection.close()
Пример #28
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    opts = parse_args(args)
    processor = None
    try:
        processor = TransactionProcessor(url=opts.connect)
        log_config = get_log_config(filename="bgt_log_config.toml")

        # If no toml, try loading yaml
        if log_config is None:
            log_config = get_log_config(filename="bgt_log_config.yaml")

        if log_config is not None:
            log_configuration(log_config=log_config)
        else:
            log_dir = get_log_dir()
            # use the transaction processor zmq identity for filename
            log_configuration(log_dir=log_dir,
                              name="bgt-" + str(processor.zmq_id)[2:-1])

        init_console_logging(verbose_level=opts.verbose)

        # The prefix should eventually be looked up from the
        # validator's namespace registry.
        if _ORIENTDB_:
            pass
            """
            def _my_callback(for_every_record):
                LOGGER.debug("record=%s",for_every_record)

            LOGGER.debug("TESTING ORIENTDB CLIENT\n")
            try:
                client = pyorient.OrientDB(ORIENTDB_HOST, 2424)
                LOGGER.debug("TESTING ORIENTDB client=%s",client)
                session_id = client.connect( DB_USER, DB_PASS )
                LOGGER.debug("_ORIENTDB_ client=%s session_id=%s",client,session_id)
                db = client.db_create( DB_NAME, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_MEMORY )
                is_db = client.db_exists( DB_NAME, pyorient.STORAGE_TYPE_MEMORY )
                if is_db :
                    db_bgx = client.db_open( DB_NAME, DB_USER, DB_PASS )
                    result = client.query_async ("select from OUser", 10, '*:0',_my_callback) #client.query
                    LOGGER.debug("_ORIENTDB_ result=%s",result)
                    LOGGER.debug("_ORIENTDB_ DB-BGX=%s db_count_records=%s",type(db_bgx),client.db_count_records())
                LOGGER.debug("_ORIENTDB_ DB=%s is_db=%s list=%s",db,is_db,client.db_list())
                

            except Exception as ex :
                LOGGER.debug("TESTING ORIENTDB '%s' FAILED (%s)\n",ORIENTDB_HOST,ex)
            """
        if _NATS_:
            pass
            """
            LOGGER.debug("TESTING NATS CLIENT")
            loop = asyncio.get_event_loop()
            loop.run_until_complete(run(loop,"nats://nats:4222"))
            loop.close()
            LOGGER.debug("DONE TESTING NATS CLIENT")
            """
        else:
            #processor = TransactionProcessor(url=opts.connect)
            handler = BgtTransactionHandler()
            processor.add_handler(handler)
            processor.start()

    except KeyboardInterrupt:
        pass
    except Exception as e:  # pylint: disable=broad-except
        print("Error: {}".format(e), file=sys.stderr)
    finally:
        if processor is not None:
            processor.stop()