generated from krisnova/rust-nova
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring VM service more inline with other auraed services
Specifically: * add a custom error enum and use it * split the basic implementation from the tonic wrapper * add basic documentation TODO: * validate requests * add tests
- Loading branch information
Showing
3 changed files
with
174 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* -------------------------------------------------------------------------- *\ | ||
* | █████╗ ██╗ ██╗██████╗ █████╗ ███████╗ | * | ||
* | ██╔══██╗██║ ██║██╔══██╗██╔══██╗██╔════╝ | * | ||
* | ███████║██║ ██║██████╔╝███████║█████╗ | * | ||
* | ██╔══██║██║ ██║██╔══██╗██╔══██║██╔══╝ | * | ||
* | ██║ ██║╚██████╔╝██║ ██║██║ ██║███████╗ | * | ||
* | ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ | * | ||
* +--------------------------------------------+ * | ||
* * | ||
* Distributed Systems Runtime * | ||
* -------------------------------------------------------------------------- * | ||
* Copyright 2022 - 2024, the aurae contributors * | ||
* SPDX-License-Identifier: Apache-2.0 * | ||
\* -------------------------------------------------------------------------- */ | ||
|
||
use thiserror::Error; | ||
use tonic::Status; | ||
use tracing::error; | ||
|
||
use super::virtual_machine::VmID; | ||
|
||
pub(crate) type Result<T> = std::result::Result<T, VmServiceError>; | ||
|
||
#[derive(Debug, Error)] | ||
pub(crate) enum VmServiceError { | ||
#[error("vm '{id}' could not be created: {source}")] | ||
FailedToCreateError { id: VmID, source: anyhow::Error }, | ||
#[error("vm '{id}' could not be freed: {source}")] | ||
FailedToFreeError { id: VmID, source: anyhow::Error }, | ||
#[error("vm '{id}' could not be started: {source}")] | ||
FailedToStartError { id: VmID, source: anyhow::Error }, | ||
#[error("vm '{id}' could not be stopped: {source}")] | ||
FailedToStopError { id: VmID, source: anyhow::Error }, | ||
#[error("vm config has no machine specified")] | ||
MissingMachineConfig, | ||
#[error("vm '{id}' config has no root drive specified")] | ||
MissingRootDrive { id: VmID }, | ||
} | ||
|
||
impl From<VmServiceError> for Status { | ||
fn from(err: VmServiceError) -> Self { | ||
let msg = err.to_string(); | ||
error!("{msg}"); | ||
match err { | ||
VmServiceError::FailedToCreateError { .. } | ||
| VmServiceError::FailedToFreeError { .. } | ||
| VmServiceError::FailedToStartError { .. } | ||
| VmServiceError::FailedToStopError { .. } => Status::internal(msg), | ||
VmServiceError::MissingMachineConfig { .. } | ||
| VmServiceError::MissingRootDrive { .. } => { | ||
Status::failed_precondition(msg) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters