1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using System.Web.Mvc;
|
---|
6 | using HeuristicLab.Services.Hive.DataAccess;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Services.Hive.Statistics.Controllers {
|
---|
9 | public class ExceptionDataController : Controller {
|
---|
10 |
|
---|
11 | public JsonResult TaskExceptions(string userName, DateTime? start = null, DateTime? end = null, string jobId = null, string taskState = null, string slaveId = null)
|
---|
12 | {
|
---|
13 | using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) {
|
---|
14 | TaskState? state = GetTaskState(taskState);
|
---|
15 | var data =
|
---|
16 | (from tasks in db.FactTasks
|
---|
17 | join jobs in db.DimJobs
|
---|
18 | on tasks.JobId equals jobs.JobId
|
---|
19 | where tasks.Exception != null &&
|
---|
20 | !tasks.Exception.Equals(string.Empty) &&
|
---|
21 | (string.IsNullOrEmpty(userName) || jobs.UserName == userName) &&
|
---|
22 | (!start.HasValue || tasks.StartTime >= start) &&
|
---|
23 | (!end.HasValue || tasks.EndTime < end) &&
|
---|
24 | (string.IsNullOrEmpty(jobId) || tasks.JobId.ToString() == jobId) &&
|
---|
25 | (string.IsNullOrEmpty(taskState) || tasks.TaskState == state) &&
|
---|
26 | (string.IsNullOrEmpty(slaveId) || tasks.LastClientId.ToString() == slaveId)
|
---|
27 | select new
|
---|
28 | {
|
---|
29 | TaskID = tasks.TaskId,
|
---|
30 | ErrorMessage = tasks.Exception,
|
---|
31 | StartDate = tasks.StartTime
|
---|
32 | }).OrderByDescending(s => s.StartDate).ToList();
|
---|
33 |
|
---|
34 | List<string> Task = new List<string>();
|
---|
35 | List<string> Error = new List<string>();
|
---|
36 | data.ForEach(t => Task.Add(t.TaskID.ToString()));
|
---|
37 | data.ForEach(e => Error.Add(e.ErrorMessage));
|
---|
38 |
|
---|
39 | //Was overflowing default MaxJsonLength
|
---|
40 | //return Json(new KeyValuePair<List<string>, List<string>>(Task, Error), JsonRequestBehavior.AllowGet);
|
---|
41 | return new JsonResult() { Data = new KeyValuePair<List<string>, List<string>>(Task, Error), JsonRequestBehavior = JsonRequestBehavior.AllowGet, MaxJsonLength = Int32.MaxValue };
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | public JsonResult SlaveExceptions(DateTime? start = null, DateTime? end = null, string clientId = null) {
|
---|
46 | using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) {
|
---|
47 | var data =
|
---|
48 | (from tasks in db.FactTasks
|
---|
49 | join jobs in db.DimJobs
|
---|
50 | on tasks.JobId equals jobs.JobId
|
---|
51 | join clients in db.DimClients
|
---|
52 | on tasks.LastClientId equals clients.Id
|
---|
53 | where tasks.Exception != null &&
|
---|
54 | !tasks.Exception.Equals(string.Empty) &&
|
---|
55 | (!start.HasValue || tasks.StartTime >= start) &&
|
---|
56 | (!end.HasValue || tasks.EndTime < end) &&
|
---|
57 | (string.IsNullOrEmpty(clientId) || tasks.LastClientId.ToString() == clientId)
|
---|
58 | select new {
|
---|
59 | TaskID = tasks.TaskId,
|
---|
60 | ErrorMessage = tasks.Exception,
|
---|
61 | ClientID = tasks.LastClientId,
|
---|
62 | ClientName = clients.Name,
|
---|
63 | UserName = jobs.UserName,
|
---|
64 | JobName = jobs.JobName,
|
---|
65 | StartDate = tasks.StartTime
|
---|
66 | }).OrderByDescending(s => s.StartDate).ToList();
|
---|
67 |
|
---|
68 | List<List<string>> results = new List<List<string>>();
|
---|
69 |
|
---|
70 | for (int i = 0; i < data.Count; i++) {
|
---|
71 | results.Add(
|
---|
72 | new List<string> { data[i].TaskID.ToString(), data[i].ErrorMessage, data[i].ClientID.ToString(), data[i].ClientName,
|
---|
73 | data[i].UserName, data[i].JobName, data[i].StartDate.ToString("dd/MM/yyyy HH:mm")
|
---|
74 | }
|
---|
75 | );
|
---|
76 | }
|
---|
77 | //Was overflowing default MaxJsonLength
|
---|
78 | //return Json(results, JsonRequestBehavior.AllowGet);
|
---|
79 | return new JsonResult() { Data = results, JsonRequestBehavior = JsonRequestBehavior.AllowGet, MaxJsonLength = Int32.MaxValue };
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | private static TaskState? GetTaskState(string taskState) {
|
---|
84 | TaskState? state;
|
---|
85 | switch (taskState) {
|
---|
86 | case "Aborted":
|
---|
87 | state = TaskState.Aborted;
|
---|
88 | break;
|
---|
89 | case "Calculating":
|
---|
90 | state = TaskState.Calculating;
|
---|
91 | break;
|
---|
92 | case "Failed":
|
---|
93 | state = TaskState.Failed;
|
---|
94 | break;
|
---|
95 | case "Finished":
|
---|
96 | state = TaskState.Finished;
|
---|
97 | break;
|
---|
98 | case "Offline":
|
---|
99 | state = TaskState.Offline;
|
---|
100 | break;
|
---|
101 | case "Paused":
|
---|
102 | state = TaskState.Paused;
|
---|
103 | break;
|
---|
104 | case "Transferring":
|
---|
105 | state = TaskState.Transferring;
|
---|
106 | break;
|
---|
107 | case "Waiting":
|
---|
108 | state = TaskState.Waiting;
|
---|
109 | break;
|
---|
110 | default :
|
---|
111 | state = null;
|
---|
112 | break;
|
---|
113 | }
|
---|
114 | return state;
|
---|
115 | }
|
---|
116 | }
|
---|
117 | }
|
---|