Skip to content

proxystore.endpoint.config

Endpoint configuration.

EndpointConfig dataclass

Endpoint configuration.

Attributes:

  • name (str) –

    Endpoint name.

  • uuid (uuid.UUID) –

    Endpoint UUID.

  • host (str | None) –

    Host endpoint is running on.

  • port (int) –

    Port endpoint is running on.

  • relay_server (str | None) –

    Optional relay server the endpoint should register with.

  • database_path (str | None) –

    Optional path to SQLite database file that will be used for storing endpoint data. If None, data will only be stored in-memory.

  • max_object_size (int | None) –

    Optional maximum object size.

  • peer_channels (int) –

    Number of peer channels to multiplex communications over.

  • verify_certificates (int) –

    Validate the SSL certificates of the relay server.

Raises:

  • ValueError

    If the name does not contain only alphanumeric, dash, or underscore characters, if the UUID cannot be parsed, or if the port is not in the range [1, 65535].

get_configs()

get_configs(proxystore_dir: str) -> list[EndpointConfig]

Get all valid endpoint configurations in parent directory.

Parameters:

  • proxystore_dir (str) –

    Parent directory containing possible endpoint configurations.

Returns:

Source code in proxystore/endpoint/config.py
def get_configs(proxystore_dir: str) -> list[EndpointConfig]:
    """Get all valid endpoint configurations in parent directory.

    Args:
        proxystore_dir: Parent directory containing possible endpoint
            configurations.

    Returns:
        List of found configs.
    """
    endpoints: list[EndpointConfig] = []

    if not os.path.isdir(proxystore_dir):
        return endpoints

    for dirpath, _, _ in os.walk(proxystore_dir):
        if os.path.samefile(proxystore_dir, dirpath):
            continue
        try:
            cfg = read_config(dirpath)
        except FileNotFoundError:
            continue
        except ValueError:
            continue
        else:
            endpoints.append(cfg)

    return endpoints

get_log_filepath()

get_log_filepath(endpoint_dir: str) -> str

Return path to log file for endpoint.

Parameters:

  • endpoint_dir (str) –

    Directory for the endpoint.

Returns:

  • str

    Path to log file.

Source code in proxystore/endpoint/config.py
def get_log_filepath(endpoint_dir: str) -> str:
    """Return path to log file for endpoint.

    Args:
        endpoint_dir: Directory for the endpoint.

    Returns:
        Path to log file.
    """
    return os.path.join(endpoint_dir, ENDPOINT_LOG_FILE)

get_pid_filepath()

get_pid_filepath(endpoint_dir: str) -> str

Return path to PID file for endpoint.

Parameters:

  • endpoint_dir (str) –

    Directory for the endpoint.

Returns:

  • str

    Path to PID file.

Source code in proxystore/endpoint/config.py
def get_pid_filepath(endpoint_dir: str) -> str:
    """Return path to PID file for endpoint.

    Args:
        endpoint_dir: Directory for the endpoint.

    Returns:
        Path to PID file.
    """
    return os.path.join(endpoint_dir, ENDPOINT_PID_FILE)

read_config()

read_config(endpoint_dir: str) -> EndpointConfig

Read endpoint config file.

Parameters:

  • endpoint_dir (str) –

    Directory containing endpoint configuration file.

Returns:

Raises:

  • FileNotFoundError

    If a config files does not exist in the directory.

  • ValueError

    If config contains an invalid value or cannot be parsed.

Source code in proxystore/endpoint/config.py
def read_config(endpoint_dir: str) -> EndpointConfig:
    """Read endpoint config file.

    Args:
        endpoint_dir: Directory containing endpoint configuration file.

    Returns:
        Config found in `endpoint_dir`.

    Raises:
        FileNotFoundError: If a config files does not exist in the directory.
        ValueError: If config contains an invalid value or cannot be parsed.
    """
    path = os.path.join(endpoint_dir, ENDPOINT_CONFIG_FILE)

    if os.path.exists(path):
        with open(path) as f:
            try:
                cfg_json = json.load(f)
            except json.decoder.JSONDecodeError as e:
                raise ValueError(
                    f'Unable to parse ({path}): {str(e)}.',
                ) from None
        try:
            cfg = EndpointConfig(**cfg_json)
        except TypeError as e:
            raise ValueError(
                f'Keys in config ({path}) do not match expected: {str(e)}.',
            ) from None
        return cfg
    else:
        raise FileNotFoundError(
            f'Endpoint directory {endpoint_dir} does not contain a valid '
            'configuration.',
        )

validate_name()

validate_name(name: str) -> bool

Validate name only contains alphanumeric or dash/underscore chars.

Source code in proxystore/endpoint/config.py
def validate_name(name: str) -> bool:
    """Validate name only contains alphanumeric or dash/underscore chars."""
    return len(re.findall(r'[^A-Za-z0-9_\-]', name)) == 0 and len(name) > 0

write_config()

write_config(
    cfg: EndpointConfig, endpoint_dir: str
) -> None

Write config to endpoint directory.

Parameters:

  • cfg (EndpointConfig) –

    Configuration to write.

  • endpoint_dir (str) –

    Directory to write config to.

Source code in proxystore/endpoint/config.py
def write_config(cfg: EndpointConfig, endpoint_dir: str) -> None:
    """Write config to endpoint directory.

    Args:
        cfg: Configuration to write.
        endpoint_dir: Directory to write config to.
    """
    os.makedirs(endpoint_dir, exist_ok=True)
    path = os.path.join(endpoint_dir, ENDPOINT_CONFIG_FILE)
    with open(path, 'w') as f:
        data = dataclasses.asdict(cfg)
        data['uuid'] = str(data['uuid'])
        json.dump(data, f, indent=4)
        # Add newline so cat on the file looks better
        f.write('\n')