- Timestamp:
- 03/11/13 14:40:04 (12 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Controller
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Azure/DAL.cs
r9227 r9305 101 101 } 102 102 103 public ExperimentEntity(string user, string experimentName, string experiment Url) {103 public ExperimentEntity(string user, string experimentName, string experimentId, string experimentUrl) { 104 104 PartitionKey = "ScenarioPartition"; 105 105 RowKey = user + "_" + experimentName; 106 106 User = user; 107 ExperimentId = experimentId; 107 108 ExperimentJsonUrl = experimentUrl; 108 109 } 110 111 public string ExperimentId { get; set; } 109 112 110 113 public string User { get; set; } … … 122 125 return false; 123 126 124 // TODO: Save the whole experiment, not just the algorithm names!!!125 127 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 126 128 container.CreateIfNotExist(); 127 129 // 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 var experimentJson = AlgorithmConverter.ConvertExperimentToJson(experiment); 130 131 Guid experimentJsonGuid = Guid.NewGuid(); 131 132 var experimentJsonId = experiment.Name + "_" + experimentJsonGuid.ToString(); 133 experimentJson["nodeId"] = experimentJsonId.ToString(); 132 134 var blob = container.GetBlobReference(experimentJsonId); 133 blob.UploadText(experimentJson); 135 blob.UploadText(experimentJson.ToString()); 136 experiment.Id = experimentJsonId; 134 137 135 138 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 136 139 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 137 var entity = new ExperimentEntity(username, experiment.Name, blob.Uri.ToString());140 var entity = new ExperimentEntity(username, experiment.Name, experiment.Id, blob.Uri.ToString()); 138 141 serviceContext.AddObject(AzureConstants.EXPERIMENT_TABLE, entity); 139 142 serviceContext.SaveChangesWithRetries(); 143 return true; 144 } 145 146 public bool Update(string username, Experiment experiment) { 147 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 148 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 149 var entity = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE) 150 where e.ExperimentId == experiment.Id 151 select e).FirstOrDefault(); 152 if (entity == null) { 153 return false; 154 } 155 156 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 157 container.CreateIfNotExist(); 158 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 159 var experimentJson = AlgorithmConverter.ConvertExperimentToJson(experiment).ToString(); 160 blob.UploadText(experimentJson); 140 161 return true; 141 162 } … … 177 198 container.CreateIfNotExist(); 178 199 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 179 return AlgorithmConverter.Convert ExperimentSimple(blob.DownloadText());200 return AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText()); 180 201 } 181 202 … … 199 220 foreach (var entity in entites) { 200 221 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 201 experiments.Add(AlgorithmConverter.Convert ExperimentSimple(blob.DownloadText()));222 experiments.Add(AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText())); 202 223 } 203 224 return experiments; … … 218 239 container.CreateIfNotExist(); 219 240 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 220 var exp = AlgorithmConverter.Convert ExperimentSimple(blob.DownloadText());241 var exp = AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText()); 221 242 return exp; 222 243 } 244 245 246 public Experiment GetExperimentById(User user, string nodeId) { 247 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 248 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 249 var entity = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE) 250 where e.ExperimentId == nodeId 251 select e).FirstOrDefault(); 252 if (entity == null || entity.ExperimentJsonUrl == null) { 253 return null; 254 } 255 256 if (entity.User != user.Username) 257 return null; 258 259 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 260 container.CreateIfNotExist(); 261 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 262 return AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText()); 263 } 264 223 265 } 224 266 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HiveScenarioManager.cs
r9227 r9305 97 97 foreach (var child in entry.Children) { 98 98 // This is a template experiment; 99 if (child. Name == null) {100 var parent = new HeuristicLab.Optimization.Experiment( child.Name);99 if (child.IsExperiment) { 100 var parent = new HeuristicLab.Optimization.Experiment(); 101 101 entry.Parent.Optimizers.Add(parent); 102 102 stack.Push(new StackEntry() { Parent = parent, Children = child.ChildAlgorithms }); … … 104 104 // This entity is mapable 105 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 } 106 IScenarioMapper mapper = GetMapper(child.Id); 107 var optScen = new OptimizationScenario() { Id = child.Id }; 108 optScen.Algorithm.Add(child); 109 IAlgorithm algo; 110 mapper.MapScenario(optScen, out algo); 111 entry.Parent.Optimizers.Add(algo); 119 112 } 120 113 } … … 166 159 private IScenarioMapper GetMapper(string scenarioId) { 167 160 var id = scenarioId; 168 if (!mappers.ContainsKey(id)) { 161 IScenarioMapper mapper = null; 162 if (!mappers.TryGetValue(id, out mapper)) { 169 163 lock (lockable) { 170 164 if (mappers.ContainsKey(id)) … … 173 167 var mapperString = GetMapperFromBlobStore(id); 174 168 if (mapperString == null) return null; 175 varmapper = CompileMapper(mapperString);169 mapper = CompileMapper(mapperString); 176 170 177 171 mappers[id] = mapper; … … 179 173 } // lock 180 174 } // if 181 return null;175 return mapper; 182 176 } 183 177 … … 471 465 } 472 466 473 public bool SaveExperiment(User user, Model.Experiment experiment) { 474 return dal.ExperimentDao.Add(user.Username, experiment); 475 } 476 477 public IEnumerable<string> GetExperiments(User user) { 467 public string SaveExperiment(User user, Model.Experiment experiment) { 468 if (experiment.Id != null) { 469 dal.ExperimentDao.Update(user.Username, experiment); 470 } 471 else { 472 dal.ExperimentDao.Add(user.Username, experiment); 473 } 474 return experiment.Id; 475 } 476 477 public IEnumerable<string> GetExperimentNames(User user) { 478 478 return (from exp in dal.ExperimentDao.GetExperiments(user.Username) 479 479 select exp.Name); … … 564 564 } 565 565 566 567 566 public IEnumerable<Model.Experiment> GetExperiments(User user) { 567 return dal.ExperimentDao.GetExperiments(user.Username); 568 } 569 570 public Model.Experiment GetExperimentById(User user, string nodeId) { 571 return dal.ExperimentDao.GetExperimentById(user, nodeId); 572 } 568 573 } 569 574 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HeuristicLab.Services.Optimization.ControllerService.csproj
r9227 r9305 189 189 </ItemGroup> 190 190 <ItemGroup> 191 <None Include="packages.config" /> 191 <None Include="packages.config"> 192 <SubType>Designer</SubType> 193 </None> 192 194 </ItemGroup> 193 195 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/DAL.cs
r9227 r9305 20 20 public interface IExperimentDao { 21 21 bool Add(string username, Experiment experiment); 22 bool Update(string username, Experiment experiment); 22 23 bool DeleteByName(string username, string experiment); 23 24 Experiment FindByName(string username, string experiment); 24 25 IEnumerable<Experiment> GetExperiments(string user); 25 26 Experiment GetExperimentByName(string username, string scenario); 27 28 Experiment GetExperimentById(User user, string nodeId); 26 29 } 27 30 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IControllerService.cs
r9227 r9305 44 44 45 45 [OperationContract] 46 boolSaveExperiment(User user, Experiment experiment);46 string SaveExperiment(User user, Experiment experiment); 47 47 48 48 [OperationContract] 49 IEnumerable<string> GetExperiments(User user); 49 IEnumerable<string> GetExperimentNames(User user); 50 51 [OperationContract] 52 IEnumerable<Experiment> GetExperiments(User user); 50 53 51 54 [OperationContract] … … 60 63 [OperationContract] 61 64 Experiment GetExperimentByName(User user, string scenario); 65 66 [OperationContract] 67 Experiment GetExperimentById(User u, string nodeId); 62 68 } 63 69 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IScenarioManager.cs
r9227 r9305 15 15 bool DeleteScenario(User user, string scenarioName); 16 16 17 bool SaveExperiment(User user, Experiment experiment); 18 IEnumerable<string> GetExperiments(User user); 17 string SaveExperiment(User user, Experiment experiment); 18 IEnumerable<string> GetExperimentNames(User user); 19 IEnumerable<Model.Experiment> GetExperiments(User user); 20 Experiment GetExperimentByName(User user, string scenario); 21 Experiment GetExperimentById(User user, string nodeId); 22 19 23 bool DeleteExperiment(User user, string experiment); 20 24 … … 22 26 Job GetTasks(User u, string jobId); 23 27 24 Experiment GetExperimentByName(User user, string scenario);28 25 29 bool DispatchExperiment(User user, Experiment exp, JobExecutionDetails details); 26 30 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/Model/ControllerModel.cs
r9227 r9305 277 277 278 278 [DataMember] 279 public string Id { get; set; } 280 281 [DataMember] 279 282 public AlgorithmParameters Parameters { get; set; } 280 283 … … 293 296 [DataMember] 294 297 public string Name { get; set; } 298 299 [DataMember] 300 public bool IsExperiment { get; set; } 295 301 } 296 302 … … 315 321 [DataMember] 316 322 public IList<Algorithm> Algorithm { get; set; } 323 324 [DataMember] 325 public string Id { get; set; } 317 326 318 327 public Experiment() { -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Mockup/MockupScenarioManager.cs
r9227 r9305 241 241 242 242 243 public boolSaveExperiment(User user, Model.Experiment experiment) {244 throw new NotImplementedException(); 245 } 246 247 248 public IEnumerable<string> GetExperiment s(User user) {243 public string SaveExperiment(User user, Model.Experiment experiment) { 244 throw new NotImplementedException(); 245 } 246 247 248 public IEnumerable<string> GetExperimentNames(User user) { 249 249 throw new NotImplementedException(); 250 250 } … … 271 271 272 272 public bool DispatchExperiment(User user, Model.Experiment exp, JobExecutionDetails details) { 273 throw new NotImplementedException(); 274 } 275 276 277 string IScenarioManager.SaveExperiment(User user, Model.Experiment experiment) { 278 throw new NotImplementedException(); 279 } 280 281 public IEnumerable<Model.Experiment> GetExperiments(User user) { 282 throw new NotImplementedException(); 283 } 284 285 public Model.Experiment GetExperimentById(User user, string nodeId) { 273 286 throw new NotImplementedException(); 274 287 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Parsers/AlgorithmConverter.cs
r9227 r9305 9 9 namespace HeuristicLab.Services.Optimization.ControllerService.Parsers { 10 10 public static class AlgorithmConverter { 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) { 18 var algorithm = new Algorithm(); 19 20 foreach (JProperty param in obj["Algorithm Parameters"]) { 21 Parameter parameter = CreateParameter(param); 22 algorithm.Parameters.Items.Add(parameter); 23 } 24 25 var problemParams = obj["Problem Parameters"]; 26 if (problemParams != null) { 27 algorithm.Problem = new Problem(); 28 foreach (JProperty param in problemParams) { 29 Parameter parameter = CreateParameter(param); 30 algorithm.Problem.Parameters.Items.Add(parameter); 31 } 32 } 33 return algorithm; 34 } 35 36 public static Algorithm ConvertAppend(string json, Algorithm algorithm) { 37 var o = JObject.Parse(json); 38 foreach (JProperty param in o["Algorithm Parameters"]) { 39 Parameter parameter = CreateParameter(param); 40 var oldParameter = (from p in algorithm.Parameters.Items where p.Value.Name == parameter.Value.Name select p).FirstOrDefault(); 41 if (oldParameter != null) { 42 oldParameter.Value = parameter.Value; 43 } 44 else { 45 algorithm.Parameters.Items.Add(parameter); 46 } 47 } 48 49 var problemParams = o["Problem Parameters"]; 50 if (problemParams != null) { 51 algorithm.Problem = new Problem(); 52 foreach (JProperty param in problemParams) { 53 Parameter parameter = CreateParameter(param); 54 var oldParameter = (from p in algorithm.Problem.Parameters.Items where p.Value.Name == parameter.Value.Name select p).FirstOrDefault(); 55 if (oldParameter != null) { 56 oldParameter.Value = parameter.Value; 57 } 58 else { 59 algorithm.Problem.Parameters.Items.Add(parameter); 60 } 61 } 62 } 63 return algorithm; 64 } 65 66 private static Parameter CreateParameter(JProperty property) { 67 JToken token = property.Value; 68 switch (token.Type) { 11 #region private methods 12 private static Parameter CreateParameter(JObject property) { 13 var name = (string)property["Name"]; 14 var value = property["Value"]; 15 switch (value.Type) { 69 16 case JTokenType.Integer: 70 17 case JTokenType.Float: 71 return new Parameter() { Type = ParameterType.Decimal, Value = new DecimalValue() { Name = property.Name, Value = (double)property.Value } };18 return new Parameter() { Type = ParameterType.Decimal, Value = new DecimalValue() { Name = name, Value = (double)value } }; 72 19 case JTokenType.Boolean: 73 return new Parameter() { Type = ParameterType.Boolean, Value = new BoolValue() { Name = property.Name, Value = (bool)property.Value } };20 return new Parameter() { Type = ParameterType.Boolean, Value = new BoolValue() { Name = name, Value = (bool)value } }; 74 21 case JTokenType.String: 75 return new Parameter() { Type = ParameterType.Type, Value = new TypeValue() { Name = property.Name, Value = (string)property.Value } };22 return new Parameter() { Type = ParameterType.Type, Value = new TypeValue() { Name = name, Value = (string)value, Options = (from e in property["Options"] select (string)e).ToArray() } }; 76 23 case JTokenType.Array: 77 var arr = (JArray) token;24 var arr = (JArray)value; 78 25 // its a matrix 79 26 if (arr[0].Type == JTokenType.Array) { 80 return CreateMatrixParameter( property.Name, arr);27 return CreateMatrixParameter(name, arr); 81 28 } 82 return CreateVectorParameter( property.Name, arr);29 return CreateVectorParameter(name, arr); 83 30 default: 84 31 throw new Exception("Unhandled datatype: " + property.Type); … … 89 36 double[][] entries = new double[arr.Count][]; 90 37 for (int i = 0; i < entries.Length; i++) { 91 entries[i] = (from d in arr[i] select (double)d).ToArray<double>(); 38 entries[i] = (from d in arr[i] select (double)d).ToArray<double>(); 92 39 } 93 40 return new Parameter { Type = ParameterType.DecimalMatrix, Value = new DecimalMatrix() { Name = name, Value = entries } }; … … 99 46 } 100 47 101 public static string ConvertJson(Algorithm algorithm) {102 return JsonConvert.SerializeObject(algorithm);103 }104 105 106 48 private class StackEntry { 107 49 public Algorithm Parent { get; set; } … … 109 51 } 110 52 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) { 53 private static JArray ConvertParametersToJson(IList<Parameter> parameters) { 54 var array = new JArray(); 55 foreach (var param in parameters) { 56 array.Add(JObject.FromObject(param.Value)); 57 } 58 return array; 59 } 60 61 private struct Entry { 62 public JObject TargetAlgorithm { get; set; } 63 64 public Algorithm SourceAlgorithm { get; set; } 65 } 66 67 private static Algorithm ParseAlgorithm(JToken jsonAlgorithm) { 68 var algorithm = new Algorithm(); 69 70 foreach (JObject param in jsonAlgorithm["AlgorithmParameters"]) { 71 Parameter parameter = CreateParameter(param); 72 algorithm.Parameters.Items.Add(parameter); 73 } 74 75 var problemParams = jsonAlgorithm["ProblemParameters"]; 76 if (problemParams != null) { 77 algorithm.Problem = new Problem(); 78 foreach (JObject param in problemParams) { 79 Parameter parameter = CreateParameter(param); 80 algorithm.Problem.Parameters.Items.Add(parameter); 81 } 82 } 83 return algorithm; 84 } 85 #endregion 86 87 88 #region public methods 89 90 91 public static JObject ConvertExperimentToJson(Experiment experiment) { 92 var exp = new JObject(); 93 exp["title"] = experiment.Name; 94 exp["children"] = new JArray(); 95 exp["nodeId"] = experiment.Id; 96 exp["isExperiment"] = true; 97 98 var stack = new Stack<Entry>(); 99 foreach (var algo in experiment.Algorithm) 100 stack.Push(new Entry() { TargetAlgorithm = exp, SourceAlgorithm = algo }); 101 102 while (stack.Count > 0) { 103 var entry = stack.Pop(); 104 var algorithm = ConvertAlgorithmToJson(entry.SourceAlgorithm); 105 (entry.TargetAlgorithm["children"] as JArray).Add(algorithm); 106 107 if (entry.SourceAlgorithm.ChildAlgorithms.Count > 0) { 108 // push children 109 foreach (var child in entry.SourceAlgorithm.ChildAlgorithms) { 110 stack.Push(new Entry() { TargetAlgorithm = algorithm, SourceAlgorithm = child }); 111 } 112 } 113 114 } 115 return exp; 116 } 117 118 public static JArray ConvertExperimentsToJson(IEnumerable<Experiment> experiments) { 119 var jarray = new JArray(); 120 foreach (var exp in experiments) 121 jarray.Add(ConvertExperimentToJson(exp)); 122 return jarray; 123 } 124 125 public static JArray ConvertAlgorithmsToJson(IEnumerable<Algorithm> algorithms) { 126 var jarray = new JArray(); 127 foreach (var algo in algorithms) 128 jarray.Add(ConvertAlgorithmToJson(algo)); 129 return jarray; 130 } 131 132 133 public static JArray ConvertScenariosToJson(IEnumerable<OptimizationScenario> scenarios) { 134 var jarray = new JArray(); 135 foreach (var scen in scenarios) 136 jarray.Add(ConvertScenarioToJson(scen)); 137 return jarray; 138 } 139 140 public static JObject ConvertScenarioToJson(OptimizationScenario scenario) { 141 var exp = new JObject(); 142 exp["title"] = scenario.Id; 143 exp["children"] = new JArray(); 144 exp["nodeId"] = scenario.Id; 145 exp["isExperiment"] = false; 146 147 var stack = new Stack<Entry>(); 148 var baseAlgorithm = ConvertAlgorithmToJson(scenario.FirstAlgorithm); 149 exp["data"] = baseAlgorithm["data"]; 150 if (scenario.FirstAlgorithm.ChildAlgorithms.Count > 0) { 151 foreach (var child in scenario.FirstAlgorithm.ChildAlgorithms) 152 stack.Push(new Entry() { TargetAlgorithm = exp, SourceAlgorithm = child}); 153 } 154 155 while (stack.Count > 0) { 156 var entry = stack.Pop(); 157 var algorithm = ConvertAlgorithmToJson(entry.SourceAlgorithm); 158 (entry.TargetAlgorithm["children"] as JArray).Add(algorithm); 159 160 if (entry.SourceAlgorithm.ChildAlgorithms.Count > 0) { 161 // push children 162 foreach (var child in entry.SourceAlgorithm.ChildAlgorithms) { 163 stack.Push(new Entry() { TargetAlgorithm = algorithm, SourceAlgorithm = child }); 164 } 165 } 166 167 } 168 return exp; 169 } 170 171 public static JObject ConvertAlgorithmToJson(Algorithm algorithm) { 172 var jalgo = new JObject(); 173 jalgo["title"] = algorithm.Name; 174 jalgo["nodeId"] = algorithm.Id; 175 var jalgoData = new JObject(); 176 jalgo["data"] = jalgoData; 177 jalgo["isExperiment"] = algorithm.IsExperiment; 178 jalgoData["AlgorithmParameters"] = ConvertParametersToJson(algorithm.Parameters.Items); 179 if (algorithm.Problem != null && algorithm.Problem.Parameters != null) 180 jalgoData["ProblemParameters"] = ConvertParametersToJson(algorithm.Problem.Parameters.Items); 181 182 jalgo["children"] = new JArray(); 183 return jalgo; 184 } 185 186 public static Experiment ConvertJsonToExperiment(string json) { 120 187 var experiment = new Experiment(); 121 188 var jsonExperiment = JObject.Parse(json); 122 experiment.Name = (string)jsonExperiment["name"]; 189 experiment.Name = (string)jsonExperiment["title"]; 190 experiment.Id = (string)jsonExperiment["nodeId"]; 123 191 var stack = new Stack<StackEntry>(); 124 192 var root = new Algorithm(); 125 193 126 if ( (bool)jsonExperiment["run"]) {194 if (jsonExperiment["run"] != null && (bool)jsonExperiment["run"]) { 127 195 experiment.JobDetails = new JobExecutionDetails() { 128 129 196 Group = (string)jsonExperiment["group"], 197 Repititions = (int)jsonExperiment["repititions"] 130 198 }; 131 199 } 132 200 133 foreach (var algo in jsonExperiment["algorithms"]["children"]) { 134 stack.Push(new StackEntry(){ Parent = root, Child = algo }); 135 } 201 // ignore experiment node, skip to its children 202 if (jsonExperiment["experiment"] != null) 203 foreach (var algo in jsonExperiment["experiment"]["children"]) { 204 stack.Push(new StackEntry() { Parent = root, Child = algo }); 205 } 206 207 if (jsonExperiment["children"] != null) 208 foreach (var algo in jsonExperiment["children"]) { 209 stack.Push(new StackEntry() { Parent = root, Child = algo }); 210 } 136 211 137 212 while (stack.Count > 0) { 138 213 var entry = stack.Pop(); 139 214 var data = entry.Child["data"]; 140 var currentAlgo = data == null ? new Algorithm() : ParseAlgorithm(entry.Child["data"]); 141 currentAlgo.Name = (string)entry.Child["name"]; 215 var currentAlgo = data == null || !data.HasValues ? new Algorithm() : ParseAlgorithm(entry.Child["data"]); 216 currentAlgo.Name = (string)entry.Child["title"]; 217 currentAlgo.Id = (string)entry.Child["nodeId"]; 218 currentAlgo.IsExperiment = (bool)entry.Child["isExperiment"]; 142 219 entry.Parent.ChildAlgorithms.Add(currentAlgo); 143 220 // push children on stack (inverse order to preserve ordering) 144 221 var cnt = entry.Child["children"].Count(); 145 for (var i =0; i < cnt; i++) {222 for (var i = 0; i < cnt; i++) { 146 223 stack.Push(new StackEntry() { Parent = currentAlgo, Child = entry.Child["children"][cnt - 1 - i] }); 147 224 } … … 154 231 return experiment; 155 232 } 233 #endregion 156 234 } 157 235 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/PlaceholderControllerService.cs
r9227 r9305 121 121 122 122 123 public boolSaveExperiment(User user, Experiment experiment) {123 public string SaveExperiment(User user, Experiment experiment) { 124 124 // make sure all algorithms store their choices aswell 125 125 var scenarioMap = new Dictionary<string, OptimizationScenario>(); … … 146 146 147 147 // finally store the experiment 148 var success= hiveManager.SaveExperiment(user, experiment);148 var id = hiveManager.SaveExperiment(user, experiment); 149 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);150 if (id != null && experiment.JobDetails != null) { 151 ScheduleExperiment(user, experiment.Id, experiment.JobDetails); 152 152 } 153 return success;153 return id; 154 154 } 155 155 156 156 157 public IEnumerable<string> GetExperiment s(User user) {158 return hiveManager.GetExperiment s(user);157 public IEnumerable<string> GetExperimentNames(User user) { 158 return hiveManager.GetExperimentNames(user); 159 159 } 160 160 … … 179 179 180 180 181 public bool ScheduleExperiment(User user, string experiment , JobExecutionDetails details) {182 var exp = hiveManager.GetExperimentBy Name(user, experiment);181 public bool ScheduleExperiment(User user, string experimentId, JobExecutionDetails details) { 182 var exp = hiveManager.GetExperimentById(user, experimentId); 183 183 return hiveManager.DispatchExperiment(user, exp, details); 184 } 185 186 187 public IEnumerable<Experiment> GetExperiments(User user) { 188 return hiveManager.GetExperiments(user); 189 } 190 191 public Experiment GetExperimentById(User u, string nodeId) { 192 return hiveManager.GetExperimentById(u, nodeId); 184 193 } 185 194 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/packages.config
r9062 r9305 1 1 <?xml version="1.0" encoding="utf-8"?> 2 <packages> 2 <packages> 3 3 <package id="Newtonsoft.Json" version="4.5.11" /> 4 4 </packages>
Note: See TracChangeset
for help on using the changeset viewer.