[4593] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.ServiceModel;
|
---|
| 6 | using HeuristicLab.Services.Hive.Common.ServiceContracts;
|
---|
| 7 | using HeuristicLab.Services.Hive.Common.DataTransfer;
|
---|
| 8 | using HeuristicLab.Hive.Contracts;
|
---|
| 9 | using System.IO;
|
---|
| 10 | using System.Security.Permissions;
|
---|
[4598] | 11 | using System.Data.Linq;
|
---|
[4593] | 12 |
|
---|
| 13 | namespace HeuristicLab.Services.Hive {
|
---|
[4598] | 14 |
|
---|
| 15 |
|
---|
[4593] | 16 | /// <summary>
|
---|
| 17 | /// Implementation of the Hive service (interface <see cref="IHiveService"/>).
|
---|
| 18 | /// </summary>
|
---|
| 19 | [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
|
---|
| 20 | public class HiveService : IHiveService {
|
---|
[4598] | 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 | }
|
---|
[4593] | 30 |
|
---|
| 31 | #region Job Methods
|
---|
| 32 | [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
|
---|
| 33 | [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
|
---|
[4598] | 34 | public Guid AddJob(Job jobDto, JobData jobDataDto) {
|
---|
[4593] | 35 | using (contextFactory.GetContext()) {
|
---|
[4598] | 36 | jobDataDto.JobId = dao.AddJob(jobDto);
|
---|
| 37 | dao.AddJobData(jobDataDto);
|
---|
| 38 | return jobDataDto.JobId;
|
---|
[4593] | 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[4598] | 42 | public Guid AddChildJob(Guid parentJobId, Job jobDto, JobData jobDataDto) {
|
---|
| 43 | jobDto.ParentJobId = parentJobId;
|
---|
| 44 | return AddJob(jobDto, jobDataDto);
|
---|
[4593] | 45 | }
|
---|
| 46 |
|
---|
[4598] | 47 | public Job GetJob(Guid jobId) {
|
---|
| 48 | using (contextFactory.GetContext()) {
|
---|
| 49 | return dao.GetJob(jobId);
|
---|
| 50 | }
|
---|
[4593] | 51 | }
|
---|
| 52 |
|
---|
[4598] | 53 | public IEnumerable<Job> GetJobs() {
|
---|
| 54 | using (contextFactory.GetContext()) {
|
---|
| 55 | return dao.GetJobs(x => true);
|
---|
| 56 | }
|
---|
[4593] | 57 | }
|
---|
| 58 |
|
---|
[4598] | 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 | }
|
---|
[4593] | 63 | }
|
---|
| 64 |
|
---|
[4598] | 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 | }
|
---|
[4593] | 69 | }
|
---|
| 70 |
|
---|
[4598] | 71 | // formerly GetLastSerializedResult
|
---|
| 72 | public JobData GetJobData(Guid jobId) {
|
---|
| 73 | using (contextFactory.GetContext()) {
|
---|
| 74 | return dao.GetJobData(jobId);
|
---|
| 75 | }
|
---|
[4593] | 76 | }
|
---|
| 77 |
|
---|
[4598] | 78 | public Stream GetJobDataStreamed(Guid jobId) {
|
---|
[4593] | 79 | throw new NotImplementedException();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[4598] | 82 | public void UpdateJob(Job jobDto, JobData jobDataDto) {
|
---|
| 83 | using (contextFactory.GetContext()) {
|
---|
| 84 | dao.UpdateJob(jobDto);
|
---|
| 85 | dao.UpdateJobData(jobDataDto);
|
---|
| 86 | }
|
---|
[4593] | 87 | }
|
---|
| 88 |
|
---|
[4598] | 89 | public void UpdateJobDataStreamed(Stream stream) {
|
---|
[4593] | 90 | throw new NotImplementedException();
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | public void DeleteChildJobs(Guid jobId) {
|
---|
[4598] | 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 | }
|
---|
[4593] | 101 | }
|
---|
| 102 |
|
---|
[4598] | 103 | public Job AquireJob(Guid slaveId) {
|
---|
[4593] | 104 | throw new NotImplementedException();
|
---|
| 105 | }
|
---|
[4598] | 106 | #endregion
|
---|
[4593] | 107 |
|
---|
| 108 |
|
---|
[4598] | 109 | #region Job Control Methods
|
---|
| 110 | public void AbortJob(Guid jobId) {
|
---|
[4593] | 111 | throw new NotImplementedException();
|
---|
| 112 | }
|
---|
[4598] | 113 | public Job PauseJob(JobData serializedJob) {
|
---|
[4593] | 114 | throw new NotImplementedException();
|
---|
| 115 | }
|
---|
[4598] | 116 | #endregion
|
---|
[4593] | 117 |
|
---|
| 118 |
|
---|
| 119 | #region HiveExperiment Methods
|
---|
| 120 | public IEnumerable<HiveExperiment> GetHiveExperiments() {
|
---|
[4598] | 121 | using (contextFactory.GetContext()) {
|
---|
| 122 | return dao.GetHiveExperiments(x => x.UserId == auth.UserId);
|
---|
| 123 | }
|
---|
[4593] | 124 | }
|
---|
| 125 |
|
---|
[4598] | 126 | public void UpdateHiveExperiment(HiveExperiment hiveExperimentDto) {
|
---|
| 127 | using (contextFactory.GetContext()) {
|
---|
| 128 | dao.UpdateHiveExperiment(hiveExperimentDto);
|
---|
| 129 | }
|
---|
[4593] | 130 | }
|
---|
| 131 |
|
---|
| 132 | public void DeleteHiveExperiment(Guid hiveExperimentId) {
|
---|
[4598] | 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 | }
|
---|
[4593] | 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
|
---|
[4598] | 218 | public Guid AddSlaveGroup(SlaveGroup slaveGroup) {
|
---|
| 219 | using (contextFactory.GetContext()) {
|
---|
| 220 | return dao.AddSlaveGroup(slaveGroup);
|
---|
| 221 | }
|
---|
[4593] | 222 | }
|
---|
| 223 |
|
---|
[4598] | 224 | public IEnumerable<Slave> GetSlaves() {
|
---|
| 225 | using (contextFactory.GetContext()) {
|
---|
| 226 | return dao.GetSlaves(x => true);
|
---|
| 227 | }
|
---|
[4593] | 228 | }
|
---|
| 229 |
|
---|
[4598] | 230 | public IEnumerable<SlaveGroup> GetSlaveGroups() {
|
---|
| 231 | using (contextFactory.GetContext()) {
|
---|
| 232 | return dao.GetSlaveGroups(x => true);
|
---|
| 233 | }
|
---|
[4593] | 234 | }
|
---|
[4598] | 235 |
|
---|
| 236 | public void DeleteSlaveGroup(Guid slaveGroupId) {
|
---|
| 237 | using (contextFactory.GetContext()) {
|
---|
| 238 | dao.DeleteSlaveGroup(slaveGroupId);
|
---|
| 239 | }
|
---|
[4593] | 240 | }
|
---|
| 241 |
|
---|
[4598] | 242 | public void AddResourceToGroup(Guid slaveGroupId, Resource resource) {
|
---|
| 243 | using (contextFactory.GetContext()) {
|
---|
| 244 | throw new NotImplementedException();
|
---|
| 245 | }
|
---|
[4593] | 246 | }
|
---|
| 247 |
|
---|
[4598] | 248 | public void RemoveResourceFromGroup(Guid clientGroupId, Guid resourceId) {
|
---|
| 249 | using (contextFactory.GetContext()) {
|
---|
| 250 | throw new NotImplementedException();
|
---|
| 251 | }
|
---|
[4593] | 252 | }
|
---|
[4598] | 253 | #endregion
|
---|
[4593] | 254 |
|
---|
[4598] | 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;
|
---|
[4593] | 271 | }
|
---|
| 272 | #endregion
|
---|
| 273 |
|
---|
[4598] | 274 |
|
---|
[4593] | 275 | }
|
---|
| 276 | }
|
---|