Changeset 4368 for branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.ExecutionEngine
- Timestamp:
- 09/07/10 10:22:27 (14 years ago)
- Location:
- branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.ExecutionEngine/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.ExecutionEngine/3.3/Executor.cs
r4285 r4368 30 30 using System.IO; 31 31 using HeuristicLab.Core; 32 using HeuristicLab.Hive.Contracts.BusinessObjects; 33 using System.Collections.Generic; 34 using System.Linq; 32 35 33 36 namespace HeuristicLab.Hive.Slave.ExecutionEngine { … … 57 60 public void Start(byte[] serializedJob) { 58 61 CreationTime = DateTime.Now; 59 Job = XmlParser.Deserialize<IJob>(new MemoryStream(serializedJob));62 Job = DeserializeJobObject(serializedJob); 60 63 61 64 Job.JobStopped += new EventHandler(Job_JobStopped); 62 65 Job.JobFailed += new EventHandler(Job_JobFailed); 63 Job.Prepare(); 64 Job.Start(); 66 Job.NewChildJob += new EventHandler<EventArgs<IJob>>(Job_NewChildJob); 67 Job.WaitForChildJobs += new EventHandler(Job_WaitForChildJobs); 68 69 if (Job.ExecutionState == Core.ExecutionState.Paused) { 70 Queue.AddMessage(new MessageContainerWithCallback<SerializedJobList>(MessageContainer.MessageType.GetChildJobs, JobId, 71 (childjobs) => { 72 Job.Resume(childjobs.Select(j => DeserializeJobObject(j.SerializedJobData))); 73 } 74 )); 75 } else { 76 Job.Prepare(); 77 Job.Start(); 78 } 79 } 80 81 void Job_NewChildJob(object sender, EventArgs<IJob> e) { 82 byte[] jobByteArray = SerializeJobObject(e.Value); 83 84 SerializedJob serializedJob = new SerializedJob() { 85 JobInfo = new JobDto() { 86 State = JobState.Offline, 87 CoresNeeded = e.Value.CoresNeeded, 88 MemoryNeeded = e.Value.MemoryNeeded, 89 PluginsNeeded = HivePluginInfoDto.FindPluginsNeeded(e.Value.GetType()), 90 }, 91 SerializedJobData = jobByteArray 92 }; 93 94 Queue.AddMessage(new MessageContainerWithJob(MessageContainer.MessageType.AddChildJob, this.JobId, serializedJob)); 95 } 96 97 void Job_WaitForChildJobs(object sender, EventArgs e) { 98 // Pause the job and send it back to the hive. The server will awake it when all child-jobs are finished 99 byte[] jobByteArray = SerializeJobObject(Job); 100 101 SerializedJob serializedJob = new SerializedJob() { 102 JobInfo = new JobDto() { 103 Id = JobId, 104 State = JobState.WaitForChildJobs 105 }, 106 SerializedJobData = jobByteArray 107 }; 108 109 JobIsFinished = true; 110 Queue.AddMessage(new MessageContainerWithJob(MessageContainer.MessageType.PauseJob, this.JobId, serializedJob)); 65 111 } 66 112 … … 101 147 CurrentMessage = MessageContainer.MessageType.NoMessage; 102 148 // Pack the whole job inside an xml document 103 byte[] job = SerializeJobObject( );149 byte[] job = SerializeJobObject(Job); 104 150 // Restart the job 105 151 // Return the Snapshot … … 113 159 throw new InvalidStateException("Job is still running"); 114 160 } else { 115 byte[] jobArr = SerializeJobObject( );161 byte[] jobArr = SerializeJobObject(Job); 116 162 return jobArr; 117 163 } … … 123 169 } 124 170 125 private byte[] SerializeJobObject() { 126 MemoryStream stream = new MemoryStream(); 127 XmlGenerator.Serialize(Job, stream); 128 return stream.ToArray(); 171 private byte[] SerializeJobObject(IJob job) { 172 MemoryStream memStream = new MemoryStream(); 173 XmlGenerator.Serialize(job, memStream); 174 byte[] jobByteArray = memStream.ToArray(); 175 memStream.Dispose(); 176 return jobByteArray; 177 } 178 179 private IJob DeserializeJobObject(byte[] sjob) { 180 MemoryStream memStream = new MemoryStream(sjob); 181 IJob job = XmlParser.Deserialize<IJob>(memStream); 182 memStream.Dispose(); 183 return job; 129 184 } 130 185 131 186 private void RestoreJobObject(byte[] sjob) { 132 Job = XmlParser.Deserialize<IJob>(new MemoryStream(sjob));187 Job = DeserializeJobObject(sjob); 133 188 } 134 189 -
branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.ExecutionEngine/3.3/HeuristicLab.Hive.Slave.ExecutionEngine-3.3.csproj
r4296 r4368 76 76 </PropertyGroup> 77 77 <ItemGroup> 78 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 78 79 <Reference Include="HeuristicLab.Common-3.3"> 79 80 <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath> 80 81 </Reference> 81 <Reference Include="HeuristicLab.Core-3.3" 82 <Reference Include="HeuristicLab.Core-3.3"> 82 83 <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath> 83 84 </Reference> 85 <Reference Include="HeuristicLab.DataAccess-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 84 86 <Reference Include="HeuristicLab.Persistence-3.3"> 85 87 <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Persistence-3.3.dll</HintPath>
Note: See TracChangeset
for help on using the changeset viewer.