1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Linq;
|
---|
27 | using System.ServiceModel;
|
---|
28 | using System.Windows.Forms;
|
---|
29 | using HeuristicLab.Hive.Contracts;
|
---|
30 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
31 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
32 | using HeuristicLab.Hive.Contracts.ResponseObjects;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
35 |
|
---|
36 | /// <summary>
|
---|
37 | /// if form is closed the loginform gets an information
|
---|
38 | /// </summary>
|
---|
39 | /// <param name="cf"></param>
|
---|
40 | /// <param name="error"></param>
|
---|
41 | public delegate void closeForm(bool cf, bool error);
|
---|
42 |
|
---|
43 | public delegate void updateListView(JobDataFetcher fetcher, ListView sender, int category);
|
---|
44 |
|
---|
45 | public partial class HiveServerManagementConsole : Form {
|
---|
46 |
|
---|
47 | public event closeForm closeFormEvent;
|
---|
48 |
|
---|
49 | #region private variables
|
---|
50 | private ResponseList<JobDto> jobs = null;
|
---|
51 |
|
---|
52 | List<ListViewGroup> jobGroup;
|
---|
53 | private Dictionary<Guid, List<ListViewItem>> clientList = new Dictionary<Guid, List<ListViewItem>>();
|
---|
54 | private List<Changes> changes = new List<Changes>();
|
---|
55 |
|
---|
56 | private JobDto currentJob = null;
|
---|
57 | private SlaveDto currentSlave = null;
|
---|
58 |
|
---|
59 | private TreeNode currentGroupNode = null;
|
---|
60 | Guid parentgroup = Guid.Empty;
|
---|
61 | private ToolTip tt = new ToolTip();
|
---|
62 |
|
---|
63 | private const string NOGROUP = "No group";
|
---|
64 | private TreeNode hoverNode;
|
---|
65 | private List<ListViewGroup> lvSlaveGroups;
|
---|
66 |
|
---|
67 | private JobDataFetcher jdfFinished = null;
|
---|
68 | private JobDataFetcher jdfOffline = null;
|
---|
69 | private JobDataFetcher jdfCalculating = null;
|
---|
70 |
|
---|
71 |
|
---|
72 | #endregion
|
---|
73 |
|
---|
74 | #region Properties
|
---|
75 | private ISlaveManager SlaveManager {
|
---|
76 | get {
|
---|
77 | try {
|
---|
78 | return ServiceLocator.GetSlaveManager();
|
---|
79 | }
|
---|
80 | catch (FaultException ex) {
|
---|
81 | MessageBox.Show(ex.Message);
|
---|
82 | }
|
---|
83 | return null;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | #endregion
|
---|
87 |
|
---|
88 | public HiveServerManagementConsole() {
|
---|
89 | InitializeComponent();
|
---|
90 | Init();
|
---|
91 | AddSlaves();
|
---|
92 | //AddJobs();
|
---|
93 | StartAutoUpdateTimers();
|
---|
94 | //timerSyncronize.Start();
|
---|
95 | }
|
---|
96 |
|
---|
97 | private void StartAutoUpdateTimers() {
|
---|
98 | jdfCalculating.NewDataAvailable += new EventHandler(jdf_NewDataAvailable);
|
---|
99 | jdfOffline.NewDataAvailable += new EventHandler(jdf_NewDataAvailable);
|
---|
100 | jdfFinished.NewDataAvailable += new EventHandler(jdf_NewDataAvailable);
|
---|
101 | jdfFinished.Start();
|
---|
102 | jdfOffline.Start();
|
---|
103 | jdfCalculating.Start();
|
---|
104 | }
|
---|
105 |
|
---|
106 | void jdf_NewDataAvailable(object sender, EventArgs e) {
|
---|
107 | JobDataFetcher fetcher = (JobDataFetcher)sender;
|
---|
108 | if (fetcher.PollStates.Contains(JobState.Finished)) {
|
---|
109 | UpdateJobListView(fetcher, lv_finishedJobs, 0);
|
---|
110 | } else if (fetcher.PollStates.Contains(JobState.Calculating)) {
|
---|
111 | UpdateJobListView(fetcher, lv_calculatingJobs, 1);
|
---|
112 | } else if (fetcher.PollStates.Contains(JobState.Offline)) {
|
---|
113 | UpdateJobListView(fetcher, lv_offlineJobs, 2);
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | private void UpdateJobListView(JobDataFetcher fetcher, ListView listView, int category) {
|
---|
118 | if (listView.InvokeRequired) {
|
---|
119 | listView.Invoke(new updateListView(UpdateJobListView), new object[] { fetcher, listView, category });
|
---|
120 | } else {
|
---|
121 | listView.BeginUpdate();
|
---|
122 | listView.Items.Clear();
|
---|
123 | foreach (JobDto job in fetcher.CachedJobs) {
|
---|
124 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), category);
|
---|
125 | lvi.Tag = job;
|
---|
126 | listView.Items.Add(lvi);
|
---|
127 | }
|
---|
128 | listView.EndUpdate();
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | private void Init() {
|
---|
134 |
|
---|
135 | jdfFinished = new JobDataFetcher(new JobState[] { JobState.Finished }, 50);
|
---|
136 | jdfCalculating = new JobDataFetcher(new JobState[] { JobState.Calculating }, 50);
|
---|
137 | jdfOffline = new JobDataFetcher(new JobState[] { JobState.Offline }, 50);
|
---|
138 |
|
---|
139 | cmb_finishedJob_count.SelectedItem = "50";
|
---|
140 | cmb_offlineJob_count.SelectedItem = "50";
|
---|
141 | cmb_calculatingJob_count.SelectedItem = "50";
|
---|
142 |
|
---|
143 | calcToolStripAbortItem.Click += (s, e) => {
|
---|
144 | if (lv_calculatingJobs.SelectedItems.Count > 0) {
|
---|
145 | ServiceLocator.GetJobManager().AbortJob(((JobDto)lv_calculatingJobs.SelectedItems[0].Tag).Id);
|
---|
146 | }
|
---|
147 | };
|
---|
148 |
|
---|
149 | offlineItemAbortJob.Click += (s, e) => {
|
---|
150 | if (lv_offlineJobs.SelectedItems.Count > 0) {
|
---|
151 | ServiceLocator.GetJobManager().AbortJob(((JobDto)lv_offlineJobs.SelectedItems[0].Tag).Id);
|
---|
152 | }
|
---|
153 | };
|
---|
154 |
|
---|
155 | //adding group
|
---|
156 | menuItemAddGroup.Click += (s, e) => {
|
---|
157 | AddGroup addgroup = new AddGroup();
|
---|
158 | parentgroup = Guid.Empty;
|
---|
159 | if ((tvClientControl.SelectedNode != null) && (((SlaveGroupDto)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
|
---|
160 | parentgroup = ((SlaveGroupDto)tvClientControl.SelectedNode.Tag).Id;
|
---|
161 | }
|
---|
162 | addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
|
---|
163 | addgroup.Show();
|
---|
164 | };
|
---|
165 |
|
---|
166 | //adding group
|
---|
167 | menuItemDeleteGroup.Click += (s, e) => {
|
---|
168 | ISlaveManager slaveManager = ServiceLocator.GetSlaveManager();
|
---|
169 | if (tvClientControl.SelectedNode != null) {
|
---|
170 | Response resp = slaveManager.DeleteSlaveGroup(((SlaveGroupDto)tvClientControl.SelectedNode.Tag).Id);
|
---|
171 | if (tvClientControl.SelectedNode == currentGroupNode) {
|
---|
172 | currentGroupNode = null;
|
---|
173 | }
|
---|
174 | tvClientControl.Nodes.Remove(tvClientControl.SelectedNode);
|
---|
175 | AddSlaves();
|
---|
176 | }
|
---|
177 | };
|
---|
178 |
|
---|
179 | menuItemOpenCalendar.Click += (s, e) => {
|
---|
180 | if (tvClientControl.SelectedNode != null) {
|
---|
181 | CgCalendar cal = new CgCalendar(((SlaveGroupDto)tvClientControl.SelectedNode.Tag).Id, ((SlaveGroupDto)tvClientControl.SelectedNode.Tag).Name);
|
---|
182 | cal.Show();
|
---|
183 | }
|
---|
184 | };
|
---|
185 |
|
---|
186 |
|
---|
187 | // drag item to treeview
|
---|
188 | lvClientControl.ItemDrag += delegate(object sender, ItemDragEventArgs e) {
|
---|
189 | List<string> itemIDs = new List<string>((sender as ListView).SelectedItems.Count);
|
---|
190 | foreach (ListViewItem item in (sender as ListView).SelectedItems) {
|
---|
191 | itemIDs.Add(item.Name);
|
---|
192 | }
|
---|
193 | (sender as ListView).DoDragDrop(itemIDs.ToArray(), DragDropEffects.Move);
|
---|
194 | };
|
---|
195 |
|
---|
196 | // drag enter on treeview
|
---|
197 | tvClientControl.DragEnter += delegate(object sender, DragEventArgs e) {
|
---|
198 | e.Effect = DragDropEffects.Move;
|
---|
199 | };
|
---|
200 |
|
---|
201 | // drag over
|
---|
202 | tvClientControl.DragOver += delegate(object sender, DragEventArgs e) {
|
---|
203 | Point mouseLocation = tvClientControl.PointToClient(new Point(e.X, e.Y));
|
---|
204 | TreeNode node = tvClientControl.GetNodeAt(mouseLocation);
|
---|
205 | if (node != null && ((SlaveGroupDto)node.Tag).Id != Guid.Empty) {
|
---|
206 | e.Effect = DragDropEffects.Move;
|
---|
207 | if (hoverNode == null) {
|
---|
208 | node.BackColor = Color.LightBlue;
|
---|
209 | node.ForeColor = Color.White;
|
---|
210 | hoverNode = node;
|
---|
211 | } else if (hoverNode != node) {
|
---|
212 | hoverNode.BackColor = Color.White;
|
---|
213 | hoverNode.ForeColor = Color.Black;
|
---|
214 | node.BackColor = Color.LightBlue;
|
---|
215 | node.ForeColor = Color.White;
|
---|
216 | hoverNode = node;
|
---|
217 | }
|
---|
218 | } else {
|
---|
219 | e.Effect = DragDropEffects.None;
|
---|
220 | }
|
---|
221 | };
|
---|
222 |
|
---|
223 | // drag drop event
|
---|
224 | tvClientControl.DragDrop += delegate(object sender, DragEventArgs e) {
|
---|
225 | if (e.Data.GetDataPresent(typeof(string[]))) {
|
---|
226 | Point dropLocation = (sender as TreeView).PointToClient(new Point(e.X, e.Y));
|
---|
227 | TreeNode dropNode = (sender as TreeView).GetNodeAt(dropLocation);
|
---|
228 | if (((SlaveGroupDto)dropNode.Tag).Id != Guid.Empty) {
|
---|
229 | Dictionary<SlaveDto, Guid> clients = new Dictionary<SlaveDto, Guid>();
|
---|
230 | foreach (ListViewItem lvi in lvClientControl.SelectedItems) {
|
---|
231 | Guid groupId = Guid.Empty;
|
---|
232 | foreach (ListViewGroup lvg in lvSlaveGroups) {
|
---|
233 | if (lvi.Group.Header == ((SlaveGroupDto)lvg.Tag).Name) {
|
---|
234 | groupId = ((SlaveGroupDto)lvg.Tag).Id;
|
---|
235 | }
|
---|
236 | }
|
---|
237 | clients.Add((SlaveDto)lvi.Tag, groupId);
|
---|
238 | }
|
---|
239 | ChangeGroup(clients, ((SlaveGroupDto)dropNode.Tag).Id);
|
---|
240 | }
|
---|
241 | tvClientControl_DragLeave(null, EventArgs.Empty);
|
---|
242 | AddSlaves();
|
---|
243 | }
|
---|
244 | };
|
---|
245 | }
|
---|
246 |
|
---|
247 | /// <summary>
|
---|
248 | /// Change client to other group
|
---|
249 | /// </summary>
|
---|
250 | /// <param name="clients">list of clients</param>
|
---|
251 | /// <param name="clientgroupID">group of clients</param>
|
---|
252 | private void ChangeGroup(Dictionary<SlaveDto, Guid> clients, Guid clientgroupID) {
|
---|
253 | ISlaveManager slaveManager = ServiceLocator.GetSlaveManager();
|
---|
254 | foreach (KeyValuePair<SlaveDto, Guid> client in clients) {
|
---|
255 | if (client.Key.Id != Guid.Empty) {
|
---|
256 | Response resp = slaveManager.DeleteResourceFromGroup(client.Value, client.Key.Id);
|
---|
257 | }
|
---|
258 | slaveManager.AddResourceToGroup(clientgroupID, client.Key);
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | #region Backgroundworker
|
---|
263 | /// <summary>
|
---|
264 | /// event on Ticker
|
---|
265 | /// </summary>
|
---|
266 | /// <param name="obj"></param>
|
---|
267 | /// <param name="e"></param>
|
---|
268 | private void TickSync(object obj, EventArgs e) {
|
---|
269 | if (!updaterWoker.IsBusy) {
|
---|
270 | updaterWoker.RunWorkerAsync();
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | private void updaterWoker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
275 | RefreshForm();
|
---|
276 | }
|
---|
277 |
|
---|
278 | private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
279 | changes.Clear();
|
---|
280 |
|
---|
281 | ResponseList<JobDto> jobsOld = jobs;
|
---|
282 | try {
|
---|
283 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
284 |
|
---|
285 | jobs = jobManager.GetAllJobs();
|
---|
286 |
|
---|
287 | IDictionary<int, JobDto> jobsOldHelp;
|
---|
288 | CloneList(jobsOld, out jobsOldHelp);
|
---|
289 |
|
---|
290 | if (jobsOld != null && jobsOld.List != null && jobsOldHelp != null)
|
---|
291 | GetDelta(jobsOld.List, jobsOldHelp);
|
---|
292 |
|
---|
293 | }
|
---|
294 | catch (FaultException fe) {
|
---|
295 | MessageBox.Show(fe.Message);
|
---|
296 | }
|
---|
297 |
|
---|
298 | }
|
---|
299 |
|
---|
300 | #endregion
|
---|
301 |
|
---|
302 |
|
---|
303 | private void AddSlaves() {
|
---|
304 | lvSlaveGroups = new List<ListViewGroup>();
|
---|
305 | clientList.Clear();
|
---|
306 | tvClientControl.Nodes.Clear();
|
---|
307 | try {
|
---|
308 | ResponseList<SlaveGroupDto> clientGroups = SlaveManager.GetAllSlaveGroups();
|
---|
309 |
|
---|
310 | if (clientGroups != null && clientGroups.List != null) {
|
---|
311 | foreach (SlaveGroupDto cg in clientGroups.List) {
|
---|
312 | AddSlaveOrGroup(cg, null);
|
---|
313 | }
|
---|
314 |
|
---|
315 | if (currentGroupNode != null) {
|
---|
316 | lvClientControl.Items.Clear();
|
---|
317 | lvClientControl.Groups.Clear();
|
---|
318 | AddGroupsToListView(currentGroupNode);
|
---|
319 | }
|
---|
320 | tvClientControl.ExpandAll();
|
---|
321 | }
|
---|
322 |
|
---|
323 | }
|
---|
324 | catch (FaultException fe) {
|
---|
325 | MessageBox.Show(fe.Message);
|
---|
326 | }
|
---|
327 | }
|
---|
328 |
|
---|
329 | private void AddSlaveOrGroup(SlaveGroupDto clientGroup, TreeNode currentNode) {
|
---|
330 | currentNode = CreateTreeNode(clientGroup, currentNode);
|
---|
331 | List<ListViewItem> clientGroupList = new List<ListViewItem>();
|
---|
332 | ListViewGroup lvg;
|
---|
333 | if (string.IsNullOrEmpty(clientGroup.Name)) {
|
---|
334 | lvg = new ListViewGroup(NOGROUP, HorizontalAlignment.Left);
|
---|
335 | } else {
|
---|
336 | lvg = new ListViewGroup(clientGroup.Name, HorizontalAlignment.Left);
|
---|
337 | }
|
---|
338 | lvClientControl.Groups.Add(lvg);
|
---|
339 | lvg.Tag = clientGroup;
|
---|
340 | lvSlaveGroups.Add(lvg);
|
---|
341 | foreach (ResourceDto resource in clientGroup.Resources) {
|
---|
342 | if (resource is SlaveDto) {
|
---|
343 | int percentageUsage;
|
---|
344 | if (((SlaveDto)resource).NrOfCores.HasValue && ((SlaveDto)resource).NrOfFreeCores.HasValue) {
|
---|
345 | percentageUsage = CapacityRam(((SlaveDto)resource).NrOfCores.Value, ((SlaveDto)resource).NrOfFreeCores.Value);
|
---|
346 | } else {
|
---|
347 | percentageUsage = 0;
|
---|
348 | }
|
---|
349 |
|
---|
350 | int usage = 3;
|
---|
351 | if ((((SlaveDto)resource).State != SlaveState.Offline) &&
|
---|
352 | (((SlaveDto)resource).State != SlaveState.NullState)) {
|
---|
353 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
354 | usage = 0;
|
---|
355 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
356 | usage = 1;
|
---|
357 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
358 | usage = 2;
|
---|
359 | }
|
---|
360 | }
|
---|
361 | ListViewItem lvi = new ListViewItem(resource.Name, usage, lvg);
|
---|
362 | lvi.Tag = resource as SlaveDto;
|
---|
363 | clientGroupList.Add(lvi);
|
---|
364 | } else if (resource is SlaveGroupDto) {
|
---|
365 | AddSlaveOrGroup(resource as SlaveGroupDto, currentNode);
|
---|
366 | }
|
---|
367 | }
|
---|
368 | clientList.Add(clientGroup.Id, clientGroupList);
|
---|
369 | }
|
---|
370 |
|
---|
371 | private TreeNode CreateTreeNode(SlaveGroupDto clientGroup, TreeNode currentNode) {
|
---|
372 | TreeNode tn;
|
---|
373 | if (string.IsNullOrEmpty(clientGroup.Name)) {
|
---|
374 | tn = new TreeNode(NOGROUP);
|
---|
375 | } else {
|
---|
376 | tn = new TreeNode(clientGroup.Name);
|
---|
377 | }
|
---|
378 | tn.Tag = clientGroup;
|
---|
379 | if (currentNode == null) {
|
---|
380 | tvClientControl.Nodes.Add(tn);
|
---|
381 | } else {
|
---|
382 | currentNode.Nodes.Add(tn);
|
---|
383 | }
|
---|
384 | return tn;
|
---|
385 | }
|
---|
386 |
|
---|
387 | private void AddGroupsToListView(TreeNode node) {
|
---|
388 | if (node != null) {
|
---|
389 | ListViewGroup lvg = new ListViewGroup(node.Text, HorizontalAlignment.Left);
|
---|
390 | lvClientControl.Groups.Add(lvg);
|
---|
391 | lvg.Tag = node.Tag;
|
---|
392 | foreach (ListViewItem item in clientList[((SlaveGroupDto)node.Tag).Id]) {
|
---|
393 | item.Group = lvg;
|
---|
394 | lvClientControl.Items.Add(item);
|
---|
395 | }
|
---|
396 |
|
---|
397 | if (node.Nodes != null) {
|
---|
398 | foreach (TreeNode curNode in node.Nodes) {
|
---|
399 | AddGroupsToListView(curNode);
|
---|
400 | }
|
---|
401 | }
|
---|
402 | }
|
---|
403 | }
|
---|
404 |
|
---|
405 | /// <summary>
|
---|
406 | /// if one job is clicked, the details for the clicked job are shown
|
---|
407 | /// in the second panel
|
---|
408 | /// </summary>
|
---|
409 | private void JobClicked() {
|
---|
410 | plJobDetails.Visible = true;
|
---|
411 | lvJobDetails.Items.Clear();
|
---|
412 |
|
---|
413 | ResponseObject<JobDto> response = ServiceLocator.GetJobManager().GetJobByIdWithDetails(currentJob.Id);
|
---|
414 |
|
---|
415 | if (response.StatusMessage != ResponseStatus.Ok || response.Obj == null)
|
---|
416 | return;
|
---|
417 |
|
---|
418 | JobDto job = response.Obj;
|
---|
419 |
|
---|
420 | //lvSnapshots.Enabled = true;
|
---|
421 |
|
---|
422 | if (job.State == JobState.Offline) {
|
---|
423 | pbJobControl.Image = ilLargeImgJob.Images[2];
|
---|
424 | } else if (job.State == JobState.Calculating) {
|
---|
425 | pbJobControl.Image = ilLargeImgJob.Images[1];
|
---|
426 | } else if (job.State == JobState.Finished) {
|
---|
427 | pbJobControl.Image = ilLargeImgJob.Images[0];
|
---|
428 | }
|
---|
429 |
|
---|
430 | lblJobName.Text = job.Id.ToString();
|
---|
431 |
|
---|
432 | progressJob.Value = (int)(currentJob.ExecutionTime.TotalDays % 1) * progressJob.Maximum;
|
---|
433 | lblProgress.Text = currentJob.ExecutionTime.ToString();
|
---|
434 |
|
---|
435 | ListViewItem lvi = new ListViewItem();
|
---|
436 | lvi.Text = "User:";
|
---|
437 | lvi.SubItems.Add(job.UserId.ToString());
|
---|
438 | lvJobDetails.Items.Add(lvi);
|
---|
439 |
|
---|
440 | lvi = null;
|
---|
441 | lvi = new ListViewItem();
|
---|
442 | lvi.Text = "created at:";
|
---|
443 | lvi.SubItems.Add(job.DateCreated.ToString());
|
---|
444 | lvJobDetails.Items.Add(lvi);
|
---|
445 |
|
---|
446 | if (job.ParentJobId != null) {
|
---|
447 | lvi = null;
|
---|
448 | lvi = new ListViewItem();
|
---|
449 | lvi.Text = "Parent job:";
|
---|
450 | lvi.SubItems.Add(job.ParentJobId.ToString());
|
---|
451 | lvJobDetails.Items.Add(lvi);
|
---|
452 | }
|
---|
453 |
|
---|
454 | lvi = null;
|
---|
455 | lvi = new ListViewItem();
|
---|
456 | lvi.Text = "Priority:";
|
---|
457 | lvi.SubItems.Add(job.Priority.ToString());
|
---|
458 | lvJobDetails.Items.Add(lvi);
|
---|
459 |
|
---|
460 | if (job.Project != null) {
|
---|
461 | lvi = null;
|
---|
462 | lvi = new ListViewItem();
|
---|
463 | lvi.Text = "Project:";
|
---|
464 | lvi.SubItems.Add(job.Project.Name.ToString());
|
---|
465 | lvJobDetails.Items.Add(lvi);
|
---|
466 | }
|
---|
467 |
|
---|
468 | if (job.Slave != null) {
|
---|
469 | lvi = null;
|
---|
470 | lvi = new ListViewItem();
|
---|
471 | lvi.Text = "Calculation begin:";
|
---|
472 | lvi.SubItems.Add(job.DateCalculated.ToString());
|
---|
473 | lvJobDetails.Items.Add(lvi);
|
---|
474 |
|
---|
475 |
|
---|
476 | lvi = null;
|
---|
477 | lvi = new ListViewItem();
|
---|
478 | lvi.Text = "Slave calculated:";
|
---|
479 | lvi.SubItems.Add(job.Slave.Name.ToString());
|
---|
480 | lvJobDetails.Items.Add(lvi);
|
---|
481 |
|
---|
482 | if (job.State == JobState.Finished) {
|
---|
483 | lvi = null;
|
---|
484 | lvi = new ListViewItem();
|
---|
485 | lvi.Text = "Calculation ended:";
|
---|
486 | lvi.SubItems.Add(job.DateFinished.ToString());
|
---|
487 | lvJobDetails.Items.Add(lvi);
|
---|
488 | }
|
---|
489 | }
|
---|
490 | }
|
---|
491 |
|
---|
492 | /// <summary>
|
---|
493 | /// if one client is clicked, the details for the clicked client are shown
|
---|
494 | /// in the second panel
|
---|
495 | /// </summary>
|
---|
496 | private void SlaveClicked() {
|
---|
497 | plClientDetails.Visible = true;
|
---|
498 |
|
---|
499 | if (currentSlave != null) {
|
---|
500 | int percentageUsage;
|
---|
501 | if (currentSlave.NrOfCores.HasValue && currentSlave.NrOfFreeCores.HasValue) {
|
---|
502 | percentageUsage = CapacityRam(currentSlave.NrOfCores.Value, currentSlave.NrOfFreeCores.Value);
|
---|
503 | } else {
|
---|
504 | percentageUsage = 0;
|
---|
505 | }
|
---|
506 | int usage = 3;
|
---|
507 | if ((currentSlave.State != SlaveState.Offline) && (currentSlave.State != SlaveState.NullState)) {
|
---|
508 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
509 | usage = 0;
|
---|
510 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
511 | usage = 1;
|
---|
512 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
513 | usage = 2;
|
---|
514 | }
|
---|
515 | }
|
---|
516 | pbClientControl.Image = ilLargeImgClient.Images[usage];
|
---|
517 | lblClientName.Text = currentSlave.Name;
|
---|
518 | lblLogin.Text = currentSlave.Login.ToString();
|
---|
519 | lblState.Text = currentSlave.State.ToString();
|
---|
520 | }
|
---|
521 | }
|
---|
522 |
|
---|
523 | private void RefreshForm() {
|
---|
524 | foreach (Changes change in changes) {
|
---|
525 | if (change.Types == Type.Job) {
|
---|
526 | RefreshJob(change);
|
---|
527 | }
|
---|
528 | }
|
---|
529 | }
|
---|
530 |
|
---|
531 | private void RefreshJob(Changes change) {
|
---|
532 | /*if (change.ChangeType == Change.Update) {
|
---|
533 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
534 | if (lvJobControl.Items[i].Text == change.ID.ToString()) {
|
---|
535 | foreach (JobDto job in jobs.List) {
|
---|
536 | if (job.Id == change.ID) {
|
---|
537 | lvJobControl.Items[i].Tag = job;
|
---|
538 | if (currentJob != null) {
|
---|
539 | if (currentJob.Id == change.ID) {
|
---|
540 | currentJob = job;
|
---|
541 | JobClicked();
|
---|
542 | }
|
---|
543 | }
|
---|
544 | break;
|
---|
545 | }
|
---|
546 | }
|
---|
547 | State state = jobs.List[change.Position].State;
|
---|
548 | if (state == State.finished) {
|
---|
549 | lvJobControl.Items[i].Group = jobGroup[1];
|
---|
550 | lvJobControl.Items[i].ImageIndex = 0;
|
---|
551 | } else if (state == State.calculating) {
|
---|
552 | lvJobControl.Items[i].Group = jobGroup[0];
|
---|
553 | lvJobControl.Items[i].ImageIndex = 1;
|
---|
554 | } else if (state == State.offline || state == State.pending) {
|
---|
555 | lvJobControl.Items[i].Group = jobGroup[2];
|
---|
556 | lvJobControl.Items[i].ImageIndex = 2;
|
---|
557 | }
|
---|
558 | lvJobControl.Refresh();
|
---|
559 | }
|
---|
560 | }
|
---|
561 | } else if (change.ChangeType == Change.Create) {
|
---|
562 |
|
---|
563 | ListViewItem lvi = new ListViewItem(
|
---|
564 | change.ID.ToString(), 2, jobGroup[2]);
|
---|
565 | foreach (JobDto job in jobs.List) {
|
---|
566 | if (job.Id == change.ID) {
|
---|
567 | lvi.Tag = job;
|
---|
568 | break;
|
---|
569 | }
|
---|
570 | }
|
---|
571 | lvJobControl.Items.Add(lvi);
|
---|
572 |
|
---|
573 | } else if (change.ChangeType == Change.Delete) {
|
---|
574 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
575 | if (change.ID.ToString() == lvJobControl.Items[i].Text.ToString()) {
|
---|
576 | lvJobControl.Items[i].Remove();
|
---|
577 | break;
|
---|
578 | }
|
---|
579 | }
|
---|
580 | } */
|
---|
581 | }
|
---|
582 |
|
---|
583 |
|
---|
584 | #region Eventhandlers
|
---|
585 | /// <summary>
|
---|
586 | /// Send event to Login-GUI when closing
|
---|
587 | /// </summary>
|
---|
588 | /// <param name="sender"></param>
|
---|
589 | /// <param name="e"></param>
|
---|
590 | private void Close_Click(object sender, EventArgs e) {
|
---|
591 | if (closeFormEvent != null) {
|
---|
592 | closeFormEvent(true, false);
|
---|
593 | }
|
---|
594 | this.Close();
|
---|
595 | }
|
---|
596 |
|
---|
597 | /// <summary>
|
---|
598 | /// Send evnt to Login-GUI when closing
|
---|
599 | /// </summary>
|
---|
600 | /// <param name="sender"></param>
|
---|
601 | /// <param name="e"></param>
|
---|
602 | private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
603 | if (closeFormEvent != null) {
|
---|
604 | closeFormEvent(true, false);
|
---|
605 | }
|
---|
606 | }
|
---|
607 |
|
---|
608 | private void AddJob_Click(object sender, EventArgs e) {
|
---|
609 | AddJobForm newForm = new AddJobForm();
|
---|
610 | newForm.Show();
|
---|
611 | newForm.addJobEvent += new addDelegate(updaterWoker.RunWorkerAsync);
|
---|
612 | }
|
---|
613 |
|
---|
614 | private void OnLVJobControlClicked(object sender, EventArgs e) {
|
---|
615 | JobListView jlv = (JobListView)sender;
|
---|
616 | currentJob = (JobDto)jlv.SelectedItems[0].Tag;
|
---|
617 | JobClicked();
|
---|
618 | }
|
---|
619 |
|
---|
620 | private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
|
---|
621 | JobListView jlv = (JobListView)sender;
|
---|
622 | if ((jlv.GetItemAt(e.X, e.Y) != null) &&
|
---|
623 | (jlv.GetItemAt(e.X, e.Y).ToolTipText != null)) {
|
---|
624 | tt.SetToolTip(jlv, jlv.GetItemAt(e.X, e.Y).ToolTipText);
|
---|
625 | }
|
---|
626 | }
|
---|
627 |
|
---|
628 | private void lvJobControl_MouseUp(object sender, MouseEventArgs e) {
|
---|
629 | // If the right mouse button was clicked and released,
|
---|
630 | // display the shortcut menu assigned to the ListView.
|
---|
631 | JobListView jlv = (JobListView)sender;
|
---|
632 | jlv.ContextMenuStrip.Items.Clear();
|
---|
633 | ListViewHitTestInfo hitTestInfo = jlv.HitTest(e.Location);
|
---|
634 | if (e.Button == MouseButtons.Right && hitTestInfo.Item != null && jlv.SelectedItems.Count == 1) {
|
---|
635 | JobDto selectedJob = (JobDto)jlv.SelectedItems[0].Tag;
|
---|
636 |
|
---|
637 | if (selectedJob != null && selectedJob.State == JobState.Calculating) {
|
---|
638 | jlv.ContextMenuStrip.Items.Add(offlineItemAbortJob);
|
---|
639 | jlv.ContextMenuStrip.Items.Add(menuItemGetSnapshot);
|
---|
640 | }
|
---|
641 | }
|
---|
642 | jlv.ContextMenuStrip.Show(new Point(e.X, e.Y));
|
---|
643 | }
|
---|
644 |
|
---|
645 | private void tvClientControl_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
646 | lvClientControl.Items.Clear();
|
---|
647 | lvClientControl.Groups.Clear();
|
---|
648 | currentGroupNode = e.Node;
|
---|
649 | AddGroupsToListView(e.Node);
|
---|
650 | }
|
---|
651 |
|
---|
652 | private void groupToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
653 | AddGroup addgroup = new AddGroup();
|
---|
654 | parentgroup = Guid.Empty;
|
---|
655 | if ((tvClientControl.SelectedNode != null) && (((SlaveGroupDto)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
|
---|
656 | parentgroup = ((SlaveGroupDto)tvClientControl.SelectedNode.Tag).Id;
|
---|
657 | }
|
---|
658 | addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
|
---|
659 | addgroup.Show();
|
---|
660 | }
|
---|
661 |
|
---|
662 | private void projectToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
663 | AddProject addproject = new AddProject();
|
---|
664 | addproject.AddProjectEvent += new AddProjectDelegate(addproject_AddProjectEvent);
|
---|
665 | addproject.Show();
|
---|
666 | }
|
---|
667 |
|
---|
668 | private void OnLVClientClicked(object sender, EventArgs e) {
|
---|
669 | currentSlave = (SlaveDto)lvClientControl.SelectedItems[0].Tag;
|
---|
670 | SlaveClicked();
|
---|
671 | }
|
---|
672 |
|
---|
673 | private void tvClientControl_MouseUp(object sender, MouseEventArgs e) {
|
---|
674 | // If the right mouse button was clicked and released,
|
---|
675 | // display the shortcut menu assigned to the ListView.
|
---|
676 | contextMenuGroup.Items.Clear();
|
---|
677 | TreeViewHitTestInfo hitTestInfo = tvClientControl.HitTest(e.Location);
|
---|
678 | tvClientControl.SelectedNode = hitTestInfo.Node;
|
---|
679 | if (e.Button != MouseButtons.Right) return;
|
---|
680 | if (hitTestInfo.Node != null) {
|
---|
681 | ResourceDto selectedGroup = (ResourceDto)tvClientControl.SelectedNode.Tag;
|
---|
682 |
|
---|
683 | if (selectedGroup != null) {
|
---|
684 | contextMenuGroup.Items.Add(menuItemAddGroup);
|
---|
685 | contextMenuGroup.Items.Add(menuItemDeleteGroup);
|
---|
686 | contextMenuGroup.Items.Add(menuItemOpenCalendar);
|
---|
687 | }
|
---|
688 | } else {
|
---|
689 | contextMenuGroup.Items.Add(menuItemAddGroup);
|
---|
690 | }
|
---|
691 | tvClientControl.ContextMenuStrip.Show(tvClientControl, new Point(e.X, e.Y));
|
---|
692 | }
|
---|
693 |
|
---|
694 | private void addproject_AddProjectEvent(string name) {
|
---|
695 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
696 |
|
---|
697 | ProjectDto pg = new ProjectDto() { Name = name };
|
---|
698 | jobManager.CreateProject(pg);
|
---|
699 |
|
---|
700 | }
|
---|
701 |
|
---|
702 | private void addgroup_addGroupEvent(string name) {
|
---|
703 | ISlaveManager slaveManager = ServiceLocator.GetSlaveManager();
|
---|
704 |
|
---|
705 | if (parentgroup != Guid.Empty) {
|
---|
706 | SlaveGroupDto cg = new SlaveGroupDto() { Name = name };
|
---|
707 | ResponseObject<SlaveGroupDto> respcg = slaveManager.AddSlaveGroup(cg);
|
---|
708 | Response res = slaveManager.AddResourceToGroup(parentgroup, respcg.Obj);
|
---|
709 | if (res != null && res.StatusMessage != ResponseStatus.Ok) {
|
---|
710 | MessageBox.Show(res.StatusMessage.ToString(), "Error adding Group", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
711 | }
|
---|
712 | } else {
|
---|
713 | SlaveGroupDto cg = new SlaveGroupDto() { Name = name };
|
---|
714 | slaveManager.AddSlaveGroup(cg);
|
---|
715 | }
|
---|
716 | AddSlaves();
|
---|
717 | }
|
---|
718 |
|
---|
719 |
|
---|
720 | private void Refresh_Click(object sender, EventArgs e) {
|
---|
721 | Form overlayingForm = new Form();
|
---|
722 |
|
---|
723 | overlayingForm.Show();
|
---|
724 | overlayingForm.FormBorderStyle = FormBorderStyle.None;
|
---|
725 | overlayingForm.BackColor = Color.Gray;
|
---|
726 | overlayingForm.Opacity = 0.4;
|
---|
727 | overlayingForm.Size = this.Size;
|
---|
728 | overlayingForm.Location = this.Location;
|
---|
729 |
|
---|
730 | AddSlaves();
|
---|
731 |
|
---|
732 | overlayingForm.Close();
|
---|
733 | }
|
---|
734 |
|
---|
735 | private void largeIconsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
736 | lvClientControl.View = View.LargeIcon;
|
---|
737 | //lvJobControl.View = View.LargeIcon;
|
---|
738 | largeIconsToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
739 | smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
740 | listToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
741 | }
|
---|
742 |
|
---|
743 | private void smallIconsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
744 | lvClientControl.View = View.SmallIcon;
|
---|
745 | //lvJobControl.View = View.SmallIcon;
|
---|
746 | largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
747 | smallIconsToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
748 | listToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
749 | }
|
---|
750 |
|
---|
751 | private void listToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
752 | lvClientControl.View = View.List;
|
---|
753 | //lvJobControl.View = View.List;
|
---|
754 | largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
755 | smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
756 | listToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
757 | }
|
---|
758 |
|
---|
759 | private void tvClientControl_DragLeave(object sender, EventArgs e) {
|
---|
760 | foreach (TreeNode node in tvClientControl.Nodes) {
|
---|
761 | node.BackColor = Color.White;
|
---|
762 | node.ForeColor = Color.Black;
|
---|
763 | }
|
---|
764 | }
|
---|
765 | #endregion
|
---|
766 |
|
---|
767 | #region Helper methods
|
---|
768 |
|
---|
769 | private void CloneList(ResponseList<JobDto> oldList, out IDictionary<int, JobDto> newList) {
|
---|
770 | newList = new Dictionary<int, JobDto>();
|
---|
771 | if (oldList != null && oldList.List != null) {
|
---|
772 | for (int i = 0; i < oldList.List.Count; i++) {
|
---|
773 | newList.Add(i, oldList.List[i]);
|
---|
774 | }
|
---|
775 | }
|
---|
776 | }
|
---|
777 |
|
---|
778 | private bool IsEqual(SlaveDto ci1, SlaveDto ci2) {
|
---|
779 | if (ci1 == null && ci2 == null) {
|
---|
780 | return true;
|
---|
781 | }
|
---|
782 | if (ci2 == null) {
|
---|
783 | return false;
|
---|
784 | }
|
---|
785 | if (ci1.Id.Equals(ci2.Id)) {
|
---|
786 | return true;
|
---|
787 | } else return false;
|
---|
788 | }
|
---|
789 |
|
---|
790 | private int CapacityRam(int noCores, int freeCores) {
|
---|
791 | if (noCores > 0) {
|
---|
792 | int capacity = ((noCores - freeCores) / noCores) * 100;
|
---|
793 | return capacity;
|
---|
794 | }
|
---|
795 | return 100;
|
---|
796 | }
|
---|
797 |
|
---|
798 | private void GetDelta(IList<JobDto> oldJobs, IDictionary<int, JobDto> helpJobs) {
|
---|
799 | bool found = false;
|
---|
800 | for (int i = 0; i < jobs.List.Count; i++) {
|
---|
801 | JobDto job = jobs.List[i];
|
---|
802 | for (int j = 0; j < oldJobs.Count; j++) {
|
---|
803 |
|
---|
804 | JobDto jobold = oldJobs[j];
|
---|
805 |
|
---|
806 | if (job.Id.Equals(jobold.Id)) {
|
---|
807 |
|
---|
808 | found = true;
|
---|
809 | bool change = false;
|
---|
810 | if (job.State != jobold.State) {
|
---|
811 | change = true;
|
---|
812 | }
|
---|
813 | if (job.State != JobState.Offline) {
|
---|
814 | if ((!IsEqual(job.Slave, jobold.Slave)) || (job.State != jobold.State)
|
---|
815 | || (job.ExecutionTime != jobold.ExecutionTime)) {
|
---|
816 | change = true;
|
---|
817 | }
|
---|
818 | } else if (job.DateCalculated != jobold.DateCalculated) {
|
---|
819 | change = true;
|
---|
820 | }
|
---|
821 | if (change) {
|
---|
822 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update, Position = i });
|
---|
823 | }
|
---|
824 |
|
---|
825 | int removeAt = -1;
|
---|
826 | foreach (KeyValuePair<int, JobDto> kvp in helpJobs) {
|
---|
827 | if (job.Id.Equals(kvp.Value.Id)) {
|
---|
828 | removeAt = kvp.Key;
|
---|
829 | break;
|
---|
830 | }
|
---|
831 | }
|
---|
832 | if (removeAt >= 0) {
|
---|
833 | helpJobs.Remove(removeAt);
|
---|
834 | }
|
---|
835 | break;
|
---|
836 | }
|
---|
837 |
|
---|
838 | }
|
---|
839 | if (found == false) {
|
---|
840 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Create });
|
---|
841 | }
|
---|
842 | found = false;
|
---|
843 | }
|
---|
844 | foreach (KeyValuePair<int, JobDto> kvp in helpJobs) {
|
---|
845 | changes.Add(new Changes { Types = Type.Job, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
|
---|
846 | }
|
---|
847 | }
|
---|
848 |
|
---|
849 | #endregion
|
---|
850 |
|
---|
851 | private void btn_prev_Click(object sender, EventArgs e) {
|
---|
852 | if (sender == btn_finishedJob_prev)
|
---|
853 | jdfFinished.Backward();
|
---|
854 | else if (sender == btn_calculatingJobs_prev)
|
---|
855 | jdfCalculating.Backward();
|
---|
856 | else if (sender == btn_offlinejob_prev) {
|
---|
857 | jdfOffline.Backward();
|
---|
858 | }
|
---|
859 | }
|
---|
860 |
|
---|
861 | private void btn_next_Click(object sender, EventArgs e) {
|
---|
862 | if (sender == btn_finishedJob_next)
|
---|
863 | jdfFinished.Forward();
|
---|
864 | else if (sender == btn_calculatingJobs_next)
|
---|
865 | jdfCalculating.Forward();
|
---|
866 | else if (sender == btn_offlineJob_next) {
|
---|
867 | jdfOffline.Forward();
|
---|
868 | }
|
---|
869 | }
|
---|
870 |
|
---|
871 | private void cmb_count_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
872 | ComboBox box = (ComboBox)sender;
|
---|
873 | if (box.SelectedItem != null) {
|
---|
874 | int val;
|
---|
875 | if (Int32.TryParse(box.SelectedItem.ToString(), out val)) {
|
---|
876 | if (box == cmb_offlineJob_count) {
|
---|
877 | jdfOffline.NrOfEntriesOnPage = val;
|
---|
878 | } else if (box == cmb_finishedJob_count) {
|
---|
879 | jdfFinished.NrOfEntriesOnPage = val;
|
---|
880 | } else if (box == cmb_calculatingJob_count) {
|
---|
881 | jdfCalculating.NrOfEntriesOnPage = val;
|
---|
882 | }
|
---|
883 | }
|
---|
884 | }
|
---|
885 | }
|
---|
886 |
|
---|
887 | private void lv_Jobs_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
888 | ListView lv = (ListView)sender;
|
---|
889 | if (lv.SelectedItems.Count > 0) {
|
---|
890 | foreach (ListViewItem lvi in lv.SelectedItems) {
|
---|
891 | currentJob = (JobDto)lvi.Tag;
|
---|
892 | JobClicked();
|
---|
893 | }
|
---|
894 | }
|
---|
895 | }
|
---|
896 | }
|
---|
897 | } |
---|