risedev/task/
frontend_service.rs1use std::process::Command;
16
17use anyhow::{Result, anyhow};
18use itertools::Itertools;
19
20use super::{ExecuteContext, Task, risingwave_cmd};
21use crate::util::{get_program_args, get_program_env_cmd, get_program_name};
22use crate::{FrontendConfig, add_tempo_endpoint};
23
24pub struct FrontendService {
25 config: FrontendConfig,
26}
27
28impl FrontendService {
29 pub fn new(config: FrontendConfig) -> Result<Self> {
30 Ok(Self { config })
31 }
32
33 pub fn apply_command_args(cmd: &mut Command, config: &FrontendConfig) -> Result<()> {
35 cmd.arg("--listen-addr")
36 .arg(format!("{}:{}", config.listen_address, config.port))
37 .arg("--advertise-addr")
38 .arg(format!("{}:{}", config.address, config.port))
39 .arg("--prometheus-listener-addr")
40 .arg(format!(
41 "{}:{}",
42 config.listen_address, config.exporter_port
43 ))
44 .arg("--health-check-listener-addr")
45 .arg(format!(
46 "{}:{}",
47 config.listen_address, config.health_check_port
48 ));
49
50 let provide_meta_node = config.provide_meta_node.as_ref().unwrap();
51 if provide_meta_node.is_empty() {
52 return Err(anyhow!(
53 "Cannot configure node: no meta node found in this configuration."
54 ));
55 } else {
56 cmd.arg("--meta-addr").arg(
57 provide_meta_node
58 .iter()
59 .map(|meta_node| format!("http://{}:{}", meta_node.address, meta_node.port))
60 .join(","),
61 );
62 }
63
64 let provide_tempo = config.provide_tempo.as_ref().unwrap();
65 add_tempo_endpoint(provide_tempo, cmd)?;
66
67 Ok(())
68 }
69}
70
71impl Task for FrontendService {
72 fn execute(&mut self, ctx: &mut ExecuteContext<impl std::io::Write>) -> anyhow::Result<()> {
73 ctx.service(self);
74 ctx.pb.set_message("starting...");
75
76 let mut cmd = risingwave_cmd("frontend-node")?;
77
78 Self::apply_command_args(&mut cmd, &self.config)?;
79
80 if !self.config.user_managed {
81 ctx.run_command(ctx.tmux_run(cmd)?)?;
82 ctx.pb.set_message("started");
83 } else {
84 ctx.pb.set_message("user managed");
85 writeln!(
86 &mut ctx.log,
87 "Please use the following parameters to start the frontend:\n{}\n{} {}\n\n",
88 get_program_env_cmd(&cmd),
89 get_program_name(&cmd),
90 get_program_args(&cmd)
91 )?;
92 }
93
94 Ok(())
95 }
96
97 fn id(&self) -> String {
98 self.config.id.clone()
99 }
100}