Skip to content

Commit 84aa3b0

Browse files
committed
feat: add support for the /status route in mithril-aggregator-fake
Update documentation to reflect new aggregator stores directory with leader/follower feature
1 parent e729c13 commit 84aa3b0

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

internal/mithril-build-script/src/fake_aggregator.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub type FileContent = String;
1414
/// of the fake aggregator.
1515
#[derive(Debug, Default)]
1616
pub struct FakeAggregatorData {
17+
status: FileContent,
18+
1719
epoch_settings: FileContent,
1820

1921
certificates_list: FileContent,
@@ -50,6 +52,9 @@ impl FakeAggregatorData {
5052
});
5153

5254
match filename.as_str() {
55+
"status.json" => {
56+
data.status = file_content;
57+
}
5358
"epoch-settings.json" => {
5459
data.epoch_settings = file_content;
5560
}
@@ -155,6 +160,7 @@ impl FakeAggregatorData {
155160
pub fn generate_code_for_all_data(self) -> String {
156161
Self::assemble_code(
157162
&[
163+
generate_list_getter("status", self.status),
158164
generate_list_getter("epoch_settings", self.epoch_settings),
159165
generate_ids_array(
160166
"snapshot_digests",

mithril-test-lab/mithril-aggregator-fake/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ In another terminal:
5454
```
5555
WORKING_DIR_END_TO_END=[SELECT A PATH]
5656
JSON_OUTPUT=./default_data
57-
TRANSACTION_HASH_SAMPLE=$(sqlite3 $WORKING_DIR_END_TO_END/stores/aggregator/cardano-transaction.sqlite3 "select transaction_hash from cardano_tx")
57+
TRANSACTION_HASH_SAMPLE=$(sqlite3 $WORKING_DIR_END_TO_END/stores/aggregator-1/cardano-transaction.sqlite3 "select transaction_hash from cardano_tx")
5858
5959
./scripts/import.sh $JSON_OUTPUT http://localhost:8080/aggregator "$TRANSACTION_HASH_SAMPLE"
6060
```

mithril-test-lab/mithril-aggregator-fake/scripts/import.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ export DATA_DIR URL;
200200
check_requirements;
201201
clean_directory;
202202

203+
echo "Downloading aggregator status"
204+
download_data "$BASE_URL/status" "status"
205+
203206
echo "Downloading epoch-settings"
204207
download_data "$BASE_URL/epoch-settings" "epoch-settings"
205208

mithril-test-lab/mithril-aggregator-fake/src/application.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,4 +704,29 @@ mod tests {
704704

705705
test(task, PORT).await;
706706
}
707+
708+
#[tokio::test]
709+
async fn get_status() {
710+
const PORT: u16 = 3023;
711+
let task = tokio::spawn(async move {
712+
// Yield back to Tokio's scheduler to ensure the web server is ready before going on.
713+
yield_now().await;
714+
715+
let path = "/status";
716+
let response = http_request(PORT, path).await;
717+
718+
APISpec::verify_conformity(
719+
get_spec_file(),
720+
"GET",
721+
path,
722+
"application/json",
723+
&Null,
724+
&response,
725+
&StatusCode::OK,
726+
)
727+
.map_err(|e| anyhow!(e))
728+
});
729+
730+
test(task, PORT).await;
731+
}
707732
}

mithril-test-lab/mithril-aggregator-fake/src/handlers.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::shared_state::SharedState;
2323

2424
pub async fn aggregator_router() -> Router<SharedState> {
2525
Router::new()
26+
.route("/status", get(status))
2627
.route("/epoch-settings", get(epoch_settings))
2728
.route("/artifact/snapshots", get(snapshots))
2829
.route(
@@ -81,6 +82,14 @@ pub async fn aggregator_router() -> Router<SharedState> {
8182
)
8283
}
8384

85+
/// HTTP: Return the aggregator status.
86+
pub async fn status(State(state): State<SharedState>) -> Result<String, AppError> {
87+
let app_state = state.read().await;
88+
let status = app_state.get_status().await?;
89+
90+
Ok(status)
91+
}
92+
8493
/// HTTP: Return the Epoch Settings.
8594
pub async fn epoch_settings(State(state): State<SharedState>) -> Result<String, AppError> {
8695
let app_state = state.read().await;

mithril-test-lab/mithril-aggregator-fake/src/shared_state.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use tracing::{debug, trace};
1111
use crate::{StdResult, default_values};
1212

1313
pub struct AppState {
14+
status: String,
1415
epoch_settings: String,
1516
certificate_list: String,
1617
certificates: BTreeMap<String, String>,
@@ -40,6 +41,7 @@ impl From<AppState> for SharedState {
4041
impl Default for AppState {
4142
fn default() -> Self {
4243
Self {
44+
status: default_values::status().to_owned(),
4345
epoch_settings: default_values::epoch_settings().to_owned(),
4446
certificate_list: default_values::certificate_list().to_owned(),
4547
certificates: default_values::certificates(),
@@ -67,6 +69,7 @@ impl AppState {
6769
/// This will fail if some files are missing or are inconsistent.
6870
pub fn from_directory(data_dir: &Path) -> StdResult<Self> {
6971
let reader = DataDir::new(data_dir)?;
72+
let status = reader.read_file("status")?;
7073
let epoch_settings = reader.read_file("epoch-settings")?;
7174
let (certificate_list, certificates) = reader.read_files("certificate")?;
7275
let (snapshot_list, snapshots) = reader.read_files("snapshot")?;
@@ -81,6 +84,7 @@ impl AppState {
8184
reader.read_files("cardano-database")?;
8285

8386
let instance = Self {
87+
status,
8488
epoch_settings,
8589
certificate_list,
8690
certificates,
@@ -100,6 +104,11 @@ impl AppState {
100104
Ok(instance)
101105
}
102106

107+
/// return the aggregator status
108+
pub async fn get_status(&self) -> StdResult<String> {
109+
Ok(self.status.clone())
110+
}
111+
103112
/// return the compiled epoch settings
104113
pub async fn get_epoch_settings(&self) -> StdResult<String> {
105114
Ok(self.epoch_settings.clone())

0 commit comments

Comments
 (0)