Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions crates/bin/ampctl/src/cmd/dataset/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,6 @@ pub struct Args {
pub worker_id: Option<NodeSelector>,
}

/// Result of a dataset deployment operation.
#[derive(serde::Serialize)]
struct DeployResult {
job_id: JobId,
}

impl std::fmt::Display for DeployResult {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
writeln!(
f,
"{} Dataset deployed successfully",
console::style("✓").green().bold()
)?;
writeln!(f, "{} Job ID: {}", console::style("→").cyan(), self.job_id)
}
}

/// Deploy a dataset to start syncing blockchain data.
///
/// Schedules a deployment job via the admin API and returns the job ID.
Expand Down Expand Up @@ -137,6 +120,23 @@ async fn deploy_dataset(
Ok(job_id)
}

/// Result of a dataset deployment operation.
#[derive(serde::Serialize)]
struct DeployResult {
job_id: JobId,
}

impl std::fmt::Display for DeployResult {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
writeln!(
f,
"{} Dataset deployed successfully",
console::style("✓").green().bold()
)?;
writeln!(f, "{} Job ID: {}", console::style("→").cyan(), self.job_id)
}
}

/// Errors for dataset deployment operations.
#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down
36 changes: 18 additions & 18 deletions crates/bin/ampctl/src/cmd/dataset/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,6 @@ pub struct Args {
pub reference: Reference,
}

/// Result of a dataset inspect operation.
#[derive(serde::Serialize)]
struct InspectResult {
#[serde(flatten)]
dataset: client::datasets::DatasetInfo,
}

impl std::fmt::Display for InspectResult {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
writeln!(f, "Namespace: {}", self.dataset.namespace)?;
writeln!(f, "Name: {}", self.dataset.name)?;
writeln!(f, "Revision: {}", self.dataset.revision)?;
writeln!(f, "Kind: {}", self.dataset.kind)?;
writeln!(f, "Manifest Hash: {}", self.dataset.manifest_hash)?;
Ok(())
}
}

/// Inspect dataset details by retrieving them from the admin API.
///
/// Retrieves dataset information and displays it based on the output format.
Expand Down Expand Up @@ -85,6 +67,24 @@ async fn get_dataset(
}
}

/// Result of a dataset inspect operation.
#[derive(serde::Serialize)]
struct InspectResult {
#[serde(flatten)]
dataset: client::datasets::DatasetInfo,
}

impl std::fmt::Display for InspectResult {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
writeln!(f, "Namespace: {}", self.dataset.namespace)?;
writeln!(f, "Name: {}", self.dataset.name)?;
writeln!(f, "Revision: {}", self.dataset.revision)?;
writeln!(f, "Kind: {}", self.dataset.kind)?;
writeln!(f, "Manifest Hash: {}", self.dataset.manifest_hash)?;
Ok(())
}
}

/// Errors for dataset inspect operations.
#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down
58 changes: 29 additions & 29 deletions crates/bin/ampctl/src/cmd/dataset/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,6 @@ pub struct Args {
pub global: GlobalArgs,
}

/// Result of a dataset list operation.
#[derive(serde::Serialize)]
struct ListResult {
datasets: Vec<client::datasets::DatasetSummary>,
}

impl std::fmt::Display for ListResult {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if self.datasets.is_empty() {
writeln!(f, "No datasets found")
} else {
writeln!(f, "Datasets:")?;
for dataset in &self.datasets {
let versions_str = if dataset.versions.is_empty() {
"no versions".to_string()
} else {
format!("{} version(s)", dataset.versions.len())
};
writeln!(
f,
" {}/{} - {}",
dataset.namespace, dataset.name, versions_str
)?;
}
Ok(())
}
}
}

/// List all datasets by retrieving them from the admin API.
///
/// Retrieves all datasets and displays them based on the output format.
Expand Down Expand Up @@ -85,6 +56,35 @@ async fn get_datasets(global: &GlobalArgs) -> Result<client::datasets::DatasetsR
Ok(datasets_response)
}

/// Result of a dataset list operation.
#[derive(serde::Serialize)]
struct ListResult {
datasets: Vec<client::datasets::DatasetSummary>,
}

impl std::fmt::Display for ListResult {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if self.datasets.is_empty() {
writeln!(f, "No datasets found")
} else {
writeln!(f, "Datasets:")?;
for dataset in &self.datasets {
let versions_str = if dataset.versions.is_empty() {
"no versions".to_string()
} else {
format!("{} version(s)", dataset.versions.len())
};
writeln!(
f,
" {}/{} - {}",
dataset.namespace, dataset.name, versions_str
)?;
}
Ok(())
}
}
}

