Changeset 16993 for branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation
- Timestamp:
- 05/29/19 12:16:15 (6 years ago)
- Location:
- branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation/ApplicationRunner.cs
r16984 r16993 1 1 using System; 2 using System.Collections.Generic;3 2 using System.IO; 4 using System.Text;5 3 6 4 namespace HeuristicLab.PluginInfrastructure { … … 17 15 public IApplication StartApplication { 18 16 get { 19 using (var memStream = new MemoryStream(serializedStartApplication)) { 20 return (IApplication)formatter.Deserialize(memStream); 17 if (application == null) { 18 using (var memStream = new MemoryStream(serializedStartApplication)) { 19 application = (IApplication)formatter.Deserialize(memStream); 20 } 21 21 } 22 return application; 22 23 } 23 24 set { … … 31 32 // instantly deserialize the application, before all assemblies are loaded. 32 33 private byte[] serializedStartApplication = new byte[0]; 34 // cache application to prevent new instances every get call of StartApplication 35 private IApplication application; 33 36 34 37 protected override void Execute() { … … 39 42 switch (runnerJob) { 40 43 case RunnerJob.Cancel: StartApplication.OnCancel(); break; 41 case RunnerJob.Pause: StartApplication.OnPause(); break;44 case RunnerJob.Pause: StartApplication.OnPause(); break; 42 45 case RunnerJob.Resume: StartApplication.OnResume(); break; 43 46 } -
branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation/AssemblyLoader.cs
r16984 r16993 120 120 #endregion 121 121 122 123 122 private void LoadTypes(IEnumerable<Assembly> assemblies) { 124 123 foreach (Assembly asm in assemblies) { … … 136 135 } 137 136 } catch (BadImageFormatException) { } 138 } catch (Exception e) { // to catch every other exception137 } catch (Exception) { // to catch every other exception 139 138 //Tracing.Logger.Error( 140 139 // $"Exception occured while loading types of assembly {asm.FullName}! \n " + … … 147 146 foreach (string path in GetAssembliesFromBasePath(basePath)) 148 147 LoadAssemblyFromPath(path); 149 148 150 149 LoadTypes(this.Assemblies); 151 150 return this.Assemblies; … … 155 154 foreach (var info in assemblyInfos) 156 155 LoadAssemblyFromPath(info.Path.ToString()); 157 156 158 157 LoadTypes(this.Assemblies); 159 158 return this.Assemblies; … … 167 166 } // else 168 167 //Tracing.Logger.Error($"Unnable to load assembly with path {path}!"); 169 } catch (Exception e) { // to catch every exception occured by assembly loading.168 } catch (Exception) { // to catch every exception occured by assembly loading. 170 169 //Tracing.Logger.Error( 171 170 // $"Exception occured while loading assembly from path {path}! \n " + -
branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation/DockerRunnerHost.cs
r16985 r16993 1 namespace HeuristicLab.PluginInfrastructure { 1 using System.Diagnostics; 2 using HeuristicLab.PluginInfrastructure.Exceptions; 3 4 namespace HeuristicLab.PluginInfrastructure { 2 5 /// <summary> 3 6 /// IRunner for isolation with docker. 4 7 /// </summary> 5 8 public class DockerRunnerHost : RunnerHost { 6 public DockerRunnerHost() 7 : base("docker", "run -i --rm --mount type=bind,source=/c/Users/,target=/Users heuristiclab33", null, null, null) { 9 #region Constants 10 private const string Docker = "docker"; 11 private const string ContainerStartup = "container run -i --rm "; 12 private const string Mounting = @"--mount type=bind,source=/c/Users/,target=/Users "; 13 private const string Image = "heuristiclab33:latest"; 14 private const string DockerExceptionMessage = "Docker is not running or image '" + Image + "' does not exists!"; 15 #endregion 16 17 #region Constructors 18 public DockerRunnerHost(bool doDockerAvailableCheck = true) 19 : base(Docker, ContainerStartup + Mounting + Image, null, null, null) { 20 if (doDockerAvailableCheck && !IsDockerAvailable()) 21 throw new DockerException(DockerExceptionMessage); 8 22 } 23 #endregion 24 25 #region Helper 26 private bool IsDockerAvailable() { 27 var process = new Process { 28 StartInfo = new ProcessStartInfo { 29 FileName = Docker, 30 Arguments = "image inspect " + Image, 31 UseShellExecute = false, 32 RedirectStandardOutput = true, 33 RedirectStandardInput = false, 34 RedirectStandardError = true, 35 CreateNoWindow = false 36 }, 37 EnableRaisingEvents = false 38 }; 39 40 process.Start(); 41 process.BeginOutputReadLine(); 42 process.BeginErrorReadLine(); 43 process.WaitForExit(); 44 return process.ExitCode == 0; 45 } 46 #endregion 9 47 } 10 48 } -
branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation/NativeRunnerHost.cs
r16985 r16993 6 6 /// </summary> 7 7 public class NativeRunnerHost : RunnerHost { 8 public NativeRunnerHost()9 : base($"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}HeuristicLab-3.3.exe", "",null, null, null) {8 #region Constructors 9 public NativeRunnerHost() : this(null, null, null) { 10 10 } 11 12 public NativeRunnerHost(string userName, string password, string domain) 13 : base($"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}HeuristicLab-3.3.exe", "", userName, password, domain) { 14 } 15 #endregion 11 16 } 12 17 } -
branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation/Runner.cs
r16984 r16993 4 4 using System.Runtime.Serialization; 5 5 using System.Runtime.Serialization.Formatters.Binary; 6 using System.Text;7 6 using System.Threading; 8 7 … … 11 10 public abstract class Runner : IRunner { 12 11 12 #region Vars 13 13 [NonSerialized] 14 14 private Thread listener; … … 19 19 [NonSerialized] 20 20 protected static IFormatter formatter = new BinaryFormatter(); 21 21 #endregion 22 23 #region Properties 22 24 public bool QuietMode { get; set; } 23 25 24 26 public IEnumerable<AssemblyInfo> AssembliesToLoad { get; set; } 27 #endregion 28 25 29 26 30 public static void Serialize(IRunner runner, Stream stream) => formatter.Serialize(stream, runner); … … 41 45 protected abstract void OnRunnerJob(RunnerJob runnerJob); 42 46 47 #region Helper 43 48 private void StartExecutor() { 44 49 executor = new Thread(Execute); … … 46 51 executor.Start(); 47 52 } 53 48 54 private void StartListener() { 49 55 listener = new Thread(() => { 50 56 Stream stdin = Console.OpenStandardInput(); 51 while (executor.IsAlive) 57 while (executor.IsAlive) 52 58 OnRunnerJob((RunnerJob)formatter.Deserialize(stdin)); 53 59 }); … … 55 61 listener.Start(); 56 62 } 57 63 #endregion 58 64 } 59 65 } -
branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation/RunnerHost.cs
r16984 r16993 74 74 UserName = string.IsNullOrEmpty(UserName) ? null : UserName, 75 75 PasswordInClearText = string.IsNullOrEmpty(Password) ? null : Password, 76 Domain = string.IsNullOrEmpty(Domain) ? null : Domain,76 Domain = string.IsNullOrEmpty(Domain) ? null : Domain, 77 77 WorkingDirectory = Directory.GetCurrentDirectory() 78 78 }, … … 86 86 Runner.Serialize(runner, process.StandardInput.BaseStream); 87 87 88 process.BeginOutputReadLine(); 89 process.BeginErrorReadLine(); 90 88 91 if (!runner.QuietMode) { 89 process.BeginOutputReadLine();90 process.BeginErrorReadLine();91 92 process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data); 92 93 process.ErrorDataReceived += (s, e) => Console.WriteLine(e.Data); … … 124 125 /// When the child process gets finished without requested cancellation, the linked token gets cancelled and a result set. 125 126 /// </summary> 126 /// <param name="token"></param>127 /// <returns></returns>128 127 private Task<bool> RegisterCancellation(CancellationToken token) { 129 128 if (process != null && State == RunnerState.Starting) {
Note: See TracChangeset
for help on using the changeset viewer.