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