Changeset 9391


Ignore:
Timestamp:
04/23/13 10:37:45 (6 years ago)
Author:
pfleck
Message:

#2030
Separated old DTO-Dao from new Dao. DTO-Dao should be replaced completely.
Heartbeat and UpdateTaskState uses new Dao.
DataContext is now closed on ServiceOperation end.

Location:
branches/HivePerformance/sources
Files:
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive.Web/Hive-3.3/Status.aspx.cs

    r9033 r9391  
    3636public partial class Status : System.Web.UI.Page {
    3737  protected void Page_Load(object sender, EventArgs e) {
    38     var dao = ServiceLocator.Instance.HiveDao;
     38    var dao = ServiceLocator.Instance.HiveDtoDao;
    3939    var transactionManager = ServiceLocator.Instance.TransactionManager;
    4040    var resourceName = Request.QueryString["resource"];
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3

    • Property svn:ignore
      •  

        old new  
        22bin
        33obj
         4*.user
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj

    r9381 r9391  
    138138    <Compile Include="DataTransfer\UserStatistics.cs" />
    139139    <Compile Include="HiveDao.cs" />
     140    <Compile Include="HiveDtoDao.cs" />
    140141    <Compile Include="HiveJanitor.cs" />
    141142    <Compile Include="HiveOperationContext.cs" />
    142143    <Compile Include="Interfaces\IHiveDao.cs" />
     144    <Compile Include="Interfaces\IHiveDtoDao.cs" />
    143145    <Compile Include="Interfaces\ITaskScheduler.cs" />
    144146    <Compile Include="Scheduler\TaskInfoForScheduler.cs" />
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveDtoDao.cs

    r9385 r9391  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Data.Linq;
    2524using System.Linq;
    2625using System.Linq.Expressions;
     
    2827
    2928namespace HeuristicLab.Services.Hive.DataAccess {
    30   public class HiveDao : IHiveDao {
     29  public class HiveDtoDao : IHiveDtoDao {
    3130    public static HiveDataContext CreateContext(bool longRunning = false) {
    3231      var context = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString);
     
    3534    }
    3635
    37     public HiveDao() { }
     36    public HiveDtoDao() { }
    3837
    3938    #region Task Methods
     
    4342      }
    4443    }
    45 
    46     public Task GetTaskDA(Guid id) {
    47       var db = HiveOperationContext.Current.DataContext;
    48       return GetTaskByIdQuery(db, id).SingleOrDefault();
    49     }
    50 
    51     private static Func<HiveDataContext, Guid, IQueryable<Task>> GetTaskByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid id) =>
    52       from t in db.Tasks
    53       where t.TaskId == id
    54       select t
    55     );
    5644
    5745    public IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate) {
     
    150138        db.SubmitChanges();
    151139      }
    152     }
    153 
    154     public void UpdateTaskDA(Task task) {
    155       var db = HiveOperationContext.Current.DataContext;
    156       db.SubmitChanges();
    157140    }
    158141
     
    212195    }
    213196
    214     public IQueryable<TaskInfoForScheduler> GetWaitingTasksDA(Slave slave) {
    215       var db = HiveOperationContext.Current.DataContext;
    216 
    217       var parentResources = GetParentResourcesDA(slave.ResourceId);
    218       var resourceIds = parentResources.Select(x => x.ResourceId);
    219       //Originally we checked here if there are parent tasks which should be calculated (with GetParentTasks(resourceIds, count, false);).
    220       //Because there is at the moment no case where this makes sense (there don't exist parent tasks which need to be calculated),
    221       //we skip this step because it's wasted runtime
    222 
    223       return from ar in db.AssignedResources
    224              where resourceIds.Contains(ar.ResourceId)
    225                  && !(ar.Task.IsParentTask && ar.Task.FinishWhenChildJobsFinished)
    226                  && ar.Task.State == TaskState.Waiting
    227                  && ar.Task.CoresNeeded <= slave.FreeCores
    228                  && ar.Task.MemoryNeeded <= slave.FreeMemory
    229              select new TaskInfoForScheduler() { TaskId = ar.Task.TaskId, JobId = ar.Task.JobId, Priority = ar.Task.Priority };
    230     }
    231 
    232     /*private static Func<HiveDataContext, Guid, Slave, IQueryable<TaskInfoForScheduler>> GetWaitingTasksQuery = CompiledQuery.Compile((HiveDataContext db, Guid id, Slave slave) =>
    233       from ar in db.AssignedResources
    234       where ar.ResourceId == id
    235           && !(ar.Task.IsParentTask && ar.Task.FinishWhenChildJobsFinished)
    236           && ar.Task.State == TaskState.Waiting
    237           && ar.Task.CoresNeeded <= slave.FreeCores
    238           && ar.Task.MemoryNeeded <= slave.FreeMemory
    239       select new TaskInfoForScheduler() { TaskId = ar.Task.TaskId, JobId = ar.Task.JobId, Priority = ar.Task.Priority }
    240     );*/
    241 
    242197    public DT.Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) {
    243198      using (var db = CreateContext()) {
     
    267222        return DT.Convert.ToDto(task);
    268223      }
    269     }
    270 
    271     public Task UpdateTaskStateDA(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) {
    272       var db = HiveOperationContext.Current.DataContext;
    273 
    274       db.StateLogs.InsertOnSubmit(new StateLog {
    275         TaskId = taskId,
    276         State = taskState,
    277         SlaveId = slaveId,
    278         UserId = userId,
    279         Exception = exception,
    280         DateTime = DateTime.Now
    281       });
    282 
    283       var task = GetTaskDA(taskId);
    284       task.State = taskState;
    285 
    286       db.SubmitChanges();
    287 
    288       return task;
    289224    }
    290225    #endregion
     
    581516    }
    582517
    583     public Slave GetSlaveDA(Guid id) {
    584       var db = HiveOperationContext.Current.DataContext;
    585       return GetSlaveByIdQuery(db, id).SingleOrDefault();
    586     }
    587 
    588     private static Func<HiveDataContext, Guid, IQueryable<Slave>> GetSlaveByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid slaveId) =>
    589       from s in db.Resources.OfType<Slave>()
    590       where s.ResourceId == slaveId
    591       select s
    592     );
    593 
    594518    public IEnumerable<DT.Slave> GetSlaves(Expression<Func<Slave, bool>> predicate) {
    595519      using (var db = CreateContext()) {
     
    614538        db.SubmitChanges();
    615539      }
    616     }
    617 
    618     public void UpdateSlaveDA(Slave slave) {
    619       var db = HiveOperationContext.Current.DataContext;
    620       db.SubmitChanges();
    621540    }
    622541
     
    736655    }
    737656
    738     public IQueryable<Guid> GetAssignedResourcesIdsDA(Guid taskId) {
    739       var db = HiveOperationContext.Current.DataContext;
    740       return GetAssignedResourcesIdQuery(db, taskId);
    741     }
    742 
    743     private static Func<HiveDataContext, Guid, IQueryable<Guid>> GetAssignedResourcesIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) =>
    744      from ar in db.AssignedResources
    745      where ar.TaskId == taskId
    746      select ar.ResourceId
    747    );
    748 
    749657    /// <summary>
    750658    /// Returns all parent resources of a resource (the given resource is also added)
     
    757665      }
    758666    }
    759 
    760     public IEnumerable<Resource> GetParentResourcesDA(Guid resourceId) {
    761       var db = HiveOperationContext.Current.DataContext;
    762       var child = db.Resources.Single(r => r.ResourceId == resourceId);
    763 
    764       yield return child;
    765       while (child.ParentResource != null) {
    766         child = child.ParentResource;
    767         yield return child;
    768       }
    769     }
    770 
    771     public IEnumerable<Guid> GetParentResourcesIDsDA(Guid resourceId) {
    772       var db = HiveOperationContext.Current.DataContext;
    773       var child = db.Resources.Single(r => r.ResourceId == resourceId);
    774 
    775       yield return resourceId;
    776       while (child.ParentResource != null) {
    777         child = child.ParentResource;
    778         yield return child.ResourceId;
    779       }
    780     }
    781 
    782     public IQueryable<int> GetNumberOfDowntimesFromParentResourcesAtCurrentTimeDA(Guid resourceId, DowntimeType type) {
    783       var db = HiveOperationContext.Current.DataContext;
    784 
    785       var ids = GetParentResourcesIDsDA(resourceId).ToArray();
    786 
    787       return from r in db.Resources
    788              where ids.Contains(r.ResourceId)
    789              select (from d in db.Downtimes
    790                      where d.ResourceId == r.ResourceId && d.DowntimeType == type && (DateTime.Now >= d.StartDate) && (DateTime.Now <= d.EndDate)
    791                      select d).Count();
    792     }
    793 
    794     /*private static Func<HiveDataContext, Guid, DowntimeType, int> GetNumberOfDowntimesAtCurrentTimeQuery =
    795       CompiledQuery.Compile((HiveDataContext db, Guid ids, DowntimeType type) =>
    796         (from d in db.Downtimes
    797          where d.ResourceId == ids && d.DowntimeType == type && (DateTime.Now >= d.StartDate) && (DateTime.Now <= d.EndDate)
    798          select d).Count()
    799     );*/
    800667
    801668    private static void CollectParentResources(ICollection<Resource> resources, Resource resource) {
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs

    r7259 r9391  
    3737    }
    3838
    39     private IHiveDao dao {
    40       get { return ServiceLocator.Instance.HiveDao; }
     39    private IHiveDtoDao dao {
     40      get { return ServiceLocator.Instance.HiveDtoDao; }
    4141    }
    4242
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveOperationContext.cs

    r9381 r9391  
    2020#endregion
    2121
     22using System;
     23using System.Collections.ObjectModel;
    2224using System.Diagnostics;
    2325using System.IO;
    2426using System.ServiceModel;
     27using System.ServiceModel.Channels;
     28using System.ServiceModel.Description;
     29using System.ServiceModel.Dispatcher;
    2530using System.Text;
    2631using HeuristicLab.Services.Hive.DataAccess;
     
    3035    public static HiveOperationContext Current {
    3136      get {
    32         var context = OperationContext.Current.Extensions.Find<HiveOperationContext>();
    33         if (context == null) {
    34           context = new HiveOperationContext();
    35           OperationContext.Current.Extensions.Add(context);
    36         }
    37         return context;
     37        return OperationContext.Current.Extensions.Find<HiveOperationContext>();
    3838      }
    3939    }
     
    4242
    4343    public void Attach(OperationContext owner) {
    44       DataContext = HiveDao.CreateContext();
     44      DataContext = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString);
    4545      //DataContext.Log = new DebugWriter();
    4646    }
    4747
    4848    public void Detach(OperationContext owner) {
    49       // nothing
     49      DataContext.Dispose();
     50    }
     51  }
     52
     53  public class HiveOperationContextMessageInspector : IDispatchMessageInspector {
     54    public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) {
     55      OperationContext.Current.Extensions.Add(new HiveOperationContext());
     56      return request.Headers.MessageId;
     57    }
     58
     59    public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState) {
     60      OperationContext.Current.Extensions.Remove(HiveOperationContext.Current);
     61    }
     62  }
     63
     64  public class HiveOperationContextBehaviorAttribute : Attribute, IServiceBehavior {
     65    public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase,
     66      Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) {
     67    }
     68
     69    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) {
     70      foreach (ChannelDispatcher cd in serviceHostBase.ChannelDispatchers) {
     71        foreach (EndpointDispatcher ed in cd.Endpoints) {
     72          ed.DispatchRuntime.MessageInspectors.Add(new HiveOperationContextMessageInspector());
     73        }
     74      }
     75    }
     76
     77    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) {
    5078    }
    5179  }
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r9369 r9391  
    3737  /// </summary>
    3838  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IgnoreExtensionDataObject = true)]
     39  [HiveOperationContextBehavior]
    3940  public class HiveService : IHiveService {
     41    private IHiveDtoDao dtoDao {
     42      get { return ServiceLocator.Instance.HiveDtoDao; }
     43    }
    4044    private IHiveDao dao {
    4145      get { return ServiceLocator.Instance.HiveDao; }
     
    6468      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    6569      return trans.UseTransaction(() => {
    66         task.Id = dao.AddTask(task);
     70        task.Id = dtoDao.AddTask(task);
    6771        taskData.TaskId = task.Id;
    6872        taskData.LastUpdate = DateTime.Now;
    69         dao.AssignJobToResource(task.Id, resourceIds);
    70         dao.AddTaskData(taskData);
    71         dao.UpdateTaskState(task.Id, DA.TaskState.Waiting, null, userManager.CurrentUserId, null);
     73        dtoDao.AssignJobToResource(task.Id, resourceIds);
     74        dtoDao.AddTaskData(taskData);
     75        dtoDao.UpdateTaskState(task.Id, DA.TaskState.Waiting, null, userManager.CurrentUserId, null);
    7276        return taskData.TaskId;
    7377      }, false, true);
     
    7882      return trans.UseTransaction(() => {
    7983        task.ParentTaskId = parentTaskId;
    80         return AddTask(task, taskData, dao.GetAssignedResources(parentTaskId).Select(x => x.Id));
     84        return AddTask(task, taskData, dtoDao.GetAssignedResources(parentTaskId).Select(x => x.Id));
    8185      }, false, true);
    8286    }
     
    8791
    8892      return trans.UseTransaction(() => {
    89         return dao.GetTask(taskId);
     93        return dtoDao.GetTask(taskId);
    9094      }, false, false);
    9195    }
     
    9498      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    9599      return trans.UseTransaction(() => {
    96         var tasks = dao.GetTasks(x => true);
     100        var tasks = dtoDao.GetTasks(x => true);
    97101        foreach (var task in tasks)
    98102          author.AuthorizeForTask(task.Id, Permission.Read);
     
    105109
    106110      return trans.UseTransaction(() => {
    107         var tasks = dao.GetTasks(x => taskIds.Contains(x.TaskId)).Select(x => new LightweightTask(x)).ToArray();
     111        var tasks = dtoDao.GetTasks(x => taskIds.Contains(x.TaskId)).Select(x => new LightweightTask(x)).ToArray();
    108112        foreach (var task in tasks)
    109113          author.AuthorizeForTask(task.Id, Permission.Read);
     
    128132
    129133      return trans.UseTransaction(() => {
    130         return dao.GetLightweightTasks(task => task.JobId == jobId).ToArray();
     134        return dtoDao.GetLightweightTasks(task => task.JobId == jobId).ToArray();
    131135      }, false, true);
    132136    }
     
    137141
    138142      return trans.UseTransaction(() => {
    139         return dao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray();
     143        return dtoDao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray();
    140144      }, false, false);
    141145    }
     
    146150
    147151      return trans.UseTransaction(() => {
    148         return dao.GetTaskData(taskId);
     152        return dtoDao.GetTaskData(taskId);
    149153      });
    150154    }
     
    155159
    156160      trans.UseTransaction(() => {
    157         dao.UpdateTaskAndPlugins(taskDto);
     161        dtoDao.UpdateTaskAndPlugins(taskDto);
    158162      });
    159163    }
     
    163167      author.AuthorizeForTask(task.Id, Permission.Full);
    164168
    165       trans.UseTransaction(() => {
    166         dao.UpdateTaskAndPlugins(task);
    167       });
    168 
    169       trans.UseTransaction(() => {
    170         taskData.LastUpdate = DateTime.Now;
    171         dao.UpdateTaskData(taskData);
     169      // what for?
     170      /*trans.UseTransaction(() => {
     171        dtoDao.UpdateTaskAndPlugins(task);
     172      });*/
     173
     174      trans.UseTransaction(() => {
     175        var data = dao.GetTaskDataByDto(taskData);
     176        data.LastUpdate = DateTime.Now;
     177        dao.UpdateTaskData(data);
    172178      });
    173179    }
     
    177183      author.AuthorizeForTask(taskId, Permission.Full);
    178184      trans.UseTransaction(() => {
    179         dao.DeleteTask(taskId);
     185        dtoDao.DeleteTask(taskId);
    180186      });
    181187    }
     
    187193        var tasks = GetChildTasks(parentTaskId, true, false);
    188194        foreach (var task in tasks) {
    189           dao.DeleteTask(task.Id);
    190           dao.DeleteTaskData(task.Id);
     195          dtoDao.DeleteTask(task.Id);
     196          dtoDao.DeleteTaskData(task.Id);
    191197        };
    192198      });
     
    196202      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
    197203      author.AuthorizeForTask(taskId, Permission.Full);
    198       return trans.UseTransaction(() => {
    199         Task task = dao.UpdateTaskState(taskId, DataTransfer.Convert.ToEntity(taskState), slaveId, userId, exception);
    200 
    201         if (task.Command.HasValue && task.Command.Value == Command.Pause && task.State == TaskState.Paused) {
     204
     205      return trans.UseTransaction(() => {
     206        var task = dao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception);
     207
     208        if (task.Command.HasValue && task.Command.Value == DA.Command.Pause && task.State == DA.TaskState.Paused) {
    202209          task.Command = null;
    203         } else if (task.Command.HasValue && task.Command.Value == Command.Abort && task.State == TaskState.Aborted) {
     210        } else if (task.Command.HasValue && task.Command.Value == DA.Command.Abort && task.State == DA.TaskState.Aborted) {
    204211          task.Command = null;
    205         } else if (task.Command.HasValue && task.Command.Value == Command.Stop && task.State == TaskState.Aborted) {
     212        } else if (task.Command.HasValue && task.Command.Value == DA.Command.Stop && task.State == DA.TaskState.Aborted) {
    206213          task.Command = null;
    207214        } else if (taskState == TaskState.Paused && !task.Command.HasValue) {
    208215          // slave paused and uploaded the task (no user-command) -> set waiting.
    209           task = dao.UpdateTaskState(taskId, DataTransfer.Convert.ToEntity(TaskState.Waiting), slaveId, userId, exception);
    210         }
    211 
    212         dao.UpdateTaskAndPlugins(task);
    213         return task;
     216          task = dao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception);
     217        }
     218
     219        //dtoDao.UpdateTaskAndPluginsDA(task); no idea why this is needed
     220        return DT.Convert.ToDto(task);
    214221      });
    215222    }
     
    217224    public IEnumerable<Task> GetTasksByResourceId(Guid resourceId) {
    218225      authen.AuthenticateForAnyRole(HiveRoles.Administrator);
    219       var tasks = trans.UseTransaction(() => dao.GetJobsByResourceId(resourceId));
     226      var tasks = trans.UseTransaction(() => dtoDao.GetJobsByResourceId(resourceId));
    220227      foreach (var task in tasks)
    221228        author.AuthorizeForTask(task.Id, Permission.Read);
     
    229236      author.AuthorizeForTask(taskId, Permission.Full);
    230237      trans.UseTransaction(() => {
    231         var task = dao.GetTask(taskId);
     238        var task = dtoDao.GetTask(taskId);
    232239        if (task.State == TaskState.Calculating || task.State == TaskState.Transferring) {
    233240          task.Command = Command.Stop;
    234           dao.UpdateTask(task);
     241          dtoDao.UpdateTask(task);
    235242        } else {
    236243          if (task.State != TaskState.Aborted && task.State != TaskState.Finished && task.State != TaskState.Failed) {
     
    245252      author.AuthorizeForTask(taskId, Permission.Full);
    246253      trans.UseTransaction(() => {
    247         var job = dao.GetTask(taskId);
     254        var job = dtoDao.GetTask(taskId);
    248255        if (job.State == TaskState.Calculating || job.State == TaskState.Transferring) {
    249256          job.Command = Command.Pause;
    250           dao.UpdateTask(job);
     257          dtoDao.UpdateTask(job);
    251258        } else {
    252259          job = UpdateTaskState(taskId, TaskState.Paused, null, null, string.Empty);
     
    259266      author.AuthorizeForTask(taskId, Permission.Full);
    260267      trans.UseTransaction(() => {
    261         Task task = dao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, string.Empty);
     268        Task task = dtoDao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, string.Empty);
    262269        task.Command = null;
    263         dao.UpdateTask(task);
     270        dtoDao.UpdateTask(task);
    264271      });
    265272    }
     
    271278      author.AuthorizeForJob(id, Permission.Read);
    272279      return trans.UseTransaction(() => {
    273         var job = dao.GetJobs(x =>
     280        var job = dtoDao.GetJobs(x =>
    274281              x.JobId == id
    275282              && (x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0)
    276283            ).FirstOrDefault();
    277284        if (job != null) {
    278           job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
     285          job.Permission = DT.Convert.ToDto(dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
    279286          job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
    280287        }
     
    286293      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    287294      return trans.UseTransaction(() => {
    288         var jobs = dao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0);
     295        var jobs = dtoDao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0);
    289296        foreach (var job in jobs) {
    290297          author.AuthorizeForJob(job.Id, Permission.Read);
    291           job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
     298          job.Permission = DT.Convert.ToDto(dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
    292299          job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
    293300        }
     
    299306      authen.AuthenticateForAnyRole(HiveRoles.Administrator);
    300307      return trans.UseTransaction(() => {
    301         var jobs = dao.GetJobs(x => true);
     308        var jobs = dtoDao.GetJobs(x => true);
    302309        foreach (var job in jobs) { // no authorization here, since this method is admin-only! (admin is allowed to read all task)
    303           job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
     310          job.Permission = DT.Convert.ToDto(dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
    304311          job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
    305312        }
     
    313320        jobDto.OwnerUserId = userManager.CurrentUserId;
    314321        jobDto.DateCreated = DateTime.Now;
    315         return dao.AddJob(jobDto);
     322        return dtoDao.AddJob(jobDto);
    316323      });
    317324    }
     
    321328      author.AuthorizeForJob(jobDto.Id, Permission.Full);
    322329      trans.UseTransaction(() => {
    323         dao.UpdateJob(jobDto);
     330        dtoDao.UpdateJob(jobDto);
    324331      });
    325332    }
     
    329336      author.AuthorizeForJob(jobId, Permission.Full);
    330337      trans.UseTransaction(() => {
    331         dao.DeleteJob(jobId); // child task will be deleted by db-trigger
     338        dtoDao.DeleteJob(jobId); // child task will be deleted by db-trigger
    332339      });
    333340    }
     
    338345      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    339346      trans.UseTransaction(() => {
    340         Job job = dao.GetJob(jobId);
     347        Job job = dtoDao.GetJob(jobId);
    341348        if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId));
    342         Permission perm = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
     349        Permission perm = DT.Convert.ToDto(dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
    343350        if (perm != Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment"));
    344         dao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DT.Convert.ToEntity(permission));
     351        dtoDao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DT.Convert.ToEntity(permission));
    345352      });
    346353    }
     
    349356      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    350357      trans.UseTransaction(() => {
    351         Job job = dao.GetJob(jobId);
     358        Job job = dtoDao.GetJob(jobId);
    352359        if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId));
    353         DA.Permission perm = dao.GetPermissionForJob(job.Id, userManager.CurrentUserId);
     360        DA.Permission perm = dtoDao.GetPermissionForJob(job.Id, userManager.CurrentUserId);
    354361        if (perm != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment"));
    355         dao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DA.Permission.NotAllowed);
     362        dtoDao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DA.Permission.NotAllowed);
    356363      });
    357364    }
     
    360367      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    361368      return trans.UseTransaction(() => {
    362         DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId);
     369        DA.Permission currentUserPermission = dtoDao.GetPermissionForJob(jobId, userManager.CurrentUserId);
    363370        if (currentUserPermission != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment"));
    364         return dao.GetJobPermissions(x => x.JobId == jobId);
     371        return dtoDao.GetJobPermissions(x => x.JobId == jobId);
    365372      });
    366373    }
     
    379386
    380387      trans.UseTransaction(() => {
    381         var slave = dao.GetSlave(slaveInfo.Id);
     388        var slave = dtoDao.GetSlave(slaveInfo.Id);
    382389
    383390        if (slave == null) {
    384           var healGroup = dao.GetResources(x => x.Name == "HEAL").First();
     391          var healGroup = dtoDao.GetResources(x => x.Name == "HEAL").First();
    385392          if (healGroup != null) {
    386393            slaveInfo.ParentResourceId = healGroup.Id;
    387394          }
    388           dao.AddSlave(slaveInfo);
     395          dtoDao.AddSlave(slaveInfo);
    389396        } else {
    390397          slave.Name = slaveInfo.Name;
     
    405412          // don't update those properties: dbSlave.IsAllowedToCalculate, dbSlave.ParentResourceId
    406413
    407           dao.UpdateSlave(slave);
     414          dtoDao.UpdateSlave(slave);
    408415        }
    409416      });
     
    413420      authen.AuthenticateForAnyRole(HiveRoles.Slave);
    414421      trans.UseTransaction(() => {
    415         var slave = dao.GetSlave(slaveId);
     422        var slave = dtoDao.GetSlave(slaveId);
    416423        if (slave != null) {
    417424          slave.SlaveState = SlaveState.Offline;
    418           dao.UpdateSlave(slave);
     425          dtoDao.UpdateSlave(slave);
    419426        }
    420427      });
     
    449456        plugin.DateCreated = DateTime.Now;
    450457
    451         var existing = dao.GetPlugins(x => x.Hash != null).Where(x => x.Hash.SequenceEqual(plugin.Hash));
     458        var existing = dtoDao.GetPlugins(x => x.Hash != null).Where(x => x.Hash.SequenceEqual(plugin.Hash));
    452459        if (existing.Count() > 0) {
    453460          // a plugin already exists.
     
    455462        }
    456463
    457         Guid pluginId = dao.AddPlugin(plugin);
     464        Guid pluginId = dtoDao.AddPlugin(plugin);
    458465        foreach (PluginData pluginData in pluginDatas) {
    459466          pluginData.PluginId = pluginId;
    460           dao.AddPluginData(pluginData);
     467          dtoDao.AddPluginData(pluginData);
    461468        }
    462469        return pluginId;
     
    467474      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
    468475      return trans.UseTransaction(() => {
    469         return dao.GetPlugin(pluginId);
     476        return dtoDao.GetPlugin(pluginId);
    470477      });
    471478    }
     
    474481      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
    475482      return trans.UseTransaction(() => {
    476         return dao.GetPlugins(x => x.Hash == hash).FirstOrDefault();
     483        return dtoDao.GetPlugins(x => x.Hash == hash).FirstOrDefault();
    477484      });
    478485    }
     
    483490      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
    484491      return trans.UseTransaction(() => {
    485         return dao.GetPlugins(x => x.Hash != null);
     492        return dtoDao.GetPlugins(x => x.Hash != null);
    486493      });
    487494    }
     
    492499      return trans.UseTransaction(() => {
    493500        foreach (Guid guid in pluginIds) {
    494           pluginDatas.AddRange(dao.GetPluginDatas(x => x.PluginId == guid).ToList());
     501          pluginDatas.AddRange(dtoDao.GetPluginDatas(x => x.PluginId == guid).ToList());
    495502        }
    496503        return pluginDatas;
     
    501508      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
    502509      trans.UseTransaction(() => {
    503         dao.DeletePlugin(pluginId);
     510        dtoDao.DeletePlugin(pluginId);
    504511      });
    505512    }
     
    510517      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    511518      trans.UseTransaction(() => {
    512         Resource resource = dao.GetResource(resourceId);
     519        Resource resource = dtoDao.GetResource(resourceId);
    513520        if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId));
    514521        if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permission for this resource"));
    515522        foreach (Guid id in grantedUserIds)
    516           dao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = userManager.CurrentUserId, GrantedUserId = id });
     523          dtoDao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = userManager.CurrentUserId, GrantedUserId = id });
    517524      });
    518525    }
     
    521528      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    522529      trans.UseTransaction(() => {
    523         Resource resource = dao.GetResource(resourceId);
     530        Resource resource = dtoDao.GetResource(resourceId);
    524531        if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId));
    525532        if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to revoke permission for this resource"));
    526533        foreach (Guid id in grantedUserIds)
    527           dao.DeleteResourcePermission(resourceId, id);
     534          dtoDao.DeleteResourcePermission(resourceId, id);
    528535      });
    529536    }
     
    532539      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    533540      return trans.UseTransaction(() => {
    534         Resource resource = dao.GetResource(resourceId);
     541        Resource resource = dtoDao.GetResource(resourceId);
    535542        if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId));
    536         return dao.GetResourcePermissions(x => x.ResourceId == resourceId);
     543        return dtoDao.GetResourcePermissions(x => x.ResourceId == resourceId);
    537544      });
    538545    }
     
    541548    #region Resource Methods
    542549    public IEnumerable<Resource> GetChildResources(Guid resourceId) {
    543       return trans.UseTransaction(() => { return dao.GetChildResources(resourceId); });
     550      return trans.UseTransaction(() => { return dtoDao.GetChildResources(resourceId); });
    544551    }
    545552    #endregion
     
    549556      authen.AuthenticateForAnyRole(HiveRoles.Slave);
    550557
    551       Slave s = trans.UseTransaction(() => { return dao.GetSlave(slaveId); });
     558      Slave s = trans.UseTransaction(() => { return dtoDao.GetSlave(slaveId); });
    552559      if (s != null) {
    553560        return s.HbInterval;
     
    559566    public Guid AddSlave(Slave slave) {
    560567      authen.AuthenticateForAnyRole(HiveRoles.Administrator);
    561       return trans.UseTransaction(() => dao.AddSlave(slave));
     568      return trans.UseTransaction(() => dtoDao.AddSlave(slave));
    562569    }
    563570
    564571    public Guid AddSlaveGroup(SlaveGroup slaveGroup) {
    565572      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    566       return trans.UseTransaction(() => dao.AddSlaveGroup(slaveGroup));
     573      return trans.UseTransaction(() => dtoDao.AddSlaveGroup(slaveGroup));
    567574    }
    568575
    569576    public Slave GetSlave(Guid slaveId) {
    570577      authen.AuthenticateForAnyRole(HiveRoles.Administrator);
    571       return trans.UseTransaction(() => { return dao.GetSlave(slaveId); });
     578      return trans.UseTransaction(() => { return dtoDao.GetSlave(slaveId); });
    572579    }
    573580
    574581    public SlaveGroup GetSlaveGroup(Guid slaveGroupId) {
    575582      authen.AuthenticateForAnyRole(HiveRoles.Administrator);
    576       return trans.UseTransaction(() => { return dao.GetSlaveGroup(slaveGroupId); });
     583      return trans.UseTransaction(() => { return dtoDao.GetSlaveGroup(slaveGroupId); });
    577584    }
    578585
     
    580587      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    581588      return trans.UseTransaction(() => {
    582         return dao.GetSlaves(x => true).Where(x => x.OwnerUserId == null
     589        return dtoDao.GetSlaves(x => true).Where(x => x.OwnerUserId == null
    583590                                           || x.OwnerUserId == userManager.CurrentUserId
    584591                                           || userManager.VerifyUser(userManager.CurrentUserId, GetResourcePermissions(x.Id).Select(y => y.GrantedUserId).ToList())
     
    590597      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    591598      return trans.UseTransaction(() => {
    592         return dao.GetSlaveGroups(x => true).Where(x => x.OwnerUserId == null
     599        return dtoDao.GetSlaveGroups(x => true).Where(x => x.OwnerUserId == null
    593600                                                || x.OwnerUserId == userManager.CurrentUserId
    594601                                                || userManager.VerifyUser(userManager.CurrentUserId, GetResourcePermissions(x.Id).Select(y => y.GrantedUserId).ToList())
     
    600607      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    601608      trans.UseTransaction(() => {
    602         dao.UpdateSlave(slave);
     609        dtoDao.UpdateSlave(slave);
    603610      });
    604611    }
     
    607614      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    608615      trans.UseTransaction(() => {
    609         dao.UpdateSlaveGroup(slaveGroup);
     616        dtoDao.UpdateSlaveGroup(slaveGroup);
    610617      });
    611618    }
     
    615622      author.AuthorizeForResourceAdministration(slaveId);
    616623      trans.UseTransaction(() => {
    617         dao.DeleteSlave(slaveId);
     624        dtoDao.DeleteSlave(slaveId);
    618625      });
    619626    }
     
    623630      author.AuthorizeForResourceAdministration(slaveGroupId);
    624631      trans.UseTransaction(() => {
    625         dao.DeleteSlaveGroup(slaveGroupId);
     632        dtoDao.DeleteSlaveGroup(slaveGroupId);
    626633      });
    627634    }
     
    630637      authen.AuthenticateForAnyRole(HiveRoles.Administrator);
    631638      trans.UseTransaction(() => {
    632         var resource = dao.GetResource(resourceId);
     639        var resource = dtoDao.GetResource(resourceId);
    633640        resource.ParentResourceId = slaveGroupId;
    634         dao.UpdateResource(resource);
     641        dtoDao.UpdateResource(resource);
    635642      });
    636643    }
     
    639646      authen.AuthenticateForAnyRole(HiveRoles.Administrator);
    640647      trans.UseTransaction(() => {
    641         var resource = dao.GetResource(resourceId);
     648        var resource = dtoDao.GetResource(resourceId);
    642649        resource.ParentResourceId = null;
    643         dao.UpdateResource(resource);
     650        dtoDao.UpdateResource(resource);
    644651      });
    645652    }
     
    648655      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    649656      return trans.UseTransaction(() => {
    650         var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault();
     657        var resource = dtoDao.GetResources(x => x.Name == resourceName).FirstOrDefault();
    651658        if (resource != null) {
    652659          return resource.Id;
     
    662669      bool cleanup = false;
    663670      trans.UseTransaction(() => {
    664         DateTime lastCleanup = dao.GetLastCleanup();
     671        DateTime lastCleanup = dtoDao.GetLastCleanup();
    665672        if (force || DateTime.Now - lastCleanup > HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval) {
    666           dao.SetLastCleanup(DateTime.Now);
     673          dtoDao.SetLastCleanup(DateTime.Now);
    667674          cleanup = true;
    668675        }
     
    679686      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    680687      author.AuthorizeForResourceAdministration(downtime.ResourceId);
    681       return trans.UseTransaction(() => dao.AddDowntime(downtime));
     688      return trans.UseTransaction(() => dtoDao.AddDowntime(downtime));
    682689    }
    683690
     
    687694      // author.AuthorizeForResource(resourceId);
    688695      trans.UseTransaction(() => {
    689         dao.DeleteDowntime(downtimeId);
     696        dtoDao.DeleteDowntime(downtimeId);
    690697      });
    691698    }
     
    695702      author.AuthorizeForResourceAdministration(downtime.ResourceId);
    696703      trans.UseTransaction(() => {
    697         dao.UpdateDowntime(downtime);
     704        dtoDao.UpdateDowntime(downtime);
    698705      });
    699706    }
     
    701708    public IEnumerable<Downtime> GetDowntimesForResource(Guid resourceId) {
    702709      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    703       return trans.UseTransaction(() => dao.GetDowntimes(x => x.ResourceId == resourceId));
     710      return trans.UseTransaction(() => dtoDao.GetDowntimes(x => x.ResourceId == resourceId));
    704711    }
    705712    #endregion
     
    724731    #region UserPriority Methods
    725732    public IEnumerable<UserPriority> GetUserPriorities() {
    726       return trans.UseTransaction(() => dao.GetUserPriorities(x => true));
     733      return trans.UseTransaction(() => dtoDao.GetUserPriorities(x => true));
    727734    }
    728735    #endregion
     
    730737    #region Helper Methods
    731738    private IEnumerable<Task> GetChildTasks(Guid? parentTaskId, bool recursive, bool includeParent) {
    732       var tasks = new List<Task>(dao.GetTasks(x => parentTaskId == null ? !x.ParentTaskId.HasValue : x.ParentTaskId.Value == parentTaskId));
     739      var tasks = new List<Task>(dtoDao.GetTasks(x => parentTaskId == null ? !x.ParentTaskId.HasValue : x.ParentTaskId.Value == parentTaskId));
    733740
    734741      if (recursive) {
     
    747754    #region Statistics Methods
    748755    public IEnumerable<Statistics> GetStatistics() {
    749       return trans.UseTransaction(() => { return dao.GetStatistics(x => true); });
     756      return trans.UseTransaction(() => { return dtoDao.GetStatistics(x => true); });
    750757    }
    751758    public IEnumerable<Statistics> GetStatisticsForTimePeriod(DateTime from, DateTime to) {
    752       return trans.UseTransaction(() => { return dao.GetStatistics(x => x.Timestamp >= from && x.Timestamp <= to); });
     759      return trans.UseTransaction(() => { return dtoDao.GetStatistics(x => x.Timestamp >= from && x.Timestamp <= to); });
    753760    }
    754761    #endregion
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDtoDao.cs

    r9385 r9391  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using System.Linq.Expressions;
    2625using HeuristicLab.Services.Hive.DataAccess;
     
    2827
    2928namespace HeuristicLab.Services.Hive {
    30   public interface IHiveDao {
     29  public interface IHiveDtoDao {
    3130    #region Task Methods
    3231    DT.Task GetTask(Guid id);
    33     Task GetTaskDA(Guid id);
    3432    IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate);
    3533    IEnumerable<DT.LightweightTask> GetLightweightTasks(Expression<Func<Task, bool>> predicate);
     
    3937    void UpdateTaskAndStateLogs(DT.Task dto);
    4038    void UpdateTask(DT.Task dto);
    41     void UpdateTaskDA(Task dto);
    4239    void DeleteTask(Guid id);
    4340    IEnumerable<TaskInfoForScheduler> GetWaitingTasks(DT.Slave slave);
    44     IQueryable<TaskInfoForScheduler> GetWaitingTasksDA(Slave slave);
    4541    IEnumerable<DT.Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished);
    4642    DT.Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception);
    47     Task UpdateTaskStateDA(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception);
    4843    #endregion
    4944
     
    10095    #region Slave Methods
    10196    DT.Slave GetSlave(Guid id);
    102     Slave GetSlaveDA(Guid id);
    10397    IEnumerable<DT.Slave> GetSlaves(Expression<Func<Slave, bool>> predicate);
    10498    Guid AddSlave(DT.Slave dto);
    10599    void UpdateSlave(DT.Slave dto);
    106     void UpdateSlaveDA(Slave dto);
    107100    void DeleteSlave(Guid id);
    108101    #endregion
     
    124117    void AssignJobToResource(Guid taskId, IEnumerable<Guid> resourceIds);
    125118    IEnumerable<DT.Resource> GetAssignedResources(Guid jobId);
    126     IQueryable<Guid> GetAssignedResourcesIdsDA(Guid taskId);
    127119    IEnumerable<DT.Resource> GetParentResources(Guid resourceId);
    128     IEnumerable<Resource> GetParentResourcesDA(Guid resourceId);
    129     IEnumerable<Guid> GetParentResourcesIDsDA(Guid resourceId);
    130     IQueryable<int> GetNumberOfDowntimesFromParentResourcesAtCurrentTimeDA(Guid resourceId, DowntimeType type);
    131120    IEnumerable<DT.Resource> GetChildResources(Guid resourceId);
    132121    IEnumerable<DT.Task> GetJobsByResourceId(Guid resourceId);
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IServiceLocator.cs

    r9123 r9391  
    2626    Access.IRoleVerifier RoleVerifier { get; }
    2727    IAuthorizationManager AuthorizationManager { get; }
     28    IHiveDtoDao HiveDtoDao { get; }
    2829    IHiveDao HiveDao { get; }
    2930    IEventManager EventManager { get; }
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs

    r8051 r9391  
    3636      if (ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Slave)) return; // slave-users can access all tasks
    3737
    38       Permission permission = ServiceLocator.Instance.HiveDao.GetPermissionForTask(taskId, ServiceLocator.Instance.UserManager.CurrentUserId);
     38      Permission permission = ServiceLocator.Instance.HiveDtoDao.GetPermissionForTask(taskId, ServiceLocator.Instance.UserManager.CurrentUserId);
    3939      if (permission == Permission.NotAllowed || (permission != DT.Convert.ToEntity(requiredPermission) && DT.Convert.ToEntity(requiredPermission) == Permission.Full))
    4040        throw new SecurityException("Current user is not authorized to access task");
     
    4242
    4343    public void AuthorizeForJob(Guid jobId, DT.Permission requiredPermission) {
    44       Permission permission = ServiceLocator.Instance.HiveDao.GetPermissionForJob(jobId, ServiceLocator.Instance.UserManager.CurrentUserId);
     44      Permission permission = ServiceLocator.Instance.HiveDtoDao.GetPermissionForJob(jobId, ServiceLocator.Instance.UserManager.CurrentUserId);
    4545      if (permission == Permission.NotAllowed || (permission != DT.Convert.ToEntity(requiredPermission) && DT.Convert.ToEntity(requiredPermission) == Permission.Full))
    4646        throw new SecurityException("Current user is not authorized to access task");
     
    4848
    4949    public void AuthorizeForResourceAdministration(Guid resourceId) {
    50       Resource resource = DT.Convert.ToEntity(ServiceLocator.Instance.HiveDao.GetResource(resourceId));
     50      Resource resource = DT.Convert.ToEntity(ServiceLocator.Instance.HiveDtoDao.GetResource(resourceId));
    5151      if (resource.OwnerUserId != ServiceLocator.Instance.UserManager.CurrentUserId && !ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Administrator))
    5252        throw new SecurityException("Current user is not authorized to access resource");
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Manager/EventManager.cs

    r9257 r9391  
    3232  /// </summary>
    3333  public class EventManager : IEventManager {
    34     private IHiveDao dao {
    35       get { return ServiceLocator.Instance.HiveDao; }
     34    private IHiveDtoDao dao {
     35      get { return ServiceLocator.Instance.HiveDtoDao; }
    3636    }
    3737    private IAuthorizationManager auth {
     
    7878      //we have to find another way to deal with this. 
    7979      //until then the next line is commented out...
    80       //stats.UserStatistics = dao.GetUserStatistics();
     80      //stats.UserStatistics = dtoDao.GetUserStatistics();
    8181      dao.AddStatistics(stats);
    8282    }
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs

    r9385 r9391  
    2424using System.Linq;
    2525using System.Threading;
    26 using HeuristicLab.Services.Hive.DataTransfer;
    27 using DA = HeuristicLab.Services.Hive.DataAccess;
     26using HeuristicLab.Services.Hive.DataAccess;
     27using Heartbeat = HeuristicLab.Services.Hive.DataTransfer.Heartbeat;
    2828
    2929namespace HeuristicLab.Services.Hive {
     
    4848      List<MessageContainer> actions = new List<MessageContainer>();
    4949
    50       DA.Slave slave = null;
     50      Slave slave = null;
    5151      trans.UseTransaction(() => {
    52         slave = dao.GetSlaveDA(heartbeat.SlaveId);
     52        slave = dao.GetSlaveById(heartbeat.SlaveId);
    5353
    5454        if (slave == null) {
     
    6767          slave.CpuUtilization = heartbeat.CpuUtilization;
    6868          slave.IsAllowedToCalculate = SlaveIsAllowedToCalculate(slave.ResourceId);
    69           slave.SlaveState = (heartbeat.JobProgress != null && heartbeat.JobProgress.Count > 0) ? DA.SlaveState.Calculating : DA.SlaveState.Idle;
     69          slave.SlaveState = (heartbeat.JobProgress != null && heartbeat.JobProgress.Count > 0) ? SlaveState.Calculating : SlaveState.Idle;
    7070          slave.LastHeartbeat = DateTime.Now;
    7171
    72           dao.UpdateSlaveDA(slave);
     72          dao.UpdateSlave(slave);
    7373        }
    7474      });
     
    8686            mutexAquired = mutex.WaitOne(Properties.Settings.Default.SchedulingPatience);
    8787            if (!mutexAquired)
    88               DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling could not be aquired.");
     88              LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling could not be aquired.");
    8989            else {
    9090              trans.UseTransaction(() => {
    9191                IEnumerable<TaskInfoForScheduler> availableTasks = null;
    92                 availableTasks = taskScheduler.Schedule(dao.GetWaitingTasksDA(slave).ToArray());
     92                availableTasks = taskScheduler.Schedule(dao.GetWaitingTasks(slave).ToArray());
    9393                if (availableTasks.Any()) {
    9494                  var task = availableTasks.First();
     
    100100          }
    101101          catch (AbandonedMutexException) {
    102             DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling has been abandoned.");
     102            LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling has been abandoned.");
    103103          }
    104104          catch (Exception ex) {
    105             DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager threw an exception in ProcessHeartbeat: " + ex.ToString());
     105            LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager threw an exception in ProcessHeartbeat: " + ex.ToString());
    106106          }
    107107          finally {
     
    113113    }
    114114
    115     private void AssignJob(DA.Slave slave, Guid taskId) {
    116       var task = dao.UpdateTaskStateDA(taskId, DataAccess.TaskState.Transferring, slave.ResourceId, null, null);
     115    private void AssignJob(Slave slave, Guid taskId) {
     116      var task = dao.UpdateTaskState(taskId, DataAccess.TaskState.Transferring, slave.ResourceId, null, null);
    117117
    118118      // from now on the task has some time to send the next heartbeat (ApplicationConstants.TransferringJobHeartbeatTimeout)
    119119      task.LastHeartbeat = DateTime.Now;
    120       dao.UpdateTaskDA(task);
     120      dao.UpdateTask(task);
    121121    }
    122122
     
    137137        foreach (var jobProgress in heartbeat.JobProgress) {
    138138          trans.UseTransaction(() => {
    139             var curTask = dao.GetTaskDA(jobProgress.Key);
     139            var curTask = dao.GetTaskById(jobProgress.Key);
    140140            if (curTask == null) {
    141141              // task does not exist in db
    142142              actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, jobProgress.Key));
    143               DA.LogFactory.GetLogger(this.GetType().Namespace).Log("Task on slave " + heartbeat.SlaveId + " does not exist in DB: " + jobProgress.Key);
     143              LogFactory.GetLogger(this.GetType().Namespace).Log("Task on slave " + heartbeat.SlaveId + " does not exist in DB: " + jobProgress.Key);
    144144            } else {
    145145              var currentStateLog = curTask.StateLogs.Last();
     
    147147                // assigned slave does not match heartbeat
    148148                actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curTask.TaskId));
    149                 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not supposed to calculate task: " + curTask);
     149                LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not supposed to calculate task: " + curTask);
    150150              } else if (!TaskIsAllowedToBeCalculatedBySlave(heartbeat.SlaveId, curTask)) {
    151151                // assigned resources ids of task do not match with slaveId (and parent resourceGroupIds); this might happen when slave is moved to different group
     
    157157
    158158                switch (curTask.Command) {
    159                   case DA.Command.Stop:
     159                  case Command.Stop:
    160160                    actions.Add(new MessageContainer(MessageContainer.MessageType.StopTask, curTask.TaskId));
    161161                    break;
    162                   case DA.Command.Pause:
     162                  case Command.Pause:
    163163                    actions.Add(new MessageContainer(MessageContainer.MessageType.PauseTask, curTask.TaskId));
    164164                    break;
    165                   case DA.Command.Abort:
     165                  case Command.Abort:
    166166                    actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curTask.TaskId));
    167167                    break;
    168168                }
    169                 dao.UpdateTaskDA(curTask);
     169                dao.UpdateTask(curTask);
    170170              }
    171171            }
     
    176176    }
    177177
    178     private bool TaskIsAllowedToBeCalculatedBySlave(Guid slaveId, DA.Task curTask) {
    179       var assignedResourceIds = dao.GetAssignedResourcesIdsDA(curTask.TaskId);
    180       var slaveResourceIds = dao.GetParentResourcesIDsDA(slaveId).ToArray();
     178    private bool TaskIsAllowedToBeCalculatedBySlave(Guid slaveId, Task curTask) {
     179      var assignedResourceIds = dao.GetAssignedResourcesIds(curTask.TaskId);
     180      var slaveResourceIds = dao.GetParentResourcesIDs(slaveId).ToArray();
    181181      return assignedResourceIds.Any(r => slaveResourceIds.Contains(r));
    182182    }
    183183
    184184    private bool SlaveIsAllowedToCalculate(Guid slaveId) {
    185       var downtimes = dao.GetNumberOfDowntimesFromParentResourcesAtCurrentTimeDA(slaveId, DA.DowntimeType.Offline);
     185      var downtimes = dao.GetNumberOfDowntimesFromParentResourcesAtCurrentTime(slaveId, DowntimeType.Offline);
    186186      // the slave may only calculate if there is no downtime right now. this needs to be checked for every parent resource also
    187187      return downtimes.All(x => x == 0);
     
    189189
    190190    private bool ShutdownSlaveComputer(Guid slaveId) {
    191       var downtimes = dao.GetNumberOfDowntimesFromParentResourcesAtCurrentTimeDA(slaveId, DA.DowntimeType.Shutdown);
     191      var downtimes = dao.GetNumberOfDowntimesFromParentResourcesAtCurrentTime(slaveId, DowntimeType.Shutdown);
    192192      return downtimes.Any(x => x != 0);
    193193    }
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs

    r9123 r9391  
    2727namespace HeuristicLab.Services.Hive {
    2828  public class RoundRobinTaskScheduler : ITaskScheduler {
    29     private IHiveDao dao {
    30       get { return ServiceLocator.Instance.HiveDao; }
     29    private IHiveDtoDao dao {
     30      get { return ServiceLocator.Instance.HiveDtoDao; }
    3131    }
    3232
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/ServiceLocator.cs

    r9123 r9391  
    3232      }
    3333      set { instance = value; }
     34    }
     35
     36    private IHiveDtoDao hiveDtoDao;
     37    public IHiveDtoDao HiveDtoDao {
     38      get {
     39        if (hiveDtoDao == null) hiveDtoDao = new HiveDtoDao();
     40        return hiveDtoDao;
     41      }
    3442    }
    3543
Note: See TracChangeset for help on using the changeset viewer.