Skip to content

Commit

Permalink
reorganize cli module
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijania committed Jul 21, 2021
1 parent 5ce04e6 commit b29198e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 24 deletions.
10 changes: 5 additions & 5 deletions iapyx/src/cli/args/load/burst/count.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cli::args::load::build_monitor;
use crate::cli::args::load::IapyxLoadCommandError;
use crate::load::IapyxLoad;
use crate::load::IapyxLoadConfig;
use crate::load::NodeLoad;
use crate::load::NodeLoadConfig;
pub use jortestkit::console::progress_bar::{parse_progress_bar_mode_from_str, ProgressBarMode};
use jortestkit::load::Configuration;
use std::path::PathBuf;
Expand Down Expand Up @@ -80,14 +80,14 @@ pub struct BurstCountIapyxLoadCommand {
impl BurstCountIapyxLoadCommand {
pub fn exec(&self) -> Result<(), IapyxLoadCommandError> {
let config = self.build_config();
let iapyx_load = IapyxLoad::new(config);
let iapyx_load = NodeLoad::new(config);
if let Some(stats) = iapyx_load.start()? {
stats.print()
}
Ok(())
}

fn build_config(&self) -> IapyxLoadConfig {
fn build_config(&self) -> NodeLoadConfig {
let config = Configuration::requests_per_thread(
self.threads,
self.count,
Expand All @@ -97,7 +97,7 @@ impl BurstCountIapyxLoadCommand {
self.status_pace,
);

IapyxLoadConfig {
NodeLoadConfig {
config,
use_v1: self.use_v1,
batch_size: self.batch_size,
Expand Down
10 changes: 5 additions & 5 deletions iapyx/src/cli/args/load/burst/duration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cli::args::load::build_monitor;
use crate::cli::args::load::IapyxLoadCommandError;
use crate::load::IapyxLoad;
use crate::load::IapyxLoadConfig;
use crate::load::NodeLoad;
use crate::load::NodeLoadConfig;
pub use jortestkit::console::progress_bar::{parse_progress_bar_mode_from_str, ProgressBarMode};
use jortestkit::load::Configuration;
use std::path::PathBuf;
Expand Down Expand Up @@ -80,14 +80,14 @@ pub struct BurstDurationIapyxLoadCommand {
impl BurstDurationIapyxLoadCommand {
pub fn exec(&self) -> Result<(), IapyxLoadCommandError> {
let config = self.build_config();
let iapyx_load = IapyxLoad::new(config);
let iapyx_load = NodeLoad::new(config);
if let Some(stats) = iapyx_load.start()? {
stats.print()
}
Ok(())
}

fn build_config(&self) -> IapyxLoadConfig {
fn build_config(&self) -> NodeLoadConfig {
let config = Configuration::duration(
self.threads,
std::time::Duration::from_secs(self.duration),
Expand All @@ -97,7 +97,7 @@ impl BurstDurationIapyxLoadCommand {
self.status_pace,
);

IapyxLoadConfig {
NodeLoadConfig {
config,
use_v1: self.use_v1,
batch_size: self.batch_size,
Expand Down
10 changes: 5 additions & 5 deletions iapyx/src/cli/args/load/constant/count.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cli::args::load::build_monitor;
use crate::cli::args::load::IapyxLoadCommandError;
use crate::load::IapyxLoad;
use crate::load::IapyxLoadConfig;
use crate::load::NodeLoad;
use crate::load::NodeLoadConfig;
pub use jortestkit::console::progress_bar::{parse_progress_bar_mode_from_str, ProgressBarMode};
use jortestkit::load::Configuration;
use std::path::PathBuf;
Expand Down Expand Up @@ -73,14 +73,14 @@ pub struct ConstantCountIapyxLoadCommand {
impl ConstantCountIapyxLoadCommand {
pub fn exec(&self) -> Result<(), IapyxLoadCommandError> {
let config = self.build_config();
let iapyx_load = IapyxLoad::new(config);
let iapyx_load = NodeLoad::new(config);
if let Some(stats) = iapyx_load.start()? {
stats.print()
}
Ok(())
}

fn build_config(&self) -> IapyxLoadConfig {
fn build_config(&self) -> NodeLoadConfig {
let config = Configuration::requests_per_thread(
self.threads,
self.count,
Expand All @@ -90,7 +90,7 @@ impl ConstantCountIapyxLoadCommand {
self.status_pace,
);

IapyxLoadConfig {
NodeLoadConfig {
config,
use_v1: false,
batch_size: 1,
Expand Down
10 changes: 5 additions & 5 deletions iapyx/src/cli/args/load/constant/duration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cli::args::load::build_monitor;
use crate::cli::args::load::IapyxLoadCommandError;
use crate::load::IapyxLoad;
use crate::load::IapyxLoadConfig;
use crate::load::NodeLoad;
use crate::load::NodeLoadConfig;
pub use jortestkit::console::progress_bar::{parse_progress_bar_mode_from_str, ProgressBarMode};
use jortestkit::load::Configuration;
use std::path::PathBuf;
Expand Down Expand Up @@ -73,14 +73,14 @@ pub struct ConstDurationIapyxLoadCommand {
impl ConstDurationIapyxLoadCommand {
pub fn exec(&self) -> Result<(), IapyxLoadCommandError> {
let config = self.build_config();
let iapyx_load = IapyxLoad::new(config);
let iapyx_load = NodeLoad::new(config);
if let Some(stats) = iapyx_load.start()? {
stats.print()
}
Ok(())
}

fn build_config(&self) -> IapyxLoadConfig {
fn build_config(&self) -> NodeLoadConfig {
let config = Configuration::duration(
self.threads,
std::time::Duration::from_secs(self.duration),
Expand All @@ -90,7 +90,7 @@ impl ConstDurationIapyxLoadCommand {
self.status_pace,
);

IapyxLoadConfig {
NodeLoadConfig {
config,
use_v1: false,
batch_size: 1,
Expand Down
59 changes: 55 additions & 4 deletions iapyx/src/cli/args/load/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mod burst;
mod constant;

use crate::load::IapyxLoadError;
use crate::load::MultiControllerError;
use crate::load::{ArtificialUserLoad, MultiControllerError, NodeLoadError, ServicingStationLoad};
use burst::BurstIapyxLoadCommand;
use constant::ConstIapyxLoadCommand;
pub use jortestkit::console::progress_bar::{parse_progress_bar_mode_from_str, ProgressBarMode};
use jortestkit::load::Monitor;
use std::path::PathBuf;
use structopt::StructOpt;
use thiserror::Error;

Expand All @@ -15,18 +15,69 @@ pub enum IapyxLoadCommandError {
#[error("duration or requests per thread stategy has to be defined")]
NoStrategyDefined,
#[error("load runner error")]
IapyxLoadError(#[from] IapyxLoadError),
NodeLoadError(#[from] NodeLoadError),
#[error("internal error")]
MultiControllerError(#[from] MultiControllerError),
#[error("serialize error")]
SerializeError(#[from] serde_json::Error),
#[error("servicing station error")]
ServicingStationError(#[from] crate::load::ServicingStationLoadError),
#[error("artificial users error")]
ArtificialUserError(#[from] crate::load::ArtificialUserLoadError),
}

#[derive(StructOpt, Debug)]
pub enum IapyxLoadCommand {
NodeOnly(NodeOnlyLoadCommand),
StaticOnly(StaticOnlyLoadCommand),
Simulation(ArtificialLoadCommand),
}

impl IapyxLoadCommand {
pub fn exec(&self) -> Result<(), IapyxLoadCommandError> {
match self {
Self::NodeOnly(node_only) => node_only.exec(),
Self::StaticOnly(static_only) => static_only.exec(),
Self::Simulation(simulation) => simulation.exec(),
}
}
}

#[derive(StructOpt, Debug)]
pub struct ArtificialLoadCommand {
#[structopt(short = "c", long = "config")]
config: PathBuf,
}

impl ArtificialLoadCommand {
pub fn exec(&self) -> Result<(), IapyxLoadCommandError> {
let config = serde_json::from_str(&jortestkit::file::read_file(&self.config))?;
let load = ArtificialUserLoad::new(config);
load.start().map(|_| ()).map_err(Into::into)
}
}

#[derive(StructOpt, Debug)]
pub struct StaticOnlyLoadCommand {
#[structopt(short = "c", long = "config")]
config: PathBuf,
}

impl StaticOnlyLoadCommand {
pub fn exec(&self) -> Result<(), IapyxLoadCommandError> {
let config = serde_json::from_str(&jortestkit::file::read_file(&self.config))?;
let load = ServicingStationLoad::new(config);
load.start().map(|_| ()).map_err(Into::into)
}
}

#[derive(StructOpt, Debug)]
pub enum NodeOnlyLoadCommand {
Burst(BurstIapyxLoadCommand),
Const(ConstIapyxLoadCommand),
}

impl IapyxLoadCommand {
impl NodeOnlyLoadCommand {
pub fn exec(&self) -> Result<(), IapyxLoadCommandError> {
match self {
Self::Burst(burst) => burst.exec(),
Expand Down

0 comments on commit b29198e

Please sign in to comment.