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
2 changes: 1 addition & 1 deletion src/Shared/Shared/ValidationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static class ValidationConstants
/// <summary>
/// Key for the memory.
/// </summary>
public static readonly string Memory = "memory_gb";
public static readonly string Memory = "memory";

/// <summary>
/// Key for the GPU.
Expand Down
15 changes: 0 additions & 15 deletions src/TaskManager/Plug-ins/Argo/StaticValues/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ internal static class Keys
/// </summary>
public static readonly string TaskPriorityClassName = "priority";

/// <summary>
/// Key for CPU
/// </summary>
public static readonly string Cpu = "cpu";

/// <summary>
/// Key for memory allocation
/// </summary>
public static readonly string Memory = "memory_gb";

/// <summary>
/// Key for GPU
/// </summary>
public static readonly string Gpu = "number_gpu";

/// <summary>
/// Required arguments to run the Argo workflow.
/// </summary>
Expand Down
8 changes: 5 additions & 3 deletions src/TaskManager/Plug-ins/Argo/StaticValues/ResourcesKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* limitations under the License.
*/

using static Monai.Deploy.WorkflowManager.Shared.ValidationConstants;

namespace Monai.Deploy.WorkflowManager.TaskManager.Argo.StaticValues
{
public static class ResourcesKeys
{
public static readonly ResourcesKey GpuLimit = new() { TaskKey = "gpu_required", ArgoKey = "nvidia.com/gpu" };
public static readonly ResourcesKey GpuLimit = new() { TaskKey = GpuRequired, ArgoKey = "nvidia.com/gpu" };

public static readonly ResourcesKey MemoryLimit = new() { TaskKey = "memory_gb", ArgoKey = "memory" };
public static readonly ResourcesKey MemoryLimit = new() { TaskKey = Memory, ArgoKey = "memory" };

public static readonly ResourcesKey CpuLimit = new() { TaskKey = "cpu", ArgoKey = "cpu" };
public static readonly ResourcesKey CpuLimit = new() { TaskKey = Cpu, ArgoKey = "cpu" };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,13 @@ private void ValidateArgoTask(TaskObject currentTask)
}
}

new List<string> { Cpu, Memory }.ForEach(key =>
if (
currentTask.Args.TryGetValue(Cpu, out var val) &&
(string.IsNullOrEmpty(val) ||
(double.TryParse(val, out double parsedVal) && (parsedVal < 1 || Math.Truncate(parsedVal) != parsedVal))))
{
if (
currentTask.Args.TryGetValue(key, out var val) &&
(string.IsNullOrEmpty(val) ||
(double.TryParse(val, out double parsedVal) && (parsedVal < 1 || Math.Truncate(parsedVal) != parsedVal))))
{
Errors.Add($"Task: '{currentTask.Id}' value '{val}' provided for argument '{key}' is not valid. The value needs to be a whole number greater than 0.");
}
});
Errors.Add($"Task: '{currentTask.Id}' value '{val}' provided for argument '{Cpu}' is not valid. The value needs to be a whole number greater than 0.");
}

if (
currentTask.Args.TryGetValue(GpuRequired, out var gpuRequired) &&
Expand Down
2 changes: 1 addition & 1 deletion tests/UnitTests/TaskManager.Argo.Tests/ArgoPluginTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public async Task ArgoPlugin_ExecuteTask_WorkflowTemplates(string filename, int

var message = GenerateTaskDispatchEventWithValidArguments(withoutDefaultArguments);
message.TaskPluginArguments["gpu_required"] = "true";
message.TaskPluginArguments["memory_gb"] = "1";
message.TaskPluginArguments["memory"] = "1";
message.TaskPluginArguments["cpu"] = "1";
message.TaskPluginArguments["priority"] = "Helo";
Workflow? submittedArgoTemplate = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
Description = "Test Argo Task",
Args = {
{ "cpu", "0.1" },
{ "memory_gb", "0.1" },
{ "memory", "0.1" },
{ "gpu_required", "2" }
},
TaskDestinations = new TaskDestination[]
Expand Down Expand Up @@ -343,7 +343,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
{ "invalid_key", "value" },
{ "workflow_template_name" ,"spot"},
{ "cpu", "1" },
{ "memory_gb", "1" },
{ "memory", "1" },
{ "gpu_required", "1" }
}
},
Expand Down Expand Up @@ -371,7 +371,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect

Assert.True(errors.Count > 0);

Assert.Equal(46, errors.Count);
Assert.Equal(45, errors.Count);

var convergingTasksDestinations = "Converging Tasks Destinations in tasks: (test-clinical-review-2, example-task) on task: example-task";
Assert.Contains(convergingTasksDestinations, errors);
Expand Down Expand Up @@ -412,9 +412,6 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
var invalidArgoArg1 = "Task: 'test-argo-task' value '0.1' provided for argument 'cpu' is not valid. The value needs to be a whole number greater than 0.";
Assert.Contains(invalidArgoArg1, errors);

var invalidArgoArg2 = "Task: 'test-argo-task' value '0.1' provided for argument 'memory_gb' is not valid. The value needs to be a whole number greater than 0.";
Assert.Contains(invalidArgoArg2, errors);

var invalidArgoArg3 = "Task: 'test-argo-task' value '2' provided for argument 'gpu_required' is not valid. The value needs to be 'true' or 'false'.";
Assert.Contains(invalidArgoArg3, errors);

Expand All @@ -436,7 +433,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
var invalidSourceName = "Data origin invalid_origin does not exists. Please review sources configuration management.";
Assert.Contains(invalidSourceName, errors);

var invalidArgoKey = $"Task: 'invalid-key-argo-task' args has invalid keys: invalid_key. Please only specify keys from the following list: workflow_template_name, priority, cpu, memory_gb, gpu_required.";
var invalidArgoKey = $"Task: 'invalid-key-argo-task' args has invalid keys: invalid_key. Please only specify keys from the following list: workflow_template_name, priority, cpu, memory, gpu_required.";
Assert.Contains(invalidArgoKey, errors);
}

Expand Down