/// Errors for datasets listing operations.
#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down
30 changes: 15 additions & 15 deletions crates/bin/ampctl/src/cmd/dataset/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ pub struct Args {
pub reference: Reference,
}

/// Result wrapper for manifest inspect output.
#[derive(serde::Serialize)]
struct InspectResult {
#[serde(flatten)]
data: serde_json::Value,
}

impl std::fmt::Display for InspectResult {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
// For manifest inspect, output pretty JSON as manifests are complex nested structures
let json = serde_json::to_string_pretty(&self.data).map_err(|_| std::fmt::Error)?;
write!(f, "{}", json)
}
}

/// Retrieve dataset manifest by fetching it from the admin API.
///
/// Retrieves the manifest JSON and displays it based on the output format.
Expand Down Expand Up @@ -86,6 +71,21 @@ async fn get_manifest(
}
}

/// Result wrapper for manifest inspect output.
#[derive(serde::Serialize)]
struct InspectResult {
#[serde(flatten)]
data: serde_json::Value,
}

impl std::fmt::Display for InspectResult {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
// For manifest inspect, output pretty JSON as manifests are complex nested structures
let json = serde_json::to_string_pretty(&self.data).map_err(|_| std::fmt::Error)?;
write!(f, "{}", json)
}
}

/// Errors for dataset manifest operations.
#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down
106 changes: 53 additions & 53 deletions crates/bin/ampctl/src/cmd/dataset/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,59 @@ pub struct Args {
pub location_id: Option<i64>,
}

/// Result of a dataset restore operation (all tables).
/// Restore dataset physical tables from object storage.
///
/// Re-indexes physical table metadata from storage into the database.
/// Optionally targets a single table with `--table`, and can activate
/// a specific revision with `--location-id`.
///
/// # Errors
///
/// Returns [`Error`] for invalid paths/URLs, API errors (400/404/500), or network failures.
#[tracing::instrument(skip_all, fields(admin_url = %global.admin_url, %dataset_ref))]
pub async fn run(
Args {
global,
dataset_ref,
table,
location_id,
}: Args,
) -> Result<(), Error> {
let client = global.build_client().map_err(Error::ClientBuild)?;

if let Some(table_name) = table {
tracing::debug!(%dataset_ref, %table_name, ?location_id, "restoring single table");

client
.datasets()
.restore_table(&dataset_ref, &table_name, location_id)
.await
.map_err(Error::RestoreTable)?;

let result = RestoreTableResult {
table: table_name,
location_id,
};
global.print(&result).map_err(Error::JsonSerialization)?;
} else {
tracing::debug!(%dataset_ref, "restoring dataset");

let response = client
.datasets()
.restore(&dataset_ref)
.await
.map_err(Error::Restore)?;

let result = RestoreResult {
tables: response.tables,
};
global.print(&result).map_err(Error::JsonSerialization)?;
}

Ok(())
}

/// Result of a dataset restore operation.
#[derive(serde::Serialize)]
struct RestoreResult {
tables: Vec<RestoredTableInfo>,
Expand Down Expand Up @@ -105,58 +157,6 @@ impl std::fmt::Display for RestoreTableResult {
}
}

/// Restore dataset physical tables from object storage.
///
/// Re-indexes physical table metadata from storage into the database.
/// Optionally targets a single table with `--table`, and can activate
/// a specific revision with `--location-id`.
///
/// # Errors
///
/// Returns [`Error`] for invalid paths/URLs, API errors (400/404/500), or network failures.
#[tracing::instrument(skip_all, fields(admin_url = %global.admin_url, %dataset_ref))]
pub async fn run(
Args {
global,
dataset_ref,
table,
location_id,
}: Args,
) -> Result<(), Error> {
let client = global.build_client().map_err(Error::ClientBuild)?;

if let Some(table_name) = table {
tracing::debug!(%dataset_ref, %table_name, ?location_id, "restoring single table");

client
.datasets()
.restore_table(&dataset_ref, &table_name, location_id)
.await
.map_err(Error::RestoreTable)?;

let result = RestoreTableResult {
table: table_name,
location_id,
};
global.print(&result).map_err(Error::JsonSerialization)?;
} else {
tracing::debug!(%dataset_ref, "restoring dataset");

let response = client
.datasets()
.restore(&dataset_ref)
.await
.map_err(Error::Restore)?;

let result = RestoreResult {
tables: response.tables,
};
global.print(&result).map_err(Error::JsonSerialization)?;
}

Ok(())
}

/// Errors for dataset restore operations.
#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down
Loading