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
Line 
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;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.Interfaces;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
28using HeuristicLab.Hive.Contracts;
29using HeuristicLab.Security.Contracts.Interfaces;
30using HeuristicLab.Hive.Server.Core.InternalInterfaces;
31
32namespace HeuristicLab.Hive.Server.Core {
33  public class ServerConsoleFacade: IServerConsoleFacade {
34    private IClientManager clientManager =
35      ServiceLocator.GetClientManager();
36
37    private IJobManager jobManager =
38      ServiceLocator.GetJobManager();
39
40    private IHivePermissionManager secMan = ServiceLocator.GetHivePermissionManager();
41
42    public Guid sessionID = Guid.Empty;
43
44    public Response Login(string username, string password) {
45      Response resp = new Response();
46     
47      /*
48      sessionID = secMan.Login(username, password);
49      if (sessionID == Guid.Empty) {
50        resp.Success = false;
51        resp.StatusMessage = ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_FAILED;
52      } else {
53        resp.Success = true;
54        resp.StatusMessage =
55          ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
56      }
57      */
58      sessionID = Guid.Empty;
59      resp.Success = true;
60      resp.StatusMessage = ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
61      return resp;
62    }
63
64
65    public ResponseList<ClientInfo> GetAllClients() {
66      if (HasPermission(PermissiveSecurityAction.List_AllClients))
67        return clientManager.GetAllClients();
68      else
69        throw new PermissionException();
70    }
71
72    public ResponseList<ClientGroup> GetAllClientGroups() {
73      if (HasPermission(PermissiveSecurityAction.List_AllClientGroups))
74        return clientManager.GetAllClientGroups();
75      else
76        throw new PermissionException();
77    }
78
79    public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
80      if (HasPermission(PermissiveSecurityAction.Show_Statistics))
81        return clientManager.GetAllUpTimeStatistics();
82      else
83        throw new PermissionException();
84    }
85
86    public ResponseObject<ClientGroup> AddClientGroup(ClientGroup clientGroup) {
87      if (HasPermission(PermissiveSecurityAction.Add_ClientGroup))
88        return clientManager.AddClientGroup(clientGroup);
89      else
90        throw new PermissionException();
91    }
92
93    public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
94      if (HasPermission(PermissiveSecurityAction.Add_Resource))
95        return clientManager.AddResourceToGroup(clientGroupId, resource);
96      else
97        throw new PermissionException();
98    }
99
100    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
101      if (HasPermission(PermissiveSecurityAction.Delete_Resource))
102        return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
103      else
104        throw new PermissionException();
105    }
106
107
108    public ResponseList<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetAllJobs() {
109      if (HasPermission(PermissiveSecurityAction.Get_AllJobs))
110        return jobManager.GetAllJobs();
111      else
112        throw new PermissionException();
113    }
114
115    public ResponseObject<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetJobById(Guid jobId) {
116      return jobManager.GetJobById(jobId);
117    }
118
119    public ResponseObject<Job> AddNewJob(Job job) {
120      if (HasPermission(PermissiveSecurityAction.Add_Job))
121        return jobManager.AddNewJob(job);
122      else
123        throw new PermissionException();
124    }
125
126    public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId, bool requested) {
127      if (HasPermission(PermissiveSecurityAction.Get_LastJobResult))
128        return jobManager.GetLastJobResultOf(jobId, requested);
129      else
130        throw new PermissionException();
131    }
132
133    public ResponseList<JobResult> GetAllJobResults(Guid jobId) {
134      if (HasPermission(PermissiveSecurityAction.Get_AllJobResults))
135        return jobManager.GetAllJobResults(jobId);
136      else
137        throw new PermissionException();
138    }
139
140    public Response RemoveJob(Guid jobId) {
141      if (HasPermission(PermissiveSecurityAction.Remove_Job))
142        return jobManager.RemoveJob(jobId);
143      else
144        throw new PermissionException();
145    }
146
147    public Response RequestSnapshot(Guid jobId) {
148      if (HasPermission(PermissiveSecurityAction.Request_Snapshot))
149        return jobManager.RequestSnapshot(jobId);
150      else
151        throw new PermissionException();
152    }
153
154    public Response AbortJob(Guid jobId) {
155      if (HasPermission(PermissiveSecurityAction.Abort_Job))
156        return jobManager.AbortJob(jobId);
157      else
158        throw new PermissionException();
159    }
160
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();     
166    }
167
168    public Response DeleteClientGroup(Guid clientGroupId) {
169      return clientManager.DeleteClientGroup(clientGroupId);
170    }
171
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!")]
185    private bool HasPermission(Guid g, Guid f) { return true; }
186
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    }
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
219  }
220}
Note: See TracBrowser for help on using the repository browser.