Changeset 6743 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
- Timestamp:
- 09/12/11 18:04:25 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
r6725 r6743 54 54 dao.UpdateSlave(slave); 55 55 56 // update jobdata57 actions.AddRange(Update Jobs(heartbeat, slave.IsAllowedToCalculate));56 // update task data 57 actions.AddRange(UpdateTasks(heartbeat, slave.IsAllowedToCalculate)); 58 58 59 // assign new job59 // assign new task 60 60 if (heartbeat.AssignJob && slave.IsAllowedToCalculate && heartbeat.FreeCores > 0) { 61 var availableJobs = dao.GetWaiting Jobs(slave, 1);61 var availableJobs = dao.GetWaitingTasks(slave, 1); 62 62 if (availableJobs.Count() > 0) { 63 63 var job = availableJobs.First(); … … 71 71 72 72 // returns true if assignment was successful 73 private bool AssignJob(Slave slave, Task job) {74 // load job again and check if it is still available (this is an attempt to reduce the race condition which causes multiple heartbeats to get the same jobassigned)75 if (dao.Get Job(job.Id).State != TaskState.Waiting) return false;73 private bool AssignJob(Slave slave, Task task) { 74 // load task again and check if it is still available (this is an attempt to reduce the race condition which causes multiple heartbeats to get the same task assigned) 75 if (dao.GetTask(task.Id).State != TaskState.Waiting) return false; 76 76 77 job = dao.UpdateJobState(job.Id, DataAccess.TaskState.Transferring, slave.Id, null, null);77 task = dao.UpdateTaskState(task.Id, DataAccess.TaskState.Transferring, slave.Id, null, null); 78 78 79 // from now on the jobhas some time to send the next heartbeat (ApplicationConstants.TransferringJobHeartbeatTimeout)80 job.LastHeartbeat = DateTime.Now;81 dao.Update Job(job);79 // from now on the task has some time to send the next heartbeat (ApplicationConstants.TransferringJobHeartbeatTimeout) 80 task.LastHeartbeat = DateTime.Now; 81 dao.UpdateTask(task); 82 82 return true; 83 83 } 84 84 85 85 /// <summary> 86 /// Update the progress of each job87 /// Checks if all the jobssent by heartbeat are supposed to be calculated by this slave86 /// Update the progress of each task 87 /// Checks if all the task sent by heartbeat are supposed to be calculated by this slave 88 88 /// </summary> 89 private IEnumerable<MessageContainer> Update Jobs(Heartbeat heartbeat, bool IsAllowedToCalculate) {89 private IEnumerable<MessageContainer> UpdateTasks(Heartbeat heartbeat, bool IsAllowedToCalculate) { 90 90 List<MessageContainer> actions = new List<MessageContainer>(); 91 91 … … 98 98 // process the jobProgresses 99 99 foreach (var jobProgress in heartbeat.JobProgress) { 100 Task curJob = dao.Get Job(jobProgress.Key);100 Task curJob = dao.GetTask(jobProgress.Key); 101 101 if (curJob == null) { 102 // jobdoes not exist in db102 // task does not exist in db 103 103 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, jobProgress.Key)); 104 104 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("Job does not exist in DB: " + jobProgress.Key); … … 108 108 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curJob.Id)); 109 109 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not supposed to calculate Job: " + curJob); 110 } else if (! JobIsAllowedToBeCalculatedBySlave(heartbeat.SlaveId, curJob)) {111 // assigned resources ids of jobdo not match with slaveId (and parent resourceGroupIds); this might happen when slave is moved to different group110 } else if (!TaskIsAllowedToBeCalculatedBySlave(heartbeat.SlaveId, curJob)) { 111 // assigned resources ids of task do not match with slaveId (and parent resourceGroupIds); this might happen when slave is moved to different group 112 112 actions.Add(new MessageContainer(MessageContainer.MessageType.PauseTask, curJob.Id)); 113 113 } else { 114 // save jobexecution time114 // save task execution time 115 115 curJob.ExecutionTime = jobProgress.Value; 116 116 curJob.LastHeartbeat = DateTime.Now; … … 127 127 break; 128 128 } 129 dao.Update Job(curJob);129 dao.UpdateTask(curJob); 130 130 } 131 131 } … … 135 135 } 136 136 137 private bool JobIsAllowedToBeCalculatedBySlave(Guid slaveId, Task curJob) {138 var assignedResourceIds = dao.GetAssignedResources(cur Job.Id).Select(x => x.Id);137 private bool TaskIsAllowedToBeCalculatedBySlave(Guid slaveId, Task curTask) { 138 var assignedResourceIds = dao.GetAssignedResources(curTask.Id).Select(x => x.Id); 139 139 var slaveResourceIds = dao.GetParentResources(slaveId).Select(x => x.Id); 140 140 return assignedResourceIds.Any(x => slaveResourceIds.Contains(x));
Note: See TracChangeset
for help on using the changeset viewer.