Changeset 9227 for branches/OaaS
- Timestamp:
- 02/19/13 08:46:01 (12 years ago)
- Location:
- branches/OaaS
- Files:
-
- 15 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Clients.Hive/3.3/Util/PluginUtil.cs
r7259 r9227 27 27 using System.ServiceModel; 28 28 using HeuristicLab.PluginInfrastructure; 29 using System.Diagnostics; 29 30 30 31 namespace HeuristicLab.Clients.Hive { … … 103 104 CollectPluginDependencies(plugins, plugin); 104 105 } 106 else if (plugin == null && !type.FullName.StartsWith("System")) { 107 Trace.WriteLine("No plugin available for: " + type.FullName); 108 } 105 109 } 106 110 } -
branches/OaaS/HeuristicLab.Services.Hive.WebRole/AzureLocalStorageTraceListener.cs
r8235 r9227 6 6 7 7 namespace HeuristicLab.Services.Hive.WebRole { 8 public class AzureLocalStorageTraceListener : XmlWriterTraceListener {8 /*public class AzureLocalStorageTraceListener : XmlWriterTraceListener { 9 9 public AzureLocalStorageTraceListener() 10 10 : base(Path.Combine(AzureLocalStorageTraceListener.GetLogDirectory().Path, "HeuristicLab.Services.Hive.WebRole.svclog")) { … … 18 18 return directory; 19 19 } 20 } 20 }*/ 21 21 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Azure/DAL.cs
r9215 r9227 9 9 using System.Diagnostics; 10 10 using HeuristicLab.Services.Optimization.ControllerService.Model; 11 using HeuristicLab.Services.Optimization.ControllerService.Parsers; 11 12 12 13 namespace HeuristicLab.Services.Optimization.ControllerService.Azure { … … 15 16 public static readonly string SCENARIO_BLOB_CONTAINER = "scenario"; 16 17 public static readonly string EXPERIMENT_TABLE = "Experiment"; 18 public static readonly string EXPERIMENT_BLOB_CONTAINER = "experiment"; 17 19 public static readonly string CLOUD_SETTINGS_KEY = "Cloudia.WindowsAzure.Storage"; 20 21 18 22 } 19 23 … … 97 101 } 98 102 99 public ExperimentEntity(string user, Experiment experiment) {103 public ExperimentEntity(string user, string experimentName, string experimentUrl) { 100 104 PartitionKey = "ScenarioPartition"; 101 RowKey = user + "_" + experiment.Name; 102 var scenarios = ""; 103 foreach (var scen in experiment.Scenarios) { 104 scenarios += scen.Id + ","; 105 } 106 Scenarios = scenarios.Remove(scenarios.Length - 1); 105 RowKey = user + "_" + experimentName; 107 106 User = user; 107 ExperimentJsonUrl = experimentUrl; 108 108 } 109 109 110 110 public string User { get; set; } 111 111 112 public string Scenarios{ get; set; }112 public string ExperimentJsonUrl { get; set; } 113 113 114 114 } … … 122 122 return false; 123 123 124 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 125 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 126 var entity = new ExperimentEntity(username, experiment); 124 // TODO: Save the whole experiment, not just the algorithm names!!! 125 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 126 container.CreateIfNotExist(); 127 // For now we store it as JSON element in the blob store 128 // TODO: Make sure, that all required properties are part of the experiment!! 129 var experimentJson = AlgorithmConverter.ConvertJson(experiment); 130 Guid experimentJsonGuid = Guid.NewGuid(); 131 var experimentJsonId = experiment.Name + "_" + experimentJsonGuid.ToString(); 132 var blob = container.GetBlobReference(experimentJsonId); 133 blob.UploadText(experimentJson); 134 135 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 136 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 137 var entity = new ExperimentEntity(username, experiment.Name, blob.Uri.ToString()); 127 138 serviceContext.AddObject(AzureConstants.EXPERIMENT_TABLE, entity); 128 139 serviceContext.SaveChangesWithRetries(); … … 139 150 if (entity == null) 140 151 return false; 152 153 if (entity.ExperimentJsonUrl != null) { 154 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 155 container.CreateIfNotExist(); 156 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 157 blob.DeleteIfExists(); 158 } 141 159 142 160 serviceContext.DeleteObject(entity); … … 156 174 } 157 175 158 var exp = Convert(entity); 159 return exp; 160 } 161 162 private Experiment Convert(ExperimentEntity entity) { 163 var exp = new Experiment() { Name = entity.RowKey.Split('_')[1] }; 164 foreach (var scenarioName in entity.Scenarios.Split(',')) 165 exp.Scenarios.Add(new OptimizationScenario() { Id = scenarioName }); 166 return exp; 167 } 176 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 177 container.CreateIfNotExist(); 178 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 179 return AlgorithmConverter.ConvertExperimentSimple(blob.DownloadText()); 180 } 181 182 //private Experiment Convert(ExperimentEntity entity, string entityJson) { 183 // // TODO: Read the whole experiment, not just the names! 184 // var exp = new Experiment() { Name = entity.RowKey.Split('_')[1] }; 185 // foreach (var scenarioName in entity.Algorithms.Split(',')) 186 // exp.Algorithm.Add(new Algorithm() { Name = scenarioName }); 187 // return exp; 188 //} 168 189 169 190 public IEnumerable<Model.Experiment> GetExperiments(string user) { … … 174 195 select e).ToList(); 175 196 var experiments = new List<Experiment>(); 197 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 198 container.CreateIfNotExist(); 176 199 foreach (var entity in entites) { 177 experiments.Add(Convert(entity)); 200 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 201 experiments.Add(AlgorithmConverter.ConvertExperimentSimple(blob.DownloadText())); 178 202 } 179 203 return experiments; 204 } 205 206 207 public Experiment GetExperimentByName(string username, string scenario) { 208 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 209 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 210 var entity = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE) 211 where e.RowKey == username + "_" + scenario 212 select e).FirstOrDefault(); 213 if (entity == null || entity.ExperimentJsonUrl == null) { 214 return null; 215 } 216 217 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 218 container.CreateIfNotExist(); 219 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 220 var exp = AlgorithmConverter.ConvertExperimentSimple(blob.DownloadText()); 221 return exp; 180 222 } 181 223 } … … 224 266 get { 225 267 if (expDao == null) { 226 expDao = new ExperimentDao() { TableClient = StorageAccount.CreateCloudTableClient() };268 expDao = new ExperimentDao() { TableClient = StorageAccount.CreateCloudTableClient(), BlobClient = StorageAccount.CreateCloudBlobClient() }; 227 269 } 228 270 return expDao; -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HiveScenarioManager.cs
r9215 r9227 58 58 // algo.Problem = problem; 59 59 60 IScenarioMapper mapper = GetMapper(scenario );60 IScenarioMapper mapper = GetMapper(scenario.Id); 61 61 IAlgorithm algo; 62 62 mapper.MapScenario(scenario, out algo); 63 if (details.Repititions > 1) {63 /*if (details.Repititions > 1) { 64 64 BatchRun br = new BatchRun(); 65 65 //br.Name = details.JobTitle; … … 69 69 } 70 70 else { 71 return SendExperimentToHive(user, algo, details); 72 } 71 72 }*/ 73 return SendExperimentToHive(user, algo, details); 74 } 75 76 private sealed class StackEntry { 77 public HeuristicLab.Optimization.Experiment Parent { get; set; } 78 public IList<Model.Algorithm> Children { get; set; } 79 } 80 81 public bool DispatchExperiment(User user, Model.Experiment exp, JobExecutionDetails details) { 82 // TODO: Determine how to build a tree of IAlgorithm 83 // For now the experiment will be flatened for execution 84 HeuristicLab.Optimization.Experiment hiveExperiment = new HeuristicLab.Optimization.Experiment(exp.Name); 85 var stack = new Stack<StackEntry>(); 86 var children = new List<Model.Algorithm>(); 87 foreach (var child in exp.Algorithm) { 88 children.Add(child); 89 } 90 stack.Push(new StackEntry() { Parent = hiveExperiment, Children = children }); 91 92 while (stack.Count > 0) { 93 var entry = stack.Pop(); 94 // handle current entry 95 96 // TODO: Store scenario name in entry.Child.Mapper when saving 97 foreach (var child in entry.Children) { 98 // This is a template experiment; 99 if (child.Name == null) { 100 var parent = new HeuristicLab.Optimization.Experiment(child.Name); 101 entry.Parent.Optimizers.Add(parent); 102 stack.Push(new StackEntry() { Parent = parent, Children = child.ChildAlgorithms }); 103 } 104 // This entity is mapable 105 else { 106 IScenarioMapper mapper = GetMapper(child.Name); 107 if (mapper == null) { // TODO: We should really be able to difference Experiment/Algorithm types; this is a workaround 108 var parent = new HeuristicLab.Optimization.Experiment(child.Name); 109 entry.Parent.Optimizers.Add(parent); 110 stack.Push(new StackEntry() { Parent = parent, Children = child.ChildAlgorithms }); 111 } 112 else { 113 var optScen = new OptimizationScenario() { Id = child.Name }; 114 optScen.Algorithm.Add(child); 115 IAlgorithm algo; 116 mapper.MapScenario(optScen, out algo); 117 entry.Parent.Optimizers.Add(algo); 118 } 119 } 120 } 121 } 122 details.JobTitle = exp.Name; 123 return SendExperimentToHive(user, hiveExperiment, details) != null; 73 124 } 74 125 … … 113 164 } 114 165 115 private IScenarioMapper GetMapper( Model.OptimizationScenario scenario) {116 var id = scenario .Id;166 private IScenarioMapper GetMapper(string scenarioId) { 167 var id = scenarioId; 117 168 if (!mappers.ContainsKey(id)) { 118 169 lock (lockable) { … … 121 172 122 173 var mapperString = GetMapperFromBlobStore(id); 174 if (mapperString == null) return null; 123 175 var mapper = CompileMapper(mapperString); 124 176 … … 131 183 132 184 private void MapExperiment(Model.OptimizationScenario scenario, out IAlgorithm algorithm) { 133 IScenarioMapper mapper = GetMapper(scenario );185 IScenarioMapper mapper = GetMapper(scenario.Id); 134 186 mapper.MapScenario(scenario, out algorithm); 135 187 } 136 188 137 private void ConfigureHive(Model.User user) { 138 HiveServiceLocator.Instance.Username = user.Username; 139 HiveServiceLocator.Instance.Password = user.Password; 140 HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName; 189 private HiveServiceLocator ConfigureHive(Model.User user) { 190 var serviceLocator = new HiveServiceLocator(); 191 serviceLocator.Username = user.Username; 192 serviceLocator.Password = user.Password; 193 serviceLocator.EndpointConfigurationName = Configuration.HiveEndpointName; 194 return serviceLocator; 141 195 } 142 196 … … 146 200 job.Job.Name = details.JobTitle; 147 201 job.Job.ResourceNames = details.Group; 148 job.RefreshAutomatically = false; 202 job.RefreshAutomatically = false; 203 204 if (details.Repititions > 1) { 205 BatchRun br = new BatchRun(); 206 br.Optimizer = exp; 207 br.Repetitions = details.Repititions; 208 exp = br; 209 } 210 149 211 if (exp.ExecutionState != ExecutionState.Prepared) { 150 212 exp.Prepare(); 151 213 } 152 214 job.HiveTasks.Add(new OptimizerHiveTask(exp)); 153 ConfigureHive(user); 154 215 var service = ConfigureHive(user); 216 217 // TODO: Fix HiveClient class to be not dependent on singleton HiveServiceLocator!!! 218 HiveServiceLocator.Instance.Username = user.Username; 219 HiveServiceLocator.Instance.Password = user.Password; 220 HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName; 155 221 HiveClient.StartJob((ex) => { 156 222 Console.WriteLine(ex.StackTrace); … … 163 229 164 230 public IList<Model.Job> GetJobs(User user) { 165 ConfigureHive(user);166 var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.Job>>(s => s.GetJobs());231 var serviceLocator = ConfigureHive(user); 232 var jobsLoaded = serviceLocator.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.Job>>(s => s.GetJobs()); 167 233 IList<Model.Job> jobs = new List<Model.Job>(); 168 234 … … 189 255 190 256 public Model.Job GetJob(User user, string id) { 191 ConfigureHive(user);257 var serviceLocator = ConfigureHive(user); 192 258 var guid = Guid.Parse(id); 193 return ConvertJob(user, HiveServiceLocator.Instance.CallHiveService<HeuristicLab.Clients.Hive.Job>(s => s.GetJob(guid)));259 return ConvertJob(user, serviceLocator.CallHiveService<HeuristicLab.Clients.Hive.Job>(s => s.GetJob(guid))); 194 260 } 195 261 196 262 197 263 public bool DeleteJob(User user, string id) { 198 ConfigureHive(user);264 var serviceLocator = ConfigureHive(user); 199 265 var guid = Guid.Parse(id); 200 HiveServiceLocator.Instance.CallHiveService(s => s.DeleteJob(guid));266 serviceLocator.CallHiveService(s => s.DeleteJob(guid)); 201 267 return true; 202 268 } 203 269 204 270 public IList<Model.Run> GetJobResults(User user, string id) { 205 ConfigureHive(user);271 var serviceLocator = ConfigureHive(user); 206 272 var guid = Guid.Parse(id); 207 var jobTasks = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(guid));273 var jobTasks = serviceLocator.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(guid)); 208 274 209 275 IList<Guid> taskIds = new List<Guid>(); … … 211 277 taskIds.Add(task.Id); 212 278 } 279 280 // TODO: Fix problems with the HiveServiceLocater singleton!!! 281 HiveServiceLocator.Instance.Username = user.Username; 282 HiveServiceLocator.Instance.Password = user.Password; 283 HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName; 213 284 TaskDownloader downloader = new TaskDownloader(taskIds); 214 285 downloader.StartAsync(); … … 337 408 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.StringValue() { Name = name, Value = "Cannot be displayed as string" }; 338 409 } 410 // TODO: Add workaround for TSP 339 411 return result; 340 412 } … … 416 488 public Model.Task GetTaskData(User u, string jobId, string taskId) { 417 489 ConfigureHive(u); 490 HiveServiceLocator.Instance.Username = u.Username; 491 HiveServiceLocator.Instance.Password = u.Password; 492 HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName; 418 493 TaskDownloader downloader = new TaskDownloader(new List<Guid>(){Guid.Parse(taskId)}); 419 494 downloader.StartAsync(); … … 446 521 447 522 public Model.Job GetTasks(User u, string jobId) { 448 ConfigureHive(u);449 var jobTasks = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(Guid.Parse(jobId)));523 var serviceLocator = ConfigureHive(u); 524 var jobTasks = serviceLocator.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(Guid.Parse(jobId))); 450 525 451 526 var job = new Model.Job(); … … 455 530 foreach (var task in jobTasks) { 456 531 // TODO: Crawl children + parent and create hierarchy! 457 var children = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightChildTasks(Guid.Parse(jobId), true, true));532 var children = serviceLocator.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightChildTasks(Guid.Parse(jobId), true, true)); 458 533 foreach (var child in children) { 459 534 tasks[child.Id] = new Model.Task() { … … 483 558 return job; 484 559 } 560 561 562 public Model.Experiment GetExperimentByName(User user, string scenario) { 563 return dal.ExperimentDao.GetExperimentByName(user.Username, scenario); 564 } 565 566 567 485 568 } 486 569 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HeuristicLab.Services.Optimization.ControllerService.csproj
r9215 r9227 168 168 <ItemGroup> 169 169 <Compile Include="Azure\DAL.cs" /> 170 <Compile Include="General\AlgorithmHelper.cs" /> 170 171 <Compile Include="General\Configuration.cs" /> 171 172 <Compile Include="HL\HiveMapper.cs" /> -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/DAL.cs
r9215 r9227 23 23 Experiment FindByName(string username, string experiment); 24 24 IEnumerable<Experiment> GetExperiments(string user); 25 Experiment GetExperimentByName(string username, string scenario); 25 26 } 26 27 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IControllerService.cs
r9215 r9227 21 21 [OperationContract] 22 22 bool ScheduleOptimizationScenario(User user, OptimizationScenario scenario, JobExecutionDetails details); 23 24 [OperationContract] 25 bool ScheduleExperiment(User user, string experiment, JobExecutionDetails details); 23 26 24 27 [OperationContract] … … 54 57 [OperationContract] 55 58 Task GetTaskData(User u, string jobId, string taskId); 59 60 [OperationContract] 61 Experiment GetExperimentByName(User user, string scenario); 56 62 } 57 63 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IScenarioManager.cs
r9215 r9227 21 21 Task GetTaskData(User u, string jobId, string taskId); 22 22 Job GetTasks(User u, string jobId); 23 24 Experiment GetExperimentByName(User user, string scenario); 25 bool DispatchExperiment(User user, Experiment exp, JobExecutionDetails details); 23 26 } 24 27 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/Model/ControllerModel.cs
r9215 r9227 274 274 [DataContract] 275 275 public class Algorithm { 276 public Algorithm() { Parameters = new AlgorithmParameters(); }276 public Algorithm() { Parameters = new AlgorithmParameters(); ChildAlgorithms = new List<Algorithm>(); } 277 277 278 278 [DataMember] … … 290 290 [DataMember] 291 291 public string Mapper { get; set; } 292 293 [DataMember] 294 public string Name { get; set; } 292 295 } 293 296 … … 296 299 [DataMember] 297 300 public string Id { get; set; } 298 301 302 public OptimizationScenario() { Algorithm = new List<Algorithm>(); } 303 299 304 [DataMember] 300 305 public IList<Algorithm> Algorithm { get; set; } … … 309 314 310 315 [DataMember] 311 public IList< OptimizationScenario> Scenarios{ get; set; }316 public IList<Algorithm> Algorithm { get; set; } 312 317 313 318 public Experiment() { 314 Scenarios = new List<OptimizationScenario>(); 315 } 319 Algorithm = new List<Algorithm>(); 320 } 321 322 [DataMember] 323 public JobExecutionDetails JobDetails { get; set; } 316 324 } 317 325 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Mockup/MockupScenarioManager.cs
r9215 r9227 263 263 throw new NotImplementedException(); 264 264 } 265 266 267 public Model.Experiment GetExperimentByName(User user, string scenario) { 268 throw new NotImplementedException(); 269 } 270 271 272 public bool DispatchExperiment(User user, Model.Experiment exp, JobExecutionDetails details) { 273 throw new NotImplementedException(); 274 } 265 275 } 266 276 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Parsers/AlgorithmConverter.cs
r9215 r9227 5 5 using HeuristicLab.Services.Optimization.ControllerService.Model; 6 6 using Newtonsoft.Json.Linq; 7 using Newtonsoft.Json; 7 8 8 9 namespace HeuristicLab.Services.Optimization.ControllerService.Parsers { … … 10 11 11 12 public static Algorithm Convert(string json) { 13 var o = JObject.Parse(json); 14 return ParseAlgorithm(o); 15 } 16 17 private static Algorithm ParseAlgorithm(JToken obj) { 12 18 var algorithm = new Algorithm(); 13 var o = JObject.Parse(json); 14 foreach (JProperty param in o ["Algorithm Parameters"]) {19 20 foreach (JProperty param in obj["Algorithm Parameters"]) { 15 21 Parameter parameter = CreateParameter(param); 16 22 algorithm.Parameters.Items.Add(parameter); 17 23 } 18 24 19 var problemParams = o["Problem Parameters"]; 20 // TODO: Store problem parameters 25 var problemParams = obj["Problem Parameters"]; 21 26 if (problemParams != null) { 22 27 algorithm.Problem = new Problem(); … … 69 74 case JTokenType.String: 70 75 return new Parameter() { Type = ParameterType.Type, Value = new TypeValue() { Name = property.Name, Value = (string)property.Value } }; 76 case JTokenType.Array: 77 var arr = (JArray)token; 78 // its a matrix 79 if (arr[0].Type == JTokenType.Array) { 80 return CreateMatrixParameter(property.Name, arr); 81 } 82 return CreateVectorParameter(property.Name, arr); 71 83 default: 72 84 throw new Exception("Unhandled datatype: " + property.Type); 73 85 } 74 86 } 87 88 private static Parameter CreateMatrixParameter(string name, JArray arr) { 89 double[][] entries = new double[arr.Count][]; 90 for (int i = 0; i < entries.Length; i++) { 91 entries[i] = (from d in arr[i] select (double)d).ToArray<double>(); 92 } 93 return new Parameter { Type = ParameterType.DecimalMatrix, Value = new DecimalMatrix() { Name = name, Value = entries } }; 94 } 95 96 private static Parameter CreateVectorParameter(string name, JArray arr) { 97 double[] entries = (from d in arr select (double)d).ToArray<double>(); 98 return new Parameter { Type = ParameterType.DecimalVector, Value = new DecimalVector() { Name = name, Value = entries } }; 99 } 100 101 public static string ConvertJson(Algorithm algorithm) { 102 return JsonConvert.SerializeObject(algorithm); 103 } 104 105 106 private class StackEntry { 107 public Algorithm Parent { get; set; } 108 public JToken Child { get; set; } 109 } 110 111 public static Experiment ConvertExperimentSimple(string json) { 112 return JsonConvert.DeserializeObject<Experiment>(json, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); 113 } 114 115 public static string ConvertJson(Experiment experiment) { 116 return JsonConvert.SerializeObject(experiment, Formatting.None, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }); 117 } 118 119 public static Experiment ConvertExperiment(string json) { 120 var experiment = new Experiment(); 121 var jsonExperiment = JObject.Parse(json); 122 experiment.Name = (string)jsonExperiment["name"]; 123 var stack = new Stack<StackEntry>(); 124 var root = new Algorithm(); 125 126 if ((bool)jsonExperiment["run"]) { 127 experiment.JobDetails = new JobExecutionDetails() { 128 Group = (string)jsonExperiment["group"], 129 Repititions = (int)jsonExperiment["repititions"] 130 }; 131 } 132 133 foreach (var algo in jsonExperiment["algorithms"]["children"]) { 134 stack.Push(new StackEntry(){ Parent = root, Child = algo }); 135 } 136 137 while (stack.Count > 0) { 138 var entry = stack.Pop(); 139 var data = entry.Child["data"]; 140 var currentAlgo = data == null ? new Algorithm() : ParseAlgorithm(entry.Child["data"]); 141 currentAlgo.Name = (string)entry.Child["name"]; 142 entry.Parent.ChildAlgorithms.Add(currentAlgo); 143 // push children on stack (inverse order to preserve ordering) 144 var cnt = entry.Child["children"].Count(); 145 for (var i=0; i < cnt; i++) { 146 stack.Push(new StackEntry() { Parent = currentAlgo, Child = entry.Child["children"][cnt - 1 - i] }); 147 } 148 } 149 150 foreach (var algo in root.ChildAlgorithms) { 151 experiment.Algorithm.Add(algo); 152 } 153 154 return experiment; 155 } 75 156 } 76 157 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/PlaceholderControllerService.cs
r9215 r9227 6 6 using HeuristicLab.Services.Optimization.ControllerService.Interfaces; 7 7 using HeuristicLab.Services.Optimization.ControllerService.Model; 8 using HeuristicLab.Services.Optimization.ControllerService.General; 8 9 9 10 namespace HeuristicLab.Services.Optimization.ControllerService { … … 120 121 121 122 122 public bool SaveExperiment(User user, Experiment experiment) { 123 return hiveManager.SaveExperiment(user, experiment); 123 public bool SaveExperiment(User user, Experiment experiment) { 124 // make sure all algorithms store their choices aswell 125 var scenarioMap = new Dictionary<string, OptimizationScenario>(); 126 var algos = new Stack<Algorithm>(); 127 foreach (var algo in experiment.Algorithm) algos.Push(algo); 128 129 130 131 while (algos.Count > 0) { 132 var algo = algos.Pop(); 133 if (algo.ChildAlgorithms != null) 134 foreach (var child in algo.ChildAlgorithms) algos.Push(child); 135 136 if (AlgorithmHelper.HasToBeUpdated(algo)) { 137 OptimizationScenario scenario; 138 if (!scenarioMap.TryGetValue(algo.Name, out scenario)) { 139 scenario = GetOptimizationScenarioByName(algo.Name); 140 scenarioMap[algo.Name] = scenario; 141 } 142 143 AlgorithmHelper.Update(algo, scenario); 144 } 145 } 146 147 // finally store the experiment 148 var success = hiveManager.SaveExperiment(user, experiment); 149 // if it has been stored, and jobdetails are present, run the job! 150 if (success && experiment.JobDetails != null) { 151 return ScheduleExperiment(user, experiment.Name, experiment.JobDetails); 152 } 153 return success; 124 154 } 125 155 … … 142 172 return hiveManager.GetTaskData(u, jobId, taskId); 143 173 } 174 175 176 public Experiment GetExperimentByName(User user, string scenario) { 177 return hiveManager.GetExperimentByName(user, scenario); 178 } 179 180 181 public bool ScheduleExperiment(User user, string experiment, JobExecutionDetails details) { 182 var exp = hiveManager.GetExperimentByName(user, experiment); 183 return hiveManager.DispatchExperiment(user, exp, details); 184 } 144 185 } 145 186 } -
branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/ExperimentController.cs
r9215 r9227 8 8 using HeuristicLab.Services.Optimization.ControllerService.Model; 9 9 using System.Web.Security; 10 using Mvc3TestApplication.Binders; 11 using HeuristicLab.Services.Optimization.ControllerService.Parsers; 10 12 11 13 namespace HeuristicLab.Services.Optimization.Web.Controllers … … 41 43 foreach (var scenario in scenarios) 42 44 model.Scenarios.Add(scenario); 45 46 Session["experiment"] = new Experiment(); 47 43 48 return View(model); 44 49 } 50 51 public ActionResult New() { 52 return Index(); 53 } 54 55 public Experiment Experiment { get { return Session["experiment"] as Experiment; } set { Session["experiment"] = value;} } 45 56 46 57 [HttpPost] … … 63 74 if (currentNode.title == "Experiment") 64 75 continue; 65 experiment. Scenarios.Add(new OptimizationScenario() { Id= currentNode.title });76 experiment.Algorithm.Add(new Algorithm() { Name = currentNode.title }); 66 77 } 67 78 … … 94 105 return RedirectToAction("Edit"); 95 106 } 107 108 [HttpPost] 109 public JsonResult SaveExperiment([ExperimentJson] Experiment experiment) { 110 return Json( 111 new { 112 Success = ControllerService.withControllerService<bool>(service => { 113 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 114 return service.SaveExperiment(u, experiment); 115 }) 116 }); 117 } 118 119 private JsonResult ComplexExperimentCase(string scenario) { 120 // complex case, find children of experiment 121 var model = new GetParametersModel() { Type = "Complex" }; 122 model.Subnames = new List<string>(); 123 124 var experiment = ControllerService.withControllerService<Experiment>(service => { 125 User user = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 126 return service.GetExperimentByName(user, scenario); 127 }); 128 129 // TODO: Make a tree out of subnames!! 130 if (experiment != null) 131 foreach (var algo in experiment.Algorithm) 132 model.Subnames.Add(algo.Name); 133 134 return Json(model, JsonRequestBehavior.AllowGet); 135 } 136 137 [HttpGet] 138 public JsonResult GetParameters(string scenario, string context, int index) { 139 if (context == "Experiment" || context == null) { 140 var optimizationScenario = ControllerService.withControllerService<OptimizationScenario>(service => { 141 return service.GetOptimizationScenarioByName(scenario); 142 }); 143 144 if (optimizationScenario != null) { 145 var model = new GetParametersModel() { Type = "Basic" }; 146 model.Algorithm = optimizationScenario.FirstAlgorithm; 147 model.Algorithm.Mapper = optimizationScenario.Id; 148 var json = Json(model, JsonRequestBehavior.AllowGet); 149 return json; 150 } 151 else { 152 // complex case, find children of experiment 153 var model = new GetParametersModel() { Type = "Complex" }; 154 model.Subnames = new List<string>(); 155 156 var experiment = ControllerService.withControllerService<Experiment>(service => { 157 User user = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 158 return service.GetExperimentByName(user, scenario); 159 }); 160 161 // TODO: Make a tree out of subnames!! 162 if (experiment != null) 163 foreach (var algo in experiment.Algorithm) 164 model.Subnames.Add(algo.Name); 165 166 return Json(model, JsonRequestBehavior.AllowGet); 167 } 168 } 169 else { 170 var experiment = ControllerService.withControllerService<Experiment>(service => { 171 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 172 return service.GetExperimentByName(u, context); 173 }); 174 175 // if child algorithm is a complex algorithm, return as such 176 if (experiment.Algorithm[index].ChildAlgorithms.Count > 0) { 177 var model = new GetParametersModel() { Type = "Complex" }; 178 model.Subnames = new List<string>(); 179 foreach (var algo in experiment.Algorithm[index].ChildAlgorithms) 180 model.Subnames.Add(algo.Name); 181 return Json(model, JsonRequestBehavior.AllowGet); 182 } 183 else { 184 // otherwise we have the algorithms just below it 185 var model = new GetParametersModel() { Type = "Basic" }; 186 model.Algorithm = experiment.Algorithm[index]; 187 model.Algorithm.Mapper = experiment.Algorithm[index].Name; 188 var json = Json(model, JsonRequestBehavior.AllowGet); 189 return json; 190 } 191 } 192 } 96 193 } 97 194 } -
branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OptimizationController.cs
r9215 r9227 57 57 58 58 public ActionResult JobDetails(string jobId) { 59 Job job = ControllerService.withControllerService<Job>((service) => {59 var model = ControllerService.withControllerService<JobDetailsModel>((service) => { 60 60 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 61 return service.GetJob(u, jobId); 61 var job = service.GetJob(u, jobId); 62 var runs = service.GetJobResults(u, jobId); 63 return new JobDetailsModel() { Job = job, Runs = runs }; 62 64 }); 63 var runs = ControllerService.withControllerService<IList<Run>>((service) => { 64 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 65 return service.GetJobResults(u, jobId); 66 }); 67 JobDetailsModel jdm = new JobDetailsModel() { Job = job, Runs = runs }; 68 Session["jobDetails"] = jdm; 69 return View(jdm); 70 } 65 Session["jobDetails"] = model; 66 return View(model); 67 } 71 68 72 69 [HttpPost] -
branches/OaaS/HeuristicLab.Services.Optimization.Web/HeuristicLab.Services.Optimization.Web.csproj
r9215 r9227 97 97 </ItemGroup> 98 98 <ItemGroup> 99 <Content Include="Content\ajax-loader.gif" /> 100 <Content Include="Content\Datatypemapping.js" /> 99 101 <Content Include="Content\dynatree\dist\jquery.dynatree.min.js" /> 100 102 <Content Include="Content\dynatree\src\skin\icons-rtl.gif" /> … … 105 107 <Content Include="Content\dynatree\src\skin\vline.gif" /> 106 108 <Content Include="Content\ExperimentSupport.js" /> 109 <Compile Include="Binders\AlgorithmJsonAttribute.cs" /> 107 110 <Compile Include="Controllers\AccountController.cs" /> 108 111 <Compile Include="Controllers\AdminController.cs" /> … … 369 372 </None> 370 373 <Content Include="Views\Status\Index.cshtml" /> 374 <Content Include="Views\Experiment\New.cshtml" /> 371 375 </ItemGroup> 372 376 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -
branches/OaaS/HeuristicLab.Services.Optimization.Web/Models/ExperimentModel.cs
r9215 r9227 3 3 using System.Linq; 4 4 using System.Web; 5 using HeuristicLab.Services.Optimization.ControllerService.Model; 5 6 6 7 namespace HeuristicLab.Services.Optimization.Web.Models { … … 16 17 public Node Experiment { get; set; } 17 18 public string Name { get; set; } 19 } 20 21 public class GetParametersModel { 22 public string Type { get; set; } 23 public Algorithm Algorithm { get; set; } 24 public IList<string> Subnames { get; set; } 18 25 } 19 26 -
branches/OaaS/HeuristicLab.Services.Optimization.Web/Views/Shared/_Layout.cshtml
r9215 r9227 30 30 <script type="text/javascript" src="@Url.Content("~/Content/dynatree/dist/jquery.dynatree.min.js")"></script> 31 31 <script type="text/javascript" src="@Url.Content("~/Content/ExperimentSupport.js")"></script> 32 33 <!-- Experiment Additions --> 34 <script src="@Url.Content("~/Content/Datatypemapping.js")" type="text/javascript"></script> 35 <link href="@Url.Content("~/Content/smartwizard2.0/styles/smart_wizard.css")" rel="stylesheet" type="text/css" /> 36 <script type="text/javascript" src="@Url.Content("~/Content/smartwizard2.0/js/jquery.smartWizard-2.0.min.js")"></script> 32 37 </head> 33 38 <body>
Note: See TracChangeset
for help on using the changeset viewer.