1#![allow(clippy::doc_markdown)] use std::fmt::Write;
18use std::process::Command;
19
20use crate::{Application, HummockInMemoryStrategy, ServiceConfig, add_hummock_backend};
21
22pub fn generate_risedev_env(services: &Vec<ServiceConfig>) -> String {
26 let mut env = String::new();
27 for item in services {
28 match item {
29 ServiceConfig::ComputeNode(c) => {
30 {
33 let mut cmd = Command::new("compute-node");
34 if add_hummock_backend(
35 "dummy",
36 c.provide_opendal.as_ref().unwrap(),
37 c.provide_minio.as_ref().unwrap(),
38 c.provide_aws_s3.as_ref().unwrap(),
39 HummockInMemoryStrategy::Disallowed,
40 &mut cmd,
41 )
42 .is_ok()
43 {
44 writeln!(
45 env,
46 "RW_HUMMOCK_URL=\"{}\"",
47 cmd.get_args().nth(1).unwrap().to_str().unwrap()
48 )
49 .unwrap();
50 }
51 }
52
53 {
55 let meta_node = &c.provide_meta_node.as_ref().unwrap()[0];
56 writeln!(
57 env,
58 "RW_META_ADDR=\"http://{}:{}\"",
59 meta_node.address, meta_node.port
60 )
61 .unwrap();
62 }
63 }
64 ServiceConfig::Frontend(c) => {
65 let listen_address = &c.listen_address;
66 writeln!(
67 env,
68 "RISEDEV_RW_FRONTEND_LISTEN_ADDRESS=\"{listen_address}\"",
69 )
70 .unwrap();
71 let port = &c.port;
72 writeln!(env, "RISEDEV_RW_FRONTEND_PORT=\"{port}\"",).unwrap();
73 }
74 ServiceConfig::Kafka(c) => {
75 let brokers = format!("{}:{}", c.address, c.port);
76 writeln!(env, r#"RISEDEV_KAFKA_BOOTSTRAP_SERVERS="{brokers}""#,).unwrap();
77 writeln!(env, r#"RISEDEV_KAFKA_WITH_OPTIONS_COMMON="connector='kafka',properties.bootstrap.server='{brokers}'""#).unwrap();
78 writeln!(env, r#"RPK_BROKERS="{brokers}""#).unwrap();
79 }
80 ServiceConfig::SchemaRegistry(c) => {
81 let url = format!("http://{}:{}", c.address, c.port);
82 writeln!(env, r#"RISEDEV_SCHEMA_REGISTRY_URL="{url}""#,).unwrap();
83 writeln!(env, r#"RPK_REGISTRY_HOSTS="{url}""#).unwrap();
84 }
85 ServiceConfig::MySql(c) if c.application != Application::Metastore => {
86 let host = &c.address;
87 let port = &c.port;
88 let user = &c.user;
89 let password = &c.password;
90 writeln!(env, r#"MYSQL_HOST="{host}""#,).unwrap();
92 writeln!(env, r#"MYSQL_TCP_PORT="{port}""#,).unwrap();
93 writeln!(env, r#"RISEDEV_MYSQL_USER="{user}""#,).unwrap();
97 writeln!(env, r#"MYSQL_PWD="{password}""#,).unwrap();
98 writeln!(env, r#"RISEDEV_MYSQL_WITH_OPTIONS_COMMON="connector='mysql-cdc',hostname='{host}',port='{port}'""#,).unwrap();
101 }
102 ServiceConfig::Pubsub(c) => {
103 let address = &c.address;
104 let port = &c.port;
105 writeln!(env, r#"PUBSUB_EMULATOR_HOST="{address}:{port}""#,).unwrap();
106 writeln!(env, r#"RISEDEV_PUBSUB_WITH_OPTIONS_COMMON="connector='google_pubsub',pubsub.emulator_host='{address}:{port}'""#,).unwrap();
107 }
108 ServiceConfig::Postgres(c) => {
109 let host = &c.address;
110 let port = &c.port;
111 let user = &c.user;
112 let password = &c.password;
113 let database = &c.database;
114 writeln!(env, r#"PGHOST="{host}""#,).unwrap();
116 writeln!(env, r#"PGPORT="{port}""#,).unwrap();
117 writeln!(env, r#"PGUSER="{user}""#,).unwrap();
118 writeln!(env, r#"PGPASSWORD="{password}""#,).unwrap();
119 writeln!(env, r#"PGDATABASE="{database}""#,).unwrap();
120 writeln!(
121 env,
122 r#"RISEDEV_POSTGRES_WITH_OPTIONS_COMMON="connector='postgres-cdc',hostname='{host}',port='{port}'""#,
123 )
124 .unwrap();
125 }
126 ServiceConfig::SqlServer(c) => {
127 let host = &c.address;
128 let port = &c.port;
129 let user = &c.user;
130 let password = &c.password;
131 let database = &c.database;
132 writeln!(env, r#"SQLCMDSERVER="{host}""#,).unwrap();
134 writeln!(env, r#"SQLCMDPORT="{port}""#,).unwrap();
135 writeln!(env, r#"SQLCMDUSER="{user}""#,).unwrap();
136 writeln!(env, r#"SQLCMDPASSWORD="{password}""#,).unwrap();
137 writeln!(env, r#"SQLCMDDBNAME="{database}""#,).unwrap();
138 writeln!(
139 env,
140 r#"RISEDEV_SQLSERVER_WITH_OPTIONS_COMMON="connector='sqlserver-cdc',hostname='{host}',port='{port}',username='{user}',password='{password}',database.name='{database}'""#,
141 )
142 .unwrap();
143 }
144 ServiceConfig::MetaNode(meta_node_config) => {
145 writeln!(
146 env,
147 r#"RISEDEV_RW_META_DASHBOARD_ADDR="http://{}:{}""#,
148 meta_node_config.address, meta_node_config.dashboard_port
149 )
150 .unwrap();
151 }
152 _ => {}
153 }
154 }
155 env
156}