- Timestamp:
- 08/30/12 16:09:34 (13 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Controller
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller
-
Property
svn:ignore
set to
bin
obj
-
Property
svn:ignore
set to
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HeuristicLab.Services.Optimization.ControllerService.csproj
r8506 r8545 95 95 <HintPath>..\bin\HeuristicLab.Optimization.Operators-3.3.dll</HintPath> 96 96 </Reference> 97 <Reference Include="HeuristicLab.ParallelEngine-3.3"> 98 <HintPath>..\bin\HeuristicLab.ParallelEngine-3.3.dll</HintPath> 99 </Reference> 97 100 <Reference Include="HeuristicLab.Parameters-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 98 101 <SpecificVersion>False</SpecificVersion> … … 108 111 <Reference Include="HeuristicLab.Problems.TravelingSalesman-3.3"> 109 112 <HintPath>..\bin\HeuristicLab.Problems.TravelingSalesman-3.3.dll</HintPath> 113 </Reference> 114 <Reference Include="HeuristicLab.Problems.VehicleRouting-3.3"> 115 <HintPath>..\bin\HeuristicLab.Problems.VehicleRouting-3.3.dll</HintPath> 116 </Reference> 117 <Reference Include="HeuristicLab.Problems.VehicleRouting-3.4"> 118 <HintPath>..\bin\HeuristicLab.Problems.VehicleRouting-3.4.dll</HintPath> 110 119 </Reference> 111 120 <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HiveScenarioManager.cs
r8506 r8545 14 14 using HeuristicLab.Clients.Hive; 15 15 using System.Threading; 16 using HeuristicLab.Data; 16 17 17 18 namespace HeuristicLab.Services.Optimization.ControllerService { … … 110 111 } 111 112 112 public void DispatchScenario(Model. OptimizationScenario scenario) {113 public void DispatchScenario(Model.User user, Model.OptimizationScenario scenario) { 113 114 Experiment experiment = new Experiment(); 114 115 var problem = new TravelingSalesmanProblem(); … … 124 125 125 126 experiment.Optimizers.Add(algo); 126 SendExperimentToHive( experiment);127 } 128 129 private void SendExperimentToHive( Experiment exp) {127 SendExperimentToHive(user, experiment); 128 } 129 130 private void SendExperimentToHive(Model.User user, Experiment exp) { 130 131 var job = new RefreshableJob(); 131 132 job.IsAllowedPrivileged = true; … … 134 135 job.RefreshAutomatically = false; 135 136 job.HiveTasks.Add(new OptimizerHiveTask(exp)); 136 HiveServiceLocator.Instance.Username = "fschoeppl";137 HiveServiceLocator.Instance.Password = "fschoeppl";137 HiveServiceLocator.Instance.Username = user.Username; 138 HiveServiceLocator.Instance.Password = user.Password; 138 139 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 139 140 … … 144 145 job.StopResultPolling(); 145 146 } 147 148 149 public IList<Model.Job> GetJobs(User user) { 150 HiveServiceLocator.Instance.Username = user.Username; 151 HiveServiceLocator.Instance.Password = user.Password; 152 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 153 var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.Job>>(s => s.GetJobs()); 154 IList<Model.Job> jobs = new List<Model.Job>(); 155 156 foreach (var job in jobsLoaded) { 157 jobs.Add(ConvertJob(user, job)); 158 } 159 return jobs; 160 } 161 162 private Model.Job ConvertJob(User user, HeuristicLab.Clients.Hive.Job job) 163 { 164 var waitingJobs = job.JobCount - job.CalculatingCount - job.FinishedCount; 165 Model.JobState? state = null; 166 var jobTasks = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(job.Id)); 167 168 foreach (var task in jobTasks) { 169 switch (task.State) { 170 case TaskState.Aborted: 171 state = JobState.Aborted; 172 break; 173 case TaskState.Failed: 174 state = JobState.Failed; 175 break; 176 } 177 } 178 if (!state.HasValue) { 179 if (job.CalculatingCount > 0) 180 state = JobState.Calculating; 181 else if (waitingJobs > 0) 182 state = JobState.Waiting; 183 else 184 state = JobState.Finished; 185 } 186 return new Model.Job() { Id = job.Id.ToString(), Name = job.Name, Resource = job.ResourceNames, State = state.Value }; 187 } 188 189 190 public Model.Job GetJob(User user, string id) { 191 HiveServiceLocator.Instance.Username = user.Username; 192 HiveServiceLocator.Instance.Password = user.Password; 193 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 194 var guid = Guid.Parse(id); 195 return ConvertJob(user, HiveServiceLocator.Instance.CallHiveService<HeuristicLab.Clients.Hive.Job>(s => s.GetJob(guid))); 196 } 197 198 199 public void DeleteJob(User user, string id) { 200 HiveServiceLocator.Instance.Username = user.Username; 201 HiveServiceLocator.Instance.Password = user.Password; 202 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 203 var guid = Guid.Parse(id); 204 HiveServiceLocator.Instance.CallHiveService(s => s.DeleteJob(guid)); 205 } 206 207 public IList<Model.Run> GetJobResults(User user, string id) { 208 HiveServiceLocator.Instance.Username = user.Username; 209 HiveServiceLocator.Instance.Password = user.Password; 210 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 211 var guid = Guid.Parse(id); 212 var jobTasks = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(guid)); 213 214 IList<Guid> taskIds = new List<Guid>(); 215 foreach (var task in jobTasks) { 216 taskIds.Add(task.Id); 217 } 218 TaskDownloader downloader = new TaskDownloader(taskIds); 219 downloader.StartAsync(); 220 while (!downloader.IsFinished) { 221 Thread.Sleep(500); 222 223 if (downloader.IsFaulted) { 224 throw downloader.Exception; 225 } 226 } 227 IDictionary<Guid, HiveTask> hiveTasks = downloader.Results; 228 IList<Model.Run> runs = new List<Model.Run>(); 229 foreach (var keyTask in hiveTasks.Keys) { 230 var oht = hiveTasks[keyTask] as OptimizerHiveTask; 231 if (oht != null) { 232 foreach (var run in oht.ItemTask.Item.Runs) { 233 Model.Run taskRun = new Model.Run(); 234 taskRun.Id = taskRun.Name = run.Name; 235 IList<Parameter> resultValues = new List<Model.Parameter>(); 236 foreach (var key in run.Results.Keys) { 237 var value = run.Results[key]; 238 Parameter result = MapHiveDataType(key, value); 239 resultValues.Add(result); 240 } 241 taskRun.Results = resultValues; 242 runs.Add(taskRun); 243 } 244 } 245 } 246 return runs; 247 } 248 private Parameter MapHiveDataType(string name, IItem item) { 249 Parameter result = new Parameter(); 250 result.Type = ParameterType.String; 251 if (item is IStringConvertibleValue) { 252 var value = (item as IStringConvertibleValue).GetValue(); 253 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.StringValue() { Name = name, Value = value }; 254 } 255 else if (item is IStringConvertibleValueTuple) { 256 var value1 = (item as IStringConvertibleValueTuple).Item1.GetValue(); 257 var value2 = (item as IStringConvertibleValueTuple).Item2.GetValue(); 258 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.StringValue() { Name = name, Value = "{" + value1 + ", " + value2 + "}" }; 259 } 260 else if (item is IStringConvertibleArray) { 261 StringBuilder sb = new StringBuilder(); 262 var array = item as IStringConvertibleArray; 263 if (array.Length == 0) { 264 sb.Append("[ ]"); 265 } else { 266 sb.Append("["); 267 for (int i=0; i < array.Length - 1; i++) { 268 sb.Append(array.GetValue(i)).Append(", "); 269 } 270 sb.Append(array.GetValue(array.Length - 1)); 271 sb.Append(" ]"); 272 } 273 var value = sb.ToString(); 274 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.StringValue() { Name = name, Value = value }; 275 } 276 else if (item is IStringConvertibleMatrix) { 277 StringBuilder sb = new StringBuilder(); 278 var matrix = item as IStringConvertibleMatrix; 279 if (matrix.Rows == 0 || matrix.Columns == 0) { 280 sb.Append("[ ]"); 281 } 282 else { 283 sb.Append("[ "); 284 for (int r = 0; r < matrix.Rows; r++) { 285 sb.Append("( "); 286 for (int c = 0; c < matrix.Columns - 1; c++) { 287 sb.Append(matrix.GetValue(r, c)).Append(", "); 288 } 289 sb.Append(matrix.GetValue(r, matrix.Columns - 1)).Append(r < matrix.Rows - 1 ? " ), " : " )"); 290 } 291 sb.Append(" ]"); 292 } 293 var value = sb.ToString(); 294 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.StringValue() { Name = name, Value = value }; 295 } 296 else { 297 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.StringValue() { Name = name, Value = "Cannot be displayed as string" }; 298 } 299 return result; 300 } 146 301 } 147 302 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IControllerService.cs
r8506 r8545 17 17 18 18 [OperationContract] 19 void ScheduleOptimizationScenario(OptimizationScenario scenario); 19 void ScheduleOptimizationScenario(User user, OptimizationScenario scenario); 20 21 [OperationContract] 22 IEnumerable<Job> GetJobs(User user); 23 24 [OperationContract] 25 Job GetJob(User user, string id); 26 27 [OperationContract] 28 void DeleteJob(User user, string id); 29 30 [OperationContract] 31 IList<Model.Run> GetJobResults(User user, string id); 20 32 } 21 33 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IScenarioManager.cs
r8506 r8545 7 7 namespace HeuristicLab.Services.Optimization.ControllerService.Interfaces { 8 8 public interface IScenarioManager { 9 void DispatchScenario(OptimizationScenario scenario); 9 void DispatchScenario(User user, OptimizationScenario scenario); 10 IList<Job> GetJobs(User user); 11 Job GetJob(User user, string id); 12 void DeleteJob(User user, string id); 13 IList<Model.Run> GetJobResults(User user, string id); 10 14 } 11 15 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Model/ControllerModel.cs
r8506 r8545 23 23 DecimalVector, 24 24 [EnumMember] 25 Percent 25 Percent, 26 [EnumMember] 27 String 26 28 } 27 29 … … 151 153 152 154 [DataContract] 155 public class StringValue : Value { 156 [DataMember] 157 public string Value { get; set; } 158 159 public override bool TrySetFromString(string input) { 160 Value = input; 161 return true; 162 } 163 } 164 165 [DataContract] 153 166 [KnownType(typeof(BoolValue))] 154 167 [KnownType(typeof(DecimalValue))] … … 156 169 [KnownType(typeof(DecimalVector))] 157 170 [KnownType(typeof(DecimalMatrix))] 171 [KnownType(typeof(StringValue))] 158 172 public class Parameter { 159 173 // some kind of value type … … 211 225 set { algorithmParameters = value; } 212 226 } 213 227 } 228 229 [DataContract] 230 public enum JobState { 231 [EnumMember] 232 Waiting, 233 [EnumMember] 234 Calculating, 235 [EnumMember] 236 Aborted, 237 [EnumMember] 238 Failed, 239 [EnumMember] 240 Finished 241 } 242 243 [DataContract] 244 public class Job { 245 [DataMember] 246 public string Id { get; set; } 247 248 [DataMember] 249 public JobState State { get; set; } 250 251 [DataMember] 252 public string Name { get; set; } 253 254 [DataMember] 255 public string Resource { get; set; } 256 } 257 258 [DataContract] 259 public class Run { 260 [DataMember] 261 public string Id { get; set; } 262 263 [DataMember] 264 public string Name { get; set; } 265 266 [DataMember] 267 public IList<Parameter> Results { get; set; } 268 } 269 270 [DataContract] 271 public class User { 272 [DataMember] 273 public string Username { get; set; } 274 [DataMember] 275 public string Password { get; set; } 214 276 } 215 277 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/PlaceholderControllerService.cs
r8506 r8545 61 61 } 62 62 63 public void ScheduleOptimizationScenario(Model. OptimizationScenario scenario) {64 hiveManager.DispatchScenario( scenario);63 public void ScheduleOptimizationScenario(Model.User user, Model.OptimizationScenario scenario) { 64 hiveManager.DispatchScenario(user, scenario); 65 65 } 66 66 67 67 public IEnumerable<Model.Job> GetJobs(Model.User user) { 68 return hiveManager.GetJobs(user); 69 } 70 71 72 public Model.Job GetJob(Model.User user, string id) { 73 return hiveManager.GetJob(user, id); 74 } 75 76 77 public void DeleteJob(Model.User user, string id) { 78 hiveManager.DeleteJob(user, id); 79 } 80 81 82 public IList<Model.Run> GetJobResults(Model.User user, string id) { 83 return hiveManager.GetJobResults(user, id); 84 } 68 85 } 69 86 }
Note: See TracChangeset
for help on using the changeset viewer.