Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/DataController.cs @ 12484

Last change on this file since 12484 was 12484, checked in by dglaser, 9 years ago

#2388: Updated Hive, DataAccess and WebApp

HeuristicLab.Services.Hive.DataAccess:

  • Updated database statistics schema

HeuristicLab.Services.Hive:

  • Fixed event flag in HiveJanitor Service
  • Improved UpdateTaskFactsTable in the HiveStatisticsGenerator

HeuristicLab.Services.WebApp:

  • Updated Statistics DataController to match the new statistics schema
File size: 3.5 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Web.Http;
26using HeuristicLab.Services.Access;
27using HeuristicLab.Services.Hive;
28using HeuristicLab.Services.Hive.DataAccess.Interfaces;
29using DTO = HeuristicLab.Services.WebApp.Statistics.WebApi.DataTransfer;
30
31namespace HeuristicLab.Services.WebApp.Statistics.WebApi {
32
33  [Authorize]
34  public class DataController : ApiController {
35
36    private IPersistenceManager PersistenceManager {
37      get { return ServiceLocator.Instance.PersistenceManager; }
38    }
39
40    private IUserManager UserManager {
41      get { return ServiceLocator.Instance.UserManager; }
42    }
43    private IRoleVerifier RoleVerifier {
44      get { return ServiceLocator.Instance.RoleVerifier; }
45    }
46    private IAuthorizationManager AuthorizationManager {
47      get { return ServiceLocator.Instance.AuthorizationManager; }
48    }
49
50    public IEnumerable<DTO.Job> GetJobs() {
51      return GetJobsByUserId(UserManager.CurrentUserId);
52    }
53
54    public IEnumerable<DTO.Job> GetJobsByUserId(Guid id) {
55      if (id != UserManager.CurrentUserId) {
56        RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator);
57      }
58      using (var pm = PersistenceManager) {
59        return pm.UseTransaction(() => {
60          var dimJobDao = pm.DimJobDao;
61          return dimJobDao.GetByUserId(id).Select(x => new DTO.Job {
62            Id = x.JobId,
63            Name = x.JobName,
64            DateCreated = x.DateCreated
65          }).ToList();
66        });
67      }
68    }
69
70    public IEnumerable<DTO.Task> GetTasksByJobId(Guid id) {
71      using (var pm = PersistenceManager) {
72        return pm.UseTransaction(() => {
73          var dimJobDao = pm.JobDao;
74          var factTaskDao = pm.FactTaskDao;
75          var job = dimJobDao.GetById(id);
76          if (job != null && job.OwnerUserId != UserManager.CurrentUserId) {
77            RoleVerifier.AuthenticateForAllRoles(HiveRoles.Administrator);
78          }
79          return factTaskDao.GetByJobId(id).Select(x => new DTO.Task {
80            Id = x.TaskId,
81            CalculatingTime = x.CalculatingTime,
82            WaitingTime = x.WaitingTime,
83            TransferTime = x.TransferTime,
84            InitialWaitingTime = x.InitialWaitingTime,
85            NumCalculationRuns = x.NumCalculationRuns,
86            NumRetries = x.NumRetries,
87            CoresRequired = x.CoresRequired,
88            MemoryRequired = x.MemoryRequired,
89            Priority = x.Priority,
90            State = x.TaskState.ToString(),
91            LastClientId = x.LastClientId,
92            StartTime = x.StartTime,
93            EndTime = x.EndTime,
94            Exception = x.Exception
95          }).ToList();
96        });
97      }
98    }
99
100  }
101}
Note: See TracBrowser for help on using the repository browser.