Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ClientFacade.cs @ 5213

Last change on this file since 5213 was 5213, checked in by cneumuel, 13 years ago

#1260

  • changed HiveEngine to be compatible with recent changes of engine
File size: 7.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Security.Permissions;
26using HeuristicLab.Hive.Contracts;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
28using HeuristicLab.Hive.Contracts.Interfaces;
29using HeuristicLab.Hive.Contracts.ResponseObjects;
30using HeuristicLab.Hive.Server.DataAccess;
31using System.ServiceModel;
32
33namespace HeuristicLab.Hive.Server.Core {
34  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
35  public class ClientFacade : IClientFacade {
36
37    private IJobManager jobManager = ServiceLocator.GetJobManager();
38    private IContextFactory contextFactory = ServiceLocator.GetContextFactory();
39
40    public ClientFacade() {
41    }
42
43    #region IClientFacade Members
44
45    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
46    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
47    public ResponseObject<JobDto> AddJob(SerializedJob job) {
48      using (contextFactory.GetContext()) {
49        return jobManager.AddNewJob(job);
50      }
51    }
52
53    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
54    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
55    public ResponseObject<JobDto> AddJobWithGroupStrings(SerializedJob job, IEnumerable<string> resources) {
56      using (contextFactory.GetContext()) {
57        return jobManager.AddJobWithGroupStrings(job, resources);
58      }
59    }
60
61    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
62    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
63    public Response RequestSnapshot(Guid jobId) {
64      using (contextFactory.GetContext()) {
65        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
66        return jobManager.RequestSnapshot(jobId);
67      }
68    }
69
70    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
71    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
72    public ResponseObject<SerializedJob> GetLastSerializedResult(Guid jobId) {
73      using (contextFactory.GetContext(false)) {
74        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
75        return jobManager.GetLastSerializedResult(jobId);
76      }
77    }
78
79    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
80    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
81    public ResponseObject<SerializedJob> GetSnapshotResult(Guid jobId) {
82      using (contextFactory.GetContext(false)) {
83        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
84        return jobManager.GetSnapshotResult(jobId);
85      }
86    }
87
88    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
89    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
90    public ResponseObject<JobDto> GetJobById(Guid jobId) {
91      using (contextFactory.GetContext(false)) {
92        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
93        return jobManager.GetJobById(jobId);
94      }
95    }
96
97    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
98    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
99    public Response AbortJob(Guid jobId) {
100      using (contextFactory.GetContext()) {
101        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
102        return jobManager.AbortJob(jobId);
103      }
104    }
105
106    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
107    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
108    public ResponseObject<JobResultList> GetJobResults(IEnumerable<Guid> jobIds) {
109      using (contextFactory.GetContext(false)) {
110        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobIds.ToArray());
111        return jobManager.GetJobResults(jobIds);
112      }
113    }
114
115    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
116    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
117    public ResponseObject<JobResultList> GetChildJobResults(Guid? parentJobId, bool recursive, bool includeParent) {
118      using (contextFactory.GetContext(false)) {
119        if (parentJobId.HasValue) {
120          ServiceLocator.GetAuthorizationManager().AuthorizeJobs(parentJobId.Value);
121        }
122        // If parentJobId is null, GetChildJobResults will filter the results for the current user
123        return jobManager.GetChildJobResults(parentJobId, recursive, includeParent);
124      }
125    }
126
127    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
128    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
129    public ResponseObject<HiveExperimentDtoList> GetHiveExperiments() {
130      using (contextFactory.GetContext(false)) {
131        return jobManager.GetHiveExperiments();
132      }
133    }
134
135    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
136    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
137    public ResponseObject<HiveExperimentDto> UpdateHiveExperiment(HiveExperimentDto hiveExperimentDto) {
138      using (contextFactory.GetContext()) {
139        if (hiveExperimentDto.UserId == Guid.Empty) {
140          hiveExperimentDto.UserId = ServiceLocator.GetAuthorizationManager().UserId;
141        } else {
142          ServiceLocator.GetAuthorizationManager().Authorize(hiveExperimentDto.UserId);
143        }
144        return jobManager.UpdateHiveExperiment(hiveExperimentDto);
145      }
146    }
147
148    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
149    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
150    public Response DeleteHiveExperiment(Guid hiveExperimentId) {
151      using (contextFactory.GetContext()) {
152        var hiveExperimentDto = DaoLocator.HiveExperimentDao.FindById(hiveExperimentId);
153        if (hiveExperimentDto != null) {
154          ServiceLocator.GetAuthorizationManager().Authorize(hiveExperimentDto.UserId);
155        }
156        return jobManager.DeleteHiveExperiment(hiveExperimentId);
157      }
158    }
159
160    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
161    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
162    public Response DeleteJob(Guid jobId) {
163      using (contextFactory.GetContext()) {
164        var jobDto = DaoLocator.JobDao.FindById(jobId);
165        if (jobId != null) {
166          ServiceLocator.GetAuthorizationManager().Authorize(jobDto.UserId);
167        }
168        return jobManager.DeleteJob(jobId);
169      }
170    }
171
172    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
173    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
174    public ResponseObject<JobDto> AddChildJob(Guid parentJobId, SerializedJob serializedJob) {
175      using (contextFactory.GetContext()) {
176        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(parentJobId);
177        return jobManager.AddChildJob(parentJobId, serializedJob);
178      }
179    }
180    #endregion
181  }
182}
Note: See TracBrowser for help on using the repository browser.