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
24 changes: 21 additions & 3 deletions netmito/src/api/suites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use crate::{
config::InfraPool,
error::ApiError,
schema::{
CancelTaskSuiteParam, CreateTaskSuiteReq, CreateTaskSuiteResp, SuiteAgentOverrideReq,
SuiteAgentOverrideResp, TaskSuiteQueryResp, TaskSuitesQueryReq, TaskSuitesQueryResp,
CancelTaskSuiteParam, ChangeTaskSuiteReq, CreateTaskSuiteReq, CreateTaskSuiteResp,
SuiteAgentOverrideReq, SuiteAgentOverrideResp, TaskSuiteQueryResp, TaskSuitesQueryReq,
TaskSuitesQueryResp,
},
service::{
self,
Expand All @@ -24,7 +25,12 @@ pub fn suites_router(st: InfraPool) -> Router<InfraPool> {
Router::new()
.route("/", post(create_suite))
.route("/query", post(query_suites))
.route("/{uuid}", get(get_suite_details).delete(cancel_suite))
.route(
"/{uuid}",
get(get_suite_details)
.put(change_suite)
.delete(cancel_suite),
)
.route("/{uuid}/close", post(close_suite))
.route("/{uuid}/agents/override", post(override_agents_for_suite))
.route_layer(middleware::from_fn_with_state(
Expand Down Expand Up @@ -67,6 +73,18 @@ pub async fn get_suite_details(
Ok(Json(details))
}

pub async fn change_suite(
Extension(u): Extension<AuthUser>,
State(pool): State<InfraPool>,
Path(uuid): Path<Uuid>,
Json(req): Json<ChangeTaskSuiteReq>,
) -> Result<(), ApiError> {
service::suite::user_change_task_suite(u.id, &pool, uuid, req)
.await
.map_err(map_service_error)?;
Ok(())
}

pub async fn close_suite(
Extension(u): Extension<AuthUser>,
State(pool): State<InfraPool>,
Expand Down
26 changes: 26 additions & 0 deletions netmito/src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,32 @@ impl MitoHttpClient {
}
}

pub async fn change_task_suite(
&mut self,
uuid: Uuid,
req: ChangeTaskSuiteReq,
) -> crate::error::Result<()> {
let credential = self
.credential_guard
.get_credential()
.ok_or(CredentialGuardError::CredentialNotFound)?
.token;
self.url.set_path(&format!("suites/{uuid}"));
let resp = self
.http_client
.put(self.url.as_str())
.bearer_auth(credential)
.json(&req)
.send()
.await
.map_err(map_reqwest_err)?;
if resp.status().is_success() {
Ok(())
} else {
Err(get_error_from_resp(resp).await.into())
}
}

pub async fn close_task_suite(&mut self, uuid: Uuid) -> crate::error::Result<()> {
let credential = self
.credential_guard
Expand Down
6 changes: 6 additions & 0 deletions netmito/src/client/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ pub(crate) fn output_parsed_task_info(info: &ParsedTaskQueryInfo) {
if let Some(downstream_task_uuid) = info.downstream_task_uuid {
tracing::info!("Downstream Task UUID: {:?}", downstream_task_uuid);
}
if let Some(suite_uuid) = info.suite_uuid {
tracing::info!("Task Suite UUID: {}", suite_uuid);
}
if let Some(runner_uuid) = info.runner_uuid {
tracing::info!("Runner UUID: {}", runner_uuid);
}
Expand Down Expand Up @@ -149,6 +152,9 @@ pub(crate) fn output_task_info(info: &TaskQueryInfo) {
if let Some(downstream_task_uuid) = info.downstream_task_uuid {
tracing::info!("Downstream Task UUID: {:?}", downstream_task_uuid);
}
if let Some(suite_uuid) = info.suite_uuid {
tracing::info!("Task Suite UUID: {}", suite_uuid);
}
if let Some(runner_uuid) = info.runner_uuid {
tracing::info!("Runner UUID: {}", runner_uuid);
} else {
Expand Down
29 changes: 27 additions & 2 deletions netmito/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,12 @@ impl MitoClient {
self.http_client.create_task_suite(args.into()).await
}

pub async fn suites_change(&mut self, args: ChangeSuiteArgs) -> crate::error::Result<()> {
self.http_client
.change_task_suite(args.uuid, args.into())
.await
}

pub async fn suites_query(
&mut self,
args: QuerySuitesArgs,
Expand Down Expand Up @@ -1879,8 +1885,19 @@ impl MitoClient {
output_task_info(&task);
}
} else {
// Without --verbose, the output shows only the task UUID.
// For a task in a suite, it also shows the suite UUID.
for task in resp.tasks {
tracing::info!("{}", task.uuid);
match task.suite_uuid {
Some(suite_uuid) => {
tracing::info!(
"{}, suite {}",
task.uuid,
suite_uuid
)
}
None => tracing::info!("{}", task.uuid),
}
}
}
}
Expand Down Expand Up @@ -2051,14 +2068,22 @@ impl MitoClient {
},
},
ClientCommand::Suites(args) => match args.command {
SuitesCommands::Create(args) => match self.suites_create(args).await {
SuitesCommands::Create(args) => match self.suites_create(*args).await {
Ok(resp) => {
tracing::info!("Suite created with uuid {}", resp.uuid);
}
Err(e) => {
tracing::error!("{}", e);
}
},
SuitesCommands::Change(args) => match self.suites_change(*args).await {
Ok(_) => {
tracing::info!("Suite changed successfully");
}
Err(e) => {
tracing::error!("{}", e);
}
},
SuitesCommands::Query(args) => {
let verbose = args.verbose;
let counted = args.count;
Expand Down
10 changes: 10 additions & 0 deletions netmito/src/config/client/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ pub struct DownloadArtifactsByFilterArgs {
/// The name of the group the tasks belong to
#[arg(short, long)]
pub group: Option<String>,
/// The UUID of the task suite that the tasks belong to. The suite also identifies the group.
/// If you also give `--group`, it must be the group of the suite
#[arg(long = "suite")]
pub suite_uuid: Option<Uuid>,
/// The tags of the tasks
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub tags: Vec<String>,
Expand Down Expand Up @@ -152,6 +156,7 @@ impl From<DownloadArtifactsByFilterArgs> for ArtifactsDownloadByFilterReq {
Some(args.creators.into_iter().collect())
},
group_name: args.group,
suite_uuid: args.suite_uuid,
tags: if args.tags.is_empty() {
None
} else {
Expand Down Expand Up @@ -194,6 +199,10 @@ pub struct DeleteArtifactsByFilterArgs {
/// The name of the group the tasks belong to
#[arg(short, long)]
pub group: Option<String>,
/// The UUID of the task suite that the tasks belong to. The suite also identifies the group.
/// If you also give `--group`, it must be the group of the suite
#[arg(long = "suite")]
pub suite_uuid: Option<Uuid>,
/// The tags of the tasks
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub tags: Vec<String>,
Expand Down Expand Up @@ -234,6 +243,7 @@ impl From<DeleteArtifactsByFilterArgs> for ArtifactsDeleteByFilterReq {
Some(args.creators.into_iter().collect())
},
group_name: args.group,
suite_uuid: args.suite_uuid,
tags: if args.tags.is_empty() {
None
} else {
Expand Down
16 changes: 15 additions & 1 deletion netmito/src/config/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::ops::Not;
use url::Url;

use crate::entity::content::ArtifactContentType;
use crate::schema::{RemoteResource, RemoteResourceDownload};
use crate::schema::{ExecSpec, RemoteResource, RemoteResourceDownload};
use std::path::PathBuf;
use uuid::Uuid;

Expand Down Expand Up @@ -158,6 +158,20 @@ fn parse_artifact_content_type(
}
}

/// Parse a hook `ExecSpec` from a JSON object. The object has the same shape that `POST /suites`
/// accepts, for example `{"args":["sh","-c","./setup.sh"],"terminal_output":true}`.
/// Only `args` is necessary.
fn parse_exec_spec(
s: &str,
) -> Result<ExecSpec, Box<dyn std::error::Error + Send + Sync + 'static>> {
let spec: ExecSpec = serde_json::from_str(s)
.map_err(|e| format!("invalid hook spec: {e}. Expected a JSON object such as {{\"args\":[\"sh\",\"-c\",\"./setup.sh\"],\"terminal_output\":true}}"))?;
if spec.args.is_empty() {
return Err("invalid hook spec: `args` must not be empty".into());
}
Ok(spec)
}

/// Parse a resource string into RemoteResourceDownload
fn parse_resources(
s: &str,
Expand Down
Loading
Loading