[13860] | 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 |
|
---|
| 23 | using HeuristicLab.Clients.Hive.WebJobManager.Services;
|
---|
[13733] | 24 | using HeuristicLab.Optimization;
|
---|
[13860] | 25 | using Microsoft.AspNetCore.SignalR;
|
---|
[13733] | 26 | using System;
|
---|
| 27 | using System.Linq;
|
---|
[13827] | 28 | using System.Reflection;
|
---|
[13834] | 29 | using HeuristicLab.Core;
|
---|
[13733] | 30 |
|
---|
| 31 | namespace HeuristicLab.Clients.Hive.WebJobManager
|
---|
| 32 | {
|
---|
| 33 | /// <summary>
|
---|
| 34 | /// SignalR Hub for displaying the progress when uploading a Job.
|
---|
| 35 | /// Also used to change child distribution and priority for inner tasks.
|
---|
| 36 | /// </summary>
|
---|
| 37 | public class ProgressHub : Hub
|
---|
| 38 | {
|
---|
[13739] | 39 | private WebLoginService weblog;
|
---|
| 40 | private Guid userId;
|
---|
| 41 | private FileOpeningService fileopener;
|
---|
| 42 | private void loader()
|
---|
| 43 | {
|
---|
| 44 | weblog = WebLoginService.Instance;
|
---|
| 45 | string uid = Context.QueryString["userid"];
|
---|
| 46 | if (uid == null || uid == "" || Guid.Parse(uid) == Guid.Empty)
|
---|
| 47 | {
|
---|
| 48 | userId = Guid.Empty;
|
---|
| 49 | }
|
---|
[13827] | 50 | else
|
---|
| 51 | {
|
---|
[13739] | 52 | userId = Guid.Parse(uid);
|
---|
| 53 | fileopener = weblog.getFileOpener(userId);
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[13733] | 57 | /// <summary>
|
---|
| 58 | /// First message from client
|
---|
| 59 | /// </summary>
|
---|
| 60 | /// <param name="receivedString">Client message</param>
|
---|
| 61 | public void HandleMessage(string receivedString)
|
---|
| 62 | {
|
---|
[13739] | 63 | loader();
|
---|
[13735] | 64 | Clients.Caller.processMessage("Connection Established");
|
---|
[13739] | 65 | fileopener.Job.Progress.StatusChanged += runHub;
|
---|
[13733] | 66 | }
|
---|
| 67 | /// <summary>
|
---|
| 68 | /// Changes name for the current job to be created
|
---|
| 69 | /// </summary>
|
---|
| 70 | /// <param name="name">Job name</param>
|
---|
[13735] | 71 | public void ChangeNameResource(string name, string resource)
|
---|
[13733] | 72 | {
|
---|
[13739] | 73 | loader();
|
---|
[13733] | 74 | if (name != null)
|
---|
[13739] | 75 | fileopener.Job.Job.Name = name;
|
---|
[13827] | 76 | if (resource != null && resource != "")
|
---|
[13735] | 77 | {
|
---|
[13739] | 78 | fileopener.Job.Job.ResourceNames += "/" + resource;
|
---|
[13735] | 79 | }
|
---|
[13733] | 80 | }
|
---|
| 81 | /// <summary>
|
---|
| 82 | /// Toggles distribute child task for a current task
|
---|
| 83 | /// </summary>
|
---|
| 84 | /// <param name="arr">2-dimensional int array.
|
---|
| 85 | /// First dimension is depth (arr.length == 4 means the item is 4 nodes deep)
|
---|
| 86 | /// Second contains expirement info or batch info. (arr[][0] contains index to select the right experiment sub task,
|
---|
| 87 | /// arr[][1] contains index to select right batch run subtask)</param>
|
---|
| 88 | public void ToggleChild(int[][] arr)
|
---|
| 89 | {
|
---|
[13739] | 90 | loader();
|
---|
[13844] | 91 | bool change = false;
|
---|
| 92 | string name = "";
|
---|
[13739] | 93 | HiveTask current = fileopener.Job.HiveTasks.ToList()[0];
|
---|
[13733] | 94 | if (arr.Length == 0)
|
---|
| 95 | {//check if upper job
|
---|
| 96 | current.ItemTask.ComputeInParallel = !current.ItemTask.ComputeInParallel;
|
---|
[13844] | 97 | change = current.ItemTask.ComputeInParallel;
|
---|
| 98 | name = current.ItemTask.Name;
|
---|
[13733] | 99 | }
|
---|
[13827] | 100 | else
|
---|
| 101 | {
|
---|
[13733] | 102 | for (var i = 0; i < arr.Length; i++)
|
---|
| 103 | {
|
---|
| 104 | //loop for depth
|
---|
| 105 |
|
---|
| 106 | if (i == arr.Length - 1)//end of depth loop, right current is selected
|
---|
| 107 | {
|
---|
| 108 | if (current.ItemTask.Item is BatchRun)
|
---|
| 109 | {
|
---|
| 110 | current.ChildHiveTasks[arr[i][1]].ItemTask.ComputeInParallel = !current.ChildHiveTasks[arr[i][1]].ItemTask.ComputeInParallel;
|
---|
[13844] | 111 | change = current.ChildHiveTasks[arr[i][1]].ItemTask.ComputeInParallel;
|
---|
| 112 | name = current.ChildHiveTasks[arr[i][1]].ItemTask.Name;
|
---|
[13733] | 113 | }
|
---|
| 114 | else if (current.ItemTask.Item is Experiment)
|
---|
| 115 | {
|
---|
| 116 | current.ChildHiveTasks[arr[i][0]].ItemTask.ComputeInParallel = !current.ChildHiveTasks[arr[i][0]].ItemTask.ComputeInParallel;
|
---|
[13844] | 117 | change = current.ChildHiveTasks[arr[i][0]].ItemTask.ComputeInParallel;
|
---|
| 118 | name = current.ChildHiveTasks[arr[i][0]].ItemTask.Name;
|
---|
[13733] | 119 | }
|
---|
| 120 |
|
---|
| 121 | }
|
---|
[13827] | 122 | else
|
---|
| 123 | {//not deep enough, select right path
|
---|
[13733] | 124 | if (current.ItemTask.Item is BatchRun)
|
---|
| 125 | current = current.ChildHiveTasks[arr[i][1]]; // select right batch
|
---|
| 126 | else if (current.ItemTask.Item is Experiment)
|
---|
| 127 | current = current.ChildHiveTasks[arr[i][0]]; // select right sub task from experiment
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
[13844] | 131 | if (change)
|
---|
| 132 | Clients.Caller.saveComplete("Child distribution activated for " + name);
|
---|
| 133 | else
|
---|
| 134 | Clients.Caller.saveComplete("Child distribution deactivated for " + name);
|
---|
[13733] | 135 | }
|
---|
[13841] | 136 | public void changeName(int[][] arr, string name, int idname)
|
---|
| 137 | {
|
---|
| 138 |
|
---|
| 139 | if (name != "" && name != null)
|
---|
| 140 | {
|
---|
| 141 | loader();
|
---|
[13844] | 142 | string old = "";
|
---|
[13841] | 143 | HiveTask current = fileopener.Job.HiveTasks.ToList()[0];
|
---|
| 144 | if (arr.Length == 0)
|
---|
| 145 | {//check if upper job
|
---|
[13844] | 146 | old = current.ItemTask.Name;
|
---|
[13841] | 147 | current.ItemTask.Name = name;
|
---|
| 148 |
|
---|
| 149 | }
|
---|
| 150 | else
|
---|
| 151 | {
|
---|
| 152 | for (var i = 0; i < arr.Length; i++)
|
---|
| 153 | {//loop for depth
|
---|
| 154 | if (i == arr.Length - 1)
|
---|
| 155 | {//Right depth reached, change name for current
|
---|
| 156 | if (current.ItemTask.Item is BatchRun)
|
---|
| 157 | {
|
---|
[13844] | 158 | old = current.ChildHiveTasks[arr[i][1]].ItemTask.Name;
|
---|
[13841] | 159 | current.ChildHiveTasks[arr[i][1]].ItemTask.Name = name;
|
---|
| 160 | }
|
---|
| 161 | else if (current.ItemTask.Item is Experiment)
|
---|
| 162 | {
|
---|
[13844] | 163 | old = current.ChildHiveTasks[arr[i][0]].ItemTask.Name;
|
---|
[13841] | 164 | current.ChildHiveTasks[arr[i][0]].ItemTask.Name = name;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | }
|
---|
| 168 | else
|
---|
| 169 | {//not deep enough, choose right path
|
---|
| 170 | if (current.ItemTask.Item is BatchRun)
|
---|
| 171 | current = current.ChildHiveTasks[arr[i][1]]; // select right batch
|
---|
| 172 | else if (current.ItemTask.Item is Experiment)
|
---|
| 173 | current = current.ChildHiveTasks[arr[i][0]]; // select right sub task from experiment
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | Clients.Caller.processName(name, idname);
|
---|
[13844] | 178 | Clients.Caller.saveComplete( old + " renamed to " + name);
|
---|
[13841] | 179 | }
|
---|
| 180 | }
|
---|
| 181 | public void changeRepit(int[][] arr, int repit)
|
---|
| 182 | {
|
---|
| 183 | loader();
|
---|
| 184 | HiveTask current = fileopener.Job.HiveTasks.ToList()[0];
|
---|
| 185 | string Name = "failed";
|
---|
| 186 | if (arr.Length == 0)
|
---|
| 187 | {//check if upper job
|
---|
| 188 | if (current.ItemTask.Item is BatchRun)
|
---|
| 189 | {
|
---|
| 190 | var b = (BatchRun)current.ItemTask.Item;
|
---|
| 191 | b.Repetitions = repit;
|
---|
| 192 | Name = current.ItemTask.Name;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | }
|
---|
| 196 | else
|
---|
| 197 | {
|
---|
| 198 | for (var i = 0; i < arr.Length; i++)
|
---|
| 199 | {//loop for depth
|
---|
| 200 | if (i == arr.Length - 1)
|
---|
| 201 | {//Right depth reached, change name for current
|
---|
| 202 | if (current.ChildHiveTasks[arr[i][0]].ItemTask.Item is BatchRun)
|
---|
| 203 | {
|
---|
| 204 | var b = (BatchRun)current.ChildHiveTasks[arr[i][0]].ItemTask.Item;
|
---|
| 205 | b.Repetitions = repit;
|
---|
| 206 | Name = current.ChildHiveTasks[arr[i][0]].ItemTask.Name;
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 | else
|
---|
| 210 | {//not deep enough, choose right path
|
---|
| 211 | if (current.ItemTask.Item is BatchRun)
|
---|
| 212 | current = current.ChildHiveTasks[arr[i][1]]; // select right batch
|
---|
| 213 | else if (current.ItemTask.Item is Experiment)
|
---|
| 214 | current = current.ChildHiveTasks[arr[i][0]]; // select right sub task from experiment
|
---|
| 215 | }
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
[13844] | 218 | if (Name == "failed")
|
---|
| 219 | Clients.Caller.createAlert("Something went wrong while changing the repititions, please try again", "danger");
|
---|
| 220 | else
|
---|
| 221 | Clients.Caller.saveComplete("Repititions changed to "+repit+ " for " + Name);
|
---|
[13841] | 222 |
|
---|
| 223 | }
|
---|
[13733] | 224 | /// <summary>
|
---|
| 225 | /// Change priority for a node
|
---|
| 226 | /// </summary>
|
---|
| 227 | /// <param name="arr">2-dimensional int array.
|
---|
| 228 | /// First dimension is depth (arr.length == 4 means the item is 4 nodes deep)
|
---|
| 229 | /// Second contains expirement info or batch info. (arr[][0] contains index to select the right experiment sub task,
|
---|
| 230 | /// arr[][1] contains index to select right batch run subtask)</param>
|
---|
| 231 | /// <param name="prior">Selected priority</param>
|
---|
| 232 | public void ChangePriority(int[][] arr, int prior)
|
---|
| 233 | {
|
---|
[13844] | 234 | string name = "";
|
---|
[13739] | 235 | loader();
|
---|
| 236 | HiveTask current = fileopener.Job.HiveTasks.ToList()[0];
|
---|
[13733] | 237 | if (arr.Length == 0)
|
---|
| 238 | {//check if upper job
|
---|
| 239 | current.Task.Priority = prior;
|
---|
[13844] | 240 | name = current.ItemTask.Name;
|
---|
[13733] | 241 | }
|
---|
[13827] | 242 | else
|
---|
| 243 | {
|
---|
[13733] | 244 | for (var i = 0; i < arr.Length; i++)
|
---|
| 245 | {//loop for depth
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 | if (i == arr.Length - 1)
|
---|
| 249 | {//Right depth reached, change priority for current
|
---|
| 250 | if (current.ItemTask.Item is BatchRun)
|
---|
| 251 | {
|
---|
| 252 | current.ChildHiveTasks[arr[i][1]].Task.Priority = prior;
|
---|
[13844] | 253 | name = current.ChildHiveTasks[arr[i][0]].ItemTask.Name;
|
---|
[13733] | 254 | }
|
---|
| 255 | else if (current.ItemTask.Item is Experiment)
|
---|
| 256 | {
|
---|
| 257 | current.ChildHiveTasks[arr[i][0]].Task.Priority = prior;
|
---|
[13844] | 258 | name = current.ChildHiveTasks[arr[i][0]].ItemTask.Name;
|
---|
[13733] | 259 | }
|
---|
| 260 |
|
---|
| 261 | }
|
---|
[13827] | 262 | else
|
---|
| 263 | {//not deep enough, choose right path
|
---|
[13733] | 264 | if (current.ItemTask.Item is BatchRun)
|
---|
| 265 | current = current.ChildHiveTasks[arr[i][1]]; // select right batch
|
---|
| 266 | else if (current.ItemTask.Item is Experiment)
|
---|
| 267 | current = current.ChildHiveTasks[arr[i][0]]; // select right sub task from experiment
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
[13844] | 271 | Clients.Caller.saveComplete("Priority changed for " + name);
|
---|
[13733] | 272 | }
|
---|
| 273 | /// <summary>
|
---|
| 274 | /// Used by event 'ProgressChanged' from current uploading Job
|
---|
| 275 | /// </summary>
|
---|
| 276 | /// <param name="sender"></param>
|
---|
| 277 | /// <param name="e"></param>
|
---|
| 278 | public void runHub(object sender, EventArgs e)
|
---|
| 279 | {
|
---|
[13739] | 280 | loader();
|
---|
[13733] | 281 | int value = 0;
|
---|
| 282 |
|
---|
[13739] | 283 | switch (fileopener.Job.Progress.Status)
|
---|
[13733] | 284 | {
|
---|
| 285 | case "Connecting to server...":
|
---|
| 286 | value = 0;
|
---|
| 287 | break;
|
---|
| 288 | case "Uploading Job...":
|
---|
| 289 | value = 10;
|
---|
| 290 | break;
|
---|
| 291 | case "Uploading plugins...":
|
---|
| 292 | value = 30;
|
---|
| 293 | break;
|
---|
| 294 | case "Uploading tasks...":
|
---|
| 295 | value = 50;
|
---|
| 296 | break;
|
---|
| 297 | case "Upload finished":
|
---|
| 298 | value = 100;
|
---|
| 299 | break;
|
---|
| 300 | default://Tasks are uploading individually
|
---|
[13739] | 301 | value = (int)(50 + (40 * fileopener.Job.Progress.ProgressValue));
|
---|
[13733] | 302 | break;
|
---|
| 303 |
|
---|
| 304 | }
|
---|
| 305 | //send info to client
|
---|
[13739] | 306 | Clients.Caller.processMessage(fileopener.Job.Progress.Status, value);
|
---|
[13733] | 307 |
|
---|
| 308 | }
|
---|
[13827] | 309 | public void paraEdit(int[][] arr, string problem, string name, string type, string value)
|
---|
| 310 | {
|
---|
[13733] | 311 |
|
---|
[13827] | 312 |
|
---|
| 313 | loader();
|
---|
| 314 | HiveTask current = fileopener.Job.HiveTasks.ToList()[0];
|
---|
| 315 | if (arr.Length == 0)
|
---|
| 316 | {//check if upper job
|
---|
| 317 | if (current.ItemTask.Item is Algorithm)
|
---|
| 318 | {
|
---|
| 319 | searchEditPara(current, problem, name, type, value);
|
---|
| 320 | }
|
---|
| 321 | }
|
---|
| 322 | else
|
---|
| 323 | {
|
---|
| 324 | for (var i = 0; i < arr.Length; i++)
|
---|
| 325 | {//loop for depth
|
---|
| 326 | if (i == arr.Length - 1)
|
---|
| 327 | {//Right depth reached, change priority for current
|
---|
| 328 | if (current.ItemTask.Item is BatchRun)
|
---|
| 329 | {
|
---|
| 330 | current = current.ChildHiveTasks[arr[i][1]];
|
---|
| 331 | }
|
---|
| 332 | else if (current.ItemTask.Item is Experiment)
|
---|
| 333 | {
|
---|
| 334 | current = current.ChildHiveTasks[arr[i][0]];
|
---|
| 335 | }
|
---|
| 336 | if (current.ItemTask.Item is Algorithm)
|
---|
| 337 | {
|
---|
| 338 | searchEditPara(current, problem, name, type, value);
|
---|
| 339 | }
|
---|
| 340 | }
|
---|
| 341 | else
|
---|
| 342 | {//not deep enough, choose right path
|
---|
| 343 | if (current.ItemTask.Item is BatchRun)
|
---|
| 344 | current = current.ChildHiveTasks[arr[i][1]]; // select right batch
|
---|
| 345 | else if (current.ItemTask.Item is Experiment)
|
---|
| 346 | current = current.ChildHiveTasks[arr[i][0]]; // select right sub task from experiment
|
---|
| 347 | }
|
---|
| 348 | }
|
---|
| 349 | }
|
---|
| 350 | }
|
---|
| 351 | /// <summary>
|
---|
| 352 | /// Generic parameter setter
|
---|
| 353 | /// </summary>
|
---|
| 354 | /// <param name="curr">Current task to edit </param>
|
---|
| 355 | /// <param name="problem">Problem parameter or normal parameter</param>
|
---|
| 356 | /// <param name="name">Property name</param>
|
---|
| 357 | /// <param name="type">Datatype</param>
|
---|
| 358 | /// <param name="value">New value</param>
|
---|
| 359 | private void searchEditPara(HiveTask curr, string problem, string name, string type, string value)
|
---|
| 360 | {
|
---|
| 361 | var prob = problem == "True" ? true : false;
|
---|
| 362 |
|
---|
| 363 | var dattype = Type.GetType(type);
|
---|
| 364 | if (dattype == null)
|
---|
| 365 | {//Use assemblies to find correct datatype
|
---|
| 366 | foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
|
---|
| 367 | {
|
---|
| 368 | dattype = a.GetType(type);
|
---|
| 369 | if (dattype != null)
|
---|
| 370 | break;
|
---|
| 371 | }
|
---|
| 372 | }
|
---|
| 373 | //find parse method
|
---|
| 374 | var parse = dattype.GetMethod("Parse", new[] { typeof(string) });
|
---|
| 375 |
|
---|
| 376 | if (parse != null)
|
---|
| 377 | {
|
---|
| 378 | //Parses string to correct datatype
|
---|
| 379 | var val = parse.Invoke(null, new object[] { value });
|
---|
| 380 |
|
---|
| 381 | //BUGGERS
|
---|
[13834] | 382 | // if (name == "DominateOnEqualQualities" || name == "PlusSelection" || name == "ReevaluteElites")
|
---|
| 383 | // val = ((BoolValue)val).Value;
|
---|
[13827] | 384 |
|
---|
[13834] | 385 | // if (name == "ReduceToPopulationSize")
|
---|
| 386 | //name += "Parameter";
|
---|
| 387 | if (val != null)
|
---|
[13827] | 388 | {
|
---|
[13834] | 389 | try
|
---|
| 390 | {
|
---|
| 391 | IAlgorithm alg = (IAlgorithm)curr.ItemTask.Item;
|
---|
| 392 | if (prob)
|
---|
| 393 | alg.Problem.Parameters[name].ActualValue = (IItem)val;
|
---|
| 394 | else
|
---|
| 395 | {
|
---|
| 396 | alg.Parameters[name].ActualValue = (IItem)val;
|
---|
| 397 | }
|
---|
[13844] | 398 | Clients.Caller.saveComplete("Parameter saved for " + name);
|
---|
[13834] | 399 | }
|
---|
| 400 | catch (NullReferenceException e)
|
---|
| 401 | {
|
---|
| 402 | Console.WriteLine("NullRefException: " + name + " - " + type);
|
---|
| 403 | }
|
---|
| 404 | catch (TargetException e)
|
---|
| 405 | {
|
---|
| 406 | Console.WriteLine("TargetException: " + name + " - " + type);
|
---|
| 407 | }
|
---|
| 408 | catch (NotSupportedException e)
|
---|
| 409 | {
|
---|
[13844] | 410 | Clients.Caller.createAlert("Parameter " + name + " could not be changed for it is a fixed parameter. All changes done in this view are not saved to Hive.", "danger");
|
---|
[13834] | 411 | }
|
---|
[13827] | 412 | }
|
---|
[13834] | 413 | else
|
---|
[13844] | 414 | Clients.Caller.createAlert("Format wrong for " + name + " of type " + type + ". Make sure you follow the right format pattern.", "warning");
|
---|
[13834] | 415 |
|
---|
| 416 |
|
---|
[13827] | 417 | }
|
---|
| 418 |
|
---|
| 419 | }
|
---|
| 420 |
|
---|
[13733] | 421 | }
|
---|
| 422 | }
|
---|