Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Server/3.3/HiveService.cs @ 4598

Last change on this file since 4598 was 4598, checked in by cneumuel, 14 years ago

worked on implementation new data layer and server components (#1233)

File size: 8.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.ServiceModel;
6using HeuristicLab.Services.Hive.Common.ServiceContracts;
7using HeuristicLab.Services.Hive.Common.DataTransfer;
8using HeuristicLab.Hive.Contracts;
9using System.IO;
10using System.Security.Permissions;
11using System.Data.Linq;
12
13namespace HeuristicLab.Services.Hive {
14
15
16  /// <summary>
17  /// Implementation of the Hive service (interface <see cref="IHiveService"/>).
18  /// </summary>
19  [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
20  public class HiveService : IHiveService {
21    private DataAccess.IHiveDao dao {
22      get { return ServiceLocator.Instance.HiveDao; }
23    }
24    private DataAccess.IContextFactory<DataAccess.HiveDataContext> contextFactory {
25      get { return ServiceLocator.Instance.ContextFactory; }
26    }
27    private IAuthorizationManager auth {
28      get { return ServiceLocator.Instance.AuthorizationManager; }
29    }
30
31    #region Job Methods
32    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
33    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
34    public Guid AddJob(Job jobDto, JobData jobDataDto) {
35      using (contextFactory.GetContext()) {
36        jobDataDto.JobId = dao.AddJob(jobDto);
37        dao.AddJobData(jobDataDto);
38        return jobDataDto.JobId;
39      }
40    }
41
42    public Guid AddChildJob(Guid parentJobId, Job jobDto, JobData jobDataDto) {
43      jobDto.ParentJobId = parentJobId;
44      return AddJob(jobDto, jobDataDto);
45    }
46
47    public Job GetJob(Guid jobId) {
48      using (contextFactory.GetContext()) {
49        return dao.GetJob(jobId);
50      }
51    }
52
53    public IEnumerable<Job> GetJobs() {
54      using (contextFactory.GetContext()) {
55        return dao.GetJobs(x => true);
56      }
57    }
58
59    public IEnumerable<LightweightJob> GetLightweightJobs(IEnumerable<Guid> jobIds) {
60      using (contextFactory.GetContext()) {
61        return dao.GetJobs(x => jobIds.Contains(x.JobId)).Select(x => new LightweightJob(x)).ToArray();
62      }
63    }
64
65    public IEnumerable<LightweightJob> GetLightweightChildJobs(Guid? parentJobId, bool recursive, bool includeParent) {
66      using (contextFactory.GetContext()) {
67        return GetChildJobs(parentJobId, recursive, includeParent).Select(x => new LightweightJob(x)).ToArray();
68      }
69    }
70
71    // formerly GetLastSerializedResult
72    public JobData GetJobData(Guid jobId) {
73      using (contextFactory.GetContext()) {
74        return dao.GetJobData(jobId);
75      }
76    }
77
78    public Stream GetJobDataStreamed(Guid jobId) {
79      throw new NotImplementedException();
80    }
81
82    public void UpdateJob(Job jobDto, JobData jobDataDto) {
83      using (contextFactory.GetContext()) {
84        dao.UpdateJob(jobDto);
85        dao.UpdateJobData(jobDataDto);
86      }
87    }
88
89    public void UpdateJobDataStreamed(Stream stream) {
90      throw new NotImplementedException();
91    }
92
93    public void DeleteChildJobs(Guid jobId) {
94      using (contextFactory.GetContext()) {
95        var jobs = GetChildJobs(jobId, true, false);
96        foreach (var job in jobs) {
97          dao.DeleteJob(job.Id);
98          dao.DeleteJobData(job.Id);
99        };
100      }
101    }
102
103    public Job AquireJob(Guid slaveId) {
104      throw new NotImplementedException();
105    }
106    #endregion
107
108
109    #region Job Control Methods
110    public void AbortJob(Guid jobId) {
111      throw new NotImplementedException();
112    }
113    public Job PauseJob(JobData serializedJob) {
114      throw new NotImplementedException();
115    }
116    #endregion
117
118
119    #region HiveExperiment Methods
120    public IEnumerable<HiveExperiment> GetHiveExperiments() {
121      using (contextFactory.GetContext()) {
122        return dao.GetHiveExperiments(x => x.UserId == auth.UserId);
123      }
124    }
125
126    public void UpdateHiveExperiment(HiveExperiment hiveExperimentDto) {
127      using (contextFactory.GetContext()) {
128        dao.UpdateHiveExperiment(hiveExperimentDto);
129      }
130    }
131
132    public void DeleteHiveExperiment(Guid hiveExperimentId) {
133      using (contextFactory.GetContext()) {
134        HiveExperiment he = dao.GetHiveExperiment(hiveExperimentId);
135        if(he.RootJobId.HasValue) {
136          var jobs = GetChildJobs(he.RootJobId.Value, true, true);
137          foreach(var j in jobs) {
138            dao.DeleteJobData(j.Id);
139            dao.DeleteJob(j.Id);
140          }
141        }
142        dao.DeleteHiveExperiment(hiveExperimentId);
143      }
144    }
145    #endregion
146
147    #region Project Methods
148    public Project GetAllProjects() {
149      throw new NotImplementedException();
150    }
151
152    public void CreateProject(Project project) {
153      throw new NotImplementedException();
154    }
155
156    public void ChangeProject(Project project) {
157      throw new NotImplementedException();
158    }
159
160    public void DeleteProject(Guid projectId) {
161      throw new NotImplementedException();
162    }
163
164    public IEnumerable<Job> GetJobsByProject(Guid projectId) {
165      throw new NotImplementedException();
166    }
167    #endregion
168
169    #region Login Methods
170    public void Login() {
171      throw new NotImplementedException();
172    }
173
174    public void Login(Slave slave) {
175      throw new NotImplementedException();
176    }
177
178    public void Logout(Guid clientId) {
179      throw new NotImplementedException();
180    }
181    #endregion
182
183    #region Heartbeat Methods
184    public List<MessageContainer> ProcessHeartBeat(HeartBeat hbData) {
185      throw new NotImplementedException();
186    }
187    #endregion
188
189    #region Plugin Methods
190    public IEnumerable<HivePluginData> GetPlugins(List<HivePlugin> pluginList) {
191      throw new NotImplementedException();
192    }
193
194    public System.IO.Stream GetStreamedPlugins(List<HivePlugin> pluginList) {
195      throw new NotImplementedException();
196    }
197    #endregion
198
199    #region Calendar Methods
200    public IEnumerable<Appointment> GetCalendar(Guid clientId) {
201      throw new NotImplementedException();
202    }
203
204    public void SetCalendarStatus(Guid clientId, CalendarState state) {
205      throw new NotImplementedException();
206    }
207
208    public IEnumerable<Appointment> GetUptimeCalendarForResource(Guid guid) {
209      throw new NotImplementedException();
210    }
211
212    public void SetUptimeCalendarForResource(Guid guid, IEnumerable<Appointment> appointments, bool isForced) {
213      throw new NotImplementedException();
214    }
215    #endregion
216
217    #region Slave Methods
218    public Guid AddSlaveGroup(SlaveGroup slaveGroup) {
219      using (contextFactory.GetContext()) {
220        return dao.AddSlaveGroup(slaveGroup);
221      }
222    }
223
224    public IEnumerable<Slave> GetSlaves() {
225      using (contextFactory.GetContext()) {
226        return dao.GetSlaves(x => true);
227      }
228    }
229
230    public IEnumerable<SlaveGroup> GetSlaveGroups() {
231      using (contextFactory.GetContext()) {
232        return dao.GetSlaveGroups(x => true);
233      }
234    }
235   
236    public void DeleteSlaveGroup(Guid slaveGroupId) {
237      using (contextFactory.GetContext()) {
238        dao.DeleteSlaveGroup(slaveGroupId);
239      }
240    }
241
242    public void AddResourceToGroup(Guid slaveGroupId, Resource resource) {
243      using (contextFactory.GetContext()) {
244        throw new NotImplementedException();       
245      }
246    }
247
248    public void RemoveResourceFromGroup(Guid clientGroupId, Guid resourceId) {
249      using (contextFactory.GetContext()) {
250        throw new NotImplementedException();
251      }
252    }
253    #endregion
254
255    #region Helper Methods
256    private IEnumerable<Job> GetChildJobs(Guid? parentJobId, bool recursive, bool includeParent) {
257      var jobs = new List<Job>(dao.GetJobs(x => parentJobId == null ? !x.ParentJobId.HasValue : x.ParentJobId.Value == parentJobId));
258
259      if (includeParent) {
260        jobs.Add(GetJob(parentJobId.Value));
261      }
262
263      if (recursive) {
264        var childs = new List<Job>();
265        foreach (var job in jobs) {
266          childs.AddRange(GetChildJobs(job.Id, recursive, false));
267        }
268        jobs.AddRange(childs);
269      }
270      return jobs;
271    }
272    #endregion
273
274
275  }
276}
Note: See TracBrowser for help on using the repository browser.