Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate logical and physical state in ItemSpec. #70

Merged
merged 8 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
* Implement `TarXItemSpec` for native target. ([#62])
* Support multiple workspace, profile, and flow parameters. ([#45], [#63])
* Support progress bars in `CliOutput`. ([#42], [#66])
* Consolidate `StateLogical` and `StatePhysical` into `ItemSpec::State`. ([#69], [#70])

[#62]: https://github.com/azriel91/peace/pull/62
[#45]: https://github.com/azriel91/peace/issues/45
[#63]: https://github.com/azriel91/peace/pull/63
[#42]: https://github.com/azriel91/peace/issues/42
[#66]: https://github.com/azriel91/peace/pull/66
[#69]: https://github.com/azriel91/peace/issues/69
[#70]: https://github.com/azriel91/peace/pull/70


## 0.0.5 (2022-12-18)
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ See:
| Symbol | Meaning |
|:------:|:---------------------|
| 🟢 | Works well |
| 🟡 | Work in progress |
| 🟡 | Partial support |
| ⚫ | Planned |
| 🔵 | Compatible by design |
| 🟣 | Works, "fun idea" |
Expand All @@ -40,15 +40,14 @@ See:
* 🟢 Idempotence: Multiple executions
* 🟢 Show state differences
* 🟢 Namespaced profile directories
* 🟢 Dry run
* 🟢 Resource clean up
* 🟡 Understandable progress ([#42])
* 🟡 Feature-gated incremental functionality
* 🟡 Off-the-shelf support for common items
* 🟡 Dry run
* 🔵 Understandable error reporting via [`miette`]
* 🔵 Actionable error messages
* 🟣 WASM support
* ⚫ Understandable progress ([#42])
* ⚫ Informative
* ⚫ Tutorial for writing a software lifecycle management tool
* ⚫ Built-in application execution methods -- CLI, web service
* ⚫ `peace` binary for configuration based workflows
Expand Down
33 changes: 9 additions & 24 deletions crate/cfg/src/clean_op_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use async_trait::async_trait;
use peace_data::Data;
use serde::{de::DeserializeOwned, Serialize};

use crate::{OpCheckStatus, State};
use crate::OpCheckStatus;

/// Defines the logic and data to clean up resources.
///
Expand All @@ -17,25 +17,18 @@ pub trait CleanOpSpec {
/// Error returned when any of the functions of this operation err.
type Error: std::error::Error;

/// Logical state of the managed item.
/// State of the managed item.
///
/// This is the type returned by the [`StateCurrentFnSpec`], and is used by
/// [`EnsureOpSpec`] to determine if [`exec`] needs to be run.
///
/// See [`ItemSpec::StateLogical`] for more detail.
/// See [`ItemSpec::State`] for more detail.
///
/// [`StateCurrentFnSpec`]: crate::ItemSpec::StateCurrentFnSpec
/// [`EnsureOpSpec`]: crate::ItemSpec::EnsureOpSpec
/// [`exec`]: Self::exec
/// [`ItemSpec::StateLogical`]: crate::ItemSpec::StateLogical
type StateLogical: Clone + Serialize + DeserializeOwned;

/// Physical state produced by the operation.
///
/// See [`ItemSpec::StatePhysical`] for more detail.
///
/// [`ItemSpec::StatePhysical`]: crate::ItemSpec::StatePhysical
type StatePhysical: Clone + Serialize + DeserializeOwned;
/// [`ItemSpec::State`]: crate::ItemSpec::State
type State: Clone + Serialize + DeserializeOwned;

/// Data that the operation reads from, or writes to.
///
Expand Down Expand Up @@ -77,10 +70,8 @@ pub trait CleanOpSpec {
///
/// [`StateCurrentFnSpec`]: crate::ItemSpec::StateCurrentFnSpec
/// [`StatePhysical`]: Self::StatePhysical
async fn check(
data: Self::Data<'_>,
state: &State<Self::StateLogical, Self::StatePhysical>,
) -> Result<OpCheckStatus, Self::Error>;
async fn check(data: Self::Data<'_>, state: &Self::State)
-> Result<OpCheckStatus, Self::Error>;

/// Dry-run clean up of resources referenced by `StatePhysical`.
///
Expand All @@ -105,10 +96,7 @@ pub trait CleanOpSpec {
/// [`exec`]: Self::exec
/// [`ExecRequired`]: crate::OpCheckStatus::ExecRequired
/// [`StateCurrentFnSpec`]: crate::ItemSpec::StateCurrentFnSpec
async fn exec_dry(
data: Self::Data<'_>,
state: &State<Self::StateLogical, Self::StatePhysical>,
) -> Result<(), Self::Error>;
async fn exec_dry(data: Self::Data<'_>, state: &Self::State) -> Result<(), Self::Error>;

/// Cleans up resources referenced by `StatePhysical`
///
Expand All @@ -123,8 +111,5 @@ pub trait CleanOpSpec {
/// [`check`]: Self::check
/// [`ExecRequired`]: crate::OpCheckStatus::ExecRequired
/// [`StateCurrentFnSpec`]: crate::ItemSpec::StateCurrentFnSpec
async fn exec(
data: Self::Data<'_>,
state: &State<Self::StateLogical, Self::StatePhysical>,
) -> Result<(), Self::Error>;
async fn exec(data: Self::Data<'_>, state: &Self::State) -> Result<(), Self::Error>;
}
64 changes: 28 additions & 36 deletions crate/cfg/src/ensure_op_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use async_trait::async_trait;
use peace_data::Data;
use serde::{de::DeserializeOwned, Serialize};

use crate::{OpCheckStatus, OpCtx, State};
use crate::{OpCheckStatus, OpCtx};

/// Defines the logic and data of an ensure operation.
///
Expand Down Expand Up @@ -32,25 +32,18 @@ pub trait EnsureOpSpec {
/// Error returned when any of the functions of this operation err.
type Error: std::error::Error;

/// Logical state of the managed item.
/// State of the managed item.
///
/// This is the type returned by the [`StateCurrentFnSpec`], and is used by
/// [`EnsureOpSpec`] to determine if [`exec`] needs to be run.
///
/// See [`ItemSpec::StateLogical`] for more detail.
/// See [`ItemSpec::State`] for more detail.
///
/// [`StateCurrentFnSpec`]: crate::ItemSpec::StateCurrentFnSpec
/// [`EnsureOpSpec`]: crate::ItemSpec::EnsureOpSpec
/// [`exec`]: Self::exec
/// [`ItemSpec::StateLogical`]: crate::ItemSpec::StateLogical
type StateLogical: Clone + Serialize + DeserializeOwned;

/// Physical state produced by the operation.
///
/// See [`ItemSpec::StatePhysical`] for more detail.
///
/// [`ItemSpec::StatePhysical`]: crate::ItemSpec::StatePhysical
type StatePhysical: Clone + Serialize + DeserializeOwned;
/// [`ItemSpec::State`]: crate::ItemSpec::State
type State: Clone + Serialize + DeserializeOwned;

/// State difference produced by [`StateDiffFnSpec`].
///
Expand Down Expand Up @@ -97,20 +90,19 @@ pub trait EnsureOpSpec {
/// * `data`: Runtime data that the operation reads from, or writes to.
/// * `state_current`: Current [`State`] of the managed item, returned from
/// [`StateCurrentFnSpec`].
/// * `state_desired`: Desired [`StateLogical`] of the managed item,
/// returned from [`StateDesiredFnSpec`].
/// * `state_diff`: Desired [`StateLogical`] of the managed item, returned
/// from [`StateDiffFnSpec`].
/// * `state_desired`: Desired [`State`] of the managed item, returned from
/// [`StateDesiredFnSpec`].
/// * `state_diff`: Desired [`State`] of the managed item, returned from
/// [`StateDiffFnSpec`].
///
/// [`State`]: crate::State
/// [`StateLogical`]: Self::StateLogical
/// [`State`]: Self::State
/// [`StateCurrentFnSpec`]: crate::ItemSpec::StateCurrentFnSpec
/// [`StateDesiredFnSpec`]: crate::ItemSpec::StateDesiredFnSpec
/// [`StateDiffFnSpec`]: crate::ItemSpec::StateDiffFnSpec
async fn check(
data: Self::Data<'_>,
state_current: &State<Self::StateLogical, Self::StatePhysical>,
state_desired: &Self::StateLogical,
state_current: &Self::State,
state_desired: &Self::State,
diff: &Self::StateDiff,
) -> Result<OpCheckStatus, Self::Error>;

Expand All @@ -137,25 +129,25 @@ pub trait EnsureOpSpec {
/// * `data`: Runtime data that the operation reads from, or writes to.
/// * `state_current`: Current [`State`] of the managed item, returned from
/// [`StateCurrentFnSpec`].
/// * `state_desired`: Desired [`StateLogical`] of the managed item,
/// returned from [`StateDesiredFnSpec`].
/// * `state_diff`: Desired [`StateLogical`] of the managed item, returned
/// from [`StateDiffFnSpec`].
/// * `state_desired`: Desired [`State`] of the managed item, returned from
/// [`StateDesiredFnSpec`].
/// * `state_diff`: Desired [`State`] of the managed item, returned from
/// [`StateDiffFnSpec`].
///
/// [`check`]: Self::check
/// [`ExecRequired`]: crate::OpCheckStatus::ExecRequired
/// [`State`]: crate::State
/// [`StateCurrentFnSpec`]: crate::ItemSpec::StateCurrentFnSpec
/// [`StateDesiredFnSpec`]: crate::ItemSpec::StateDesiredFnSpec
/// [`StateDiffFnSpec`]: crate::ItemSpec::StateDiffFnSpec
/// [`StateLogical`]: Self::StateLogical
/// [`State`]: Self::State
async fn exec_dry(
ctx: OpCtx<'_>,
data: Self::Data<'_>,
state_current: &State<Self::StateLogical, Self::StatePhysical>,
state_desired: &Self::StateLogical,
state_current: &Self::State,
state_desired: &Self::State,
diff: &Self::StateDiff,
) -> Result<Self::StatePhysical, Self::Error>;
) -> Result<Self::State, Self::Error>;

/// Transforms the current state to the desired state.
///
Expand All @@ -166,23 +158,23 @@ pub trait EnsureOpSpec {
/// * `data`: Runtime data that the operation reads from, or writes to.
/// * `state_current`: Current [`State`] of the managed item, returned from
/// [`StateCurrentFnSpec`].
/// * `state_desired`: Desired [`StateLogical`] of the managed item,
/// returned from [`StateDesiredFnSpec`].
/// * `state_diff`: Desired [`StateLogical`] of the managed item, returned
/// from [`StateDiffFnSpec`].
/// * `state_desired`: Desired [`State`] of the managed item, returned from
/// [`StateDesiredFnSpec`].
/// * `state_diff`: Desired [`State`] of the managed item, returned from
/// [`StateDiffFnSpec`].
///
/// [`check`]: Self::check
/// [`ExecRequired`]: crate::OpCheckStatus::ExecRequired
/// [`State`]: crate::State
/// [`StateCurrentFnSpec`]: crate::ItemSpec::StateCurrentFnSpec
/// [`StateDesiredFnSpec`]: crate::ItemSpec::StateDesiredFnSpec
/// [`StateDiffFnSpec`]: crate::ItemSpec::StateDiffFnSpec
/// [`StateLogical`]: Self::StateLogical
/// [`State`]: Self::State
async fn exec(
ctx: OpCtx<'_>,
data: Self::Data<'_>,
state_current: &State<Self::StateLogical, Self::StatePhysical>,
state_desired: &Self::StateLogical,
state_current: &Self::State,
state_desired: &Self::State,
diff: &Self::StateDiff,
) -> Result<Self::StatePhysical, Self::Error>;
) -> Result<Self::State, Self::Error>;
}
Loading