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); } }
public void AuthorizeForTask(Guid taskId, DT.Permission requiredPermission) { if (ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Slave)) return; // slave-users can access all tasks var pm = PersistenceManager; var taskDao = pm.TaskDao; pm.UseTransaction(() => { var task = taskDao.GetById(taskId); if (task == null) throw new SecurityException(NOT_AUTHORIZED); AuthorizeJob(pm, task.JobId, requiredPermission); }); }
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; } }
public static void ToEntity(DT.StateLog source, DB.StateLog target) { if ((source != null) && (target != null)) { target.StateLogId = source.Id; target.DateTime = source.DateTime; target.Exception = source.Exception; target.TaskId = source.TaskId; target.SlaveId = source.SlaveId; target.State = Convert.ToEntity(source.State); target.UserId = source.UserId; } }
public static void ToEntity(DT.SlaveStatistics source, DB.SlaveStatistics target) { if ((source != null) && (target != null)) { target.StatisticsId = source.Id; target.SlaveId = source.SlaveId; target.Cores = source.Cores; target.CpuUtilization = source.CpuUtilization; target.FreeCores = source.FreeCores; target.FreeMemory = source.FreeMemory; target.Memory = source.Memory; } }
public static DB.SlaveState ToEntity(DT.SlaveState source) { if (source == DT.SlaveState.Calculating) { return DB.SlaveState.Calculating; } else if (source == DT.SlaveState.Idle) { return DB.SlaveState.Idle; } else if (source == DT.SlaveState.Offline) { return DB.SlaveState.Offline; } else return DB.SlaveState.Offline; }
public static void ToEntity(DT.UserPriority source, DB.UserPriority target) { if ((source != null) && (target != null)) { target.UserId = source.Id; target.DateEnqueued = source.DateEnqueued; } }
public static DB.Permission ToEntity(DT.Permission source) { if (source == DT.Permission.Full) { return DB.Permission.Full; } else if (source == DT.Permission.NotAllowed) { return DB.Permission.NotAllowed; } else if (source == DT.Permission.Read) { return DB.Permission.Read; } else return DB.Permission.NotAllowed; }
public static DB.CpuArchitecture ToEntity(DT.CpuArchitecture source) { if (source == DT.CpuArchitecture.x64) { return DB.CpuArchitecture.x64; } else if (source == DT.CpuArchitecture.x86) { return DB.CpuArchitecture.x86; } else return DB.CpuArchitecture.x86; }
public static DB.PluginData ToEntity(DT.PluginData source) { if (source == null) return null; var entity = new DB.PluginData(); ToEntity(source, entity); return entity; }
public static void ToEntity(DT.UserStatistics source, DB.UserStatistics target) { if ((source != null) && (target != null)) { target.StatisticsId = source.Id; target.UserId = source.UserId; target.UsedCores = source.UsedCores; target.ExecutionTimeMs = source.ExecutionTime.TotalMilliseconds; target.ExecutionTimeMsFinishedJobs = source.ExecutionTimeFinishedJobs.TotalMilliseconds; target.StartToEndTimeMs = source.StartToEndTime.TotalMilliseconds; } }
public static void ToEntity(DT.JobPermission source, DB.JobPermission target) { if ((source != null) && (target != null)) { target.JobId = source.JobId; target.GrantedUserId = source.GrantedUserId; target.GrantedByUserId = source.GrantedByUserId; target.Permission = Convert.ToEntity(source.Permission); } }
public static void ToEntity(DT.Plugin source, DB.Plugin target) { if ((source != null) && (target != null)) { target.PluginId = source.Id; target.Name = source.Name; target.Version = source.Version.ToString(); target.UserId = source.UserId; target.DateCreated = source.DateCreated; target.Hash = source.Hash; } }
public static void ToEntity(DT.Job source, DB.Job target) { if ((source != null) && (target != null)) { target.JobId = source.Id; target.Description = source.Description; target.Name = source.Name; target.OwnerUserId = source.OwnerUserId; target.DateCreated = source.DateCreated; target.ResourceIds = source.ResourceNames; } }
public static DB.Job ToEntity(DT.Job source) { if (source == null) return null; var entity = new DB.Job(); ToEntity(source, entity); return entity; }
public static void ToEntity(DT.Downtime source, DB.Downtime target) { if ((source != null) && (target != null)) { target.DowntimeId = source.Id; target.AllDayEvent = source.AllDayEvent; target.EndDate = source.EndDate; target.Recurring = source.Recurring; target.RecurringId = source.RecurringId; target.ResourceId = source.ResourceId; target.StartDate = source.StartDate; target.DowntimeType = source.DowntimeType; } }
public static void ToEntity(DT.Statistics source, DB.Statistics target) { if ((source != null) && (target != null)) { target.StatisticsId = source.Id; target.Timestamp = source.TimeStamp; } }
public static void ToEntity(DT.PluginData source, DB.PluginData target) { if ((source != null) && (target != null)) { target.PluginDataId = source.Id; target.PluginId = source.PluginId; target.Data = source.Data; target.FileName = source.FileName; } }
public static DB.UserStatistics ToEntity(DT.UserStatistics source) { if (source == null) return null; var entity = new DB.UserStatistics(); ToEntity(source, entity); return entity; }
public static void ToEntity(DT.SlaveGroup source, DB.SlaveGroup target) { if ((source != null) && (target != null)) { target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId; target.HbInterval = source.HbInterval; target.OwnerUserId = source.OwnerUserId; } }
public static DB.TaskState ToEntity(DT.TaskState source) { if (source == DT.TaskState.Aborted) { return DB.TaskState.Aborted; } else if (source == DT.TaskState.Calculating) { return DB.TaskState.Calculating; } else if (source == DT.TaskState.Failed) { return DB.TaskState.Failed; } else if (source == DT.TaskState.Finished) { return DB.TaskState.Finished; } else if (source == DT.TaskState.Offline) { return DB.TaskState.Offline; } else if (source == DT.TaskState.Paused) { return DB.TaskState.Paused; } else if (source == DT.TaskState.Transferring) { return DB.TaskState.Transferring; } else if (source == DT.TaskState.Waiting) { return DB.TaskState.Waiting; } else return DB.TaskState.Failed; }
public static DB.Slave ToEntity(DT.Slave source) { if (source == null) return null; var entity = new DB.Slave(); ToEntity(source, entity); return entity; }
public static DB.Command? ToEntity(DT.Command? source) { if (source.HasValue) { if (source == DT.Command.Abort) { return DB.Command.Abort; } else if (source == DT.Command.Pause) { return DB.Command.Pause; } else if (source == DT.Command.Stop) { return DB.Command.Stop; } else return DB.Command.Pause; } else return null; }
public static void ToEntity(DT.Slave source, DB.Slave target) { if ((source != null) && (target != null)) { target.ResourceId = source.Id; target.ParentResourceId = source.ParentResourceId; target.Cores = source.Cores; target.CpuSpeed = source.CpuSpeed; target.FreeCores = source.FreeCores; target.FreeMemory = source.FreeMemory; target.IsAllowedToCalculate = source.IsAllowedToCalculate; target.Memory = source.Memory; target.Name = source.Name; target.SlaveState = Convert.ToEntity(source.SlaveState); target.CpuArchitecture = Convert.ToEntity(source.CpuArchitecture); target.OperatingSystem = source.OperatingSystem; target.LastHeartbeat = source.LastHeartbeat; target.CpuUtilization = source.CpuUtilization; target.HbInterval = source.HbInterval; target.IsDisposable = source.IsDisposable; target.OwnerUserId = source.OwnerUserId; } }
public static DB.Task ToEntity(DT.Task source) { if (source == null) return null; var entity = new DB.Task(); ToEntity(source, entity); return entity; }
public static void ToEntity(DT.TaskData source, DB.TaskData target) { if ((source != null) && (target != null)) { target.TaskId = source.TaskId; target.Data = source.Data; target.LastUpdate = source.LastUpdate; } }
public static DB.UserPriority ToEntity(DT.UserPriority source) { if (source == null) return null; var entity = new DB.UserPriority(); ToEntity(source, entity); return entity; }
public static void ToEntity(DT.ResourcePermission source, DB.ResourcePermission target) { if ((source != null) && (target != null)) { target.ResourceId = source.ResourceId; target.GrantedUserId = source.GrantedUserId; target.GrantedByUserId = source.GrantedByUserId; } }
public static DB.ResourcePermission ToEntity(DT.ResourcePermission source) { if (source == null) return null; var entity = new DB.ResourcePermission(); ToEntity(source, entity); return entity; }
public static DB.StateLog ToEntity(DT.StateLog source) { if (source == null) return null; var entity = new DB.StateLog(); ToEntity(source, entity); return entity; }