High-Level API

High-level API for SKA SDP configuration.

class ska_sdp_config.config.Config(backend=None, global_prefix: str = '', owner: dict | Owner | None = None, component_name: str | None = None, wrapper: TxnWrapper | None = None, owned_entity: tuple[str, str] | None = None, **cargs)[source]

Connection to SKA SDP configuration.

property backend: Backend

Get the backend database object.

property client_lease: Lease

Return the lease associated with the client.

It will be kept alive until the client gets closed.

close() None[source]

Close the client connection.

is_alive() bool[source]

Is the connection alive in the sense that the keep-alive key exists?

Returns:

whether it is

lease(ttl=10) Lease[source]

Generate a new lease.

Once entered can be associated with keys, which will be kept alive until the end of the lease. At that point a daemon thread will be started automatically to refresh the lease periodically (default seems to be TTL/4).

Parameters:

ttl – Time to live for lease

Returns:

lease object

property lease_is_lost: bool

Return whether this Config object’s lease has been lost.

revoke_lease() None[source]

Revokes the lease internally held by this client, if any. Shouldn’t normally be called by users, but is useful for tests.

set_alive() None[source]

Set the keep-alive key.

txn(max_retries: int = 64) Iterable[Transaction | TxnWrapper][source]

Create a Transaction for atomic configuration query/change.

As we do not use locks, transactions might have to be repeated in order to guarantee atomicity. Suggested usage is as follows:

for watcher in config.watcher(timeout=0.1):
    for txn in watcher.txn():
        # Use txn to read+write configuration

As the for loop suggests, the code might get run multiple times. Any writes using the transaction will be discarded if the transaction fails, but the application must make sure that the loop body has no other observable side effects.

See also Usage Guide for best practices for using transactions.

Parameters:

max_retries – Number of transaction retries before a RuntimeError gets raised.

watcher(timeout: float | None = None) Iterable[Watcher][source]

Create a new watcher.

Useful for waiting for changes in the configuration. Calling Etcd3Watcher.txn() on the returned watchers will create Transaction objects just like txn().

See also Usage Guide for best practices for using watchers.

Parameters:

timeout – Timeout for waiting. Watcher will loop after this time.

exception ska_sdp_config.config.LeaseLostError[source]

For when a Config object’s lease has been lost.

class ska_sdp_config.config.Transaction(owner: Owner, owned_entity: tuple[str, str] | None, lease_getter: Callable[[], Lease], txn: DbTransaction, global_prefix: str)[source]

High-level configuration queries and updates to execute atomically.

allocation: AllocationOperations

Operations over allocations

arbitrary: ArbitraryOperations

Operations over arbitrary paths

component: ComponentOperations

Operations over SDP components

deployment: DeploymentOperations

Operations over Deployments

execution_block: ExecutionBlockOperations

Operations over Execution Blocks

flow: FlowOperations

Operations over Flows

new_execution_block_id(generator: str) str[source]

Generate a new execution block ID that is not yet in use.

Parameters:

generator – Name of the generator

Returns:

execution block ID

new_processing_block_id(generator: str) str[source]

Generate a new processing block ID that is not yet in use.

Parameters:

generator – Name of the generator

Returns:

Processing block ID

processing_block: ProcessingBlockOperations

Operations over Processing Blocks

property raw: DbTransaction

Return transaction object for accessing database directly.

request: RequestOperations

Operations over requests

resource: ResourceOperations

Operations over resources

script: ScriptOperations

Operations over Scripts

property self: EntityOperations | None

Fast access to entity identified when creating the parent Config

system: SystemOperations

Operations over system config