Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15913


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

#2839: updated genealogy computation for hive job administrator

Location:
branches/2839_HiveProjectManagement
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs

    r15658 r15913  
    4343    public const string additionalSlavesGroupDescription = "Contains additional slaves which are either ungrouped or the parenting slave group is not assigned to the selected project.";
    4444
     45    private const string CURRENT_SELECTION_TAG = " [current selection]";
     46    private const string NEW_SELECTION_TAG = " [new selection]";
     47    private const string CHANGED_SELECTION_TAG = " [changed selection]";
    4548
    4649    private readonly HashSet<TreeNode> mainTreeNodes = new HashSet<TreeNode>();
     
    5457    private readonly HashSet<Resource> newIncludedResources = new HashSet<Resource>();
    5558
    56     private readonly Dictionary<Guid, HashSet<Project>> projectAncestors = new Dictionary<Guid, HashSet<Project>>();
    57     private readonly Dictionary<Guid, HashSet<Project>> projectDescendants = new Dictionary<Guid, HashSet<Project>>();
    58     private readonly Dictionary<Guid, HashSet<Resource>> resourceAncestors = new Dictionary<Guid, HashSet<Resource>>();
    59     private readonly Dictionary<Guid, HashSet<Resource>> resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();
    60 
    6159    private IEnumerable<Resource> addedResources;
    6260    private IEnumerable<Resource> removedResources;
     
    6866    private readonly Color addedIncludeColor = Color.FromArgb(25, 169, 221, 221); // #a9dddd
    6967    private readonly Color removedIncludeColor = Color.FromArgb(25, 249, 210, 145); // #f9d291
    70     private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b
     68    private readonly Color selectedBackColor = Color.DodgerBlue;
     69    private readonly Color selectedForeColor = Color.White;
    7170
    7271    private string currentSearchString;
     
    173172      base.OnContentChanged();
    174173
    175       if (Content != null) {       
    176         UpdateProjectGenealogy();
    177         UpdateResourceGenealogy();
    178        
     174      if (Content != null) {               
    179175        if (SelectedProjectId.HasValue && SelectedProjectId.Value != Guid.Empty) {
    180176          SelectedProject = GetSelectedProjectById(SelectedProjectId.Value);
     
    218214        projectsTreeView.SelectedNode = null;
    219215      } else {
    220         ReColorTreeNodes(projectsTreeView.Nodes, selectedColor, Color.Transparent, true);
    221         e.Node.BackColor = selectedColor;
     216        ResetTreeNodes(projectsTreeView.Nodes);
     217        e.Node.BackColor = selectedBackColor;
     218        e.Node.ForeColor = selectedForeColor;
    222219       
    223220        if(node.Id == projectId) {
    224           e.Node.Text += " [current selection]";
     221          e.Node.Text += CURRENT_SELECTION_TAG;
    225222        } else if(projectId == null || projectId == Guid.Empty) {
    226           e.Node.Text += " [new selection]";
     223          e.Node.Text += NEW_SELECTION_TAG;
    227224        } else {
    228           e.Node.Text += " [changed selection]";
     225          e.Node.Text += CHANGED_SELECTION_TAG;
    229226        }
    230227
     
    270267
    271268    #region Helpers
    272 
    273 
    274     #region old
    275     private void UpdateMainTree() {
    276       mainTreeNodes.Clear();
    277 
    278       foreach (Project g in Content.OrderBy(x => x.Name)) {
    279         if (g.ParentProjectId == null) {
    280           TreeNode tn = new TreeNode();
    281           tn.ImageIndex = greenFlagImageIndex;
    282           tn.SelectedImageIndex = tn.ImageIndex;
    283 
    284           tn.Tag = g;
    285           tn.Text = g.Name;
    286           tn.Checked = assignedResources.Any(x => x.Id == g.Id);
    287 
    288           BuildMainTree(tn);
    289           mainTreeNodes.Add(tn);
    290         }
    291       }
    292       UpdateFilteredTree();
    293     }
    294 
    295     private void BuildMainTree(TreeNode tn) {
    296       foreach (Project r in Content.Where(s => s.ParentProjectId != null && s.ParentProjectId == ((Project)tn.Tag).Id).OrderBy(x => x.Name)) {
    297         TreeNode stn = new TreeNode(r.Name);
    298         stn.ImageIndex = redFlagImageIndex;
    299         stn.SelectedImageIndex = stn.ImageIndex;
    300         stn.Tag = r;
    301         stn.Checked = assignedResources.Any(x => x.Id == r.Id);
    302         tn.Nodes.Add(stn);
    303         mainTreeNodes.Add(stn);
    304 
    305         BuildMainTree(stn);
    306       }
    307     }
    308 
    309     private void UpdateFilteredTree() {
    310       filteredTreeNodes.Clear();
    311       foreach (TreeNode n in mainTreeNodes) {
    312         n.BackColor = SystemColors.Window;
    313         if (currentSearchString == null || ((Project)n.Tag).Name.ToLower().Contains(currentSearchString)) {
    314           n.BackColor = string.IsNullOrEmpty(currentSearchString) ? SystemColors.Window : Color.LightBlue;
    315           filteredTreeNodes.Add(n);
    316           TraverseParentNodes(n);
    317         }
    318       }
    319       UpdateProjectsTree();
    320     }
    321 
    322     private void UpdateProjectsTree() {
    323       projectsTreeView.Nodes.Clear();
    324       nodeStore.Clear();
    325 
    326       foreach (TreeNode node in filteredTreeNodes) {
    327         var clone = nodeStore.SingleOrDefault(x => ((Project)x.Tag).Id == ((Project)node.Tag).Id);
    328         if (clone == null) {
    329           clone = (TreeNode)node.Clone();
    330           nodeStore.Add(clone);
    331           clone.Nodes.Clear();
    332         }
    333         foreach (TreeNode child in node.Nodes)
    334           if (filteredTreeNodes.Any(x => ((Project)x.Tag).Id == ((Project)child.Tag).Id)) {
    335             var childClone = nodeStore.SingleOrDefault(x => ((Project)x.Tag).Id == ((Project)child.Tag).Id);
    336             if (childClone == null) {
    337               childClone = (TreeNode)child.Clone();
    338               nodeStore.Add(childClone);
    339               childClone.Nodes.Clear();
    340             }
    341             clone.Nodes.Add(childClone);
    342           }
    343       }
    344       projectsTreeView.Nodes.AddRange(nodeStore.Where(x => ((Project)x.Tag).ParentProjectId == null).ToArray());
    345       if (string.IsNullOrEmpty(currentSearchString)) ExpandSlaveGroupNodes();
    346       else projectsTreeView.ExpandAll();
    347     }
    348 
    349     private void TraverseParentNodes(TreeNode node) {
    350       if (node != null) {
    351         for (TreeNode parent = node.Parent; parent != null; parent = parent.Parent)
    352           filteredTreeNodes.Add(parent);
    353       }
    354     }
    355     #endregion
    356269
    357270    private Project GetSelectedProjectById(Guid projectId) {
     
    368281          if(project.Name.ToLower().Contains(currentSearchString.ToLower())) {
    369282            filteredProjects.Add(project);
    370             filteredProjects.UnionWith(projectAncestors[project.Id]);
     283            filteredProjects.UnionWith(Content.Where(p => HiveClient.Instance.ProjectAncestors[project.Id].Contains(p.Id)));
    371284          }
    372285        }
     
    379292      if (!projects.Any()) return;
    380293
    381       // select all top level projects (withouth parent, or without parent within current project collection)
     294      // select all top level projects (withouth parent, or without any ancestor within current project collection)
    382295      var mainProjects = new HashSet<Project>(projects.Where(x => x.ParentProjectId == null));
    383296      var parentedMainProjects = new HashSet<Project>(projects
    384297        .Where(x => x.ParentProjectId.HasValue
    385         && !projects.Select(y => y.Id).Contains(x.ParentProjectId.Value)));
     298        && !projects.Select(y => y.Id).Contains(x.ParentProjectId.Value)
     299        && !projects.SelectMany(y => HiveClient.Instance.ProjectAncestors[y.Id]).Contains(x.ParentProjectId.Value)));
    386300      mainProjects.UnionWith(parentedMainProjects);
    387301      var subProbjects = new HashSet<Project>(projects.Except(mainProjects));
     302      foreach(var p in subProbjects) {
     303        p.ParentProjectId = HiveClient.Instance.ProjectAncestors[p.Id].Where(x => projects.Select(y => y.Id).Contains(x)).FirstOrDefault();
     304      }
    388305
    389306      var stack = new Stack<Project>(mainProjects.OrderByDescending(x => x.Name));
     
    412329
    413330        if (SelectedProject != null && SelectedProject.Id.Equals(newProject.Id)) {
    414           newNode.BackColor = selectedColor;
     331          newNode.BackColor = selectedBackColor;
     332          newNode.ForeColor = selectedForeColor;
    415333          if(SelectedProject.Id == projectId) {
    416             newNode.Text += " [current selection]";
     334            newNode.Text += CURRENT_SELECTION_TAG;
    417335          } else if (projectId == null || projectId == Guid.Empty) {
    418             newNode.Text += " [new selection]";
     336            newNode.Text += NEW_SELECTION_TAG;
    419337          } else {
    420             newNode.Text += " [changed selection]";
     338            newNode.Text += CHANGED_SELECTION_TAG;
    421339          }
    422340        }
     
    439357      projectsTreeView.ExpandAll();
    440358    }
    441 
    442     private void UpdateProjectGenealogy() {
    443       projectAncestors.Clear();
    444       projectDescendants.Clear();
    445       var projects = Content;
    446 
    447       foreach (var p in projects) {
    448         projectAncestors.Add(p.Id, new HashSet<Project>());
    449         projectDescendants.Add(p.Id, new HashSet<Project>());
    450       }
    451 
    452       foreach (var p in projects) {
    453         var parentProjectId = p.ParentProjectId;
    454         while (parentProjectId != null) {
    455           var parent = projects.SingleOrDefault(x => x.Id == parentProjectId);
    456           if (parent != null) {
    457             projectAncestors[p.Id].Add(parent);
    458             projectDescendants[parent.Id].Add(p);
    459             parentProjectId = parent.ParentProjectId;
    460           } else {
    461             parentProjectId = null;
    462           }
    463         }
    464       }
    465     }
    466 
    467359
    468360    private static IEnumerable<Resource> GetAssignedResourcesForProject(Guid projectId) {
     
    495387        foreach (var resource in assignedProjectResources) {
    496388          availableResources.Add(resource);
    497           foreach(var descendant in resourceDescendants[resource.Id]) {
     389          foreach(var descendant in HiveClient.Instance.Resources.Where(x => HiveClient.Instance.ResourceDescendants[resource.Id].Contains(x.Id))) {
    498390            availableResources.Add(descendant);
    499391          }
     
    544436    private void UpdateNewAssignedResources() {
    545437      for(int i = newAssignedResources.Count-1; i>=0; i--) {
    546         if(newAssignedResources.Intersect(resourceAncestors[newAssignedResources.ElementAt(i).Id]).Any()) {
     438        if(newAssignedResources.Intersect(HiveClient.Instance.GetAvailableParentResources(newAssignedResources.ElementAt(i).Id)).Any()) {
    547439          newAssignedResources.Remove(newAssignedResources.ElementAt(i));
    548440        }
     
    556448      if (JobId != Guid.Empty) {
    557449        foreach (var item in assignedResources) {
    558           foreach (var descendant in resourceDescendants[item.Id]) {
     450          foreach (var descendant in HiveClient.Instance.GetAvailableChildResources(item.Id)) {
    559451            includedResources.Add(descendant);
    560452          }
     
    563455
    564456      foreach (var item in newAssignedResources) {
    565         foreach (var descendant in resourceDescendants[item.Id]) {
     457        foreach (var descendant in HiveClient.Instance.GetAvailableChildResources(item.Id)) {
    566458          newIncludedResources.Add(descendant);
    567459        }
     
    572464      newIncludedResources.Clear();
    573465      foreach (var item in newAssignedResources) {
    574         foreach (var descendant in resourceDescendants[item.Id]) {
     466        foreach (var descendant in HiveClient.Instance.GetAvailableChildResources(item.Id)) {
    575467          newIncludedResources.Add(descendant);
    576         }
    577       }
    578     }
    579 
    580     private void UpdateResourceGenealogy() {
    581       resourceAncestors.Clear();
    582       resourceDescendants.Clear();
    583       var resources = HiveClient.Instance.Resources;
    584 
    585       foreach (var r in resources) {
    586         resourceAncestors.Add(r.Id, new HashSet<Resource>());
    587         resourceDescendants.Add(r.Id, new HashSet<Resource>());
    588       }
    589 
    590       foreach (var r in resources) {
    591         var parentResourceId = r.ParentResourceId;
    592         while (parentResourceId != null) {
    593           var parent = resources.SingleOrDefault(x => x.Id == parentResourceId);
    594           if (parent != null) {
    595             resourceAncestors[r.Id].Add(parent);
    596             resourceDescendants[parent.Id].Add(r);
    597             parentResourceId = parent.ParentResourceId;
    598           } else {
    599             parentResourceId = null;
    600           }
    601468        }
    602469      }
     
    743610      HashSet<Slave> newAssignedSlaves = new HashSet<Slave>(newAssignedResources.OfType<Slave>());
    744611      foreach (var slaveGroup in newAssignedResources.OfType<SlaveGroup>()) {
    745         foreach(var slave in resourceDescendants[slaveGroup.Id].OfType<Slave>()) {
     612        foreach(var slave in HiveClient.Instance.ResourceDescendants[slaveGroup.Id].OfType<Slave>()) {
    746613          newAssignedSlaves.Add(slave);
    747614        }
     
    753620        var slaveGroup = resource as SlaveGroup;
    754621        if (slaveGroup != null) {
    755           selectedSlaves = new HashSet<Slave>(resourceDescendants[slaveGroup.Id].OfType<Slave>());
     622          selectedSlaves = new HashSet<Slave>(HiveClient.Instance.ResourceDescendants[slaveGroup.Id].OfType<Slave>());
    756623          //selectedSlaves.IntersectWith(newAssignedSlaves);
    757624        } else {
     
    771638    }
    772639
    773     private void ReColorTreeNodes(TreeNodeCollection nodes, Color c1, Color c2, bool resetText) {
     640    private void StyleTreeNode(TreeNode n, string name) {
     641      n.Text = name;
     642      n.BackColor = Color.Transparent;
     643      n.ForeColor = Color.Black;
     644    }
     645
     646    private void ResetTreeNodes(TreeNodeCollection nodes) {
    774647      foreach (TreeNode n in nodes) {
    775         if (n.BackColor.Equals(c1)) {
    776           n.BackColor = c2;
    777           if(resetText) n.Text = ((Project)n.Tag).Name;
    778         }
     648        string name = "";
     649        if (n.Tag is Project) name = ((Project)n.Tag).Name;
     650        else if (n.Tag is Resource) name = ((Resource)n.Tag).Name;
     651        StyleTreeNode(n, name);
    779652        if (n.Nodes.Count > 0) {
    780           ReColorTreeNodes(n.Nodes, c1, c2, resetText);
     653          ResetTreeNodes(n.Nodes);
    781654        }
    782655      }
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelectorDialog.cs

    r15658 r15913  
    161161      hiveResourceSelector.SelectedProjectId = selectedProjectId;
    162162      hiveResourceSelector.SelectedResourceIds = selectedResourceIds;
    163       var projectList = new ItemList<Project>(HiveServiceLocator.Instance.CallHiveService(s => s.GetProjects()));
    164       hiveResourceSelector.Content = projectList;
     163      hiveResourceSelector.Content = HiveClient.Instance.Projects;
    165164    }
    166165
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r15642 r15913  
    482482    }
    483483
    484     //private void updateButton_Click(object sender, EventArgs e) {
    485     //  var task = System.Threading.Tasks.Task.Factory.StartNew(UpdateJobAsync, Content);
    486     //  task.ContinueWith((t) => {
    487     //    Content.Progress.Finish();
    488     //    MessageBox.Show("An error occured updating the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
    489     //    Content.Log.LogException(t.Exception);
    490     //  }, TaskContinuationOptions.OnlyOnFaulted);
    491     //}
    492 
    493     //private void UpdateJobAsync(object job) {
    494     //  Content.Progress.Start("Updating job...");
    495     //  HiveClient.UpdateJob((RefreshableJob)job);
    496     //  Content.Progress.Finish();
    497     //}
    498 
    499484    private void UnloadButton_Click(object sender, EventArgs e) {
    500485      Content.Unload();
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/HiveTaskView.cs

    r14185 r15913  
    211211      }
    212212    }
     213
     214    private void coresNeededComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     215      if (int.TryParse(coresNeededComboBox.SelectedItem.ToString(), out int cores))
     216        Content.Task.CoresNeeded = cores;
     217    }
    213218  }
    214219}
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/HiveTaskView.designer.cs

    r14185 r15913  
    292292            "2",
    293293            "3",
    294             "4"});
     294            "4",
     295            "6",
     296            "8",
     297            "10",
     298            "12"});
    295299      this.coresNeededComboBox.Location = new System.Drawing.Point(134, 13);
    296300      this.coresNeededComboBox.Name = "coresNeededComboBox";
    297301      this.coresNeededComboBox.Size = new System.Drawing.Size(134, 21);
    298302      this.coresNeededComboBox.TabIndex = 41;
     303      this.coresNeededComboBox.SelectedIndexChanged += new System.EventHandler(this.coresNeededComboBox_SelectedIndexChanged);
    299304      //
    300305      // memoryNeededLabel
  • 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
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveServiceClient.cs

    r15819 r15913  
    24492449        System.Collections.Generic.List<HeuristicLab.Clients.Hive.Project> GetProjectsForAdministration();
    24502450       
     2451        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetProjectGenealogy", ReplyAction="http://tempuri.org/IHiveService/GetProjectGenealogyResponse")]
     2452        System.Collections.Generic.Dictionary<System.Guid, System.Collections.Generic.List<System.Guid>> GetProjectGenealogy();
     2453       
    24512454        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/SaveProjectPermissions", ReplyAction="http://tempuri.org/IHiveService/SaveProjectPermissionsResponse")]
    24522455        void SaveProjectPermissions(System.Guid projectId, System.Collections.Generic.List<System.Guid> grantedUserIds, bool reassign, bool cascading, bool reassignCascading);
     
    24902493        System.Collections.Generic.List<HeuristicLab.Clients.Hive.SlaveGroup> GetSlaveGroupsForAdministration();
    24912494       
     2495        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetResourceGenealogy", ReplyAction="http://tempuri.org/IHiveService/GetResourceGenealogyResponse")]
     2496        System.Collections.Generic.Dictionary<System.Guid, System.Collections.Generic.List<System.Guid>> GetResourceGenealogy();
     2497       
    24922498        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/UpdateSlave", ReplyAction="http://tempuri.org/IHiveService/UpdateSlaveResponse")]
    24932499        void UpdateSlave(HeuristicLab.Clients.Hive.Slave slave);
     
    27542760        }
    27552761       
     2762        public System.Collections.Generic.Dictionary<System.Guid, System.Collections.Generic.List<System.Guid>> GetProjectGenealogy()
     2763        {
     2764            return base.Channel.GetProjectGenealogy();
     2765        }
     2766       
    27562767        public void SaveProjectPermissions(System.Guid projectId, System.Collections.Generic.List<System.Guid> grantedUserIds, bool reassign, bool cascading, bool reassignCascading)
    27572768        {
     
    28192830        }
    28202831       
     2832        public System.Collections.Generic.Dictionary<System.Guid, System.Collections.Generic.List<System.Guid>> GetResourceGenealogy()
     2833        {
     2834            return base.Channel.GetResourceGenealogy();
     2835        }
     2836       
    28212837        public void UpdateSlave(HeuristicLab.Clients.Hive.Slave slave)
    28222838        {
  • branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15908 r15913  
    795795      }
    796796    }
     797
     798    public IDictionary<Guid, HashSet<Guid>> GetProjectGenealogy() {
     799      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     800      var pm = PersistenceManager;
     801      using(new PerformanceLogger("GetProjectGenealogy")) {
     802        var projectDao = pm.ProjectDao;
     803        var projectAncestors = new Dictionary<Guid, HashSet<Guid>>();
     804        return pm.UseTransaction(() => {
     805          var projects = projectDao.GetAll().ToList();
     806          projects.ForEach(p => projectAncestors.Add(p.ProjectId, new HashSet<Guid>()));
     807          foreach (var p in projects) {
     808            var parentProject = p.ParentProject;
     809            while(parentProject != null) {
     810              projectAncestors[p.ProjectId].Add(parentProject.ProjectId);
     811              parentProject = parentProject.ParentProject;
     812            }
     813          }
     814          return projectAncestors;
     815        });
     816      }
     817    }
    797818    #endregion
    798819
     
    12451266    }
    12461267
     1268    public IDictionary<Guid, HashSet<Guid>> GetResourceGenealogy() {
     1269      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     1270      var pm = PersistenceManager;
     1271      using (new PerformanceLogger("GetResourceGenealogy")) {
     1272        var resourceDao = pm.ResourceDao;
     1273        var resourceAncestors = new Dictionary<Guid, HashSet<Guid>>();
     1274        return pm.UseTransaction(() => {
     1275          var resources = resourceDao.GetAll().ToList();
     1276          resources.ForEach(r => resourceAncestors.Add(r.ResourceId, new HashSet<Guid>()));
     1277         
     1278          foreach(var r in resources) {
     1279            var parentResource = r.ParentResource;
     1280            while(parentResource != null) {
     1281              resourceAncestors[r.ResourceId].Add(parentResource.ResourceId);
     1282              parentResource = parentResource.ParentResource;
     1283            }
     1284          }
     1285          return resourceAncestors;
     1286        });
     1287      }
     1288    }
     1289
    12471290    public void UpdateSlave(DT.Slave slaveDto) {
    12481291      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
  • branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs

    r15819 r15913  
    154154    [OperationContract]
    155155    IEnumerable<Project> GetProjectsForAdministration();
     156
     157    [OperationContract]
     158    IDictionary<Guid, HashSet<Guid>> GetProjectGenealogy();
    156159    #endregion
    157160
     
    211214    [OperationContract]
    212215    IEnumerable<SlaveGroup> GetSlaveGroupsForAdministration();
     216
     217    [OperationContract]
     218    IDictionary<Guid, HashSet<Guid>> GetResourceGenealogy();
    213219
    214220    [OperationContract]
Note: See TracChangeset for help on using the changeset viewer.