- Timestamp:
- 04/24/13 13:40:43 (12 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Controller
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Azure/DAL.cs
r9362 r9395 18 18 public static readonly string EXPERIMENT_BLOB_CONTAINER = "experiment"; 19 19 public static readonly string VISUAL_BLOB_CONTAINER = "visualextensions"; 20 public static readonly string JOB_TABLE = "Job"; 20 21 public static readonly string CLOUD_SETTINGS_KEY = "Cloudia.WindowsAzure.Storage"; 21 22 … … 311 312 312 313 public string FindById(string algorithmId) { 313 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.VISUAL_BLOB_CONTAINER); 314 container.CreateIfNotExist(); 315 var blob = container.GetBlobReference(algorithmId); 316 return blob.DownloadText(); 314 try { 315 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.VISUAL_BLOB_CONTAINER); 316 container.CreateIfNotExist(); 317 var blob = container.GetBlobReference(algorithmId); 318 return blob.DownloadText(); 319 } 320 catch (Exception ex) { 321 Trace.TraceError(ex.ToString()); 322 return null; 323 } 324 } 325 326 327 public bool Exists(string algorithmId) { 328 try { 329 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.VISUAL_BLOB_CONTAINER); 330 container.CreateIfNotExist(); 331 var blob = container.GetBlobReference(algorithmId); 332 blob.FetchAttributes(); 333 return true; 334 } 335 catch (StorageClientException ex) { 336 if (ex.ErrorCode == StorageErrorCode.ResourceNotFound) { 337 return false; 338 } 339 Trace.TraceError(ex.ToString()); 340 return false; 341 } 342 } 343 } 344 345 internal sealed class JobEntity : TableServiceEntity { 346 public JobEntity() { 347 } 348 349 public JobEntity(string user, string experimentName, string experimentId, string jobId) { 350 PartitionKey = "JobPartition"; 351 RowKey = user + "_" + jobId; 352 User = user; 353 ExperimentId = experimentId; 354 JobId = jobId; 355 } 356 357 public string ExperimentId { get; set; } 358 359 public string User { get; set; } 360 361 public string JobId { get; set; } 362 } 363 364 public class JobDao : IJobDao { 365 public IExperimentDao ExperimentDao { get; set; } 366 public CloudTableClient TableClient { get; set; } 367 368 public bool Add(string username, Experiment experiment, string jobId) { 369 try { 370 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 371 TableClient.CreateTableIfNotExist(AzureConstants.JOB_TABLE); 372 serviceContext.AddObject(AzureConstants.JOB_TABLE, 373 new JobEntity(username, experiment.Name, experiment.Id, jobId) 374 ); 375 serviceContext.SaveChangesWithRetries(); 376 return true; 377 } 378 catch (Exception ex) { 379 Trace.TraceError(ex.ToString()); 380 return false; 381 } 382 } 383 384 public bool Delete(string username, string jobId) { 385 try { 386 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 387 TableClient.CreateTableIfNotExist(AzureConstants.JOB_TABLE); 388 var entity = (from e in serviceContext.CreateQuery<JobEntity>(AzureConstants.JOB_TABLE) 389 where e.JobId == jobId && e.User == username 390 select e).FirstOrDefault(); 391 serviceContext.DeleteObject(entity); 392 return true; 393 } 394 catch (Exception ex) { 395 Trace.TraceError(ex.ToString()); 396 return false; 397 } 398 } 399 400 public Experiment FindByJobId(string username, string jobId) { 401 try { 402 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 403 TableClient.CreateTableIfNotExist(AzureConstants.JOB_TABLE); 404 var entity = (from e in serviceContext.CreateQuery<JobEntity>(AzureConstants.JOB_TABLE) 405 where e.JobId == jobId && e.User == username 406 select e).FirstOrDefault(); 407 return ExperimentDao.GetExperimentById(new User() { Username = username }, entity.ExperimentId); 408 } 409 catch (Exception ex) { 410 Trace.TraceError(ex.ToString()); 411 return null; 412 } 317 413 } 318 414 } … … 323 419 private IExperimentDao expDao; 324 420 private IVisualExtensionDao visualDao; 421 private IJobDao jobDao; 325 422 326 423 private CloudStorageAccount storageAccount; … … 377 474 } 378 475 } 476 477 478 public IJobDao JobDao { 479 get { 480 if (jobDao == null) { 481 jobDao = new JobDao() { ExperimentDao = ExperimentDao, TableClient = StorageAccount.CreateCloudTableClient() }; 482 } 483 return jobDao; 484 } 485 } 379 486 } 380 487 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HiveScenarioManager.cs
r9365 r9395 110 110 IAlgorithm algo; 111 111 mapper.MapScenario(optScen, out algo); 112 algo.Name = child.Id; 112 113 entry.Parent.Optimizers.Add(algo); 113 114 } … … 115 116 } 116 117 details.JobTitle = exp.Name; 117 return SendExperimentToHive(user, hiveExperiment, details) != null; 118 var jobId = SendExperimentToHive(user, hiveExperiment, details); 119 120 // add relationship to azure tablestorage 121 if (jobId != null) { 122 dal.JobDao.Add(user.Username, exp, jobId); 123 } 124 return jobId != null; 118 125 } 119 126 … … 214 221 HiveServiceLocator.Instance.Password = user.Password; 215 222 HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName; 216 HiveClient.StartJob((ex) => { 217 Console.WriteLine(ex.StackTrace); 218 }, job, new CancellationToken()); 223 HiveClient.Store(job, new CancellationToken()); 219 224 220 225 job.StopResultPolling(); … … 286 291 } 287 292 } 293 //var experiment = dal.JobDao.FindByJobId(user.Username, id); 294 288 295 IDictionary<Guid, HiveTask> hiveTasks = downloader.Results; 289 296 IList<Model.Run> runs = new List<Model.Run>(); … … 294 301 Model.Run taskRun = new Model.Run(); 295 302 taskRun.Id = taskRun.Name = run.Name; 296 taskRun.AlgorithmName = run.Algorithm != null ? run.Algorithm.Name : run.Name; 303 // We try to extract the original algorithm name here 304 var index = taskRun.Name.LastIndexOf(" Run "); 305 var algorithName = taskRun.Name.Substring(0, index); 306 taskRun.AlgorithmName = algorithName; 307 if (taskRun.AlgorithmName == null) 308 taskRun.AlgorithmName = run.Algorithm != null ? run.Algorithm.Name : run.Name; 309 297 310 IList<Parameter> resultValues = new List<Model.Parameter>(); 298 311 foreach (var key in run.Results.Keys) { … … 617 630 return dal.VisualExtensionDao.FindById(algorithmId); 618 631 } 632 633 634 public bool AddVisualExtension(string algorithmId, string script) { 635 return dal.VisualExtensionDao.Add(algorithmId, script); 636 } 637 638 public bool DeleteVisualExtension(string algorithmId) { 639 return dal.VisualExtensionDao.DeleteById(algorithmId); 640 } 641 642 643 public bool ExistsVisualExtension(string algorithmId) { 644 return dal.VisualExtensionDao.Exists(algorithmId); 645 } 619 646 } 620 647 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/DAL.cs
r9362 r9395 30 30 } 31 31 32 public interface IJobDao { 33 bool Add(string username, Experiment experiment, string jobId); 34 bool Delete(string username, string jobId); 35 Experiment FindByJobId(string username, string jobId); 36 } 37 32 38 public interface IBlobDao { 33 39 bool Add(StringEntry entry); … … 41 47 bool DeleteById(string algorithmId); 42 48 string FindById(string algorithmId); 49 bool Exists(string algorithmId); 43 50 } 44 51 … … 48 55 IExperimentDao ExperimentDao { get; } 49 56 IVisualExtensionDao VisualExtensionDao { get; } 57 IJobDao JobDao { get; } 50 58 } 51 59 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IControllerService.cs
r9362 r9395 68 68 69 69 [OperationContract] 70 stringGetVisualExtension(string algorithmId);70 VisualExtension GetVisualExtension(string algorithmId); 71 71 72 72 [OperationContract] … … 75 75 [OperationContract] 76 76 bool DeleteVisualExtension(string algorithmId); 77 78 [OperationContract] 79 bool ExistsVisualExtension(string algorithmId); 77 80 } 78 81 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IScenarioManager.cs
r9362 r9395 30 30 31 31 string GetVisualExtension(string algorithmId); 32 33 bool AddVisualExtension(string algorithmId, string script); 34 35 bool DeleteVisualExtension(string algorithmId); 36 37 bool ExistsVisualExtension(string algorithmId); 32 38 } 33 39 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/Model/ControllerModel.cs
r9362 r9395 467 467 set { tasks = value; } 468 468 } 469 469 } 470 471 [DataContract] 472 public class VisualExtension { 473 [DataMember] 474 public string ScenarioId { get; set; } 475 476 [DataMember] 477 public string ScenarioJs { get; set; } 470 478 } 471 479 … … 484 492 public IList<Parameter> InputParameters { get; set; } 485 493 494 [DataMember] 486 495 public string AlgorithmName { get; set; } 487 496 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Mockup/MockupDAL.cs
r9362 r9395 258 258 get { throw new NotImplementedException(); } 259 259 } 260 261 262 public IJobDao JobDao { 263 get { throw new NotImplementedException(); } 264 } 260 265 } 261 266 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Mockup/MockupScenarioManager.cs
r9362 r9395 291 291 throw new NotImplementedException(); 292 292 } 293 294 295 public bool AddVisualExtension(string algorithmId, string script) { 296 throw new NotImplementedException(); 297 } 298 299 public bool DeleteVisualExtension(string algorithmId) { 300 throw new NotImplementedException(); 301 } 302 303 304 public bool ExistsVisualExtension(string algorithmId) { 305 throw new NotImplementedException(); 306 } 293 307 } 294 308 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Parsers/AlgorithmConverter.cs
r9362 r9395 190 190 jrun["results"] = ConvertParametersToJson(run.Results); 191 191 jrun["params"] = ConvertParametersToJson(run.InputParameters); 192 jrun["algorithmName"] = run.AlgorithmName; 192 jrun["algorithmName"] = run.AlgorithmName; 193 193 return jrun; 194 194 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/PlaceholderControllerService.cs
r9363 r9395 100 100 var added = hiveManager.AddScenario(user, scenario.Id, scenarioXml, scenarioMapper); 101 101 if (added) 102 scenarios.Add(scenario); 102 scenarios.Add(scenario); 103 103 return added; 104 104 } … … 192 192 193 193 194 public stringGetVisualExtension(string algorithmId) {195 return hiveManager.GetVisualExtension(algorithmId);194 public VisualExtension GetVisualExtension(string algorithmId) { 195 return new VisualExtension() { ScenarioId = algorithmId, ScenarioJs = hiveManager.GetVisualExtension(algorithmId) }; 196 196 } 197 197 198 198 199 199 public bool AddVisualExtension(string algorithmId, string script) { 200 //return hiveManager.AddVisualExtension(algorithmId, script); 201 return true; 200 return hiveManager.AddVisualExtension(algorithmId, script); 202 201 } 203 202 204 203 public bool DeleteVisualExtension(string algorithmId) { 205 //return hiveManager.DeleteVisualExtension(algorithmId); 206 return true; 204 return hiveManager.DeleteVisualExtension(algorithmId); 205 } 206 207 208 public bool ExistsVisualExtension(string algorithmId) { 209 return hiveManager.ExistsVisualExtension(algorithmId); 207 210 } 208 211 }
Note: See TracChangeset
for help on using the changeset viewer.