- Timestamp:
- 03/11/13 14:40:04 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Azure/DAL.cs
r9227 r9305 101 101 } 102 102 103 public ExperimentEntity(string user, string experimentName, string experiment Url) {103 public ExperimentEntity(string user, string experimentName, string experimentId, string experimentUrl) { 104 104 PartitionKey = "ScenarioPartition"; 105 105 RowKey = user + "_" + experimentName; 106 106 User = user; 107 ExperimentId = experimentId; 107 108 ExperimentJsonUrl = experimentUrl; 108 109 } 110 111 public string ExperimentId { get; set; } 109 112 110 113 public string User { get; set; } … … 122 125 return false; 123 126 124 // TODO: Save the whole experiment, not just the algorithm names!!!125 127 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 126 128 container.CreateIfNotExist(); 127 129 // 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); 130 131 Guid experimentJsonGuid = Guid.NewGuid(); 131 132 var experimentJsonId = experiment.Name + "_" + experimentJsonGuid.ToString(); 133 experimentJson["nodeId"] = experimentJsonId.ToString(); 132 134 var blob = container.GetBlobReference(experimentJsonId); 133 blob.UploadText(experimentJson); 135 blob.UploadText(experimentJson.ToString()); 136 experiment.Id = experimentJsonId; 134 137 135 138 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 136 139 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()); 138 141 serviceContext.AddObject(AzureConstants.EXPERIMENT_TABLE, entity); 139 142 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); 140 161 return true; 141 162 } … … 177 198 container.CreateIfNotExist(); 178 199 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 179 return AlgorithmConverter.Convert ExperimentSimple(blob.DownloadText());200 return AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText()); 180 201 } 181 202 … … 199 220 foreach (var entity in entites) { 200 221 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 201 experiments.Add(AlgorithmConverter.Convert ExperimentSimple(blob.DownloadText()));222 experiments.Add(AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText())); 202 223 } 203 224 return experiments; … … 218 239 container.CreateIfNotExist(); 219 240 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 220 var exp = AlgorithmConverter.Convert ExperimentSimple(blob.DownloadText());241 var exp = AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText()); 221 242 return exp; 222 243 } 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 223 265 } 224 266
Note: See TracChangeset
for help on using the changeset viewer.