- Timestamp:
- 07/08/15 15:51:32 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs
r12584 r12691 68 68 public Guid AddTask(Task task, TaskData taskData, IEnumerable<Guid> resourceIds) { 69 69 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 70 return trans.UseTransaction(() => { 71 var t = DT.Convert.ToEntity(task); 72 t.RequiredPlugins.AddRange(task.PluginsNeededIds.Select(pluginId => new DA.RequiredPlugin { Task = t, PluginId = pluginId })); 73 74 t.JobData = DT.Convert.ToEntity(taskData); 75 t.JobData.LastUpdate = DateTime.Now; 76 77 optimizedDao.AddTask(t); 78 79 dao.AssignJobToResource(t.TaskId, resourceIds); 80 81 optimizedDao.UpdateTaskState(t.TaskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, null); 82 83 return t.TaskId; 84 }, false, true); 70 using (new PerformanceLogger("Old_AddTask")) { 71 return trans.UseTransaction(() => { 72 var t = DT.Convert.ToEntity(task); 73 t.RequiredPlugins.AddRange(task.PluginsNeededIds.Select(pluginId => new DA.RequiredPlugin { Task = t, PluginId = pluginId })); 74 75 t.JobData = DT.Convert.ToEntity(taskData); 76 t.JobData.LastUpdate = DateTime.Now; 77 78 optimizedDao.AddTask(t); 79 80 dao.AssignJobToResource(t.TaskId, resourceIds); 81 82 optimizedDao.UpdateTaskState(t.TaskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, null); 83 84 return t.TaskId; 85 }, false, true); 86 } 85 87 } 86 88 … … 88 90 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 89 91 task.ParentTaskId = parentTaskId; 90 return AddTask(task, taskData, optimizedDao.GetAssignedResourceIds(parentTaskId).ToList()); 92 List<Guid> list = null; 93 using (new PerformanceLogger("Old_AddChildTask")) { 94 list = optimizedDao.GetAssignedResourceIds(parentTaskId).ToList(); 95 } 96 return AddTask(task, taskData, list); 91 97 } 92 98 … … 94 100 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 95 101 author.AuthorizeForTask(taskId, Permission.Read); 96 return trans.UseTransaction(() => { 97 return DT.Convert.ToDto(optimizedDao.GetTaskById(taskId)); 98 }, false, false); 102 using (new PerformanceLogger("Old_GetTask")) { 103 return trans.UseTransaction(() => { 104 return DT.Convert.ToDto(optimizedDao.GetTaskById(taskId)); 105 }, false, false); 106 } 99 107 } 100 108 … … 134 142 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 135 143 author.AuthorizeForJob(jobId, Permission.Read); 136 137 return trans.UseTransaction(() => { 138 return optimizedDao.GetLightweightTasks(jobId).ToArray(); 139 }, false, true); 144 using (new PerformanceLogger("Old_GetLightweightJobTasks")) { 145 return trans.UseTransaction(() => { 146 return optimizedDao.GetLightweightTasks(jobId).ToArray(); 147 }, false, true); 148 } 140 149 } 141 150 … … 143 152 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 144 153 author.AuthorizeForJob(jobId, Permission.Read); 145 146 return trans.UseTransaction(() => { 147 return dao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray(); 148 }, false, false); 154 using (new PerformanceLogger("Old_GetLightweightJobTasksWithoutStateLog")) { 155 return trans.UseTransaction(() => { 156 return dao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray(); 157 }, false, false); 158 } 149 159 } 150 160 … … 153 163 author.AuthorizeForTask(taskId, Permission.Read); 154 164 155 return trans.UseTransaction(() => { 156 return dao.GetTaskData(taskId); 157 }); 165 using (new PerformanceLogger("Old_GetTaskData")) { 166 return trans.UseTransaction(() => { 167 return dao.GetTaskData(taskId); 168 }); 169 } 158 170 } 159 171 … … 162 174 author.AuthorizeForTask(taskDto.Id, Permission.Full); 163 175 164 trans.UseTransaction(() => { 165 var task = optimizedDao.GetTaskByDto(taskDto); 166 optimizedDao.UpdateTask(task); 167 }); 176 using (new PerformanceLogger("Old_UpdateTask")) { 177 trans.UseTransaction(() => { 178 var task = optimizedDao.GetTaskByDto(taskDto); 179 optimizedDao.UpdateTask(task); 180 }); 181 } 168 182 } 169 183 … … 172 186 author.AuthorizeForTask(task.Id, Permission.Full); 173 187 174 trans.UseTransaction(() => { 175 var t = optimizedDao.GetTaskByDto(task); 176 optimizedDao.UpdateTask(t); 177 }); 178 179 trans.UseTransaction(() => { 180 var data = optimizedDao.GetTaskDataByDto(taskData); 181 data.LastUpdate = DateTime.Now; 182 optimizedDao.UpdateTaskData(data); 183 }); 188 using (new PerformanceLogger("Old_UpdateTaskData")) { 189 trans.UseTransaction(() => { 190 var t = optimizedDao.GetTaskByDto(task); 191 optimizedDao.UpdateTask(t); 192 }); 193 194 trans.UseTransaction(() => { 195 var data = optimizedDao.GetTaskDataByDto(taskData); 196 data.LastUpdate = DateTime.Now; 197 optimizedDao.UpdateTaskData(data); 198 }); 199 } 184 200 } 185 201 … … 207 223 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 208 224 author.AuthorizeForTask(taskId, Permission.Full); 209 210 return trans.UseTransaction(() => { 211 var task = optimizedDao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception); 212 213 if (task.Command.HasValue && task.Command.Value == DA.Command.Pause && task.State == DA.TaskState.Paused) { 214 task.Command = null; 215 } else if (task.Command.HasValue && task.Command.Value == DA.Command.Abort && task.State == DA.TaskState.Aborted) { 216 task.Command = null; 217 } else if (task.Command.HasValue && task.Command.Value == DA.Command.Stop && task.State == DA.TaskState.Aborted) { 218 task.Command = null; 219 } else if (taskState == TaskState.Paused && !task.Command.HasValue) { 220 // slave paused and uploaded the task (no user-command) -> set waiting. 221 task = optimizedDao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception); 222 } 223 224 return DT.Convert.ToDto(task); 225 }); 225 using (new PerformanceLogger("Old_UpdateTaskState")) { 226 return trans.UseTransaction(() => { 227 var task = optimizedDao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception); 228 229 if (task.Command.HasValue && task.Command.Value == DA.Command.Pause && task.State == DA.TaskState.Paused) { 230 task.Command = null; 231 } else if (task.Command.HasValue && task.Command.Value == DA.Command.Abort && task.State == DA.TaskState.Aborted) { 232 task.Command = null; 233 } else if (task.Command.HasValue && task.Command.Value == DA.Command.Stop && task.State == DA.TaskState.Aborted) { 234 task.Command = null; 235 } else if (taskState == TaskState.Paused && !task.Command.HasValue) { 236 // slave paused and uploaded the task (no user-command) -> set waiting. 237 task = optimizedDao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception); 238 } 239 240 return DT.Convert.ToDto(task); 241 }); 242 } 226 243 } 227 244 … … 281 298 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 282 299 author.AuthorizeForJob(id, Permission.Read); 283 return trans.UseTransaction(() => { 284 var job = dao.GetJobs(x => 285 x.JobId == id 286 && (x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0) 287 ).FirstOrDefault(); 288 if (job != null) { 289 job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 290 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 291 } 292 return job; 293 }); 300 using (new PerformanceLogger("Old_GetJob")) { 301 return trans.UseTransaction(() => { 302 var job = dao.GetJobs(x => 303 x.JobId == id 304 && (x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0) 305 ).FirstOrDefault(); 306 if (job != null) { 307 job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 308 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 309 } 310 return job; 311 }); 312 } 294 313 } 295 314 296 315 public IEnumerable<Job> GetJobs() { 297 316 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 298 return trans.UseTransaction(() => { 299 var jobs = dao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0); 300 foreach (var job in jobs) { 301 author.AuthorizeForJob(job.Id, Permission.Read); 302 job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 303 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 304 } 305 return jobs; 306 }); 317 using (new PerformanceLogger("Old_GetJobs")) { 318 return trans.UseTransaction(() => { 319 var jobs = dao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0); 320 foreach (var job in jobs) { 321 author.AuthorizeForJob(job.Id, Permission.Read); 322 job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 323 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 324 } 325 return jobs; 326 }); 327 } 307 328 } 308 329 … … 321 342 public Guid AddJob(Job jobDto) { 322 343 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 323 return trans.UseTransaction(() => { 324 jobDto.OwnerUserId = userManager.CurrentUserId; 325 jobDto.DateCreated = DateTime.Now; 326 return dao.AddJob(jobDto); 327 }); 344 using (new PerformanceLogger("Old_AddJob")) { 345 return trans.UseTransaction(() => { 346 jobDto.OwnerUserId = userManager.CurrentUserId; 347 jobDto.DateCreated = DateTime.Now; 348 return dao.AddJob(jobDto); 349 }); 350 } 328 351 } 329 352 … … 370 393 public IEnumerable<JobPermission> GetJobPermissions(Guid jobId) { 371 394 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 372 return trans.UseTransaction(() => { 373 DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId); 374 if (currentUserPermission != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment")); 375 return dao.GetJobPermissions(x => x.JobId == jobId); 376 }); 395 using (new PerformanceLogger("GetJobPermissions")) { 396 return trans.UseTransaction(() => { 397 DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId); 398 if (currentUserPermission != DA.Permission.Full) 399 throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment")); 400 return dao.GetJobPermissions(x => x.JobId == jobId); 401 }); 402 } 377 403 } 378 404 … … 389 415 slaveInfo.OwnerUserId = userManager.CurrentUserId; 390 416 391 trans.UseTransaction(() => { 392 var slave = dao.GetSlave(slaveInfo.Id); 393 394 if (slave == null) { 395 dao.AddSlave(slaveInfo); 396 } else { 397 slave.Name = slaveInfo.Name; 398 slave.Description = slaveInfo.Description; 399 slave.OwnerUserId = slaveInfo.OwnerUserId; 400 401 slave.Cores = slaveInfo.Cores; 402 slave.CpuArchitecture = slaveInfo.CpuArchitecture; 403 slave.CpuSpeed = slaveInfo.CpuSpeed; 404 slave.FreeCores = slaveInfo.FreeCores; 405 slave.FreeMemory = slaveInfo.FreeMemory; 406 slave.Memory = slaveInfo.Memory; 407 slave.OperatingSystem = slaveInfo.OperatingSystem; 408 409 slave.LastHeartbeat = DateTime.Now; 410 slave.SlaveState = SlaveState.Idle; 411 412 // don't update those properties: dbSlave.IsAllowedToCalculate, dbSlave.ParentResourceId 413 414 dao.UpdateSlave(slave); 415 } 416 }); 417 using (new PerformanceLogger("Old_Hello")) { 418 trans.UseTransaction(() => { 419 var slave = dao.GetSlave(slaveInfo.Id); 420 421 if (slave == null) { 422 dao.AddSlave(slaveInfo); 423 } else { 424 slave.Name = slaveInfo.Name; 425 slave.Description = slaveInfo.Description; 426 slave.OwnerUserId = slaveInfo.OwnerUserId; 427 428 slave.Cores = slaveInfo.Cores; 429 slave.CpuArchitecture = slaveInfo.CpuArchitecture; 430 slave.CpuSpeed = slaveInfo.CpuSpeed; 431 slave.FreeCores = slaveInfo.FreeCores; 432 slave.FreeMemory = slaveInfo.FreeMemory; 433 slave.Memory = slaveInfo.Memory; 434 slave.OperatingSystem = slaveInfo.OperatingSystem; 435 436 slave.LastHeartbeat = DateTime.Now; 437 slave.SlaveState = SlaveState.Idle; 438 439 // don't update those properties: dbSlave.IsAllowedToCalculate, dbSlave.ParentResourceId 440 441 dao.UpdateSlave(slave); 442 } 443 }); 444 } 417 445 } 418 446 419 447 public void GoodBye(Guid slaveId) { 420 448 authen.AuthenticateForAnyRole(HiveRoles.Slave); 421 trans.UseTransaction(() => { 422 var slave = dao.GetSlave(slaveId); 423 if (slave != null) { 424 slave.SlaveState = SlaveState.Offline; 425 dao.UpdateSlave(slave); 426 } 427 }); 449 using (new PerformanceLogger("Old_GoodBye")) { 450 trans.UseTransaction(() => { 451 var slave = dao.GetSlave(slaveId); 452 if (slave != null) { 453 slave.SlaveState = SlaveState.Offline; 454 dao.UpdateSlave(slave); 455 } 456 }); 457 } 428 458 } 429 459 #endregion … … 435 465 List<MessageContainer> result = new List<MessageContainer>(); 436 466 try { 437 result = heartbeatManager.ProcessHeartbeat(heartbeat); 467 using (new PerformanceLogger("Old_ProcessHeartbeat")) { 468 result = heartbeatManager.ProcessHeartbeat(heartbeat); 469 } 438 470 } 439 471 catch (Exception ex) { 440 472 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("Exception processing Heartbeat: " + ex.ToString()); 441 473 } 442 443 474 if (HeuristicLab.Services.Hive.Properties.Settings.Default.TriggerEventManagerInHeartbeat) { 444 475 TriggerEventManager(false); … … 489 520 public IEnumerable<Plugin> GetPlugins() { 490 521 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 491 return trans.UseTransaction(() => { 492 return dao.GetPlugins(x => x.Hash != null); 493 }); 522 using (new PerformanceLogger("Old_GetPlugins")) { 523 return trans.UseTransaction(() => { 524 return dao.GetPlugins(x => x.Hash != null); 525 }); 526 } 494 527 } 495 528 … … 497 530 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 498 531 var pluginDatas = new List<PluginData>(); 499 return trans.UseTransaction(() => { 500 foreach (Guid guid in pluginIds) { 501 pluginDatas.AddRange(dao.GetPluginDatas(x => x.PluginId == guid).ToList()); 502 } 503 return pluginDatas; 504 }); 532 using (new PerformanceLogger("Old_GetPluginData")) { 533 return trans.UseTransaction(() => { 534 foreach (Guid guid in pluginIds) { 535 pluginDatas.AddRange(dao.GetPluginDatas(x => x.PluginId == guid).ToList()); 536 } 537 return pluginDatas; 538 }); 539 } 505 540 } 506 541 … … 654 689 public Guid GetResourceId(string resourceName) { 655 690 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 656 return trans.UseTransaction(() => { 657 var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault(); 658 if (resource != null) { 659 return resource.Id; 660 } else { 661 return Guid.Empty; 662 } 663 }); 691 using (new PerformanceLogger("Old_GetResourceId")) { 692 return trans.UseTransaction(() => { 693 var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault(); 694 if (resource != null) { 695 return resource.Id; 696 } else { 697 return Guid.Empty; 698 } 699 }); 700 } 664 701 } 665 702
Note: See TracChangeset
for help on using the changeset viewer.