Changeset 9257 for trunk/sources/HeuristicLab.Services.Hive/3.3/Manager
- Timestamp:
- 02/28/13 13:57:49 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Services.Hive/3.3/Manager
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Services.Hive/3.3/Manager/EventManager.cs
r7862 r9257 50 50 SetTimeoutTasksWaiting(); 51 51 DeleteObsoleteSlaves(); 52 } , true);52 }); 53 53 54 54 trans.UseTransaction(() => { 55 55 FinishParentTasks(); 56 56 UpdateStatistics(); 57 } , false);57 }); 58 58 } 59 59 -
trunk/sources/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
r9123 r9257 37 37 get { return ServiceLocator.Instance.TaskScheduler; } 38 38 } 39 private DataAccess.ITransactionManager trans { 40 get { return ServiceLocator.Instance.TransactionManager; } 41 } 39 42 40 43 /// <summary> … … 44 47 public List<MessageContainer> ProcessHeartbeat(Heartbeat heartbeat) { 45 48 List<MessageContainer> actions = new List<MessageContainer>(); 46 Slave slave = dao.GetSlave(heartbeat.SlaveId); 49 Slave slave = null; 50 slave = trans.UseTransaction(() => { return dao.GetSlave(heartbeat.SlaveId); }); 51 47 52 if (slave == null) { 48 53 actions.Add(new MessageContainer(MessageContainer.MessageType.SayHello)); … … 62 67 slave.SlaveState = (heartbeat.JobProgress != null && heartbeat.JobProgress.Count > 0) ? SlaveState.Calculating : SlaveState.Idle; 63 68 slave.LastHeartbeat = DateTime.Now; 64 dao.UpdateSlave(slave); 69 70 trans.UseTransaction(() => { dao.UpdateSlave(slave); }); 65 71 66 72 // update task data … … 76 82 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling could not be aquired."); 77 83 else { 78 var availableTasks = taskScheduler.Schedule(dao.GetWaitingTasks(slave)); 84 IEnumerable<TaskInfoForScheduler> availableTasks = null; 85 availableTasks = trans.UseTransaction(() => { return taskScheduler.Schedule(dao.GetWaitingTasks(slave)); }); 79 86 if (availableTasks.Any()) { 80 87 var task = availableTasks.First(); … … 99 106 100 107 private void AssignJob(Slave slave, Guid taskId) { 101 var task = dao.UpdateTaskState(taskId, DataAccess.TaskState.Transferring, slave.Id, null, null); 108 trans.UseTransaction(() => { 109 var task = dao.UpdateTaskState(taskId, DataAccess.TaskState.Transferring, slave.Id, null, null); 102 110 103 // from now on the task has some time to send the next heartbeat (ApplicationConstants.TransferringJobHeartbeatTimeout) 104 task.LastHeartbeat = DateTime.Now; 105 dao.UpdateTask(task); 111 // from now on the task has some time to send the next heartbeat (ApplicationConstants.TransferringJobHeartbeatTimeout) 112 task.LastHeartbeat = DateTime.Now; 113 dao.UpdateTask(task); 114 }); 106 115 } 107 116 … … 121 130 // process the jobProgresses 122 131 foreach (var jobProgress in heartbeat.JobProgress) { 123 Task curTask = dao.GetTask(jobProgress.Key); 132 Task curTask = null; 133 curTask = trans.UseTransaction(() => { return dao.GetTask(jobProgress.Key); }); 124 134 if (curTask == null) { 125 135 // task does not exist in db … … 150 160 break; 151 161 } 152 dao.UpdateTask(curTask);162 trans.UseTransaction(() => { dao.UpdateTask(curTask); }); 153 163 } 154 164 } … … 159 169 160 170 private bool TaskIsAllowedToBeCalculatedBySlave(Guid slaveId, Task curTask) { 161 var assignedResourceIds = dao.GetAssignedResources(curTask.Id).Select(x => x.Id); 162 var slaveResourceIds = dao.GetParentResources(slaveId).Select(x => x.Id); 163 return assignedResourceIds.Any(x => slaveResourceIds.Contains(x)); 171 return trans.UseTransaction(() => { 172 var assignedResourceIds = dao.GetAssignedResources(curTask.Id).Select(x => x.Id); 173 var slaveResourceIds = dao.GetParentResources(slaveId).Select(x => x.Id); 174 return assignedResourceIds.Any(x => slaveResourceIds.Contains(x)); 175 }); 164 176 } 165 177 166 178 private bool SlaveIsAllowedToCalculate(Guid slaveId) { 167 179 // the slave may only calculate if there is no downtime right now. this needs to be checked for every parent resource also 168 return dao.GetParentResources(slaveId).All(r => dao.GetDowntimes(x => x.ResourceId == r.Id && x.DowntimeType == DA.DowntimeType.Offline && (DateTime.Now >= x.StartDate) && (DateTime.Now <= x.EndDate)).Count() == 0);180 return trans.UseTransaction(() => { return dao.GetParentResources(slaveId).All(r => dao.GetDowntimes(x => x.ResourceId == r.Id && x.DowntimeType == DA.DowntimeType.Offline && (DateTime.Now >= x.StartDate) && (DateTime.Now <= x.EndDate)).Count() == 0); }); 169 181 } 170 182 171 183 private bool ShutdownSlaveComputer(Guid slaveId) { 172 return dao.GetParentResources(slaveId).Any(r => dao.GetDowntimes(x => x.ResourceId == r.Id && x.DowntimeType == DA.DowntimeType.Shutdown && (DateTime.Now >= x.StartDate) && (DateTime.Now <= x.EndDate)).Count() != 0);184 return trans.UseTransaction(() => { return dao.GetParentResources(slaveId).Any(r => dao.GetDowntimes(x => x.ResourceId == r.Id && x.DowntimeType == DA.DowntimeType.Shutdown && (DateTime.Now >= x.StartDate) && (DateTime.Now <= x.EndDate)).Count() != 0); }); 173 185 } 174 186 }
Note: See TracChangeset
for help on using the changeset viewer.