- Timestamp:
- 01/18/18 15:08:25 (7 years ago)
- Location:
- branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Converter.cs
r15628 r15630 121 121 OwnerUserId = source.OwnerUserId, 122 122 DateCreated = source.DateCreated, 123 ProjectId = source.ProjectId 123 ProjectId = source.ProjectId, 124 State = source.State.ToDto() 124 125 }; 125 126 } … … 140 141 target.DateCreated = source.DateCreated; 141 142 target.ProjectId = source.ProjectId; 143 target.State = source.State.ToEntity(); 142 144 } 143 145 #endregion … … 242 244 #endregion 243 245 244 #region State246 #region TaskState 245 247 public static DT.TaskState ToDto(this DA.TaskState source) { 246 248 switch (source) { … … 268 270 case DT.TaskState.Waiting: return DA.TaskState.Waiting; 269 271 default: return DA.TaskState.Failed; 272 } 273 } 274 #endregion 275 276 #region JobState 277 public static DT.JobState ToDto(this DA.JobState source) { 278 switch (source) { 279 case DA.JobState.Online: return DT.JobState.Online; 280 case DA.JobState.StatisticsPending: return DT.JobState.StatisticsPending; 281 case DA.JobState.DeletionPending: return DT.JobState.DeletionPending; 282 default: return DT.JobState.Online; 283 } 284 } 285 286 public static DA.JobState ToEntity(this DT.JobState source) { 287 switch (source) { 288 case DT.JobState.Online: return DA.JobState.Online; 289 case DT.JobState.StatisticsPending: return DA.JobState.StatisticsPending; 290 case DT.JobState.DeletionPending: return DA.JobState.DeletionPending; 291 default: return DA.JobState.Online; 270 292 } 271 293 } -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/DataTransfer/Job.cs
r15399 r15630 37 37 [DataMember] 38 38 public string OwnerUsername { get; set; } 39 [DataMember] 40 public JobState State { get; set; } 39 41 40 42 /* ==== some computed statistics ==== */ -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
r15628 r15630 122 122 <Compile Include="DataTransfer\AssignedProjectResource.cs" /> 123 123 <Compile Include="DataTransfer\Command.cs" /> 124 <Compile Include="DataTransfer\JobState.cs" /> 124 125 <Compile Include="DataTransfer\Project.cs" /> 125 126 <Compile Include="DataTransfer\ProjectPermission.cs" /> -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r15628 r15630 361 361 return pm.UseTransaction(() => { 362 362 var jobs = jobDao.GetAll() 363 .Where(x => x.OwnerUserId == currentUserId 364 || x.JobPermissions.Count(y => y.Permission != DA.Permission.NotAllowed 365 && y.GrantedUserId == currentUserId) > 0) 363 .Where(x => x.State == DA.JobState.Online 364 && (x.OwnerUserId == currentUserId 365 || x.JobPermissions.Count(y => y.Permission != DA.Permission.NotAllowed 366 && y.GrantedUserId == currentUserId) > 0) 367 ) 366 368 .Select(x => x.ToDto()) 367 369 .ToList(); … … 524 526 } 525 527 526 public void DeleteJob(Guid jobId) {528 public void UpdateJobState(Guid jobId, DT.JobState jobState) { 527 529 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 528 530 AuthorizationManager.AuthorizeForJob(jobId, DT.Permission.Full); 529 531 var pm = PersistenceManager; 530 using (new PerformanceLogger(" DeleteJob")) {532 using (new PerformanceLogger("UpdateJobState")) { 531 533 var jobDao = pm.JobDao; 532 534 pm.UseTransaction(() => { 533 // not necessary anymore: child tasks will be deleted by db-trigger 534 // now: tasks are deleted by jobId 535 // entries in AssignedJobResource will be deleted by foreign key clause CASCADE ON DELETE 536 jobDao.Delete(jobId); 537 pm.SubmitChanges(); 535 var job = jobDao.GetById(jobId); 536 if(job != null) { 537 var jobStateEntity = jobState.ToEntity(); 538 // note: allow solely state changes from "Online" to "StatisticsPending" 539 // and from "StatisticsPending" to "DeletionPending" 540 if (job.State == DA.JobState.Online && jobStateEntity == DA.JobState.StatisticsPending) { 541 job.State = jobStateEntity; 542 foreach(var task in job.Tasks 543 .Where(x => x.State == DA.TaskState.Waiting 544 || x.State == DA.TaskState.Paused 545 || x.State == DA.TaskState.Offline)) { 546 task.State = DA.TaskState.Aborted; 547 } 548 pm.SubmitChanges(); 549 } else if(job.State == DA.JobState.StatisticsPending && jobStateEntity == DA.JobState.DeletionPending) { 550 job.State = jobStateEntity; 551 pm.SubmitChanges(); 552 } 553 } 538 554 }); 539 555 } -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/EventManager.cs
r14185 r15630 34 34 public void Cleanup() { 35 35 var pm = PersistenceManager; 36 37 pm.UseTransaction(() => { 38 FinishJobDeletion(pm); 39 pm.SubmitChanges(); 40 }); 41 36 42 pm.UseTransaction(() => { 37 43 SetTimeoutSlavesOffline(pm); … … 45 51 pm.SubmitChanges(); 46 52 }); 53 } 54 55 /// <summary> 56 /// Deletes all jobs which are in state "DeletionPending" (this will include all corresponding tasks). 57 /// The state "DeletionPending" is set by HiveJanitor > StatisticsGenerator 58 /// </summary> 59 private void FinishJobDeletion(IPersistenceManager pm) { 60 var jobDao = pm.JobDao; 61 jobDao.DeleteByState(JobState.DeletionPending); 47 62 } 48 63 -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
r15411 r15630 141 141 /// </summary> 142 142 private IEnumerable<MessageContainer> UpdateTasks(IPersistenceManager pm, Heartbeat heartbeat, bool isAllowedToCalculate) { 143 var taskDao = pm.TaskDao; 144 var jobDao = pm.JobDao; 145 var assignedJobResourceDao = pm.AssignedJobResourceDao; 146 var actions = new List<MessageContainer>(); 147 if (heartbeat.JobProgress == null || !heartbeat.JobProgress.Any()) 148 return actions; 149 150 var jobIdsWithStatisticsPending = jobDao.GetJobIdsByState(DA.JobState.StatisticsPending).ToList(); 151 152 // select all tasks and statelogs with one query 153 var taskIds = heartbeat.JobProgress.Select(x => x.Key).ToList(); 154 var taskInfos = pm.UseTransaction(() => 155 (from task in taskDao.GetAll() 156 where taskIds.Contains(task.TaskId) 157 let lastStateLog = task.StateLogs.OrderByDescending(x => x.DateTime).FirstOrDefault() 158 select new { 159 TaskId = task.TaskId, 160 JobId = task.JobId, 161 State = task.State, 162 Command = task.Command, 163 SlaveId = lastStateLog != null ? lastStateLog.SlaveId : default(Guid) 164 }).ToList() 165 ); 166 167 // process the jobProgresses 168 foreach (var jobProgress in heartbeat.JobProgress) { 169 var progress = jobProgress; 170 var curTask = taskInfos.SingleOrDefault(x => x.TaskId == progress.Key); 171 if (curTask == null) { 172 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, progress.Key)); 173 LogFactory.GetLogger(this.GetType().Namespace).Log("Task on slave " + heartbeat.SlaveId + " does not exist in DB: " + jobProgress.Key); 174 } else if (jobIdsWithStatisticsPending.Contains(curTask.JobId)) { 175 // parenting job of current task has been requested for deletion (indicated by job state "Statistics Pending") 176 // update task execution time 177 pm.UseTransaction(() => { 178 taskDao.UpdateExecutionTime(curTask.TaskId, progress.Value.TotalMilliseconds); 179 }); 180 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curTask.TaskId)); 181 LogFactory.GetLogger(this.GetType().Namespace).Log("Abort task " + curTask.TaskId + " on slave " + heartbeat.SlaveId + ". The parenting job " + curTask.JobId + " was requested to be deleted."); 182 } else if (curTask.SlaveId == Guid.Empty || curTask.SlaveId != heartbeat.SlaveId) { 183 // assigned slave does not match heartbeat 184 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curTask.TaskId)); 185 LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not supposed to calculate task: " + curTask.TaskId); 186 } else if (!isAllowedToCalculate) { 187 actions.Add(new MessageContainer(MessageContainer.MessageType.PauseTask, curTask.TaskId)); 188 LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not allowed to calculate any tasks tue to a downtime. The task is paused."); 189 } else if (assignedJobResourceDao.CheckJobGrantedForResource(curTask.JobId, heartbeat.SlaveId)) { 190 // assigned resources ids of task do not match with slaveId (and parent resourceGroupIds); this might happen when slave is moved to different group 191 actions.Add(new MessageContainer(MessageContainer.MessageType.PauseTask, curTask.TaskId)); 192 LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not granted to calculate task: " + curTask.TaskId); 193 } else { 194 // update task execution time 195 pm.UseTransaction(() => { 196 taskDao.UpdateExecutionTime(curTask.TaskId, progress.Value.TotalMilliseconds); 197 }); 198 switch (curTask.Command) { 199 case DA.Command.Stop: 200 actions.Add(new MessageContainer(MessageContainer.MessageType.StopTask, curTask.TaskId)); 201 break; 202 case DA.Command.Pause: 203 actions.Add(new MessageContainer(MessageContainer.MessageType.PauseTask, curTask.TaskId)); 204 break; 205 case DA.Command.Abort: 206 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curTask.TaskId)); 207 break; 208 } 209 } 210 211 } 212 return actions; 213 } 214 215 /// <summary> 216 /// Update the progress of each task 217 /// Checks if all the task sent by heartbeat are supposed to be calculated by this slave 218 /// </summary> 219 private IEnumerable<MessageContainer> UpdateTasks_Old(IPersistenceManager pm, Heartbeat heartbeat, bool isAllowedToCalculate) { 143 220 var taskDao = pm.TaskDao; 144 221 var assignedResourceDao = pm.AssignedTaskResourceDao; -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs
r15628 r15630 93 93 94 94 [OperationContract] 95 void DeleteJob(Guid JobId);95 void UpdateJobState(Guid JobId, JobState jobState); 96 96 97 97 [OperationContract]
Note: See TracChangeset
for help on using the changeset viewer.