- Timestamp:
- 02/11/13 10:15:52 (12 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Controller
- Files:
-
- 3 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Azure/DAL.cs
r9166 r9215 8 8 using Microsoft.WindowsAzure.ServiceRuntime; 9 9 using System.Diagnostics; 10 using HeuristicLab.Services.Optimization.ControllerService.Model; 10 11 11 12 namespace HeuristicLab.Services.Optimization.ControllerService.Azure { … … 13 14 public static readonly string SCENARIO_TABLE = "Scenario"; 14 15 public static readonly string SCENARIO_BLOB_CONTAINER = "scenario"; 16 public static readonly string EXPERIMENT_TABLE = "Experiment"; 15 17 public static readonly string CLOUD_SETTINGS_KEY = "Cloudia.WindowsAzure.Storage"; 16 18 } … … 91 93 } 92 94 95 internal sealed class ExperimentEntity : TableServiceEntity { 96 public ExperimentEntity() { 97 } 98 99 public ExperimentEntity(string user, Experiment experiment) { 100 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); 107 User = user; 108 } 109 110 public string User { get; set; } 111 112 public string Scenarios { get; set; } 113 114 } 115 116 public class ExperimentDao : IExperimentDao { 117 public CloudBlobClient BlobClient { get; set; } 118 public CloudTableClient TableClient { get; set; } 119 120 public bool Add(string username, Model.Experiment experiment) { 121 if (FindByName(username, experiment.Name) != null) 122 return false; 123 124 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 125 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 126 var entity = new ExperimentEntity(username, experiment); 127 serviceContext.AddObject(AzureConstants.EXPERIMENT_TABLE, entity); 128 serviceContext.SaveChangesWithRetries(); 129 return true; 130 } 131 132 public bool DeleteByName(string username, string experiment) { 133 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 134 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 135 var entity = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE) 136 where e.RowKey == (username + "_" + experiment) 137 select e).FirstOrDefault(); 138 139 if (entity == null) 140 return false; 141 142 serviceContext.DeleteObject(entity); 143 serviceContext.SaveChangesWithRetries(); 144 return true; 145 } 146 147 public Model.Experiment FindByName(string username, string experiment) { 148 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 149 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 150 var entity = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE) 151 where e.RowKey == (username + "_" + experiment) 152 select e).FirstOrDefault(); 153 154 if (entity == null) { 155 return null; 156 } 157 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 } 168 169 public IEnumerable<Model.Experiment> GetExperiments(string user) { 170 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 171 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 172 var entites = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE) 173 where e.User == user 174 select e).ToList(); 175 var experiments = new List<Experiment>(); 176 foreach (var entity in entites) { 177 experiments.Add(Convert(entity)); 178 } 179 return experiments; 180 } 181 } 182 93 183 public class AzureDataAccessLayer : IDataAccessLayer { 94 184 private IScenarioDao scenarioDao; 95 185 private IBlobDao blobDao; 186 private IExperimentDao expDao; 96 187 97 188 private CloudStorageAccount storageAccount; … … 115 206 get { 116 207 if (scenarioDao == null) { 117 scenarioDao = new ScenarioDao() ;208 scenarioDao = new ScenarioDao() { TableClient = StorageAccount.CreateCloudTableClient() }; 118 209 } 119 210 return scenarioDao; … … 124 215 get { 125 216 if (blobDao == null) { 126 blobDao = new BlobDao() ;217 blobDao = new BlobDao() { BlobClient = StorageAccount.CreateCloudBlobClient() }; 127 218 } 128 219 return blobDao; … … 130 221 } 131 222 132 public IScenarioDao CreateScenarioDao() { 133 return new ScenarioDao() { TableClient = StorageAccount.CreateCloudTableClient() }; 134 } 135 136 public IBlobDao CreateBlobDao() { 137 return new BlobDao() { BlobClient = StorageAccount.CreateCloudBlobClient() }; 223 public IExperimentDao ExperimentDao { 224 get { 225 if (expDao == null) { 226 expDao = new ExperimentDao() { TableClient = StorageAccount.CreateCloudTableClient() }; 227 } 228 return expDao; 229 } 138 230 } 139 231 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HiveScenarioManager.cs
r9166 r9215 52 52 } 53 53 54 public voidDispatchScenario(Model.User user, Model.OptimizationScenario scenario, JobExecutionDetails details) {54 public string DispatchScenario(Model.User user, Model.OptimizationScenario scenario, JobExecutionDetails details) { 55 55 // Experiment experiment = new Experiment(); 56 56 // var problem = new TravelingSalesmanProblem(); … … 66 66 br.Optimizer = algo; 67 67 br.Repetitions = details.Repititions; 68 SendExperimentToHive(user, br, details);68 return SendExperimentToHive(user, br, details); 69 69 } 70 70 else { 71 SendExperimentToHive(user, algo, details);71 return SendExperimentToHive(user, algo, details); 72 72 } 73 73 } … … 141 141 } 142 142 143 private voidSendExperimentToHive(Model.User user, IOptimizer exp, JobExecutionDetails details) {143 private string SendExperimentToHive(Model.User user, IOptimizer exp, JobExecutionDetails details) { 144 144 var job = new RefreshableJob(); 145 145 job.IsAllowedPrivileged = true; … … 156 156 Console.WriteLine(ex.StackTrace); 157 157 }, job, new CancellationToken()); 158 158 159 159 job.StopResultPolling(); 160 return job.Id != null ? job.Id.ToString() : null; 160 161 } 161 162 … … 168 169 foreach (var job in jobsLoaded) { 169 170 jobs.Add(ConvertJob(user, job)); 170 } 171 } 171 172 return jobs; 172 173 } … … 182 183 else 183 184 state = JobState.Waiting; 185 184 186 return new Model.Job() { Id = job.Id.ToString(), Name = job.Name, Resource = job.ResourceNames, State = state.Value, DateCreated = job.DateCreated }; 185 187 } … … 193 195 194 196 195 public voidDeleteJob(User user, string id) {197 public bool DeleteJob(User user, string id) { 196 198 ConfigureHive(user); 197 var guid = Guid.Parse(id); 198 HiveServiceLocator.Instance.CallHiveService(s => s.DeleteJob(guid)); 199 var guid = Guid.Parse(id); 200 HiveServiceLocator.Instance.CallHiveService(s => s.DeleteJob(guid)); 201 return true; 199 202 } 200 203 … … 344 347 345 348 // insert into table & blob store 346 var scenDao = dal. CreateScenarioDao();347 var blobDao = dal. CreateBlobDao();349 var scenDao = dal.ScenarioDao; 350 var blobDao = dal.BlobDao; 348 351 349 352 Guid scenarioXmlGuid = Guid.NewGuid(); … … 369 372 370 373 private string GetMapperFromBlobStore(string scenarioName) { 371 var scenarioDao = dal. CreateScenarioDao();372 var blobDao = dal. CreateBlobDao();374 var scenarioDao = dal.ScenarioDao; 375 var blobDao = dal.BlobDao; 373 376 var entity = scenarioDao.FindByName(scenarioName); 374 377 if (entity == null) … … 383 386 public bool DeleteScenario(User user, string scenarioName) { 384 387 // delete from table & blob store 385 var scenarioDao = dal. CreateScenarioDao();386 var blobDao = dal. CreateBlobDao();388 var scenarioDao = dal.ScenarioDao; 389 var blobDao = dal.BlobDao; 387 390 388 391 var entity = scenarioDao.FindByName(scenarioName); … … 395 398 return true; 396 399 } 400 401 public bool SaveExperiment(User user, Model.Experiment experiment) { 402 return dal.ExperimentDao.Add(user.Username, experiment); 403 } 404 405 public IEnumerable<string> GetExperiments(User user) { 406 return (from exp in dal.ExperimentDao.GetExperiments(user.Username) 407 select exp.Name); 408 } 409 410 411 public bool DeleteExperiment(User user, string experiment) { 412 return dal.ExperimentDao.DeleteByName(user.Username, experiment); 413 } 414 415 416 public Model.Task GetTaskData(User u, string jobId, string taskId) { 417 ConfigureHive(u); 418 TaskDownloader downloader = new TaskDownloader(new List<Guid>(){Guid.Parse(taskId)}); 419 downloader.StartAsync(); 420 while (!downloader.IsFinished) { 421 Thread.Sleep(250); 422 if (downloader.IsFaulted) { 423 throw downloader.Exception; 424 } 425 } 426 427 IDictionary<Guid, HiveTask> hiveTasks = downloader.Results; 428 var task = hiveTasks[Guid.Parse(taskId)]; 429 if (task == null) 430 return null; 431 432 return new Model.Task() { 433 State = new Model.TaskState() { 434 DateCreated = task.Task.DateCreated.ToString(), 435 DateFinished = task.Task.DateFinished.ToString(), 436 ExecutionTime = task.Task.ExecutionTime.ToString(), 437 State = task.Task.State.ToString() 438 }, 439 General = new Model.General() { 440 Id = task.Task.Id.ToString(), 441 LastChanged = task.Task.Modified.ToString(), 442 Name = task.ItemTask.Name 443 } 444 }; 445 } 446 447 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))); 450 451 var job = new Model.Job(); 452 job.Id = jobId; 453 var tasks = new Dictionary<Guid, Model.Task>(); 454 // push all elements to dictionary 455 foreach (var task in jobTasks) { 456 // 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)); 458 foreach (var child in children) { 459 tasks[child.Id] = new Model.Task() { 460 State = new Model.TaskState() { 461 DateCreated = child.DateCreated.ToString(), 462 DateFinished = child.DateFinished.ToString(), 463 ExecutionTime = child.ExecutionTime.ToString(), 464 State = child.State.ToString() 465 }, 466 General = new Model.General() { 467 Id = child.Id.ToString(), 468 LastChanged = child.Modified.ToString(), 469 Name = child.ItemName 470 } 471 }; 472 } 473 } 474 475 // traverse all tasks again and create tree of tasks 476 foreach (var task in jobTasks) { 477 if (task.ParentTaskId.HasValue) 478 tasks[task.Id].Children.Add(tasks[task.ParentTaskId.Value]); 479 else // its a root task 480 job.Tasks.Add(tasks[task.Id]); 481 } 482 483 return job; 484 } 397 485 } 398 486 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HeuristicLab.Services.Optimization.ControllerService.csproj
r9166 r9215 151 151 <Reference Include="Microsoft.WindowsAzure.ServiceRuntime, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> 152 152 <Reference Include="Microsoft.WindowsAzure.StorageClient, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> 153 <Reference Include="Newtonsoft.Json"> 154 <HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath> 155 </Reference> 153 156 <Reference Include="System" /> 154 157 <Reference Include="System.configuration" /> … … 175 178 <Compile Include="Mockup\MockupDAL.cs" /> 176 179 <Compile Include="Mockup\MockupScenarioManager.cs" /> 180 <Compile Include="Parsers\AlgorithmConverter.cs" /> 177 181 <Compile Include="PlaceholderControllerService.cs" /> 178 182 <Compile Include="Properties\AssemblyInfo.cs" /> 179 <Compile Include=" HL\ScenarioParser.cs" />183 <Compile Include="Parsers\ScenarioParser.cs" /> 180 184 <Compile Include="Utility.cs" /> 181 185 </ItemGroup> … … 186 190 <None Include="packages.config" /> 187 191 </ItemGroup> 188 <ItemGroup />189 192 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 190 193 <PropertyGroup> -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/DAL.cs
r9166 r9215 3 3 using System.Linq; 4 4 using System.Text; 5 using HeuristicLab.Services.Optimization.ControllerService.Model; 5 6 6 7 namespace HeuristicLab.Services.Optimization.ControllerService.Interfaces { … … 17 18 } 18 19 20 public interface IExperimentDao { 21 bool Add(string username, Experiment experiment); 22 bool DeleteByName(string username, string experiment); 23 Experiment FindByName(string username, string experiment); 24 IEnumerable<Experiment> GetExperiments(string user); 25 } 26 19 27 public interface IBlobDao { 20 28 bool Add(StringEntry entry); … … 24 32 25 33 public interface IDataAccessLayer { 26 IScenarioDao CreateScenarioDao(); 27 IBlobDao CreateBlobDao(); 34 IScenarioDao ScenarioDao { get; } 35 IBlobDao BlobDao { get; } 36 IExperimentDao ExperimentDao { get; } 28 37 } 29 38 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IControllerService.cs
r9166 r9215 20 20 21 21 [OperationContract] 22 voidScheduleOptimizationScenario(User user, OptimizationScenario scenario, JobExecutionDetails details);22 bool ScheduleOptimizationScenario(User user, OptimizationScenario scenario, JobExecutionDetails details); 23 23 24 24 [OperationContract] … … 29 29 30 30 [OperationContract] 31 voidDeleteJob(User user, string id);31 bool DeleteJob(User user, string id); 32 32 33 33 [OperationContract] … … 39 39 [OperationContract] 40 40 bool DeleteHiveScenario(User user, string scenarioName); 41 42 [OperationContract] 43 bool SaveExperiment(User user, Experiment experiment); 44 45 [OperationContract] 46 IEnumerable<string> GetExperiments(User user); 47 48 [OperationContract] 49 bool DeleteExperiment(User user, string experiment); 50 51 [OperationContract] 52 Job GetTasks(User u, string jobId); 53 54 [OperationContract] 55 Task GetTaskData(User u, string jobId, string taskId); 41 56 } 42 57 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IScenarioManager.cs
r9166 r9215 7 7 namespace HeuristicLab.Services.Optimization.ControllerService.Interfaces { 8 8 public interface IScenarioManager { 9 voidDispatchScenario(User user, OptimizationScenario scenario, JobExecutionDetails details);9 string DispatchScenario(User user, OptimizationScenario scenario, JobExecutionDetails details); 10 10 IList<Job> GetJobs(User user); 11 11 Job GetJob(User user, string id); 12 voidDeleteJob(User user, string id);12 bool DeleteJob(User user, string id); 13 13 IList<Model.Run> GetJobResults(User user, string id); 14 14 bool AddScenario(User user, string scenarioName, string scenarioXml, string scenarioMapper); 15 15 bool DeleteScenario(User user, string scenarioName); 16 17 bool SaveExperiment(User user, Experiment experiment); 18 IEnumerable<string> GetExperiments(User user); 19 bool DeleteExperiment(User user, string experiment); 20 21 Task GetTaskData(User u, string jobId, string taskId); 22 Job GetTasks(User u, string jobId); 16 23 } 17 24 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/Model/ControllerModel.cs
r9166 r9215 306 306 public class Experiment { 307 307 [DataMember] 308 public string Name { get; set; } 309 310 [DataMember] 308 311 public IList<OptimizationScenario> Scenarios { get; set; } 309 312 … … 340 343 341 344 [DataContract] 345 public class Property { 346 [DataMember] 347 public string Key { get; set; } 348 [DataMember] 349 public string Value { get; set; } 350 } 351 352 [DataContract] 353 public class General { 354 [DataMember] 355 public string Name { get { return GetValue("Name"); } set { SetValue("Name", value); } } 356 [DataMember] 357 public string Id { get { return GetValue("Id"); } set { SetValue("Id", value); } } 358 [DataMember] 359 public string Priority { get { return GetValue("Priority"); } set { SetValue("Priority", value); } } 360 [DataMember] 361 public string LastChanged { get { return GetValue("LastChanged"); } set { SetValue("LastChanged", value); } } 362 363 364 private IList<Property> properties = new List<Property>(); 365 [DataMember] 366 public IList<Property> Properties 367 { 368 get { 369 if (properties == null) 370 properties = new List<Property>(); 371 return properties; 372 } 373 set { properties = value;} 374 } 375 376 private string GetValue(string key) { 377 return (from p in Properties where p.Key == key select p.Value).FirstOrDefault(); 378 } 379 380 private void SetValue(string key, string value) { 381 var prop = (from p in Properties where p.Key == key select p).FirstOrDefault(); 382 if (prop == null) { 383 prop = new Property(); 384 Properties.Add(prop); 385 } 386 prop.Key = key; 387 prop.Value = value; 388 } 389 } 390 391 [DataContract] 392 public class TaskState { 393 [DataMember] 394 public string State { get; set; } 395 [DataMember] 396 public string ExecutionTime { get; set; } 397 [DataMember] 398 public string DateCreated { get; set; } 399 [DataMember] 400 public string DateFinished { get; set; } 401 } 402 403 [DataContract] 404 public class Task { 405 private General general = new General(); 406 [DataMember] 407 public General General { 408 get { return general; } 409 set { general = value; } 410 } 411 412 private IList<Task> tasks = new List<Task>(); 413 [DataMember] 414 public IList<Task> Children { 415 get { return tasks; } 416 set { tasks = value; } 417 } 418 419 private TaskState state = new TaskState(); 420 421 [DataMember] 422 public TaskState State { 423 get { return state; } 424 set { state = value; } 425 } 426 } 427 428 [DataContract] 342 429 public class Job { 343 430 [DataMember] … … 355 442 [DataMember] 356 443 public DateTime DateCreated { get; set; } 444 445 private IList<Task> tasks = new List<Task>(); 446 447 [DataMember] 448 public IList<Task> Tasks { 449 get { return tasks; } 450 set { tasks = value; } 451 } 452 357 453 } 358 454 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Mockup/MockupDAL.cs
r9166 r9215 246 246 } 247 247 248 public IScenarioDao CreateScenarioDao() { 249 return new ScenarioDao(); 250 } 251 252 public IBlobDao CreateBlobDao() { 253 return new BlobDao(); 254 } 248 private IExperimentDao experimentDao; 249 250 public IExperimentDao ExperimentDao { 251 get { 252 return null; 253 } 254 } 255 255 256 } 256 257 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Mockup/MockupScenarioManager.cs
r9166 r9215 131 131 } 132 132 133 public void DispatchScenario(Model.User user, Model.OptimizationScenario scenario, JobExecutionDetails details) { 134 // does nothign 133 public string DispatchScenario(Model.User user, Model.OptimizationScenario scenario, JobExecutionDetails details) { 134 // does nothing 135 return "guid"; 135 136 } 136 137 … … 144 145 145 146 146 public voidDeleteJob(User user, string id) {147 public bool DeleteJob(User user, string id) { 147 148 jobs.RemoveAll(j => j.Id == id); 149 return true; 148 150 } 149 151 … … 199 201 200 202 // insert into table & blob store 201 var scenDao = dal. CreateScenarioDao();202 var blobDao = dal. CreateBlobDao();203 var scenDao = dal.ScenarioDao; 204 var blobDao = dal.BlobDao; 203 205 204 206 Guid scenarioXmlGuid = Guid.NewGuid(); … … 225 227 public bool DeleteScenario(User user, string scenarioName) { 226 228 // delete from table & blob store 227 var scenarioDao = dal. CreateScenarioDao();228 var blobDao = dal. CreateBlobDao();229 var scenarioDao = dal.ScenarioDao; 230 var blobDao = dal.BlobDao; 229 231 230 232 var entity = scenarioDao.FindByName(scenarioName); … … 237 239 return true; 238 240 } 241 242 243 public bool SaveExperiment(User user, Model.Experiment experiment) { 244 throw new NotImplementedException(); 245 } 246 247 248 public IEnumerable<string> GetExperiments(User user) { 249 throw new NotImplementedException(); 250 } 251 252 253 public bool DeleteExperiment(User user, string experiment) { 254 throw new NotImplementedException(); 255 } 256 257 258 public Model.Task GetTaskData(User u, string jobId, string taskId) { 259 throw new NotImplementedException(); 260 } 261 262 public Model.Job GetTasks(User u, string jobId) { 263 throw new NotImplementedException(); 264 } 239 265 } 240 266 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/PlaceholderControllerService.cs
r9166 r9215 69 69 } 70 70 71 public voidScheduleOptimizationScenario(Model.User user, Model.OptimizationScenario scenario, JobExecutionDetails details) {71 public bool ScheduleOptimizationScenario(Model.User user, Model.OptimizationScenario scenario, JobExecutionDetails details) { 72 72 hiveManager.DispatchScenario(user, scenario, details); 73 return true; 73 74 } 74 75 … … 83 84 84 85 85 public voidDeleteJob(Model.User user, string id) {86 hiveManager.DeleteJob(user, id);86 public bool DeleteJob(Model.User user, string id) { 87 return hiveManager.DeleteJob(user, id); 87 88 } 88 89 … … 117 118 select e.Id).AsEnumerable(); 118 119 } 120 121 122 public bool SaveExperiment(User user, Experiment experiment) { 123 return hiveManager.SaveExperiment(user, experiment); 124 } 125 126 127 public IEnumerable<string> GetExperiments(User user) { 128 return hiveManager.GetExperiments(user); 129 } 130 131 132 public bool DeleteExperiment(User user, string experiment) { 133 return hiveManager.DeleteExperiment(user, experiment); 134 } 135 136 137 public Job GetTasks(User u, string jobId) { 138 return hiveManager.GetTasks(u, jobId); 139 } 140 141 public Task GetTaskData(User u, string jobId, string taskId) { 142 return hiveManager.GetTaskData(u, jobId, taskId); 143 } 119 144 } 120 145 }
Note: See TracChangeset
for help on using the changeset viewer.