1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
pub enum Components {
#[clap(name = "minio")]
Minio,
Hdfs,
PrometheusAndGrafana,
Etcd,
Kafka,
@@ -77,6 +78,7 @@ impl Components {
pub fn title(&self) -> String {
match self {
Self::Minio => "[Component] Hummock: MinIO + MinIO-CLI",
Self::Hdfs => "[Component] Hummock: Hdfs Backend",
Self::PrometheusAndGrafana => "[Component] Metrics: Prometheus + Grafana",
Self::Etcd => "[Component] Etcd",
Self::Kafka => "[Component] Kafka",
@@ -97,6 +99,10 @@ impl Components {
match self {
Self::Minio => {
"
Required by Hummock state store."
}
Self::Hdfs => {
"
Required by Hummock state store."
}
Self::PrometheusAndGrafana => {
@@ -169,6 +175,7 @@ Required if you want to create CDC source from external Databases.
pub fn from_env(env: impl AsRef<str>) -> Option<Self> {
match env.as_ref() {
"ENABLE_MINIO" => Some(Self::Minio),
"ENABLE_HDFS" => Some(Self::Hdfs),
"ENABLE_PROMETHEUS_GRAFANA" => Some(Self::PrometheusAndGrafana),
"ENABLE_ETCD" => Some(Self::Etcd),
"ENABLE_KAFKA" => Some(Self::Kafka),
@@ -188,6 +195,7 @@ Required if you want to create CDC source from external Databases.
pub fn env(&self) -> String {
match self {
Self::Minio => "ENABLE_MINIO",
Self::Hdfs => "ENABLE_HDFS",
Self::PrometheusAndGrafana => "ENABLE_PROMETHEUS_GRAFANA",
Self::Etcd => "ENABLE_ETCD",
Self::Kafka => "ENABLE_KAFKA",
Self::Pubsub => "ENABLE_PUBSUB",
Self::Redis => "ENABLE_REDIS",
Self::RustComponents => "ENABLE_BUILD_RUST",
Self::Dashboard => "ENABLE_BUILD_DASHBOARD_V2",
Self::Tracing => "ENABLE_COMPUTE_TRACING",
Self::Release => "ENABLE_RELEASE_PROFILE",
Self::AllInOne => "ENABLE_ALL_IN_ONE",
Self::Sanitizer => "ENABLE_SANITIZER",
Self::ConnectorNode => "ENABLE_RW_CONNECTOR",
}
.into()
}
pub fn default_enabled() -> &'static [Self] {
&[Self::RustComponents]
}
}
fn configure(chosen: &[Components]) -> Result<Option<Vec<Components>>> {
println!("=== Configure RiseDev ===");
let all_components = all::<Components>().collect_vec();
const ITEMS_PER_PAGE: usize = 6;
let items = all_components
.iter()
.map(|c| {
let title = c.title();
let desc = style(
("\n".to_string() + c.description().trim())
.split('\n')
.join("\n "),
)
.dim();
(format!("{title}{desc}",), chosen.contains(c))
})
.collect_vec();
let Some(chosen_indices) = MultiSelect::new()
.with_prompt(
format!(
"RiseDev includes several components. You can select the ones you need, so as to reduce build time\n\n{}: navigate\n{}: confirm and save {}: quit without saving\n\nPick items with {}",
style("↑ / ↓ / ← / → ").reverse(),
style("Enter").reverse(),
style("Esc / q").reverse(),
style("Space").reverse(),
)
)
.items_checked(&items)
.max_length(ITEMS_PER_PAGE)
.interact_opt()? else {
return Ok(None);
};
let chosen = chosen_indices
.into_iter()
.map(|i| all_components[i])
.collect_vec();
Ok(Some(chosen))
}
fn main() -> Result<()> {
let opts = RiseDevConfigOpts::parse();
let file_path = opts.file;
let chosen = {
if let Ok(file) = OpenOptions::new().read(true).open(&file_path) {
let reader = BufReader::new(file);
let mut enabled = vec![];
for line in reader.lines() {
let line = line?;
if line.trim().is_empty() || line.trim().starts_with('#') {
continue;
}
let Some((component, val)) = line.split_once('=') else {
println!("invalid config line {}, discarded", line);
continue;
};
if component == "RISEDEV_CONFIGURED" {
continue;
}
match Components::from_env(component) {
Some(component) => {
if val == "true" {
enabled.push(component);
}
}
None => {
println!("unknown configure {}, discarded", component);
continue;
}
}
}
enabled
} else {
println!(
"RiseDev component config not found, generating {}",
file_path
);
Components::default_enabled().to_vec()
}
};
let chosen = match &opts.command {
Some(Commands::Default) => {
println!("Using default config");
Components::default_enabled().to_vec()
}
Some(Commands::Enable { component }) => {
let mut chosen = chosen;
chosen.push(*component);
chosen
}
Some(Commands::Disable { component }) => {
chosen.into_iter().filter(|x| x != component).collect()
}
None => match configure(&chosen)? {
Some(chosen) => chosen,
None => {
println!("Quit without saving");
println!("=========================");
return Ok(());
}
},
};
println!("=== Enabled Components ===");
for component in all::<Components>() {
println!(
"{}: {}",
component.title(),
if chosen.contains(&component) {
style("enabled").green()
} else {
style("disabled").dim()
}
);
}
println!("Configuration saved at {}", file_path);
println!("=========================");
let mut file = BufWriter::new(
OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(&file_path)
.context(format!("failed to open component config at {}", file_path))?,
);
writeln!(file, "RISEDEV_CONFIGURED=true")?;
writeln!(file)?;
for component in all::<Components>() {
writeln!(file, "# {}", component.title())?;
writeln!(
file,
"# {}",
component.description().trim().split('\n').join("\n# ")
)?;
if chosen.contains(&component) {
writeln!(file, "{}=true", component.env())?;
} else {
writeln!(file, "# {}=true", component.env())?;
}
writeln!(file)?;
}
file.flush()?;
println!(
"RiseDev will {} the components you've enabled.",
style("only download").bold()
);
println!(
"If you want to use these components, please {} in {} to start that component.",
style("modify the cluster config").yellow().bold(),
style(RISEDEV_CONFIG_FILE).bold(),
);
println!("See CONTRIBUTING.md or RiseDev's readme for more information.");
Ok(())
} |
Partager