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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
27 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
28 | using HeuristicLab.Hive.Contracts;
|
---|
29 | using HeuristicLab.Security.Contracts.Interfaces;
|
---|
30 | using HeuristicLab.Hive.Server.Core.InternalInterfaces;
|
---|
31 | using System.ServiceModel;
|
---|
32 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
33 | using HeuristicLab.Hive.Contracts.ResponseObjects;
|
---|
34 |
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Hive.Server.Core {
|
---|
37 | public class ServerConsoleFacade : IServerConsoleFacade {
|
---|
38 | private ISlaveManager slaveManager = ServiceLocator.GetSlaveManager();
|
---|
39 |
|
---|
40 | private IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
41 |
|
---|
42 | private IHivePermissionManager secMan = ServiceLocator.GetHivePermissionManager();
|
---|
43 |
|
---|
44 | private IContextFactory contextFactory = ServiceLocator.GetContextFactory();
|
---|
45 |
|
---|
46 | public Guid sessionID = Guid.Empty;
|
---|
47 |
|
---|
48 | public ServerConsoleFacade() {
|
---|
49 | }
|
---|
50 |
|
---|
51 | public Response Login(string username, string password) {
|
---|
52 | Response resp = new Response();
|
---|
53 |
|
---|
54 | sessionID = secMan.Login(username, password);
|
---|
55 | if (sessionID == Guid.Empty) {
|
---|
56 | resp.StatusMessage = ResponseStatus.Login_LoginFaild;
|
---|
57 | }
|
---|
58 | return resp;
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | public ResponseList<ClientDto> GetAllSlaves() {
|
---|
63 | using (contextFactory.GetContext(false)) {
|
---|
64 | secMan.Authorize("AccessClients", sessionID, Guid.Empty);
|
---|
65 | return slaveManager.GetAllSlaves();
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | public ResponseList<ClientGroupDto> GetAllClientGroups() {
|
---|
70 | using (contextFactory.GetContext(false)) {
|
---|
71 | //secMan.Authorize("AccessClientGroup", sessionID, Guid.Empty);
|
---|
72 | return slaveManager.GetAllClientGroups();
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public ResponseList<UpTimeStatisticsDto> GetAllUpTimeStatistics() {
|
---|
77 | using (contextFactory.GetContext(false)) {
|
---|
78 | secMan.Authorize("AccessStatistics", sessionID, Guid.Empty);
|
---|
79 | return slaveManager.GetAllUpTimeStatistics();
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public ResponseObject<ClientGroupDto> AddClientGroup(ClientGroupDto clientGroup) {
|
---|
84 | using (contextFactory.GetContext()) {
|
---|
85 | secMan.Authorize("AddClientGroup", sessionID, Guid.Empty);
|
---|
86 | return slaveManager.AddClientGroup(clientGroup);
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | public Response AddResourceToGroup(Guid clientGroupId, ResourceDto resource) {
|
---|
91 | using (contextFactory.GetContext()) {
|
---|
92 | secMan.Authorize("AddResource", sessionID, Guid.Empty);
|
---|
93 | return slaveManager.AddResourceToGroup(clientGroupId, resource);
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
|
---|
98 | using (contextFactory.GetContext()) {
|
---|
99 | return slaveManager.DeleteResourceFromGroup(clientGroupId, resourceId);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | public ResponseList<JobDto> GetAllJobs() {
|
---|
104 | using (contextFactory.GetContext(false)) {
|
---|
105 | secMan.Authorize("AccessJobs", sessionID, Guid.Empty);
|
---|
106 | return jobManager.GetAllJobs();
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | public ResponseList<JobDto> GetAllJobsWithFilter(State jobState, int offset, int count) {
|
---|
111 | using (contextFactory.GetContext(false)) {
|
---|
112 | secMan.Authorize("AccessJobs", sessionID, Guid.Empty);
|
---|
113 | return jobManager.GetAllJobsWithFilter(jobState, offset, count);
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | public ResponseObject<JobDto> GetJobById(Guid jobId) {
|
---|
118 | using (contextFactory.GetContext(false)) {
|
---|
119 | secMan.Authorize("AccessJobs", sessionID, jobId);
|
---|
120 | return jobManager.GetJobById(jobId);
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | public ResponseObject<JobDto> GetJobByIdWithDetails(Guid jobId) {
|
---|
125 | using (contextFactory.GetContext(false)) {
|
---|
126 | secMan.Authorize("AccessJobs", sessionID, jobId);
|
---|
127 | return jobManager.GetJobByIdWithDetails(jobId);
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | public ResponseObject<JobDto> AddNewJob(SerializedJob job) {
|
---|
132 | using (contextFactory.GetContext()) {
|
---|
133 | secMan.Authorize("AddJob", sessionID, job.JobInfo.Id);
|
---|
134 | return jobManager.AddNewJob(job);
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | //public ResponseObject<JobDto> GetLastJobResultOf(Guid jobId) {
|
---|
139 | // using (contextFactory.GetContext(false)) {
|
---|
140 | // secMan.Authorize("AccessJobResults", sessionID, jobId);
|
---|
141 | // return jobManager.GetLastJobResultOf(jobId);
|
---|
142 | // }
|
---|
143 | //}
|
---|
144 |
|
---|
145 | public ResponseObject<SerializedJob> GetLastSerializedResult(Guid jobId, bool requested, bool snapshot) {
|
---|
146 | using (contextFactory.GetContext(false)) {
|
---|
147 | secMan.Authorize("AccessJobResults", sessionID, jobId);
|
---|
148 | return jobManager.GetLastSerializedResult(jobId, requested, snapshot);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | public ResponseObject<JobResultList> GetJobResults(IEnumerable<Guid> jobIds) {
|
---|
153 | using (contextFactory.GetContext(false)) {
|
---|
154 | //secMan.Authorize("AccessJobResults", sessionID, jobId); skip authorization
|
---|
155 | return jobManager.GetJobResults(jobIds);
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | //public Response RemoveJob(Guid jobId) {
|
---|
160 | // using (contextFactory.GetContext()) {
|
---|
161 | // secMan.Authorize("RemoveJob", sessionID, jobId);
|
---|
162 | // return jobManager.RemoveJob(jobId);
|
---|
163 | // }
|
---|
164 | //}
|
---|
165 |
|
---|
166 | public Response RequestSnapshot(Guid jobId) {
|
---|
167 | using (contextFactory.GetContext()) {
|
---|
168 | secMan.Authorize("AccessJobResults", sessionID, jobId);
|
---|
169 | return jobManager.RequestSnapshot(jobId);
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | public Response AbortJob(Guid jobId) {
|
---|
174 | using (contextFactory.GetContext()) {
|
---|
175 | secMan.Authorize("AbortJob", sessionID, Guid.Empty);
|
---|
176 | return jobManager.AbortJob(jobId);
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | public ResponseObject<ClientGroupDtoList> GetAllGroupsOfResource(Guid resourceId) {
|
---|
181 | using (contextFactory.GetContext(false)) {
|
---|
182 | secMan.Authorize("AccessUserGroup", sessionID, Guid.Empty);
|
---|
183 | return slaveManager.GetAllGroupsOfResource(resourceId);
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | public Response DeleteClientGroup(Guid clientGroupId) {
|
---|
188 | using (contextFactory.GetContext()) {
|
---|
189 | secMan.Authorize("DeleteClientGroup", sessionID, Guid.Empty);
|
---|
190 | return slaveManager.DeleteClientGroup(clientGroupId);
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | public ResponseList<ProjectDto> GetAllProjects() {
|
---|
195 | using (contextFactory.GetContext(false)) {
|
---|
196 | secMan.Authorize("AccessProjects", sessionID, Guid.Empty);
|
---|
197 | return jobManager.GetAllProjects();
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | public Response CreateProject(ProjectDto project) {
|
---|
202 | using (contextFactory.GetContext()) {
|
---|
203 | secMan.Authorize("CreateProjects", sessionID, Guid.Empty);
|
---|
204 | return jobManager.CreateProject(project);
|
---|
205 | }
|
---|
206 | }
|
---|
207 |
|
---|
208 | public Response ChangeProject(ProjectDto project) {
|
---|
209 | using (contextFactory.GetContext()) {
|
---|
210 | secMan.Authorize("ChangeProjects", sessionID, Guid.Empty);
|
---|
211 | return jobManager.ChangeProject(project);
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | public Response DeleteProject(Guid projectId) {
|
---|
216 | using (contextFactory.GetContext()) {
|
---|
217 | secMan.Authorize("DeleteProjects", sessionID, projectId);
|
---|
218 | return jobManager.DeleteProject(projectId);
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | public ResponseList<JobDto> GetJobsByProject(Guid projectId) {
|
---|
223 | using (contextFactory.GetContext(false)) {
|
---|
224 | secMan.Authorize("AccessJobs", sessionID, Guid.Empty);
|
---|
225 | return jobManager.GetJobsByProject(projectId);
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | public ResponseList<AppointmentDto> GetUptimeCalendarForResource(Guid guid) {
|
---|
230 | using (contextFactory.GetContext(false)) {
|
---|
231 | return slaveManager.GetUptimeCalendarForResource(guid);
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | public Response SetUptimeCalendarForResource(Guid guid, IEnumerable<AppointmentDto> appointments, bool isForced) {
|
---|
236 | using (contextFactory.GetContext()) {
|
---|
237 | return slaveManager.SetUptimeCalendarForResource(guid, appointments, isForced);
|
---|
238 | }
|
---|
239 | }
|
---|
240 |
|
---|
241 | public ResponseObject<JobDto> AddJobWithGroupStrings(SerializedJob job, IEnumerable<string> resources) {
|
---|
242 | using (contextFactory.GetContext()) {
|
---|
243 | return jobManager.AddJobWithGroupStrings(job, resources);
|
---|
244 | }
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|