rename frontend to web and update contributing guide (#2509)

* rename frontend to web and update contributing guide

* rename this time

* fix build

* restructure rust code

* update documentation

* update descriptions

* Update CONTRIBUTING.md

Co-authored-by: J H <2364004+Blu-J@users.noreply.github.com>

---------

Co-authored-by: Aiden McClelland <me@drbonez.dev>
Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
Co-authored-by: J H <2364004+Blu-J@users.noreply.github.com>
This commit is contained in:
Matt Hill
2023-11-13 14:22:23 -07:00
committed by GitHub
parent 871f78b570
commit 86567e7fa5
968 changed files with 812 additions and 6672 deletions

View File

@@ -0,0 +1,126 @@
use std::collections::{BTreeMap, BTreeSet};
use chrono::{DateTime, Utc};
pub use models::HealthCheckId;
use models::ImageId;
use serde::{Deserialize, Serialize};
use tracing::instrument;
use crate::context::RpcContext;
use crate::procedure::{NoOutput, PackageProcedure, ProcedureName};
use crate::s9pk::manifest::PackageId;
use crate::util::serde::Duration;
use crate::util::Version;
use crate::volume::Volumes;
use crate::{Error, ResultExt};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct HealthChecks(pub BTreeMap<HealthCheckId, HealthCheck>);
impl HealthChecks {
#[instrument(skip_all)]
pub fn validate(
&self,
eos_version: &Version,
volumes: &Volumes,
image_ids: &BTreeSet<ImageId>,
) -> Result<(), Error> {
for check in self.0.values() {
check
.implementation
.validate(eos_version, volumes, image_ids, false)
.with_ctx(|_| {
(
crate::ErrorKind::ValidateS9pk,
format!("Health Check {}", check.name),
)
})?;
}
Ok(())
}
pub async fn check_all(
&self,
ctx: &RpcContext,
started: DateTime<Utc>,
pkg_id: &PackageId,
pkg_version: &Version,
volumes: &Volumes,
) -> Result<BTreeMap<HealthCheckId, HealthCheckResult>, Error> {
let res = futures::future::try_join_all(self.0.iter().map(|(id, check)| async move {
Ok::<_, Error>((
id.clone(),
check
.check(ctx, id, started, pkg_id, pkg_version, volumes)
.await?,
))
}))
.await?;
Ok(res.into_iter().collect())
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct HealthCheck {
pub name: String,
pub success_message: Option<String>,
#[serde(flatten)]
implementation: PackageProcedure,
pub timeout: Option<Duration>,
}
impl HealthCheck {
#[instrument(skip_all)]
pub async fn check(
&self,
ctx: &RpcContext,
id: &HealthCheckId,
started: DateTime<Utc>,
pkg_id: &PackageId,
pkg_version: &Version,
volumes: &Volumes,
) -> Result<HealthCheckResult, Error> {
let res = self
.implementation
.execute(
ctx,
pkg_id,
pkg_version,
ProcedureName::Health(id.clone()),
volumes,
Some(Utc::now().signed_duration_since(started).num_milliseconds()),
Some(
self.timeout
.map_or(std::time::Duration::from_secs(30), |d| *d),
),
)
.await?;
Ok(match res {
Ok(NoOutput) => HealthCheckResult::Success,
Err((59, _)) => HealthCheckResult::Disabled,
Err((60, _)) => HealthCheckResult::Starting,
Err((61, message)) => HealthCheckResult::Loading { message },
Err((_, error)) => HealthCheckResult::Failure { error },
})
}
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[serde(tag = "result")]
pub enum HealthCheckResult {
Success,
Disabled,
Starting,
Loading { message: String },
Failure { error: String },
}
impl std::fmt::Display for HealthCheckResult {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
HealthCheckResult::Success => write!(f, "Succeeded"),
HealthCheckResult::Disabled => write!(f, "Disabled"),
HealthCheckResult::Starting => write!(f, "Starting"),
HealthCheckResult::Loading { message } => write!(f, "Loading ({})", message),
HealthCheckResult::Failure { error } => write!(f, "Failed ({})", error),
}
}
}

View File

@@ -0,0 +1,94 @@
use std::collections::BTreeMap;
use chrono::{DateTime, Utc};
use models::PackageId;
use serde::{Deserialize, Serialize};
use self::health_check::HealthCheckId;
use crate::prelude::*;
use crate::status::health_check::HealthCheckResult;
pub mod health_check;
#[derive(Clone, Debug, Deserialize, Serialize, HasModel)]
#[serde(rename_all = "kebab-case")]
#[model = "Model<Self>"]
pub struct Status {
pub configured: bool,
pub main: MainStatus,
#[serde(default)]
pub dependency_config_errors: DependencyConfigErrors,
}
#[derive(Clone, Debug, Deserialize, Serialize, HasModel, Default)]
#[serde(rename_all = "kebab-case")]
#[model = "Model<Self>"]
pub struct DependencyConfigErrors(pub BTreeMap<PackageId, String>);
impl Map for DependencyConfigErrors {
type Key = PackageId;
type Value = String;
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[serde(tag = "status")]
#[serde(rename_all = "kebab-case")]
pub enum MainStatus {
Stopped,
Restarting,
Stopping,
Starting,
Running {
started: DateTime<Utc>,
health: BTreeMap<HealthCheckId, HealthCheckResult>,
},
BackingUp {
started: Option<DateTime<Utc>>,
health: BTreeMap<HealthCheckId, HealthCheckResult>,
},
}
impl MainStatus {
pub fn running(&self) -> bool {
match self {
MainStatus::Starting { .. }
| MainStatus::Running { .. }
| MainStatus::BackingUp {
started: Some(_), ..
} => true,
MainStatus::Stopped
| MainStatus::Stopping
| MainStatus::Restarting
| MainStatus::BackingUp { started: None, .. } => false,
}
}
pub fn stop(&mut self) {
match self {
MainStatus::Starting { .. } | MainStatus::Running { .. } => {
*self = MainStatus::Stopping;
}
MainStatus::BackingUp { started, .. } => {
*started = None;
}
MainStatus::Stopped | MainStatus::Stopping | MainStatus::Restarting => (),
}
}
pub fn started(&self) -> Option<DateTime<Utc>> {
match self {
MainStatus::Running { started, .. } => Some(*started),
MainStatus::BackingUp { started, .. } => *started,
MainStatus::Stopped => None,
MainStatus::Restarting => None,
MainStatus::Stopping => None,
MainStatus::Starting { .. } => None,
}
}
pub fn backing_up(&self) -> Self {
let (started, health) = match self {
MainStatus::Starting { .. } => (Some(Utc::now()), Default::default()),
MainStatus::Running { started, health } => (Some(started.clone()), health.clone()),
MainStatus::Stopped | MainStatus::Stopping | MainStatus::Restarting => {
(None, Default::default())
}
MainStatus::BackingUp { .. } => return self.clone(),
};
MainStatus::BackingUp { started, health }
}
}