- Timestamp:
- 05/03/13 13:47:27 (12 years ago)
- Location:
- branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3
- Files:
-
- 11 edited
- 2 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Convert.cs
r9393 r9434 103 103 public static DT.TaskData ToDto(DB.TaskData source) { 104 104 if (source == null) return null; 105 return new DT.TaskData { TaskId = source.TaskId, Data = source.Data .ToArray(), LastUpdate = source.LastUpdate };105 return new DT.TaskData { TaskId = source.TaskId, Data = source.Data, LastUpdate = source.LastUpdate }; 106 106 } 107 107 public static DB.TaskData ToEntity(DT.TaskData source) { -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
r9391 r9434 137 137 <Compile Include="DataTransfer\Statistics.cs" /> 138 138 <Compile Include="DataTransfer\UserStatistics.cs" /> 139 <Compile Include="OptimizedHiveDao.cs" /> 139 140 <Compile Include="HiveDao.cs" /> 140 <Compile Include="HiveDtoDao.cs" />141 141 <Compile Include="HiveJanitor.cs" /> 142 142 <Compile Include="HiveOperationContext.cs" /> 143 <Compile Include="Interfaces\IOptimizedHiveDao.cs" /> 143 144 <Compile Include="Interfaces\IHiveDao.cs" /> 144 <Compile Include="Interfaces\IHiveDtoDao.cs" />145 145 <Compile Include="Interfaces\ITaskScheduler.cs" /> 146 146 <Compile Include="Scheduler\TaskInfoForScheduler.cs" /> -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveDao.cs
r9394 r9434 27 27 28 28 namespace HeuristicLab.Services.Hive.DataAccess { 29 public class HiveD toDao : IHiveDtoDao {29 public class HiveDao : IHiveDao { 30 30 public static HiveDataContext CreateContext(bool longRunning = false) { 31 31 var context = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); … … 33 33 return context; 34 34 } 35 36 public HiveDtoDao() { }37 35 38 36 #region Task Methods -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs
r9391 r9434 37 37 } 38 38 39 private IHiveD toDao dao {40 get { return ServiceLocator.Instance.HiveD toDao; }39 private IHiveDao dao { 40 get { return ServiceLocator.Instance.HiveDao; } 41 41 } 42 42 -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveOperationContext.cs
r9393 r9434 22 22 using System; 23 23 using System.Collections.ObjectModel; 24 using System.Diagnostics;25 using System.IO;26 24 using System.ServiceModel; 27 25 using System.ServiceModel.Channels; 28 26 using System.ServiceModel.Description; 29 27 using System.ServiceModel.Dispatcher; 30 using System.Text;31 28 using HeuristicLab.Services.Hive.DataAccess; 32 29 33 30 namespace HeuristicLab.Services.Hive { 34 31 public class HiveOperationContext : IExtension<OperationContext> { 32 35 33 public static HiveOperationContext Current { 36 34 get { … … 42 40 public HiveDataContext DataContext { 43 41 get { 44 if (dataContext == null) { 45 dataContext = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); 46 //dataContext.Log = new DebugWriter(); 47 } 48 return dataContext; 42 return dataContext ?? (dataContext = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)); 49 43 } 50 44 } … … 67 61 } 68 62 69 public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState) {63 public void BeforeSendReply(ref Message reply, object correlationState) { 70 64 OperationContext.Current.Extensions.Remove(HiveOperationContext.Current); 71 65 } … … 88 82 } 89 83 } 90 91 internal class DebugWriter : TextWriter {92 public override Encoding Encoding {93 get { return Encoding.UTF8; }94 }95 96 public override void Write(char value) {97 Debug.Write(value);98 }99 100 public override void Write(string value) {101 Debug.Write(value);102 }103 104 public override void WriteLine(string value) {105 Debug.WriteLine(value);106 }107 }108 84 } -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs
r9399 r9434 39 39 [HiveOperationContextBehavior] 40 40 public class HiveService : IHiveService { 41 private IHiveDtoDao dtoDao {42 get { return ServiceLocator.Instance.HiveDtoDao; }43 }44 41 private IHiveDao dao { 45 42 get { return ServiceLocator.Instance.HiveDao; } 46 43 } 44 private IOptimizedHiveDao optimizedDao { 45 get { return ServiceLocator.Instance.OptimizedHiveDao; } 46 } 47 47 private Access.IRoleVerifier authen { 48 48 get { return ServiceLocator.Instance.RoleVerifier; } … … 68 68 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 69 69 return trans.UseTransaction(() => { 70 task.Id = dtoDao.AddTask(task); 71 taskData.TaskId = task.Id; 72 taskData.LastUpdate = DateTime.Now; 73 dtoDao.AssignJobToResource(task.Id, resourceIds); 74 dtoDao.AddTaskData(taskData); 75 dtoDao.UpdateTaskState(task.Id, DA.TaskState.Waiting, null, userManager.CurrentUserId, null); 76 return taskData.TaskId; 70 var t = DT.Convert.ToEntity(task); 71 t.RequiredPlugins.AddRange(task.PluginsNeededIds.Select(pluginId => new DA.RequiredPlugin { Task = t, PluginId = pluginId })); 72 73 t.JobData = DT.Convert.ToEntity(taskData); 74 t.JobData.LastUpdate = DateTime.Now; 75 76 optimizedDao.AddTask(t); 77 78 dao.AssignJobToResource(t.TaskId, resourceIds); 79 80 optimizedDao.UpdateTaskState(t.TaskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, null); 81 82 return t.TaskId; 77 83 }, false, true); 78 84 } … … 80 86 public Guid AddChildTask(Guid parentTaskId, Task task, TaskData taskData) { 81 87 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 82 return trans.UseTransaction(() => { 83 task.ParentTaskId = parentTaskId; 84 return AddTask(task, taskData, dtoDao.GetAssignedResources(parentTaskId).Select(x => x.Id)); 85 }, false, true); 88 task.ParentTaskId = parentTaskId; 89 return AddTask(task, taskData, optimizedDao.GetAssignedResourceIds(parentTaskId)); 86 90 } 87 91 … … 91 95 92 96 return trans.UseTransaction(() => { 93 return DT.Convert.ToDto( dao.GetTaskById(taskId));97 return DT.Convert.ToDto(optimizedDao.GetTaskById(taskId)); 94 98 }, false, false); 95 99 } … … 98 102 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 99 103 return trans.UseTransaction(() => { 100 var tasks = d toDao.GetTasks(x => true);104 var tasks = dao.GetTasks(x => true); 101 105 foreach (var task in tasks) 102 106 author.AuthorizeForTask(task.Id, Permission.Read); … … 109 113 110 114 return trans.UseTransaction(() => { 111 var tasks = d toDao.GetTasks(x => taskIds.Contains(x.TaskId)).Select(x => new LightweightTask(x)).ToArray();115 var tasks = dao.GetTasks(x => taskIds.Contains(x.TaskId)).Select(x => new LightweightTask(x)).ToArray(); 112 116 foreach (var task in tasks) 113 117 author.AuthorizeForTask(task.Id, Permission.Read); … … 132 136 133 137 return trans.UseTransaction(() => { 134 return dao.GetLightweightTasks(jobId).ToArray();138 return optimizedDao.GetLightweightTasks(jobId).ToArray(); 135 139 }, false, true); 136 140 } … … 141 145 142 146 return trans.UseTransaction(() => { 143 return d toDao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray();147 return dao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray(); 144 148 }, false, false); 145 149 } … … 150 154 151 155 return trans.UseTransaction(() => { 152 return d toDao.GetTaskData(taskId);156 return dao.GetTaskData(taskId); 153 157 }); 154 158 } … … 159 163 160 164 trans.UseTransaction(() => { 161 var task = dao.GetTaskByDto(taskDto);162 dao.UpdateTask(task);165 var task = optimizedDao.GetTaskByDto(taskDto); 166 optimizedDao.UpdateTask(task); 163 167 }); 164 168 } … … 169 173 170 174 trans.UseTransaction(() => { 171 var t = dao.GetTaskByDto(task);172 dao.UpdateTask(t);173 }); 174 175 trans.UseTransaction(() => { 176 var data = dao.GetTaskDataByDto(taskData);175 var t = optimizedDao.GetTaskByDto(task); 176 optimizedDao.UpdateTask(t); 177 }); 178 179 trans.UseTransaction(() => { 180 var data = optimizedDao.GetTaskDataByDto(taskData); 177 181 data.LastUpdate = DateTime.Now; 178 dao.UpdateTaskData(data);182 optimizedDao.UpdateTaskData(data); 179 183 }); 180 184 } … … 184 188 author.AuthorizeForTask(taskId, Permission.Full); 185 189 trans.UseTransaction(() => { 186 d toDao.DeleteTask(taskId);190 dao.DeleteTask(taskId); 187 191 }); 188 192 } … … 194 198 var tasks = GetChildTasks(parentTaskId, true, false); 195 199 foreach (var task in tasks) { 196 d toDao.DeleteTask(task.Id);197 d toDao.DeleteTaskData(task.Id);200 dao.DeleteTask(task.Id); 201 dao.DeleteTaskData(task.Id); 198 202 }; 199 203 }); … … 205 209 206 210 return trans.UseTransaction(() => { 207 var task = dao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception);211 var task = optimizedDao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception); 208 212 209 213 if (task.Command.HasValue && task.Command.Value == DA.Command.Pause && task.State == DA.TaskState.Paused) { … … 215 219 } else if (taskState == TaskState.Paused && !task.Command.HasValue) { 216 220 // slave paused and uploaded the task (no user-command) -> set waiting. 217 task = dao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception);218 } 219 220 // dao.UpdateTaskAndPlugins(task); no idea why this is needed221 task = optimizedDao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception); 222 } 223 224 //optimizedDao.UpdateTaskAndPlugins(task); no idea why this is needed 221 225 return DT.Convert.ToDto(task); 222 226 }); … … 225 229 public IEnumerable<Task> GetTasksByResourceId(Guid resourceId) { 226 230 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 227 var tasks = trans.UseTransaction(() => d toDao.GetJobsByResourceId(resourceId));231 var tasks = trans.UseTransaction(() => dao.GetJobsByResourceId(resourceId)); 228 232 foreach (var task in tasks) 229 233 author.AuthorizeForTask(task.Id, Permission.Read); … … 237 241 author.AuthorizeForTask(taskId, Permission.Full); 238 242 trans.UseTransaction(() => { 239 var task = d toDao.GetTask(taskId);243 var task = dao.GetTask(taskId); 240 244 if (task.State == TaskState.Calculating || task.State == TaskState.Transferring) { 241 245 task.Command = Command.Stop; 242 d toDao.UpdateTask(task);246 dao.UpdateTask(task); 243 247 } else { 244 248 if (task.State != TaskState.Aborted && task.State != TaskState.Finished && task.State != TaskState.Failed) { … … 253 257 author.AuthorizeForTask(taskId, Permission.Full); 254 258 trans.UseTransaction(() => { 255 var job = d toDao.GetTask(taskId);259 var job = dao.GetTask(taskId); 256 260 if (job.State == TaskState.Calculating || job.State == TaskState.Transferring) { 257 261 job.Command = Command.Pause; 258 d toDao.UpdateTask(job);262 dao.UpdateTask(job); 259 263 } else { 260 264 job = UpdateTaskState(taskId, TaskState.Paused, null, null, string.Empty); … … 267 271 author.AuthorizeForTask(taskId, Permission.Full); 268 272 trans.UseTransaction(() => { 269 Task task = d toDao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, string.Empty);273 Task task = dao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, string.Empty); 270 274 task.Command = null; 271 d toDao.UpdateTask(task);275 dao.UpdateTask(task); 272 276 }); 273 277 } … … 279 283 author.AuthorizeForJob(id, Permission.Read); 280 284 return trans.UseTransaction(() => { 281 var job = d toDao.GetJobs(x =>285 var job = dao.GetJobs(x => 282 286 x.JobId == id 283 287 && (x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0) 284 288 ).FirstOrDefault(); 285 289 if (job != null) { 286 job.Permission = DT.Convert.ToDto(d toDao.GetPermissionForJob(job.Id, userManager.CurrentUserId));290 job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 287 291 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 288 292 } … … 294 298 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 295 299 return trans.UseTransaction(() => { 296 var jobs = d toDao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0);300 var jobs = dao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0); 297 301 foreach (var job in jobs) { 298 302 author.AuthorizeForJob(job.Id, Permission.Read); 299 job.Permission = DT.Convert.ToDto(d toDao.GetPermissionForJob(job.Id, userManager.CurrentUserId));303 job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 300 304 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 301 305 } … … 307 311 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 308 312 return trans.UseTransaction(() => { 309 var jobs = d toDao.GetJobs(x => true);313 var jobs = dao.GetJobs(x => true); 310 314 foreach (var job in jobs) { // no authorization here, since this method is admin-only! (admin is allowed to read all task) 311 job.Permission = DT.Convert.ToDto(d toDao.GetPermissionForJob(job.Id, userManager.CurrentUserId));315 job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 312 316 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 313 317 } … … 321 325 jobDto.OwnerUserId = userManager.CurrentUserId; 322 326 jobDto.DateCreated = DateTime.Now; 323 return d toDao.AddJob(jobDto);327 return dao.AddJob(jobDto); 324 328 }); 325 329 } … … 329 333 author.AuthorizeForJob(jobDto.Id, Permission.Full); 330 334 trans.UseTransaction(() => { 331 d toDao.UpdateJob(jobDto);335 dao.UpdateJob(jobDto); 332 336 }); 333 337 } … … 337 341 author.AuthorizeForJob(jobId, Permission.Full); 338 342 trans.UseTransaction(() => { 339 d toDao.DeleteJob(jobId); // child task will be deleted by db-trigger343 dao.DeleteJob(jobId); // child task will be deleted by db-trigger 340 344 }); 341 345 } … … 346 350 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 347 351 trans.UseTransaction(() => { 348 Job job = d toDao.GetJob(jobId);352 Job job = dao.GetJob(jobId); 349 353 if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId)); 350 Permission perm = DT.Convert.ToDto(d toDao.GetPermissionForJob(job.Id, userManager.CurrentUserId));354 Permission perm = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 351 355 if (perm != Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment")); 352 d toDao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DT.Convert.ToEntity(permission));356 dao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DT.Convert.ToEntity(permission)); 353 357 }); 354 358 } … … 357 361 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 358 362 trans.UseTransaction(() => { 359 Job job = d toDao.GetJob(jobId);363 Job job = dao.GetJob(jobId); 360 364 if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId)); 361 DA.Permission perm = d toDao.GetPermissionForJob(job.Id, userManager.CurrentUserId);365 DA.Permission perm = dao.GetPermissionForJob(job.Id, userManager.CurrentUserId); 362 366 if (perm != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment")); 363 d toDao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DA.Permission.NotAllowed);367 dao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DA.Permission.NotAllowed); 364 368 }); 365 369 } … … 368 372 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 369 373 return trans.UseTransaction(() => { 370 DA.Permission currentUserPermission = d toDao.GetPermissionForJob(jobId, userManager.CurrentUserId);374 DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId); 371 375 if (currentUserPermission != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment")); 372 return d toDao.GetJobPermissions(x => x.JobId == jobId);376 return dao.GetJobPermissions(x => x.JobId == jobId); 373 377 }); 374 378 } … … 387 391 388 392 trans.UseTransaction(() => { 389 var slave = d toDao.GetSlave(slaveInfo.Id);393 var slave = dao.GetSlave(slaveInfo.Id); 390 394 391 395 if (slave == null) { 392 var healGroup = d toDao.GetResources(x => x.Name == "HEAL").First();396 var healGroup = dao.GetResources(x => x.Name == "HEAL").First(); 393 397 if (healGroup != null) { 394 398 slaveInfo.ParentResourceId = healGroup.Id; 395 399 } 396 d toDao.AddSlave(slaveInfo);400 dao.AddSlave(slaveInfo); 397 401 } else { 398 402 slave.Name = slaveInfo.Name; … … 413 417 // don't update those properties: dbSlave.IsAllowedToCalculate, dbSlave.ParentResourceId 414 418 415 d toDao.UpdateSlave(slave);419 dao.UpdateSlave(slave); 416 420 } 417 421 }); … … 421 425 authen.AuthenticateForAnyRole(HiveRoles.Slave); 422 426 trans.UseTransaction(() => { 423 var slave = d toDao.GetSlave(slaveId);427 var slave = dao.GetSlave(slaveId); 424 428 if (slave != null) { 425 429 slave.SlaveState = SlaveState.Offline; 426 d toDao.UpdateSlave(slave);430 dao.UpdateSlave(slave); 427 431 } 428 432 }); … … 457 461 plugin.DateCreated = DateTime.Now; 458 462 459 var existing = d toDao.GetPlugins(x => x.Hash != null).Where(x => x.Hash.SequenceEqual(plugin.Hash));463 var existing = dao.GetPlugins(x => x.Hash != null).Where(x => x.Hash.SequenceEqual(plugin.Hash)); 460 464 if (existing.Count() > 0) { 461 465 // a plugin already exists. … … 463 467 } 464 468 465 Guid pluginId = d toDao.AddPlugin(plugin);469 Guid pluginId = dao.AddPlugin(plugin); 466 470 foreach (PluginData pluginData in pluginDatas) { 467 471 pluginData.PluginId = pluginId; 468 d toDao.AddPluginData(pluginData);472 dao.AddPluginData(pluginData); 469 473 } 470 474 return pluginId; … … 475 479 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 476 480 return trans.UseTransaction(() => { 477 return DT.Convert.ToDto( dao.GetPluginById(pluginId));481 return DT.Convert.ToDto(optimizedDao.GetPluginById(pluginId)); 478 482 }); 479 483 } … … 482 486 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 483 487 return trans.UseTransaction(() => { 484 return d toDao.GetPlugins(x => x.Hash == hash).FirstOrDefault();488 return dao.GetPlugins(x => x.Hash == hash).FirstOrDefault(); 485 489 }); 486 490 } … … 491 495 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 492 496 return trans.UseTransaction(() => { 493 return d toDao.GetPlugins(x => x.Hash != null);497 return dao.GetPlugins(x => x.Hash != null); 494 498 }); 495 499 } … … 500 504 return trans.UseTransaction(() => { 501 505 foreach (Guid guid in pluginIds) { 502 pluginDatas.AddRange(d toDao.GetPluginDatas(x => x.PluginId == guid).ToList());506 pluginDatas.AddRange(dao.GetPluginDatas(x => x.PluginId == guid).ToList()); 503 507 } 504 508 return pluginDatas; … … 509 513 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 510 514 trans.UseTransaction(() => { 511 d toDao.DeletePlugin(pluginId);515 dao.DeletePlugin(pluginId); 512 516 }); 513 517 } … … 518 522 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 519 523 trans.UseTransaction(() => { 520 Resource resource = d toDao.GetResource(resourceId);524 Resource resource = dao.GetResource(resourceId); 521 525 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 522 526 if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permission for this resource")); 523 527 foreach (Guid id in grantedUserIds) 524 d toDao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = userManager.CurrentUserId, GrantedUserId = id });528 dao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = userManager.CurrentUserId, GrantedUserId = id }); 525 529 }); 526 530 } … … 529 533 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 530 534 trans.UseTransaction(() => { 531 Resource resource = d toDao.GetResource(resourceId);535 Resource resource = dao.GetResource(resourceId); 532 536 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 533 537 if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to revoke permission for this resource")); 534 538 foreach (Guid id in grantedUserIds) 535 d toDao.DeleteResourcePermission(resourceId, id);539 dao.DeleteResourcePermission(resourceId, id); 536 540 }); 537 541 } … … 540 544 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 541 545 return trans.UseTransaction(() => { 542 Resource resource = d toDao.GetResource(resourceId);546 Resource resource = dao.GetResource(resourceId); 543 547 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 544 return d toDao.GetResourcePermissions(x => x.ResourceId == resourceId);548 return dao.GetResourcePermissions(x => x.ResourceId == resourceId); 545 549 }); 546 550 } … … 549 553 #region Resource Methods 550 554 public IEnumerable<Resource> GetChildResources(Guid resourceId) { 551 return trans.UseTransaction(() => { return d toDao.GetChildResources(resourceId); });555 return trans.UseTransaction(() => { return dao.GetChildResources(resourceId); }); 552 556 } 553 557 #endregion … … 557 561 authen.AuthenticateForAnyRole(HiveRoles.Slave); 558 562 559 Slave s = trans.UseTransaction(() => { return d toDao.GetSlave(slaveId); });563 Slave s = trans.UseTransaction(() => { return dao.GetSlave(slaveId); }); 560 564 if (s != null) { 561 565 return s.HbInterval; … … 567 571 public Guid AddSlave(Slave slave) { 568 572 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 569 return trans.UseTransaction(() => d toDao.AddSlave(slave));573 return trans.UseTransaction(() => dao.AddSlave(slave)); 570 574 } 571 575 572 576 public Guid AddSlaveGroup(SlaveGroup slaveGroup) { 573 577 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 574 return trans.UseTransaction(() => d toDao.AddSlaveGroup(slaveGroup));578 return trans.UseTransaction(() => dao.AddSlaveGroup(slaveGroup)); 575 579 } 576 580 577 581 public Slave GetSlave(Guid slaveId) { 578 582 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 579 return trans.UseTransaction(() => { return d toDao.GetSlave(slaveId); });583 return trans.UseTransaction(() => { return dao.GetSlave(slaveId); }); 580 584 } 581 585 582 586 public SlaveGroup GetSlaveGroup(Guid slaveGroupId) { 583 587 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 584 return trans.UseTransaction(() => { return d toDao.GetSlaveGroup(slaveGroupId); });588 return trans.UseTransaction(() => { return dao.GetSlaveGroup(slaveGroupId); }); 585 589 } 586 590 … … 588 592 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 589 593 return trans.UseTransaction(() => { 590 return d toDao.GetSlaves(x => true).Where(x => x.OwnerUserId == null594 return dao.GetSlaves(x => true).Where(x => x.OwnerUserId == null 591 595 || x.OwnerUserId == userManager.CurrentUserId 592 596 || userManager.VerifyUser(userManager.CurrentUserId, GetResourcePermissions(x.Id).Select(y => y.GrantedUserId).ToList()) … … 598 602 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 599 603 return trans.UseTransaction(() => { 600 return d toDao.GetSlaveGroups(x => true).Where(x => x.OwnerUserId == null604 return dao.GetSlaveGroups(x => true).Where(x => x.OwnerUserId == null 601 605 || x.OwnerUserId == userManager.CurrentUserId 602 606 || userManager.VerifyUser(userManager.CurrentUserId, GetResourcePermissions(x.Id).Select(y => y.GrantedUserId).ToList()) … … 608 612 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 609 613 trans.UseTransaction(() => { 610 d toDao.UpdateSlave(slave);614 dao.UpdateSlave(slave); 611 615 }); 612 616 } … … 615 619 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 616 620 trans.UseTransaction(() => { 617 d toDao.UpdateSlaveGroup(slaveGroup);621 dao.UpdateSlaveGroup(slaveGroup); 618 622 }); 619 623 } … … 623 627 author.AuthorizeForResourceAdministration(slaveId); 624 628 trans.UseTransaction(() => { 625 d toDao.DeleteSlave(slaveId);629 dao.DeleteSlave(slaveId); 626 630 }); 627 631 } … … 631 635 author.AuthorizeForResourceAdministration(slaveGroupId); 632 636 trans.UseTransaction(() => { 633 d toDao.DeleteSlaveGroup(slaveGroupId);637 dao.DeleteSlaveGroup(slaveGroupId); 634 638 }); 635 639 } … … 638 642 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 639 643 trans.UseTransaction(() => { 640 var resource = d toDao.GetResource(resourceId);644 var resource = dao.GetResource(resourceId); 641 645 resource.ParentResourceId = slaveGroupId; 642 d toDao.UpdateResource(resource);646 dao.UpdateResource(resource); 643 647 }); 644 648 } … … 647 651 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 648 652 trans.UseTransaction(() => { 649 var resource = d toDao.GetResource(resourceId);653 var resource = dao.GetResource(resourceId); 650 654 resource.ParentResourceId = null; 651 d toDao.UpdateResource(resource);655 dao.UpdateResource(resource); 652 656 }); 653 657 } … … 656 660 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 657 661 return trans.UseTransaction(() => { 658 var resource = d toDao.GetResources(x => x.Name == resourceName).FirstOrDefault();662 var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault(); 659 663 if (resource != null) { 660 664 return resource.Id; … … 670 674 bool cleanup = false; 671 675 trans.UseTransaction(() => { 672 DateTime lastCleanup = d toDao.GetLastCleanup();676 DateTime lastCleanup = dao.GetLastCleanup(); 673 677 if (force || DateTime.Now - lastCleanup > HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval) { 674 d toDao.SetLastCleanup(DateTime.Now);678 dao.SetLastCleanup(DateTime.Now); 675 679 cleanup = true; 676 680 } … … 687 691 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 688 692 author.AuthorizeForResourceAdministration(downtime.ResourceId); 689 return trans.UseTransaction(() => d toDao.AddDowntime(downtime));693 return trans.UseTransaction(() => dao.AddDowntime(downtime)); 690 694 } 691 695 … … 695 699 // author.AuthorizeForResource(resourceId); 696 700 trans.UseTransaction(() => { 697 d toDao.DeleteDowntime(downtimeId);701 dao.DeleteDowntime(downtimeId); 698 702 }); 699 703 } … … 703 707 author.AuthorizeForResourceAdministration(downtime.ResourceId); 704 708 trans.UseTransaction(() => { 705 d toDao.UpdateDowntime(downtime);709 dao.UpdateDowntime(downtime); 706 710 }); 707 711 } … … 709 713 public IEnumerable<Downtime> GetDowntimesForResource(Guid resourceId) { 710 714 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 711 return trans.UseTransaction(() => d toDao.GetDowntimes(x => x.ResourceId == resourceId));715 return trans.UseTransaction(() => dao.GetDowntimes(x => x.ResourceId == resourceId)); 712 716 } 713 717 #endregion … … 732 736 #region UserPriority Methods 733 737 public IEnumerable<UserPriority> GetUserPriorities() { 734 return trans.UseTransaction(() => d toDao.GetUserPriorities(x => true));738 return trans.UseTransaction(() => dao.GetUserPriorities(x => true)); 735 739 } 736 740 #endregion … … 738 742 #region Helper Methods 739 743 private IEnumerable<Task> GetChildTasks(Guid? parentTaskId, bool recursive, bool includeParent) { 740 var tasks = new List<Task>(d toDao.GetTasks(x => parentTaskId == null ? !x.ParentTaskId.HasValue : x.ParentTaskId.Value == parentTaskId));744 var tasks = new List<Task>(dao.GetTasks(x => parentTaskId == null ? !x.ParentTaskId.HasValue : x.ParentTaskId.Value == parentTaskId)); 741 745 742 746 if (recursive) { … … 755 759 #region Statistics Methods 756 760 public IEnumerable<Statistics> GetStatistics() { 757 return trans.UseTransaction(() => { return d toDao.GetStatistics(x => true); });761 return trans.UseTransaction(() => { return dao.GetStatistics(x => true); }); 758 762 } 759 763 public IEnumerable<Statistics> GetStatisticsForTimePeriod(DateTime from, DateTime to) { 760 return trans.UseTransaction(() => { return d toDao.GetStatistics(x => x.Timestamp >= from && x.Timestamp <= to); });764 return trans.UseTransaction(() => { return dao.GetStatistics(x => x.Timestamp >= from && x.Timestamp <= to); }); 761 765 } 762 766 #endregion -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDao.cs
r9394 r9434 27 27 28 28 namespace HeuristicLab.Services.Hive { 29 public interface IHiveD toDao {29 public interface IHiveDao { 30 30 #region Task Methods 31 31 DT.Task GetTask(Guid id); -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IOptimizedHiveDao.cs
r9399 r9434 27 27 using DT = HeuristicLab.Services.Hive.DataTransfer; 28 28 namespace HeuristicLab.Services.Hive { 29 public interface I HiveDao {29 public interface IOptimizedHiveDao { 30 30 #region Task Methods 31 31 Task GetTaskById(Guid task); … … 38 38 void UpdateTask(Task task); 39 39 Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception); 40 41 Guid AddTask(Task task); 42 void AssignJobToResource(Guid taskId, IEnumerable<Guid> resourceIds); 40 43 41 44 bool TaskIsAllowedToBeCalculatedBySlave(Guid taskId, Guid slaveId); … … 81 84 82 85 #region Resource Methods 83 86 IEnumerable<Guid> GetAssignedResourceIds(Guid jobId); 84 87 #endregion 85 88 -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IServiceLocator.cs
r9391 r9434 26 26 Access.IRoleVerifier RoleVerifier { get; } 27 27 IAuthorizationManager AuthorizationManager { get; } 28 IHiveDtoDao HiveDtoDao { get; }29 28 IHiveDao HiveDao { get; } 29 IOptimizedHiveDao OptimizedHiveDao { get; } 30 30 IEventManager EventManager { get; } 31 31 ITransactionManager TransactionManager { get; } -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r9391 r9434 36 36 if (ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Slave)) return; // slave-users can access all tasks 37 37 38 Permission permission = ServiceLocator.Instance.HiveD toDao.GetPermissionForTask(taskId, ServiceLocator.Instance.UserManager.CurrentUserId);38 Permission permission = ServiceLocator.Instance.HiveDao.GetPermissionForTask(taskId, ServiceLocator.Instance.UserManager.CurrentUserId); 39 39 if (permission == Permission.NotAllowed || (permission != DT.Convert.ToEntity(requiredPermission) && DT.Convert.ToEntity(requiredPermission) == Permission.Full)) 40 40 throw new SecurityException("Current user is not authorized to access task"); … … 42 42 43 43 public void AuthorizeForJob(Guid jobId, DT.Permission requiredPermission) { 44 Permission permission = ServiceLocator.Instance.HiveD toDao.GetPermissionForJob(jobId, ServiceLocator.Instance.UserManager.CurrentUserId);44 Permission permission = ServiceLocator.Instance.HiveDao.GetPermissionForJob(jobId, ServiceLocator.Instance.UserManager.CurrentUserId); 45 45 if (permission == Permission.NotAllowed || (permission != DT.Convert.ToEntity(requiredPermission) && DT.Convert.ToEntity(requiredPermission) == Permission.Full)) 46 46 throw new SecurityException("Current user is not authorized to access task"); … … 48 48 49 49 public void AuthorizeForResourceAdministration(Guid resourceId) { 50 Resource resource = DT.Convert.ToEntity(ServiceLocator.Instance.HiveD toDao.GetResource(resourceId));50 Resource resource = DT.Convert.ToEntity(ServiceLocator.Instance.HiveDao.GetResource(resourceId)); 51 51 if (resource.OwnerUserId != ServiceLocator.Instance.UserManager.CurrentUserId && !ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Administrator)) 52 52 throw new SecurityException("Current user is not authorized to access resource"); -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Manager/EventManager.cs
r9391 r9434 32 32 /// </summary> 33 33 public class EventManager : IEventManager { 34 private IHiveD toDao dao {35 get { return ServiceLocator.Instance.HiveD toDao; }34 private IHiveDao dao { 35 get { return ServiceLocator.Instance.HiveDao; } 36 36 } 37 37 private IAuthorizationManager auth { -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
r9397 r9434 31 31 private const string MutexName = "HiveTaskSchedulingMutex"; 32 32 33 private I HiveDao dao {34 get { return ServiceLocator.Instance. HiveDao; }33 private IOptimizedHiveDao dao { 34 get { return ServiceLocator.Instance.OptimizedHiveDao; } 35 35 } 36 36 private ITaskScheduler taskScheduler { -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/OptimizedHiveDao.cs
r9399 r9434 27 27 28 28 namespace HeuristicLab.Services.Hive.DataAccess { 29 public class HiveDao : IHiveDao {30 private HiveDataContext Db { get { return HiveOperationContext.Current.DataContext; } }29 public class OptimizedHiveDao : IOptimizedHiveDao { 30 private static HiveDataContext Db { get { return HiveOperationContext.Current.DataContext; } } 31 31 32 32 #region Task Methods … … 35 35 } 36 36 37 private static Func<HiveDataContext, Guid, IQueryable<Task>> GetTaskByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) =>37 private static readonly Func<HiveDataContext, Guid, IQueryable<Task>> GetTaskByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) => 38 38 from t in db.Tasks 39 39 where t.TaskId == taskId … … 51 51 } 52 52 53 private static Func<HiveDataContext, Guid, IQueryable<Tuple<Task, Guid?>>> GetTaskByIdAndLastStateLogSlaveIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) =>53 private static readonly Func<HiveDataContext, Guid, IQueryable<Tuple<Task, Guid?>>> GetTaskByIdAndLastStateLogSlaveIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) => 54 54 from t in db.Tasks 55 55 join sl in db.StateLogs on t.TaskId equals sl.TaskId … … 89 89 } 90 90 91 private static Func<HiveDataContext, Guid, IQueryable<DT.LightweightTask>> GetLightweightTasksQuery = CompiledQuery.Compile((HiveDataContext db, Guid jobId) =>91 private static readonly Func<HiveDataContext, Guid, IQueryable<DT.LightweightTask>> GetLightweightTasksQuery = CompiledQuery.Compile((HiveDataContext db, Guid jobId) => 92 92 from task in db.Tasks 93 93 where task.JobId == jobId … … 103 103 ); 104 104 105 staticFunc<StateLog, DT.StateLog> ConvertStateLog = sl => DT.Convert.ToDto(sl);106 staticFunc<TaskState, DT.TaskState> ConvertTaskState = ts => DT.Convert.ToDto(ts);107 staticFunc<Command?, DT.Command?> ConvertCommand = c => DT.Convert.ToDto(c);105 private static readonly Func<StateLog, DT.StateLog> ConvertStateLog = sl => DT.Convert.ToDto(sl); 106 private static readonly Func<TaskState, DT.TaskState> ConvertTaskState = ts => DT.Convert.ToDto(ts); 107 private static readonly Func<Command?, DT.Command?> ConvertCommand = c => DT.Convert.ToDto(c); 108 108 109 109 public void UpdateTask(Task task) { … … 127 127 128 128 return task; 129 } 130 131 public Guid AddTask(Task task) { 132 Db.Tasks.InsertOnSubmit(task); 133 Db.SubmitChanges(); 134 return task.TaskId; 135 } 136 137 public void AssignJobToResource(Guid taskId, IEnumerable<Guid> resourceIds) { 138 Db.AssignedResources.InsertAllOnSubmit(resourceIds.Select(resourceId => new AssignedResource { TaskId = taskId, ResourceId = resourceId })); 139 Db.SubmitChanges(); 129 140 } 130 141 … … 153 164 } 154 165 155 private static Func<HiveDataContext, Guid, IQueryable<TaskData>> GetTaskDataByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid id) =>166 private static readonly Func<HiveDataContext, Guid, IQueryable<TaskData>> GetTaskDataByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid id) => 156 167 from t in db.TaskDatas 157 168 where t.TaskId == id … … 187 198 } 188 199 189 private static Func<HiveDataContext, Guid, IQueryable<Plugin>> GetPluginByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid pluginId) =>200 private static readonly Func<HiveDataContext, Guid, IQueryable<Plugin>> GetPluginByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid pluginId) => 190 201 from p in db.Plugins 191 202 where p.PluginId == pluginId … … 204 215 } 205 216 206 private static Func<HiveDataContext, Guid, IQueryable<Slave>> GetSlaveByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid slaveId) =>217 private static readonly Func<HiveDataContext, Guid, IQueryable<Slave>> GetSlaveByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid slaveId) => 207 218 from s in db.Resources.OfType<Slave>() 208 219 where s.ResourceId == slaveId … … 243 254 244 255 #region Resource Methods 256 public IEnumerable<Guid> GetAssignedResourceIds(Guid taskId) { 257 return GetAssignedResourceIdsQuery(Db, taskId); 258 } 259 260 private static readonly Func<HiveDataContext, Guid, IQueryable<Guid>> GetAssignedResourceIdsQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) => 261 from ar in db.AssignedResources 262 where ar.TaskId == taskId 263 select ar.ResourceId 264 ); 245 265 #endregion 246 266 -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs
r9391 r9434 27 27 namespace HeuristicLab.Services.Hive { 28 28 public class RoundRobinTaskScheduler : ITaskScheduler { 29 private IHiveD toDao dao {30 get { return ServiceLocator.Instance.HiveD toDao; }29 private IHiveDao dao { 30 get { return ServiceLocator.Instance.HiveDao; } 31 31 } 32 32 -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/ServiceLocator.cs
r9391 r9434 34 34 } 35 35 36 private IHiveDtoDao hiveDtoDao;37 public IHiveDtoDao HiveDtoDao {38 get {39 if (hiveDtoDao == null) hiveDtoDao = new HiveDtoDao();40 return hiveDtoDao;41 }42 }43 44 36 private IHiveDao hiveDao; 45 37 public IHiveDao HiveDao { … … 47 39 if (hiveDao == null) hiveDao = new HiveDao(); 48 40 return hiveDao; 41 } 42 } 43 44 private IOptimizedHiveDao optimizedHiveDao; 45 public IOptimizedHiveDao OptimizedHiveDao { 46 get { 47 if (optimizedHiveDao == null) optimizedHiveDao = new OptimizedHiveDao(); 48 return optimizedHiveDao; 49 49 } 50 50 }
Note: See TracChangeset
for help on using the changeset viewer.