Пример #1
0
def launch(server_addr=None, server_bin=None, server_log=None, auth_token=None,
           server_public_key=''):
    """
    Launch a connection to the graphlab server. The connection can be stopped by
    the `stop` function.

    Automatically spawns a local server, if no arguments provided or "server_bin"
    is specified.

    Notes
    -----
        Only a single connection can exist at anytime.
        Prints warning if trying to launch while there is an active connection.

    Parameters
    ----------
    server_addr : string
        The address of the server.

    server_bin : string
        The path to the server binary (local server only).

    server_log : string
        The path to the server log (local server only).

    server_public_key : string
        The server's libsodium public key, used for encryption. Default is no encryption.
    """
    if is_connected():
        __LOGGER__.warning(
            "Attempt to connect to a new server while still connected to a server."
            " Please stop the connection first by running 'graphlab.stop()' and try again.")
        return

    try:
        server_type = _get_server_type(server_addr)
        __LOGGER__.debug("Server type: %s" % server_type)
    except ValueError as e:
        __LOGGER__.error(e)
        _get_metric_tracker().track('server_launch.server_type_error', send_sys_info=True)
        return

    # Check that the unity_server binary exists
    if not hasattr(_DEFAULT_CONFIG, 'server_bin') and server_bin is None:
        __LOGGER__.error("Could not find a unity_server binary. Please try reinstalling.")
        raise AssertionError
    
    # Test that the unity_server binary works
    _verify_engine_binary(_DEFAULT_CONFIG.server_bin if server_bin is None else server_bin)

    # get and validate the product / registration key
    try:
        product_key = graphlab.product_key.get_product_key()
    except KeyError as k:
        __LOGGER__.error(k.message)
        # metric is tracked in product_key.py for different code paths
        return

    # check if there is product key
    if product_key is None:
        __LOGGER__.error(" ========================================\n"
        "GraphLab Create requires a license to use. To get a trial, non-commercial, "
        " or commercial license, visit https://dato.com/register.\n"
        "=================================================\n")
        _get_metric_tracker().track('server_launch.product_key_missing')
        return

    # get product key license info
    try:
        license_info = graphlab.product_key._get_license_info()
    except KeyError as k:
        __LOGGER__.error(k.message)
        # metric is tracked in product_key.py for different code paths
        return

    # product key check
    try:
        product_key_good = graphlab.product_key._is_product_key_valid(product_key, license_info)
    except RuntimeError as r:
        __LOGGER__.error("Fatal error. The unity_server process cannot be started. There may have been an "
                       "issue during installation of graphlab-create. Please uninstall graphlab-create "
                       "and reinstall it, looking for errors that may occur during installation. "
                       "If the problem persists, please contact [email protected].")
        _get_metric_tracker().track('server_launch.unity_server_error', send_sys_info=True)
        return

    # verify product key is good
    if (not product_key_good):
        _get_metric_tracker().track('server_launch.product_key_invalid')
        return

    # construct a server server instance based on the server_type
    if (server_type == LOCAL_SERVER_TYPE):
        server = LocalServer(server_addr, server_bin, server_log, product_key)
    elif (server_type == REMOTE_SERVER_TYPE):
        server = RemoteServer(server_addr, auth_token, product_key, public_key=server_public_key)
    else:
        raise ValueError('Invalid server type: %s' % server_type)

    # start the server
    try:
        server.start()
    except Exception as e:
        __LOGGER__.error('Cannot start server: %s' % e)
        server.try_stop()
        return

    # start the client
    (public_key, secret_key) = ('', '')
    if server_public_key != '':
       (public_key, secret_key) = get_public_secret_key_pair()
    try:
        num_tolerable_ping_failures = 4294967295
        client = Client([], server.get_server_addr(), num_tolerable_ping_failures,
                        public_key=public_key, secret_key=secret_key,
                        server_public_key=server_public_key)
        if hasattr(server, 'proc') and hasattr(server.proc, 'pid'):
            client.set_server_alive_watch_pid(server.proc.pid)
        if(auth_token is not None):
            client.add_auth_method_token(auth_token)
        client.start()
    except Exception as e:
        __LOGGER__.error("Cannot start client: %s" % e)
        if (client):
            client.stop()
        return

    _assign_server_and_client(server, client)

    assert is_connected()
