2021-03-23 11:00:50 +01:00
|
|
|
mod actor;
|
|
|
|
mod handle_impl;
|
2021-03-24 11:29:11 +01:00
|
|
|
mod message;
|
2021-03-23 11:00:50 +01:00
|
|
|
mod update_store;
|
|
|
|
|
2021-04-22 10:14:29 +02:00
|
|
|
use std::{collections::HashSet, path::PathBuf};
|
2021-03-23 11:00:50 +01:00
|
|
|
|
|
|
|
use thiserror::Error;
|
|
|
|
use tokio::sync::mpsc;
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
use crate::index_controller::{UpdateMeta, UpdateStatus};
|
|
|
|
|
|
|
|
use actor::UpdateActor;
|
|
|
|
use message::UpdateMsg;
|
2021-04-22 10:14:29 +02:00
|
|
|
use update_store::UpdateStore;
|
|
|
|
pub use update_store::UpdateStoreInfo;
|
2021-03-23 11:00:50 +01:00
|
|
|
|
|
|
|
pub use handle_impl::UpdateActorHandleImpl;
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, UpdateError>;
|
|
|
|
type PayloadData<D> = std::result::Result<D, Box<dyn std::error::Error + Sync + Send + 'static>>;
|
|
|
|
|
2021-03-23 16:19:01 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
use mockall::automock;
|
|
|
|
|
2021-03-23 11:00:50 +01:00
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum UpdateError {
|
|
|
|
#[error("error with update: {0}")]
|
|
|
|
Error(Box<dyn std::error::Error + Sync + Send + 'static>),
|
|
|
|
#[error("Update {0} doesn't exist.")]
|
|
|
|
UnexistingUpdate(u64),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
2021-03-23 16:19:01 +01:00
|
|
|
#[cfg_attr(test, automock(type Data=Vec<u8>;))]
|
2021-03-23 11:00:50 +01:00
|
|
|
pub trait UpdateActorHandle {
|
|
|
|
type Data: AsRef<[u8]> + Sized + 'static + Sync + Send;
|
|
|
|
|
|
|
|
async fn get_all_updates_status(&self, uuid: Uuid) -> Result<Vec<UpdateStatus>>;
|
|
|
|
async fn update_status(&self, uuid: Uuid, id: u64) -> Result<UpdateStatus>;
|
|
|
|
async fn delete(&self, uuid: Uuid) -> Result<()>;
|
2021-04-28 16:43:49 +02:00
|
|
|
async fn create(&self, uuid: Uuid) -> Result<()>;
|
|
|
|
async fn snapshot(&self, uuid: Uuid, path: PathBuf) -> Result<()>;
|
|
|
|
async fn dump(&self, uuid: Uuid, path: PathBuf) -> Result<()>;
|
2021-04-14 18:55:04 +02:00
|
|
|
async fn get_info(&self) -> Result<UpdateStoreInfo>;
|
2021-04-28 16:43:49 +02:00
|
|
|
async fn get_size(&self, uuid: Uuid) -> Result<u64>;
|
2021-03-23 11:00:50 +01:00
|
|
|
async fn update(
|
|
|
|
&self,
|
|
|
|
meta: UpdateMeta,
|
|
|
|
data: mpsc::Receiver<PayloadData<Self::Data>>,
|
|
|
|
uuid: Uuid,
|
2021-03-24 11:29:11 +01:00
|
|
|
) -> Result<UpdateStatus>;
|
2021-03-23 11:00:50 +01:00
|
|
|
}
|