Skip to content

Commit 893df6a

Browse files
authored
Merge branch 'develop' into AC-1567
2 parents fee2d99 + 3f13648 commit 893df6a

File tree

6 files changed

+17
-36
lines changed

6 files changed

+17
-36
lines changed

src/Shared/Shared/ValidationConstants.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static class ValidationConstants
6161
/// <summary>
6262
/// Key for the memory.
6363
/// </summary>
64-
public static readonly string Memory = "memory_gb";
64+
public static readonly string Memory = "memory";
6565

6666
/// <summary>
6767
/// Key for the GPU.

src/TaskManager/Plug-ins/Argo/StaticValues/Keys.cs

-15
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,6 @@ internal static class Keys
8888
/// </summary>
8989
public static readonly string TaskPriorityClassName = "priority";
9090

91-
/// <summary>
92-
/// Key for CPU
93-
/// </summary>
94-
public static readonly string Cpu = "cpu";
95-
96-
/// <summary>
97-
/// Key for memory allocation
98-
/// </summary>
99-
public static readonly string Memory = "memory_gb";
100-
101-
/// <summary>
102-
/// Key for GPU
103-
/// </summary>
104-
public static readonly string Gpu = "number_gpu";
105-
10691
/// <summary>
10792
/// Required arguments to run the Argo workflow.
10893
/// </summary>

src/TaskManager/Plug-ins/Argo/StaticValues/ResourcesKeys.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17+
using static Monai.Deploy.WorkflowManager.Shared.ValidationConstants;
18+
1719
namespace Monai.Deploy.WorkflowManager.TaskManager.Argo.StaticValues
1820
{
1921
public static class ResourcesKeys
2022
{
21-
public static readonly ResourcesKey GpuLimit = new() { TaskKey = "gpu_required", ArgoKey = "nvidia.com/gpu" };
23+
public static readonly ResourcesKey GpuLimit = new() { TaskKey = GpuRequired, ArgoKey = "nvidia.com/gpu" };
2224

23-
public static readonly ResourcesKey MemoryLimit = new() { TaskKey = "memory_gb", ArgoKey = "memory" };
25+
public static readonly ResourcesKey MemoryLimit = new() { TaskKey = Memory, ArgoKey = "memory" };
2426

25-
public static readonly ResourcesKey CpuLimit = new() { TaskKey = "cpu", ArgoKey = "cpu" };
27+
public static readonly ResourcesKey CpuLimit = new() { TaskKey = Cpu, ArgoKey = "cpu" };
2628
}
2729
}

src/WorkflowManager/WorkflowManager/Validators/WorkflowValidator.cs

+6-9
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,13 @@ private void ValidateArgoTask(TaskObject currentTask)
375375
}
376376
}
377377

378-
new List<string> { Cpu, Memory }.ForEach(key =>
378+
if (
379+
currentTask.Args.TryGetValue(Cpu, out var val) &&
380+
(string.IsNullOrEmpty(val) ||
381+
(double.TryParse(val, out double parsedVal) && (parsedVal < 1 || Math.Truncate(parsedVal) != parsedVal))))
379382
{
380-
if (
381-
currentTask.Args.TryGetValue(key, out var val) &&
382-
(string.IsNullOrEmpty(val) ||
383-
(double.TryParse(val, out double parsedVal) && (parsedVal < 1 || Math.Truncate(parsedVal) != parsedVal))))
384-
{
385-
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.");
386-
}
387-
});
383+
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.");
384+
}
388385

389386
if (
390387
currentTask.Args.TryGetValue(GpuRequired, out var gpuRequired) &&

tests/UnitTests/TaskManager.Argo.Tests/ArgoPluginTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public async Task ArgoPlugin_ExecuteTask_WorkflowTemplates(string filename, int
273273

274274
var message = GenerateTaskDispatchEventWithValidArguments(withoutDefaultArguments);
275275
message.TaskPluginArguments["gpu_required"] = "true";
276-
message.TaskPluginArguments["memory_gb"] = "1";
276+
message.TaskPluginArguments["memory"] = "1";
277277
message.TaskPluginArguments["cpu"] = "1";
278278
message.TaskPluginArguments["priority"] = "Helo";
279279
Workflow? submittedArgoTemplate = null;

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
209209
Description = "Test Argo Task",
210210
Args = {
211211
{ "cpu", "0.1" },
212-
{ "memory_gb", "0.1" },
212+
{ "memory", "0.1" },
213213
{ "gpu_required", "2" }
214214
},
215215
TaskDestinations = new TaskDestination[]
@@ -343,7 +343,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
343343
{ "invalid_key", "value" },
344344
{ "workflow_template_name" ,"spot"},
345345
{ "cpu", "1" },
346-
{ "memory_gb", "1" },
346+
{ "memory", "1" },
347347
{ "gpu_required", "1" }
348348
}
349349
},
@@ -371,7 +371,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
371371

372372
Assert.True(errors.Count > 0);
373373

374-
Assert.Equal(46, errors.Count);
374+
Assert.Equal(45, errors.Count);
375375

376376
var convergingTasksDestinations = "Converging Tasks Destinations in tasks: (test-clinical-review-2, example-task) on task: example-task";
377377
Assert.Contains(convergingTasksDestinations, errors);
@@ -412,9 +412,6 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
412412
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.";
413413
Assert.Contains(invalidArgoArg1, errors);
414414

415-
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.";
416-
Assert.Contains(invalidArgoArg2, errors);
417-
418415
var invalidArgoArg3 = "Task: 'test-argo-task' value '2' provided for argument 'gpu_required' is not valid. The value needs to be 'true' or 'false'.";
419416
Assert.Contains(invalidArgoArg3, errors);
420417

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

439-
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.";
436+
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.";
440437
Assert.Contains(invalidArgoKey, errors);
441438
}
442439

0 commit comments

Comments
 (0)