From 1a60dc2a5143af23b96ee27ce7ad4cdacee3b596 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 13 Nov 2024 15:46:15 +0530 Subject: [PATCH] update: reworked commands run and setup --- crates/orchestrator/src/cli/cron/mod.rs | 3 +- crates/orchestrator/src/cli/mod.rs | 555 ++++++++++++-------- crates/orchestrator/src/cli/provider/mod.rs | 1 - crates/orchestrator/src/cron/mod.rs | 1 - crates/orchestrator/src/main.rs | 27 +- crates/orchestrator/src/setup/mod.rs | 9 +- 6 files changed, 357 insertions(+), 239 deletions(-) diff --git a/crates/orchestrator/src/cli/cron/mod.rs b/crates/orchestrator/src/cli/cron/mod.rs index 2b40c5ae..19e8a5cf 100644 --- a/crates/orchestrator/src/cli/cron/mod.rs +++ b/crates/orchestrator/src/cli/cron/mod.rs @@ -1,9 +1,8 @@ use crate::cron::event_bridge::AWSEventBridgeValidatedArgs; - pub mod event_bridge; #[derive(Clone, Debug)] pub enum CronValidatedArgs { AWSEventBridge(AWSEventBridgeValidatedArgs), -} \ No newline at end of file +} diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index 2a68552d..edef75e0 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -1,7 +1,7 @@ use std::time::Duration; use alert::AlertValidatedArgs; -use clap::{ArgGroup, Parser}; +use clap::{ArgGroup, Parser, Subcommand}; use cron::event_bridge::AWSEventBridgeCliArgs; use cron::CronValidatedArgs; use da::DaValidatedArgs; @@ -42,16 +42,29 @@ pub mod settlement; pub mod snos; pub mod storage; +#[derive(Parser, Debug)] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand, Debug)] +pub enum Commands { + /// Run the orchestrator + Run { + #[command(flatten)] + run_command: Box, + }, + /// Setup the orchestrator + Setup { + #[command(flatten)] + setup_command: Box, + }, +} + #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] #[clap( - group( - ArgGroup::new("mode") - .args(&["run", "setup"]) - .required(true) - .multiple(false) - ), - group( ArgGroup::new("provider") .args(&["aws"]) @@ -69,18 +82,21 @@ pub mod storage; .args(&["aws_s3"]) .required(true) .multiple(false) + .requires("provider") ), group( ArgGroup::new("queue") .args(&["aws_sqs"]) .required(true) .multiple(false) + .requires("provider") ), group( ArgGroup::new("alert") .args(&["aws_sns"]) .required(true) .multiple(false) + .requires("provider") ), group( ArgGroup::new("prover") @@ -94,21 +110,8 @@ pub mod storage; .required(true) .multiple(false) ), - group( - ArgGroup::new("cron") - .args(&["aws_event_bridge"]) - .required(true) - .multiple(false) - ), )] pub struct RunCmd { - // Run mode - #[arg(long)] - pub run: bool, - - #[arg(long)] - pub setup: bool, - // AWS Config #[clap(flatten)] pub aws_config_args: AWSConfigCliArgs, @@ -148,10 +151,6 @@ pub struct RunCmd { #[clap(flatten)] pub sharp_args: prover::sharp::SharpCliArgs, - // Cron - #[clap(flatten)] - pub aws_event_bridge_args: AWSEventBridgeCliArgs, - // SNOS #[clap(flatten)] pub snos_args: snos::SNOSCliArgs, @@ -334,33 +333,6 @@ impl RunCmd { } } - pub fn validate_cron_params(&self) -> Result { - if self.aws_event_bridge_args.aws_event_bridge { - Ok(CronValidatedArgs::AWSEventBridge(AWSEventBridgeValidatedArgs { - target_queue_name: self - .aws_event_bridge_args - .target_queue_name - .clone() - .expect("Target queue name is required"), - cron_time: Duration::from_secs( - self.aws_event_bridge_args - .cron_time - .clone() - .expect("Cron time is required") - .parse::() - .expect("Failed to parse cron time"), - ), - trigger_rule_name: self - .aws_event_bridge_args - .trigger_rule_name - .clone() - .expect("Trigger rule name is required"), - })) - } else { - Err("Only AWS Event Bridge is supported as of now".to_string()) - } - } - pub fn validate_instrumentation_params(&self) -> Result { Ok(InstrumentationParams { otel_service_name: self @@ -394,192 +366,323 @@ impl RunCmd { } } -#[cfg(test)] -pub mod test { - - use rstest::{fixture, rstest}; - use tracing::Level; - use url::Url; - - use super::alert::aws_sns::AWSSNSCliArgs; - use super::cron::event_bridge::AWSEventBridgeCliArgs; - use super::da::ethereum::EthereumDaCliArgs; - use super::database::mongodb::MongoDBCliArgs; - use super::instrumentation::InstrumentationCliArgs; - use super::prover::sharp::SharpCliArgs; - use super::provider::aws::AWSConfigCliArgs; - use super::queue::aws_sqs::AWSSQSCliArgs; - use super::server::ServerCliArgs; - use super::service::ServiceCliArgs; - use super::settlement::ethereum::EthereumSettlementCliArgs; - use super::settlement::starknet::StarknetSettlementCliArgs; - use super::snos::SNOSCliArgs; - use super::storage::aws_s3::AWSS3CliArgs; - use crate::cli::RunCmd; - - // create a fixture for the CLI - #[fixture] - pub fn setup_cmd() -> RunCmd { - RunCmd { - run: true, - setup: false, - aws_config_args: AWSConfigCliArgs { - aws: true, - aws_access_key_id: "".to_string(), - aws_secret_access_key: "".to_string(), - aws_region: "".to_string(), - }, - aws_event_bridge_args: AWSEventBridgeCliArgs { - aws_event_bridge: true, - target_queue_name: Some("".to_string()), - cron_time: Some("12".to_string()), - trigger_rule_name: Some("".to_string()), - }, - aws_s3_args: AWSS3CliArgs { aws_s3: true, bucket_name: Some("".to_string()) }, - aws_sqs_args: AWSSQSCliArgs { - aws_sqs: true, - queue_base_url: Some("".to_string()), - sqs_prefix: Some("".to_string()), - sqs_suffix: Some("".to_string()), - }, - server_args: ServerCliArgs { host: "".to_string(), port: 0 }, - aws_sns_args: AWSSNSCliArgs { aws_sns: true, sns_arn: Some("".to_string()) }, - - instrumentation_args: InstrumentationCliArgs { - otel_service_name: Some("".to_string()), - otel_collector_endpoint: None, - log_level: Level::INFO, - }, - - mongodb_args: MongoDBCliArgs { - mongodb: true, - mongodb_connection_url: Some("".to_string()), - mongodb_database_name: Some("".to_string()), - }, - - madara_rpc_url: Url::parse("http://localhost:8545").unwrap(), - - sharp_args: SharpCliArgs { - sharp: true, - sharp_customer_id: Some("".to_string()), - sharp_url: Some(Url::parse("http://localhost:8545").unwrap()), - sharp_user_crt: Some("".to_string()), - sharp_user_key: Some("".to_string()), - sharp_rpc_node_url: Some(Url::parse("http://localhost:8545").unwrap()), - sharp_proof_layout: Some("".to_string()), - gps_verifier_contract_address: Some("".to_string()), - sharp_server_crt: Some("".to_string()), - }, - - starknet_args: StarknetSettlementCliArgs { - starknet_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), - starknet_private_key: Some("".to_string()), - starknet_account_address: Some("".to_string()), - starknet_cairo_core_contract_address: Some("".to_string()), - starknet_finality_retry_wait_in_secs: Some(0), - starknet_madara_binary_path: Some("".to_string()), - settle_on_starknet: false, - }, - - ethereum_args: EthereumSettlementCliArgs { - ethereum_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), - ethereum_private_key: Some("".to_string()), - l1_core_contract_address: Some("".to_string()), - starknet_operator_address: Some("".to_string()), - settle_on_ethereum: true, - }, - - ethereum_da_args: EthereumDaCliArgs { - da_on_ethereum: true, - ethereum_da_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), - }, - - snos_args: SNOSCliArgs { rpc_for_snos: Url::parse("http://localhost:8545").unwrap() }, - - service_args: ServiceCliArgs { - max_block_to_process: Some("".to_string()), - min_block_to_process: Some("".to_string()), - }, - } - } - - // Let's create a test for the CLI each validator - - #[rstest] - fn test_validate_provider_params(setup_cmd: RunCmd) { - let provider_params = setup_cmd.validate_provider_params(); - assert!(provider_params.is_ok()); - } - - #[rstest] - fn test_validate_alert_params(setup_cmd: RunCmd) { - let alert_params = setup_cmd.validate_alert_params(); - assert!(alert_params.is_ok()); - } - - #[rstest] - fn test_validate_queue_params(setup_cmd: RunCmd) { - let queue_params = setup_cmd.validate_queue_params(); - assert!(queue_params.is_ok()); - } - - #[rstest] - fn test_validate_storage_params(setup_cmd: RunCmd) { - let storage_params = setup_cmd.validate_storage_params(); - assert!(storage_params.is_ok()); - } +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +#[clap( + group( + ArgGroup::new("provider") + .args(&["aws"]) + .required(true) + .multiple(false) + ), + group( + ArgGroup::new("storage") + .args(&["aws_s3"]) + .required(true) + .multiple(false) + .requires("provider") + ), + group( + ArgGroup::new("queue") + .args(&["aws_sqs"]) + .required(true) + .multiple(false) + .requires("provider") + ), + group( + ArgGroup::new("alert") + .args(&["aws_sns"]) + .required(true) + .multiple(false) + .requires("provider") + ), + group( + ArgGroup::new("cron") + .args(&["aws_event_bridge"]) + .required(true) + .multiple(false) + .requires("provider") + ), +)] +pub struct SetupCmd { + // AWS Config + #[clap(flatten)] + pub aws_config_args: AWSConfigCliArgs, - #[rstest] - fn test_validate_database_params(setup_cmd: RunCmd) { - let database_params = setup_cmd.validate_database_params(); - assert!(database_params.is_ok()); - } + // Storage + #[clap(flatten)] + pub aws_s3_args: storage::aws_s3::AWSS3CliArgs, - #[rstest] - fn test_validate_da_params(setup_cmd: RunCmd) { - let da_params = setup_cmd.validate_da_params(); - assert!(da_params.is_ok()); - } + // Queue + #[clap(flatten)] + pub aws_sqs_args: queue::aws_sqs::AWSSQSCliArgs, - #[rstest] - fn test_validate_settlement_params(setup_cmd: RunCmd) { - let settlement_params = setup_cmd.validate_settlement_params(); - assert!(settlement_params.is_ok()); - } + // Alert + #[clap(flatten)] + pub aws_sns_args: alert::aws_sns::AWSSNSCliArgs, - #[rstest] - fn test_validate_prover_params(setup_cmd: RunCmd) { - let prover_params = setup_cmd.validate_prover_params(); - assert!(prover_params.is_ok()); - } + // Cron + #[clap(flatten)] + pub aws_event_bridge_args: AWSEventBridgeCliArgs, +} - #[rstest] - fn test_validate_cron_params(setup_cmd: RunCmd) { - let cron_params = setup_cmd.validate_cron_params(); - assert!(cron_params.is_ok()); +impl SetupCmd { + pub fn validate_provider_params(&self) -> Result { + if self.aws_config_args.aws { + Ok(ProviderValidatedArgs::AWS(AWSConfigValidatedArgs { + aws_access_key_id: self.aws_config_args.aws_access_key_id.clone(), + aws_secret_access_key: self.aws_config_args.aws_secret_access_key.clone(), + aws_region: self.aws_config_args.aws_region.clone(), + })) + } else { + Err("Only AWS is supported as of now".to_string()) + } } - #[rstest] - fn test_validate_instrumentation_params(setup_cmd: RunCmd) { - let instrumentation_params = setup_cmd.validate_instrumentation_params(); - assert!(instrumentation_params.is_ok()); + pub fn validate_alert_params(&self) -> Result { + if self.aws_sns_args.aws_sns { + Ok(AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { + topic_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), + })) + } else { + Err("Only AWS SNS is supported as of now".to_string()) + } } - #[rstest] - fn test_validate_server_params(setup_cmd: RunCmd) { - let server_params = setup_cmd.validate_server_params(); - assert!(server_params.is_ok()); + pub fn validate_queue_params(&self) -> Result { + if self.aws_sqs_args.aws_sqs { + Ok(QueueValidatedArgs::AWSSQS(AWSSQSValidatedArgs { + queue_base_url: self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), + sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), + sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), + })) + } else { + Err("Only AWS SQS is supported as of now".to_string()) + } } - #[rstest] - fn test_validate_snos_params(setup_cmd: RunCmd) { - let snos_params = setup_cmd.validate_snos_params(); - assert!(snos_params.is_ok()); + pub fn validate_storage_params(&self) -> Result { + if self.aws_s3_args.aws_s3 { + Ok(StorageValidatedArgs::AWSS3(AWSS3ValidatedArgs { + bucket_name: self.aws_s3_args.bucket_name.clone().expect("Bucket name is required"), + })) + } else { + Err("Only AWS S3 is supported as of now".to_string()) + } } - #[rstest] - fn test_validate_service_params(setup_cmd: RunCmd) { - let service_params = setup_cmd.validate_service_params(); - assert!(service_params.is_ok()); + pub fn validate_cron_params(&self) -> Result { + if self.aws_event_bridge_args.aws_event_bridge { + Ok(CronValidatedArgs::AWSEventBridge(AWSEventBridgeValidatedArgs { + target_queue_name: self + .aws_event_bridge_args + .target_queue_name + .clone() + .expect("Target queue name is required"), + cron_time: Duration::from_secs( + self.aws_event_bridge_args + .cron_time + .clone() + .expect("Cron time is required") + .parse::() + .expect("Failed to parse cron time"), + ), + trigger_rule_name: self + .aws_event_bridge_args + .trigger_rule_name + .clone() + .expect("Trigger rule name is required"), + })) + } else { + Err("Only AWS Event Bridge is supported as of now".to_string()) + } } } + +// #[cfg(test)] +// pub mod test { + +// use rstest::{fixture, rstest}; +// use tracing::Level; +// use url::Url; + +// use super::alert::aws_sns::AWSSNSCliArgs; +// use super::cron::event_bridge::AWSEventBridgeCliArgs; +// use super::da::ethereum::EthereumDaCliArgs; +// use super::database::mongodb::MongoDBCliArgs; +// use super::instrumentation::InstrumentationCliArgs; +// use super::prover::sharp::SharpCliArgs; +// use super::provider::aws::AWSConfigCliArgs; +// use super::queue::aws_sqs::AWSSQSCliArgs; +// use super::server::ServerCliArgs; +// use super::service::ServiceCliArgs; +// use super::settlement::ethereum::EthereumSettlementCliArgs; +// use super::settlement::starknet::StarknetSettlementCliArgs; +// use super::snos::SNOSCliArgs; +// use super::storage::aws_s3::AWSS3CliArgs; +// use crate::cli::RunCmd; + +// // create a fixture for the CLI +// #[fixture] +// pub fn setup_cmd() -> RunCmd { +// RunCmd { +// aws_config_args: AWSConfigCliArgs { +// aws: true, +// aws_access_key_id: "".to_string(), +// aws_secret_access_key: "".to_string(), +// aws_region: "".to_string(), +// }, +// aws_event_bridge_args: AWSEventBridgeCliArgs { +// aws_event_bridge: true, +// target_queue_name: Some("".to_string()), +// cron_time: Some("12".to_string()), +// trigger_rule_name: Some("".to_string()), +// }, +// aws_s3_args: AWSS3CliArgs { aws_s3: true, bucket_name: Some("".to_string()) }, +// aws_sqs_args: AWSSQSCliArgs { +// aws_sqs: true, +// queue_base_url: Some("".to_string()), +// sqs_prefix: Some("".to_string()), +// sqs_suffix: Some("".to_string()), +// }, +// server_args: ServerCliArgs { host: "".to_string(), port: 0 }, +// aws_sns_args: AWSSNSCliArgs { aws_sns: true, sns_arn: Some("".to_string()) }, + +// instrumentation_args: InstrumentationCliArgs { +// otel_service_name: Some("".to_string()), +// otel_collector_endpoint: None, +// log_level: Level::INFO, +// }, + +// mongodb_args: MongoDBCliArgs { +// mongodb: true, +// mongodb_connection_url: Some("".to_string()), +// mongodb_database_name: Some("".to_string()), +// }, + +// madara_rpc_url: Url::parse("http://localhost:8545").unwrap(), + +// sharp_args: SharpCliArgs { +// sharp: true, +// sharp_customer_id: Some("".to_string()), +// sharp_url: Some(Url::parse("http://localhost:8545").unwrap()), +// sharp_user_crt: Some("".to_string()), +// sharp_user_key: Some("".to_string()), +// sharp_rpc_node_url: Some(Url::parse("http://localhost:8545").unwrap()), +// sharp_proof_layout: Some("".to_string()), +// gps_verifier_contract_address: Some("".to_string()), +// sharp_server_crt: Some("".to_string()), +// }, + +// starknet_args: StarknetSettlementCliArgs { +// starknet_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), +// starknet_private_key: Some("".to_string()), +// starknet_account_address: Some("".to_string()), +// starknet_cairo_core_contract_address: Some("".to_string()), +// starknet_finality_retry_wait_in_secs: Some(0), +// starknet_madara_binary_path: Some("".to_string()), +// settle_on_starknet: false, +// }, + +// ethereum_args: EthereumSettlementCliArgs { +// ethereum_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), +// ethereum_private_key: Some("".to_string()), +// l1_core_contract_address: Some("".to_string()), +// starknet_operator_address: Some("".to_string()), +// settle_on_ethereum: true, +// }, + +// ethereum_da_args: EthereumDaCliArgs { +// da_on_ethereum: true, +// ethereum_da_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), +// }, + +// snos_args: SNOSCliArgs { rpc_for_snos: Url::parse("http://localhost:8545").unwrap() }, + +// service_args: ServiceCliArgs { +// max_block_to_process: Some("".to_string()), +// min_block_to_process: Some("".to_string()), +// }, +// } +// } + +// // Let's create a test for the CLI each validator + +// #[rstest] +// fn test_validate_provider_params(setup_cmd: RunCmd) { +// let provider_params = setup_cmd.validate_provider_params(); +// assert!(provider_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_alert_params(setup_cmd: RunCmd) { +// let alert_params = setup_cmd.validate_alert_params(); +// assert!(alert_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_queue_params(setup_cmd: RunCmd) { +// let queue_params = setup_cmd.validate_queue_params(); +// assert!(queue_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_storage_params(setup_cmd: RunCmd) { +// let storage_params = setup_cmd.validate_storage_params(); +// assert!(storage_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_database_params(setup_cmd: RunCmd) { +// let database_params = setup_cmd.validate_database_params(); +// assert!(database_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_da_params(setup_cmd: RunCmd) { +// let da_params = setup_cmd.validate_da_params(); +// assert!(da_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_settlement_params(setup_cmd: RunCmd) { +// let settlement_params = setup_cmd.validate_settlement_params(); +// assert!(settlement_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_prover_params(setup_cmd: RunCmd) { +// let prover_params = setup_cmd.validate_prover_params(); +// assert!(prover_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_cron_params(setup_cmd: RunCmd) { +// let cron_params = setup_cmd.validate_cron_params(); +// assert!(cron_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_instrumentation_params(setup_cmd: RunCmd) { +// let instrumentation_params = setup_cmd.validate_instrumentation_params(); +// assert!(instrumentation_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_server_params(setup_cmd: RunCmd) { +// let server_params = setup_cmd.validate_server_params(); +// assert!(server_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_snos_params(setup_cmd: RunCmd) { +// let snos_params = setup_cmd.validate_snos_params(); +// assert!(snos_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_service_params(setup_cmd: RunCmd) { +// let service_params = setup_cmd.validate_service_params(); +// assert!(service_params.is_ok()); +// } +// } diff --git a/crates/orchestrator/src/cli/provider/mod.rs b/crates/orchestrator/src/cli/provider/mod.rs index ae8d93f5..7f51fe33 100644 --- a/crates/orchestrator/src/cli/provider/mod.rs +++ b/crates/orchestrator/src/cli/provider/mod.rs @@ -1,6 +1,5 @@ pub mod aws; - #[derive(Debug, Clone)] pub enum ProviderValidatedArgs { AWS(AWSConfigValidatedArgs), diff --git a/crates/orchestrator/src/cron/mod.rs b/crates/orchestrator/src/cron/mod.rs index d3ad7a4c..ec1804b0 100644 --- a/crates/orchestrator/src/cron/mod.rs +++ b/crates/orchestrator/src/cron/mod.rs @@ -7,7 +7,6 @@ use crate::queue::job_queue::{WorkerTriggerMessage, WorkerTriggerType}; pub mod event_bridge; - lazy_static! { pub static ref CRON_DURATION: Duration = Duration::from_mins(1); // TODO : we can take this from clap. diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index d63087b3..90461de6 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -1,6 +1,6 @@ use clap::Parser as _; use dotenvy::dotenv; -use orchestrator::cli::RunCmd; +use orchestrator::cli::{Cli, Commands, RunCmd, SetupCmd}; use orchestrator::config::init_config; use orchestrator::queue::init_consumers; use orchestrator::routes::setup_server; @@ -14,14 +14,20 @@ use orchestrator::telemetry::{setup_analytics, shutdown_analytics}; #[allow(clippy::needless_return)] async fn main() { dotenv().ok(); - // TODO: could this be an ARC ? - let run_cmd: RunCmd = RunCmd::parse(); - if run_cmd.setup { - setup_cloud(&run_cmd).await.expect("Failed to setup cloud"); - return; + let cli = Cli::parse(); + + match &cli.command { + Commands::Run { run_command } => { + run_orchestrator(run_command).await.expect("Failed to run orchestrator"); + } + Commands::Setup { setup_command } => { + setup_orchestrator(setup_command).await.expect("Failed to setup orchestrator"); + } } +} +async fn run_orchestrator(run_cmd: &RunCmd) -> color_eyre::Result<()> { // Analytics Setup let instrumentation_params = run_cmd.validate_instrumentation_params().expect("Invalid instrumentation params"); let meter_provider = setup_analytics(&instrumentation_params); @@ -30,7 +36,7 @@ async fn main() { color_eyre::install().expect("Unable to install color_eyre"); // initial config setup - let config = init_config(&run_cmd).await.expect("Config instantiation failed"); + let config = init_config(run_cmd).await.expect("Config instantiation failed"); tracing::debug!(service = "orchestrator", "Configuration initialized"); // initialize the server @@ -52,4 +58,11 @@ async fn main() { // Analytics Shutdown shutdown_analytics(meter_provider, &instrumentation_params); tracing::info!(service = "orchestrator", "Orchestrator service shutting down"); + + Ok(()) +} + +async fn setup_orchestrator(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { + setup_cloud(setup_cmd).await.expect("Failed to setup cloud"); + Ok(()) } diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index 42e2d51b..3957816f 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -8,7 +8,7 @@ use crate::cli::alert::AlertValidatedArgs; use crate::cli::cron::CronValidatedArgs; use crate::cli::queue::QueueValidatedArgs; use crate::cli::storage::StorageValidatedArgs; -use crate::cli::RunCmd; +use crate::cli::SetupCmd; use crate::config::build_provider_config; use crate::cron::event_bridge::AWSEventBridge; use crate::cron::Cron; @@ -23,11 +23,13 @@ pub enum SetupConfig { } // TODO : move this to main.rs after moving to clap. -pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { +pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { println!("Setting up cloud."); + // AWS let provider_params = run_cmd.validate_provider_params().expect("Failed to validate provider params"); let provider_config = build_provider_config(&provider_params).await; + // Data Storage println!("Setting up data storage."); let data_storage_params = run_cmd.validate_storage_params().expect("Failed to validate storage params"); let aws_config = provider_config.get_aws_client_or_panic(); @@ -40,6 +42,7 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { } println!("Data storage setup completed ✅"); + // Queues println!("Setting up queues"); let queue_params = run_cmd.validate_queue_params().expect("Failed to validate queue params"); match queue_params { @@ -50,6 +53,7 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { } println!("Queues setup completed ✅"); + // Cron println!("Setting up cron"); let cron_params = run_cmd.validate_cron_params().expect("Failed to validate cron params"); match cron_params { @@ -61,6 +65,7 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { } println!("Cron setup completed ✅"); + // Alerts println!("Setting up alerts."); let alert_params = run_cmd.validate_alert_params().expect("Failed to validate alert params"); match alert_params {