Пример #2
0
def launch(server_addr=None, server_bin=None, server_log=None, auth_token=None,
           server_public_key=''):
    """
    Launch a connection to the graphlab server. The connection can be stopped by
    the `stop` function.

    Automatically spawns a local server, if no arguments provided or "server_bin"
    is specified.

    Notes
    -----
        Only a single connection can exist at anytime.
        Prints warning if trying to launch while there is an active connection.

    Parameters
    ----------
    server_addr : string
        The address of the server.

    server_bin : string
        The path to the server binary (local server only).

    server_log : string
        The path to the server log (local server only).

    server_public_key : string
        The server's libsodium public key, used for encryption. Default is no encryption. 
    """
    if is_connected():
        __LOGGER__.warning(
            "Attempt to connect to a new server while still connected to a server."
            " Please stop the connection first by running 'graphlab.stop()' and try again.")
        return

    try:
        server_type = _get_server_type(server_addr)
        __LOGGER__.debug("Server type: %s" % server_type)
    except ValueError as e:
        __LOGGER__.error(e)
        _get_metric_tracker().track('server_launch.server_type_error', send_sys_info=True)
        return

    # get and validate the product / registration key
    try:
        product_key = graphlab.product_key.get_product_key()
    except KeyError as k:
        __LOGGER__.error(k.message)
        # metric is tracked in product_key.py for different code paths
        return

    # product key check. This may fail if there are issues running
    # the unity_server binary
    try:
        product_key_good = graphlab.product_key.is_product_key_valid(product_key)
    except RuntimeError as r:
        __LOGGER__.error("Fatal error. The unity_server process cannot be started. There may have been an "
                       "issue during installation of graphlab-create. Please uninstall graphlab-create "
                       "and reinstall it, looking for errors that may occur during installation. "
                       "If the problem persists, please contact [email protected].")
        _get_metric_tracker().track('server_launch.unity_server_error', send_sys_info=True)
        return

    # verify product key is good
    if (not product_key_good):
        if product_key is None:
            __LOGGER__.error("No product key found. Please configure your product key by setting the [%s] section with"
            " '%s' key in %s or by setting the environment variable GRAPHLAB_PRODUCT_KEY to the product key."
            " If you do not have a product key, please register for one at https://dato.com/register."  % (
                    graphlab.product_key.__section, graphlab.product_key.__key, graphlab.product_key.__default_config_path))
            _get_metric_tracker().track('server_launch.product_key_missing')
        else:
            __LOGGER__.error("Product Key validation failed, please confirm your product key is correct. "
                             "If you believe this key to be valid, please contact [email protected]")
            _get_metric_tracker().track('server_launch.product_key_invalid')
        return

    # construct a server server instance based on the server_type
    if (server_type == LOCAL_SERVER_TYPE):
        server = LocalServer(server_addr, server_bin, server_log, product_key)
    elif (server_type == REMOTE_SERVER_TYPE):
        server = RemoteServer(server_addr, auth_token, product_key, public_key=server_public_key)
    else:
        raise ValueError('Invalid server type: %s' % server_type)

    # start the server
    try:
        server.start()
    except Exception as e:
        __LOGGER__.error('Cannot start server: %s' % e)
        server.try_stop()
        return

    # start the client
    (public_key, secret_key) = ('', '')
    if server_public_key != '':
       (public_key, secret_key) = get_public_secret_key_pair()
    try:
        num_tolerable_ping_failures = 3
        client = Client([], server.get_server_addr(), num_tolerable_ping_failures,
                        public_key=public_key, secret_key=secret_key,
                        server_public_key=server_public_key)
        if(auth_token is not None):
            client.add_auth_method_token(auth_token)
        client.start()
    except Exception as e:
        __LOGGER__.error("Cannot start client: %s" % e)
        if (client):
            client.stop()
        return

    _assign_server_and_client(server, client)

    assert is_connected()