Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9227


Ignore:
Timestamp:
02/19/13 08:46:01 (11 years ago)
Author:
fschoepp
Message:

#1888:

  • Experiments will be saved as JSON elements within the blob store.
  • Added simple model and JSON converters.
  • Backend stores and runs experiments.
  • Updated interfaces to save/read experiments.
  • Added a binding to automatically map incoming JSON ajax requests to experiment models.
  • Added the javascript DatatypeMapper to map parameter inputs to the right html elements and vice versa.
  • Added smartwizard to generate Wizards for creating new experiments (New.cshtml).
Location:
branches/OaaS
Files:
15 added
17 edited

Legend:

Unmodified
Added
Removed
  • branches/OaaS/HeuristicLab.Clients.Hive/3.3/Util/PluginUtil.cs

    r7259 r9227  
    2727using System.ServiceModel;
    2828using HeuristicLab.PluginInfrastructure;
     29using System.Diagnostics;
    2930
    3031namespace HeuristicLab.Clients.Hive {
     
    103104          CollectPluginDependencies(plugins, plugin);
    104105        }
     106        else if (plugin == null && !type.FullName.StartsWith("System")) {
     107          Trace.WriteLine("No plugin available for: " + type.FullName);
     108        }
    105109      }
    106110    }
  • branches/OaaS/HeuristicLab.Services.Hive.WebRole/AzureLocalStorageTraceListener.cs

    r8235 r9227  
    66
    77namespace HeuristicLab.Services.Hive.WebRole {
    8   public class AzureLocalStorageTraceListener : XmlWriterTraceListener {
     8  /*public class AzureLocalStorageTraceListener : XmlWriterTraceListener {
    99    public AzureLocalStorageTraceListener()
    1010      : base(Path.Combine(AzureLocalStorageTraceListener.GetLogDirectory().Path, "HeuristicLab.Services.Hive.WebRole.svclog")) {
     
    1818      return directory;
    1919    }
    20   }
     20  }*/
    2121}
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/Azure/DAL.cs

    r9215 r9227  
    99using System.Diagnostics;
    1010using HeuristicLab.Services.Optimization.ControllerService.Model;
     11using HeuristicLab.Services.Optimization.ControllerService.Parsers;
    1112
    1213namespace HeuristicLab.Services.Optimization.ControllerService.Azure {
     
    1516    public static readonly string SCENARIO_BLOB_CONTAINER = "scenario";
    1617    public static readonly string EXPERIMENT_TABLE = "Experiment";
     18    public static readonly string EXPERIMENT_BLOB_CONTAINER = "experiment";
    1719    public static readonly string CLOUD_SETTINGS_KEY = "Cloudia.WindowsAzure.Storage";
     20
     21   
    1822  }
    1923
     
    97101    }
    98102
    99     public ExperimentEntity(string user, Experiment experiment) {
     103    public ExperimentEntity(string user, string experimentName, string experimentUrl) {
    100104      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);
     105      RowKey = user + "_" + experimentName;     
    107106      User = user;
     107      ExperimentJsonUrl = experimentUrl;
    108108    }
    109109
    110110    public string User { get; set; }
    111111
    112     public string Scenarios { get; set; }
     112    public string ExperimentJsonUrl { get; set; }
    113113
    114114  }
     
    122122        return false;
    123123
    124       TableServiceContext serviceContext = TableClient.GetDataServiceContext();
    125       TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE);
    126       var entity = new ExperimentEntity(username, experiment);
     124      // TODO: Save the whole experiment, not just the algorithm names!!!
     125      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER);
     126      container.CreateIfNotExist();
     127      // For now we store it as JSON element in the blob store
     128      // TODO: Make sure, that all required properties are part of the experiment!!
     129      var experimentJson = AlgorithmConverter.ConvertJson(experiment);
     130      Guid experimentJsonGuid = Guid.NewGuid();
     131      var experimentJsonId = experiment.Name + "_" + experimentJsonGuid.ToString();
     132      var blob = container.GetBlobReference(experimentJsonId);     
     133      blob.UploadText(experimentJson);
     134
     135      TableServiceContext serviceContext = TableClient.GetDataServiceContext();     
     136      TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE);
     137      var entity = new ExperimentEntity(username, experiment.Name, blob.Uri.ToString());
    127138      serviceContext.AddObject(AzureConstants.EXPERIMENT_TABLE, entity);
    128139      serviceContext.SaveChangesWithRetries();
     
    139150      if (entity == null)
    140151        return false;
     152
     153      if (entity.ExperimentJsonUrl != null) {
     154        CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER);
     155        container.CreateIfNotExist();
     156        var blob = container.GetBlobReference(entity.ExperimentJsonUrl);
     157        blob.DeleteIfExists();
     158      }
    141159
    142160      serviceContext.DeleteObject(entity);
     
    156174      }
    157175
    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     }
     176      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER);
     177      container.CreateIfNotExist();
     178      var blob = container.GetBlobReference(entity.ExperimentJsonUrl);
     179      return AlgorithmConverter.ConvertExperimentSimple(blob.DownloadText());
     180    }
     181
     182    //private Experiment Convert(ExperimentEntity entity, string entityJson) {
     183    //  // TODO: Read the whole experiment, not just the names!
     184    //  var exp = new Experiment() { Name = entity.RowKey.Split('_')[1] };
     185    //  foreach (var scenarioName in entity.Algorithms.Split(','))
     186    //    exp.Algorithm.Add(new Algorithm() { Name = scenarioName });
     187    //  return exp;
     188    //}
    168189
    169190    public IEnumerable<Model.Experiment> GetExperiments(string user) {
     
    174195                    select e).ToList();
    175196      var experiments = new List<Experiment>();
     197      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER);
     198      container.CreateIfNotExist();
    176199      foreach (var entity in entites) {
    177         experiments.Add(Convert(entity));
     200        var blob = container.GetBlobReference(entity.ExperimentJsonUrl);
     201        experiments.Add(AlgorithmConverter.ConvertExperimentSimple(blob.DownloadText()));
    178202      }
    179203      return experiments;
     204    }
     205
     206
     207    public Experiment GetExperimentByName(string username, string scenario) {
     208      TableServiceContext serviceContext = TableClient.GetDataServiceContext();
     209      TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE);
     210      var entity = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE)
     211                      where e.RowKey == username + "_" + scenario
     212                      select e).FirstOrDefault();
     213      if (entity == null || entity.ExperimentJsonUrl == null) {
     214        return null;
     215      }
     216
     217      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER);
     218      container.CreateIfNotExist();
     219      var blob = container.GetBlobReference(entity.ExperimentJsonUrl);
     220      var exp = AlgorithmConverter.ConvertExperimentSimple(blob.DownloadText());
     221      return exp;
    180222    }
    181223  }
     
    224266      get {
    225267        if (expDao == null) {
    226           expDao = new ExperimentDao() { TableClient = StorageAccount.CreateCloudTableClient() };
     268          expDao = new ExperimentDao() { TableClient = StorageAccount.CreateCloudTableClient(), BlobClient = StorageAccount.CreateCloudBlobClient() };
    227269        }
    228270        return expDao;
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HiveScenarioManager.cs

    r9215 r9227  
    5858      // algo.Problem = problem;     
    5959     
    60       IScenarioMapper mapper = GetMapper(scenario);
     60      IScenarioMapper mapper = GetMapper(scenario.Id);
    6161      IAlgorithm algo;
    6262      mapper.MapScenario(scenario, out algo);
    63       if (details.Repititions > 1) {
     63      /*if (details.Repititions > 1) {
    6464        BatchRun br = new BatchRun();
    6565        //br.Name = details.JobTitle;
     
    6969      }
    7070      else {       
    71         return SendExperimentToHive(user, algo, details);
    72       }
     71       
     72      }*/
     73      return SendExperimentToHive(user, algo, details);
     74    }
     75
     76    private sealed class StackEntry {
     77      public HeuristicLab.Optimization.Experiment Parent { get; set; }
     78      public IList<Model.Algorithm> Children { get; set; }
     79    }
     80
     81    public bool DispatchExperiment(User user, Model.Experiment exp, JobExecutionDetails details) {
     82      // TODO: Determine how to build a tree of IAlgorithm
     83      // For now the experiment will be flatened for execution
     84      HeuristicLab.Optimization.Experiment hiveExperiment = new HeuristicLab.Optimization.Experiment(exp.Name);
     85      var stack = new Stack<StackEntry>();
     86      var children = new List<Model.Algorithm>();
     87      foreach (var child in exp.Algorithm) {
     88        children.Add(child);       
     89      }
     90      stack.Push(new StackEntry() { Parent = hiveExperiment, Children = children });
     91
     92      while (stack.Count > 0) {
     93        var entry = stack.Pop();
     94        // handle current entry
     95
     96        // TODO: Store scenario name in entry.Child.Mapper when saving
     97        foreach (var child in entry.Children) {
     98          // This is a template experiment;
     99          if (child.Name == null) {
     100            var parent = new HeuristicLab.Optimization.Experiment(child.Name);
     101            entry.Parent.Optimizers.Add(parent);
     102            stack.Push(new StackEntry() { Parent = parent, Children = child.ChildAlgorithms });         
     103          }
     104          // This entity is mapable
     105          else {           
     106            IScenarioMapper mapper = GetMapper(child.Name);
     107            if (mapper == null) { // TODO: We should really be able to difference Experiment/Algorithm types; this is a workaround
     108              var parent = new HeuristicLab.Optimization.Experiment(child.Name);
     109              entry.Parent.Optimizers.Add(parent);
     110              stack.Push(new StackEntry() { Parent = parent, Children = child.ChildAlgorithms });         
     111            }
     112            else {
     113              var optScen = new OptimizationScenario() { Id = child.Name };
     114              optScen.Algorithm.Add(child);
     115              IAlgorithm algo;
     116              mapper.MapScenario(optScen, out algo);
     117              entry.Parent.Optimizers.Add(algo);
     118            }
     119          } 
     120        }
     121      }
     122      details.JobTitle = exp.Name;
     123      return SendExperimentToHive(user, hiveExperiment, details) != null;
    73124    }
    74125
     
    113164    }
    114165
    115     private IScenarioMapper GetMapper(Model.OptimizationScenario scenario) {
    116       var id = scenario.Id;
     166    private IScenarioMapper GetMapper(string scenarioId) {
     167      var id = scenarioId;
    117168      if (!mappers.ContainsKey(id)) {
    118169        lock (lockable) {
     
    121172         
    122173          var mapperString = GetMapperFromBlobStore(id);
     174          if (mapperString == null) return null;
    123175          var mapper = CompileMapper(mapperString);
    124176
     
    131183
    132184    private void MapExperiment(Model.OptimizationScenario scenario, out IAlgorithm algorithm) {     
    133       IScenarioMapper mapper = GetMapper(scenario);
     185      IScenarioMapper mapper = GetMapper(scenario.Id);
    134186      mapper.MapScenario(scenario, out algorithm);     
    135187    }
    136188
    137     private void ConfigureHive(Model.User user) {
    138       HiveServiceLocator.Instance.Username = user.Username;
    139       HiveServiceLocator.Instance.Password = user.Password;
    140       HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName;     
     189    private HiveServiceLocator ConfigureHive(Model.User user) {
     190      var serviceLocator = new HiveServiceLocator();
     191      serviceLocator.Username = user.Username;
     192      serviceLocator.Password = user.Password;
     193      serviceLocator.EndpointConfigurationName = Configuration.HiveEndpointName;
     194      return serviceLocator;
    141195    }
    142196
     
    146200      job.Job.Name = details.JobTitle;
    147201      job.Job.ResourceNames = details.Group;     
    148       job.RefreshAutomatically = false;     
     202      job.RefreshAutomatically = false;
     203     
     204      if (details.Repititions > 1) {
     205        BatchRun br = new BatchRun();
     206        br.Optimizer = exp;
     207        br.Repetitions = details.Repititions;
     208        exp = br;
     209      }
     210
    149211      if (exp.ExecutionState != ExecutionState.Prepared) {
    150212        exp.Prepare();
    151213      }     
    152214      job.HiveTasks.Add(new OptimizerHiveTask(exp));
    153       ConfigureHive(user);
    154      
     215      var service = ConfigureHive(user);
     216     
     217      // TODO: Fix HiveClient class to be not dependent on singleton HiveServiceLocator!!!
     218      HiveServiceLocator.Instance.Username = user.Username;
     219      HiveServiceLocator.Instance.Password = user.Password;
     220      HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName;
    155221      HiveClient.StartJob((ex) => {
    156222        Console.WriteLine(ex.StackTrace);
     
    163229
    164230    public IList<Model.Job> GetJobs(User user) {
    165       ConfigureHive(user);
    166       var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.Job>>(s => s.GetJobs());
     231      var serviceLocator = ConfigureHive(user);
     232      var jobsLoaded = serviceLocator.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.Job>>(s => s.GetJobs());
    167233      IList<Model.Job> jobs = new List<Model.Job>();
    168234
     
    189255
    190256    public Model.Job GetJob(User user, string id) {
    191       ConfigureHive(user);
     257      var serviceLocator = ConfigureHive(user);
    192258      var guid = Guid.Parse(id);
    193       return ConvertJob(user, HiveServiceLocator.Instance.CallHiveService<HeuristicLab.Clients.Hive.Job>(s => s.GetJob(guid)));
     259      return ConvertJob(user, serviceLocator.CallHiveService<HeuristicLab.Clients.Hive.Job>(s => s.GetJob(guid)));
    194260    }
    195261
    196262
    197263    public bool DeleteJob(User user, string id) {
    198       ConfigureHive(user);
     264      var serviceLocator = ConfigureHive(user);
    199265      var guid = Guid.Parse(id);     
    200       HiveServiceLocator.Instance.CallHiveService(s => s.DeleteJob(guid));
     266      serviceLocator.CallHiveService(s => s.DeleteJob(guid));
    201267      return true;
    202268    }
    203269
    204270    public IList<Model.Run> GetJobResults(User user, string id) {
    205       ConfigureHive(user);
     271      var serviceLocator = ConfigureHive(user);
    206272      var guid = Guid.Parse(id);
    207       var jobTasks = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(guid));
     273      var jobTasks = serviceLocator.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(guid));
    208274
    209275      IList<Guid> taskIds = new List<Guid>();
     
    211277        taskIds.Add(task.Id);
    212278      }
     279
     280      // TODO: Fix problems with the HiveServiceLocater singleton!!!
     281      HiveServiceLocator.Instance.Username = user.Username;
     282      HiveServiceLocator.Instance.Password = user.Password;
     283      HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName;
    213284      TaskDownloader downloader = new TaskDownloader(taskIds);
    214285      downloader.StartAsync();
     
    337408        result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.StringValue() { Name = name, Value = "Cannot be displayed as string" };
    338409      }
     410      // TODO: Add workaround for TSP
    339411      return result;
    340412    }
     
    416488    public Model.Task GetTaskData(User u, string jobId, string taskId) {
    417489      ConfigureHive(u);
     490      HiveServiceLocator.Instance.Username = u.Username;
     491      HiveServiceLocator.Instance.Password = u.Password;
     492      HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName;
    418493      TaskDownloader downloader = new TaskDownloader(new List<Guid>(){Guid.Parse(taskId)});
    419494      downloader.StartAsync();
     
    446521
    447522    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)));
     523      var serviceLocator = ConfigureHive(u);
     524      var jobTasks = serviceLocator.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(Guid.Parse(jobId)));
    450525     
    451526      var job = new Model.Job();
     
    455530      foreach (var task in jobTasks) {
    456531        // 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));
     532        var children = serviceLocator.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightChildTasks(Guid.Parse(jobId), true, true));
    458533        foreach (var child in children) {
    459534          tasks[child.Id] = new Model.Task() {
     
    483558      return job;
    484559    }
     560
     561
     562    public Model.Experiment GetExperimentByName(User user, string scenario) {
     563      return dal.ExperimentDao.GetExperimentByName(user.Username, scenario);
     564    }
     565
     566
     567
    485568  }
    486569}
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/HeuristicLab.Services.Optimization.ControllerService.csproj

    r9215 r9227  
    168168  <ItemGroup>
    169169    <Compile Include="Azure\DAL.cs" />
     170    <Compile Include="General\AlgorithmHelper.cs" />
    170171    <Compile Include="General\Configuration.cs" />
    171172    <Compile Include="HL\HiveMapper.cs" />
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/DAL.cs

    r9215 r9227  
    2323    Experiment FindByName(string username, string experiment);
    2424    IEnumerable<Experiment> GetExperiments(string user);
     25    Experiment GetExperimentByName(string username, string scenario);
    2526  }
    2627
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IControllerService.cs

    r9215 r9227  
    2121    [OperationContract]
    2222    bool ScheduleOptimizationScenario(User user, OptimizationScenario scenario, JobExecutionDetails details);
     23
     24    [OperationContract]
     25    bool ScheduleExperiment(User user, string experiment, JobExecutionDetails details);
    2326
    2427    [OperationContract]
     
    5457    [OperationContract]
    5558    Task GetTaskData(User u, string jobId, string taskId);
     59
     60    [OperationContract]
     61    Experiment GetExperimentByName(User user, string scenario);
    5662  }
    5763}
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IScenarioManager.cs

    r9215 r9227  
    2121    Task GetTaskData(User u, string jobId, string taskId);
    2222    Job GetTasks(User u, string jobId);
     23
     24    Experiment GetExperimentByName(User user, string scenario);
     25    bool DispatchExperiment(User user, Experiment exp, JobExecutionDetails details);
    2326  }
    2427}
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/Model/ControllerModel.cs

    r9215 r9227  
    274274  [DataContract]
    275275  public class Algorithm {
    276     public Algorithm() { Parameters = new AlgorithmParameters(); }
     276    public Algorithm() { Parameters = new AlgorithmParameters(); ChildAlgorithms = new List<Algorithm>(); }
    277277
    278278    [DataMember]
     
    290290    [DataMember]
    291291    public string Mapper { get; set; }
     292
     293    [DataMember]
     294    public string Name { get; set; }
    292295  }
    293296
     
    296299    [DataMember]
    297300    public string Id { get; set; }
    298    
     301
     302    public OptimizationScenario() { Algorithm = new List<Algorithm>(); }
     303
    299304    [DataMember]
    300305    public IList<Algorithm> Algorithm { get; set; }
     
    309314
    310315    [DataMember]
    311     public IList<OptimizationScenario> Scenarios { get; set; }
     316    public IList<Algorithm> Algorithm { get; set; }
    312317
    313318    public Experiment() {
    314       Scenarios = new List<OptimizationScenario>();
    315     }
     319      Algorithm = new List<Algorithm>();
     320    }
     321
     322    [DataMember]
     323    public JobExecutionDetails JobDetails { get; set; }
    316324  }
    317325
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/Mockup/MockupScenarioManager.cs

    r9215 r9227  
    263263      throw new NotImplementedException();
    264264    }
     265
     266
     267    public Model.Experiment GetExperimentByName(User user, string scenario) {
     268      throw new NotImplementedException();
     269    }
     270
     271
     272    public bool DispatchExperiment(User user, Model.Experiment exp, JobExecutionDetails details) {
     273      throw new NotImplementedException();
     274    }
    265275  }
    266276}
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/Parsers/AlgorithmConverter.cs

    r9215 r9227  
    55using HeuristicLab.Services.Optimization.ControllerService.Model;
    66using Newtonsoft.Json.Linq;
     7using Newtonsoft.Json;
    78
    89namespace HeuristicLab.Services.Optimization.ControllerService.Parsers {
     
    1011
    1112    public static Algorithm Convert(string json) {
     13      var o = JObject.Parse(json);
     14      return ParseAlgorithm(o);     
     15    }
     16
     17    private static Algorithm ParseAlgorithm(JToken obj) {
    1218      var algorithm = new Algorithm();
    13       var o = JObject.Parse(json);
    14       foreach (JProperty param in o["Algorithm Parameters"]) {
     19
     20      foreach (JProperty param in obj["Algorithm Parameters"]) {
    1521        Parameter parameter = CreateParameter(param);
    1622        algorithm.Parameters.Items.Add(parameter);
    1723      }
    1824
    19       var problemParams = o["Problem Parameters"];
    20       // TODO: Store problem parameters
     25      var problemParams = obj["Problem Parameters"];
    2126      if (problemParams != null) {
    2227        algorithm.Problem = new Problem();
     
    6974        case JTokenType.String:
    7075          return new Parameter() { Type = ParameterType.Type, Value = new TypeValue() { Name = property.Name, Value = (string)property.Value } };                 
     76        case JTokenType.Array:
     77          var arr = (JArray)token;
     78          // its a matrix
     79          if (arr[0].Type == JTokenType.Array) {
     80            return CreateMatrixParameter(property.Name, arr);
     81          }
     82          return CreateVectorParameter(property.Name, arr);
    7183        default:
    7284          throw new Exception("Unhandled datatype: " + property.Type);
    7385      }
    7486    }
     87
     88    private static Parameter CreateMatrixParameter(string name, JArray arr) {
     89      double[][] entries = new double[arr.Count][];
     90      for (int i = 0; i < entries.Length; i++) {
     91        entries[i] = (from d in arr[i] select (double)d).ToArray<double>(); 
     92      }
     93      return new Parameter { Type = ParameterType.DecimalMatrix, Value = new DecimalMatrix() { Name = name, Value = entries } };
     94    }
     95
     96    private static Parameter CreateVectorParameter(string name, JArray arr) {
     97      double[] entries = (from d in arr select (double)d).ToArray<double>();
     98      return new Parameter { Type = ParameterType.DecimalVector, Value = new DecimalVector() { Name = name, Value = entries } };
     99    }
     100
     101    public static string ConvertJson(Algorithm algorithm) {
     102      return JsonConvert.SerializeObject(algorithm);
     103    }
     104
     105   
     106    private class StackEntry {
     107      public Algorithm Parent { get; set; }
     108      public JToken Child { get; set; }
     109    }
     110
     111    public static Experiment ConvertExperimentSimple(string json) {
     112      return JsonConvert.DeserializeObject<Experiment>(json, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto });
     113    }
     114
     115    public static string ConvertJson(Experiment experiment) {
     116      return JsonConvert.SerializeObject(experiment, Formatting.None, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
     117    }
     118
     119    public static Experiment ConvertExperiment(string json) {
     120      var experiment = new Experiment();
     121      var jsonExperiment = JObject.Parse(json);
     122      experiment.Name = (string)jsonExperiment["name"];
     123      var stack = new Stack<StackEntry>();
     124      var root = new Algorithm();
     125
     126      if ((bool)jsonExperiment["run"]) {
     127        experiment.JobDetails = new JobExecutionDetails() {
     128           Group = (string)jsonExperiment["group"],
     129           Repititions = (int)jsonExperiment["repititions"]
     130        };
     131      }
     132
     133      foreach (var algo in jsonExperiment["algorithms"]["children"]) {
     134        stack.Push(new StackEntry(){ Parent = root, Child = algo });
     135      }
     136
     137      while (stack.Count > 0) {
     138        var entry = stack.Pop();
     139        var data = entry.Child["data"];
     140        var currentAlgo = data == null ? new Algorithm() : ParseAlgorithm(entry.Child["data"]);
     141        currentAlgo.Name = (string)entry.Child["name"];
     142        entry.Parent.ChildAlgorithms.Add(currentAlgo);
     143        // push children on stack (inverse order to preserve ordering)
     144        var cnt = entry.Child["children"].Count();
     145        for (var i=0; i < cnt; i++) {
     146          stack.Push(new StackEntry() { Parent = currentAlgo, Child = entry.Child["children"][cnt - 1 - i] });
     147        }
     148      }
     149
     150      foreach (var algo in root.ChildAlgorithms) {
     151        experiment.Algorithm.Add(algo);
     152      }
     153
     154      return experiment;
     155    }
    75156  }
    76157}
  • branches/OaaS/HeuristicLab.Services.Optimization.Controller/PlaceholderControllerService.cs

    r9215 r9227  
    66using HeuristicLab.Services.Optimization.ControllerService.Interfaces;
    77using HeuristicLab.Services.Optimization.ControllerService.Model;
     8using HeuristicLab.Services.Optimization.ControllerService.General;
    89
    910namespace HeuristicLab.Services.Optimization.ControllerService {
     
    120121
    121122
    122     public bool SaveExperiment(User user, Experiment experiment) {
    123       return hiveManager.SaveExperiment(user, experiment);
     123    public bool SaveExperiment(User user, Experiment experiment) {     
     124      // make sure all algorithms store their choices aswell
     125      var scenarioMap = new Dictionary<string, OptimizationScenario>();
     126      var algos = new Stack<Algorithm>();
     127      foreach (var algo in experiment.Algorithm) algos.Push(algo);
     128     
     129     
     130
     131      while (algos.Count > 0) {
     132        var algo = algos.Pop();
     133        if (algo.ChildAlgorithms != null)
     134          foreach (var child in algo.ChildAlgorithms) algos.Push(child);
     135
     136        if (AlgorithmHelper.HasToBeUpdated(algo)) {
     137          OptimizationScenario scenario;
     138          if (!scenarioMap.TryGetValue(algo.Name, out scenario)) {
     139            scenario = GetOptimizationScenarioByName(algo.Name);
     140            scenarioMap[algo.Name] = scenario;
     141          }
     142         
     143          AlgorithmHelper.Update(algo, scenario);
     144        }
     145      }
     146
     147      // finally store the experiment
     148      var success = hiveManager.SaveExperiment(user, experiment);
     149      // if it has been stored, and jobdetails are present, run the job!
     150      if (success && experiment.JobDetails != null) {
     151        return ScheduleExperiment(user, experiment.Name, experiment.JobDetails);
     152      }
     153      return success;
    124154    }
    125155
     
    142172      return hiveManager.GetTaskData(u, jobId, taskId);
    143173    }
     174
     175
     176    public Experiment GetExperimentByName(User user, string scenario) {
     177      return hiveManager.GetExperimentByName(user, scenario);
     178    }
     179
     180
     181    public bool ScheduleExperiment(User user, string experiment, JobExecutionDetails details) {
     182      var exp = hiveManager.GetExperimentByName(user, experiment);
     183      return hiveManager.DispatchExperiment(user, exp, details);
     184    }
    144185  }
    145186}
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/ExperimentController.cs

    r9215 r9227  
    88using HeuristicLab.Services.Optimization.ControllerService.Model;
    99using System.Web.Security;
     10using Mvc3TestApplication.Binders;
     11using HeuristicLab.Services.Optimization.ControllerService.Parsers;
    1012
    1113namespace HeuristicLab.Services.Optimization.Web.Controllers
     
    4143          foreach (var scenario in scenarios)
    4244            model.Scenarios.Add(scenario);
     45
     46          Session["experiment"] = new Experiment();
     47
    4348          return View(model);
    4449        }
     50
     51        public ActionResult New() {
     52          return Index();
     53        }
     54
     55        public Experiment Experiment { get { return Session["experiment"] as Experiment; } set { Session["experiment"] = value;} }
    4556
    4657        [HttpPost]
     
    6374            if (currentNode.title == "Experiment")
    6475              continue;
    65             experiment.Scenarios.Add(new OptimizationScenario() { Id = currentNode.title });
     76            experiment.Algorithm.Add(new Algorithm() { Name = currentNode.title });
    6677          }
    6778
     
    94105          return RedirectToAction("Edit");
    95106        }
     107
     108        [HttpPost]
     109        public JsonResult SaveExperiment([ExperimentJson] Experiment experiment) {
     110          return Json(
     111            new {
     112              Success = ControllerService.withControllerService<bool>(service => {
     113                User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
     114                return service.SaveExperiment(u, experiment);
     115              })
     116            });
     117        }
     118
     119        private JsonResult ComplexExperimentCase(string scenario) {
     120          // complex case, find children of experiment
     121          var model = new GetParametersModel() { Type = "Complex" };
     122          model.Subnames = new List<string>();
     123
     124          var experiment = ControllerService.withControllerService<Experiment>(service => {
     125            User user = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
     126            return service.GetExperimentByName(user, scenario);
     127          });
     128
     129          // TODO: Make a tree out of subnames!!
     130          if (experiment != null)
     131            foreach (var algo in experiment.Algorithm)
     132              model.Subnames.Add(algo.Name);
     133
     134          return Json(model, JsonRequestBehavior.AllowGet);
     135        }
     136
     137        [HttpGet]
     138        public JsonResult GetParameters(string scenario, string context, int index) {
     139          if (context == "Experiment" || context == null) {
     140            var optimizationScenario = ControllerService.withControllerService<OptimizationScenario>(service => {
     141              return service.GetOptimizationScenarioByName(scenario);
     142            });
     143
     144            if (optimizationScenario != null) {
     145              var model = new GetParametersModel() { Type = "Basic" };
     146              model.Algorithm = optimizationScenario.FirstAlgorithm;
     147              model.Algorithm.Mapper = optimizationScenario.Id;
     148              var json = Json(model, JsonRequestBehavior.AllowGet);
     149              return json;
     150            }
     151            else {
     152              // complex case, find children of experiment
     153              var model = new GetParametersModel() { Type = "Complex" };
     154              model.Subnames = new List<string>();
     155
     156              var experiment = ControllerService.withControllerService<Experiment>(service => {
     157                User user = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
     158                return service.GetExperimentByName(user, scenario);
     159              });
     160
     161              // TODO: Make a tree out of subnames!!
     162              if (experiment != null)
     163                foreach (var algo in experiment.Algorithm)
     164                  model.Subnames.Add(algo.Name);
     165
     166              return Json(model, JsonRequestBehavior.AllowGet);
     167            }
     168          }
     169          else {
     170            var experiment = ControllerService.withControllerService<Experiment>(service => {
     171              User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
     172              return service.GetExperimentByName(u, context);
     173            });
     174
     175            // if child algorithm is a complex algorithm, return as such
     176            if (experiment.Algorithm[index].ChildAlgorithms.Count > 0) {
     177              var model = new GetParametersModel() { Type = "Complex" };
     178              model.Subnames = new List<string>();
     179              foreach (var algo in experiment.Algorithm[index].ChildAlgorithms)
     180                model.Subnames.Add(algo.Name);
     181              return Json(model, JsonRequestBehavior.AllowGet);
     182            }
     183            else {
     184              // otherwise we have the algorithms just below it
     185              var model = new GetParametersModel() { Type = "Basic" };
     186              model.Algorithm = experiment.Algorithm[index];
     187              model.Algorithm.Mapper = experiment.Algorithm[index].Name;
     188              var json = Json(model, JsonRequestBehavior.AllowGet);
     189              return json;
     190            }
     191          }
     192        }
    96193    }
    97194}
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OptimizationController.cs

    r9215 r9227  
    5757
    5858        public ActionResult JobDetails(string jobId) {
    59           Job job = ControllerService.withControllerService<Job>((service) => {
     59          var model = ControllerService.withControllerService<JobDetailsModel>((service) => {
    6060            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
    61             return service.GetJob(u, jobId);
     61            var job = service.GetJob(u, jobId);
     62            var runs = service.GetJobResults(u, jobId);
     63            return new JobDetailsModel() { Job = job, Runs = runs };
    6264          });
    63           var runs = ControllerService.withControllerService<IList<Run>>((service) => {
    64             User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
    65             return service.GetJobResults(u, jobId);
    66           });
    67           JobDetailsModel jdm = new JobDetailsModel() { Job = job, Runs = runs };
    68           Session["jobDetails"] = jdm;
    69           return View(jdm);
    70         }
     65          Session["jobDetails"] = model;
     66          return View(model);
     67       }
    7168
    7269        [HttpPost]
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/HeuristicLab.Services.Optimization.Web.csproj

    r9215 r9227  
    9797  </ItemGroup>
    9898  <ItemGroup>
     99    <Content Include="Content\ajax-loader.gif" />
     100    <Content Include="Content\Datatypemapping.js" />
    99101    <Content Include="Content\dynatree\dist\jquery.dynatree.min.js" />
    100102    <Content Include="Content\dynatree\src\skin\icons-rtl.gif" />
     
    105107    <Content Include="Content\dynatree\src\skin\vline.gif" />
    106108    <Content Include="Content\ExperimentSupport.js" />
     109    <Compile Include="Binders\AlgorithmJsonAttribute.cs" />
    107110    <Compile Include="Controllers\AccountController.cs" />
    108111    <Compile Include="Controllers\AdminController.cs" />
     
    369372    </None>
    370373    <Content Include="Views\Status\Index.cshtml" />
     374    <Content Include="Views\Experiment\New.cshtml" />
    371375  </ItemGroup>
    372376  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/Models/ExperimentModel.cs

    r9215 r9227  
    33using System.Linq;
    44using System.Web;
     5using HeuristicLab.Services.Optimization.ControllerService.Model;
    56
    67namespace HeuristicLab.Services.Optimization.Web.Models {
     
    1617    public Node Experiment { get; set; }
    1718    public string Name { get; set; }
     19  }
     20
     21  public class GetParametersModel {
     22    public string Type { get; set; }
     23    public Algorithm Algorithm { get; set; }
     24    public IList<string> Subnames { get; set; }
    1825  }
    1926
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/Views/Shared/_Layout.cshtml

    r9215 r9227  
    3030    <script type="text/javascript" src="@Url.Content("~/Content/dynatree/dist/jquery.dynatree.min.js")"></script>
    3131    <script type="text/javascript" src="@Url.Content("~/Content/ExperimentSupport.js")"></script>
     32
     33    <!-- Experiment Additions -->
     34    <script src="@Url.Content("~/Content/Datatypemapping.js")" type="text/javascript"></script>
     35    <link href="@Url.Content("~/Content/smartwizard2.0/styles/smart_wizard.css")" rel="stylesheet" type="text/css" />
     36    <script type="text/javascript" src="@Url.Content("~/Content/smartwizard2.0/js/jquery.smartWizard-2.0.min.js")"></script>
    3237</head>
    3338<body>
Note: See TracChangeset for help on using the changeset viewer.