From d826b802034c2c2f5325f3d221e78f83f111e7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Gudi=C5=A1kis?= Date: Thu, 4 May 2023 17:01:05 +0300 Subject: [PATCH] refactor: Remove raw config from cloud deploy API payload (#1533) --- dozer-orchestrator/src/cli/helper.rs | 5 +++++ dozer-orchestrator/src/cli/mod.rs | 4 +++- dozer-orchestrator/src/lib.rs | 2 +- dozer-orchestrator/src/main.rs | 22 +++++++++++++++++----- dozer-orchestrator/src/simple/cloud.rs | 11 ++--------- dozer-types/protos/cloud.proto | 4 +--- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/dozer-orchestrator/src/cli/helper.rs b/dozer-orchestrator/src/cli/helper.rs index 42f7281f4d..df808627c4 100644 --- a/dozer-orchestrator/src/cli/helper.rs +++ b/dozer-orchestrator/src/cli/helper.rs @@ -23,6 +23,11 @@ pub fn init_dozer(config_path: String) -> Result { Ok(Dozer::new(config, Arc::new(runtime))) } +pub fn init_dozer_with_default_config() -> Result { + let runtime = Runtime::new().map_err(CliError::FailedToCreateTokioRuntime)?; + Ok(Dozer::new(Config::default(), Arc::new(runtime))) +} + pub fn list_sources(config_path: &str) -> Result<(), OrchestrationError> { let dozer = init_dozer(config_path.to_string())?; let connection_map = dozer.list_connectors()?; diff --git a/dozer-orchestrator/src/cli/mod.rs b/dozer-orchestrator/src/cli/mod.rs index eb1de27547..24d5adf48a 100644 --- a/dozer-orchestrator/src/cli/mod.rs +++ b/dozer-orchestrator/src/cli/mod.rs @@ -4,5 +4,7 @@ mod helper; mod init; pub mod types; -pub use helper::{init_dozer, list_sources, load_config_from_file, LOGO}; +pub use helper::{ + init_dozer, init_dozer_with_default_config, list_sources, load_config_from_file, LOGO, +}; pub use init::{generate_config_repl, generate_connection}; diff --git a/dozer-orchestrator/src/lib.rs b/dozer-orchestrator/src/lib.rs index 6b6f0d0e52..eea0412d6a 100644 --- a/dozer-orchestrator/src/lib.rs +++ b/dozer-orchestrator/src/lib.rs @@ -40,7 +40,7 @@ pub trait Orchestrator { #[cfg(feature = "cloud")] pub trait CloudOrchestrator { - fn deploy(&mut self, cloud: Cloud, config_path: String) -> Result<(), OrchestrationError>; + fn deploy(&mut self, cloud: Cloud) -> Result<(), OrchestrationError>; fn list(&mut self, cloud: Cloud) -> Result<(), OrchestrationError>; fn status(&mut self, cloud: Cloud, app_id: String) -> Result<(), OrchestrationError>; } diff --git a/dozer-orchestrator/src/main.rs b/dozer-orchestrator/src/main.rs index a1a8b38235..3557b5018f 100644 --- a/dozer-orchestrator/src/main.rs +++ b/dozer-orchestrator/src/main.rs @@ -3,7 +3,7 @@ use clap::Parser; use dozer_orchestrator::cli::cloud::CloudCommands; use dozer_orchestrator::cli::generate_config_repl; use dozer_orchestrator::cli::types::{ApiCommands, AppCommands, Cli, Commands, ConnectorCommands}; -use dozer_orchestrator::cli::{init_dozer, list_sources, LOGO}; +use dozer_orchestrator::cli::{init_dozer, init_dozer_with_default_config, list_sources, LOGO}; use dozer_orchestrator::errors::{CliError, OrchestrationError}; use dozer_orchestrator::simple::SimpleOrchestrator; #[cfg(feature = "cloud")] @@ -110,7 +110,12 @@ fn run() -> Result<(), OrchestrationError> { // and then initializing it after reading the configuration. This is a hacky workaround, but it works. let cli = parse_and_generate()?; - let mut dozer = init_orchestrator(&cli)?; + #[cfg(feature = "cloud")] + let is_cloud_orchestrator = matches!(cli.cmd, Some(Commands::Cloud(_))); + #[cfg(not(feature = "cloud"))] + let is_cloud_orchestrator = false; + + let mut dozer = init_orchestrator(&cli, is_cloud_orchestrator)?; let (shutdown_sender, shutdown_receiver) = shutdown::new(&dozer.runtime); set_ctrl_handler(shutdown_sender); @@ -151,7 +156,7 @@ fn run() -> Result<(), OrchestrationError> { Commands::Clean => dozer.clean(), #[cfg(feature = "cloud")] Commands::Cloud(cloud) => match cloud.command.clone() { - CloudCommands::Deploy => dozer.deploy(cloud, cli.config_path), + CloudCommands::Deploy => dozer.deploy(cloud), CloudCommands::List => dozer.list(cloud), CloudCommands::Status(ref app) => dozer.status(cloud, app.app_id.clone()), }, @@ -186,9 +191,16 @@ fn parse_and_generate() -> Result { }) } -fn init_orchestrator(cli: &Cli) -> Result { +fn init_orchestrator( + cli: &Cli, + is_cloud_orchestrator: bool, +) -> Result { dozer_tracing::init_telemetry_closure(None, None, || -> Result { - let res = init_dozer(cli.config_path.clone()); + let res = if is_cloud_orchestrator { + init_dozer_with_default_config() + } else { + init_dozer(cli.config_path.clone()) + }; match res { Ok(dozer) => { diff --git a/dozer-orchestrator/src/simple/cloud.rs b/dozer-orchestrator/src/simple/cloud.rs index 4c36fe9106..45d7430c04 100644 --- a/dozer-orchestrator/src/simple/cloud.rs +++ b/dozer-orchestrator/src/simple/cloud.rs @@ -9,11 +9,10 @@ use dozer_types::grpc_types::cloud::{ }; use dozer_types::log::info; use dozer_types::prettytable::{row, table}; -use std::fs; impl CloudOrchestrator for SimpleOrchestrator { // TODO: Deploy Dozer application using local Dozer configuration - fn deploy(&mut self, cloud: Cloud, config_path: String) -> Result<(), OrchestrationError> { + fn deploy(&mut self, cloud: Cloud) -> Result<(), OrchestrationError> { let target_url = cloud.target_url; // let username = match deploy.username { // Some(u) => u, @@ -26,9 +25,6 @@ impl CloudOrchestrator for SimpleOrchestrator { info!("Deployment target url: {:?}", target_url); // info!("Authenticating for username: {:?}", username); // info!("Local dozer configuration path: {:?}", config_path); - // getting local dozer config file - let config_content = fs::read_to_string(&config_path) - .map_err(|e| DeployError::CannotReadConfig(config_path.into(), e))?; // calling the target url with the config fetched self.runtime.block_on(async move { // 1. CREATE application @@ -36,10 +32,7 @@ impl CloudOrchestrator for SimpleOrchestrator { DozerCloudClient::connect(target_url).await?; let files = list_files()?; let response = client - .create_application(CreateAppRequest { - files, - config: config_content, - }) + .create_application(CreateAppRequest { files }) .await? .into_inner(); diff --git a/dozer-types/protos/cloud.proto b/dozer-types/protos/cloud.proto index 1cf010f572..878f083229 100644 --- a/dozer-types/protos/cloud.proto +++ b/dozer-types/protos/cloud.proto @@ -47,7 +47,6 @@ message GetStatusResponse { } message CreateAppRequest { - string config = 2; repeated File files = 3; } message ParseRequest { string sql = 1; } @@ -131,8 +130,7 @@ message LogMessageRequest { string app_name = 1; } message StatusUpdateRequest { - optional string host = 1; - optional uint32 port = 2; + string app_id = 1; } message Pagination { uint32 limit = 1;