1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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.Data;
|
---|
26 | using System.Drawing;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
31 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
32 | using HeuristicLab.Hive.Contracts;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
35 |
|
---|
36 | public delegate void closeForm(bool cf, bool error);
|
---|
37 |
|
---|
38 | public partial class HiveServerManagementConsole : Form {
|
---|
39 |
|
---|
40 | public event closeForm closeFormEvent;
|
---|
41 |
|
---|
42 | #region private variables
|
---|
43 | private ResponseList<ClientGroup> clients = null;
|
---|
44 | private ResponseList<ClientInfo> clientInfo = null;
|
---|
45 | private ResponseList<Job> jobs = null;
|
---|
46 |
|
---|
47 | private Dictionary<Guid, ListViewGroup> clientObjects;
|
---|
48 | private Dictionary<Guid, ListViewItem> clientInfoObjects;
|
---|
49 | private Dictionary<Guid, ListViewItem> jobObjects;
|
---|
50 |
|
---|
51 | private Job currentJob = null;
|
---|
52 | private ClientInfo currentClient = null;
|
---|
53 | private string nameCurrentJob = "";
|
---|
54 | private string nameCurrentClient = "";
|
---|
55 | private bool flagJob = false;
|
---|
56 | private bool flagClient = false;
|
---|
57 |
|
---|
58 | private List<Changes> changes = new List<Changes>();
|
---|
59 |
|
---|
60 | private ToolTip tt = new ToolTip();
|
---|
61 | #endregion
|
---|
62 |
|
---|
63 | public HiveServerManagementConsole() {
|
---|
64 | InitializeComponent();
|
---|
65 | AddClients();
|
---|
66 | AddJobs();
|
---|
67 | timerSyncronize.Start();
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | #region Backgroundworker
|
---|
72 | /// <summary>
|
---|
73 | /// event on Ticker
|
---|
74 | /// </summary>
|
---|
75 | /// <param name="obj"></param>
|
---|
76 | /// <param name="e"></param>
|
---|
77 | private void TickSync(object obj, EventArgs e) {
|
---|
78 | if (!updaterWoker.IsBusy) {
|
---|
79 | updaterWoker.RunWorkerAsync();
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void updaterWoker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
84 | Refresh();
|
---|
85 | }
|
---|
86 |
|
---|
87 | #endregion
|
---|
88 |
|
---|
89 | /// <summary>
|
---|
90 | /// Adds clients to ListView and TreeView
|
---|
91 | /// </summary>
|
---|
92 | private void AddClients() {
|
---|
93 | try {
|
---|
94 | clientObjects = new Dictionary<Guid, ListViewGroup>();
|
---|
95 | clientInfoObjects = new Dictionary<Guid, ListViewItem>();
|
---|
96 | IClientManager clientManager =
|
---|
97 | ServiceLocator.GetClientManager();
|
---|
98 |
|
---|
99 | clients = clientManager.GetAllClientGroups();
|
---|
100 | lvClientControl.Items.Clear();
|
---|
101 | List<Guid> inGroup = new List<Guid>();
|
---|
102 | foreach (ClientGroup cg in clients.List) {
|
---|
103 | ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
|
---|
104 | foreach (ClientInfo ci in cg.Resources) {
|
---|
105 | ListViewItem item = null;
|
---|
106 | if ((ci.State == State.offline) || (ci.State == State.nullState)) {
|
---|
107 | item = new ListViewItem(ci.Name, 3, lvg);
|
---|
108 | } else {
|
---|
109 | int percentageUsage = CapacityRam(ci.NrOfCores, ci.NrOfFreeCores);
|
---|
110 | int usage = 0;
|
---|
111 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
112 | usage = 0;
|
---|
113 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
114 | usage = 1;
|
---|
115 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
116 | usage = 2;
|
---|
117 | }
|
---|
118 |
|
---|
119 | item = new ListViewItem(ci.Name, usage, lvg);
|
---|
120 | }
|
---|
121 | item.Tag = ci.Id;
|
---|
122 | lvClientControl.Items.Add(item);
|
---|
123 | clientInfoObjects.Add(ci.Id, item);
|
---|
124 | inGroup.Add(ci.Id);
|
---|
125 |
|
---|
126 | }
|
---|
127 | lvClientControl.BeginUpdate();
|
---|
128 | lvClientControl.Groups.Add(lvg);
|
---|
129 | lvClientControl.EndUpdate();
|
---|
130 | clientObjects.Add(cg.Id, lvg);
|
---|
131 | } // Groups
|
---|
132 |
|
---|
133 | clientInfo = clientManager.GetAllClients();
|
---|
134 | ListViewGroup lvunsorted = new ListViewGroup("no group", HorizontalAlignment.Left);
|
---|
135 | foreach (ClientInfo ci in clientInfo.List) {
|
---|
136 | bool help = false;
|
---|
137 | foreach (Guid client in inGroup) {
|
---|
138 | if (client == ci.Id) {
|
---|
139 | help = true;
|
---|
140 | break;
|
---|
141 | }
|
---|
142 | }
|
---|
143 | if (!help) {
|
---|
144 | ListViewItem item = null;
|
---|
145 | if ((ci.State == State.offline) || (ci.State == State.nullState)) {
|
---|
146 | item = new ListViewItem(ci.Name, 3, lvunsorted);
|
---|
147 | } else {
|
---|
148 | int percentageUsage = CapacityRam(ci.NrOfCores, ci.NrOfFreeCores);
|
---|
149 | int usage = 0;
|
---|
150 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
151 | usage = 0;
|
---|
152 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
153 | usage = 1;
|
---|
154 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
155 | usage = 2;
|
---|
156 | }
|
---|
157 | item = new ListViewItem(ci.Name, usage, lvunsorted);
|
---|
158 | }
|
---|
159 | item.Tag = ci.Id;
|
---|
160 | lvClientControl.Items.Add(item);
|
---|
161 | }
|
---|
162 | }
|
---|
163 | lvClientControl.BeginUpdate();
|
---|
164 | lvClientControl.Groups.Add(lvunsorted);
|
---|
165 | lvClientControl.EndUpdate();
|
---|
166 | if (flagClient) {
|
---|
167 | ClientClicked();
|
---|
168 | }
|
---|
169 | }
|
---|
170 | catch (Exception ex) {
|
---|
171 | closeFormEvent(true, true);
|
---|
172 | this.Close();
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | List<ListViewGroup> jobGroup;
|
---|
178 | /// <summary>
|
---|
179 | /// Adds jobs to ListView and TreeView
|
---|
180 | /// </summary>
|
---|
181 | private void AddJobs() {
|
---|
182 | try {
|
---|
183 | jobObjects = new Dictionary<Guid, ListViewItem>();
|
---|
184 | IJobManager jobManager =
|
---|
185 | ServiceLocator.GetJobManager();
|
---|
186 | jobs = jobManager.GetAllJobs();
|
---|
187 |
|
---|
188 | lvJobControl.Items.Clear();
|
---|
189 |
|
---|
190 | ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
|
---|
191 | ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
|
---|
192 | ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
|
---|
193 |
|
---|
194 | jobGroup = new List<ListViewGroup>();
|
---|
195 | jobGroup.Add(lvJobCalculating);
|
---|
196 | jobGroup.Add(lvJobFinished);
|
---|
197 | jobGroup.Add(lvJobPending);
|
---|
198 |
|
---|
199 | foreach (Job job in jobs.List) {
|
---|
200 | if (job.State == State.calculating) {
|
---|
201 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);
|
---|
202 | jobObjects.Add(job.Id, lvi);
|
---|
203 |
|
---|
204 | //lvJobControl.Items.Add(lvi);
|
---|
205 |
|
---|
206 | lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
|
---|
207 | } else if (job.State == State.finished) {
|
---|
208 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
|
---|
209 | jobObjects.Add(job.Id, lvi);
|
---|
210 | //lvJobControl.Items.Add(lvi);
|
---|
211 | } else if (job.State == State.offline) {
|
---|
212 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);
|
---|
213 | jobObjects.Add(job.Id, lvi);
|
---|
214 | //lvJobControl.Items.Add(lvi);
|
---|
215 | }
|
---|
216 | } // Jobs
|
---|
217 | lvJobControl.BeginUpdate();
|
---|
218 | foreach (ListViewItem lvi in jobObjects.Values) {
|
---|
219 | lvJobControl.Items.Add(lvi);
|
---|
220 | }
|
---|
221 | lvJobControl.Groups.Add(lvJobCalculating);
|
---|
222 | lvJobControl.Groups.Add(lvJobFinished);
|
---|
223 | lvJobControl.Groups.Add(lvJobPending);
|
---|
224 | lvJobControl.EndUpdate();
|
---|
225 | if (flagJob) {
|
---|
226 | JobClicked();
|
---|
227 | }
|
---|
228 | }
|
---|
229 | catch (Exception ex) {
|
---|
230 | closeFormEvent(true, true);
|
---|
231 | this.Close();
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | /// <summary>
|
---|
236 | /// if one client is clicked, the details for the clicked client are shown
|
---|
237 | /// in the second panel
|
---|
238 | /// </summary>
|
---|
239 | private void ClientClicked() {
|
---|
240 | plClientDetails.Visible = true;
|
---|
241 | int i = 0;
|
---|
242 | while (clientInfo.List[i].Id.ToString() != nameCurrentClient) {
|
---|
243 | i++;
|
---|
244 | }
|
---|
245 | currentClient = clientInfo.List[i];
|
---|
246 | int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
|
---|
247 | int usage = 3;
|
---|
248 | if ((currentClient.State != State.offline) && (currentClient.State != State.nullState)) {
|
---|
249 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
250 | usage = 0;
|
---|
251 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
252 | usage = 1;
|
---|
253 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
254 | usage = 2;
|
---|
255 | }
|
---|
256 | }
|
---|
257 | pbClientControl.Image = ilClientControl.Images[usage];
|
---|
258 | lblClientName.Text = currentClient.Name;
|
---|
259 | lblLogin.Text = currentClient.Login.ToString();
|
---|
260 | lblState.Text = currentClient.State.ToString();
|
---|
261 | }
|
---|
262 |
|
---|
263 | /// <summary>
|
---|
264 | /// if one job is clicked, the details for the clicked job are shown
|
---|
265 | /// in the second panel
|
---|
266 | /// </summary>
|
---|
267 | private void JobClicked() {
|
---|
268 | plJobDetails.Visible = true;
|
---|
269 | int i = 0;
|
---|
270 | while (jobs.List[i].Id.ToString() != nameCurrentJob) {
|
---|
271 | i++;
|
---|
272 | }
|
---|
273 | lvSnapshots.Enabled = true;
|
---|
274 | currentJob = jobs.List[i];
|
---|
275 | pbJobControl.Image = ilJobControl.Images[0];
|
---|
276 | lblJobName.Text = currentJob.Id.ToString();
|
---|
277 | progressJob.Value = (int)(currentJob.Percentage * 100);
|
---|
278 | lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
|
---|
279 | lblUserCreatedJob.Text = currentJob.UserId.ToString() + /* currentJob.User.Name + */ " created Job";
|
---|
280 | lblJobCreated.Text = "Created at " + currentJob.DateCreated;
|
---|
281 | if (currentJob.ParentJob != null) {
|
---|
282 | lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
|
---|
283 | } else {
|
---|
284 | lblParentJob.Text = "";
|
---|
285 | }
|
---|
286 | lblPriorityJob.Text = "Priority of job is " + currentJob.Priority;
|
---|
287 | if (currentJob.Client != null) {
|
---|
288 | lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
|
---|
289 | lblJobCalculationBegin.Text = "Startet calculation at " + currentJob.DateCalculated;
|
---|
290 |
|
---|
291 | if (currentJob.State == State.finished) {
|
---|
292 | IJobManager jobManager =
|
---|
293 | ServiceLocator.GetJobManager();
|
---|
294 | ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
|
---|
295 | lblJobCalculationEnd.Text = "Calculation ended at " + jobRes.Obj.DateFinished;
|
---|
296 | }
|
---|
297 | } else {
|
---|
298 | lblClientCalculating.Text = "";
|
---|
299 | lblJobCalculationBegin.Text = "";
|
---|
300 | lblJobCalculationEnd.Text = "";
|
---|
301 | }
|
---|
302 | if (currentJob.State != State.offline) {
|
---|
303 | lvSnapshots.Items.Clear();
|
---|
304 | if (currentJob.State == State.finished)
|
---|
305 | GetSnapshotList();
|
---|
306 | lvSnapshots.Visible = true;
|
---|
307 | } else {
|
---|
308 | lvSnapshots.Visible = false;
|
---|
309 | }
|
---|
310 | }
|
---|
311 |
|
---|
312 | private void Refresh() {
|
---|
313 | foreach (Changes change in changes) {
|
---|
314 | if (change.Types == Type.Job) {
|
---|
315 | RefreshJob(change);
|
---|
316 | } else if (change.Types == Type.Client) {
|
---|
317 | RefreshClient(change);
|
---|
318 | } else if (change.Types == Type.ClientGroup) {
|
---|
319 | RefreshClientGroup(change);
|
---|
320 | }
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | private void RefreshJob(Changes change) {
|
---|
325 | if (change.ChangeType == Change.Update) {
|
---|
326 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
327 | if (lvJobControl.Items[i].Text == change.ID.ToString()) {
|
---|
328 | if (nameCurrentJob == change.ID.ToString()) {
|
---|
329 | JobClicked();
|
---|
330 | }
|
---|
331 | State state = jobs.List[change.Position].State;
|
---|
332 | System.Diagnostics.Debug.WriteLine(lvJobControl.Items[i].Text.ToString());
|
---|
333 | if (state == State.finished) {
|
---|
334 | lvJobControl.Items[i].Group = jobGroup[1];
|
---|
335 | System.Diagnostics.Debug.WriteLine("finished");
|
---|
336 | } else if (state == State.calculating) {
|
---|
337 | lvJobControl.Items[i].Group = jobGroup[0];
|
---|
338 | System.Diagnostics.Debug.WriteLine("calculating");
|
---|
339 | } else if (state == State.offline) {
|
---|
340 | lvJobControl.Items[i].Group = jobGroup[2];
|
---|
341 | System.Diagnostics.Debug.WriteLine("offline");
|
---|
342 |
|
---|
343 | }
|
---|
344 | lvJobControl.Refresh();
|
---|
345 | }
|
---|
346 | }
|
---|
347 | } else if (change.ChangeType == Change.Create) {
|
---|
348 | ListViewItem lvi = new ListViewItem(
|
---|
349 | change.ID.ToString(), 0, jobGroup[2]);
|
---|
350 | jobObjects.Add(change.ID, lvi);
|
---|
351 | lvJobControl.Items.Add(lvi);
|
---|
352 |
|
---|
353 | } else if (change.ChangeType == Change.Delete) {
|
---|
354 | jobObjects.Remove(change.ID);
|
---|
355 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
356 | if (change.ID.ToString() == lvJobControl.Items[i].Text.ToString()) {
|
---|
357 | lvJobControl.Items[i].Remove();
|
---|
358 | break;
|
---|
359 | }
|
---|
360 | }
|
---|
361 | }
|
---|
362 | }
|
---|
363 |
|
---|
364 | private void RefreshClient(Changes change) {
|
---|
365 | if (change.ChangeType == Change.Update) {
|
---|
366 | for (int i = 0; i < lvClientControl.Items.Count; i++) {
|
---|
367 | if (lvClientControl.Items[i].Tag.ToString() == change.ID.ToString()) {
|
---|
368 | if (nameCurrentClient == change.ID.ToString()) {
|
---|
369 | ClientClicked();
|
---|
370 | }
|
---|
371 | State state = clientInfo.List[change.Position].State;
|
---|
372 | System.Diagnostics.Debug.WriteLine(lvClientControl.Items[i].Text.ToString());
|
---|
373 | int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
|
---|
374 | if ((state == State.offline) || (state == State.nullState)) {
|
---|
375 | lvClientControl.Items[i].ImageIndex = 3;
|
---|
376 | } else {
|
---|
377 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
378 | lvClientControl.Items[i].ImageIndex = 0;
|
---|
379 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
380 | lvClientControl.Items[i].ImageIndex = 1;
|
---|
381 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
382 | lvClientControl.Items[i].ImageIndex = 2;
|
---|
383 | }
|
---|
384 |
|
---|
385 | }
|
---|
386 | lvClientControl.Refresh();
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 |
|
---|
391 | } else if (change.ChangeType == Change.Create) {
|
---|
392 |
|
---|
393 | } else if (change.ChangeType == Change.Delete) {
|
---|
394 | clientInfoObjects.Remove(change.ID);
|
---|
395 | for (int i = 0; i < lvClientControl.Items.Count; i++) {
|
---|
396 | if (change.ID.ToString() == lvClientControl.Items[i].Text.ToString()) {
|
---|
397 | lvClientControl.Items[i].Remove();
|
---|
398 | break;
|
---|
399 | }
|
---|
400 | }
|
---|
401 |
|
---|
402 | }
|
---|
403 | }
|
---|
404 |
|
---|
405 | private void RefreshClientGroup(Changes change) {
|
---|
406 |
|
---|
407 | }
|
---|
408 |
|
---|
409 | #region Eventhandlers
|
---|
410 | /// <summary>
|
---|
411 | /// Send event to Login-GUI when closing
|
---|
412 | /// </summary>
|
---|
413 | /// <param name="sender"></param>
|
---|
414 | /// <param name="e"></param>
|
---|
415 | private void Close_Click(object sender, EventArgs e) {
|
---|
416 | if (closeFormEvent != null) {
|
---|
417 | closeFormEvent(true, false);
|
---|
418 | }
|
---|
419 | this.Close();
|
---|
420 | }
|
---|
421 |
|
---|
422 | /// <summary>
|
---|
423 | /// Send evnt to Login-GUI when closing
|
---|
424 | /// </summary>
|
---|
425 | /// <param name="sender"></param>
|
---|
426 | /// <param name="e"></param>
|
---|
427 | private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
428 | if (closeFormEvent != null) {
|
---|
429 | closeFormEvent(true, false);
|
---|
430 | }
|
---|
431 | }
|
---|
432 |
|
---|
433 | private void AddJob_Click(object sender, EventArgs e) {
|
---|
434 | AddJobForm newForm = new AddJobForm();
|
---|
435 | newForm.Show();
|
---|
436 | newForm.addJobEvent += new addDelegate(updaterWoker.RunWorkerAsync);
|
---|
437 | }
|
---|
438 |
|
---|
439 | private void OnLVClientClicked(object sender, EventArgs e) {
|
---|
440 | nameCurrentClient = lvClientControl.SelectedItems[0].Tag.ToString();
|
---|
441 | flagClient = true;
|
---|
442 | ClientClicked();
|
---|
443 | }
|
---|
444 |
|
---|
445 | private void OnLVJobControlClicked(object sender, EventArgs e) {
|
---|
446 | nameCurrentJob = lvJobControl.SelectedItems[0].Text;
|
---|
447 | flagJob = true;
|
---|
448 | JobClicked();
|
---|
449 | }
|
---|
450 |
|
---|
451 | private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
|
---|
452 | if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
|
---|
453 | (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
|
---|
454 | tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
|
---|
455 | }
|
---|
456 | }
|
---|
457 |
|
---|
458 | private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
459 |
|
---|
460 | changes.Clear();
|
---|
461 | IClientManager clientManager =
|
---|
462 | ServiceLocator.GetClientManager();
|
---|
463 |
|
---|
464 | #region ClientInfo
|
---|
465 | ResponseList<ClientInfo> clientInfoOld = clientInfo;
|
---|
466 | clientInfo = clientManager.GetAllClients();
|
---|
467 |
|
---|
468 | IDictionary<int, ClientInfo> clientInfoOldHelp;
|
---|
469 |
|
---|
470 | CloneList(clientInfoOld, out clientInfoOldHelp);
|
---|
471 |
|
---|
472 | GetDelta(clientInfoOld.List, clientInfoOldHelp);
|
---|
473 | #endregion
|
---|
474 |
|
---|
475 | #region Clients
|
---|
476 | ResponseList<ClientGroup> clientsOld = clients;
|
---|
477 |
|
---|
478 | clients = clientManager.GetAllClientGroups();
|
---|
479 |
|
---|
480 | IDictionary<int, ClientGroup> clientsOldHelp;
|
---|
481 |
|
---|
482 | CloneList(clientsOld, out clientsOldHelp);
|
---|
483 |
|
---|
484 | GetDelta(clientsOld.List, clientsOldHelp);
|
---|
485 | #endregion
|
---|
486 |
|
---|
487 | #region Job
|
---|
488 | ResponseList<Job> jobsOld = jobs;
|
---|
489 | IJobManager jobManager =
|
---|
490 | ServiceLocator.GetJobManager();
|
---|
491 |
|
---|
492 | jobs = jobManager.GetAllJobs();
|
---|
493 |
|
---|
494 | IDictionary<int, Job> jobsOldHelp;
|
---|
495 | CloneList(jobsOld, out jobsOldHelp);
|
---|
496 |
|
---|
497 | GetDelta(jobsOld.List, jobsOldHelp);
|
---|
498 |
|
---|
499 | #endregion
|
---|
500 |
|
---|
501 | foreach (Changes change in changes) {
|
---|
502 | System.Diagnostics.Debug.WriteLine(change.ID + " " + change.ChangeType);
|
---|
503 | }
|
---|
504 |
|
---|
505 | }
|
---|
506 | #endregion
|
---|
507 |
|
---|
508 | #region Helper methods
|
---|
509 |
|
---|
510 | private void CloneList(ResponseList<Job> oldList, out IDictionary<int, Job> newList) {
|
---|
511 | newList = new Dictionary<int, Job>();
|
---|
512 | for (int i = 0; i < oldList.List.Count; i++) {
|
---|
513 | newList.Add(i, oldList.List[i]);
|
---|
514 | }
|
---|
515 | }
|
---|
516 |
|
---|
517 | private void CloneList(ResponseList<ClientInfo> oldList, out IDictionary<int, ClientInfo> newList) {
|
---|
518 | newList = new Dictionary<int, ClientInfo>();
|
---|
519 | for (int i = 0; i < oldList.List.Count; i++) {
|
---|
520 | newList.Add(i, oldList.List[i]);
|
---|
521 | }
|
---|
522 | }
|
---|
523 |
|
---|
524 | private void CloneList(ResponseList<ClientGroup> oldList, out IDictionary<int, ClientGroup> newList) {
|
---|
525 | newList = new Dictionary<int, ClientGroup>();
|
---|
526 | for (int i = 0; i < oldList.List.Count; i++) {
|
---|
527 | newList.Add(i, oldList.List[i]);
|
---|
528 | }
|
---|
529 | }
|
---|
530 |
|
---|
531 | private bool IsEqual(ClientInfo ci1, ClientInfo ci2) {
|
---|
532 | if (ci2 == null) {
|
---|
533 | return false;
|
---|
534 | }
|
---|
535 | if (ci1.Id.Equals(ci2.Id)) {
|
---|
536 | return true;
|
---|
537 | } else return false;
|
---|
538 | }
|
---|
539 |
|
---|
540 | private int CapacityRam(int noCores, int freeCores) {
|
---|
541 | int capacity = ((noCores - freeCores) / noCores) * 100;
|
---|
542 | System.Diagnostics.Debug.WriteLine(capacity);
|
---|
543 | return capacity;
|
---|
544 | }
|
---|
545 |
|
---|
546 | private void GetDelta(IList<ClientInfo> oldClient, IDictionary<int, ClientInfo> helpClients) {
|
---|
547 | bool found = false;
|
---|
548 |
|
---|
549 | for (int i = 0; i < clientInfo.List.Count; i++) {
|
---|
550 | ClientInfo ci = clientInfo.List[i];
|
---|
551 | for (int j = 0; j < oldClient.Count; j++) {
|
---|
552 | ClientInfo cio = oldClient[j];
|
---|
553 | if (ci.Id.Equals(cio.Id)) {
|
---|
554 | found = true;
|
---|
555 | if ((ci.State != cio.State) || (ci.NrOfFreeCores != ci.NrOfFreeCores)) {
|
---|
556 | changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Update, Position = i });
|
---|
557 | }
|
---|
558 | int removeAt = -1;
|
---|
559 | foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) {
|
---|
560 | if (cio.Id.Equals(kvp.Value.Id)) {
|
---|
561 | removeAt = kvp.Key;
|
---|
562 | break;
|
---|
563 | }
|
---|
564 | }
|
---|
565 | if (removeAt >= 0) {
|
---|
566 | helpClients.Remove(removeAt);
|
---|
567 | }
|
---|
568 | break;
|
---|
569 | }
|
---|
570 | }
|
---|
571 | if (found == false) {
|
---|
572 | changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Create });
|
---|
573 | }
|
---|
574 | found = false;
|
---|
575 | }
|
---|
576 | foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) {
|
---|
577 | changes.Add(new Changes { Types = Type.Client, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
|
---|
578 | }
|
---|
579 |
|
---|
580 | }
|
---|
581 |
|
---|
582 | private void GetDelta(IList<ClientGroup> oldClient, IDictionary<int, ClientGroup> helpClients) {
|
---|
583 |
|
---|
584 | bool found = false;
|
---|
585 | for (int i = 0; i < clients.List.Count; i++) {
|
---|
586 | ClientGroup cg = clients.List[i];
|
---|
587 | for (int j = 0; j < oldClient.Count; i++) {
|
---|
588 | ClientGroup cgo = oldClient[j];
|
---|
589 | if (cg.Id.Equals(cgo.Id)) {
|
---|
590 | found = true;
|
---|
591 | foreach (Resource resource in cg.Resources) {
|
---|
592 | foreach (Resource resourceold in cgo.Resources) {
|
---|
593 | if (resource.Id.Equals(resourceold.Id)) {
|
---|
594 | if (resourceold.Name != resource.Name) {
|
---|
595 | changes.Add(new Changes { Types = Type.Client, ID = cg.Id, ChangeType = Change.Update, Position = i });
|
---|
596 | }
|
---|
597 | }
|
---|
598 | }
|
---|
599 | }
|
---|
600 | for (int k = 0; k < helpClients.Count; k++) {
|
---|
601 | if (cgo.Id.Equals(helpClients[k].Id)) {
|
---|
602 | helpClients.Remove(k);
|
---|
603 | break;
|
---|
604 | }
|
---|
605 | }
|
---|
606 | break;
|
---|
607 | }
|
---|
608 | }
|
---|
609 | if (found == false) {
|
---|
610 | changes.Add(new Changes { Types = Type.ClientGroup, ID = cg.Id, ChangeType = Change.Create });
|
---|
611 | }
|
---|
612 | found = false;
|
---|
613 | }
|
---|
614 | foreach (KeyValuePair<int, ClientGroup> kvp in helpClients) {
|
---|
615 | changes.Add(new Changes { Types = Type.ClientGroup, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
|
---|
616 | }
|
---|
617 | }
|
---|
618 |
|
---|
619 | private void GetDelta(IList<Job> oldJobs, IDictionary<int, Job> helpJobs) {
|
---|
620 | bool found = false;
|
---|
621 | for (int i = 0; i < jobs.List.Count; i++) {
|
---|
622 | Job job = jobs.List[i];
|
---|
623 | for (int j = 0; j < oldJobs.Count; j++) {
|
---|
624 |
|
---|
625 | Job jobold = oldJobs[j];
|
---|
626 |
|
---|
627 | if (job.Id.Equals(jobold.Id)) {
|
---|
628 |
|
---|
629 | found = true;
|
---|
630 | if (job.State != State.offline) {
|
---|
631 | if ((!IsEqual(job.Client, jobold.Client)) || (job.State != jobold.State)
|
---|
632 | || (job.Percentage != jobold.Percentage)) {
|
---|
633 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update, Position = i });
|
---|
634 | }
|
---|
635 | } else if (job.DateCalculated != jobold.DateCalculated) {
|
---|
636 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update, Position = i });
|
---|
637 | }
|
---|
638 |
|
---|
639 | int removeAt = -1;
|
---|
640 | foreach (KeyValuePair<int, Job> kvp in helpJobs) {
|
---|
641 | if (job.Id.Equals(kvp.Value.Id)) {
|
---|
642 | removeAt = kvp.Key;
|
---|
643 | break;
|
---|
644 | }
|
---|
645 | }
|
---|
646 | if (removeAt >= 0) {
|
---|
647 | helpJobs.Remove(removeAt);
|
---|
648 | }
|
---|
649 | break;
|
---|
650 | }
|
---|
651 |
|
---|
652 | }
|
---|
653 | if (found == false) {
|
---|
654 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Create });
|
---|
655 | System.Diagnostics.Debug.WriteLine("new Job: " + job.Id);
|
---|
656 | }
|
---|
657 | found = false;
|
---|
658 | }
|
---|
659 | foreach (KeyValuePair<int, Job> kvp in helpJobs) {
|
---|
660 | changes.Add(new Changes { Types = Type.Job, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
|
---|
661 | System.Diagnostics.Debug.WriteLine("delete Job: " + kvp.Value.Id);
|
---|
662 | }
|
---|
663 | }
|
---|
664 |
|
---|
665 | private void GetSnapshotList() {
|
---|
666 |
|
---|
667 | lvSnapshots.Items.Clear();
|
---|
668 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
669 |
|
---|
670 | ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
|
---|
671 |
|
---|
672 | // iterate threw all snapshots if method is implemented
|
---|
673 |
|
---|
674 | ListViewItem curSnapshot = new ListViewItem(jobRes.Obj.Client.Name);
|
---|
675 | double percentage = jobRes.Obj.Percentage * 100;
|
---|
676 | curSnapshot.SubItems.Add(percentage.ToString() + " %");
|
---|
677 | curSnapshot.SubItems.Add(jobRes.Obj.timestamp.ToString());
|
---|
678 | lvSnapshots.Items.Add(curSnapshot);
|
---|
679 | }
|
---|
680 |
|
---|
681 | #endregion
|
---|
682 |
|
---|
683 | }
|
---|
684 | } |
---|