1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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.Threading;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Clients.Hive.WebJobManager.Services;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Clients.Hive
|
---|
29 | {
|
---|
30 | [Item("Hive Administrator", "Hive Administrator")]
|
---|
31 | public sealed class HiveAdminClientWeb : IContent
|
---|
32 | {
|
---|
33 | private WebLoginService weblog;
|
---|
34 | private HiveServiceLocatorWeb servloc;
|
---|
35 | public Guid userId { get; set; }
|
---|
36 | public HiveAdminClientWeb(Guid uid) {
|
---|
37 | weblog = WebLoginService.Instance;
|
---|
38 | userId = uid;
|
---|
39 | servloc = weblog.getServiceLocator(uid);
|
---|
40 |
|
---|
41 | }
|
---|
42 |
|
---|
43 | private IItemList<Resource> resources;
|
---|
44 | public IItemList<Resource> Resources
|
---|
45 | {
|
---|
46 | get { return resources; }
|
---|
47 | }
|
---|
48 |
|
---|
49 | private IItemList<Downtime> downtimes;
|
---|
50 | public IItemList<Downtime> Downtimes
|
---|
51 | {
|
---|
52 | get { return downtimes; }
|
---|
53 | }
|
---|
54 |
|
---|
55 | private Guid downtimeForResourceId;
|
---|
56 | public Guid DowntimeForResourceId
|
---|
57 | {
|
---|
58 | get { return downtimeForResourceId; }
|
---|
59 | set
|
---|
60 | {
|
---|
61 | downtimeForResourceId = value;
|
---|
62 | if (downtimes != null)
|
---|
63 | {
|
---|
64 | downtimes.Clear();
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | #region Events
|
---|
70 | public event EventHandler Refreshing;
|
---|
71 | private void OnRefreshing()
|
---|
72 | {
|
---|
73 | EventHandler handler = Refreshing;
|
---|
74 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
75 | }
|
---|
76 | public event EventHandler Refreshed;
|
---|
77 | private void OnRefreshed()
|
---|
78 | {
|
---|
79 | var handler = Refreshed;
|
---|
80 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
81 | }
|
---|
82 | #endregion
|
---|
83 |
|
---|
84 |
|
---|
85 |
|
---|
86 | #region Refresh
|
---|
87 | public void Refresh()
|
---|
88 | {
|
---|
89 | OnRefreshing();
|
---|
90 |
|
---|
91 | try
|
---|
92 | {
|
---|
93 | resources = new ItemList<Resource>();
|
---|
94 |
|
---|
95 | servloc.CallHiveService(service =>
|
---|
96 | {
|
---|
97 | service.GetSlaveGroups().ForEach(g => resources.Add(g));
|
---|
98 | service.GetSlaves().ForEach(s => resources.Add(s));
|
---|
99 | });
|
---|
100 | }
|
---|
101 | catch
|
---|
102 | {
|
---|
103 | throw;
|
---|
104 | }
|
---|
105 | finally
|
---|
106 | {
|
---|
107 | OnRefreshed();
|
---|
108 | }
|
---|
109 | }
|
---|
110 | #endregion
|
---|
111 |
|
---|
112 | #region Refresh downtime calendar
|
---|
113 | public void RefreshCalendar()
|
---|
114 | {
|
---|
115 | if (downtimeForResourceId != null && downtimeForResourceId != Guid.Empty)
|
---|
116 | {
|
---|
117 | OnRefreshing();
|
---|
118 |
|
---|
119 | try
|
---|
120 | {
|
---|
121 | downtimes = new ItemList<Downtime>();
|
---|
122 |
|
---|
123 | servloc.CallHiveService(service =>
|
---|
124 | {
|
---|
125 | service.GetDowntimesForResource(downtimeForResourceId).ForEach(d => downtimes.Add(d));
|
---|
126 | });
|
---|
127 | }
|
---|
128 | catch
|
---|
129 | {
|
---|
130 | throw;
|
---|
131 | }
|
---|
132 | finally
|
---|
133 | {
|
---|
134 | OnRefreshed();
|
---|
135 | }
|
---|
136 | }
|
---|
137 | }
|
---|
138 | #endregion
|
---|
139 |
|
---|
140 | #region Store
|
---|
141 | public void Store(IHiveItem item, CancellationToken cancellationToken)
|
---|
142 | {
|
---|
143 | if (item.Id == Guid.Empty)
|
---|
144 | {
|
---|
145 | if (item is SlaveGroup)
|
---|
146 | {
|
---|
147 | item.Id = servloc.CallHiveService((s) => s.AddSlaveGroup((SlaveGroup)item));
|
---|
148 | }
|
---|
149 | if (item is Slave)
|
---|
150 | {
|
---|
151 | item.Id = servloc.CallHiveService((s) => s.AddSlave((Slave)item));
|
---|
152 | }
|
---|
153 | if (item is Downtime)
|
---|
154 | {
|
---|
155 | item.Id = servloc.CallHiveService((s) => s.AddDowntime((Downtime)item));
|
---|
156 | }
|
---|
157 | }
|
---|
158 | else
|
---|
159 | {
|
---|
160 | if (item is SlaveGroup)
|
---|
161 | {
|
---|
162 | servloc.CallHiveService((s) => s.UpdateSlaveGroup((SlaveGroup)item));
|
---|
163 | }
|
---|
164 | if (item is Slave)
|
---|
165 | {
|
---|
166 | servloc.CallHiveService((s) => s.UpdateSlave((Slave)item));
|
---|
167 | }
|
---|
168 | if (item is Downtime)
|
---|
169 | {
|
---|
170 | servloc.CallHiveService((s) => s.UpdateDowntime((Downtime)item));
|
---|
171 | }
|
---|
172 | }
|
---|
173 | }
|
---|
174 | #endregion
|
---|
175 |
|
---|
176 | #region Delete
|
---|
177 | public void Delete(IHiveItem item)
|
---|
178 | {
|
---|
179 | if (item is SlaveGroup)
|
---|
180 | {
|
---|
181 | servloc.CallHiveService((s) => s.DeleteSlaveGroup(item.Id));
|
---|
182 | }
|
---|
183 | else if (item is Slave)
|
---|
184 | {
|
---|
185 | servloc.CallHiveService((s) => s.DeleteSlave(item.Id));
|
---|
186 | }
|
---|
187 | else if (item is Downtime)
|
---|
188 | {
|
---|
189 | servloc.CallHiveService((s) => s.DeleteDowntime(item.Id));
|
---|
190 | }
|
---|
191 | }
|
---|
192 | #endregion
|
---|
193 |
|
---|
194 | public void ResetDowntime()
|
---|
195 | {
|
---|
196 | downtimeForResourceId = Guid.Empty;
|
---|
197 | if (downtimes != null)
|
---|
198 | {
|
---|
199 | downtimes.Clear();
|
---|
200 | }
|
---|
201 | }
|
---|
202 | }
|
---|
203 | }
|
---|