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()
def main(args=None): if args is None: args = sys.argv[1:] opts = parse_args(args) processor = None try: init_console_logging(verbose_level=opts.verbose) processor = TransactionProcessor(url=opts.connect) log_config = get_log_config(filename="supplychain_log_config.toml") # If no toml, try loading yaml if log_config is None: log_config = get_log_config(filename="supplychain_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="supplychain-" + str(processor.zmq_id)[2:-1]) processor.add_handler(SupplyChainHandler()) 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()
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) 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) start_rest_api( host, port, connection, int(rest_api_config.timeout)) # pylint: disable=broad-except except Exception as e: print("Error: {}".format(e), file=sys.stderr) finally: if connection is not None: connection.close()
def main(args=sys.argv[1:]): opts = parse_args(args) processor = None try: processor = TransactionProcessor(url=opts.endpoint) log_config = get_log_config(filename="supplier_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="supplier-" + 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. supplier_prefix = hashlib.sha512( 'supplier'.encode("utf-8")).hexdigest()[0:6] handler = SupplierTransactionHandler(namespace_prefix=supplier_prefix) 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()
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="intkey_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="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 = IntkeyTransactionHandler() 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()
def main(args=sys.argv[1:]): opts = parse_args(args) processor = None try: processor = TransactionProcessor(url=opts.endpoint) log_config = get_log_config(filename="intkey_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="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 = IntkeyTransactionHandler() 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()
def main(): stream = None try: opts = parse_args(sys.argv[1:]) stream = Stream(opts.stream_url) log_config = get_log_config(filename="rest_api_log_config.toml") 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="sawtooth_rest_api") init_console_logging(verbose_level=opts.verbose) start_rest_api( opts.host, int(opts.port), stream, int(opts.timeout)) # pylint: disable=broad-except except Exception as e: print("Error: {}".format(e), file=sys.stderr) sys.exit(1) finally: if stream is not None: stream.close()
def main(args=sys.argv[1:]): opts = parse_args(args) processor = TransactionProcessor(url=opts.endpoint) log_config = get_log_config(filename="intkey_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="intkey_python-" + 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. intkey_prefix = hashlib.sha512('intkey'.encode()).hexdigest()[0:6] handler = IntkeyTransactionHandler(namespace_prefix=intkey_prefix) processor.add_handler(handler) try: processor.start() except KeyboardInterrupt: pass finally: processor.stop()
def do_subscribe(opts): opts_config = SubscriberConfig( connect=opts.connect, database_name=opts.database_name, database_host=opts.database_host, database_port=opts.database_port, database_user=opts.database_user, database_password=opts.database_password) subscriber_config = load_subscriber_config(opts_config) subscriber = None stream = None connection = None # pylint: disable=broad-except try: url = None if "tcp://" not in subscriber_config.connect: url = "tcp://" + subscriber_config.connect else: url = subscriber_config.connect stream = Stream(url) connection = psycopg2.connect( dbname=subscriber_config.database_name, host=subscriber_config.database_host, port=subscriber_config.database_port, user=subscriber_config.database_user, password=subscriber_config.database_password) subscriber = Subscriber(stream, connection) log_config = get_log_config( filename="supplychain_sds_log_config.toml") if log_config is not None: log_configuration(log_config=log_config) else: log_dir = get_log_dir() # use the stream zmq identity for filename log_configuration( log_dir=log_dir, name="supplychain-sds-" + str(stream.zmq_id)[2:-1]) subscriber.start() except KeyboardInterrupt: pass except Exception as e: print('Error: {}'.format(e), file=sys.stderr) finally: if subscriber is not None: subscriber.shutdown() if stream is not None: stream.close() if connection is not None: connection.close()
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="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()
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) 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 log_config is not None: log_configuration(log_config=log_config) else: log_dir = get_log_dir() log_configuration(log_dir=log_dir, name="sawtooth_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) start_rest_api( host, port, connection, int(rest_api_config.timeout)) # pylint: disable=broad-except except Exception as e: print("Error: {}".format(e), file=sys.stderr) finally: if connection is not None: connection.close()
def do_start(opts): try: opts_config = RestApiConfig(bind=opts.bind, database_name=opts.database_name, database_host=opts.database_host, database_port=opts.database_port, database_user=opts.database_user, database_password=opts.database_password) rest_api_config = load_rest_api_config(opts_config) log_config = get_log_config( filename="supply_chain_rest_api_log_config.toml") 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="supply_chain_rest_api") start_rest_api(rest_api_config) # pylint: disable=broad-except except Exception as e: print("Error: {}".format(e), file=sys.stderr) sys.exit(1)
def main(): stream = None try: opts = parse_args(sys.argv[1:]) opts_config = RestApiConfig(bind=opts.bind, connect=opts.connect, timeout=opts.timeout) rest_api_config = load_rest_api_config(opts_config) if "tcp://" not in rest_api_config.connect: stream = Stream("tcp://" + rest_api_config.connect) else: stream = Stream(rest_api_config.connect) log_config = get_log_config(filename="rest_api_log_config.toml") 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="sawtooth_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) start_rest_api(host, port, stream, int(rest_api_config.timeout)) # pylint: disable=broad-except except Exception as e: print("Error: {}".format(e), file=sys.stderr) sys.exit(1) finally: if stream is not None: stream.close()
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()