Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/23/13 10:37:45 (12 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/HeuristicLab.Services.Hive/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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/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    }
Note: See TracChangeset for help on using the changeset viewer.