Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ServerConsoleFacade.cs @ 4302

Last change on this file since 4302 was 4302, checked in by cneumuel, 14 years ago
  • made ServerConsole work with wsHttpBinding
  • applied role-base restrictions to all WCF-Services
  • made wcf-services work with certificates
  • renamed ExecutionEngineFacade to ClientFacade

(#1168)

File size: 8.8 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.Hive.Server.Core.InternalInterfaces;
30using System.ServiceModel;
31using HeuristicLab.Hive.Server.DataAccess;
32using HeuristicLab.Hive.Contracts.ResponseObjects;
33using System.Security.Permissions;
34
35      //IIdentity id = ServiceSecurityContext.Current.PrimaryIdentity;
36      //if (!Thread.CurrentPrincipal.IsInRole("Administrator")) {
37
38      //} else {
39      //  // access denied
40      //  throw new SecurityException();
41      //}
42
43namespace HeuristicLab.Hive.Server.Core {
44  public class ServerConsoleFacade : IServerConsoleFacade {
45    private ISlaveManager slaveManager = ServiceLocator.GetSlaveManager();
46
47    private IJobManager jobManager = ServiceLocator.GetJobManager();
48
49    private IContextFactory contextFactory = ServiceLocator.GetContextFactory();
50
51    public Guid sessionID = Guid.Empty;
52
53    public ServerConsoleFacade() {
54    }
55
56    public Response Login() {
57      Response resp = new Response();
58      return resp;
59    }
60
61    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
62    public ResponseList<SlaveDto> GetAllSlaves() {
63      using (contextFactory.GetContext(false)) {
64        return slaveManager.GetAllSlaves();
65      }
66    }
67
68    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
69    public ResponseList<SlaveGroupDto> GetAllSlaveGroups() {
70      using (contextFactory.GetContext(false)) {
71        return slaveManager.GetAllSlaveGroups();
72      }
73    }
74
75    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
76    public ResponseList<UpTimeStatisticsDto> GetAllUpTimeStatistics() {
77      using (contextFactory.GetContext(false)) {
78        return slaveManager.GetAllUpTimeStatistics();
79      }
80    }
81
82    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
83    public ResponseObject<SlaveGroupDto> AddSlaveGroup(SlaveGroupDto slaveGroup) {
84      using (contextFactory.GetContext()) {
85        return slaveManager.AddSlaveGroup(slaveGroup);
86      }
87    }
88
89    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
90    public Response AddResourceToGroup(Guid slaveGroupId, ResourceDto resource) {
91      using (contextFactory.GetContext()) {
92        return slaveManager.AddResourceToGroup(slaveGroupId, resource);
93      }
94    }
95
96    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
97    public Response DeleteResourceFromGroup(Guid slaveGroupId, Guid resourceId) {
98      using (contextFactory.GetContext()) {
99        return slaveManager.DeleteResourceFromGroup(slaveGroupId, resourceId);
100      }
101    }
102
103    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
104    public ResponseList<JobDto> GetAllJobs() {
105      using (contextFactory.GetContext(false)) {
106        return jobManager.GetAllJobs();
107      }
108    }
109
110    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
111    public ResponseList<JobDto> GetAllJobsWithFilter(JobState jobState, int offset, int count) {
112      using (contextFactory.GetContext(false)) {
113        return jobManager.GetAllJobsWithFilter(jobState, offset, count);
114      }
115    }
116
117    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
118    public ResponseObject<JobDto> GetJobById(Guid jobId) {
119      using (contextFactory.GetContext(false)) {
120        return jobManager.GetJobById(jobId);
121      }
122    }
123
124    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
125    public ResponseObject<JobDto> GetJobByIdWithDetails(Guid jobId) {
126      using (contextFactory.GetContext(false)) {
127        return jobManager.GetJobByIdWithDetails(jobId);
128      }
129    }
130
131    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
132    public ResponseObject<JobDto> AddNewJob(SerializedJob job) {
133      using (contextFactory.GetContext()) {
134        return jobManager.AddNewJob(job);
135      }
136    }
137
138    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
139    public ResponseObject<SerializedJob> GetLastSerializedResult(Guid jobId, bool requested, bool snapshot) {
140      using (contextFactory.GetContext(false)) {
141        return jobManager.GetLastSerializedResult(jobId, requested, snapshot);
142      }
143    }
144
145    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
146    public ResponseObject<JobResultList> GetJobResults(IEnumerable<Guid> jobIds) {
147      using (contextFactory.GetContext(false)) {
148        return jobManager.GetJobResults(jobIds);
149      }
150    }
151
152    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
153    public Response RequestSnapshot(Guid jobId) {
154      using (contextFactory.GetContext()) {
155        return jobManager.RequestSnapshot(jobId);
156      }
157    }
158
159    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
160    public Response AbortJob(Guid jobId) {
161      using (contextFactory.GetContext()) {
162        return jobManager.AbortJob(jobId);
163      }
164    }
165
166    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
167    public ResponseObject<SlaveGroupDtoList> GetAllGroupsOfResource(Guid resourceId) {
168      using (contextFactory.GetContext(false)) {
169        return slaveManager.GetAllGroupsOfResource(resourceId);
170      }
171    }
172
173    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
174    public Response DeleteSlaveGroup(Guid slaveGroupId) {
175      using (contextFactory.GetContext()) {
176        return slaveManager.DeleteSlaveGroup(slaveGroupId);
177      }
178    }
179
180    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
181    public ResponseList<ProjectDto> GetAllProjects() {
182      using (contextFactory.GetContext(false)) {
183        return jobManager.GetAllProjects();
184      }
185    }
186
187    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
188    public Response CreateProject(ProjectDto project) {
189      using (contextFactory.GetContext()) {
190        return jobManager.CreateProject(project);
191      }
192    }
193
194    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
195    public Response ChangeProject(ProjectDto project) {
196      using (contextFactory.GetContext()) {
197        return jobManager.ChangeProject(project);
198      }
199    }
200
201    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
202    public Response DeleteProject(Guid projectId) {
203      using (contextFactory.GetContext()) {
204        return jobManager.DeleteProject(projectId);
205      }
206    }
207
208    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
209    public ResponseList<JobDto> GetJobsByProject(Guid projectId) {
210      using (contextFactory.GetContext(false)) {
211        return jobManager.GetJobsByProject(projectId);
212      }
213    }
214
215    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
216    public ResponseList<AppointmentDto> GetUptimeCalendarForResource(Guid guid) {
217      using (contextFactory.GetContext(false)) {
218        return slaveManager.GetUptimeCalendarForResource(guid);
219      }
220    }
221
222    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
223    public Response SetUptimeCalendarForResource(Guid guid, IEnumerable<AppointmentDto> appointments, bool isForced) {
224      using (contextFactory.GetContext()) {
225        return slaveManager.SetUptimeCalendarForResource(guid, appointments, isForced);
226      }
227    }
228
229    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
230    public ResponseObject<JobDto> AddJobWithGroupStrings(SerializedJob job, IEnumerable<string> resources) {
231      using (contextFactory.GetContext()) {
232        return jobManager.AddJobWithGroupStrings(job, resources);
233      }
234    }
235  }
236}
Note: See TracBrowser for help on using the repository browser.