Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/18 11:52:33 (6 years ago)
Author:
jzenisek
Message:

#2839: updated genealogy computation for hive job administrator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r15742 r15913  
    6767    }
    6868
     69    private Dictionary<Guid, HashSet<Guid>> projectAncestors;
     70    public Dictionary<Guid, HashSet<Guid>> ProjectAncestors {
     71      get { return projectAncestors; }
     72    }
     73
     74    private Dictionary<Guid, HashSet<Guid>> projectDescendants;
     75    public Dictionary<Guid, HashSet<Guid>> ProjectDescendants {
     76      get { return projectDescendants; }
     77    }
     78
     79    private Dictionary<Guid, HashSet<Guid>> resourceAncestors;
     80    public Dictionary<Guid, HashSet<Guid>> ResourceAncestors {
     81      get { return resourceAncestors; }
     82    }
     83
     84    private Dictionary<Guid, HashSet<Guid>> resourceDescendants;
     85    public Dictionary<Guid, HashSet<Guid>> ResourceDescendants {
     86      get { return resourceDescendants; }
     87    }
     88
    6989
    7090    private List<Plugin> onlinePlugins;
     
    107127        resources = new ItemList<Resource>();
    108128        jobs = new HiveItemCollection<RefreshableJob>();
     129
     130        projectAncestors = new Dictionary<Guid, HashSet<Guid>>();
     131        projectDescendants = new Dictionary<Guid, HashSet<Guid>>();
     132        resourceAncestors = new Dictionary<Guid, HashSet<Guid>>();
     133        resourceDescendants = new Dictionary<Guid, HashSet<Guid>>();
    109134
    110135        HiveServiceLocator.Instance.CallHiveService(service => {
     
    114139          service.GetJobs().ForEach(p => jobs.Add(new RefreshableJob(p)));
    115140        });
     141
     142        UpdateResourceGenealogy();
     143        UpdateProjectGenealogy();
    116144      }
    117145      catch {
     
    133161        resources = new ItemList<Resource>();
    134162
     163        projectAncestors = new Dictionary<Guid, HashSet<Guid>>();
     164        projectDescendants = new Dictionary<Guid, HashSet<Guid>>();
     165        resourceAncestors = new Dictionary<Guid, HashSet<Guid>>();
     166        resourceDescendants = new Dictionary<Guid, HashSet<Guid>>();
     167
    135168        HiveServiceLocator.Instance.CallHiveService(service => {
    136169          service.GetProjects().ForEach(p => projects.Add(p));
     
    138171          service.GetSlaves().ForEach(s => resources.Add(s));
    139172        });
     173
     174        UpdateResourceGenealogy();
     175        UpdateProjectGenealogy();
    140176      } catch {
    141177        projects = null;
     
    162198      }, null);
    163199    }
    164    
     200
     201    private void UpdateResourceGenealogy() {
     202      resourceAncestors.Clear();
     203      resourceDescendants.Clear();
     204
     205      // fetch resource ancestor set
     206      HiveServiceLocator.Instance.CallHiveService(service => {
     207        var ra = service.GetResourceGenealogy();
     208        ra.Keys.ToList().ForEach(k => resourceAncestors.Add(k, new HashSet<Guid>()));
     209        resourceAncestors.Keys.ToList().ForEach(k => resourceAncestors[k].UnionWith(ra[k]));
     210      });
     211
     212      // build resource descendant set
     213      resourceAncestors.Keys.ToList().ForEach(k => resourceDescendants.Add(k, new HashSet<Guid>()));
     214      foreach (var ra in resourceAncestors) {
     215        foreach(var ancestor in ra.Value) {
     216          resourceDescendants[ancestor].Add(ra.Key);
     217        }
     218      }
     219    }
     220
     221    private void UpdateProjectGenealogy() {
     222      projectAncestors.Clear();
     223      projectDescendants.Clear();
     224
     225      // fetch project ancestor list
     226      HiveServiceLocator.Instance.CallHiveService(service => {
     227        var pa = service.GetProjectGenealogy();
     228        pa.Keys.ToList().ForEach(k => projectAncestors.Add(k, new HashSet<Guid>()));
     229        projectAncestors.Keys.ToList().ForEach(k => projectAncestors[k].UnionWith(pa[k]));
     230      });
     231
     232      // build project descendant list
     233      projectAncestors.Keys.ToList().ForEach(k => projectDescendants.Add(k, new HashSet<Guid>()));
     234      foreach(var pa in projectAncestors) {
     235        foreach(var ancestor in pa.Value) {
     236          projectDescendants[ancestor].Add(pa.Key);
     237        }
     238      }
     239    }
     240
     241    public IEnumerable<Project> GetAvailableParentProjects(Guid id) {
     242      return projects.Where(x => projectAncestors[id].Contains(x.Id));
     243    }
     244
     245    public IEnumerable<Project> GetAvailableChildProjects(Guid id) {
     246      return projects.Where(x => projectDescendants[id].Contains(x.Id));
     247    }
     248
     249    public IEnumerable<Resource> GetAvailableParentResources(Guid id) {
     250      return resources.Where(x => resourceAncestors[id].Contains(x.Id));
     251    }
     252
     253    public IEnumerable<Resource> GetAvailableChildResources(Guid id) {
     254      return resources.Where(x => resourceDescendants[id].Contains(x.Id));
     255    }
     256
    165257    #endregion
    166258
     
    446538      }
    447539    }
    448 
    449 
    450     /// <summary>
    451     /// Uploads the given task and all its child-jobs while setting the proper parentJobId values for the childs
    452     /// </summary>
    453     /// <param name="parentHiveTask">shall be null if its the root task</param>
    454     //private void UploadTaskWithChildren_Old(IProgress progress, HiveTask hiveTask, HiveTask parentHiveTask, IEnumerable<Guid> groups, int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, CancellationToken cancellationToken) {
    455     //  taskUploadSemaphore.WaitOne();
    456     //  bool semaphoreReleased = false;
    457     //  try {
    458     //    cancellationToken.ThrowIfCancellationRequested();
    459     //    lock (jobCountLocker) {
    460     //      taskCount[0]++;
    461     //    }
    462     //    TaskData taskData;
    463     //    List<IPluginDescription> plugins;
    464 
    465     //    if (hiveTask.ItemTask.ComputeInParallel) {
    466     //      hiveTask.Task.IsParentTask = true;
    467     //      hiveTask.Task.FinishWhenChildJobsFinished = true;
    468     //      taskData = hiveTask.GetAsTaskData(true, out plugins);
    469     //    } else {
    470     //      hiveTask.Task.IsParentTask = false;
    471     //      hiveTask.Task.FinishWhenChildJobsFinished = false;
    472     //      taskData = hiveTask.GetAsTaskData(false, out plugins);
    473     //    }
    474     //    cancellationToken.ThrowIfCancellationRequested();
    475 
    476     //    TryAndRepeat(() => {
    477     //      if (!cancellationToken.IsCancellationRequested) {
    478     //        lock (pluginLocker) {
    479     //          HiveServiceLocator.Instance.CallHiveService((s) => hiveTask.Task.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, this.onlinePlugins, this.alreadyUploadedPlugins, plugins));
    480     //        }
    481     //      }
    482     //    }, Settings.Default.MaxRepeatServiceCalls, "Failed to upload plugins");
    483     //    cancellationToken.ThrowIfCancellationRequested();
    484     //    hiveTask.Task.PluginsNeededIds.Add(configPluginId);
    485     //    hiveTask.Task.JobId = jobId;
    486 
    487     //    log.LogMessage(string.Format("Uploading task ({0} kb, {1} objects)", taskData.Data.Count() / 1024, hiveTask.ItemTask.GetObjectGraphObjects().Count()));
    488     //    TryAndRepeat(() => {
    489     //      if (!cancellationToken.IsCancellationRequested) {
    490     //        if (parentHiveTask != null) {
    491     //          hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddChildTask(parentHiveTask.Task.Id, hiveTask.Task, taskData));
    492     //        } else {
    493     //          hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddTask(hiveTask.Task, taskData, groups.ToList()));
    494     //        }
    495     //      }
    496     //    }, Settings.Default.MaxRepeatServiceCalls, "Failed to add task", log);
    497     //    cancellationToken.ThrowIfCancellationRequested();
    498 
    499     //    lock (jobCountLocker) {
    500     //      progress.ProgressValue = (double)taskCount[0] / totalJobCount;
    501     //      progress.Status = string.Format("Uploaded task ({0} of {1})", taskCount[0], totalJobCount);
    502     //    }
    503 
    504     //    var tasks = new List<TS.Task>();
    505     //    foreach (HiveTask child in hiveTask.ChildHiveTasks) {
    506     //      var task = TS.Task.Factory.StartNew((tuple) => {
    507     //        var arguments = (Tuple<HiveTask, HiveTask>)tuple;
    508     //        UploadTaskWithChildren_Old(progress, arguments.Item1, arguments.Item2, groups, taskCount, totalJobCount, configPluginId, jobId, log, cancellationToken);
    509     //      }, new Tuple<HiveTask, HiveTask>(child, hiveTask));
    510     //      task.ContinueWith((x) => log.LogException(x.Exception), TaskContinuationOptions.OnlyOnFaulted);
    511     //      tasks.Add(task);
    512     //    }
    513     //    taskUploadSemaphore.Release(); semaphoreReleased = true; // the semaphore has to be release before waitall!
    514     //    TS.Task.WaitAll(tasks.ToArray());
    515     //  }
    516     //  finally {
    517     //    if (!semaphoreReleased) taskUploadSemaphore.Release();
    518     //  }
    519     //}
    520    
    521540    #endregion
    522541
Note: See TracChangeset for help on using the changeset viewer.