Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/24/13 13:40:43 (12 years ago)
Author:
fschoepp
Message:

#1888:

  • Added visual extensions (dynamic JavaScript) which will be used to render additional result parameters specific to scenarios (e. g. create a graphical representation of a TSP).
  • Added relationship between jobs and experiments (otherwise, it's not possible to get the job's experiment).
  • Updated Admin page to allow removal/addition of visual extensions.
  • Added back-end logic to store/retrieve/delete visual extensions.
  • Added visual extension functionality to the JavaScript views/controllers (job.*.js).
  • Added tsp.js which is a visual extension for the "Genetic Algorithm - TSP" scenario. It adds a graphical representation of the TSP (just like the C# version does) to the results.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/Azure/DAL.cs

    r9362 r9395  
    1818    public static readonly string EXPERIMENT_BLOB_CONTAINER = "experiment";
    1919    public static readonly string VISUAL_BLOB_CONTAINER = "visualextensions";
     20    public static readonly string JOB_TABLE = "Job";
    2021    public static readonly string CLOUD_SETTINGS_KEY = "Cloudia.WindowsAzure.Storage";
    2122
     
    311312
    312313    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      }
    317413    }
    318414  }
     
    323419    private IExperimentDao expDao;
    324420    private IVisualExtensionDao visualDao;
     421    private IJobDao jobDao;
    325422
    326423    private CloudStorageAccount storageAccount;
     
    377474      }
    378475    }
     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    }
    379486  }
    380487}
Note: See TracChangeset for help on using the changeset viewer.