- Timestamp:
- 09/21/18 16:00:50 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
addons/HeuristicLab.MetaOptimization/HeuristicLab.HiveEngine/3.3/HiveEngine.cs
r14913 r16173 45 45 46 46 [Storable] 47 public string ResourceNames { get; set; } 47 public Guid ProjectId { get; set; } 48 49 [Storable] 50 public IEnumerable<Guid> ResourceIds { get; set; } 48 51 49 52 [Storable] … … 94 97 #region constructors and cloning 95 98 public HiveEngine() { 96 this.ResourceNames = "HEAL"; 99 this.ProjectId = Guid.Empty; 100 this.ResourceIds = new List<Guid>(); 97 101 this.Priority = 0; 98 102 this.log = new ThreadSafeLog(); … … 103 107 protected HiveEngine(HiveEngine original, Cloner cloner) 104 108 : base(original, cloner) { 105 this.ResourceNames = original.ResourceNames; 109 this.ProjectId = original.ProjectId; 110 this.ResourceIds = original.ResourceIds.ToList(); 106 111 this.currentOperator = cloner.Clone(original.currentOperator); 107 112 this.priority = original.priority; … … 145 150 firstRun = false; 146 151 } 152 153 if (ProjectId == Guid.Empty) 154 throw new ArgumentException("Cannot run HiveEngine. No project has been specified."); 155 156 if (!ResourceIds.Any()) 157 throw new ArgumentException("Cannot run HiveEngine. No resources have been specified."); 147 158 148 159 while (executionStack.Count > 0) { … … 175 186 } 176 187 } 177 } 178 catch { 188 } catch { 179 189 executionStack.Push(coll); throw; 180 190 } … … 187 197 try { 188 198 next = operation.Operator.Execute((IExecutionContext)operation, cancellationToken); 189 } 190 catch (Exception ex) { 199 } catch (Exception ex) { 191 200 executionStack.Push(operation); 192 201 if (ex is OperationCanceledException) throw ex; … … 217 226 } 218 227 return FindRandomParameter(ec.Parent); 219 } 220 catch { return null; } 228 } catch { return null; } 221 229 } 222 230 … … 256 264 random.Reset(random.Next()); 257 265 } 266 258 267 HiveClient.StartJob((e) => { log.LogException(e); }, refreshableJob, cancellationToken); 259 268 260 269 // do polling until experiment is finished and all jobs are downloaded 261 270 while (!refreshableJob.IsFinished()) { 271 if (!refreshableJob.RefreshAutomatically && refreshableJob.Id != Guid.Empty) 272 refreshableJob.RefreshAutomatically = true; 273 262 274 Thread.Sleep(2000); 275 263 276 this.ExecutionTimeOnHive = TimeSpan.FromMilliseconds(jobs.Sum(x => x.ExecutionTime.TotalMilliseconds)); 264 277 cancellationToken.ThrowIfCancellationRequested(); 265 278 } 279 266 280 log.LogMessage(string.Format("{0} finished (TotalExecutionTime: {1}).", refreshableJob.ToString(), refreshableJob.ExecutionTime)); 267 281 … … 277 291 scopes[j++] = scope; 278 292 } 293 279 294 return scopes; 280 } 281 catch (OperationCanceledException e) { 295 } catch (OperationCanceledException e) { 282 296 throw e; 283 } 284 catch (Exception e) { 297 } catch (Exception e) { 285 298 log.LogException(e); 286 299 throw e; 287 } 288 finally { 300 } finally { 289 301 DisposeJob(refreshableJob); 290 302 } … … 293 305 private RefreshableJob CreateJob() { 294 306 lock (locker) { 295 var hiveExperiment = new Job(); 296 hiveExperiment.Name = "HiveEngine Run " + jobs.Count; 297 hiveExperiment.DateCreated = DateTime.Now; 298 hiveExperiment.ResourceNames = this.ResourceNames; 299 var refreshableHiveExperiment = new RefreshableJob(hiveExperiment); 300 refreshableHiveExperiment.IsDownloadable = false; // download happens automatically so disable button 307 var hiveExperiment = new Job { 308 Name = "HiveEngine Run " + jobs.Count, 309 DateCreated = DateTime.Now, 310 ProjectId = ProjectId, 311 ResourceIds = ResourceIds.ToList(), 312 }; 313 314 var refreshableHiveExperiment = new RefreshableJob(hiveExperiment) { 315 RefreshAutomatically = false, 316 IsDownloadable = false // download happens automatically later on so disable button 317 }; 318 301 319 jobs.Add(refreshableHiveExperiment); 320 302 321 return refreshableHiveExperiment; 303 322 } … … 319 338 private void DeleteHiveExperiment(Guid jobId) { 320 339 HiveClient.TryAndRepeat(() => { 321 HiveServiceLocator.Instance.CallHiveService(s => s. DeleteJob(jobId));340 HiveServiceLocator.Instance.CallHiveService(s => s.UpdateJobState(jobId, JobState.StatisticsPending)); 322 341 }, 5, string.Format("Could not delete jobs")); 323 }324 325 private List<Guid> GetResourceIds() {326 return HiveServiceLocator.Instance.CallHiveService(service => {327 var resourceNames = ResourceNames.Split(';');328 var resourceIds = new List<Guid>();329 foreach (var resourceName in resourceNames) {330 Guid resourceId = service.GetResourceId(resourceName);331 if (resourceId == Guid.Empty) {332 throw new ResourceNotFoundException(string.Format("Could not find the resource '{0}'", resourceName));333 }334 resourceIds.Add(resourceId);335 }336 return resourceIds;337 });338 342 } 339 343 }
Note: See TracChangeset
for help on using the changeset viewer.