Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/18 14:32:16 (7 years ago)
Author:
jzenisek
Message:

#2839 preliminary integration of several HiveAdministrator related improvements from #2877 (full merge pending)

  • slaves and slave groups are sorted by name
  • slave state is indicated by different colors
  • number of contained slaves is shown for each group
  • CPU utilization is shown for each calculating slave
  • last heartbeat date is shown for each offline slave
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r15777 r15792  
    4545    private readonly Color changedColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1
    4646    private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b
     47    private readonly Color calculatingColor = Color.FromArgb(255, 58, 114, 35); // #3a7223
     48    private readonly Color offlineColor = Color.FromArgb(255, 187, 36, 36); // #bb2424
    4749
    4850    private Resource selectedResource = null;
     
    215217      };
    216218
     219      HiveAdminClient.Instance.UpdateResourceGenealogy(Content);
    217220      SelectedResource = group;
    218221      Content.Add(group);
     
    252255      if (result == DialogResult.Yes) {
    253256        await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
    254           action: () => RemoveResource(selectedResource),
    255           finallyCallback: () => {
     257          action: () => {
     258            RemoveResource(selectedResource);
     259          },
     260          finallyCallback: () => {
    256261            btnRemoveGroup.Enabled = true;
    257262          });
     
    279284    private void treeSlaveGroup_MouseDown(object sender, MouseEventArgs e) {
    280285      var node = treeView.GetNodeAt(e.Location);
    281       if(node != null && node.Name != ungroupedGroupName) ChangeSelectedResourceNode(node);
     286      if(node != null && !node.Text.StartsWith(ungroupedGroupName)) ChangeSelectedResourceNode(node);
    282287    }
    283288
     
    325330      }
    326331
     332      HiveAdminClient.Instance.UpdateResourceGenealogy(Content);
    327333      SelectedResource = sourceResource;
    328334      OnContentChanged();
     
    350356        || sourceNode == targetNode
    351357        || !HiveAdminClient.Instance.CheckParentChange(sourceResource, targetResource)
    352         || (targetNode != null && (targetNode.Text == ungroupedGroupName || targetNode.Parent != null && targetNode.Parent.Text == ungroupedGroupName))) {
     358        || (targetNode != null && (targetNode.Text.StartsWith(ungroupedGroupName) || targetNode.Parent != null && targetNode.Parent.Text.StartsWith(ungroupedGroupName)))) {
    353359        e.Effect = DragDropEffects.None;
    354360      }
     
    361367
    362368    #region Helpers
    363     private void ResetTreeNodes(TreeNodeCollection nodes, Color c1, Color c2, bool resetText) {
    364       foreach (TreeNode n in nodes) {
    365         var res = ((Resource)n.Tag);
    366         if (n.BackColor.Equals(c1)) {
    367           n.BackColor = c2;
    368         }
    369         if (resetText) {
    370           n.Text = res.Name;
    371 
    372           if (res.Id == Guid.Empty && res.Name != ungroupedGroupName) {
    373             n.Text += " [not stored]";
    374           } else if (res.Modified && res.Name != ungroupedGroupName) {
    375             n.Text += " [changes not stored]";
    376           }
    377         }
    378         if (n.Nodes.Count > 0) {
    379           ResetTreeNodes(n.Nodes, c1, c2, resetText);
    380         }
    381       }
    382     }
    383 
    384369    private void BuildResourceTree(IEnumerable<Resource> resources) {
    385370      treeView.Nodes.Clear();
     
    400385      Resource currentResource = null;
    401386
    402       while(stack.Any()) {
     387      while (stack.Any()) {
    403388        var newResource = stack.Pop();
    404389        var newNode = new TreeNode(newResource.Name) { Tag = newResource };
    405 
    406         if(newResource.Id == Guid.Empty) {
    407           newNode.Text += " [not stored]";
    408         } else if(newResource.Modified) {
    409           newNode.Text += " [changes not stored]";
    410         }
     390        StyleTreeNode(newNode, newResource, resources);
     391
    411392        if (selectedResource == null) {
    412393          SelectedResource = newResource;
     
    426407        }
    427408
    428         if(currentNode == null) {
     409        if (currentNode == null) {
    429410          treeView.Nodes.Add(newNode);
    430411        } else {
     
    432413        }
    433414
    434         if(newResource is Slave) {
    435           newNode.ImageIndex = slaveImageIndex;
    436         } else {
    437           newNode.ImageIndex = slaveGroupImageIndex;
    438 
     415        if (newResource is SlaveGroup) {
    439416          var childResources = subResources.Where(x => x.ParentResourceId == newResource.Id);
    440           if(childResources.Any()) {
    441             foreach(var resource in childResources.OrderByDescending(x => x.Name)) {
     417          if (childResources.Any()) {
     418            foreach (var resource in childResources.OrderByDescending(x => x.Name)) {
    442419              subResources.Remove(resource);
    443420              stack.Push(resource);
     
    448425        }
    449426        newNode.SelectedImageIndex = newNode.ImageIndex;
    450         //if (newResource.OwnerUserId == UserInformation.Instance.User.Id)
    451         //  newNode.BackColor = ownedResourceColor;
    452427      }
    453428
     
    460435      };
    461436
     437      int ungroupedSlavesCount = 0;
    462438      foreach (var slave in subResources.OfType<Slave>().OrderBy(x => x.Name)) {
    463439        var slaveNode = new TreeNode(slave.Name) { Tag = slave };
     440        StyleTreeNode(slaveNode, slave, resources);
    464441        ungroupedNode.Nodes.Add(slaveNode);
    465         if(selectedResource == null) {
     442        ungroupedSlavesCount++;
     443        if (selectedResource == null) {
    466444          SelectedResource = slave;
    467445        }
    468         if (slave.Id == Guid.Empty) {
    469           slaveNode.Text += " [not stored]";
    470         } else if (slave.Modified) {
    471           slaveNode.Text += " [changes not stored]";
    472         }
     446
    473447        if (slave.Id == selectedResource.Id && !nodeSelected) {
    474448          slaveNode.BackColor = selectedColor;
     
    478452      }
    479453
     454      if (ungroupedSlavesCount > 0)
     455        ungroupedNode.Text += " [" + ungroupedSlavesCount.ToString() + "]";
    480456      treeView.Nodes.Add(ungroupedNode);
    481457      treeView.ExpandAll();
     458     
    482459    }
    483460
     
    488465          UpdateChildHbIntervall(r);
    489466        }
    490       }
    491     }
    492 
    493     private bool CheckParentsEqualsMovedNode(TreeNode dest, TreeNode movedNode) {
    494       TreeNode tmp = dest;
    495 
    496       while (tmp != null) {
    497         if (tmp == movedNode) {
    498           return true;
    499         }
    500         tmp = tmp.Parent;
    501       }
    502       return false;
    503     }
    504 
    505     private void ResetView() {
    506       if (InvokeRequired) Invoke((Action)ResetView);
    507       else {
    508         treeView.Nodes.Clear();
    509 
    510         if (viewHost.Content != null && viewHost.Content is SlaveGroup) {
    511           ((SlaveGroup)viewHost.Content).PropertyChanged -= SlaveViewContent_PropertyChanged;
    512         }
    513 
    514         viewHost.Content = null;
    515         if (scheduleView.Content != null) {
    516           scheduleView.Content.Clear();
    517         }
    518 
    519         HiveAdminClient.Instance.ResetDowntime();
    520467      }
    521468    }
     
    534481
    535482      try {
    536         if(resource.Id != Guid.Empty) HiveAdminClient.Delete(resource);
    537         Content.Remove(selectedResource);
     483        if (resource.Id != Guid.Empty) {
     484          var resourcesToSave = Content.Where(x => x.Id == Guid.Empty || x.Modified);
     485          foreach (var r in resourcesToSave)
     486            r.Store();
     487          HiveAdminClient.Delete(resource);
     488          UpdateResources();
     489        } else {
     490          Content.Remove(selectedResource);
     491        }
    538492      } catch(AnonymousUserException) {
    539493        ShowHiveInformationDialog();
     
    549503    }
    550504
    551     private bool IsAuthorized(Resource resource) {
    552       return resource != null
    553           && resource.Name != ungroupedGroupName
    554           //&& resource.Id != Guid.Empty
    555           && UserInformation.Instance.UserExists
    556           && (HiveRoles.CheckAdminUserPermissions()
    557             || HiveAdminClient.Instance.CheckOwnershipOfResource(resource, UserInformation.Instance.User.Id));
    558     }
    559 
    560505    private bool IsAdmin() {
    561506      return HiveRoles.CheckAdminUserPermissions();
     507    }
     508
     509    private void StyleTreeNode(TreeNode n, Resource r, IEnumerable<Resource> resources) {
     510      n.Text = r.Name;
     511      n.BackColor = Color.Transparent;
     512      n.ForeColor = Color.Black;
     513
     514      // slave count
     515      int childSlavesCount = 0;
     516      if (r.Id != Guid.Empty && r is SlaveGroup) {
     517        var descendants = HiveAdminClient.Instance.ResourceDescendants;
     518        if (descendants.ContainsKey(r.Id)) {
     519          childSlavesCount = resources
     520            .OfType<Slave>()
     521            .Where(x => descendants[r.Id].Select(y => y.Id)
     522            .Contains(x.Id))
     523            .Count();
     524        }
     525      } else if(r.Name.StartsWith(ungroupedGroupName)) {
     526        childSlavesCount = resources
     527          .OfType<Slave>()
     528          .Where(x => x.ParentResourceId == null
     529            || (x.ParentResourceId.HasValue && x.ParentResourceId.Value == Guid.Empty))
     530          .Count();
     531      }
     532      if (childSlavesCount > 0)
     533        n.Text += " [" + childSlavesCount.ToString() + "]";
     534
     535      // slave image index, state, utilization
     536      if (r is Slave) {
     537        n.ImageIndex = slaveImageIndex;
     538        var s = r as Slave;
     539        if (s.SlaveState == SlaveState.Calculating) {
     540          n.ForeColor = calculatingColor;
     541          n.Text += " [" + s.CpuUtilization.ToString("N2") + "%]";
     542        } else if (s.SlaveState == SlaveState.Offline) {
     543          n.ForeColor = offlineColor;
     544          if (s.LastHeartbeat.HasValue)
     545            n.Text += " [" + s.LastHeartbeat?.ToString("g") + "]";
     546        }
     547      } else {
     548        n.ImageIndex = slaveGroupImageIndex;
     549      }
     550
     551      // not stored (i.e. new), changed
     552      if (r.Id == Guid.Empty && !r.Name.StartsWith(ungroupedGroupName)) {
     553        n.Text += " [not stored]";
     554      } else if (r.Modified && !r.Name.StartsWith(ungroupedGroupName)) {
     555        n.Text += " [changes not stored]";
     556      }
     557
     558      // ungrouped
     559      if(r.Name.StartsWith(ungroupedGroupName)) {
     560        n.ForeColor = ForeColor = SystemColors.GrayText;
     561      }
     562    }
     563
     564    private void ResetTreeNodes(TreeNodeCollection nodes, IEnumerable<Resource> resources) {
     565      foreach (TreeNode n in nodes) {
     566        StyleTreeNode(n, (Resource)n.Tag, resources);
     567        if (n.Nodes.Count > 0) {
     568          ResetTreeNodes(n.Nodes, resources);
     569        }
     570      }
    562571    }
    563572
     
    571580
    572581      bool locked = !IsAdmin() || resource == null;
    573       bool addLocked = locked || (resource != null && resource.Id == Guid.Empty);
     582      bool scheduleLocked = locked || (resource != null && resource.Id == Guid.Empty);
     583      bool addLocked = locked || (resource != null && resource.Id == Guid.Empty) || resource is Slave;
    574584
    575585      btnAddGroup.Enabled = !addLocked;
     
    578588      viewHost.Locked = locked;
    579589      scheduleView.Locked = locked;
    580       scheduleView.SetEnabledStateOfSchedule(!addLocked);
     590      scheduleView.SetEnabledStateOfSchedule(!scheduleLocked);
    581591    }
    582592
     
    584594      if (resourceNode == null) return;
    585595      SelectedResource = (Resource)resourceNode.Tag;
    586       ResetTreeNodes(treeView.Nodes, selectedColor, Color.Transparent, true);
     596      ResetTreeNodes(treeView.Nodes, Content);
    587597      resourceNode.BackColor = selectedColor;
    588598      resourceNode.Text += " [selected]";
     
    597607      }
    598608    }
     609
     610    private void ResetView() {
     611      if (InvokeRequired) Invoke((Action)ResetView);
     612      else {
     613        treeView.Nodes.Clear();
     614
     615        if (viewHost.Content != null && viewHost.Content is SlaveGroup) {
     616          ((SlaveGroup)viewHost.Content).PropertyChanged -= SlaveViewContent_PropertyChanged;
     617        }
     618
     619        viewHost.Content = null;
     620        if (scheduleView.Content != null) {
     621          scheduleView.Content.Clear();
     622        }
     623
     624        HiveAdminClient.Instance.ResetDowntime();
     625      }
     626    }
     627
    599628    #endregion
    600629  }
Note: See TracChangeset for help on using the changeset viewer.