Skip to content

Commit

Permalink
feat: add reindexing support
Browse files Browse the repository at this point in the history
* Create indexer module with common indexing logic shared by bombastic and vexination.
* Use infrastructure HTTP endpoint on indexers to trigger reindexing and checking reindexing status.
* Create admin module with commands that can be used by system administrators.
* Add trust admin reindex command as a way to trigger reindexing and checking reindexing status using the indexer HTTP endpoint.

Issue #379, #9
  • Loading branch information
Ulf Lilleengen committed Aug 14, 2023
1 parent f6c9525 commit 71cd5ea
Show file tree
Hide file tree
Showing 22 changed files with 551 additions and 326 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ members = [
"index",
"infrastructure",
"version",
"admin",
"indexer",
]
default-members = [
"auth",
Expand Down Expand Up @@ -79,6 +81,7 @@ default-members = [
"index",
"infrastructure",
"version",
"indexer",
]

[patch.crates-io]
Expand Down
13 changes: 13 additions & 0 deletions admin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "trustification-admin"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.68"
tokio = { version = "1.0", features = ["full"] }
log = "0.4"
clap = { version = "4", features = ["derive"] }
anyhow = "1"
reqwest = { version = "0.11.16", features = ["stream"] }
17 changes: 17 additions & 0 deletions admin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::process::ExitCode;

mod reindex;

#[derive(clap::Subcommand, Debug)]
pub enum Command {
#[command(subcommand)]
Reindex(reindex::Reindex),
}

impl Command {
pub async fn run(self) -> anyhow::Result<ExitCode> {
match self {
Self::Reindex(reindex) => reindex.run().await,
}
}
}
65 changes: 65 additions & 0 deletions admin/src/reindex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use std::process::ExitCode;

use reqwest::StatusCode;

#[derive(clap::Subcommand, Debug)]
pub enum Reindex {
Status(ReindexStatus),
Start(ReindexStart),
}

impl Reindex {
pub async fn run(self) -> anyhow::Result<ExitCode> {
match self {
Self::Start(run) => run.run().await,
Self::Status(run) => run.run().await,
}
}
}

#[derive(clap::Args, Debug)]
#[command(about = "Trigger reindex", args_conflicts_with_subcommands = true)]
pub struct ReindexStart {
#[arg(long = "devmode", default_value_t = false)]
pub devmode: bool,

#[arg(short = 'i', long = "indexer", default_value = "http://localhost:8080/")]
pub indexer_url: String,
}

impl ReindexStart {
pub async fn run(self) -> anyhow::Result<ExitCode> {
let client = reqwest::Client::new();
match client.post(self.indexer_url).send().await {
Ok(response) => {
if response.status() == StatusCode::OK {
println!("Reindexing started successfully");
} else {
let body = response.text().await;
println!("Error starting reindexing: {:?}", body);
}
}
Err(e) => {
println!("Error starting reindexing: {:?}", e);
}
}

Ok(ExitCode::SUCCESS)
}
}

#[derive(clap::Args, Debug)]
#[command(about = "Check reindex status", args_conflicts_with_subcommands = true)]
pub struct ReindexStatus {
#[arg(long = "devmode", default_value_t = false)]
pub devmode: bool,

#[arg(short = 'i', long = "indexer", default_value = "http://localhost:8080/")]
pub indexer_url: String,
}

impl ReindexStatus {
pub async fn run(self) -> anyhow::Result<ExitCode> {
Ok(ExitCode::SUCCESS)
}
}
4 changes: 4 additions & 0 deletions bombastic/index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ impl trustification_index::Index for Index {
}
}

fn parse_doc(data: &[u8]) -> Result<SBOM, SearchError> {
SBOM::parse(data).map_err(|e| SearchError::DocParser(e.to_string()))
}

fn schema(&self) -> Schema {
self.schema.clone()
}
Expand Down
3 changes: 1 addition & 2 deletions bombastic/indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name = "bombastic-indexer"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -17,6 +15,7 @@ trustification-event-bus = { path = "../../event-bus" }
trustification-infrastructure = { path = "../../infrastructure" }
trustification-storage = { path = "../../storage" }
trustification-index = { path = "../../index" }
trustification-indexer = { path = "../../indexer" }
clap = { version = "4", features = ["derive"] }
anyhow = "1"
futures = "0.3"
Expand Down
140 changes: 0 additions & 140 deletions bombastic/indexer/src/indexer.rs

This file was deleted.

0 comments on commit 71cd5ea

Please sign in to comment.