Ignore:
Timestamp:
09/21/18 16:00:50 (4 years ago)
Author:
jkarder
Message:

#2839:

  • fixed compilation errors in HiveEngine
  • minor changes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • addons/HeuristicLab.MetaOptimization/HeuristicLab.HiveEngine/3.3/HiveEngine.cs

    r14913 r16173  
    4545
    4646    [Storable]
    47     public string ResourceNames { get; set; }
     47    public Guid ProjectId { get; set; }
     48
     49    [Storable]
     50    public IEnumerable<Guid> ResourceIds { get; set; }
    4851
    4952    [Storable]
     
    9497    #region constructors and cloning
    9598    public HiveEngine() {
    96       this.ResourceNames = "HEAL";
     99      this.ProjectId = Guid.Empty;
     100      this.ResourceIds = new List<Guid>();
    97101      this.Priority = 0;
    98102      this.log = new ThreadSafeLog();
     
    103107    protected HiveEngine(HiveEngine original, Cloner cloner)
    104108      : base(original, cloner) {
    105       this.ResourceNames = original.ResourceNames;
     109      this.ProjectId = original.ProjectId;
     110      this.ResourceIds = original.ResourceIds.ToList();
    106111      this.currentOperator = cloner.Clone(original.currentOperator);
    107112      this.priority = original.priority;
     
    145150        firstRun = false;
    146151      }
     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.");
    147158
    148159      while (executionStack.Count > 0) {
     
    175186                }
    176187              }
    177             }
    178             catch {
     188            } catch {
    179189              executionStack.Push(coll); throw;
    180190            }
     
    187197          try {
    188198            next = operation.Operator.Execute((IExecutionContext)operation, cancellationToken);
    189           }
    190           catch (Exception ex) {
     199          } catch (Exception ex) {
    191200            executionStack.Push(operation);
    192201            if (ex is OperationCanceledException) throw ex;
     
    217226        }
    218227        return FindRandomParameter(ec.Parent);
    219       }
    220       catch { return null; }
     228      } catch { return null; }
    221229    }
    222230
     
    256264            random.Reset(random.Next());
    257265        }
     266
    258267        HiveClient.StartJob((e) => { log.LogException(e); }, refreshableJob, cancellationToken);
    259268
    260269        // do polling until experiment is finished and all jobs are downloaded
    261270        while (!refreshableJob.IsFinished()) {
     271          if (!refreshableJob.RefreshAutomatically && refreshableJob.Id != Guid.Empty)
     272            refreshableJob.RefreshAutomatically = true;
     273
    262274          Thread.Sleep(2000);
     275
    263276          this.ExecutionTimeOnHive = TimeSpan.FromMilliseconds(jobs.Sum(x => x.ExecutionTime.TotalMilliseconds));
    264277          cancellationToken.ThrowIfCancellationRequested();
    265278        }
     279
    266280        log.LogMessage(string.Format("{0} finished (TotalExecutionTime: {1}).", refreshableJob.ToString(), refreshableJob.ExecutionTime));
    267281
     
    277291          scopes[j++] = scope;
    278292        }
     293
    279294        return scopes;
    280       }
    281       catch (OperationCanceledException e) {
     295      } catch (OperationCanceledException e) {
    282296        throw e;
    283       }
    284       catch (Exception e) {
     297      } catch (Exception e) {
    285298        log.LogException(e);
    286299        throw e;
    287       }
    288       finally {
     300      } finally {
    289301        DisposeJob(refreshableJob);
    290302      }
     
    293305    private RefreshableJob CreateJob() {
    294306      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
    301319        jobs.Add(refreshableHiveExperiment);
     320
    302321        return refreshableHiveExperiment;
    303322      }
     
    319338    private void DeleteHiveExperiment(Guid jobId) {
    320339      HiveClient.TryAndRepeat(() => {
    321         HiveServiceLocator.Instance.CallHiveService(s => s.DeleteJob(jobId));
     340        HiveServiceLocator.Instance.CallHiveService(s => s.UpdateJobState(jobId, JobState.StatisticsPending));
    322341      }, 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       });
    338342    }
    339343  }
Note: See TracChangeset for help on using the changeset viewer.