- Timestamp:
- 04/24/13 13:40:43 (12 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.