Ejemplo n.º 1
0
def main_status(argv=None):
    args = parse_args_status(argv)

    if args.engine is None:
        engines = Engine.list()
    else:
        engine = Engine(args.engine)
        ensure_engine_exists(engine)

        engines = [engine]

    if len(engines) == 0:
        print('No engine found.')

    for engine in engines:
        node = EngineNode(engine)
        node_running = node.running
        node_state = node.state

        rest_api_s = ('running - %s/translate' % node_state.api_port) \
            if node_running else 'stopped'
        cluster_s = ('running - port %d' % node_state.cluster_port) \
            if node_running else 'stopped'
        binlog_s = ('running - %s:%d' % (node_state.binlog_host, node_state.binlog_port)) \
            if node_running else 'stopped'
        database_s = ('running - %s:%d' % (node_state.database_host, node_state.database_port)) \
            if node_running else 'stopped'

        print('[Engine: "%s"]' % engine.name)
        print('    REST API:   %s' % rest_api_s)
        print('    Cluster:    %s' % cluster_s)
        print('    Binary log: %s' % binlog_s)
        print('    Database:   %s' % database_s)
Ejemplo n.º 2
0
def _load_node(engine_name):
    engine = Engine(engine_name)
    ensure_engine_exists(engine)

    node = EngineNode(engine)
    ensure_node_running(node)
    ensure_node_has_api(node)

    return node
Ejemplo n.º 3
0
def main_stop(argv=None):
    args = parse_args_stop(argv)

    engine = Engine(args.engine)
    ensure_engine_exists(engine)
    node = EngineNode(engine)
    ensure_node_running(node)

    try:
        print('Halting engine "%s"...' % engine.name, end='', flush=True)
        node.stop(force=args.forced)
        print('OK', flush=True)
    except Exception:
        print('FAIL', flush=True)
        raise
Ejemplo n.º 4
0
def main(argv=None):
    args = parse_args(argv)

    engine = Engine(args.engine)
    ensure_engine_exists(engine)

    node = EngineNode(engine)
    ensure_node_running(node)
    ensure_node_has_api(node)

    wdir = engine.get_tempdir('evaluate')
    shutil.rmtree(wdir, ignore_errors=True)
    os.makedirs(wdir)

    activity = EvaluateActivity(node, args, wdir=wdir, delete_on_exit=not args.debug)
    activity.run()
Ejemplo n.º 5
0
def main_start(argv=None):
    args = parse_args_start(argv)

    engine = Engine(args.engine)
    ensure_engine_exists(engine)
    node = EngineNode(engine)
    ensure_node_not_running(node)

    success = False

    try:
        # start the ClusterNode
        print('Starting engine "%s"...' % engine.name, end='', flush=True)
        node.start(api_port=args.api_port,
                   cluster_port=args.cluster_port,
                   binlog_port=args.binlog_port,
                   db_port=args.db_port,
                   leader=args.leader,
                   verbosity=args.verbosity,
                   remote_debug=args.remote_debug,
                   log_file=args.log_file)
        node.wait('JOINED')
        print('OK', flush=True)

        print('Loading models...', end='', flush=True)
        node.wait('RUNNING')
        print('OK', flush=True)

        # the node has started
        print('\nEngine "%s" started successfully\n' % engine.name)

        if node.api is not None:
            print(
                'You can try the API with:\n'
                '\tcurl "%s/translate?q=world&source=en&target=it&context=computer"'
                ' | python -mjson.tool\n' % node.api.base_path)
        success = True
    except Exception:
        print('FAIL', flush=True)
        raise
    finally:
        if not success:
            node.stop()