Changeset 4140 for branches/3.2/sources
- Timestamp:
- 08/03/10 17:20:46 (14 years ago)
- Location:
- branches/3.2/sources
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/sources/HeuristicLab.Hive.Client.Communication/3.2/WcfService.cs
r3931 r4140 462 462 } 463 463 } 464 465 464 } 466 465 } -
branches/3.2/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs
r4042 r4140 45 45 using HeuristicLab.Hive.Client.Core.JobStorage; 46 46 using HeuristicLab.Tracing; 47 using System.IO; 47 48 48 49 namespace HeuristicLab.Hive.Client.Core { … … 135 136 136 137 case MessageContainer.MessageType.JobAborted: 137 //todo: thread this 138 lock (engines) { 139 Guid jobId = new Guid(container.JobId.ToString()); 140 if (engines.ContainsKey(jobId)) { 141 appDomains[jobId].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException); 142 AppDomain.Unload(appDomains[jobId]); 143 appDomains.Remove(jobId); 144 engines.Remove(jobId); 145 jobs.Remove(jobId); 146 GC.Collect(); 147 } else 148 Logger.Error("JobAbort: Engine doesn't exist"); 149 } 138 Guid jobId = new Guid(container.JobId.ToString()); 139 KillAppDomain(jobId); 150 140 break; 151 141 … … 252 242 sJob, 253 243 1, 254 null,244 engines[jId].CurrentException, 255 245 true); 256 246 } else { 257 247 Logger.Info("Storing the finished job with id: " + jId + " to hdd"); 258 248 JobStorageManager.PersistObjectToDisc(wcfService.ServerIP, wcfService.ServerPort, jId, sJob); 259 lock (engines) { 260 appDomains[jId].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException); 261 262 //Disposing it 263 engines[jId].Dispose(); 264 265 AppDomain.Unload(appDomains[jId]); 266 Logger.Debug("Unloaded appdomain"); 267 appDomains.Remove(jId); 268 engines.Remove(jId); 269 jobs.Remove(jId); 270 Logger.Debug("Removed job from appDomains, Engines and Jobs"); 271 } 249 KillAppDomain(jId); 272 250 } 273 251 } … … 339 317 PluginCache.Instance.PreparePlugins(e.Result.Job.PluginsNeeded); 340 318 341 // foreach (CachedHivePluginInfoDto plugininfo in PluginCache.Instance.GetPlugins(e.Result.Job.PluginsNeeded)) 342 // files.AddRange(plugininfo.PluginFiles); 319 PluginCache.Instance.CopyPluginsForJob(e.Result.Job.PluginsNeeded, e.Result.Job.Id); 320 343 321 Logger.Debug("Plugins fetched for job " + e.Result.Job.Id); 344 322 try { 323 String pluginDir = Path.Combine(PluginCache.PLUGIN_REPO, e.Result.Job.Id.ToString()); 345 324 AppDomain appDomain = 346 HeuristicLab.PluginInfrastructure.Sandboxing.SandboxManager.CreateAndInitSandbox( 347 e.Result.Job.Id.ToString(), null); 325 HeuristicLab.PluginInfrastructure.Sandboxing.SandboxManager.CreateAndInitSandbox(pluginDir, null); 348 326 appDomain.UnhandledException += new UnhandledExceptionEventHandler(appDomain_UnhandledException); 349 327 lock (engines) { … … 372 350 CurrentlyFetching = false; 373 351 KillAppDomain(e.Result.Job.Id); 352 wcfService.StoreFinishedJobResultsSync(ConfigManager.Instance.GetClientInfo().Id, e.Result.Job.Id, new byte[] { }, 353 1, exception, true); 374 354 } 375 355 } else … … 504 484 engines.Remove(id); 505 485 jobs.Remove(id); 486 PluginCache.Instance.DeletePluginsForJob(id); 506 487 GC.Collect(); 507 488 } -
branches/3.2/sources/HeuristicLab.Hive.Client.Core/3.2/PluginCache.cs
r4042 r4140 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using System.Runtime.CompilerServices; 4 5 using System.Text; 5 6 using HeuristicLab.PluginInfrastructure; … … 9 10 using HeuristicLab.Tracing; 10 11 using System.IO; 12 using HeuristicLab.PluginInfrastructure.Manager; 11 13 12 14 namespace HeuristicLab.Hive.Client.Core { 15 16 17 13 18 public class PluginCache { 14 19 15 20 private static PluginCache instance = null; 21 22 public const string PLUGIN_REPO = @"plugins\"; 23 24 private List<PluginDescription> cachedPlugins = new List<PluginDescription>(); 25 26 private PluginManager pm = new PluginManager(PLUGIN_REPO); 27 16 28 public static PluginCache Instance { 17 29 get { … … 22 34 } 23 35 24 private List<CachedHivePluginInfoDto> pluginCache;25 26 36 27 public PluginCache() { 28 pluginCache = new List<CachedHivePluginInfoDto>(); 29 } 30 31 public void AddPlugin(CachedHivePluginInfoDto plugin) { 32 pluginCache.Add(plugin); 37 public PluginCache() { 38 DoUpdateRun(); 33 39 } 34 40 35 public List<CachedHivePluginInfoDto> GetPlugins(List<HivePluginInfoDto> requests) { 41 private void DoUpdateRun() { 42 pm.DiscoverAndCheckPlugins(); 43 cachedPlugins = new List<PluginDescription>(pm.Plugins); 44 } 45 46 47 [MethodImpl(MethodImplOptions.Synchronized)] 48 public bool CopyPluginsForJob(List<HivePluginInfoDto> requests, Guid jobId) { 49 50 String targetDir = PLUGIN_REPO + jobId.ToString() + "\\"; 51 52 if(Directory.Exists(targetDir)) { 53 Directory.Delete(targetDir, true); 54 } 55 56 DirectoryInfo di = Directory.CreateDirectory(targetDir); 57 58 foreach (HivePluginInfoDto requestedPlugin in requests) { 59 PluginDescription pd = 60 cachedPlugins.Where( 61 cp => 62 cp.Name == requestedPlugin.Name && 63 cp.Version.Major == requestedPlugin.Version.Major && 64 cp.Version.Minor == requestedPlugin.Version.Minor && 65 cp.Version.Revision >= requestedPlugin.Version.Revision). 66 SingleOrDefault(); 67 if (pd == null) { 68 return false; 69 } 70 71 foreach(IPluginFile ipf in pd.Files) { 72 File.Copy(ipf.Name, targetDir + ipf.Name.Split('\\').Last()); 73 } 74 } 75 return true; 76 } 77 78 [MethodImpl(MethodImplOptions.Synchronized)] 79 internal void PreparePlugins(List<HivePluginInfoDto> requiredPlugins) { 36 80 Logger.Debug("Fetching plugins for job"); 37 List<CachedHivePluginInfoDto> neededPlugins = new List<CachedHivePluginInfoDto>(); 81 List<HivePluginInfoDto> localPlugins = new List<HivePluginInfoDto>(); 82 List<HivePluginInfoDto> neededPlugins = new List<HivePluginInfoDto>(); 38 83 List<HivePluginInfoDto> missingPlugins = new List<HivePluginInfoDto>(); 39 84 bool found = false; 40 41 foreach (HivePluginInfoDto info in requ ests) {85 86 foreach (HivePluginInfoDto info in requiredPlugins) { 42 87 //we MAY run in problems here - if there is a plugin twice in requests, there may be added two different versions of the plugin 43 foreach ( CachedHivePluginInfoDto cache in pluginCache) {44 if (info.Name.Equals(cache .Name) && info.Version.Equals(cache.Version) && info.BuildDate <= cache.BuildDate) {88 foreach (PluginDescription cachedPlugin in cachedPlugins) { 89 if (info.Name.Equals(cachedPlugin.Name)) { 45 90 Logger.Debug("Found plugin " + info.Name + ", " + info.Version); 46 neededPlugins.Add(cache); 91 localPlugins.Add(new HivePluginInfoDto() { BuildDate = DateTime.Now, Id = new Guid(), Name = info.Name, Version = info.Version, Update = true}); 92 neededPlugins.Add(info); 47 93 found = true; 94 48 95 break; 49 96 } 50 97 } 51 if (!found) 52 Logger.Debug(" FoundNOT found " + info.Name + ", " + info.Version);98 if (!found) { 99 Logger.Debug("Plugin NOT found " + info.Name + ", " + info.Version); 53 100 missingPlugins.Add(info); 101 } 54 102 found = false; 55 103 } 56 104 57 Logger.Debug("Requesting missing plugins"); 58 List<CachedHivePluginInfoDto> receivedPlugins = WcfService.Instance.RequestPlugins(missingPlugins); 59 Logger.Debug("Requested missing plugins"); 105 Logger.Debug("First run - Update the plugins in the cache"); 60 106 61 if (receivedPlugins != null) { 62 neededPlugins.AddRange(receivedPlugins); 63 pluginCache.AddRange(receivedPlugins); 64 } else 65 Logger.Error("Fetching of the plugins failed!"); 107 localPlugins.AddRange(missingPlugins); 66 108 67 return neededPlugins; 109 List<CachedHivePluginInfoDto> updateablePlugins = WcfService.Instance.RequestPlugins(localPlugins); 110 111 foreach (CachedHivePluginInfoDto updateablePlugin in updateablePlugins) { 112 PluginDescription pd = 113 cachedPlugins.Where(cachedPlugin => cachedPlugin.Name.Equals(updateablePlugin.Name)).SingleOrDefault(); 114 115 if (pd != null) { 116 Logger.Debug("deleting old files"); 117 foreach (IPluginFile ipf in pd.Files) { 118 File.Delete(ipf.Name); 119 } 120 } 121 122 Logger.Debug("deleted old files"); 123 Logger.Debug("creating new files"); 124 125 126 127 foreach (HivePluginFile pf in updateablePlugin.PluginFiles) { 128 File.WriteAllBytes(PLUGIN_REPO + pf.Name.Split('\\').Last(), pf.BinaryFile); 129 } 130 131 Logger.Debug("created new files"); 132 DoUpdateRun(); 133 } 68 134 } 69 135 70 71 internal void PreparePlugins(List<HivePluginInfoDto> requiredPlugins) { 72 List<HivePluginInfoDto> missingPlugins = new List<HivePluginInfoDto>(); 73 foreach (HivePluginInfoDto requiredPlugin in requiredPlugins) { 74 if(ApplicationManager.Manager.Plugins.Count(ipd => ipd.Version.Major == requiredPlugin.Version.Major && ipd.Version.Minor >= requiredPlugin.Version.Minor) == 0) { 75 missingPlugins.Add(requiredPlugin); 76 } 136 internal void DeletePluginsForJob(Guid id) { 137 try { 138 Logger.Debug("unloading..."); 139 Directory.Delete(Path.Combine(PLUGIN_REPO, id.ToString()), true); 140 } catch (Exception ex) { 141 Logger.Debug("failed while unloading " + id + " with exception " + ex); 77 142 } 78 79 Logger.Debug("Requesting missing plugins");80 List<CachedHivePluginInfoDto> receivedPlugins = WcfService.Instance.RequestPlugins(missingPlugins);81 Logger.Debug("Requested missing plugins");82 83 foreach (CachedHivePluginInfoDto receivedPlugin in receivedPlugins) {84 foreach (HivePluginFile hpf in receivedPlugin.PluginFiles) {85 Logger.Info("writing file " + hpf.Name);86 File.WriteAllBytes("C:\\temp\\" + hpf.Name.Split('\\').Last(), hpf.BinaryFile);87 }88 }89 90 143 } 91 144 } -
branches/3.2/sources/HeuristicLab.Hive.Client.ExecutionEngine/3.2/ExecutionEnginePlugin.cs
r2591 r4140 30 30 [PluginFile("HeuristicLab.Hive.Client.ExecutionEngine-3.2.dll", PluginFileType.Assembly)] 31 31 [PluginDependency("HeuristicLab.Core-3.2")] 32 [PluginDependency("HeuristicLab.Common")] 32 33 [PluginDependency("HeuristicLab.Hive.Client.Common-3.2")] 33 34 [PluginDependency("HeuristicLab.Hive.Client.Communication-3.2")] -
branches/3.2/sources/HeuristicLab.Hive.Client.ExecutionEngine/3.2/Executor.cs
r3931 r4140 37 37 public IJob Job { get; set; } 38 38 public MessageContainer.MessageType CurrentMessage { get; set; } 39 public Exception CurrentException { get; set; } 40 39 41 public MessageQueue Queue { get; set; } 40 42 … … 66 68 67 69 void Job_JobFailed(object sender, EventArgs e) { 68 Queue.AddMessage(new MessageContainer(MessageContainer.MessageType.JobFailed, JobId)); 70 HeuristicLab.Common.EventArgs<Exception> ex = (HeuristicLab.Common.EventArgs<Exception>) e; 71 CurrentException = ex.Value; 72 Queue.AddMessage(new MessageContainer(MessageContainer.MessageType.FinishedJob, JobId)); 69 73 } 70 74 -
branches/3.2/sources/HeuristicLab.Hive.Client.ExecutionEngine/3.2/HeuristicLab.Hive.Client.ExecutionEngine-3.2.csproj
r1534 r4140 90 90 </ItemGroup> 91 91 <ItemGroup> 92 <ProjectReference Include="..\..\HeuristicLab.Common\3.2\HeuristicLab.Common-3.2.csproj"> 93 <Project>{1FC004FC-59AF-4249-B1B6-FF25873A20E4}</Project> 94 <Name>HeuristicLab.Common-3.2</Name> 95 </ProjectReference> 92 96 <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj"> 93 97 <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project> -
branches/3.2/sources/HeuristicLab.Hive.Contracts/3.2/ApplicationConstants.cs
r3931 r4140 85 85 public static string RESPONSE_COMMUNICATOR_SEND_JOBRESULT = "Please send the Jobresult to the server"; 86 86 public static string RESPONSE_COMMUNICATOR_PLUGINS_SENT = "Communicator.PluginsSent"; 87 public static string RESPONSE_COMMUNICATOR_PLUGINS_NOT_AVAIL = "Communicator.PluginsNotAvail"; 87 88 public static string RESPONSE_COMMUNICATOR_JOB_WAS_ABORTED = "Job was aborted"; 88 89 -
branches/3.2/sources/HeuristicLab.Hive.Contracts/3.2/BusinessObjects/ClientDto.cs
r3931 r4140 28 28 namespace HeuristicLab.Hive.Contracts.BusinessObjects { 29 29 30 public enum State { nullState, idle, calculating, offline, finished, abort, requestSnapshot, requestSnapshotSent, pending };30 public enum State { nullState, idle, calculating, offline, finished, abort, requestSnapshot, requestSnapshotSent, pending, failed }; 31 31 public enum CalendarState { Fetch, ForceFetch, Fetching, Fetched, NotAllowedToFetch }; 32 32 -
branches/3.2/sources/HeuristicLab.Hive.Contracts/3.2/BusinessObjects/HivePluginInfoDto.cs
r4042 r4140 41 41 [DataMember] 42 42 public DateTime BuildDate { get; set; } 43 44 [DataMember] 45 public Boolean Update { get; set; } 43 46 } 44 47 } -
branches/3.2/sources/HeuristicLab.Hive.Contracts/3.2/BusinessObjects/JobDto.cs
r3578 r4140 44 44 public double? Percentage { get; set; } 45 45 [DataMember] 46 public String Exception { get; set; } 47 [DataMember] 46 48 public DateTime? DateCreated { get; set; } 47 49 [DataMember] -
branches/3.2/sources/HeuristicLab.Hive.Server.Core/3.2/ClientCommunicator.cs
r4042 r4140 595 595 } 596 596 job.JobInfo.Percentage = percentage; 597 598 if (finished) { 597 if(exception != null) { 598 job.JobInfo.State = State.failed; 599 job.JobInfo.Exception = exception.ToString(); 600 job.JobInfo.DateFinished = DateTime.Now; 601 } else if (finished) { 599 602 job.JobInfo.State = State.finished; 600 603 job.JobInfo.DateFinished = DateTime.Now; … … 718 721 ResponsePlugin response = new ResponsePlugin(); 719 722 foreach (HivePluginInfoDto pluginInfo in pluginList) { 720 // TODO: BuildDate deleted, not needed??? 721 // TODO: Split version to major, minor and revision number 722 foreach (IPluginDescription currPlugin in ApplicationManager.Manager.Plugins) { 723 if (currPlugin.Name == pluginInfo.Name) { 724 725 CachedHivePluginInfoDto currCachedPlugin = new CachedHivePluginInfoDto { 726 Name = currPlugin.Name, 727 Version = currPlugin.Version, 728 BuildDate = currPlugin.BuildDate 729 }; 730 731 foreach (string fileName in from file in currPlugin.Files select file.Name) { 732 currCachedPlugin.PluginFiles.Add(new HivePluginFile(File.ReadAllBytes(fileName), fileName)); 733 } 734 response.Plugins.Add(currCachedPlugin); 723 if(pluginInfo.Update) { 724 //check if there is a newer version 725 IPluginDescription ipd = 726 ApplicationManager.Manager.Plugins.Where(pd => pd.Name == pluginInfo.Name && pd.Version.Major == pluginInfo.Version.Major && pd.Version.Minor == pluginInfo.Version.Minor && pd.Version.Revision > pluginInfo.Version.Revision).SingleOrDefault(); 727 if(ipd != null) { 728 response.Plugins.Add(convertPluginDescriptorToDto(ipd)); 729 } 730 } else { 731 IPluginDescription ipd = 732 ApplicationManager.Manager.Plugins.Where(pd => pd.Name == pluginInfo.Name && pd.Version.Major == pluginInfo.Version.Major && pd.Version.Minor == pluginInfo.Version.Minor && pd.Version.Revision >= pluginInfo.Version.Revision).SingleOrDefault(); 733 if(ipd != null) { 734 response.Plugins.Add(convertPluginDescriptorToDto(ipd)); 735 } else { 736 response.Success = false; 737 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_PLUGINS_NOT_AVAIL; 738 return response; 735 739 } 736 740 } … … 741 745 return response; 742 746 747 } 748 749 private CachedHivePluginInfoDto convertPluginDescriptorToDto(IPluginDescription currPlugin) { 750 CachedHivePluginInfoDto currCachedPlugin = new CachedHivePluginInfoDto { 751 Name = currPlugin.Name, 752 Version = currPlugin.Version, 753 BuildDate = currPlugin.BuildDate 754 }; 755 756 foreach (string fileName in from file in currPlugin.Files select file.Name) { 757 currCachedPlugin.PluginFiles.Add(new HivePluginFile(File.ReadAllBytes(fileName), fileName)); 758 } 759 return currCachedPlugin; 743 760 } 744 761 -
branches/3.2/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/HiveDataContext.cs
r3931 r4140 1941 1941 private System.Nullable<double> _Percentage; 1942 1942 1943 private string _Exception; 1944 1943 1945 private System.Data.Linq.Link<System.Data.Linq.Binary> _SerializedJob; 1944 1946 … … 1985 1987 partial void OnPercentageChanging(System.Nullable<double> value); 1986 1988 partial void OnPercentageChanged(); 1989 partial void OnExceptionChanging(string value); 1990 partial void OnExceptionChanged(); 1987 1991 partial void OnSerializedJobChanging(System.Data.Linq.Binary value); 1988 1992 partial void OnSerializedJobChanged(); … … 2124 2128 } 2125 2129 2130 [Column(Storage="_Exception", DbType="VarChar(MAX)")] 2131 public string Exception 2132 { 2133 get 2134 { 2135 return this._Exception; 2136 } 2137 set 2138 { 2139 if ((this._Exception != value)) 2140 { 2141 this.OnExceptionChanging(value); 2142 this.SendPropertyChanging(); 2143 this._Exception = value; 2144 this.SendPropertyChanged("Exception"); 2145 this.OnExceptionChanged(); 2146 } 2147 } 2148 } 2149 2126 2150 [Column(Storage="_SerializedJob", DbType="VarBinary(MAX)", UpdateCheck=UpdateCheck.Never)] 2127 2151 public System.Data.Linq.Binary SerializedJob -
branches/3.2/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/HiveDataContext.xml
r3931 r4140 99 99 <Column Name="ResourceId" Member="ResourceId" DbType="UniqueIdentifier" Type="System.Guid" CanBeNull="true"/> 100 100 <Column Name="Percentage" Member="Percentage" DbType="Float" Type="System.Double" CanBeNull="true"/> 101 <Column Name="Exception" Member="Exception" DbType="VarChar(MAX)" Type="System.String" CanBeNull="true"/> 101 102 <Column Name="SerializedJob" Member="SerializedJob" DbType="VarBinary(MAX)" UpdateCheck="Never" Type="System.Data.Linq.Binary" IsDelayLoaded="true"/> 102 103 <Column Name="DateCreated" Member="DateCreated" DbType="DateTime" Type="System.DateTime" CanBeNull="true"/> -
branches/3.2/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/JobDao.cs
r3931 r4140 167 167 target.DateFinished = source.DateFinished; 168 168 target.JobId = source.Id; 169 169 170 170 target.Percentage = source.Percentage; 171 target.Exception = source.Exception; 171 172 172 173 target.Priority = source.Priority; … … 195 196 target.DateFinished = source.DateFinished; 196 197 target.Id = source.JobId; 197 198 199 target.Exception = source.Exception; 198 200 target.Percentage = source.Percentage; 199 201 -
branches/3.2/sources/HeuristicLab.PluginInfrastructure/Manager/PluginManager.cs
r3247 r4140 35 35 /// Class to manage different plugins. 36 36 /// </summary> 37 internalsealed class PluginManager : MarshalByRefObject {37 public sealed class PluginManager : MarshalByRefObject { 38 38 internal event EventHandler<PluginInfrastructureEventArgs> PluginLoaded; 39 39 internal event EventHandler<PluginInfrastructureEventArgs> PluginUnloaded; … … 49 49 /// Gets all installed plugins. 50 50 /// </summary> 51 internalIEnumerable<PluginDescription> Plugins {51 public IEnumerable<PluginDescription> Plugins { 52 52 get { return plugins; } 53 53 } … … 64 64 private bool initialized; 65 65 66 internalPluginManager(string pluginDir) {66 public PluginManager(string pluginDir) { 67 67 this.pluginDir = pluginDir; 68 68 plugins = new List<PluginDescription>(); … … 74 74 /// Determines installed plugins and checks if all plugins are loadable. 75 75 /// </summary> 76 internalvoid DiscoverAndCheckPlugins() {76 public void DiscoverAndCheckPlugins() { 77 77 OnInitializing(PluginInfrastructureEventArgs.Empty); 78 78 AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; -
branches/3.2/sources/HeuristicLab.PluginInfrastructure/Sandboxing/SandboxManager.cs
r4050 r4140 94 94 DefaultApplicationManager applicationManager = 95 95 (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null, null); 96 ApplicationDescription[] apps = ApplicationManager.Manager.Applications.Cast<ApplicationDescription>().ToArray();97 PluginDescription[] plugins = ApplicationManager.Manager.Plugins.Cast<PluginDescription>().ToArray();98 applicationManager.PrepareApplicationDomain(apps, plugins);99 if (files != null && files.Count() > 0)100 applicationManager.LoadAssemblies(files);96 PluginManager pm = new PluginManager(name); 97 pm.DiscoverAndCheckPlugins(); 98 ApplicationDescription[] apps = pm.Applications.Cast<ApplicationDescription>().ToArray(); 99 PluginDescription[] plugins = pm.Plugins.Cast<PluginDescription>().ToArray(); 100 applicationManager.PrepareApplicationDomain(apps, plugins); 101 101 return applicationDomain; 102 102 }
Note: See TracChangeset
for help on using the changeset viewer.