Skip to content

Commit

Permalink
merge in
Browse files Browse the repository at this point in the history
Signed-off-by: Neil South <[email protected]>
  • Loading branch information
neildsouth committed Nov 15, 2023
2 parents 1726d6b + 449e557 commit ed574e6
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 5 deletions.
38 changes: 35 additions & 3 deletions src/TaskManager/Plug-ins/Docker/DockerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

using System.Diagnostics;
using System.Globalization;
using Amazon.Runtime.Internal.Transform;
using Ardalis.GuardClauses;
using Docker.DotNet;
using Docker.DotNet.Models;
Expand Down Expand Up @@ -364,9 +364,14 @@ private CreateContainerParameters BuildContainerSpecification(IList<ContainerVol
{
Runtime = Strings.RuntimeNvidia,
Mounts = volumeMounts,
}
},
};

if (Event.TaskPluginArguments.ContainsKey(Keys.User))
{
parameters.User = Event.TaskPluginArguments[Keys.User];
}

return parameters;
}

Expand Down Expand Up @@ -406,6 +411,7 @@ private async Task<List<ContainerVolumeMount>> SetupInputs(CancellationToken can
// eg: /monai/input
var volumeMount = new ContainerVolumeMount(input, Event.TaskPluginArguments[input.Name], inputHostDirRoot, inputContainerDirRoot);
volumeMounts.Add(volumeMount);
_logger.InputVolumeMountAdded(inputHostDirRoot, inputContainerDirRoot);

// For each file, download from bucket and store in Task Manager Container.
foreach (var obj in objects)
Expand All @@ -424,6 +430,8 @@ private async Task<List<ContainerVolumeMount>> SetupInputs(CancellationToken can
}
}

SetPermission(containerPath);

return volumeMounts;
}

Expand All @@ -436,7 +444,10 @@ private ContainerVolumeMount SetupIntermediateVolume()

Directory.CreateDirectory(containerPath);

return new ContainerVolumeMount(Event.IntermediateStorage, Event.TaskPluginArguments[Keys.WorkingDirectory], hostPath, containerPath);
var volumeMount = new ContainerVolumeMount(Event.IntermediateStorage, Event.TaskPluginArguments[Keys.WorkingDirectory], hostPath, containerPath);
_logger.IntermediateVolumeMountAdded(hostPath, containerPath);
SetPermission(containerPath);
return volumeMount;
}

return default!;
Expand Down Expand Up @@ -465,11 +476,32 @@ private List<ContainerVolumeMount> SetupOutputs()
Directory.CreateDirectory(containerPath);

volumeMounts.Add(new ContainerVolumeMount(output, Event.TaskPluginArguments[output.Name], hostPath, containerPath));
_logger.OutputVolumeMountAdded(hostPath, containerPath);
}

SetPermission(containerRootPath);

return volumeMounts;
}

private void SetPermission(string path)
{
if (Event.TaskPluginArguments.ContainsKey(Keys.User))
{
if (!System.OperatingSystem.IsWindows())
{
var process = Process.Start("chown", $"-R {Event.TaskPluginArguments[Keys.User]} {path}");
process.WaitForExit();

if (process.ExitCode != 0)
{
_logger.ErrorSettingDirectoryPermission(path, Event.TaskPluginArguments[Keys.User]);
throw new SetPermissionException($"chown command exited with code {process.ExitCode}");
}
}
}
}

protected override void Dispose(bool disposing)
{
if (!DisposedValue && disposing)
Expand Down
5 changes: 5 additions & 0 deletions src/TaskManager/Plug-ins/Docker/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ internal static class Keys
/// </summary>
public static readonly string EntryPoint = "entrypoint";

/// <summary>
/// Key for specifying the user to the container. Same as -u argument for docker run.
/// </summary>
public static readonly string User = "user";

/// <summary>
/// Key for the command to execute by the container.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/TaskManager/Plug-ins/Docker/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,17 @@ public static partial class Log

[LoggerMessage(EventId = 1027, Level = LogLevel.Information, Message = "Image does not exist '{image}' locally, attempting to pull.")]
public static partial void ImageDoesNotExist(this ILogger logger, string image);

[LoggerMessage(EventId = 1028, Level = LogLevel.Information, Message = "Input volume added {hostPath} = {containerPath}.")]
public static partial void InputVolumeMountAdded(this ILogger logger, string hostPath, string containerPath);

[LoggerMessage(EventId = 1029, Level = LogLevel.Information, Message = "Output volume added {hostPath} = {containerPath}.")]
public static partial void OutputVolumeMountAdded(this ILogger logger, string hostPath, string containerPath);

[LoggerMessage(EventId = 1030, Level = LogLevel.Information, Message = "Intermediate volume added {hostPath} = {containerPath}.")]
public static partial void IntermediateVolumeMountAdded(this ILogger logger, string hostPath, string containerPath);

[LoggerMessage(EventId = 1031, Level = LogLevel.Error, Message = "Error setting directory {path} with permission {user}.")]
public static partial void ErrorSettingDirectoryPermission(this ILogger logger, string path, string user);
}
}
40 changes: 40 additions & 0 deletions src/TaskManager/Plug-ins/Docker/SetPermissionException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2022 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Runtime.Serialization;

namespace Monai.Deploy.WorkflowManager.TaskManager.Docker
{
[Serializable]
internal class SetPermissionException : Exception
{
public SetPermissionException()
{
}

public SetPermissionException(string? message) : base(message)
{
}

public SetPermissionException(string? message, Exception? innerException) : base(message, innerException)
{
}

protected SetPermissionException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
21 changes: 21 additions & 0 deletions src/TaskManager/TaskManager/Services/Http/Startup.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ public void ConfigureServices(IServiceCollection services)
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "MONAI Workflow Manager", Version = "v1" });
c.DescribeAllParametersInCamelCase();
c.AddSecurityDefinition("basic", new OpenApiSecurityScheme
{
Scheme = "basic",
Name = "basic",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "basic",
},
},
System.Array.Empty<string>()
},
});
});

var serviceProvider = services.BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private async Task ProcessArtifactReceivedOutputs(ArtifactsReceivedEvent message
}
}

var currentTask = workflowInstance.Tasks?.FirstOrDefault(t => t.TaskId == taskId);
var currentTask = workflowInstance.Tasks?.Find(t => t.TaskId == taskId);

currentTask!.OutputArtifacts = validArtifacts; // added here are the parent function saves the object !

Expand Down Expand Up @@ -735,7 +735,7 @@ private async Task<bool> HandleOutputArtifacts(WorkflowInstance workflowInstance
return false;
}

var currentTask = workflowInstance.Tasks?.FirstOrDefault(t => t.TaskId == task.TaskId);
var currentTask = workflowInstance.Tasks?.Find(t => t.TaskId == task.TaskId);

if (currentTask is not null)
{
Expand Down
Empty file modified src/WorkflowManager/WorkflowManager/Services/Http/Startup.cs
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions tests/UnitTests/WorkflowExecuter.Tests/Services/WorkflowExecuterServiceTests.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3184,6 +3184,7 @@ public async Task ArtifactReceveid_Valid_ReturnesTrue()

Assert.True(result);
}

[Fact]
public async Task ProcessArtifactReceived_Calls_WorkflowInstanceRepository_UpdateTaskOutputArtifactsAsync()
{
Expand Down

0 comments on commit ed574e6

Please sign in to comment.