Changeset 9391
- Timestamp:
- 04/23/13 10:37:45 (12 years ago)
- Location:
- branches/HivePerformance/sources
- Files:
-
- 12 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HivePerformance/sources/HeuristicLab.Services.Hive.Web/Hive-3.3/Status.aspx.cs
r9033 r9391 36 36 public partial class Status : System.Web.UI.Page { 37 37 protected void Page_Load(object sender, EventArgs e) { 38 var dao = ServiceLocator.Instance.HiveD ao;38 var dao = ServiceLocator.Instance.HiveDtoDao; 39 39 var transactionManager = ServiceLocator.Instance.TransactionManager; 40 40 var resourceName = Request.QueryString["resource"]; -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3
- Property svn:ignore
-
old new 2 2 bin 3 3 obj 4 *.user
-
- Property svn:ignore
-
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
r9381 r9391 138 138 <Compile Include="DataTransfer\UserStatistics.cs" /> 139 139 <Compile Include="HiveDao.cs" /> 140 <Compile Include="HiveDtoDao.cs" /> 140 141 <Compile Include="HiveJanitor.cs" /> 141 142 <Compile Include="HiveOperationContext.cs" /> 142 143 <Compile Include="Interfaces\IHiveDao.cs" /> 144 <Compile Include="Interfaces\IHiveDtoDao.cs" /> 143 145 <Compile Include="Interfaces\ITaskScheduler.cs" /> 144 146 <Compile Include="Scheduler\TaskInfoForScheduler.cs" /> -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveDtoDao.cs
r9385 r9391 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Data.Linq;25 24 using System.Linq; 26 25 using System.Linq.Expressions; … … 28 27 29 28 namespace HeuristicLab.Services.Hive.DataAccess { 30 public class HiveD ao : IHiveDao {29 public class HiveDtoDao : IHiveDtoDao { 31 30 public static HiveDataContext CreateContext(bool longRunning = false) { 32 31 var context = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); … … 35 34 } 36 35 37 public HiveD ao() { }36 public HiveDtoDao() { } 38 37 39 38 #region Task Methods … … 43 42 } 44 43 } 45 46 public Task GetTaskDA(Guid id) {47 var db = HiveOperationContext.Current.DataContext;48 return GetTaskByIdQuery(db, id).SingleOrDefault();49 }50 51 private static Func<HiveDataContext, Guid, IQueryable<Task>> GetTaskByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid id) =>52 from t in db.Tasks53 where t.TaskId == id54 select t55 );56 44 57 45 public IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate) { … … 150 138 db.SubmitChanges(); 151 139 } 152 }153 154 public void UpdateTaskDA(Task task) {155 var db = HiveOperationContext.Current.DataContext;156 db.SubmitChanges();157 140 } 158 141 … … 212 195 } 213 196 214 public IQueryable<TaskInfoForScheduler> GetWaitingTasksDA(Slave slave) {215 var db = HiveOperationContext.Current.DataContext;216 217 var parentResources = GetParentResourcesDA(slave.ResourceId);218 var resourceIds = parentResources.Select(x => x.ResourceId);219 //Originally we checked here if there are parent tasks which should be calculated (with GetParentTasks(resourceIds, count, false);).220 //Because there is at the moment no case where this makes sense (there don't exist parent tasks which need to be calculated),221 //we skip this step because it's wasted runtime222 223 return from ar in db.AssignedResources224 where resourceIds.Contains(ar.ResourceId)225 && !(ar.Task.IsParentTask && ar.Task.FinishWhenChildJobsFinished)226 && ar.Task.State == TaskState.Waiting227 && ar.Task.CoresNeeded <= slave.FreeCores228 && ar.Task.MemoryNeeded <= slave.FreeMemory229 select new TaskInfoForScheduler() { TaskId = ar.Task.TaskId, JobId = ar.Task.JobId, Priority = ar.Task.Priority };230 }231 232 /*private static Func<HiveDataContext, Guid, Slave, IQueryable<TaskInfoForScheduler>> GetWaitingTasksQuery = CompiledQuery.Compile((HiveDataContext db, Guid id, Slave slave) =>233 from ar in db.AssignedResources234 where ar.ResourceId == id235 && !(ar.Task.IsParentTask && ar.Task.FinishWhenChildJobsFinished)236 && ar.Task.State == TaskState.Waiting237 && ar.Task.CoresNeeded <= slave.FreeCores238 && ar.Task.MemoryNeeded <= slave.FreeMemory239 select new TaskInfoForScheduler() { TaskId = ar.Task.TaskId, JobId = ar.Task.JobId, Priority = ar.Task.Priority }240 );*/241 242 197 public DT.Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) { 243 198 using (var db = CreateContext()) { … … 267 222 return DT.Convert.ToDto(task); 268 223 } 269 }270 271 public Task UpdateTaskStateDA(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) {272 var db = HiveOperationContext.Current.DataContext;273 274 db.StateLogs.InsertOnSubmit(new StateLog {275 TaskId = taskId,276 State = taskState,277 SlaveId = slaveId,278 UserId = userId,279 Exception = exception,280 DateTime = DateTime.Now281 });282 283 var task = GetTaskDA(taskId);284 task.State = taskState;285 286 db.SubmitChanges();287 288 return task;289 224 } 290 225 #endregion … … 581 516 } 582 517 583 public Slave GetSlaveDA(Guid id) {584 var db = HiveOperationContext.Current.DataContext;585 return GetSlaveByIdQuery(db, id).SingleOrDefault();586 }587 588 private static Func<HiveDataContext, Guid, IQueryable<Slave>> GetSlaveByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid slaveId) =>589 from s in db.Resources.OfType<Slave>()590 where s.ResourceId == slaveId591 select s592 );593 594 518 public IEnumerable<DT.Slave> GetSlaves(Expression<Func<Slave, bool>> predicate) { 595 519 using (var db = CreateContext()) { … … 614 538 db.SubmitChanges(); 615 539 } 616 }617 618 public void UpdateSlaveDA(Slave slave) {619 var db = HiveOperationContext.Current.DataContext;620 db.SubmitChanges();621 540 } 622 541 … … 736 655 } 737 656 738 public IQueryable<Guid> GetAssignedResourcesIdsDA(Guid taskId) {739 var db = HiveOperationContext.Current.DataContext;740 return GetAssignedResourcesIdQuery(db, taskId);741 }742 743 private static Func<HiveDataContext, Guid, IQueryable<Guid>> GetAssignedResourcesIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) =>744 from ar in db.AssignedResources745 where ar.TaskId == taskId746 select ar.ResourceId747 );748 749 657 /// <summary> 750 658 /// Returns all parent resources of a resource (the given resource is also added) … … 757 665 } 758 666 } 759 760 public IEnumerable<Resource> GetParentResourcesDA(Guid resourceId) {761 var db = HiveOperationContext.Current.DataContext;762 var child = db.Resources.Single(r => r.ResourceId == resourceId);763 764 yield return child;765 while (child.ParentResource != null) {766 child = child.ParentResource;767 yield return child;768 }769 }770 771 public IEnumerable<Guid> GetParentResourcesIDsDA(Guid resourceId) {772 var db = HiveOperationContext.Current.DataContext;773 var child = db.Resources.Single(r => r.ResourceId == resourceId);774 775 yield return resourceId;776 while (child.ParentResource != null) {777 child = child.ParentResource;778 yield return child.ResourceId;779 }780 }781 782 public IQueryable<int> GetNumberOfDowntimesFromParentResourcesAtCurrentTimeDA(Guid resourceId, DowntimeType type) {783 var db = HiveOperationContext.Current.DataContext;784 785 var ids = GetParentResourcesIDsDA(resourceId).ToArray();786 787 return from r in db.Resources788 where ids.Contains(r.ResourceId)789 select (from d in db.Downtimes790 where d.ResourceId == r.ResourceId && d.DowntimeType == type && (DateTime.Now >= d.StartDate) && (DateTime.Now <= d.EndDate)791 select d).Count();792 }793 794 /*private static Func<HiveDataContext, Guid, DowntimeType, int> GetNumberOfDowntimesAtCurrentTimeQuery =795 CompiledQuery.Compile((HiveDataContext db, Guid ids, DowntimeType type) =>796 (from d in db.Downtimes797 where d.ResourceId == ids && d.DowntimeType == type && (DateTime.Now >= d.StartDate) && (DateTime.Now <= d.EndDate)798 select d).Count()799 );*/800 667 801 668 private static void CollectParentResources(ICollection<Resource> resources, Resource resource) { -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs
r7259 r9391 37 37 } 38 38 39 private IHiveD ao dao {40 get { return ServiceLocator.Instance.HiveD ao; }39 private IHiveDtoDao dao { 40 get { return ServiceLocator.Instance.HiveDtoDao; } 41 41 } 42 42 -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveOperationContext.cs
r9381 r9391 20 20 #endregion 21 21 22 using System; 23 using System.Collections.ObjectModel; 22 24 using System.Diagnostics; 23 25 using System.IO; 24 26 using System.ServiceModel; 27 using System.ServiceModel.Channels; 28 using System.ServiceModel.Description; 29 using System.ServiceModel.Dispatcher; 25 30 using System.Text; 26 31 using HeuristicLab.Services.Hive.DataAccess; … … 30 35 public static HiveOperationContext Current { 31 36 get { 32 var context = OperationContext.Current.Extensions.Find<HiveOperationContext>(); 33 if (context == null) { 34 context = new HiveOperationContext(); 35 OperationContext.Current.Extensions.Add(context); 36 } 37 return context; 37 return OperationContext.Current.Extensions.Find<HiveOperationContext>(); 38 38 } 39 39 } … … 42 42 43 43 public void Attach(OperationContext owner) { 44 DataContext = HiveDao.CreateContext();44 DataContext = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); 45 45 //DataContext.Log = new DebugWriter(); 46 46 } 47 47 48 48 public void Detach(OperationContext owner) { 49 // nothing 49 DataContext.Dispose(); 50 } 51 } 52 53 public class HiveOperationContextMessageInspector : IDispatchMessageInspector { 54 public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { 55 OperationContext.Current.Extensions.Add(new HiveOperationContext()); 56 return request.Headers.MessageId; 57 } 58 59 public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { 60 OperationContext.Current.Extensions.Remove(HiveOperationContext.Current); 61 } 62 } 63 64 public class HiveOperationContextBehaviorAttribute : Attribute, IServiceBehavior { 65 public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, 66 Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) { 67 } 68 69 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { 70 foreach (ChannelDispatcher cd in serviceHostBase.ChannelDispatchers) { 71 foreach (EndpointDispatcher ed in cd.Endpoints) { 72 ed.DispatchRuntime.MessageInspectors.Add(new HiveOperationContextMessageInspector()); 73 } 74 } 75 } 76 77 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { 50 78 } 51 79 } -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs
r9369 r9391 37 37 /// </summary> 38 38 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IgnoreExtensionDataObject = true)] 39 [HiveOperationContextBehavior] 39 40 public class HiveService : IHiveService { 41 private IHiveDtoDao dtoDao { 42 get { return ServiceLocator.Instance.HiveDtoDao; } 43 } 40 44 private IHiveDao dao { 41 45 get { return ServiceLocator.Instance.HiveDao; } … … 64 68 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 65 69 return trans.UseTransaction(() => { 66 task.Id = d ao.AddTask(task);70 task.Id = dtoDao.AddTask(task); 67 71 taskData.TaskId = task.Id; 68 72 taskData.LastUpdate = DateTime.Now; 69 d ao.AssignJobToResource(task.Id, resourceIds);70 d ao.AddTaskData(taskData);71 d ao.UpdateTaskState(task.Id, DA.TaskState.Waiting, null, userManager.CurrentUserId, null);73 dtoDao.AssignJobToResource(task.Id, resourceIds); 74 dtoDao.AddTaskData(taskData); 75 dtoDao.UpdateTaskState(task.Id, DA.TaskState.Waiting, null, userManager.CurrentUserId, null); 72 76 return taskData.TaskId; 73 77 }, false, true); … … 78 82 return trans.UseTransaction(() => { 79 83 task.ParentTaskId = parentTaskId; 80 return AddTask(task, taskData, d ao.GetAssignedResources(parentTaskId).Select(x => x.Id));84 return AddTask(task, taskData, dtoDao.GetAssignedResources(parentTaskId).Select(x => x.Id)); 81 85 }, false, true); 82 86 } … … 87 91 88 92 return trans.UseTransaction(() => { 89 return d ao.GetTask(taskId);93 return dtoDao.GetTask(taskId); 90 94 }, false, false); 91 95 } … … 94 98 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 95 99 return trans.UseTransaction(() => { 96 var tasks = d ao.GetTasks(x => true);100 var tasks = dtoDao.GetTasks(x => true); 97 101 foreach (var task in tasks) 98 102 author.AuthorizeForTask(task.Id, Permission.Read); … … 105 109 106 110 return trans.UseTransaction(() => { 107 var tasks = d ao.GetTasks(x => taskIds.Contains(x.TaskId)).Select(x => new LightweightTask(x)).ToArray();111 var tasks = dtoDao.GetTasks(x => taskIds.Contains(x.TaskId)).Select(x => new LightweightTask(x)).ToArray(); 108 112 foreach (var task in tasks) 109 113 author.AuthorizeForTask(task.Id, Permission.Read); … … 128 132 129 133 return trans.UseTransaction(() => { 130 return d ao.GetLightweightTasks(task => task.JobId == jobId).ToArray();134 return dtoDao.GetLightweightTasks(task => task.JobId == jobId).ToArray(); 131 135 }, false, true); 132 136 } … … 137 141 138 142 return trans.UseTransaction(() => { 139 return d ao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray();143 return dtoDao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray(); 140 144 }, false, false); 141 145 } … … 146 150 147 151 return trans.UseTransaction(() => { 148 return d ao.GetTaskData(taskId);152 return dtoDao.GetTaskData(taskId); 149 153 }); 150 154 } … … 155 159 156 160 trans.UseTransaction(() => { 157 d ao.UpdateTaskAndPlugins(taskDto);161 dtoDao.UpdateTaskAndPlugins(taskDto); 158 162 }); 159 163 } … … 163 167 author.AuthorizeForTask(task.Id, Permission.Full); 164 168 165 trans.UseTransaction(() => { 166 dao.UpdateTaskAndPlugins(task); 167 }); 168 169 trans.UseTransaction(() => { 170 taskData.LastUpdate = DateTime.Now; 171 dao.UpdateTaskData(taskData); 169 // what for? 170 /*trans.UseTransaction(() => { 171 dtoDao.UpdateTaskAndPlugins(task); 172 });*/ 173 174 trans.UseTransaction(() => { 175 var data = dao.GetTaskDataByDto(taskData); 176 data.LastUpdate = DateTime.Now; 177 dao.UpdateTaskData(data); 172 178 }); 173 179 } … … 177 183 author.AuthorizeForTask(taskId, Permission.Full); 178 184 trans.UseTransaction(() => { 179 d ao.DeleteTask(taskId);185 dtoDao.DeleteTask(taskId); 180 186 }); 181 187 } … … 187 193 var tasks = GetChildTasks(parentTaskId, true, false); 188 194 foreach (var task in tasks) { 189 d ao.DeleteTask(task.Id);190 d ao.DeleteTaskData(task.Id);195 dtoDao.DeleteTask(task.Id); 196 dtoDao.DeleteTaskData(task.Id); 191 197 }; 192 198 }); … … 196 202 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 197 203 author.AuthorizeForTask(taskId, Permission.Full); 198 return trans.UseTransaction(() => { 199 Task task = dao.UpdateTaskState(taskId, DataTransfer.Convert.ToEntity(taskState), slaveId, userId, exception); 200 201 if (task.Command.HasValue && task.Command.Value == Command.Pause && task.State == TaskState.Paused) { 204 205 return trans.UseTransaction(() => { 206 var task = dao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception); 207 208 if (task.Command.HasValue && task.Command.Value == DA.Command.Pause && task.State == DA.TaskState.Paused) { 202 209 task.Command = null; 203 } else if (task.Command.HasValue && task.Command.Value == Command.Abort && task.State ==TaskState.Aborted) {210 } else if (task.Command.HasValue && task.Command.Value == DA.Command.Abort && task.State == DA.TaskState.Aborted) { 204 211 task.Command = null; 205 } else if (task.Command.HasValue && task.Command.Value == Command.Stop && task.State ==TaskState.Aborted) {212 } else if (task.Command.HasValue && task.Command.Value == DA.Command.Stop && task.State == DA.TaskState.Aborted) { 206 213 task.Command = null; 207 214 } else if (taskState == TaskState.Paused && !task.Command.HasValue) { 208 215 // slave paused and uploaded the task (no user-command) -> set waiting. 209 task = dao.UpdateTaskState(taskId, D ataTransfer.Convert.ToEntity(TaskState.Waiting), slaveId, userId, exception);210 } 211 212 dao.UpdateTaskAndPlugins(task);213 return task;216 task = dao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception); 217 } 218 219 //dtoDao.UpdateTaskAndPluginsDA(task); no idea why this is needed 220 return DT.Convert.ToDto(task); 214 221 }); 215 222 } … … 217 224 public IEnumerable<Task> GetTasksByResourceId(Guid resourceId) { 218 225 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 219 var tasks = trans.UseTransaction(() => d ao.GetJobsByResourceId(resourceId));226 var tasks = trans.UseTransaction(() => dtoDao.GetJobsByResourceId(resourceId)); 220 227 foreach (var task in tasks) 221 228 author.AuthorizeForTask(task.Id, Permission.Read); … … 229 236 author.AuthorizeForTask(taskId, Permission.Full); 230 237 trans.UseTransaction(() => { 231 var task = d ao.GetTask(taskId);238 var task = dtoDao.GetTask(taskId); 232 239 if (task.State == TaskState.Calculating || task.State == TaskState.Transferring) { 233 240 task.Command = Command.Stop; 234 d ao.UpdateTask(task);241 dtoDao.UpdateTask(task); 235 242 } else { 236 243 if (task.State != TaskState.Aborted && task.State != TaskState.Finished && task.State != TaskState.Failed) { … … 245 252 author.AuthorizeForTask(taskId, Permission.Full); 246 253 trans.UseTransaction(() => { 247 var job = d ao.GetTask(taskId);254 var job = dtoDao.GetTask(taskId); 248 255 if (job.State == TaskState.Calculating || job.State == TaskState.Transferring) { 249 256 job.Command = Command.Pause; 250 d ao.UpdateTask(job);257 dtoDao.UpdateTask(job); 251 258 } else { 252 259 job = UpdateTaskState(taskId, TaskState.Paused, null, null, string.Empty); … … 259 266 author.AuthorizeForTask(taskId, Permission.Full); 260 267 trans.UseTransaction(() => { 261 Task task = d ao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, string.Empty);268 Task task = dtoDao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, string.Empty); 262 269 task.Command = null; 263 d ao.UpdateTask(task);270 dtoDao.UpdateTask(task); 264 271 }); 265 272 } … … 271 278 author.AuthorizeForJob(id, Permission.Read); 272 279 return trans.UseTransaction(() => { 273 var job = d ao.GetJobs(x =>280 var job = dtoDao.GetJobs(x => 274 281 x.JobId == id 275 282 && (x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0) 276 283 ).FirstOrDefault(); 277 284 if (job != null) { 278 job.Permission = DT.Convert.ToDto(d ao.GetPermissionForJob(job.Id, userManager.CurrentUserId));285 job.Permission = DT.Convert.ToDto(dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 279 286 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 280 287 } … … 286 293 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 287 294 return trans.UseTransaction(() => { 288 var jobs = d ao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0);295 var jobs = dtoDao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0); 289 296 foreach (var job in jobs) { 290 297 author.AuthorizeForJob(job.Id, Permission.Read); 291 job.Permission = DT.Convert.ToDto(d ao.GetPermissionForJob(job.Id, userManager.CurrentUserId));298 job.Permission = DT.Convert.ToDto(dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 292 299 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 293 300 } … … 299 306 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 300 307 return trans.UseTransaction(() => { 301 var jobs = d ao.GetJobs(x => true);308 var jobs = dtoDao.GetJobs(x => true); 302 309 foreach (var job in jobs) { // no authorization here, since this method is admin-only! (admin is allowed to read all task) 303 job.Permission = DT.Convert.ToDto(d ao.GetPermissionForJob(job.Id, userManager.CurrentUserId));310 job.Permission = DT.Convert.ToDto(dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 304 311 job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName; 305 312 } … … 313 320 jobDto.OwnerUserId = userManager.CurrentUserId; 314 321 jobDto.DateCreated = DateTime.Now; 315 return d ao.AddJob(jobDto);322 return dtoDao.AddJob(jobDto); 316 323 }); 317 324 } … … 321 328 author.AuthorizeForJob(jobDto.Id, Permission.Full); 322 329 trans.UseTransaction(() => { 323 d ao.UpdateJob(jobDto);330 dtoDao.UpdateJob(jobDto); 324 331 }); 325 332 } … … 329 336 author.AuthorizeForJob(jobId, Permission.Full); 330 337 trans.UseTransaction(() => { 331 d ao.DeleteJob(jobId); // child task will be deleted by db-trigger338 dtoDao.DeleteJob(jobId); // child task will be deleted by db-trigger 332 339 }); 333 340 } … … 338 345 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 339 346 trans.UseTransaction(() => { 340 Job job = d ao.GetJob(jobId);347 Job job = dtoDao.GetJob(jobId); 341 348 if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId)); 342 Permission perm = DT.Convert.ToDto(d ao.GetPermissionForJob(job.Id, userManager.CurrentUserId));349 Permission perm = DT.Convert.ToDto(dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId)); 343 350 if (perm != Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment")); 344 d ao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DT.Convert.ToEntity(permission));351 dtoDao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DT.Convert.ToEntity(permission)); 345 352 }); 346 353 } … … 349 356 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 350 357 trans.UseTransaction(() => { 351 Job job = d ao.GetJob(jobId);358 Job job = dtoDao.GetJob(jobId); 352 359 if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId)); 353 DA.Permission perm = d ao.GetPermissionForJob(job.Id, userManager.CurrentUserId);360 DA.Permission perm = dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId); 354 361 if (perm != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment")); 355 d ao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DA.Permission.NotAllowed);362 dtoDao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DA.Permission.NotAllowed); 356 363 }); 357 364 } … … 360 367 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 361 368 return trans.UseTransaction(() => { 362 DA.Permission currentUserPermission = d ao.GetPermissionForJob(jobId, userManager.CurrentUserId);369 DA.Permission currentUserPermission = dtoDao.GetPermissionForJob(jobId, userManager.CurrentUserId); 363 370 if (currentUserPermission != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment")); 364 return d ao.GetJobPermissions(x => x.JobId == jobId);371 return dtoDao.GetJobPermissions(x => x.JobId == jobId); 365 372 }); 366 373 } … … 379 386 380 387 trans.UseTransaction(() => { 381 var slave = d ao.GetSlave(slaveInfo.Id);388 var slave = dtoDao.GetSlave(slaveInfo.Id); 382 389 383 390 if (slave == null) { 384 var healGroup = d ao.GetResources(x => x.Name == "HEAL").First();391 var healGroup = dtoDao.GetResources(x => x.Name == "HEAL").First(); 385 392 if (healGroup != null) { 386 393 slaveInfo.ParentResourceId = healGroup.Id; 387 394 } 388 d ao.AddSlave(slaveInfo);395 dtoDao.AddSlave(slaveInfo); 389 396 } else { 390 397 slave.Name = slaveInfo.Name; … … 405 412 // don't update those properties: dbSlave.IsAllowedToCalculate, dbSlave.ParentResourceId 406 413 407 d ao.UpdateSlave(slave);414 dtoDao.UpdateSlave(slave); 408 415 } 409 416 }); … … 413 420 authen.AuthenticateForAnyRole(HiveRoles.Slave); 414 421 trans.UseTransaction(() => { 415 var slave = d ao.GetSlave(slaveId);422 var slave = dtoDao.GetSlave(slaveId); 416 423 if (slave != null) { 417 424 slave.SlaveState = SlaveState.Offline; 418 d ao.UpdateSlave(slave);425 dtoDao.UpdateSlave(slave); 419 426 } 420 427 }); … … 449 456 plugin.DateCreated = DateTime.Now; 450 457 451 var existing = d ao.GetPlugins(x => x.Hash != null).Where(x => x.Hash.SequenceEqual(plugin.Hash));458 var existing = dtoDao.GetPlugins(x => x.Hash != null).Where(x => x.Hash.SequenceEqual(plugin.Hash)); 452 459 if (existing.Count() > 0) { 453 460 // a plugin already exists. … … 455 462 } 456 463 457 Guid pluginId = d ao.AddPlugin(plugin);464 Guid pluginId = dtoDao.AddPlugin(plugin); 458 465 foreach (PluginData pluginData in pluginDatas) { 459 466 pluginData.PluginId = pluginId; 460 d ao.AddPluginData(pluginData);467 dtoDao.AddPluginData(pluginData); 461 468 } 462 469 return pluginId; … … 467 474 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 468 475 return trans.UseTransaction(() => { 469 return d ao.GetPlugin(pluginId);476 return dtoDao.GetPlugin(pluginId); 470 477 }); 471 478 } … … 474 481 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 475 482 return trans.UseTransaction(() => { 476 return d ao.GetPlugins(x => x.Hash == hash).FirstOrDefault();483 return dtoDao.GetPlugins(x => x.Hash == hash).FirstOrDefault(); 477 484 }); 478 485 } … … 483 490 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 484 491 return trans.UseTransaction(() => { 485 return d ao.GetPlugins(x => x.Hash != null);492 return dtoDao.GetPlugins(x => x.Hash != null); 486 493 }); 487 494 } … … 492 499 return trans.UseTransaction(() => { 493 500 foreach (Guid guid in pluginIds) { 494 pluginDatas.AddRange(d ao.GetPluginDatas(x => x.PluginId == guid).ToList());501 pluginDatas.AddRange(dtoDao.GetPluginDatas(x => x.PluginId == guid).ToList()); 495 502 } 496 503 return pluginDatas; … … 501 508 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 502 509 trans.UseTransaction(() => { 503 d ao.DeletePlugin(pluginId);510 dtoDao.DeletePlugin(pluginId); 504 511 }); 505 512 } … … 510 517 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 511 518 trans.UseTransaction(() => { 512 Resource resource = d ao.GetResource(resourceId);519 Resource resource = dtoDao.GetResource(resourceId); 513 520 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 514 521 if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permission for this resource")); 515 522 foreach (Guid id in grantedUserIds) 516 d ao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = userManager.CurrentUserId, GrantedUserId = id });523 dtoDao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = userManager.CurrentUserId, GrantedUserId = id }); 517 524 }); 518 525 } … … 521 528 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 522 529 trans.UseTransaction(() => { 523 Resource resource = d ao.GetResource(resourceId);530 Resource resource = dtoDao.GetResource(resourceId); 524 531 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 525 532 if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to revoke permission for this resource")); 526 533 foreach (Guid id in grantedUserIds) 527 d ao.DeleteResourcePermission(resourceId, id);534 dtoDao.DeleteResourcePermission(resourceId, id); 528 535 }); 529 536 } … … 532 539 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 533 540 return trans.UseTransaction(() => { 534 Resource resource = d ao.GetResource(resourceId);541 Resource resource = dtoDao.GetResource(resourceId); 535 542 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 536 return d ao.GetResourcePermissions(x => x.ResourceId == resourceId);543 return dtoDao.GetResourcePermissions(x => x.ResourceId == resourceId); 537 544 }); 538 545 } … … 541 548 #region Resource Methods 542 549 public IEnumerable<Resource> GetChildResources(Guid resourceId) { 543 return trans.UseTransaction(() => { return d ao.GetChildResources(resourceId); });550 return trans.UseTransaction(() => { return dtoDao.GetChildResources(resourceId); }); 544 551 } 545 552 #endregion … … 549 556 authen.AuthenticateForAnyRole(HiveRoles.Slave); 550 557 551 Slave s = trans.UseTransaction(() => { return d ao.GetSlave(slaveId); });558 Slave s = trans.UseTransaction(() => { return dtoDao.GetSlave(slaveId); }); 552 559 if (s != null) { 553 560 return s.HbInterval; … … 559 566 public Guid AddSlave(Slave slave) { 560 567 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 561 return trans.UseTransaction(() => d ao.AddSlave(slave));568 return trans.UseTransaction(() => dtoDao.AddSlave(slave)); 562 569 } 563 570 564 571 public Guid AddSlaveGroup(SlaveGroup slaveGroup) { 565 572 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 566 return trans.UseTransaction(() => d ao.AddSlaveGroup(slaveGroup));573 return trans.UseTransaction(() => dtoDao.AddSlaveGroup(slaveGroup)); 567 574 } 568 575 569 576 public Slave GetSlave(Guid slaveId) { 570 577 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 571 return trans.UseTransaction(() => { return d ao.GetSlave(slaveId); });578 return trans.UseTransaction(() => { return dtoDao.GetSlave(slaveId); }); 572 579 } 573 580 574 581 public SlaveGroup GetSlaveGroup(Guid slaveGroupId) { 575 582 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 576 return trans.UseTransaction(() => { return d ao.GetSlaveGroup(slaveGroupId); });583 return trans.UseTransaction(() => { return dtoDao.GetSlaveGroup(slaveGroupId); }); 577 584 } 578 585 … … 580 587 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 581 588 return trans.UseTransaction(() => { 582 return d ao.GetSlaves(x => true).Where(x => x.OwnerUserId == null589 return dtoDao.GetSlaves(x => true).Where(x => x.OwnerUserId == null 583 590 || x.OwnerUserId == userManager.CurrentUserId 584 591 || userManager.VerifyUser(userManager.CurrentUserId, GetResourcePermissions(x.Id).Select(y => y.GrantedUserId).ToList()) … … 590 597 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 591 598 return trans.UseTransaction(() => { 592 return d ao.GetSlaveGroups(x => true).Where(x => x.OwnerUserId == null599 return dtoDao.GetSlaveGroups(x => true).Where(x => x.OwnerUserId == null 593 600 || x.OwnerUserId == userManager.CurrentUserId 594 601 || userManager.VerifyUser(userManager.CurrentUserId, GetResourcePermissions(x.Id).Select(y => y.GrantedUserId).ToList()) … … 600 607 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 601 608 trans.UseTransaction(() => { 602 d ao.UpdateSlave(slave);609 dtoDao.UpdateSlave(slave); 603 610 }); 604 611 } … … 607 614 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 608 615 trans.UseTransaction(() => { 609 d ao.UpdateSlaveGroup(slaveGroup);616 dtoDao.UpdateSlaveGroup(slaveGroup); 610 617 }); 611 618 } … … 615 622 author.AuthorizeForResourceAdministration(slaveId); 616 623 trans.UseTransaction(() => { 617 d ao.DeleteSlave(slaveId);624 dtoDao.DeleteSlave(slaveId); 618 625 }); 619 626 } … … 623 630 author.AuthorizeForResourceAdministration(slaveGroupId); 624 631 trans.UseTransaction(() => { 625 d ao.DeleteSlaveGroup(slaveGroupId);632 dtoDao.DeleteSlaveGroup(slaveGroupId); 626 633 }); 627 634 } … … 630 637 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 631 638 trans.UseTransaction(() => { 632 var resource = d ao.GetResource(resourceId);639 var resource = dtoDao.GetResource(resourceId); 633 640 resource.ParentResourceId = slaveGroupId; 634 d ao.UpdateResource(resource);641 dtoDao.UpdateResource(resource); 635 642 }); 636 643 } … … 639 646 authen.AuthenticateForAnyRole(HiveRoles.Administrator); 640 647 trans.UseTransaction(() => { 641 var resource = d ao.GetResource(resourceId);648 var resource = dtoDao.GetResource(resourceId); 642 649 resource.ParentResourceId = null; 643 d ao.UpdateResource(resource);650 dtoDao.UpdateResource(resource); 644 651 }); 645 652 } … … 648 655 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 649 656 return trans.UseTransaction(() => { 650 var resource = d ao.GetResources(x => x.Name == resourceName).FirstOrDefault();657 var resource = dtoDao.GetResources(x => x.Name == resourceName).FirstOrDefault(); 651 658 if (resource != null) { 652 659 return resource.Id; … … 662 669 bool cleanup = false; 663 670 trans.UseTransaction(() => { 664 DateTime lastCleanup = d ao.GetLastCleanup();671 DateTime lastCleanup = dtoDao.GetLastCleanup(); 665 672 if (force || DateTime.Now - lastCleanup > HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval) { 666 d ao.SetLastCleanup(DateTime.Now);673 dtoDao.SetLastCleanup(DateTime.Now); 667 674 cleanup = true; 668 675 } … … 679 686 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 680 687 author.AuthorizeForResourceAdministration(downtime.ResourceId); 681 return trans.UseTransaction(() => d ao.AddDowntime(downtime));688 return trans.UseTransaction(() => dtoDao.AddDowntime(downtime)); 682 689 } 683 690 … … 687 694 // author.AuthorizeForResource(resourceId); 688 695 trans.UseTransaction(() => { 689 d ao.DeleteDowntime(downtimeId);696 dtoDao.DeleteDowntime(downtimeId); 690 697 }); 691 698 } … … 695 702 author.AuthorizeForResourceAdministration(downtime.ResourceId); 696 703 trans.UseTransaction(() => { 697 d ao.UpdateDowntime(downtime);704 dtoDao.UpdateDowntime(downtime); 698 705 }); 699 706 } … … 701 708 public IEnumerable<Downtime> GetDowntimesForResource(Guid resourceId) { 702 709 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 703 return trans.UseTransaction(() => d ao.GetDowntimes(x => x.ResourceId == resourceId));710 return trans.UseTransaction(() => dtoDao.GetDowntimes(x => x.ResourceId == resourceId)); 704 711 } 705 712 #endregion … … 724 731 #region UserPriority Methods 725 732 public IEnumerable<UserPriority> GetUserPriorities() { 726 return trans.UseTransaction(() => d ao.GetUserPriorities(x => true));733 return trans.UseTransaction(() => dtoDao.GetUserPriorities(x => true)); 727 734 } 728 735 #endregion … … 730 737 #region Helper Methods 731 738 private IEnumerable<Task> GetChildTasks(Guid? parentTaskId, bool recursive, bool includeParent) { 732 var tasks = new List<Task>(d ao.GetTasks(x => parentTaskId == null ? !x.ParentTaskId.HasValue : x.ParentTaskId.Value == parentTaskId));739 var tasks = new List<Task>(dtoDao.GetTasks(x => parentTaskId == null ? !x.ParentTaskId.HasValue : x.ParentTaskId.Value == parentTaskId)); 733 740 734 741 if (recursive) { … … 747 754 #region Statistics Methods 748 755 public IEnumerable<Statistics> GetStatistics() { 749 return trans.UseTransaction(() => { return d ao.GetStatistics(x => true); });756 return trans.UseTransaction(() => { return dtoDao.GetStatistics(x => true); }); 750 757 } 751 758 public IEnumerable<Statistics> GetStatisticsForTimePeriod(DateTime from, DateTime to) { 752 return trans.UseTransaction(() => { return d ao.GetStatistics(x => x.Timestamp >= from && x.Timestamp <= to); });759 return trans.UseTransaction(() => { return dtoDao.GetStatistics(x => x.Timestamp >= from && x.Timestamp <= to); }); 753 760 } 754 761 #endregion -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDtoDao.cs
r9385 r9391 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 24 using System.Linq.Expressions; 26 25 using HeuristicLab.Services.Hive.DataAccess; … … 28 27 29 28 namespace HeuristicLab.Services.Hive { 30 public interface IHiveD ao {29 public interface IHiveDtoDao { 31 30 #region Task Methods 32 31 DT.Task GetTask(Guid id); 33 Task GetTaskDA(Guid id);34 32 IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate); 35 33 IEnumerable<DT.LightweightTask> GetLightweightTasks(Expression<Func<Task, bool>> predicate); … … 39 37 void UpdateTaskAndStateLogs(DT.Task dto); 40 38 void UpdateTask(DT.Task dto); 41 void UpdateTaskDA(Task dto);42 39 void DeleteTask(Guid id); 43 40 IEnumerable<TaskInfoForScheduler> GetWaitingTasks(DT.Slave slave); 44 IQueryable<TaskInfoForScheduler> GetWaitingTasksDA(Slave slave);45 41 IEnumerable<DT.Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished); 46 42 DT.Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception); 47 Task UpdateTaskStateDA(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception);48 43 #endregion 49 44 … … 100 95 #region Slave Methods 101 96 DT.Slave GetSlave(Guid id); 102 Slave GetSlaveDA(Guid id);103 97 IEnumerable<DT.Slave> GetSlaves(Expression<Func<Slave, bool>> predicate); 104 98 Guid AddSlave(DT.Slave dto); 105 99 void UpdateSlave(DT.Slave dto); 106 void UpdateSlaveDA(Slave dto);107 100 void DeleteSlave(Guid id); 108 101 #endregion … … 124 117 void AssignJobToResource(Guid taskId, IEnumerable<Guid> resourceIds); 125 118 IEnumerable<DT.Resource> GetAssignedResources(Guid jobId); 126 IQueryable<Guid> GetAssignedResourcesIdsDA(Guid taskId);127 119 IEnumerable<DT.Resource> GetParentResources(Guid resourceId); 128 IEnumerable<Resource> GetParentResourcesDA(Guid resourceId);129 IEnumerable<Guid> GetParentResourcesIDsDA(Guid resourceId);130 IQueryable<int> GetNumberOfDowntimesFromParentResourcesAtCurrentTimeDA(Guid resourceId, DowntimeType type);131 120 IEnumerable<DT.Resource> GetChildResources(Guid resourceId); 132 121 IEnumerable<DT.Task> GetJobsByResourceId(Guid resourceId); -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IServiceLocator.cs
r9123 r9391 26 26 Access.IRoleVerifier RoleVerifier { get; } 27 27 IAuthorizationManager AuthorizationManager { get; } 28 IHiveDtoDao HiveDtoDao { get; } 28 29 IHiveDao HiveDao { get; } 29 30 IEventManager EventManager { get; } -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r8051 r9391 36 36 if (ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Slave)) return; // slave-users can access all tasks 37 37 38 Permission permission = ServiceLocator.Instance.HiveD ao.GetPermissionForTask(taskId, ServiceLocator.Instance.UserManager.CurrentUserId);38 Permission permission = ServiceLocator.Instance.HiveDtoDao.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 ao.GetPermissionForJob(jobId, ServiceLocator.Instance.UserManager.CurrentUserId);44 Permission permission = ServiceLocator.Instance.HiveDtoDao.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 ao.GetResource(resourceId));50 Resource resource = DT.Convert.ToEntity(ServiceLocator.Instance.HiveDtoDao.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
r9257 r9391 32 32 /// </summary> 33 33 public class EventManager : IEventManager { 34 private IHiveD ao dao {35 get { return ServiceLocator.Instance.HiveD ao; }34 private IHiveDtoDao dao { 35 get { return ServiceLocator.Instance.HiveDtoDao; } 36 36 } 37 37 private IAuthorizationManager auth { … … 78 78 //we have to find another way to deal with this. 79 79 //until then the next line is commented out... 80 //stats.UserStatistics = d ao.GetUserStatistics();80 //stats.UserStatistics = dtoDao.GetUserStatistics(); 81 81 dao.AddStatistics(stats); 82 82 } -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
r9385 r9391 24 24 using System.Linq; 25 25 using System.Threading; 26 using HeuristicLab.Services.Hive.Data Transfer;27 using DA = HeuristicLab.Services.Hive.DataAccess;26 using HeuristicLab.Services.Hive.DataAccess; 27 using Heartbeat = HeuristicLab.Services.Hive.DataTransfer.Heartbeat; 28 28 29 29 namespace HeuristicLab.Services.Hive { … … 48 48 List<MessageContainer> actions = new List<MessageContainer>(); 49 49 50 DA.Slave slave = null;50 Slave slave = null; 51 51 trans.UseTransaction(() => { 52 slave = dao.GetSlave DA(heartbeat.SlaveId);52 slave = dao.GetSlaveById(heartbeat.SlaveId); 53 53 54 54 if (slave == null) { … … 67 67 slave.CpuUtilization = heartbeat.CpuUtilization; 68 68 slave.IsAllowedToCalculate = SlaveIsAllowedToCalculate(slave.ResourceId); 69 slave.SlaveState = (heartbeat.JobProgress != null && heartbeat.JobProgress.Count > 0) ? DA.SlaveState.Calculating : DA.SlaveState.Idle;69 slave.SlaveState = (heartbeat.JobProgress != null && heartbeat.JobProgress.Count > 0) ? SlaveState.Calculating : SlaveState.Idle; 70 70 slave.LastHeartbeat = DateTime.Now; 71 71 72 dao.UpdateSlave DA(slave);72 dao.UpdateSlave(slave); 73 73 } 74 74 }); … … 86 86 mutexAquired = mutex.WaitOne(Properties.Settings.Default.SchedulingPatience); 87 87 if (!mutexAquired) 88 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling could not be aquired.");88 LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling could not be aquired."); 89 89 else { 90 90 trans.UseTransaction(() => { 91 91 IEnumerable<TaskInfoForScheduler> availableTasks = null; 92 availableTasks = taskScheduler.Schedule(dao.GetWaitingTasks DA(slave).ToArray());92 availableTasks = taskScheduler.Schedule(dao.GetWaitingTasks(slave).ToArray()); 93 93 if (availableTasks.Any()) { 94 94 var task = availableTasks.First(); … … 100 100 } 101 101 catch (AbandonedMutexException) { 102 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling has been abandoned.");102 LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling has been abandoned."); 103 103 } 104 104 catch (Exception ex) { 105 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager threw an exception in ProcessHeartbeat: " + ex.ToString());105 LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager threw an exception in ProcessHeartbeat: " + ex.ToString()); 106 106 } 107 107 finally { … … 113 113 } 114 114 115 private void AssignJob( DA.Slave slave, Guid taskId) {116 var task = dao.UpdateTaskState DA(taskId, DataAccess.TaskState.Transferring, slave.ResourceId, null, null);115 private void AssignJob(Slave slave, Guid taskId) { 116 var task = dao.UpdateTaskState(taskId, DataAccess.TaskState.Transferring, slave.ResourceId, null, null); 117 117 118 118 // from now on the task has some time to send the next heartbeat (ApplicationConstants.TransferringJobHeartbeatTimeout) 119 119 task.LastHeartbeat = DateTime.Now; 120 dao.UpdateTask DA(task);120 dao.UpdateTask(task); 121 121 } 122 122 … … 137 137 foreach (var jobProgress in heartbeat.JobProgress) { 138 138 trans.UseTransaction(() => { 139 var curTask = dao.GetTask DA(jobProgress.Key);139 var curTask = dao.GetTaskById(jobProgress.Key); 140 140 if (curTask == null) { 141 141 // task does not exist in db 142 142 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, jobProgress.Key)); 143 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("Task on slave " + heartbeat.SlaveId + " does not exist in DB: " + jobProgress.Key);143 LogFactory.GetLogger(this.GetType().Namespace).Log("Task on slave " + heartbeat.SlaveId + " does not exist in DB: " + jobProgress.Key); 144 144 } else { 145 145 var currentStateLog = curTask.StateLogs.Last(); … … 147 147 // assigned slave does not match heartbeat 148 148 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curTask.TaskId)); 149 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not supposed to calculate task: " + curTask);149 LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not supposed to calculate task: " + curTask); 150 150 } else if (!TaskIsAllowedToBeCalculatedBySlave(heartbeat.SlaveId, curTask)) { 151 151 // assigned resources ids of task do not match with slaveId (and parent resourceGroupIds); this might happen when slave is moved to different group … … 157 157 158 158 switch (curTask.Command) { 159 case DA.Command.Stop:159 case Command.Stop: 160 160 actions.Add(new MessageContainer(MessageContainer.MessageType.StopTask, curTask.TaskId)); 161 161 break; 162 case DA.Command.Pause:162 case Command.Pause: 163 163 actions.Add(new MessageContainer(MessageContainer.MessageType.PauseTask, curTask.TaskId)); 164 164 break; 165 case DA.Command.Abort:165 case Command.Abort: 166 166 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curTask.TaskId)); 167 167 break; 168 168 } 169 dao.UpdateTask DA(curTask);169 dao.UpdateTask(curTask); 170 170 } 171 171 } … … 176 176 } 177 177 178 private bool TaskIsAllowedToBeCalculatedBySlave(Guid slaveId, DA.Task curTask) {179 var assignedResourceIds = dao.GetAssignedResourcesIds DA(curTask.TaskId);180 var slaveResourceIds = dao.GetParentResourcesIDs DA(slaveId).ToArray();178 private bool TaskIsAllowedToBeCalculatedBySlave(Guid slaveId, Task curTask) { 179 var assignedResourceIds = dao.GetAssignedResourcesIds(curTask.TaskId); 180 var slaveResourceIds = dao.GetParentResourcesIDs(slaveId).ToArray(); 181 181 return assignedResourceIds.Any(r => slaveResourceIds.Contains(r)); 182 182 } 183 183 184 184 private bool SlaveIsAllowedToCalculate(Guid slaveId) { 185 var downtimes = dao.GetNumberOfDowntimesFromParentResourcesAtCurrentTime DA(slaveId, DA.DowntimeType.Offline);185 var downtimes = dao.GetNumberOfDowntimesFromParentResourcesAtCurrentTime(slaveId, DowntimeType.Offline); 186 186 // the slave may only calculate if there is no downtime right now. this needs to be checked for every parent resource also 187 187 return downtimes.All(x => x == 0); … … 189 189 190 190 private bool ShutdownSlaveComputer(Guid slaveId) { 191 var downtimes = dao.GetNumberOfDowntimesFromParentResourcesAtCurrentTime DA(slaveId, DA.DowntimeType.Shutdown);191 var downtimes = dao.GetNumberOfDowntimesFromParentResourcesAtCurrentTime(slaveId, DowntimeType.Shutdown); 192 192 return downtimes.Any(x => x != 0); 193 193 } -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs
r9123 r9391 27 27 namespace HeuristicLab.Services.Hive { 28 28 public class RoundRobinTaskScheduler : ITaskScheduler { 29 private IHiveD ao dao {30 get { return ServiceLocator.Instance.HiveD ao; }29 private IHiveDtoDao dao { 30 get { return ServiceLocator.Instance.HiveDtoDao; } 31 31 } 32 32 -
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/ServiceLocator.cs
r9123 r9391 32 32 } 33 33 set { instance = value; } 34 } 35 36 private IHiveDtoDao hiveDtoDao; 37 public IHiveDtoDao HiveDtoDao { 38 get { 39 if (hiveDtoDao == null) hiveDtoDao = new HiveDtoDao(); 40 return hiveDtoDao; 41 } 34 42 } 35 43
Note: See TracChangeset
for help on using the changeset viewer.