Skip to content

Commit

Permalink
Bring VM service more inline with other auraed services (#530)
Browse files Browse the repository at this point in the history
* 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

* rename create to allocate to match auraed API style

* locked
  • Loading branch information
dmah42 authored Aug 18, 2024
1 parent e789441 commit 02e32f0
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 67 deletions.
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,35 +204,35 @@ $(1)-lint: $(GEN_RS) $(GEN_TS)

.PHONY: $(1)-test
$(1)-test: $(GEN_RS) $(GEN_TS) auraed
$(cargo) test -p $(1)
$(cargo) test -p $(1) --locked

.PHONY: $(1)-test-all
$(1)-test-all: $(GEN_RS) $(GEN_TS) auraed
$(root_cargo) test -p $(1) -- --include-ignored
$(root_cargo) test -p $(1) --locked -- --include-ignored

.PHONY: $(1)-test-integration
$(1)-test-integration: $(GEN_RS) $(GEN_TS) auraed
$(root_cargo) test -p $(1) --test '*' -- --include-ignored
$(root_cargo) test -p $(1) --locked --test '*' -- --include-ignored

.PHONY: $(1)-test-watch
$(1)-test-watch: $(GEN_RS) $(GEN_TS) auraed # Use cargo-watch to continuously run a test (e.g. make $(1)-test-watch name=path::to::test)
$(root_cargo) watch -- $(cargo) test -p $(1) $(name) -- --include-ignored --nocapture
$(root_cargo) watch -- $(cargo) test -p $(1) --locked $(name) -- --include-ignored --nocapture

.PHONY: $(1)-build
$(1)-build: $(GEN_RS) $(GEN_TS)
$(cargo) build -p $(1)
$(cargo) build -p $(1) --locked

.PHONY: $(1)-build-release
$(1)-build-release: $(GEN_RS) $(GEN_TS)
$(cargo) build -p $(1) --release
$(cargo) build -p $(1) --locked --release

.PHONY: $(1)-debug
$(1)-debug: $(GEN_RS) $(GEN_TS) $(1)-lint
$(cargo) install --path ./$(1) --debug --force
$(cargo) install --path ./$(1) --debug --force --locked

.PHONY: $(1)-release
$(1)-release: $(GEN_RS) $(GEN_TS) $(1)-lint $(1)-test ## Lint, test, and install $(1)
$(cargo) install --path ./$(1) --force
$(cargo) install --path ./$(1) --force --locked
endef

$(foreach p,$(PROGS),$(eval $(call AURAE_template,$(p),$(if $(findstring auraed,$(p)),))))
Expand All @@ -257,19 +257,19 @@ endif

.PHONY: not-auraed-build
not-auraed-build: $(GEN_RS) $(GEN_TS)
$(cargo) build --workspace --exclude auraed
$(cargo) build --workspace --locked --exclude auraed

.PHONY: not-auraed-lint
not-auraed-lint: $(GEN_RS) $(GEN_TS)
$(cargo) clippy --all-features --workspace --exclude auraed -- -D clippy::all -D warnings

.PHONY: not-auraed-test
not-auraed-test: $(GEN_RS) $(GEN_TS)
$(cargo) test --workspace --exclude auraed
$(cargo) test --workspace --locked --exclude auraed

.PHONY: not-auraed-test-all
not-auraed-test-all: $(GEN_RS) $(GEN_TS)
$(cargo) test --workspace --exclude auraed -- --include-ignored
$(cargo) test --workspace --locked --exclude auraed -- --include-ignored

#------------------------------------------------------------------------------#

Expand All @@ -281,11 +281,11 @@ libs-lint: $(GEN_RS) $(GEN_TS)

.PHONY: libs-test
libs-test: $(GEN_RS) $(GEN_TS)
$(cargo) test --workspace --exclude auraed --exclude auraescript --exclude aer
$(cargo) test --workspace --locked --exclude auraed --exclude auraescript --exclude aer

.PHONY: libs-test-all
libs-test-all: $(GEN_RS) $(GEN_TS)
$(cargo) test --workspace --exclude auraed --exclude auraescript --exclude aer -- --include-ignored
$(cargo) test --workspace --locked --exclude auraed --exclude auraescript --exclude aer -- --include-ignored

.PHONY: ebpf
ebpf:
Expand Down
6 changes: 3 additions & 3 deletions api/v0/vms/vms.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ option go_package = "github.com/aurae-runtime/ae/client/pkg/api/v0/vms;vmsv0";

service VmService {
// Reserve requested system resources for a new VM.
rpc Create(VmServiceCreateRequest) returns (VmServiceCreateResponse) {}
rpc Allocate(VmServiceAllocateRequest) returns (VmServiceAllocateResponse) {}

// Free up previously requested resources for an existing VM
rpc Free(VmServiceFreeRequest) returns (VmServiceFreeResponse) {}
Expand Down Expand Up @@ -79,10 +79,10 @@ message VirtualMachineSummary {
string auraed_address = 7;
}

message VmServiceCreateRequest{
message VmServiceAllocateRequest{
VirtualMachine machine = 1;
}
message VmServiceCreateResponse{
message VmServiceAllocateResponse{
string vm_id = 1;
}

Expand Down
55 changes: 55 additions & 0 deletions auraed/src/vms/error.rs
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 allocated: {source}")]
FailedToAllocateError { 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::FailedToAllocateError { .. }
| VmServiceError::FailedToFreeError { .. }
| VmServiceError::FailedToStartError { .. }
| VmServiceError::FailedToStopError { .. } => Status::internal(msg),
VmServiceError::MissingMachineConfig { .. }
| VmServiceError::MissingRootDrive { .. } => {
Status::failed_precondition(msg)
}
}
}
}
4 changes: 1 addition & 3 deletions auraed/src/vms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
* SPDX-License-Identifier: Apache-2.0 *
\* -------------------------------------------------------------------------- */

mod error;
mod manager;
mod virtual_machine;
mod virtual_machines;
mod vm_service;

pub(crate) use vm_service::VmService;

// TODO: Custom Errors
// pub mod errors;
Loading

0 comments on commit 02e32f0

Please sign in to comment.