Skip to content

Commit

Permalink
Merge pull request #766 from Project-MONAI/AC-2129
Browse files Browse the repository at this point in the history
change so failed to delete returns 500
  • Loading branch information
neildsouth authored Apr 25, 2023
2 parents 4c630ca + 1a8888e commit 9afe61c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/TaskManager/Plug-ins/Argo/ArgoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ public async Task<WorkflowTemplate> Argo_GetWorkflowTemplateAsync(string argoNam
public virtual async Task<WorkflowTemplate> Argo_CreateWorkflowTemplateAsync(string argoNamespace, WorkflowTemplateCreateRequest body, CancellationToken cancellationToken)
{
Guard.Against.NullOrWhiteSpace(argoNamespace);
Guard.Against.Null(body);
Guard.Against.Null(body.Template);

var urlBuilder = new StringBuilder();
urlBuilder.Append(CultureInfo.InvariantCulture, $"{FormattedBaseUrl}/api/v1/workflow-templates/{argoNamespace}");

var method = "POST";
var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body));
var stringBody = Newtonsoft.Json.JsonConvert.SerializeObject(body);
var content = new StringContent(stringBody);

var _logger = NLog.LogManager.GetCurrentClassLogger();
_logger.Debug($"Sending content to Argo :{stringBody}");
return await SendRequest<WorkflowTemplate>(content, urlBuilder, method, cancellationToken).ConfigureAwait(false);
}

Expand Down
10 changes: 9 additions & 1 deletion src/TaskManager/Plug-ins/Argo/Controllers/TemplateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Text;
using Argo;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -72,6 +73,8 @@ public async Task<ActionResult<WorkflowTemplate>> CreateArgoTemplate()
}

[Route("{name}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[HttpDelete]
public async Task<ActionResult<bool>> DeleteArgoTemplate(string name)
{
Expand All @@ -82,7 +85,12 @@ public async Task<ActionResult<bool>> DeleteArgoTemplate(string name)

try
{
return Ok(await _argoPlugin.DeleteArgoTemplate(name));
var result = await _argoPlugin.DeleteArgoTemplate(name);
if (result is true)
{
return Ok();
}
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/UnitTests/TaskManager.Argo.Tests/ArgoClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public async Task Argo_CreateWorkflowTemplateAsync()
ArgoClient argoClient = new(httpclient);

var result = await argoClient.Argo_CreateWorkflowTemplateAsync("argo",
new WorkflowTemplateCreateRequest { Namespace = "argo" },
new WorkflowTemplateCreateRequest { Namespace = "argo", Template = new WorkflowTemplate() },
CancellationToken.None);

Assert.NotNull(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ public async Task DeleteArgoTemplate_Controller_ReturnsOk()
_argoLogger.Object,
Options);

ArgoClient.Setup(a => a.Argo_DeleteWorkflowTemplateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult(true));

var result = await TemplateController.DeleteArgoTemplate("template");

Assert.IsType<ActionResult<bool>>(result);
var okResult = Assert.IsType<OkObjectResult>(result.Result);
var okResult = Assert.IsType<OkResult>(result.Result);
Assert.Equal((int)HttpStatusCode.OK, okResult.StatusCode);
}

Expand Down

0 comments on commit 9afe61c

Please sign in to comment.