pub struct Store { /* private fields */ }Expand description
The trestle state: workspaces, their environments (each a draft and numbered, immutable revisions), instances and the host-wide slot leases, in one SQLite database (WAL mode, so readers never block the writer).
Several processes open the same file: the CLI and the desktop app see each other’s writes.
A write waits for another process’s to finish. A Watcher notices commits
made through other connections.
Implementations§
Source§impl Store
impl Store
Sourcepub fn open_default() -> Result<Self>
pub fn open_default() -> Result<Self>
Open (creating it if needed) the store in the state directory.
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Open (creating it if needed) the store at path, and bring its schema up to
SCHEMA_VERSION. Errors with Error::UnsupportedVersion for a newer schema rather
than read it half-way.
Sourcepub fn create_workspace(&self, name: &str, mesh: bool) -> Result<Workspace>
pub fn create_workspace(&self, name: &str, mesh: bool) -> Result<Workspace>
Create a workspace called name.
Sourcepub fn workspaces(&self) -> Result<Vec<Workspace>>
pub fn workspaces(&self) -> Result<Vec<Workspace>>
Every workspace, by name.
Sourcepub fn workspace_by_id(&self, id: &WorkspaceId) -> Result<Workspace>
pub fn workspace_by_id(&self, id: &WorkspaceId) -> Result<Workspace>
The workspace id.
Sourcepub fn set_workspace_vars(&self, id: &WorkspaceId, vars: &VarSet) -> Result<()>
pub fn set_workspace_vars(&self, id: &WorkspaceId, vars: &VarSet) -> Result<()>
Replace the workspace’s vars.
Sourcepub fn set_workspace_source(
&self,
id: &WorkspaceId,
name: &str,
config: Option<Value>,
) -> Result<()>
pub fn set_workspace_source( &self, id: &WorkspaceId, name: &str, config: Option<Value>, ) -> Result<()>
Set the config every instance of the workspace binds the source name with, or clear it
(None).
Sourcepub fn modify_vars<E: From<Error>>(
&self,
scope: &VarScope,
f: impl FnOnce(&mut VarSet) -> Result<(), E>,
) -> Result<VarSet, E>
pub fn modify_vars<E: From<Error>>( &self, scope: &VarScope, f: impl FnOnce(&mut VarSet) -> Result<(), E>, ) -> Result<VarSet, E>
Change the vars scope names with f, in one write transaction, so a concurrent writer’s
change to other vars of the same set is kept. Returns the vars as written.
Sourcepub fn delete_workspace(&self, id: &WorkspaceId) -> Result<()>
pub fn delete_workspace(&self, id: &WorkspaceId) -> Result<()>
Delete the workspace with all its environments, revisions, instances and leases.
Sourcepub fn create_environment(
&self,
workspace: &WorkspaceId,
name: &str,
draft: Draft,
) -> Result<Environment>
pub fn create_environment( &self, workspace: &WorkspaceId, name: &str, draft: Draft, ) -> Result<Environment>
Create the environment name in workspace, with draft as its draft and no
revision yet. The draft’s env_name is set to name.
Sourcepub fn environments(&self, workspace: &WorkspaceId) -> Result<Vec<Environment>>
pub fn environments(&self, workspace: &WorkspaceId) -> Result<Vec<Environment>>
The environments of workspace, by name.
Sourcepub fn environment(&self, id: &EnvironmentId) -> Result<Environment>
pub fn environment(&self, id: &EnvironmentId) -> Result<Environment>
The environment id.
Sourcepub fn update_draft(&self, id: &EnvironmentId, draft: &Draft) -> Result<()>
pub fn update_draft(&self, id: &EnvironmentId, draft: &Draft) -> Result<()>
Replace the environment’s draft. Its committed revisions are untouched. The draft’s
env_name is kept as the environment’s name.
Sourcepub fn modify_draft<E: From<Error>>(
&self,
id: &EnvironmentId,
f: impl FnOnce(&mut Draft) -> Result<(), E>,
) -> Result<Draft, E>
pub fn modify_draft<E: From<Error>>( &self, id: &EnvironmentId, f: impl FnOnce(&mut Draft) -> Result<(), E>, ) -> Result<Draft, E>
Change the environment’s draft with f, in one write transaction, so two writers (the
CLI and the app, say) never lose each other’s edits. The draft’s env_name is kept as
the environment’s name. Returns the draft as written.
Sourcepub fn set_environment_vars(
&self,
id: &EnvironmentId,
vars: &VarSet,
) -> Result<()>
pub fn set_environment_vars( &self, id: &EnvironmentId, vars: &VarSet, ) -> Result<()>
Replace the vars every revision of the environment sees.
Sourcepub fn delete_environment(&self, id: &EnvironmentId) -> Result<()>
pub fn delete_environment(&self, id: &EnvironmentId) -> Result<()>
Delete the environment with its revisions, instances and their leases.
Sourcepub fn commit_draft(&self, id: &EnvironmentId) -> Result<Revision>
pub fn commit_draft(&self, id: &EnvironmentId) -> Result<Revision>
Commit the environment’s draft as its next revision (numbered one past its head) and make it the head.
Sourcepub fn revision(&self, env: &EnvironmentId, number: u32) -> Result<Revision>
pub fn revision(&self, env: &EnvironmentId, number: u32) -> Result<Revision>
Revision number of the environment.
Sourcepub fn revisions(&self, env: &EnvironmentId) -> Result<Vec<Revision>>
pub fn revisions(&self, env: &EnvironmentId) -> Result<Vec<Revision>>
Every revision of the environment, oldest first.
Sourcepub fn create_instance(
&self,
env: &EnvironmentId,
revision: u32,
) -> Result<Instance>
pub fn create_instance( &self, env: &EnvironmentId, revision: u32, ) -> Result<Instance>
Create an instance of revision revision of the environment, stopped and without a
slot.
Sourcepub fn instance(&self, id: &InstanceId) -> Result<Instance>
pub fn instance(&self, id: &InstanceId) -> Result<Instance>
The instance id.
Sourcepub fn instances_of(&self, env: &EnvironmentId) -> Result<Vec<Instance>>
pub fn instances_of(&self, env: &EnvironmentId) -> Result<Vec<Instance>>
The instances of the environment, oldest first.
Sourcepub fn set_desired(&self, id: &InstanceId, desired: Desired) -> Result<()>
pub fn set_desired(&self, id: &InstanceId, desired: Desired) -> Result<()>
Set whether the instance should be running.
Sourcepub fn set_overrides(&self, id: &InstanceId, overrides: &VarSet) -> Result<()>
pub fn set_overrides(&self, id: &InstanceId, overrides: &VarSet) -> Result<()>
Replace the instance’s overrides.
Sourcepub fn set_sources(
&self,
id: &InstanceId,
sources: &[SourceBinding],
) -> Result<()>
pub fn set_sources( &self, id: &InstanceId, sources: &[SourceBinding], ) -> Result<()>
Replace the overlay sources the instance takes.
Sourcepub fn delete_instance(&self, id: &InstanceId) -> Result<()>
pub fn delete_instance(&self, id: &InstanceId) -> Result<()>
Delete the instance, releasing its slot.
Sourcepub fn lease_slot(&self, instance: &InstanceId) -> Result<SlotLease>
pub fn lease_slot(&self, instance: &InstanceId) -> Result<SlotLease>
Lease the instance the lowest slot no instance on the host holds, or return the one it already holds. Atomic across processes.
Sourcepub fn release_slot(&self, instance: &InstanceId) -> Result<()>
pub fn release_slot(&self, instance: &InstanceId) -> Result<()>
Release the instance’s slot, if it holds one.
Source§impl Store
impl Store
Sourcepub fn import_workspace(&self, dir: &Path) -> Result<Workspace>
pub fn import_workspace(&self, dir: &Path) -> Result<Workspace>
Import the workspace directory dir (a trestle-workspace.toml and one environment
directory per member) as a new workspace. Each member becomes an environment whose
draft is its env.toml and the module manifests it lists, committed as revision 1.
Slots are not imported: the store leases them per instance, host-wide. Nor is
secrets.env: the store holds secret references, not values.
Sourcepub fn export_instances(
&self,
instances: &[InstanceId],
dir: &Path,
) -> Result<()>
pub fn export_instances( &self, instances: &[InstanceId], dir: &Path, ) -> Result<()>
Export instances (all of one workspace, each of a different environment) as a
workspace directory in dir: a trestle-workspace.toml whose members sit on the slots
the instances lease, and per member its revision’s env.toml and module manifests. In
the exported directory trestle env render and docker compose up work as in any
workspace.
Sourcepub fn export_workspace(
&self,
workspace: &WorkspaceId,
dir: &Path,
) -> Result<()>
pub fn export_workspace( &self, workspace: &WorkspaceId, dir: &Path, ) -> Result<()>
Export the head revision of every environment of the workspace as a workspace
directory in dir, as export_instances does. A member sits
on the slot of an instance of its head when one holds a slot, else on the lowest slot no
other member takes. Every environment needs a revision.
Sourcepub fn export_revision(
&self,
env: &EnvironmentId,
number: u32,
dir: &Path,
) -> Result<()>
pub fn export_revision( &self, env: &EnvironmentId, number: u32, dir: &Path, ) -> Result<()>
Export revision number of the environment as an environment directory in dir: its
env.toml and module manifests. No instance is needed. Like any env.toml it carries no
placement, so it renders as an environment on its own.