proxystore.endpoint.directory¶
Endpoint directory layout and files.
ConnectionInfo
¶
Bases: VersionedFile
Information that clients use to connect to a running endpoint.
The endpoint writes this to the connection file in its directory each
time it starts and removes it when it stops (see
EndpointDir.write_connection()).
Attributes:
-
version(int) –Format version of the connection file.
-
host(str) –Host address the endpoint is listening on.
-
port(int) –Port the endpoint is listening on.
-
token(EndpointToken) –Token that the client and endpoint prove they know.
-
tls_fingerprint(str | None) –SHA-256 fingerprint of the endpoint's TLS certificate or
Noneif the endpoint does not use TLS. -
hostname(str) –Name of the machine the endpoint is running on.
-
pid(int) –Process ID of the endpoint on that machine.
EndpointOptions
¶
Bases: TypedDict
Options of a new endpoint.
See EndpointConfig for
the meaning and default of each option.
EndpointStatus
¶
Bases: Enum
Status of an endpoint.
See
EndpointDir.status().
STALE
class-attribute
instance-attribute
¶
Endpoint on this host stopped without removing its connection file.
This happens if the endpoint process was killed or crashed. Starting or stopping the endpoint removes the stale connection file.
OTHER_HOST
class-attribute
instance-attribute
¶
Endpoint was started on another host and may still be running there.
The connection file was written by an endpoint on another host which shares the endpoint directory. Whether the endpoint is still running on that host cannot be checked from this host.
EndpointLock
¶
EndpointLock(path: str)
Advisory lock held by a running endpoint.
A running endpoint holds an exclusive lock (see
fcntl.flock()) on the lock file in its directory for as
long as it runs. The operating system releases the lock when the process
exits, even if the process crashes, so the lock reliably shows if the
endpoint is running on this host. Whether the lock is also visible to
other hosts depends on the file system of the endpoint directory.
Some file systems (e.g., some network or parallel file systems) do not
support locks. Then, acquiring the lock always succeeds, supported is
False, and the status of the endpoint is determined from the PID in
its connection file instead.
Attributes:
-
path–Path of the lock file.
-
supported–If the file system supports locks. This is
Trueuntil locking fails because locks are not supported.
Parameters:
-
path(str) –Path of the lock file.
Source code in proxystore/endpoint/directory.py
acquire
¶
Acquire the lock without waiting.
Raises:
-
RuntimeError–If this lock object already holds the lock.
-
EndpointRunningError–If another process (or another lock object in this process) holds the lock.
Source code in proxystore/endpoint/directory.py
release
¶
Release the lock if it is held.
Source code in proxystore/endpoint/directory.py
is_locked
¶
is_locked() -> bool | None
Check if the lock is held.
Returns:
-
bool | None–Trueif the lock is held by any lock object,Falseif the lock is not held, orNoneif locks are not supported.
Source code in proxystore/endpoint/directory.py
EndpointDir
dataclass
¶
EndpointDir(path: str)
Directory of an endpoint.
An endpoint directory contains the endpoint's configuration and the files created while it runs (e.g., its log and the connection file that clients use to connect).
Example
Attributes:
-
path(str) –Path of the directory.
peer_addrs_path
property
¶
peer_addrs_path: str
Path to the cache of peer addresses written by the endpoint.
from_name
classmethod
¶
Get the directory of an endpoint in a ProxyStore home directory.
The directory may not exist (e.g., because the endpoint has not been created yet).
Parameters:
-
name(str) –Name of the endpoint.
-
proxystore_dir(str | None, default:None) –ProxyStore home directory. Defaults to
home_dir().
Source code in proxystore/endpoint/directory.py
create
classmethod
¶
create(
name: str,
proxystore_dir: str | None = None,
*,
secret_key: SecretKey | None = None,
port: int | None = None,
**options: Unpack[EndpointOptions],
) -> Self
Create a new endpoint.
Creates the endpoint directory, only accessible by the owner, and writes a new secret key and the configuration of the endpoint.
Example
Parameters:
-
name(str) –Name of the endpoint.
-
proxystore_dir(str | None, default:None) –ProxyStore home directory. Defaults to
home_dir(). -
secret_key(SecretKey | None, default:None) –Secret key of the endpoint. A new key is generated if
None. -
port(int | None, default:None) –Port of the endpoint. A random port in the range [10240, 20480] is chosen if
None. -
options(Unpack[EndpointOptions], default:{}) –Other options of the endpoint (see
EndpointOptions).
Returns:
-
Self–The new endpoint directory.
Raises:
-
EndpointExistsError–If an endpoint with the name already exists.
-
ValueError–If the configuration is invalid.
Source code in proxystore/endpoint/directory.py
find_all
classmethod
¶
find_all(
proxystore_dir: str | None = None,
) -> list[tuple[Self, EndpointConfig]]
Find all endpoints with a valid configuration.
Parameters:
-
proxystore_dir(str | None, default:None) –ProxyStore home directory to search in. Defaults to
home_dir().
Returns:
-
list[tuple[Self, EndpointConfig]]–List of each endpoint directory and its configuration.
Source code in proxystore/endpoint/directory.py
read_config
¶
read_config() -> EndpointConfig
Read the endpoint configuration.
Raises:
-
EndpointNotFoundError–If the configuration file does not exist.
-
EndpointConfigError–If the configuration contains an invalid value, cannot be parsed, or the name of the endpoint does not match the name of the directory.
Source code in proxystore/endpoint/directory.py
write_config
¶
write_config(config: EndpointConfig) -> None
Atomically write the endpoint configuration.
The directory is created, only accessible by the owner, if needed.
Parameters:
-
config(EndpointConfig) –Configuration to write.
Source code in proxystore/endpoint/directory.py
resolve_path
¶
Resolve a path in the configuration of the endpoint.
~ is expanded to the user's home directory, and a relative path
is relative to the endpoint directory.
Source code in proxystore/endpoint/directory.py
write_secret_key
¶
write_secret_key(secret_key: SecretKey) -> None
Atomically write the secret key of the endpoint.
The file is only readable by the owner.
read_secret_key
¶
read_secret_key(endpoint_id: EndpointId) -> SecretKey
Read the secret key of the endpoint.
Parameters:
-
endpoint_id(EndpointId) –ID the secret key must match (i.e., the ID in the configuration of the endpoint).
Raises:
-
EndpointConfigError–If the secret key file does not exist, is malformed, or does not match the ID.
Source code in proxystore/endpoint/directory.py
peers
¶
peers() -> Peers
Get the peers of the endpoint.
This reads the configuration to get the ID of the endpoint.
Raises:
-
EndpointNotFoundError–If the configuration does not exist.
-
EndpointConfigError–If the configuration is invalid.
Source code in proxystore/endpoint/directory.py
write_connection
¶
write_connection(info: ConnectionInfo) -> None
Atomically write the connection file of the running endpoint.
The file is only readable by the owner because it contains the endpoint's token.
Source code in proxystore/endpoint/directory.py
read_connection
¶
read_connection() -> ConnectionInfo
Read the connection file of the running endpoint.
Raises:
-
FileNotFoundError–If the connection file does not exist (e.g., because the endpoint is not running).
-
EndpointConfigError–If the connection file is malformed or has an unsupported format version.
Source code in proxystore/endpoint/directory.py
remove_connection
¶
remove_connection(
info: ConnectionInfo | None = None,
) -> None
Remove the connection file if it exists.
Parameters:
-
info(ConnectionInfo | None, default:None) –Only remove the connection file if it contains this information (i.e., it was not replaced by another instance of the endpoint).
Source code in proxystore/endpoint/directory.py
status
¶
status() -> EndpointStatus
Get the status of the endpoint.
The endpoint is running if it holds its lock (see
lock()). If the
file system does not support locks, the endpoint is running if the
process in its connection file is running on this host.
Returns:
-
EndpointStatus–The status of the endpoint.
Raises:
-
EndpointNotFoundError–If the endpoint directory does not exist.
Source code in proxystore/endpoint/directory.py
check_stopped
¶
Check that the endpoint is not running.
A stale connection file left by an endpoint which stopped
unexpectedly (see
EndpointStatus.STALE)
is removed.
Raises:
-
EndpointNotFoundError–If the endpoint directory does not exist.
-
EndpointRunningError–If the endpoint is running on this host or may be running on another host.
Source code in proxystore/endpoint/directory.py
remove
¶
Remove the endpoint directory and all of its files.
Raises:
-
EndpointNotFoundError–If the endpoint directory does not exist.
-
EndpointRunningError–If the endpoint is running or may be running on another host.
Source code in proxystore/endpoint/directory.py
check_exists
¶
Check that the endpoint directory exists.
Raises:
-
EndpointNotFoundError–If the endpoint directory does not exist.
Source code in proxystore/endpoint/directory.py
restrict_permissions
¶
restrict_permissions() -> bool
Remove all group and other permissions from the directory.
Clients trust the connection file in the endpoint directory, so no one other than the owner may be able to create, replace, or rename files in it. The directory also contains the endpoint's secret key, database, and log which may contain user data. Group and other permissions are also removed from the secret key file.
Returns:
-
bool–Trueif the permissions of the directory or secret key file were changed.
Source code in proxystore/endpoint/directory.py
is_own_process
¶
Check if a process with the PID exists and is owned by this user.