Skip to content
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
55 changes: 23 additions & 32 deletions src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

use std::{
collections::{HashMap, HashSet},
env,
sync::Arc,
};

use futures::future;
use {futures::future, rustls::pki_types::ServerName, tokio_rustls::TlsConnector};

use crate::{
commands::{Handle, HandledResult},
Expand All @@ -22,11 +23,8 @@ use crate::{
/// targets), and services know which nodes they expect to run on.
///
/// This model is slightly more convenient for performing cluster operations.
#[derive(Debug)]
pub struct Cluster {
resource_groups: Vec<ResourceGroup>,
num_zpools: u32,
num_targets: u32,

/// The hosts in the Cluster are mapped by their ID, a unique identifier which is the hostname
/// normally. However, in the test environment, it is a test-defined identifier since the
Expand All @@ -41,6 +39,14 @@ pub struct Cluster {
/// File to use to store/load cluster state. This must be specified on the manager side where
/// state must be considered; otherwise, this does not need to be specified.
state: Option<State>,

pub tls_args: Option<TlsArgs>,
}

pub struct TlsArgs {
pub tls_connector: TlsConnector,

pub domain: ServerName<'static>,
}

impl Cluster {
Expand Down Expand Up @@ -108,14 +114,6 @@ impl Cluster {
};
}

pub fn num_zpools(&self) -> u32 {
self.num_zpools
}

pub fn num_targets(&self) -> u32 {
self.num_targets
}

pub fn resource_groups(&self) -> impl Iterator<Item = &ResourceGroup> {
self.resource_groups.iter()
}
Expand All @@ -126,19 +124,6 @@ impl Cluster {
.flat_map(|group| group.resources())
}

pub fn zpool_resources(&self) -> impl Iterator<Item = &Resource> {
self.resources().filter(|res| res.kind == "heartbeat/ZFS")
}

pub fn lustre_resources(&self) -> impl Iterator<Item = &Resource> {
self.resources().filter(|res| res.kind == "lustre/Lustre")
}

pub fn lustre_resources_no_mgs(&self) -> impl Iterator<Item = &Resource> {
self.lustre_resources()
.filter(|res| res.parameters.get("type").unwrap() != "mgs")
}

pub fn host_home_resource_groups<'a>(
&'a self,
host: &'a Host,
Expand All @@ -155,11 +140,6 @@ impl Cluster {
.unwrap()
}

pub fn get_mgs(&self) -> Option<&Resource> {
self.lustre_resources()
.find(|res| res.parameters.get("type").unwrap() == "mgs")
}

pub fn hosts(&self) -> impl Iterator<Item = &Arc<Host>> {
self.hosts.values()
}
Expand Down Expand Up @@ -197,14 +177,25 @@ impl Cluster {
None => None,
};

let tls_args = if args.mtls {
Some(TlsArgs {
tls_connector: crate::tls::get_connector()?,
domain: ServerName::try_from(
env::var("HALO_SERVER_DOMAIN_NAME").expect("HALO_SERVER_DOMAIN_NAME not set."),
)
.handle_err(|e| eprintln!("Could not create server domain name: {e}"))?,
})
} else {
None
};

let mut new = Cluster {
resource_groups: Vec::new(),
hosts: HashMap::new(),
num_zpools: 0,
num_targets: 0,
args: args.clone(),
failover: false,
state,
tls_args,
};

let hosts: HashMap<String, Arc<Host>> = config
Expand Down
4 changes: 2 additions & 2 deletions src/commands/discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
parameters: HashMap::from([
("mountpoint".to_string(), "/mnt/ost2".to_string()),
("target".to_string(), "oss01e0/ost2".to_string()),
("kind".to_string(), "ost".to_string()),
("type".to_string(), "ost".to_string()),
]),
requires: Some("oss01e0".to_string()),
};
Expand All @@ -170,7 +170,7 @@ mod tests {
parameters: HashMap::from([
("mountpoint".to_string(), "/mnt/ost3".to_string()),
("target".to_string(), "oss01e1/ost3".to_string()),
("kind".to_string(), "ost".to_string()),
("type".to_string(), "ost".to_string()),
]),
requires: Some("oss01e1".to_string()),
};
Expand Down
41 changes: 11 additions & 30 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ pub mod fence;
pub mod manage;
pub mod power;
pub mod reset;
pub mod start;
pub mod status;
pub mod stop;
pub mod validate;

use {
Expand All @@ -26,8 +24,6 @@ use {

use clap::{Parser, Subcommand};

use crate::cluster::Cluster;

/// A `HandledError` represents an error that has already been handled. When you call a function
/// that returns a `HandledError` or `HandledResult`, you don't need to do anything with that error,
/// other than just be aware that it happened, and return it on to your caller.
Expand Down Expand Up @@ -93,8 +89,6 @@ pub struct Cli {
#[derive(Subcommand, Debug)]
pub enum Commands {
Status(StatusArgs),
Start,
Stop,
Discover(DiscoverArgs),
Failback(FailbackArgs),
Fence(FenceArgs),
Expand All @@ -109,31 +103,18 @@ pub enum Commands {

pub fn main(cli: &Cli) -> HandledResult<()> {
match &cli.command {
Commands::Discover(args) => return discover::discover(args),
Commands::Failback(args) => return failback::failback(cli, args),
Commands::Fence(args) => return fence::fence(cli, args),
Commands::Power(args) => return power::power(cli, args),
Commands::Validate => return validate::validate(cli),
Commands::Status(args) => return status::status(cli, args),
Commands::Manage(args) => return manage::manage(cli, args),
Commands::Unmanage(args) => return manage::unmanage(cli, args),
Commands::Activate(args) => return activate::activate(cli, args),
Commands::Deactivate(args) => return activate::deactivate(cli, args),
Commands::Reset(args) => return reset::reset(cli, args),
_ => {}
Commands::Discover(args) => discover::discover(args),
Commands::Failback(args) => failback::failback(cli, args),
Commands::Fence(args) => fence::fence(cli, args),
Commands::Power(args) => power::power(cli, args),
Commands::Validate => validate::validate(cli),
Commands::Status(args) => status::status(cli, args),
Commands::Manage(args) => manage::manage(cli, args),
Commands::Unmanage(args) => manage::unmanage(cli, args),
Commands::Activate(args) => activate::activate(cli, args),
Commands::Deactivate(args) => activate::deactivate(cli, args),
Commands::Reset(args) => reset::reset(cli, args),
}

let rt = tokio::runtime::Runtime::new()
.handle_err(|e| eprintln!("Error launching tokio runtime: {e}"))?;

rt.block_on(async {
let cluster = Cluster::from_config(cli.config.clone())?;
match &cli.command {
Commands::Start => start::start(cluster).await,
Commands::Stop => stop::stop(cluster).await,
_ => unreachable!(),
}
})
}

/// Convert multiple nodeset strings into a single, deduplicated NodeSet object.
Expand Down
48 changes: 0 additions & 48 deletions src/commands/start.rs

This file was deleted.

38 changes: 0 additions & 38 deletions src/commands/stop.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Resource {
parameters: HashMap::from([
("mountpoint".to_string(), mountpoint.to_string()),
("target".to_string(), device.to_string()),
("kind".to_string(), kind.to_string()),
("type".to_string(), kind.to_string()),
]),
requires: Some(zpool.to_string()),
})
Expand Down
Loading
Loading