harmos_operations/storage/
write_streams.rs1use super::IO_POLICY;
22use harmos_domain::Identifier;
23use harmos_domain::MemorySize;
24use harmos_domain::model::storage::codec::{Id, Optional, product};
25use harmos_domain::model::storage::{DataBatch, WriteCompletion, WriteReceipt};
26use harmos_domain::operations::ReplaySafety;
27#[cfg(feature = "runtime")]
28use harmos_sdk::operations::access::GrantAccess;
29#[cfg(feature = "runtime")]
30use harmos_storage::{ErasedCatalog, StorageManager};
31
32product!(WriteStreams {
37 scope: Optional<Id> => 1,
38});
39
40#[harmos::operation(
46 harmos_path = crate,
47 resources = [StorageManager<ErasedCatalog>, GrantAccess],
48 codec = manual,
49 id = "storage.write_streams",
50 response = WriteCompletion,
51 policy = IO_POLICY,
52 input = DataBatch,
53 output = WriteReceipt,
54 visibility = Shared,
55 replay = ReplaySafety::Unknown,
56 grpc(package = "harmos.storage.v1", service = "Storage", method = "WriteStreams"),
57)]
58#[derive(Clone, Debug, PartialEq, Eq)]
59pub struct WriteStreams {
60 pub scope: Option<Identifier>,
61}
62
63impl MemorySize for WriteStreams {
70 fn memory_size(&self) -> usize {
71 std::mem::size_of::<Self>().saturating_add(self.scope.memory_size().saturating_sub(std::mem::size_of_val(&self.scope)))
72 }
73}
74
75#[cfg(feature = "runtime")]
76mod execution {
77 use super::*;
78 use crate::storage::exchange::{WriteKind, exchange};
79
80 use crate::{Error, Result};
84 use harmos_sdk::operations::{Operation, OperationDeclaration};
85 use harmos_storage::writes::WriteCompletion;
86
87 impl Operation for super::WriteStreams {
88 type Error = Error;
89
90 async fn run(self, context: harmos_sdk::Context<'_, Self>) -> Result<harmos_sdk::operations::Response<WriteCompletion>> {
91 let storage = context.resource::<harmos_storage::StorageManager<harmos_storage::ErasedCatalog>>();
92 let grants = context.resource::<harmos_sdk::operations::access::GrantAccess>();
93 let endpoints = context.streams();
94
95 let host = grants;
96 let ctx = &host.0;
97 let completion = exchange(&storage, ctx, self.scope.as_ref(), endpoints, WriteKind::Streams, WriteStreams::ID).await?;
98 Ok(completion.into())
99 }
100
101 fn classify(error: &Error) -> harmos_sdk::operations::FailureKind {
102 crate::storage::classify(error)
103 }
104 }
105}
106
107