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); } }
private void UpdateTaskState(IPersistenceManager pm, DA.Task task, DT.TaskState taskState, Guid? slaveId, Guid? userId, string exception) { var stateLogDao = pm.StateLogDao; var taskStateEntity = taskState.ToEntity(); if (task.Command == DA.Command.Pause && task.State == DA.TaskState.Paused || task.Command == DA.Command.Abort && task.State == DA.TaskState.Aborted || task.Command == DA.Command.Stop && task.State == DA.TaskState.Aborted) { task.Command = null; } else if (taskStateEntity == DA.TaskState.Paused && task.Command == null) { // slave paused and uploaded the task (no user-command) -> set waiting. taskStateEntity = DA.TaskState.Waiting; } stateLogDao.Save(new DA.StateLog { State = taskStateEntity, DateTime = DateTime.Now, TaskId = task.TaskId, UserId = userId, SlaveId = slaveId, Exception = exception }); task.State = taskStateEntity; }
public void UpdateDowntime(DT.Downtime downtimeDto) { RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); AuthorizationManager.AuthorizeForResourceAdministration(downtimeDto.ResourceId); var pm = PersistenceManager; using (new PerformanceLogger("UpdateDowntime")) { var downtimeDao = pm.DowntimeDao; pm.UseTransaction(() => { var downtime = downtimeDao.GetById(downtimeDto.Id); if (downtime != null) { downtimeDto.CopyToEntity(downtime); } else { downtimeDao.Save(downtimeDto.ToEntity()); } pm.SubmitChanges(); }); } }
public Guid AddDowntime(DT.Downtime downtimeDto) { RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); AuthorizationManager.AuthorizeForResourceAdministration(downtimeDto.ResourceId); var pm = PersistenceManager; using (new PerformanceLogger("AddDowntime")) { var downtimeDao = pm.DowntimeDao; return pm.UseTransaction(() => { var downtime = downtimeDao.Save(downtimeDto.ToEntity()); pm.SubmitChanges(); return downtime.ResourceId; }); } }
public void UpdateSlaveGroup(DT.SlaveGroup slaveGroupDto) { RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); var pm = PersistenceManager; using (new PerformanceLogger("UpdateSlaveGroup")) { var slaveGroupDao = pm.SlaveGroupDao; pm.UseTransaction(() => { var slaveGroup = slaveGroupDao.GetById(slaveGroupDto.Id); if (slaveGroup != null) { slaveGroupDto.CopyToEntity(slaveGroup); } else { slaveGroupDao.Save(slaveGroupDto.ToEntity()); } pm.SubmitChanges(); }); } }
public Guid AddSlave(DT.Slave slaveDto) { RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator); var pm = PersistenceManager; using (new PerformanceLogger("AddSlave")) { var slaveDao = pm.SlaveDao; return pm.UseTransaction(() => { var slave = slaveDao.Save(slaveDto.ToEntity()); pm.SubmitChanges(); return slave.ResourceId; }); } }
public Guid AddSlaveGroup(DT.SlaveGroup slaveGroupDto) { RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); var pm = PersistenceManager; using (new PerformanceLogger("AddSlaveGroup")) { var slaveGroupDao = pm.SlaveGroupDao; return pm.UseTransaction(() => { if (slaveGroupDto.Id == Guid.Empty) { slaveGroupDto.Id = Guid.NewGuid(); } var slaveGroup = slaveGroupDao.Save(slaveGroupDto.ToEntity()); pm.SubmitChanges(); return slaveGroup.ResourceId; }); } }
public Guid AddPlugin(DT.Plugin plugin, List<DT.PluginData> pluginData) { RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); var pm = PersistenceManager; using (new PerformanceLogger("AddPlugin")) { var pluginDao = pm.PluginDao; plugin.UserId = UserManager.CurrentUserId; plugin.DateCreated = DateTime.Now; return pm.UseTransaction(() => { var pluginEntity = pluginDao.GetByHash(plugin.Hash).SingleOrDefault(); if (pluginEntity != null) { throw new FaultException<PluginAlreadyExistsFault>(new PluginAlreadyExistsFault(pluginEntity.PluginId)); } pluginEntity = plugin.ToEntity(); foreach (var data in pluginData) { data.PluginId = default(Guid); // real id will be assigned from linq2sql pluginEntity.PluginData.Add(data.ToEntity()); } pluginDao.Save(pluginEntity); pm.SubmitChanges(); return pluginEntity.PluginId; }); } }
public void Hello(DT.Slave slaveInfo) { RoleVerifier.AuthenticateForAnyRole(HiveRoles.Slave); if (UserManager.CurrentUser.UserName != "hiveslave") { slaveInfo.OwnerUserId = UserManager.CurrentUserId; } var pm = PersistenceManager; using (new PerformanceLogger("Hello")) { var slaveDao = pm.SlaveDao; pm.UseTransaction(() => { var slave = slaveDao.GetById(slaveInfo.Id); if (slave == null) { slaveDao.Save(slaveInfo.ToEntity()); } else { bool oldIsAllowedToCalculate = slave.IsAllowedToCalculate; Guid? oldParentResourceId = slave.ParentResourceId; slaveInfo.CopyToEntity(slave); slave.IsAllowedToCalculate = oldIsAllowedToCalculate; slave.ParentResourceId = oldParentResourceId; slave.LastHeartbeat = DateTime.Now; slave.SlaveState = DA.SlaveState.Idle; } pm.SubmitChanges(); }); } }
public void GrantPermission(Guid jobId, Guid grantedUserId, DT.Permission permission) { RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); AuthorizationManager.AuthorizeForJob(jobId, Permission.Full); var pm = PersistenceManager; using (new PerformanceLogger("GrantPermission")) { var jobPermissionDao = pm.JobPermissionDao; var currentUserId = UserManager.CurrentUserId; pm.UseTransaction(() => { jobPermissionDao.SetJobPermission(jobId, currentUserId, grantedUserId, permission.ToEntity()); pm.SubmitChanges(); }); } }
public Guid AddJob(DT.Job jobDto) { RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); var pm = PersistenceManager; using (new PerformanceLogger("AddJob")) { var jobDao = pm.JobDao; var userPriorityDao = pm.UserPriorityDao; return pm.UseTransaction(() => { jobDto.OwnerUserId = UserManager.CurrentUserId; jobDto.DateCreated = DateTime.Now; var job = jobDao.Save(jobDto.ToEntity()); if (userPriorityDao.GetById(jobDto.OwnerUserId) == null) { userPriorityDao.Save(new DA.UserPriority { UserId = jobDto.OwnerUserId, DateEnqueued = jobDto.DateCreated }); } pm.SubmitChanges(); return job.JobId; }); } }
private void AuthorizeJob(IPersistenceManager pm, Guid jobId, DT.Permission requiredPermission) { var requiredPermissionEntity = requiredPermission.ToEntity(); DA.Permission permission = GetPermissionForJob(pm, jobId, UserManager.CurrentUserId); if (permission == Permission.NotAllowed || ((permission != requiredPermissionEntity) && requiredPermissionEntity == Permission.Full)) { throw new SecurityException(NOT_AUTHORIZED); } }