Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/03/18 15:06:21 (6 years ago)
Author:
jzenisek
Message:

#2839:

  • adapted job execution implementation at ProjectJobsView
  • prohibited resource checking for non-admins
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs

    r16208 r16209  
    8080    }
    8181
     82    private Dictionary<Guid, List<LightweightTask>> tasks;
     83    public Dictionary<Guid, List<LightweightTask>> Tasks {
     84      get { return tasks; }
     85    }
     86
    8287    private Dictionary<Guid, HashSet<Guid>> projectAncestors;
    8388    public Dictionary<Guid, HashSet<Guid>> ProjectAncestors {
     
    145150        projectResourceAssignments = new ItemList<AssignedProjectResource>();
    146151        jobs = new Dictionary<Guid, HiveItemCollection<RefreshableJob>>();
     152        tasks = new Dictionary<Guid, List<LightweightTask>>();
    147153        projectNames = new Dictionary<Guid, string>();
    148154        resourceNames = new Dictionary<Guid, string>();
     
    311317      var projectIds = new List<Guid>();
    312318      jobs = new Dictionary<Guid, HiveItemCollection<RefreshableJob>>();
     319      tasks = new Dictionary<Guid, List<LightweightTask>>();
    313320
    314321      HiveServiceLocator.Instance.CallHiveService(service => {
     
    329336    }
    330337
    331     public static void LoadLightweightJob(RefreshableJob refreshableJob) {
     338    public void LoadLightweightJob(RefreshableJob refreshableJob) {
    332339      var job = refreshableJob.Job;
    333       var tasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(job.Id));
    334       if (tasks != null && tasks.Count > 0 && tasks.All(x => x.Id != Guid.Empty)) {
    335         if (tasks.All(x =>
     340      var lightweightTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(job.Id));
     341
     342      if (tasks.ContainsKey(job.Id)) {
     343        tasks[job.Id].Clear();
     344        tasks[job.Id].AddRange(lightweightTasks);
     345      } else {
     346        tasks.Add(job.Id, new List<LightweightTask>(lightweightTasks));       
     347      }
     348
     349      if (lightweightTasks != null && lightweightTasks.Count > 0 && lightweightTasks.All(x => x.Id != Guid.Empty)) {
     350        if (lightweightTasks.All(x =>
    336351          x.State == TaskState.Finished
    337352          || x.State == TaskState.Aborted
     
    340355          refreshableJob.RefreshAutomatically = false;
    341356        } else if (
    342           tasks
     357          lightweightTasks
    343358            .Where(x => x.ParentTaskId != null)
    344359            .All(x =>
     
    346361              || x.State != TaskState.Transferring
    347362              || x.State != TaskState.Calculating)
    348           && tasks
     363          && lightweightTasks
    349364             .Where(x => x.ParentTaskId != null)
    350365             .Any(x => x.State == TaskState.Paused)) {
    351366          refreshableJob.ExecutionState = ExecutionState.Paused;
    352367          refreshableJob.RefreshAutomatically = false;
    353         } else if (tasks.Any(x => x.State == TaskState.Calculating
     368        } else if (lightweightTasks.Any(x => x.State == TaskState.Calculating
    354369                                  || x.State == TaskState.Transferring
    355370                                  || x.State == TaskState.Waiting)) {
    356371          refreshableJob.ExecutionState = ExecutionState.Started;
    357372        }
     373
     374        refreshableJob.ExecutionTime = TimeSpan.FromMilliseconds(lightweightTasks.Sum(x => x.ExecutionTime.TotalMilliseconds));
    358375      }
    359376    }
     
    451468    public static void ResumeJob(RefreshableJob refreshableJob) {
    452469      HiveServiceLocator.Instance.CallHiveService(service => {
    453         foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) {
    454           if (task.Task.State == TaskState.Paused) {
    455             service.RestartTask(task.Task.Id);
     470        var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id);
     471        foreach (var task in tasks) {
     472          if (task.State == TaskState.Paused) {
     473            service.RestartTask(task.Id);
    456474          }
    457475        }
     
    462480    public static void PauseJob(RefreshableJob refreshableJob) {
    463481      HiveServiceLocator.Instance.CallHiveService(service => {
    464         foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) {
    465           if (task.Task.State != TaskState.Finished && task.Task.State != TaskState.Aborted && task.Task.State != TaskState.Failed)
    466             service.PauseTask(task.Task.Id);
     482        var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id);
     483        foreach (var task in tasks) {
     484          if (task.State != TaskState.Finished && task.State != TaskState.Aborted && task.State != TaskState.Failed)
     485            service.PauseTask(task.Id);
    467486        }
    468487      });
     
    472491    public static void StopJob(RefreshableJob refreshableJob) {
    473492      HiveServiceLocator.Instance.CallHiveService(service => {
    474         foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) {
    475           if (task.Task.State != TaskState.Finished && task.Task.State != TaskState.Aborted && task.Task.State != TaskState.Failed)
    476             service.StopTask(task.Task.Id);
     493        var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id);
     494        foreach (var task in tasks) {
     495          if (task.State != TaskState.Finished && task.State != TaskState.Aborted && task.State != TaskState.Failed)
     496            service.StopTask(task.Id);
    477497        }
    478498      });
     
    481501
    482502    public static void RemoveJob(RefreshableJob refreshableJob) {
    483       HiveServiceLocator.Instance.CallHiveService((s) => {
    484         s.UpdateJobState(refreshableJob.Id, JobState.StatisticsPending);
     503      HiveServiceLocator.Instance.CallHiveService((service) => {
     504        service.UpdateJobState(refreshableJob.Id, JobState.StatisticsPending);
    485505      });
    486506    }
     
    624644    }
    625645
     646    public IEnumerable<Resource> GetAssignedResourcesForJob(Guid jobId) {
     647      var assignedJobResource =  HiveServiceLocator.Instance.CallHiveService(service => service.GetAssignedResourcesForJob(jobId));
     648      return Resources.Where(x => assignedJobResource.Select(y => y.ResourceId).Contains(x.Id));
     649    }
     650
    626651    private bool IsAdmin() {
    627652      return HiveRoles.CheckAdminUserPermissions();
Note: See TracChangeset for help on using the changeset viewer.