Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/11/13 10:15:52 (12 years ago)
Author:
fschoepp
Message:

#1888:

  • Janitor is now working as expected in Windows Azure
  • Added basic support for experiments (draggable experiments)
  • Added methods to save/read experiments from TableStorage
  • The job status can now be retrieved by using the GetTasks/GetTaskData methods
  • Added a class to convert JSON-objects to Algorithm instances
  • Web page: Added experiment button to navigation
File:
1 edited

Legend:

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

    r9166 r9215  
    88using Microsoft.WindowsAzure.ServiceRuntime;
    99using System.Diagnostics;
     10using HeuristicLab.Services.Optimization.ControllerService.Model;
    1011
    1112namespace HeuristicLab.Services.Optimization.ControllerService.Azure {
     
    1314    public static readonly string SCENARIO_TABLE = "Scenario";
    1415    public static readonly string SCENARIO_BLOB_CONTAINER = "scenario";
     16    public static readonly string EXPERIMENT_TABLE = "Experiment";
    1517    public static readonly string CLOUD_SETTINGS_KEY = "Cloudia.WindowsAzure.Storage";
    1618  }
     
    9193  }
    9294
     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
    93183  public class AzureDataAccessLayer : IDataAccessLayer {
    94184    private IScenarioDao scenarioDao;
    95185    private IBlobDao blobDao;
     186    private IExperimentDao expDao;
    96187
    97188    private CloudStorageAccount storageAccount;
     
    115206      get {
    116207        if (scenarioDao == null) {
    117           scenarioDao = new ScenarioDao();
     208          scenarioDao = new ScenarioDao() { TableClient = StorageAccount.CreateCloudTableClient() };
    118209        }
    119210        return scenarioDao;
     
    124215      get {
    125216        if (blobDao == null) {
    126           blobDao = new BlobDao();
     217          blobDao = new BlobDao() { BlobClient = StorageAccount.CreateCloudBlobClient() };
    127218        }
    128219        return blobDao;
     
    130221    }
    131222
    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      }
    138230    }
    139231  }
Note: See TracChangeset for help on using the changeset viewer.