Skip to main content

harmos_operations/storage/
storage_status.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16// Standard Library Imports
17
18// Third Party Imports
19
20// Local Imports
21use super::POLICY;
22use harmos_domain::MemorySize;
23use harmos_domain::model::storage::StorageInfo;
24use harmos_domain::model::storage::codec::product;
25use harmos_domain::operations::ReplaySafety;
26#[cfg(feature = "runtime")]
27use harmos_storage::{ErasedCatalog, StorageManager};
28
29/* === Constants === */
30
31/* === Macros === */
32
33product!(StorageStatus {});
34
35/* === Type Aliases === */
36
37/* === Structs === */
38
39// Read The Storage Frontiers, Mutation Window And File Batch Size.
40#[harmos::operation(harmos_path = crate, resources = [StorageManager<ErasedCatalog>], codec = manual,
41    id = "storage.status",
42    response = StorageInfo,
43    policy = POLICY,
44    visibility = Host,
45    replay = ReplaySafety::Idempotent)]
46#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
47pub struct StorageStatus {}
48
49/* === Enums === */
50
51/* === Traits === */
52
53/* === Implementations === */
54
55impl MemorySize for StorageStatus {
56    fn memory_size(&self) -> usize {
57        std::mem::size_of::<Self>()
58    }
59}
60
61#[cfg(feature = "runtime")]
62mod execution {
63
64    // Standard Library Imports
65
66    // Third Party Imports
67
68    // Local Imports
69
70    use harmos_sdk::operations::Operation;
71    use harmos_storage::StorageInfo;
72
73    use crate::{Error, Result};
74
75    impl Operation for super::StorageStatus {
76        type Error = Error;
77
78        async fn run(self, context: harmos_sdk::Context<'_, Self>) -> Result<harmos_sdk::operations::Response<StorageInfo>> {
79            let storage = context.resource::<harmos_storage::StorageManager<harmos_storage::ErasedCatalog>>();
80
81            let result: ::core::result::Result<StorageInfo, Self::Error> = async move { storage.info().map_err(Into::into) }.await;
82            result.map(::core::convert::Into::into)
83        }
84
85        fn classify(error: &Error) -> harmos_sdk::operations::FailureKind {
86            crate::storage::classify(error)
87        }
88    }
89}
90
91/* === Public Functions === */
92
93/* === Private Functions === */
94
95/* === Tests === */