Skip to content

Commit

Permalink
refactor: Remove raw config from cloud deploy API payload (#1533)
Browse files Browse the repository at this point in the history
  • Loading branch information
karolisg authored May 4, 2023
1 parent a0cb5b3 commit d826b80
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
5 changes: 5 additions & 0 deletions dozer-orchestrator/src/cli/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pub fn init_dozer(config_path: String) -> Result<Dozer, CliError> {
Ok(Dozer::new(config, Arc::new(runtime)))
}

pub fn init_dozer_with_default_config() -> Result<Dozer, CliError> {
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()?;
Expand Down
4 changes: 3 additions & 1 deletion dozer-orchestrator/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
2 changes: 1 addition & 1 deletion dozer-orchestrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}
Expand Down
22 changes: 17 additions & 5 deletions dozer-orchestrator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()),
},
Expand Down Expand Up @@ -186,9 +191,16 @@ fn parse_and_generate() -> Result<Cli, OrchestrationError> {
})
}

fn init_orchestrator(cli: &Cli) -> Result<SimpleOrchestrator, CliError> {
fn init_orchestrator(
cli: &Cli,
is_cloud_orchestrator: bool,
) -> Result<SimpleOrchestrator, CliError> {
dozer_tracing::init_telemetry_closure(None, None, || -> Result<SimpleOrchestrator, CliError> {
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) => {
Expand Down
11 changes: 2 additions & 9 deletions dozer-orchestrator/src/simple/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,20 +25,14 @@ 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
let mut client: DozerCloudClient<tonic::transport::Channel> =
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();

Expand Down
4 changes: 1 addition & 3 deletions dozer-types/protos/cloud.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ message GetStatusResponse {
}

message CreateAppRequest {
string config = 2;
repeated File files = 3;
}
message ParseRequest { string sql = 1; }
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d826b80

Please sign in to comment.