Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/12/11 18:04:25 (13 years ago)
Author:
ascheibe
Message:

#1233

  • fixed a bug in the Slave UI
  • finished renaming Webservice and Dao methods to be consistent with Job/Task naming
  • some cosmetic changes and project dependencies cleanups
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r6725 r6743  
    8686        var oldExperiments = jobs ?? new ItemCollection<RefreshableJob>();
    8787        jobs = new HiveItemCollection<RefreshableJob>();
    88         var experimentsLoaded = ServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetHiveExperiments());
     88        var experimentsLoaded = ServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs());
    8989
    9090        foreach (var he in experimentsLoaded) {
    91           var hiveExperiment = oldExperiments.SingleOrDefault(x => x.Id == he.Id);
    92           if (hiveExperiment == null) {
     91          var job = oldExperiments.SingleOrDefault(x => x.Id == he.Id);
     92          if (job == null) {
    9393            // new
    9494            jobs.Add(new RefreshableJob(he) { IsAllowedPrivileged = this.isAllowedPrivileged });
    9595          } else {
    9696            // update
    97             hiveExperiment.Job = he;
    98             hiveExperiment.IsAllowedPrivileged = this.isAllowedPrivileged;
    99             jobs.Add(hiveExperiment);
     97            job.Job = he;
     98            job.IsAllowedPrivileged = this.isAllowedPrivileged;
     99            jobs.Add(job);
    100100          }
    101101        }
     
    139139      if (item.Id == Guid.Empty) {
    140140        if (item is RefreshableJob) {
    141           HiveClient.Instance.UploadExperiment((RefreshableJob)item, cancellationToken);
     141          HiveClient.Instance.UploadJob((RefreshableJob)item, cancellationToken);
    142142        }
    143143        if (item is JobPermission) {
     
    151151      } else {
    152152        if (item is Job)
    153           ServiceLocator.Instance.CallHiveService(s => s.UpdateHiveExperiment((Job)item));
     153          ServiceLocator.Instance.CallHiveService(s => s.UpdateJob((Job)item));
    154154      }
    155155    }
     
    177177
    178178      if (item is Job)
    179         ServiceLocator.Instance.CallHiveService(s => s.DeleteHiveExperiment(item.Id));
     179        ServiceLocator.Instance.CallHiveService(s => s.DeleteJob(item.Id));
    180180      if (item is RefreshableJob)
    181         ServiceLocator.Instance.CallHiveService(s => s.DeleteHiveExperiment(item.Id));
     181        ServiceLocator.Instance.CallHiveService(s => s.DeleteJob(item.Id));
    182182      if (item is JobPermission) {
    183183        var hep = (JobPermission)item;
     
    206206    #endregion
    207207
    208     public static void StartExperiment(Action<Exception> exceptionCallback, RefreshableJob refreshableJob, CancellationToken cancellationToken) {
     208    public static void StartJob(Action<Exception> exceptionCallback, RefreshableJob refreshableJob, CancellationToken cancellationToken) {
    209209      HiveClient.StoreAsync(
    210210        new Action<Exception>((Exception ex) => {
     
    215215    }
    216216
    217     public static void PauseExperiment(RefreshableJob refreshableHiveExperiment) {
     217    public static void PauseJob(RefreshableJob refreshableJob) {
    218218      ServiceLocator.Instance.CallHiveService(service => {
    219         foreach (HiveTask job in refreshableHiveExperiment.GetAllHiveJobs()) {
    220           if (job.Task.State != TaskState.Finished && job.Task.State != TaskState.Aborted && job.Task.State != TaskState.Failed)
    221             service.PauseJob(job.Task.Id);
     219        foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) {
     220          if (task.Task.State != TaskState.Finished && task.Task.State != TaskState.Aborted && task.Task.State != TaskState.Failed)
     221            service.PauseTask(task.Task.Id);
    222222        }
    223223      });
    224       refreshableHiveExperiment.ExecutionState = ExecutionState.Paused;
    225     }
    226 
    227     public static void StopExperiment(RefreshableJob refreshableJob) {
     224      refreshableJob.ExecutionState = ExecutionState.Paused;
     225    }
     226
     227    public static void StopJob(RefreshableJob refreshableJob) {
    228228      ServiceLocator.Instance.CallHiveService(service => {
    229         foreach (HiveTask job in refreshableJob.GetAllHiveJobs()) {
    230           if (job.Task.State != TaskState.Finished && job.Task.State != TaskState.Aborted && job.Task.State != TaskState.Failed)
    231             service.StopJob(job.Task.Id);
     229        foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) {
     230          if (task.Task.State != TaskState.Finished && task.Task.State != TaskState.Aborted && task.Task.State != TaskState.Failed)
     231            service.StopTask(task.Task.Id);
    232232        }
    233233      });
     
    235235    }
    236236
    237     #region Upload Experiment
     237    #region Upload Job
    238238    private Semaphore jobUploadSemaphore = new Semaphore(4, 4); // todo: take magic number into config
    239239    private static object jobCountLocker = new object();
    240240    private static object pluginLocker = new object();
    241     private void UploadExperiment(RefreshableJob refreshableJob, CancellationToken cancellationToken) {
     241    private void UploadJob(RefreshableJob refreshableJob, CancellationToken cancellationToken) {
    242242      try {
    243243        refreshableJob.Progress = new Progress("Connecting to server...");
     
    254254        }
    255255
    256         foreach (OptimizerHiveTask hiveJob in refreshableJob.HiveJobs.OfType<OptimizerHiveTask>()) {
     256        foreach (OptimizerHiveTask hiveJob in refreshableJob.HiveTasks.OfType<OptimizerHiveTask>()) {
    257257          hiveJob.SetIndexInParentOptimizerList(null);
    258258        }
     
    260260        // upload Task
    261261        refreshableJob.Progress.Status = "Uploading Task...";
    262         refreshableJob.Job.Id = ServiceLocator.Instance.CallHiveService((s) => s.AddHiveExperiment(refreshableJob.Job));
     262        refreshableJob.Job.Id = ServiceLocator.Instance.CallHiveService((s) => s.AddJob(refreshableJob.Job));
    263263        bool isPrivileged = refreshableJob.Job.IsPrivileged;
    264         refreshableJob.Job = ServiceLocator.Instance.CallHiveService((s) => s.GetHiveExperiment(refreshableJob.Job.Id)); // update owner and permissions
     264        refreshableJob.Job = ServiceLocator.Instance.CallHiveService((s) => s.GetJob(refreshableJob.Job.Id)); // update owner and permissions
    265265        refreshableJob.Job.IsPrivileged = isPrivileged;
    266266        cancellationToken.ThrowIfCancellationRequested();
    267267
    268         int totalJobCount = refreshableJob.GetAllHiveJobs().Count();
     268        int totalJobCount = refreshableJob.GetAllHiveTasks().Count();
    269269        int[] jobCount = new int[1]; // use a reference type (int-array) instead of value type (int) in order to pass the value via a delegate to task-parallel-library
    270270        cancellationToken.ThrowIfCancellationRequested();
     
    284284
    285285        var tasks = new List<TS.Task>();
    286         foreach (HiveTask hiveJob in refreshableJob.HiveJobs) {
     286        foreach (HiveTask hiveJob in refreshableJob.HiveTasks) {
    287287          tasks.Add(TS.Task.Factory.StartNew((hj) => {
    288             UploadJobWithChildren(refreshableJob.Progress, (HiveTask)hj, null, resourceIds, jobCount, totalJobCount, configFilePlugin.Id, refreshableJob.Job.Id, refreshableJob.Log, refreshableJob.Job.IsPrivileged, cancellationToken);
     288            UploadTaskWithChildren(refreshableJob.Progress, (HiveTask)hj, null, resourceIds, jobCount, totalJobCount, configFilePlugin.Id, refreshableJob.Job.Id, refreshableJob.Log, refreshableJob.Job.IsPrivileged, cancellationToken);
    289289          }, hiveJob)
    290290          .ContinueWith((x) => refreshableJob.Log.LogException(x.Exception), TaskContinuationOptions.OnlyOnFaulted));
     
    334334    /// </summary>
    335335    /// <param name="parentHiveTask">shall be null if its the root task</param>
    336     private void UploadJobWithChildren(IProgress progress, HiveTask hiveJob, HiveTask parentHiveJob, IEnumerable<Guid> groups, int[] jobCount, int totalJobCount, Guid configPluginId, Guid hiveExperimentId, ILog log, bool isPrivileged, CancellationToken cancellationToken) {
     336    private void UploadTaskWithChildren(IProgress progress, HiveTask hiveTask, HiveTask parentHiveJob, IEnumerable<Guid> groups, int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, bool isPrivileged, CancellationToken cancellationToken) {
    337337      jobUploadSemaphore.WaitOne();
    338338      bool semaphoreReleased = false;
     
    340340        cancellationToken.ThrowIfCancellationRequested();
    341341        lock (jobCountLocker) {
    342           jobCount[0]++;
     342          taskCount[0]++;
    343343        }
    344344        TaskData jobData;
    345345        List<IPluginDescription> plugins;
    346346
    347         if (hiveJob.ItemTask.ComputeInParallel && (hiveJob.ItemTask.Item is Optimization.Experiment || hiveJob.ItemTask.Item is Optimization.BatchRun)) {
    348           hiveJob.Task.IsParentTask = true;
    349           hiveJob.Task.FinishWhenChildJobsFinished = true;
    350           jobData = hiveJob.GetAsTaskData(true, out plugins);
     347        if (hiveTask.ItemTask.ComputeInParallel && (hiveTask.ItemTask.Item is Optimization.Experiment || hiveTask.ItemTask.Item is Optimization.BatchRun)) {
     348          hiveTask.Task.IsParentTask = true;
     349          hiveTask.Task.FinishWhenChildJobsFinished = true;
     350          jobData = hiveTask.GetAsTaskData(true, out plugins);
    351351        } else {
    352           hiveJob.Task.IsParentTask = false;
    353           hiveJob.Task.FinishWhenChildJobsFinished = false;
    354           jobData = hiveJob.GetAsTaskData(false, out plugins);
     352          hiveTask.Task.IsParentTask = false;
     353          hiveTask.Task.FinishWhenChildJobsFinished = false;
     354          jobData = hiveTask.GetAsTaskData(false, out plugins);
    355355        }
    356356        cancellationToken.ThrowIfCancellationRequested();
     
    359359          if (!cancellationToken.IsCancellationRequested) {
    360360            lock (pluginLocker) {
    361               ServiceLocator.Instance.CallHiveService((s) => hiveJob.Task.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, this.onlinePlugins, this.alreadyUploadedPlugins, plugins));
     361              ServiceLocator.Instance.CallHiveService((s) => hiveTask.Task.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, this.onlinePlugins, this.alreadyUploadedPlugins, plugins));
    362362            }
    363363          }
    364364        }, -1, "Failed to upload plugins");
    365365        cancellationToken.ThrowIfCancellationRequested();
    366         hiveJob.Task.PluginsNeededIds.Add(configPluginId);
    367         hiveJob.Task.JobId = hiveExperimentId;
    368         hiveJob.Task.IsPrivileged = isPrivileged;
    369 
    370         log.LogMessage(string.Format("Uploading task ({0} kb, {1} objects)", jobData.Data.Count() / 1024, hiveJob.ItemTask.GetObjectGraphObjects().Count()));
     366        hiveTask.Task.PluginsNeededIds.Add(configPluginId);
     367        hiveTask.Task.JobId = jobId;
     368        hiveTask.Task.IsPrivileged = isPrivileged;
     369
     370        log.LogMessage(string.Format("Uploading task ({0} kb, {1} objects)", jobData.Data.Count() / 1024, hiveTask.ItemTask.GetObjectGraphObjects().Count()));
    371371        TryAndRepeat(() => {
    372372          if (!cancellationToken.IsCancellationRequested) {
    373373            if (parentHiveJob != null) {
    374               hiveJob.Task.Id = ServiceLocator.Instance.CallHiveService((s) => s.AddChildJob(parentHiveJob.Task.Id, hiveJob.Task, jobData));
     374              hiveTask.Task.Id = ServiceLocator.Instance.CallHiveService((s) => s.AddChildTask(parentHiveJob.Task.Id, hiveTask.Task, jobData));
    375375            } else {
    376               hiveJob.Task.Id = ServiceLocator.Instance.CallHiveService((s) => s.AddJob(hiveJob.Task, jobData, groups.ToList()));
     376              hiveTask.Task.Id = ServiceLocator.Instance.CallHiveService((s) => s.AddTask(hiveTask.Task, jobData, groups.ToList()));
    377377            }
    378378          }
     
    381381
    382382        lock (jobCountLocker) {
    383           progress.ProgressValue = (double)jobCount[0] / totalJobCount;
    384           progress.Status = string.Format("Uploaded task ({0} of {1})", jobCount[0], totalJobCount);
     383          progress.ProgressValue = (double)taskCount[0] / totalJobCount;
     384          progress.Status = string.Format("Uploaded task ({0} of {1})", taskCount[0], totalJobCount);
    385385        }
    386386
    387387        var tasks = new List<TS.Task>();
    388         foreach (HiveTask child in hiveJob.ChildHiveTasks) {
     388        foreach (HiveTask child in hiveTask.ChildHiveTasks) {
    389389          tasks.Add(TS.Task.Factory.StartNew((tuple) => {
    390390            var arguments = (Tuple<HiveTask, HiveTask>)tuple;
    391             UploadJobWithChildren(progress, arguments.Item1, arguments.Item2, groups, jobCount, totalJobCount, configPluginId, hiveExperimentId, log, isPrivileged, cancellationToken);
    392           }, new Tuple<HiveTask, HiveTask>(child, hiveJob))
     391            UploadTaskWithChildren(progress, arguments.Item1, arguments.Item2, groups, taskCount, totalJobCount, configPluginId, jobId, log, isPrivileged, cancellationToken);
     392          }, new Tuple<HiveTask, HiveTask>(child, hiveTask))
    393393          .ContinueWith((x) => log.LogException(x.Exception), TaskContinuationOptions.OnlyOnFaulted));
    394394        }
     
    408408
    409409    #region Download Experiment
    410     public static void LoadExperiment(RefreshableJob refreshableJob) {
     410    public static void LoadJob(RefreshableJob refreshableJob) {
    411411      var hiveExperiment = refreshableJob.Job;
    412412      refreshableJob.Progress = new Progress();
     
    415415        refreshableJob.IsProgressing = true;
    416416        int totalJobCount = 0;
    417         IEnumerable<LightweightTask> allJobs;
     417        IEnumerable<LightweightTask> allTasks;
    418418
    419419        refreshableJob.Progress.Status = "Connecting to Server...";
    420420        // fetch all Task objects to create the full tree of tree of HiveTask objects
    421421        refreshableJob.Progress.Status = "Downloading list of jobs...";
    422         allJobs = ServiceLocator.Instance.CallHiveService(s => s.GetLightweightExperimentJobs(hiveExperiment.Id));
    423         totalJobCount = allJobs.Count();
    424 
    425         TaskDownloader downloader = new TaskDownloader(allJobs.Select(x => x.Id));
     422        allTasks = ServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasks(hiveExperiment.Id));
     423        totalJobCount = allTasks.Count();
     424
     425        TaskDownloader downloader = new TaskDownloader(allTasks.Select(x => x.Id));
    426426        downloader.StartAsync();
    427427
     
    435435          }
    436436        }
    437         IDictionary<Guid, HiveTask> allHiveJobs = downloader.Results;
    438 
    439         refreshableJob.HiveJobs = new ItemCollection<HiveTask>(allHiveJobs.Values.Where(x => !x.Task.ParentTaskId.HasValue));
     437        IDictionary<Guid, HiveTask> allHiveTasks = downloader.Results;
     438
     439        refreshableJob.HiveTasks = new ItemCollection<HiveTask>(allHiveTasks.Values.Where(x => !x.Task.ParentTaskId.HasValue));
    440440
    441441        if (refreshableJob.IsFinished()) {
     
    446446
    447447        // build child-task tree
    448         foreach (HiveTask hiveJob in refreshableJob.HiveJobs) {
    449           BuildHiveJobTree(hiveJob, allJobs, allHiveJobs);
     448        foreach (HiveTask hiveTask in refreshableJob.HiveTasks) {
     449          BuildHiveJobTree(hiveTask, allTasks, allHiveTasks);
    450450        }
    451451
     
    482482
    483483    public static ItemTask LoadItemJob(Guid jobId) {
    484       TaskData jobData = ServiceLocator.Instance.CallHiveService(s => s.GetJobData(jobId));
     484      TaskData jobData = ServiceLocator.Instance.CallHiveService(s => s.GetTaskData(jobId));
    485485      try {
    486486        return PersistenceUtil.Deserialize<ItemTask>(jobData.Data);
     
    506506    }
    507507
    508     public static HiveItemCollection<JobPermission> GetHiveExperimentPermissions(Guid hiveExperimentId) {
     508    public static HiveItemCollection<JobPermission> GetJobPermissions(Guid jobId) {
    509509      return ServiceLocator.Instance.CallHiveService((service) => {
    510         IEnumerable<JobPermission> heps = service.GetHiveExperimentPermissions(hiveExperimentId);
    511         foreach (var hep in heps) {
     510        IEnumerable<JobPermission> jps = service.GetJobPermissions(jobId);
     511        foreach (var hep in jps) {
    512512          hep.GrantedUserName = service.GetUsernameByUserId(hep.GrantedUserId);
    513513        }
    514         return new HiveItemCollection<JobPermission>(heps);
     514        return new HiveItemCollection<JobPermission>(jps);
    515515      });
    516516    }
Note: See TracChangeset for help on using the changeset viewer.