Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/17/11 14:47:56 (14 years ago)
Author:
cneumuel
Message:

#1233

  • added StateLog to log state transitions of hive jobs
  • added permissions to hive experiments (in data access layer, no UI for that yet)
  • extended unit tests
Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/AuthorizationManager.cs

    r5264 r5511  
    2121
    2222using System;
    23 using System.Linq;
    2423using System.Security;
    2524using System.Web.Security;
     
    3534    }
    3635
    37     public void AuthorizeJobs(params Guid[] jobIds) {
    38       if (!IsAuthorizedForJobs(jobIds)) {
    39         throw new SecurityException("User '" + Identity.UserName + "' is not authorized to access job (Id: " + string.Join(", ", jobIds.Select(x => x.ToString()).ToArray()) + ")");
    40       }
    41     }
     36    //public void AuthorizeJobs(params Guid[] jobIds) {
     37    //  if (!IsAuthorizedForJobs(jobIds)) {
     38    //    throw new SecurityException("User '" + Identity.UserName + "' is not authorized to access job (Id: " + string.Join(", ", jobIds.Select(x => x.ToString()).ToArray()) + ")");
     39    //  }
     40    //}
    4241
    43     private bool IsAuthorizedForJobs(params Guid[] jobIds) {
    44       return ServiceLocator.Instance.HiveDao.IsUserAuthorizedForJobs(UserId, jobIds);
    45     }
     42    //private bool IsAuthorizedForJobs(params Guid[] jobIds) {
     43    //  return ServiceLocator.Instance.HiveDao.IsUserAuthorizedForJobs(UserId, jobIds);
     44    //}
    4645
    4746    public void Authorize(Guid userId) {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HeartbeatManager.cs

    r5405 r5511  
    22using System.Collections.Generic;
    33using System.Linq;
    4 using System.Text;
    54using HeuristicLab.Services.Hive.Common;
    65using HeuristicLab.Services.Hive.Common.DataTransfer;
     
    5453
    5554    private void AssignJob(Slave slave, Job job) {
    56       job.SlaveId = slave.Id;
    57       job.JobState = JobState.Calculating; // Todo: Maybe use State = Transferring (?)
    58       job.DateCalculated = DateTime.Now; // Todo: use statelog instead
     55      job.SetState(JobState.Transferring, slave.Id, "");
    5956      dao.UpdateJob(job);
    6057      dao.UpdateSlave(slave);
     
    7976          Logger.Error("Job does not exist in DB: " + jobProgress.Key);
    8077        } else {
    81           if (curJob.SlaveId == Guid.Empty || curJob.SlaveId != heartbeat.SlaveId) {
     78          if (curJob.CurrentStateLog.SlaveId == Guid.Empty || curJob.CurrentStateLog.SlaveId != heartbeat.SlaveId) {
    8279            // assigned slave does not match heartbeat
    8380            actions.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id));
     
    8885            curJob.LastHeartbeat = DateTime.Now;
    8986
    90             if (curJob.JobState == JobState.Aborted) {
     87            if (curJob.State == JobState.Aborted) {
    9188              // a request to abort the job has been set
    9289              actions.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id));
     90            } else if (curJob.State != JobState.Calculating) {
     91              // jobstate was 'Transferring' before, now calculating
     92              curJob.SetState(JobState.Calculating, heartbeat.SlaveId, "");
    9393            }
    9494            dao.UpdateJob(curJob);
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs

    r5458 r5511  
    3333    //[PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
    3434    //[PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
    35     public Guid AddJob(Job job, JobData jobData, IEnumerable<Guid> slaveGroupIds) {
    36       using (trans.OpenTransaction()) {
    37         job.UserId = auth.UserId;
    38         job.DateCreated = DateTime.Now;
    39         job.JobState = JobState.Waiting;
     35    public Guid AddJob(Job job, JobData jobData, IEnumerable<Guid> resourceIds) {
     36      using (trans.OpenTransaction()) {
     37        job.SetState(JobState.Waiting, auth.UserId);
    4038        job.Id = dao.AddJob(job);
    4139        jobData.JobId = job.Id;
    4240        jobData.LastUpdate = DateTime.Now;
    43         if (slaveGroupIds != null) {
    44           foreach (Guid slaveGroupId in slaveGroupIds) {
     41        if (resourceIds != null) {
     42          foreach (Guid slaveGroupId in resourceIds) {
    4543            dao.AssignJobToResource(job.Id, slaveGroupId);
    4644          }
     
    8078    }
    8179
    82     public void UpdateJob(Job job, JobData jobData) {
     80    public void UpdateJob(Job job) {
     81      using (trans.OpenTransaction()) {
     82        dao.UpdateJob(job);
     83      }
     84    }
     85
     86    public void UpdateJobData(Job job, JobData jobData) {
    8387      using (trans.OpenTransaction()) {
    8488        jobData.LastUpdate = DateTime.Now;
     
    122126
    123127    public HiveExperiment GetHiveExperiment(Guid id) {
    124       return dao.GetHiveExperiments(x => x.UserId == auth.UserId && x.HiveExperimentId == id).FirstOrDefault();
     128      return dao.GetHiveExperiments(x =>
     129             x.HiveExperimentId == id
     130          && (x.OwnerUserId == auth.UserId || x.HiveExperimentPermissions.Count(hep => hep.Permission != Permission.NotAllowed && hep.GrantedUserId == auth.UserId) > 0)
     131          ).FirstOrDefault();
    125132    }
    126133
    127134    public IEnumerable<HiveExperiment> GetHiveExperiments() {
    128       return dao.GetHiveExperiments(x => x.UserId == auth.UserId);
     135      return dao.GetHiveExperiments(x => x.OwnerUserId == auth.UserId || x.HiveExperimentPermissions.Count(hep => hep.Permission != Permission.NotAllowed && hep.GrantedUserId == auth.UserId) > 0);
    129136    }
    130137
    131138    public Guid AddHiveExperiment(HiveExperiment hiveExperimentDto) {
    132139      using (trans.OpenTransaction()) {
    133         hiveExperimentDto.UserId = auth.UserId;
     140        hiveExperimentDto.OwnerUserId = auth.UserId;
    134141        hiveExperimentDto.DateCreated = DateTime.Now;
    135142        return dao.AddHiveExperiment(hiveExperimentDto);
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/Interfaces/IAuthorizationManager.cs

    r5043 r5511  
    3333    /// </summary>
    3434    /// <exception cref="SecurityException">thrown when access denied</exception>
    35     void AuthorizeJobs(params Guid[] jobId);
     35    //void AuthorizeJobs(params Guid[] jobId);
    3636
    3737    /// <summary>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/LifecycleManager.cs

    r5405 r5511  
    11using System;
    2 using System.Collections.Generic;
    32using System.Linq;
    4 using System.Text;
    5 using System.Transactions;
     3using HeuristicLab.Core;
    64using HeuristicLab.Services.Hive.Common;
    75using HeuristicLab.Services.Hive.Common.DataTransfer;
    8 using HeuristicLab.Tracing;
    9 using HeuristicLab.Core;
    106
    117namespace HeuristicLab.Services.Hive {
     
    2723
    2824    // Windows-Forms timer is single threaded, so callbacks will be synchron
    29     System.Windows.Forms.Timer timer;
     25    private System.Windows.Forms.Timer timer;
    3026
    3127    public ExecutionState ExecutionState {
     
    4036    public void Start() {
    4137      if (ExecutionState == Core.ExecutionState.Stopped) {
    42         this.timer.Interval = (int)new TimeSpan(0, 0, 10).TotalMilliseconds;
     38        this.timer.Interval = (int)new TimeSpan(0, 0, 30).TotalMilliseconds;
    4339        this.timer.Start();
    4440      }
     
    7167
    7268    private void AbortJobs(Guid slaveId) {
    73       var jobs = dao.GetJobs(x => x.Slave.ResourceId == slaveId);
     69      var jobs = dao.GetJobs(x => x.StateLogs.Last().SlaveId == slaveId);
    7470      foreach (var j in jobs) {
    75         j.JobState = JobState.Waiting;
     71        j.StateLog.Add(new StateLog() {
     72          UserId = auth.UserId,
     73          State = JobState.Waiting,
     74          JobId = j.Id,
     75          DateTime = DateTime.Now,
     76          Exception = "Slave timed out"
     77        });
    7678        dao.UpdateJob(j);
    7779      }
Note: See TracChangeset for help on using the changeset viewer.