Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17575


Ignore:
Timestamp:
05/29/20 13:31:30 (4 years ago)
Author:
jkarder
Message:

#3072: fixed statelog updates

  • fixed UpdateTasks so that it selects the correct last slave id for a specified task
  • introduced check if a slave is allowed to update a task's state (IsAuthorizedForTask)
Location:
trunk/HeuristicLab.Services.Hive/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r17376 r17575  
    209209    }
    210210
     211    private bool IsAuthorizedForTask(DA.Task task, Guid? slaveId) {
     212      var lastStateLog = task.StateLogs.OrderByDescending(x => x.DateTime).FirstOrDefault(x => x.State == DA.TaskState.Transferring);
     213      return lastStateLog == null || slaveId == null || lastStateLog.SlaveId == slaveId;
     214    }
     215
    211216    public DT.Task UpdateTaskState(Guid taskId, DT.TaskState taskState, Guid? slaveId, Guid? userId, string exception) {
    212217      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
     
    217222        return pm.UseTransaction(() => {
    218223          var task = taskDao.GetById(taskId);
    219           UpdateTaskState(pm, task, taskState, slaveId, userId, exception);
    220           pm.SubmitChanges();
     224          if (IsAuthorizedForTask(task, slaveId)) {
     225            UpdateTaskState(pm, task, taskState, slaveId, userId, exception);
     226            pm.SubmitChanges();
     227          }
    221228          return task.ToDto();
    222229        });
  • trunk/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs

    r17574 r17575  
    120120      var taskInfos = pm.UseTransaction(() =>
    121121        (from task in taskDao.GetAll()
    122           where taskIds.Contains(task.TaskId)
    123           let lastStateLog = task.StateLogs.OrderByDescending(x => x.DateTime).FirstOrDefault()
    124           select new {
    125             TaskId = task.TaskId,
    126             JobId = task.JobId,
    127             State = task.State,
    128             Command = task.Command,
    129             SlaveId = lastStateLog != null ? lastStateLog.SlaveId : default(Guid)
    130           }).ToList()
     122         where taskIds.Contains(task.TaskId)
     123         let lastStateLog = task.StateLogs.OrderByDescending(x => x.DateTime).FirstOrDefault(x => x.State == DA.TaskState.Transferring)
     124         select new {
     125           TaskId = task.TaskId,
     126           JobId = task.JobId,
     127           State = task.State,
     128           Command = task.Command,
     129           SlaveId = lastStateLog != null ? lastStateLog.SlaveId : Guid.Empty
     130         }).ToList()
    131131      );
    132132
Note: See TracChangeset for help on using the changeset viewer.