Skip to content

Commit 176efb7

Browse files
committed
AC-1989 validate priority
Signed-off-by: Neil South <[email protected]>
1 parent 4165c41 commit 176efb7

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

src/WorkflowManager/WorkflowManager/Validators/WorkflowValidator.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class WorkflowValidator
4141
public static readonly string Separator = ";";
4242
private const string Comma = ", ";
4343
private readonly ILogger<WorkflowValidator> _logger;
44+
public static readonly string TaskPriorityClassName = "priority";
4445

4546
/// <summary>
4647
/// Initializes a new instance of the <see cref="WorkflowValidator"/> class.
@@ -335,6 +336,18 @@ private void ValidateArgoTask(TaskObject currentTask)
335336
{
336337
Errors.Add($"Task: '{currentTask.Id}' workflow_template_name must be specified{Comma}this corresponds to an Argo template name.");
337338
}
339+
340+
if (currentTask.Args.ContainsKey(TaskPriorityClassName))
341+
{
342+
switch (currentTask.Args[TaskPriorityClassName].ToLower())
343+
{
344+
case "high" or "standard" or "low":
345+
break;
346+
default:
347+
Errors.Add($"Task: '{currentTask.Id}' TaskPriorityClassName must be one of \"high\"{Comma} \"standard\" or \"low\"");
348+
break;
349+
}
350+
}
338351
}
339352

340353
private void ValidateClinicalReviewTask(TaskObject[] tasks, TaskObject currentTask)

tests/UnitTests/WorkflowManager.Tests/Validators/WorkflowValidatorTests.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System;
1818
using System.Security.Cryptography.Xml;
1919
using System.Threading.Tasks;
20+
using Amazon.Runtime.Internal.Transform;
2021
using Microsoft.Extensions.Logging;
2122
using Monai.Deploy.WorkflowManager.Common.Interfaces;
2223
using Monai.Deploy.WorkflowManager.Contracts.Models;
@@ -535,5 +536,97 @@ public async Task ValidateWorkflow_ValidateWorkflow_ReturnsNoErrors()
535536
Assert.True(errors.Count == 0);
536537
}
537538
}
539+
540+
[Fact]
541+
public async Task ValidateWorkflow_Incorrect_podPriorityClassName_ReturnsErrors()
542+
{
543+
var workflow = new Workflow
544+
{
545+
Name = "Workflowname1",
546+
Description = "Workflowdesc1",
547+
Version = "1",
548+
InformaticsGateway = new InformaticsGateway
549+
{
550+
AeTitle = "aetitle",
551+
ExportDestinations = new string[] { "oneDestination", "twoDestination", "threeDestination" }
552+
},
553+
Tasks = new TaskObject[]
554+
{
555+
new TaskObject
556+
{
557+
Args = new System.Collections.Generic.Dictionary<string, string>{
558+
{ "priority" ,"god" },
559+
{ "workflow_template_name" ,"spot"}
560+
},
561+
Id = "rootTask",
562+
Type = "argo",
563+
Description = "TestDesc",
564+
Artifacts = new ArtifactMap
565+
{
566+
Input = new Artifact[]{
567+
new Artifact
568+
{
569+
Name = "non_unique_artifact",
570+
Value = "Example Value"
571+
}
572+
}
573+
}
574+
},
575+
}
576+
};
577+
578+
_workflowService.Setup(w => w.GetByNameAsync(It.IsAny<string>()))
579+
.ReturnsAsync(null, TimeSpan.FromSeconds(.1));
580+
581+
var errors = await _workflowValidator.ValidateWorkflow(workflow);
582+
583+
Assert.Single(errors);
584+
}
585+
586+
[Fact]
587+
public async Task ValidateWorkflow_correct_podPriorityClassName_ReturnsNoErrors()
588+
{
589+
var workflow = new Workflow
590+
{
591+
Name = "Workflowname1",
592+
Description = "Workflowdesc1",
593+
Version = "1",
594+
InformaticsGateway = new InformaticsGateway
595+
{
596+
AeTitle = "aetitle",
597+
ExportDestinations = new string[] { "oneDestination", "twoDestination", "threeDestination" }
598+
},
599+
Tasks = new TaskObject[]
600+
{
601+
new TaskObject
602+
{
603+
Args = new System.Collections.Generic.Dictionary<string, string>{
604+
{ "priority" ,"high" },
605+
{ "workflow_template_name" ,"spot"}
606+
},
607+
Id = "rootTask",
608+
Type = "argo",
609+
Description = "TestDesc",
610+
Artifacts = new ArtifactMap
611+
{
612+
Input = new Artifact[]{
613+
new Artifact
614+
{
615+
Name = "non_unique_artifact",
616+
Value = "Example Value"
617+
}
618+
}
619+
}
620+
},
621+
}
622+
};
623+
624+
_workflowService.Setup(w => w.GetByNameAsync(It.IsAny<string>()))
625+
.ReturnsAsync(null, TimeSpan.FromSeconds(.1));
626+
627+
var errors = await _workflowValidator.ValidateWorkflow(workflow);
628+
629+
Assert.Empty(errors);
630+
}
538631
}
539632
}

0 commit comments

Comments
 (0)