Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring VM service more inline with other auraed services #530

Merged
merged 3 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading