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 @ 5153

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

#1260

  • increased timeouts for sent jobs (which are needed if the jobs take long time to deserialize on slave)
  • added DeleteJob to ClientService
  • made optimizer actually Pause instead of Stop when stop is called explicitly (so they can be resumed later)
  • temporarily disabled job-abortion from server because it aborted jobs which took too long to deserialize on slaves (this issue needs to be investigated)
  • reduced locking of engines on slave so that the deserialization does not block heartbeats

#1347

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