def test_sawtooth_stats(self): try: keys = 10 rounds = 2 txn_intv = 0 print("Testing transaction load.") test = IntKeyLoadTest() urls = self.urls self.assertEqual(5, len(urls)) test.setup(self.urls, keys) test.run(keys, rounds, txn_intv) test.validate() try: stats_config_dict = self.stats_config_dict() run_stats(self.urls[0], config_opts=None, config_dict=stats_config_dict) except MessageException as e: raise MessageException('cant run stats print: {0}'.format(e)) finally: print("No Validators need to be stopped")
def do_cluster_stats(args): # pylint: disable=redefined-variable-type file_name = \ os.path.join(os.path.expanduser("~"), '.sawtooth', 'cluster', "state.yaml") # Get current expected state if os.path.isfile(file_name): with open(file_name, 'r') as state_file: state = yaml.load(state_file) else: raise CliException("Missing state file") node_controller = get_node_controller(state, args) node_command_generator = SimpleNodeCommandGenerator() vnm = ValidatorNetworkManager( node_controller=node_controller, node_command_generator=node_command_generator) nodes = state["Nodes"] for node_name in nodes: try: node_ip = vnm.get_ip(node_name) node_name_stats = node_name break except ManagementError as e: raise CliException(str(e)) node_url = "http://" + node_ip.strip(' \t\n\r') + ":" + \ nodes[node_name_stats]["HttpPort"] run_stats(node_url)
def main(): vnm = None error_occurred = False try: opts = configure(sys.argv[1:]) except Exception as e: print >> sys.stderr, str(e) sys.exit(1) try: vnm = get_default_vnm(opts['count'], txnvalidator=opts['validator'], overrides=opts['validator_config'], log_config=opts['log_config_dict'], data_dir=opts['data_dir'], block_chain_archive=opts['load_blockchain'], http_port=int(opts['http_port']), udp_port=int(opts['port']), host=opts['host'], endpoint_host=opts['endpoint']) vnm.do_genesis() vnm.staged_launch() run_stats(vnm.urls()[0]) except KeyboardInterrupt: print "\nExiting" except ExitError as e: # this is an expected error/exit, don't print stack trace - # the code raising this exception is expected to have printed the error # details error_occurred = True print "\nFailed!\nExiting: {}".format(e) except: error_occurred = True traceback.print_exc() print "\nFailed!\nExiting: {}".format(sys.exc_info()[0]) finally: archive_name = None if opts['save_blockchain']: archive_name = opts['save_blockchain'] if vnm is not None: vnm.shutdown(archive_name=archive_name)
def do_cluster_stats(args): state = load_state() node_controller = get_node_controller(state, args) node_command_generator = SimpleNodeCommandGenerator() vnm = ValidatorNetworkManager( node_controller=node_controller, node_command_generator=node_command_generator) nodes = state["Nodes"] for node_name in nodes: try: node_ip = vnm.get_ip(node_name) node_name_stats = node_name break except ManagementError as e: raise CliException(str(e)) node_url = "http://" + node_ip.strip(' \t\n\r') + ":" + \ nodes[node_name_stats]["HttpPort"] run_stats(node_url)
def main(): node_ctrl = None try: opts = configure(sys.argv[1:]) except Exception as e: print(str(e), file=sys.stderr) sys.exit(1) try: count = opts['count'] # log_config = NEED currency_home = opts['data_dir'] http_port = int(opts['http_port']) gossip_port = int(opts['port']) try: ledger_type = opts["validator_config"]["LedgerType"] except KeyError: # None defaults to poet1 ledger_type = None node_ctrl = WrappedNodeController(SubprocessNodeController(), data_dir=currency_home) nodes = [] for idx in range(count): node = NodeArguments("validator-{:0>3}".format(idx), http_port=http_port + idx, gossip_port=gossip_port + idx, ledger_type=ledger_type) nodes.append(node) currency_home = node_ctrl.get_data_dir() if opts['log_config_dict']: file_name = 'launcher_cli_global_log_config.js' full_name = '{}/etc/{}'.format(currency_home, file_name) with open(full_name, 'w') as f: f.write(json.dumps(opts['log_config_dict'], indent=4)) opts['validator_config']['LogConfigFile'] = full_name if opts['validator_config']: file_name = 'launcher_cli_global_validator_config.js' with open('{}/etc/{}'.format(currency_home, file_name), 'w') as f: f.write(json.dumps(opts['validator_config'], indent=4)) for nd in nodes: nd.config_files.append(file_name) # set up our urls (external interface) urls = ['http://localhost:%s' % x.http_port for x in nodes] # Make genesis block print('creating genesis block...') nodes[0].genesis = True node_ctrl.create_genesis_block(nodes[0]) # Launch network (node zero will trigger bootstrapping) batch_size = 8 print('staged-launching network (batch_size: {})...' .format(batch_size)) lower_bound = 0 while lower_bound < count: upper_bound = lower_bound + min(count - lower_bound, batch_size) for idx in range(lower_bound, upper_bound): print("launching {}".format(nodes[idx].node_name)) node_ctrl.start(nodes[idx]) _poll_for_convergence(urls[lower_bound:upper_bound]) lower_bound = upper_bound run_stats(urls[0]) except KeyboardInterrupt: print("\nExiting") except ExitError as e: # this is an expected error/exit, don't print stack trace - # the code raising this exception is expected to have printed the error # details print("\nFailed!\nExiting: {}".format(e)) except: traceback.print_exc() print("\nFailed!\nExiting: {}".format(sys.exc_info()[0])) finally: if node_ctrl is not None: # stop all nodes for node_name in node_ctrl.get_node_names(): node_ctrl.stop(node_name) with Progress("terminating network") as p: to = TimeOut(16) while len(node_ctrl.get_node_names()) > 0: if to.is_timed_out(): break time.sleep(1) p.step() # force kill anything left over for node_name in node_ctrl.get_node_names(): print("%s still 'up'; sending kill..." % node_name) node_ctrl.kill(node_name) node_ctrl.archive('launcher') node_ctrl.clean()