Esempio n. 1
0
        public static void CopyToEntity(this DT.Task source, DA.Task target)
        {
            if ((source == null) || (target == null))
            {
                return;
            }
            target.TaskId                      = source.Id;
            target.State                       = source.State.ToEntity();
            target.ExecutionTimeMs             = source.ExecutionTime.TotalMilliseconds;
            target.LastHeartbeat               = source.LastHeartbeat;
            target.ParentTaskId                = source.ParentTaskId;
            target.Priority                    = source.Priority;
            target.CoresNeeded                 = source.CoresNeeded;
            target.MemoryNeeded                = source.MemoryNeeded;
            target.IsParentTask                = source.IsParentTask;
            target.FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished;
            target.Command                     = source.Command.ToEntity();
            target.JobId                       = source.JobId;
            var ids = target.RequiredPlugins.Select(x => x.PluginId);

            target.RequiredPlugins.AddRange(source.PluginsNeededIds
                                            .Where(x => !ids.Contains(x))
                                            .Select(x => new DA.RequiredPlugin {
                PluginId = x
            })
                                            );
            target.StateLogs.AddRange(source.StateLog
                                      .Where(x => x.Id == Guid.Empty)
                                      .Select(x => x.ToEntity())
                                      );
            // result.JobData missing
            // result.AssignedResources missing
        }
Esempio n. 2
0
        public Task GetTaskByDto(DT.Task taskDto)
        {
            var task = GetTaskById(taskDto.Id);

            DT.Convert.ToEntity(taskDto, task);
            return(task);
        }
Esempio n. 3
0
        public Guid AddTask(DT.Task task, DT.TaskData taskData, IEnumerable <Guid> resourceIds)
        {
            RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
            var pm = PersistenceManager;

            using (new PerformanceLogger("AddTask")) {
                var taskDao     = pm.TaskDao;
                var stateLogDao = pm.StateLogDao;
                var newTask     = task.ToEntity();
                newTask.JobData            = taskData.ToEntity();
                newTask.JobData.LastUpdate = DateTime.Now;
                newTask.AssignedResources.AddRange(resourceIds.Select(
                                                       x => new DA.AssignedResource {
                    ResourceId = x
                }));
                newTask.State = DA.TaskState.Waiting;
                return(pm.UseTransaction(() => {
                    taskDao.Save(newTask);
                    pm.SubmitChanges();
                    stateLogDao.Save(new DA.StateLog {
                        State = DA.TaskState.Waiting,
                        DateTime = DateTime.Now,
                        TaskId = newTask.TaskId,
                        UserId = UserManager.CurrentUserId,
                        SlaveId = null,
                        Exception = null
                    });
                    pm.SubmitChanges();
                    return newTask.TaskId;
                }, false, true));
            }
        }
Esempio n. 4
0
 public LightweightTask(Task task) {
   this.Id = task.Id;
   this.ExecutionTime = task.ExecutionTime;
   this.ParentTaskId = task.ParentTaskId;
   this.StateLog = new List<StateLog>(task.StateLog);
   this.State = task.State;
   this.Command = task.Command;
   this.LastTaskDataUpdate = task.LastTaskDataUpdate;
 }
Esempio n. 5
0
        public static DB.Task ToEntity(DT.Task source)
        {
            if (source == null)
            {
                return(null);
            }
            var entity = new DB.Task(); ToEntity(source, entity);

            return(entity);
        }
Esempio n. 6
0
        public static DA.Task ToEntity(this DT.Task source)
        {
            if (source == null)
            {
                return(null);
            }
            var result = new DA.Task();

            source.CopyToEntity(result);
            return(result);
        }
Esempio n. 7
0
        public void UpdateTask(DT.Task taskDto)
        {
            RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
            AuthorizationManager.AuthorizeForTask(taskDto.Id, Permission.Full);
            var pm = PersistenceManager;

            using (new PerformanceLogger("UpdateTask")) {
                var taskDao = pm.TaskDao;
                pm.UseTransaction(() => {
                    var task = taskDao.GetById(taskDto.Id);
                    taskDto.CopyToEntity(task);
                    pm.SubmitChanges();
                });
            }
        }
Esempio n. 8
0
        public Guid AddChildTask(Guid parentTaskId, DT.Task task, DT.TaskData taskData)
        {
            RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
            IEnumerable <Guid> resourceIds;
            var pm = PersistenceManager;

            using (new PerformanceLogger("AddChildTask")) {
                var assignedResourceDao = pm.AssignedResourceDao;
                resourceIds = pm.UseTransaction(() => {
                    return(assignedResourceDao.GetByTaskId(parentTaskId)
                           .Select(x => x.ResourceId)
                           .ToList());
                });
            }
            task.ParentTaskId = parentTaskId;
            return(AddTask(task, taskData, resourceIds));
        }
Esempio n. 9
0
 public static void ToEntityTaskOnly(DT.Task source, DB.Task target)
 {
     if ((source != null) && (target != null))
     {
         target.TaskId                      = source.Id;
         target.CoresNeeded                 = source.CoresNeeded;
         target.ExecutionTimeMs             = source.ExecutionTime.TotalMilliseconds;
         target.MemoryNeeded                = source.MemoryNeeded;
         target.ParentTaskId                = source.ParentTaskId;
         target.Priority                    = source.Priority;
         target.LastHeartbeat               = source.LastHeartbeat;
         target.State                       = Convert.ToEntity(source.State);
         target.IsParentTask                = source.IsParentTask;
         target.FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished;
         target.Command                     = Convert.ToEntity(source.Command);
         // RequiredPlugins are added by Dao
         target.JobId        = source.JobId;
         target.IsPrivileged = source.IsPrivileged;
     }
 }