Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ServerConsoleFacade.cs @ 2036

Last change on this file since 2036 was 2005, checked in by svonolfe, 15 years ago

Updated jobManager (#431)

File size: 7.3 KB
RevLine 
[907]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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;
[800]23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.Interfaces;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
[902]28using HeuristicLab.Hive.Contracts;
[1648]29using HeuristicLab.Security.Contracts.Interfaces;
[1769]30using HeuristicLab.Hive.Server.Core.InternalInterfaces;
[800]31
32namespace HeuristicLab.Hive.Server.Core {
33  public class ServerConsoleFacade: IServerConsoleFacade {
[1099]34    private IClientManager clientManager =
35      ServiceLocator.GetClientManager();
[1084]36
[1099]37    private IJobManager jobManager =
38      ServiceLocator.GetJobManager();
39
[1769]40    private IHivePermissionManager secMan = ServiceLocator.GetHivePermissionManager();
[1084]41
[1648]42    public Guid sessionID = Guid.Empty;
43
[1086]44    public Response Login(string username, string password) {
45      Response resp = new Response();
[1801]46     
47      /*
[1769]48      sessionID = secMan.Login(username, password);
[1800]49      if (sessionID == Guid.Empty) {
[1648]50        resp.Success = false;
[1800]51        resp.StatusMessage = ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_FAILED;
52      } else {
[1648]53        resp.Success = true;
54        resp.StatusMessage =
55          ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
56      }
[1801]57      */
58      sessionID = Guid.Empty;
59      resp.Success = true;
60      resp.StatusMessage = ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
[1086]61      return resp;
[1084]62    }
63
64
[902]65    public ResponseList<ClientInfo> GetAllClients() {
[1769]66      if (HasPermission(PermissiveSecurityAction.List_AllClients))
[1648]67        return clientManager.GetAllClients();
68      else
69        throw new PermissionException();
[800]70    }
71
[902]72    public ResponseList<ClientGroup> GetAllClientGroups() {
[1769]73      if (HasPermission(PermissiveSecurityAction.List_AllClientGroups))
[1648]74        return clientManager.GetAllClientGroups();
75      else
76        throw new PermissionException();
[800]77    }
78
[902]79    public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
[1769]80      if (HasPermission(PermissiveSecurityAction.Show_Statistics))
[1648]81        return clientManager.GetAllUpTimeStatistics();
82      else
83        throw new PermissionException();
[800]84    }
85
[1825]86    public ResponseObject<ClientGroup> AddClientGroup(ClientGroup clientGroup) {
[1769]87      if (HasPermission(PermissiveSecurityAction.Add_ClientGroup))
[1648]88        return clientManager.AddClientGroup(clientGroup);
89      else
90        throw new PermissionException();
[934]91    }
92
[1449]93    public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
[1769]94      if (HasPermission(PermissiveSecurityAction.Add_Resource))
[1648]95        return clientManager.AddResourceToGroup(clientGroupId, resource);
96      else
97        throw new PermissionException();
[934]98    }
99
[1449]100    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
[1769]101      if (HasPermission(PermissiveSecurityAction.Delete_Resource))
[1648]102        return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
103      else
104        throw new PermissionException();
[934]105    }
106
[800]107
[902]108    public ResponseList<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetAllJobs() {
[1769]109      if (HasPermission(PermissiveSecurityAction.Get_AllJobs))
[1648]110        return jobManager.GetAllJobs();
111      else
112        throw new PermissionException();
[800]113    }
[1648]114
[2005]115    public ResponseObject<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetJobById(Guid jobId) {
116      return jobManager.GetJobById(jobId);
117    }
118
[967]119    public ResponseObject<Job> AddNewJob(Job job) {
[1805]120      if (HasPermission(PermissiveSecurityAction.Add_Job))
[1648]121        return jobManager.AddNewJob(job);
122      else
123        throw new PermissionException();
[967]124    }
[800]125
[1509]126    public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId, bool requested) {
[1769]127      if (HasPermission(PermissiveSecurityAction.Get_LastJobResult))
[1648]128        return jobManager.GetLastJobResultOf(jobId, requested);
129      else
130        throw new PermissionException();
[1171]131    }
132
[1799]133    public ResponseList<JobResult> GetAllJobResults(Guid jobId) {
[1769]134      if (HasPermission(PermissiveSecurityAction.Get_AllJobResults))
[1648]135        return jobManager.GetAllJobResults(jobId);
136      else
137        throw new PermissionException();
138    }
139
[1449]140    public Response RemoveJob(Guid jobId) {
[1769]141      if (HasPermission(PermissiveSecurityAction.Remove_Job))
[1648]142        return jobManager.RemoveJob(jobId);
143      else
144        throw new PermissionException();
[967]145    }
146
[1509]147    public Response RequestSnapshot(Guid jobId) {
[1769]148      if (HasPermission(PermissiveSecurityAction.Request_Snapshot))
[1648]149        return jobManager.RequestSnapshot(jobId);
150      else
151        throw new PermissionException();
[1509]152    }
153
154    public Response AbortJob(Guid jobId) {
[1769]155      if (HasPermission(PermissiveSecurityAction.Abort_Job))
[1648]156        return jobManager.AbortJob(jobId);
157      else
158        throw new PermissionException();
[1509]159    }
160
[1769]161    public ResponseObject<List<ClientGroup>> GetAllGroupsOfResource(Guid resourceId) {
162      if (HasPermission(PermissiveSecurityAction.Get_AllGroupsOfResource))
163        return clientManager.GetAllGroupsOfResource(resourceId);
164      else
165        throw new PermissionException();     
[1627]166    }
167
[1824]168    public Response DeleteClientGroup(Guid clientGroupId) {
169      return clientManager.DeleteClientGroup(clientGroupId);
170    }
171
[1769]172  /*
173    private bool HasPermission(Guid action) {
174      return (sessionID == Guid.Empty) ? false : secMan.CheckPermission(sessionID, action, Guid.Empty);
175    }
176
177    private bool HasPermission(Guid action, Guid entityId) {
178      return (sessionID == Guid.Empty) ? false : secMan.CheckPermission(sessionID, action, entityId);
179    }
180   */
181
182    [Obsolete("Only for testing!")]
183    private bool HasPermission(Guid g) { return true; }
184    [Obsolete("Only for testing!")]
[1804]185    private bool HasPermission(Guid g, Guid f) { return true; }
[1769]186
[1648]187    public class PermissionException : Exception {
188      public PermissionException()
189        : base("Current user has insufficent rights for this action!") {
190      }
191
192      public PermissionException(string msg)
193        : base(msg) {
194      }
195
196
197    }
[1932]198
199    public ResponseList<Project> GetAllProjects() {
200      return jobManager.GetAllProjects();
201    }
202
203    public Response CreateProject(Project project) {
204      return jobManager.CreateProject(project);
205    }
206
207    public Response ChangeProject(Project project) {
208      return jobManager.ChangeProject(project);
209    }
210
211    public Response DeleteProject(Guid projectId) {
212      return jobManager.DeleteProject(projectId);
213    }
214
215    public ResponseList<Job> GetJobsByProject(Guid projectId) {
216      return jobManager.GetJobsByProject(projectId);
217    }
218
[800]219  }
220}
Note: See TracBrowser for help on using the repository browser.