Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/11/13 14:40:04 (12 years ago)
Author:
fschoepp
Message:

#1888:

  • Added an Update / GetExperiment... methods to the controller for updating and querying experiments.
  • The AlgorithmConverter class now properly converts from/to JSON format.
  • Integrated backbone js as MVC provider for JavaScript + jquery.
  • Added experiment.model.js + experiment.view.js + experiment.controller.js containing the MVC impl. for the Experiment pages.
  • Added new methods to the ExperimentController usable by the backbone js model implementation.
  • Added the experiment dialog from HL 3.3.7 (variate experiment parameters). It's capable of variating the algorithm parameters.
File:
1 edited

Legend:

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

    r9227 r9305  
    101101    }
    102102
    103     public ExperimentEntity(string user, string experimentName, string experimentUrl) {
     103    public ExperimentEntity(string user, string experimentName, string experimentId, string experimentUrl) {
    104104      PartitionKey = "ScenarioPartition";
    105105      RowKey = user + "_" + experimentName;     
    106106      User = user;
     107      ExperimentId = experimentId;
    107108      ExperimentJsonUrl = experimentUrl;
    108109    }
     110
     111    public string ExperimentId { get; set; }
    109112
    110113    public string User { get; set; }
     
    122125        return false;
    123126
    124       // TODO: Save the whole experiment, not just the algorithm names!!!
    125127      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER);
    126128      container.CreateIfNotExist();
    127129      // 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      var experimentJson = AlgorithmConverter.ConvertExperimentToJson(experiment);
    130131      Guid experimentJsonGuid = Guid.NewGuid();
    131132      var experimentJsonId = experiment.Name + "_" + experimentJsonGuid.ToString();
     133      experimentJson["nodeId"] = experimentJsonId.ToString();
    132134      var blob = container.GetBlobReference(experimentJsonId);     
    133       blob.UploadText(experimentJson);
     135      blob.UploadText(experimentJson.ToString());
     136      experiment.Id = experimentJsonId;
    134137
    135138      TableServiceContext serviceContext = TableClient.GetDataServiceContext();     
    136139      TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE);
    137       var entity = new ExperimentEntity(username, experiment.Name, blob.Uri.ToString());
     140      var entity = new ExperimentEntity(username, experiment.Name, experiment.Id, blob.Uri.ToString());
    138141      serviceContext.AddObject(AzureConstants.EXPERIMENT_TABLE, entity);
    139142      serviceContext.SaveChangesWithRetries();
     143      return true;
     144    }
     145
     146    public bool Update(string username, Experiment experiment) {
     147      TableServiceContext serviceContext = TableClient.GetDataServiceContext();
     148      TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE);
     149      var entity = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE)
     150                    where e.ExperimentId == experiment.Id
     151                    select e).FirstOrDefault();
     152      if (entity == null) {
     153        return false;
     154      }
     155
     156      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER);
     157      container.CreateIfNotExist();
     158      var blob = container.GetBlobReference(entity.ExperimentJsonUrl);
     159      var experimentJson = AlgorithmConverter.ConvertExperimentToJson(experiment).ToString();
     160      blob.UploadText(experimentJson);
    140161      return true;
    141162    }
     
    177198      container.CreateIfNotExist();
    178199      var blob = container.GetBlobReference(entity.ExperimentJsonUrl);
    179       return AlgorithmConverter.ConvertExperimentSimple(blob.DownloadText());
     200      return AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText());
    180201    }
    181202
     
    199220      foreach (var entity in entites) {
    200221        var blob = container.GetBlobReference(entity.ExperimentJsonUrl);
    201         experiments.Add(AlgorithmConverter.ConvertExperimentSimple(blob.DownloadText()));
     222        experiments.Add(AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText()));
    202223      }
    203224      return experiments;
     
    218239      container.CreateIfNotExist();
    219240      var blob = container.GetBlobReference(entity.ExperimentJsonUrl);
    220       var exp = AlgorithmConverter.ConvertExperimentSimple(blob.DownloadText());
     241      var exp = AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText());
    221242      return exp;
    222243    }
     244
     245
     246    public Experiment GetExperimentById(User user, string nodeId) {
     247      TableServiceContext serviceContext = TableClient.GetDataServiceContext();
     248      TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE);
     249      var entity = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE)
     250                    where e.ExperimentId == nodeId
     251                    select e).FirstOrDefault();
     252      if (entity == null || entity.ExperimentJsonUrl == null) {
     253        return null;
     254      }
     255
     256      if (entity.User != user.Username)
     257        return null;
     258
     259      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER);
     260      container.CreateIfNotExist();
     261      var blob = container.GetBlobReference(entity.ExperimentJsonUrl);
     262      return AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText());
     263    }
     264
    223265  }
    224266
Note: See TracChangeset for help on using the changeset viewer.