Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15969


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

#2839: finalized ProjectJobsView

Location:
branches/2839_HiveProjectManagement
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectJobsView.cs

    r15966 r15969  
    3030using HeuristicLab.Data.Views;
    3131using HeuristicLab.Data;
     32using HeuristicLab.Clients.Hive.Views;
    3233
    3334namespace HeuristicLab.Clients.Hive.Administrator.Views {
     
    3839    private const string JOB_NAME = "Name";
    3940    private const string JOB_OWNER = "Owner";
     41    private const string JOB_OWNERID = "Owner Id";
    4042    private const string JOB_DATECREATED = "Date Created";
    4143    private const string JOB_STATE = "State";
    4244    private const string JOB_DESCRIPTION = "Description";
     45    private const string JOB_TASKCOUNT = "Tasks";
     46    private const string JOB_CALCULATINGTASKCOUNT = "Calculating";
     47    private const string JOB_FINISHEDTASKCOUNT = "Finished";
     48
     49
     50    private readonly Color onlineStatusColor = Color.FromArgb(255, 189, 249, 143); // #bdf98f
     51    private readonly Color onlineStatusColor2 = Color.FromArgb(255, 157, 249, 143); // #9df98f
     52    private readonly Color statisticsPendingStatusColor = Color.FromArgb(255, 249, 210, 145); // #f9d291
     53    private readonly Color deletionPendingStatusColor = Color.FromArgb(255, 249, 172, 144); // #f9ac90
     54    private readonly Color deletionPendingStatusColor2 = Color.FromArgb(255, 249, 149, 143); // #f9958f
    4355
    4456    public new Project Content {
     
    4759    }
    4860
    49     public ProjectJobsView() /*: base()*/ {
     61    public ProjectJobsView() {
    5062      InitializeComponent();
     63
     64      removeButton.Enabled = false;
     65      matrixView.DataGridView.SelectionChanged += DataGridView_SelectionChanged;
     66    }
     67
     68    private void DataGridView_SelectionChanged(object sender, EventArgs e) {
     69      if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return;
     70
     71      bool anyDeletable = false;
     72      foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) {
     73        if (((string)r.Cells[0].Value) == JobState.Online.ToString()) anyDeletable = true;
     74      }
     75
     76      removeButton.Enabled = anyDeletable;
    5177    }
    5278
     
    5480    protected override void OnContentChanged() {
    5581      base.OnContentChanged();
     82      removeButton.Enabled = false;
    5683      UpdateJobs();
    5784    }
     
    6188
    6289      refreshButton.Enabled = enabled;
    63       removeButton.Enabled = enabled;
     90      removeButton.Enabled = false;
    6491      matrixView.Enabled = enabled;
    6592    }
     
    7299
    73100    private void refreshButton_Click(object sender, EventArgs e) {
    74       HiveAdminClient.Instance.Refresh();
    75       // Update list/matrix
     101      RefreshJobs();
    76102    }
    77103
    78104    private async void removeButton_Click(object sender, EventArgs e) {
    79       // remove selected job(s)
     105      if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return;
     106
     107      var jobNamesToDelete = new List<string>();
     108      var jobIdsToDelete = new List<Guid>();
     109      foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) {
     110        if(((string)r.Cells[0].Value) == JobState.Online.ToString()) {
     111          jobNamesToDelete.Add(" - " + ((string)r.Cells[3].Value));
     112          jobIdsToDelete.Add(Guid.Parse((string)r.Cells[8].Value));
     113        }
     114      }
     115
     116      if(jobIdsToDelete.Any()) {
     117        var result = MessageBox.Show("Do you really want to remove following job(s):\n\n"
     118          + String.Join("\n", jobNamesToDelete),
     119          "HeuristicLab Hive Administrator",
     120          MessageBoxButtons.YesNo,
     121          MessageBoxIcon.Question);
     122
     123        if (result == DialogResult.Yes) {
     124          await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     125            action: () => {
     126              DeleteJobs(jobIdsToDelete);
     127            },
     128            finallyCallback: () => {
     129              matrixView.DataGridView.ClearSelection();
     130              removeButton.Enabled = false;
     131              RefreshJobs();
     132            });
     133        }
     134      }
    80135    }
    81136
     
    83138
    84139    #region Helpers
     140    private void RefreshJobs() {
     141      HiveAdminClient.Instance.RefreshJobs();
     142      UpdateJobs();
     143    }
     144
    85145    private StringMatrix CreateValueMatrix() {
    86146      var jobs = HiveAdminClient.Instance.Jobs[Content.Id];
    87       string[,] values = new string[jobs.Count, 7];
     147      var resources = HiveAdminClient.Instance.Resources;
     148      string[,] values = new string[jobs.Count, 10];
    88149
    89150      for(int i = 0; i < jobs.Count; i++) {
    90151        var job = jobs.ElementAt(i);
    91         values[i, 0] = job.Id.ToString();
    92         values[i, 1] = job.Name;
    93         values[i, 2] = job.OwnerUserId.ToString();
    94         values[i, 3] = job.OwnerUsername;
    95         values[i, 4] = job.DateCreated.ToString();
    96         values[i, 5] = job.State.ToString();
    97         values[i, 6] = job.Description;
    98       }
    99 
     152       
     153        values[i, 0] = job.State.ToString();
     154        values[i, 1] = job.DateCreated.ToString();
     155        values[i, 2] = job.OwnerUsername;
     156        values[i, 3] = job.Name;
     157        values[i, 4] = job.JobCount.ToString();
     158        values[i, 5] = job.CalculatingCount.ToString();
     159        values[i, 6] = job.FinishedCount.ToString();
     160        values[i, 7] = job.Description;       
     161        values[i, 8] = job.Id.ToString();
     162        values[i, 9] = job.OwnerUserId.ToString();
     163      }
     164     
    100165      var matrix = new StringMatrix(values);
    101       matrix.ColumnNames = new string[] { JOB_ID, JOB_NAME, JOB_OWNER, JOB_OWNER, JOB_DATECREATED, JOB_STATE, JOB_DESCRIPTION };
     166      matrix.ColumnNames = new string[] { JOB_STATE, JOB_DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID };
    102167      matrix.SortableView = true;
    103168      return matrix;
    104169    }
    105 
     170   
    106171    private void UpdateJobs() {
    107172      if (InvokeRequired) Invoke((Action)UpdateJobs);
     
    115180        }
    116181        matrixView.Content = matrix;
     182       
     183        foreach(DataGridViewRow row in matrixView.DataGridView.Rows) {
     184          string val = ((string)row.Cells[0].Value);
     185          if (val == JobState.Online.ToString()) {
     186            row.DefaultCellStyle.BackColor = onlineStatusColor;
     187          } else if(val == JobState.StatisticsPending.ToString()) {
     188            row.DefaultCellStyle.BackColor = statisticsPendingStatusColor;
     189          } else if(val == JobState.DeletionPending.ToString()) {
     190            row.DefaultCellStyle.BackColor = deletionPendingStatusColor;
     191          }
     192        }
     193
    117194        matrixView.DataGridView.AutoResizeColumns();
    118         //foreach(DataGridViewColumn col in matrixView.DataGridView.Columns) {
    119         //  col.Width = -2;
    120         //}
     195        matrixView.DataGridView.Columns[0].MinimumWidth = 90;
     196        matrixView.DataGridView.Columns[1].MinimumWidth = 108;
     197      }
     198    }
     199
     200    private void DeleteJobs(List<Guid> jobIds) {
     201      try {
     202        HiveAdminClient.DeleteJobs(jobIds);
     203      } catch (AnonymousUserException) {
     204        ShowHiveInformationDialog();
     205      }
     206    }
     207
     208    private void ShowHiveInformationDialog() {
     209      if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog);
     210      else {
     211        using (HiveInformationDialog dialog = new HiveInformationDialog()) {
     212          dialog.ShowDialog(this);
     213        }
    121214      }
    122215    }
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs

    r15966 r15969  
    7979    }
    8080
    81 
    82     //private Dictionary<Guid, HashSet<Project>> projectAncestors;
    83     //public Dictionary<Guid, HashSet<Project>> ProjectAncestors {
    84     //  get { return projectAncestors; }
    85     //}
    86 
    87     //private Dictionary<Guid, HashSet<Project>> projectDescendants;
    88     //public Dictionary<Guid, HashSet<Project>> ProjectDescendants {
    89     //  get { return projectDescendants; }
    90     //}
    91 
    92     //private Dictionary<Guid, HashSet<Resource>> resourceAncestors;
    93     //public Dictionary<Guid, HashSet<Resource>> ResourceAncestors {
    94     //  get { return resourceAncestors; }
    95     //}
    96 
    97     //private Dictionary<Guid, HashSet<Resource>> resourceDescendants;
    98     //public Dictionary<Guid, HashSet<Resource>> ResourceDescendants {
    99     //  get { return resourceDescendants; }
    100     //}
    101 
    10281    private Dictionary<Guid, HashSet<Guid>> projectAncestors;
    10382    public Dictionary<Guid, HashSet<Guid>> ProjectAncestors {
     
    160139              .ForEach(a => projectResourceAssignments.Add(a));
    161140            projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection<Job>()));
    162             service.GetJobsByProjectIds(projectIds)
    163               .ForEach(j => jobs[j.ProjectId].Add(j));
     141            var unsortedJobs = service.GetJobsByProjectIds(projectIds)
     142              .OrderBy(x => x.DateCreated).ToList();
     143           
     144            unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j));
     145            unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j));
     146            unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(j));
    164147          }
    165148        });
     
    264247    }
    265248
     249    public void RefreshJobs() {
     250      var projectIds = new List<Guid>();
     251      jobs = new Dictionary<Guid, HiveItemCollection<Job>>();
     252
     253      HiveServiceLocator.Instance.CallHiveService(service => {
     254        service.GetProjectsForAdministration().ForEach(p => projectIds.Add(p.Id));
     255        if(projectIds.Any()) {
     256          projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection<Job>()));
     257          var unsortedJobs = service.GetJobsByProjectIds(projectIds)
     258            .OrderBy(x => x.DateCreated).ToList();
     259          unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j));
     260          unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j));
     261          unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(j));
     262        }
     263      });
     264    }
     265
     266    public void SortJobs() {
     267      for(int i = 0; i < jobs.Count; i++) {
     268        var projectId = jobs.Keys.ElementAt(i);
     269        var unsortedJobs = jobs.Values.ElementAt(i);
     270
     271        var sortedJobs = new HiveItemCollection<Job>();
     272        sortedJobs.AddRange(unsortedJobs.Where(j => j.State == JobState.DeletionPending));
     273        sortedJobs.AddRange(unsortedJobs.Where(j => j.State == JobState.StatisticsPending));
     274        sortedJobs.AddRange(unsortedJobs.Where(j => j.State == JobState.Online));
     275
     276        jobs[projectId] = sortedJobs;
     277      }
     278    }
     279
    266280    #endregion
    267281
     
    331345        HiveServiceLocator.Instance.CallHiveService((s) => s.DeleteProject(item.Id));
    332346      }
     347    }
     348
     349    public static void DeleteJobs(List<Guid> jobIds) {
     350
     351      HiveServiceLocator.Instance.CallHiveService((s) => s.UpdateJobStates(jobIds, JobState.StatisticsPending));
    333352    }
    334353    #endregion
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveServiceClient.cs

    r15966 r15969  
    7575       
    7676        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    77        
     77
    7878    }
    7979   
     
    24002400        void UpdateJobState(System.Guid JobId, HeuristicLab.Clients.Hive.JobState jobState);
    24012401       
     2402        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/UpdateJobStates", ReplyAction="http://tempuri.org/IHiveService/UpdateJobStatesResponse")]
     2403        void UpdateJobStates(System.Collections.Generic.List<System.Guid> jobIds, HeuristicLab.Clients.Hive.JobState jobState);
     2404       
    24022405        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetAssignedResourcesForJob", ReplyAction="http://tempuri.org/IHiveService/GetAssignedResourcesForJobResponse")]
    24032406        System.Collections.Generic.List<HeuristicLab.Clients.Hive.AssignedJobResource> GetAssignedResourcesForJob(System.Guid jobId);
     
    26862689        }
    26872690       
     2691        public void UpdateJobStates(System.Collections.Generic.List<System.Guid> jobIds, HeuristicLab.Clients.Hive.JobState jobState)
     2692        {
     2693            base.Channel.UpdateJobStates(jobIds, jobState);
     2694        }
     2695       
    26882696        public System.Collections.Generic.List<HeuristicLab.Clients.Hive.AssignedJobResource> GetAssignedResourcesForJob(System.Guid jobId)
    26892697        {
  • branches/2839_HiveProjectManagement/HeuristicLab.Services.Access/3.3/UserManager.cs

    r15577 r15969  
    4646    public string GetUserNameById(Guid userId) {
    4747      var user = GetUserById(userId);
    48       if (user != null) {
     48      if (user != null && !string.IsNullOrWhiteSpace(user.UserName)) {
    4949        return user.UserName;
    5050      } else {
  • branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15966 r15969  
    336336            .Select(x => x.ToDto())
    337337            .ToList();
    338           var statistics = taskDao.GetAll()
    339               .Where(x => jobs.Select(y => y.Id).Contains(x.JobId))
    340               .GroupBy(x => x.JobId)
    341               .Select(x => new {
    342                 x.Key,
    343                 TotalCount = x.Count(),
    344                 CalculatingCount = x.Count(y => y.State == DA.TaskState.Calculating),
    345                 FinishedCount = x.Count(y => CompletedStates.Contains(y.State))
    346               })
    347               .ToList();
    348           foreach (var job in jobs) {
    349             var statistic = statistics.FirstOrDefault(x => x.Key == job.Id);
    350             if (statistic != null) {
    351               job.JobCount = statistic.TotalCount;
    352               job.CalculatingCount = statistic.CalculatingCount;
    353               job.FinishedCount = statistic.FinishedCount;
    354             }
    355             job.OwnerUsername = UserManager.GetUserNameById(job.OwnerUserId);
    356             if (currentUserId == job.OwnerUserId) {
    357               job.Permission = Permission.Full;
    358             } else {
    359               var jobPermission = jobPermissionDao.GetByJobAndUserId(job.Id, currentUserId);
    360               job.Permission = jobPermission == null ? Permission.NotAllowed : jobPermission.Permission.ToDto();
    361             }
    362           }
     338
     339          EvaluateJobs(pm, jobs);
    363340          return jobs;
    364341        });
     
    381358
    382359          if(administrationGrantedProjects.Select(x => x.ProjectId).Contains(projectId)) {
    383             return jobDao.GetByProjectId(projectId)
     360            var jobs = jobDao.GetByProjectId(projectId)
    384361            .Select(x => x.ToDto())
    385362            .ToList();
     363
     364            EvaluateJobs(pm, jobs);
     365            return jobs;
    386366          } else {
    387367            return Enumerable.Empty<DT.Job>();
     
    407387
    408388          if(requestedAndGrantedProjectIds.Any()) {
    409             return jobDao.GetByProjectIds(requestedAndGrantedProjectIds)
     389            var jobs = jobDao.GetByProjectIds(requestedAndGrantedProjectIds)
    410390              .Select(x => x.ToDto())
    411391              .ToList();
     392
     393            EvaluateJobs(pm, jobs);
     394            return jobs;
    412395          } else {
    413396            return Enumerable.Empty<DT.Job>();
     
    548531    }
    549532
     533    public void UpdateJobStates(IEnumerable<Guid> jobIds, DT.JobState jobState) {
     534      if (jobState != JobState.StatisticsPending) return; // only process requests for "StatisticsPending"
     535
     536      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     537      bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
     538      var currentUserId = UserManager.CurrentUserId;
     539
     540      var pm = PersistenceManager;
     541      using (new PerformanceLogger("UpdateJobsState")) {
     542        var jobDao = pm.JobDao;
     543        var projectDao = pm.ProjectDao;
     544        pm.UseTransaction(() => {
     545          foreach(var jobId in jobIds) {
     546            var job = jobDao.GetById(jobId);
     547            if (job != null) {
     548
     549              var administrationGrantedProjects = projectDao
     550                .GetAdministrationGrantedProjectsForUser(currentUserId)
     551                .ToList();
     552
     553              // check if user is granted to administer the job-parenting project
     554              if (isAdministrator || administrationGrantedProjects.Contains(job.Project)) {
     555                // note: allow solely state changes from "Online" to "StatisticsPending" = deletion request by user for HiveStatisticGenerator
     556                if (job.State == DA.JobState.Online) {
     557                  job.State = DA.JobState.StatisticsPending;
     558                  foreach (var task in job.Tasks
     559                  .Where(x => x.State == DA.TaskState.Waiting
     560                    || x.State == DA.TaskState.Paused
     561                    || x.State == DA.TaskState.Offline)) {
     562                      task.State = DA.TaskState.Aborted;
     563                  }
     564                  pm.SubmitChanges();
     565                }
     566              }
     567            }
     568          }
     569        });
     570      }
     571    }
     572
    550573    public IEnumerable<DT.AssignedJobResource> GetAssignedResourcesForJob(Guid jobId) {
    551574      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     
    17381761    }
    17391762
     1763    private void EvaluateJobs(IPersistenceManager pm, IEnumerable<DT.Job> jobs) {
     1764      if (jobs == null || !jobs.Any()) return;
     1765
     1766      var currentUserId = UserManager.CurrentUserId;     
     1767      var taskDao = pm.TaskDao;
     1768      var jobPermissionDao = pm.JobPermissionDao;
     1769
     1770      var statistics = taskDao.GetAll()
     1771        .Where(x => jobs.Select(y => y.Id).Contains(x.JobId))
     1772        .GroupBy(x => x.JobId)
     1773        .Select(x => new {
     1774          x.Key,
     1775          TotalCount = x.Count(),
     1776          CalculatingCount = x.Count(y => y.State == DA.TaskState.Calculating),
     1777          FinishedCount = x.Count(y => CompletedStates.Contains(y.State))
     1778        })
     1779        .ToList();
     1780
     1781      foreach (var job in jobs) {
     1782        var statistic = statistics.FirstOrDefault(x => x.Key == job.Id);
     1783        if (statistic != null) {
     1784          job.JobCount = statistic.TotalCount;
     1785          job.CalculatingCount = statistic.CalculatingCount;
     1786          job.FinishedCount = statistic.FinishedCount;
     1787        }
     1788
     1789        job.OwnerUsername = UserManager.GetUserNameById(job.OwnerUserId);
     1790
     1791        if (currentUserId == job.OwnerUserId) {
     1792          job.Permission = Permission.Full;
     1793        } else {
     1794          var jobPermission = jobPermissionDao.GetByJobAndUserId(job.Id, currentUserId);
     1795          job.Permission = jobPermission == null ? Permission.NotAllowed : jobPermission.Permission.ToDto();
     1796        }
     1797      }
     1798    }
    17401799    #endregion
    17411800  }
  • branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs

    r15966 r15969  
    9494
    9595    [OperationContract]
     96    void UpdateJobStates(IEnumerable<Guid> jobIds, JobState jobState);
     97
     98    [OperationContract]
    9699    IEnumerable<AssignedJobResource> GetAssignedResourcesForJob(Guid jobId);
    97100    #endregion
Note: See TracChangeset for help on using the changeset viewer.