- Timestamp:
- 09/02/15 13:16:18 (9 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 9 deleted
- 13 edited
- 8 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Services.Hive
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/DataTransfer/Task.cs
r12012 r12931 44 44 [DataMember] 45 45 public Guid JobId { get; set; } 46 [DataMember]47 public bool IsPrivileged { get; set; }48 46 49 47 public Task() { -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
r11623 r12931 118 118 </ItemGroup> 119 119 <ItemGroup> 120 <Compile Include="Convert .cs" />120 <Compile Include="Converter.cs" /> 121 121 <Compile Include="DataTransfer\Command.cs" /> 122 122 <Compile Include="DataTransfer\UserPriority.cs" /> … … 139 139 <Compile Include="DataTransfer\SlaveGroup.cs" /> 140 140 <Compile Include="DataTransfer\SlaveState.cs" /> 141 <Compile Include="DataTransfer\SlaveStatistics.cs" />142 141 <Compile Include="DataTransfer\StateLog.cs" /> 143 <Compile Include="DataTransfer\Statistics.cs" /> 144 <Compile Include="DataTransfer\UserStatistics.cs" /> 145 <Compile Include="OptimizedHiveDao.cs" /> 146 <Compile Include="HiveDao.cs" /> 142 <Compile Include="HiveStatisticsGenerator.cs" /> 143 <Compile Include="Interfaces\IStatisticsGenerator.cs" /> 147 144 <Compile Include="HiveJanitor.cs" /> 148 145 <Compile Include="HiveOperationContext.cs" /> 149 <Compile Include="Interfaces\IOptimizedHiveDao.cs" />150 <Compile Include="Interfaces\IHiveDao.cs" />151 146 <Compile Include="Interfaces\ITaskScheduler.cs" /> 147 <Compile Include="PerformanceLogger.cs" /> 152 148 <Compile Include="Scheduler\TaskInfoForScheduler.cs" /> 153 149 <Compile Include="Scheduler\JobInfoForScheduler.cs" /> 154 150 <Compile Include="Scheduler\RoundRobinTaskScheduler.cs" /> 155 <Compile Include="Settings.cs" />156 151 <None Include="app.config" /> 157 152 <None Include="Plugin.cs.frame" /> … … 182 177 </ItemGroup> 183 178 <ItemGroup> 179 <ProjectReference Include="..\..\HeuristicLab.Services.Access.DataAccess\3.3\HeuristicLab.Services.Access.DataAccess-3.3.csproj"> 180 <Project>{0F652437-998A-4EAB-8BF1-444B5FE8CE97}</Project> 181 <Name>HeuristicLab.Services.Access.DataAccess-3.3</Name> 182 </ProjectReference> 184 183 <ProjectReference Include="..\..\HeuristicLab.Services.Access\3.3\HeuristicLab.Services.Access-3.3.csproj"> 185 184 <Project>{9FAC0B23-2730-452A-9BA0-D7CA1746C541}</Project> -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs
r12012 r12931 23 23 using System.Threading; 24 24 using HeuristicLab.Services.Hive.DataAccess; 25 using HeuristicLab.Services.Hive.DataAccess.Interfaces; 25 26 26 27 namespace HeuristicLab.Services.Hive { 27 28 public class HiveJanitor { 28 29 private bool stop; 29 private AutoResetEvent waitHandle; 30 private AutoResetEvent cleanupWaitHandle; 31 private AutoResetEvent generateStatisticsWaitHandle; 30 32 31 private DataAccess.ITransactionManager trans{32 get { return ServiceLocator.Instance. TransactionManager; }33 private IPersistenceManager PersistenceManager { 34 get { return ServiceLocator.Instance.PersistenceManager; } 33 35 } 34 35 private IEventManager eventManager { 36 private IEventManager EventManager { 36 37 get { return ServiceLocator.Instance.EventManager; } 37 38 } 38 39 39 private I HiveDao dao{40 get { return ServiceLocator.Instance. HiveDao; }40 private IStatisticsGenerator StatisticsGenerator { 41 get { return ServiceLocator.Instance.StatisticsGenerator; } 41 42 } 42 43 43 44 public HiveJanitor() { 44 45 stop = false; 45 waitHandle = new AutoResetEvent(true); 46 cleanupWaitHandle = new AutoResetEvent(false); 47 generateStatisticsWaitHandle = new AutoResetEvent(false); 46 48 } 47 49 48 50 public void StopJanitor() { 49 51 stop = true; 50 waitHandle.Set(); 52 cleanupWaitHandle.Set(); 53 generateStatisticsWaitHandle.Set(); 51 54 } 52 55 53 public void Run() { 56 public void RunCleanup() { 57 var pm = PersistenceManager; 54 58 while (!stop) { 55 59 try { 56 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup ");60 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup."); 57 61 bool cleanup = false; 58 trans.UseTransaction(() => { 59 DateTime lastCleanup = dao.GetLastCleanup(); 60 if (DateTime.Now - lastCleanup > HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval) { 61 dao.SetLastCleanup(DateTime.Now); 62 63 var lifecycleDao = pm.LifecycleDao; 64 pm.UseTransaction(() => { 65 var lifecycle = lifecycleDao.GetLastLifecycle(); 66 if (lifecycle == null 67 || DateTime.Now - lifecycle.LastCleanup > Properties.Settings.Default.CleanupInterval) { 68 lifecycleDao.UpdateLifecycle(); 62 69 cleanup = true; 63 70 } 71 pm.SubmitChanges(); 64 72 }, true); 65 73 66 74 if (cleanup) { 67 eventManager.Cleanup();75 EventManager.Cleanup(); 68 76 } 69 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished ");77 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished."); 70 78 } 71 79 catch (Exception e) { 72 80 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e.ToString())); 73 81 } 74 waitHandle.WaitOne(HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval);82 cleanupWaitHandle.WaitOne(Properties.Settings.Default.CleanupInterval); 75 83 } 76 waitHandle.Close(); 84 cleanupWaitHandle.Close(); 85 } 86 87 public void RunGenerateStatistics() { 88 while (!stop) { 89 try { 90 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting generate statistics."); 91 StatisticsGenerator.GenerateStatistics(); 92 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: generate statistics finished."); 93 } 94 catch (Exception e) { 95 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e)); 96 } 97 98 generateStatisticsWaitHandle.WaitOne(Properties.Settings.Default.GenerateStatisticsInterval); 99 } 100 101 generateStatisticsWaitHandle.Close(); 77 102 } 78 103 } -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/HiveRoles.cs
r12012 r12931 25 25 public const string Slave = "Hive Slave"; 26 26 public const string Client = "Hive User"; 27 public const string IsAllowedPrivileged = "Hive IsAllowedPrivileged";28 27 } 29 28 } -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/Interfaces/IServiceLocator.cs
r12012 r12931 20 20 #endregion 21 21 22 using HeuristicLab.Services.Hive.DataAccess; 22 using HeuristicLab.Services.Hive.DataAccess.Interfaces; 23 using HeuristicLab.Services.Hive.Manager; 23 24 24 25 namespace HeuristicLab.Services.Hive { … … 26 27 Access.IRoleVerifier RoleVerifier { get; } 27 28 IAuthorizationManager AuthorizationManager { get; } 28 IHiveDao HiveDao { get; } 29 IOptimizedHiveDao OptimizedHiveDao { get; } 29 IPersistenceManager PersistenceManager { get; } 30 30 IEventManager EventManager { get; } 31 I TransactionManager TransactionManager { get; }31 IStatisticsGenerator StatisticsGenerator { get; } 32 32 Access.IUserManager UserManager { get; } 33 33 HeartbeatManager HeartbeatManager { get; } -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r12012 r12931 22 22 using System; 23 23 using System.Security; 24 using HeuristicLab.Services.Access; 24 25 using HeuristicLab.Services.Hive.DataAccess; 26 using HeuristicLab.Services.Hive.DataAccess.Interfaces; 27 using DA = HeuristicLab.Services.Hive.DataAccess; 25 28 using DT = HeuristicLab.Services.Hive.DataTransfer; 26 29 … … 28 31 namespace HeuristicLab.Services.Hive { 29 32 public class AuthorizationManager : IAuthorizationManager { 33 34 private const string NOT_AUTHORIZED = "Current user is not authorized to access the requested resource"; 35 private IPersistenceManager PersistenceManager { 36 get { return ServiceLocator.Instance.PersistenceManager; } 37 } 38 39 private IUserManager UserManager { 40 get { return ServiceLocator.Instance.UserManager; } 41 } 42 43 private IRoleVerifier RoleVerifier { 44 get { return ServiceLocator.Instance.RoleVerifier; } 45 } 46 30 47 public void Authorize(Guid userId) { 31 48 if (userId != ServiceLocator.Instance.UserManager.CurrentUserId) 32 throw new SecurityException( "Current user is not authorized to access object");49 throw new SecurityException(NOT_AUTHORIZED); 33 50 } 34 51 35 52 public void AuthorizeForTask(Guid taskId, DT.Permission requiredPermission) { 36 53 if (ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Slave)) return; // slave-users can access all tasks 37 38 Permission permission = ServiceLocator.Instance.HiveDao.GetPermissionForTask(taskId, ServiceLocator.Instance.UserManager.CurrentUserId); 39 if (permission == Permission.NotAllowed || (permission != DT.Convert.ToEntity(requiredPermission) && DT.Convert.ToEntity(requiredPermission) == Permission.Full)) 40 throw new SecurityException("Current user is not authorized to access task"); 54 var pm = PersistenceManager; 55 var taskDao = pm.TaskDao; 56 pm.UseTransaction(() => { 57 var task = taskDao.GetById(taskId); 58 if (task == null) throw new SecurityException(NOT_AUTHORIZED); 59 AuthorizeJob(pm, task.JobId, requiredPermission); 60 }); 41 61 } 42 62 43 63 public void AuthorizeForJob(Guid jobId, DT.Permission requiredPermission) { 44 Permission permission = ServiceLocator.Instance.HiveDao.GetPermissionForJob(jobId, ServiceLocator.Instance.UserManager.CurrentUserId); 45 if (permission == Permission.NotAllowed || (permission != DT.Convert.ToEntity(requiredPermission) && DT.Convert.ToEntity(requiredPermission) == Permission.Full)) 46 throw new SecurityException("Current user is not authorized to access task"); 64 var pm = PersistenceManager; 65 pm.UseTransaction(() => { 66 AuthorizeJob(pm, jobId, requiredPermission); 67 }); 47 68 } 48 69 49 70 public void AuthorizeForResourceAdministration(Guid resourceId) { 50 Resource resource = DT.Convert.ToEntity(ServiceLocator.Instance.HiveDao.GetResource(resourceId)); 51 if (resource.OwnerUserId != ServiceLocator.Instance.UserManager.CurrentUserId && !ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Administrator)) 52 throw new SecurityException("Current user is not authorized to access resource"); 71 var pm = PersistenceManager; 72 var resourceDao = pm.ResourceDao; 73 pm.UseTransaction(() => { 74 var resource = resourceDao.GetById(resourceId); 75 if (resource == null) throw new SecurityException(NOT_AUTHORIZED); 76 if (resource.OwnerUserId != UserManager.CurrentUserId 77 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { 78 throw new SecurityException(NOT_AUTHORIZED); 79 } 80 }); 81 } 82 83 private DA.Permission GetPermissionForJob(IPersistenceManager pm, Guid jobId, Guid userId) { 84 var jobDao = pm.JobDao; 85 var jobPermissionDao = pm.JobPermissionDao; 86 var job = jobDao.GetById(jobId); 87 if (job == null) return DA.Permission.NotAllowed; 88 if (job.OwnerUserId == userId) return DA.Permission.Full; 89 var jobPermission = jobPermissionDao.GetByJobAndUserId(jobId, userId); 90 if (jobPermission == null) return DA.Permission.NotAllowed; 91 return jobPermission.Permission; 92 } 93 94 private void AuthorizeJob(IPersistenceManager pm, Guid jobId, DT.Permission requiredPermission) { 95 var requiredPermissionEntity = requiredPermission.ToEntity(); 96 DA.Permission permission = GetPermissionForJob(pm, jobId, UserManager.CurrentUserId); 97 if (permission == Permission.NotAllowed 98 || ((permission != requiredPermissionEntity) && requiredPermissionEntity == Permission.Full)) { 99 throw new SecurityException(NOT_AUTHORIZED); 100 } 53 101 } 54 102 } -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/Properties/Settings.Designer.cs
r11623 r12931 1 1 //------------------------------------------------------------------------------ 2 2 // <auto-generated> 3 // This code was generated by a tool.4 // Runtime Version:4.0.30319.340143 // Dieser Code wurde von einem Tool generiert. 4 // Laufzeitversion:4.0.30319.42000 5 5 // 6 // Changes to this file may cause incorrect behavior and will be lost if7 // the code is regenerated.6 // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn 7 // der Code erneut generiert wird. 8 8 // </auto-generated> 9 9 //------------------------------------------------------------------------------ … … 13 13 14 14 [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "1 2.0.0.0")]15 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 16 public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 17 … … 86 86 } 87 87 } 88 89 [global::System.Configuration.ApplicationScopedSettingAttribute()] 90 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 91 [global::System.Configuration.DefaultSettingValueAttribute("True")] 92 public bool ProfileServicePerformance { 93 get { 94 return ((bool)(this["ProfileServicePerformance"])); 95 } 96 } 97 98 [global::System.Configuration.ApplicationScopedSettingAttribute()] 99 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 100 [global::System.Configuration.DefaultSettingValueAttribute("00:03:00")] 101 public global::System.TimeSpan GenerateStatisticsInterval { 102 get { 103 return ((global::System.TimeSpan)(this["GenerateStatisticsInterval"])); 104 } 105 } 88 106 } 89 107 } -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/Properties/Settings.settings
r9123 r12931 24 24 <Value Profile="(Default)">00:00:20</Value> 25 25 </Setting> 26 <Setting Name="ProfileServicePerformance" Type="System.Boolean" Scope="Application"> 27 <Value Profile="(Default)">True</Value> 28 </Setting> 29 <Setting Name="GenerateStatisticsInterval" Type="System.TimeSpan" Scope="Application"> 30 <Value Profile="(Default)">00:03:00</Value> 31 </Setting> 26 32 </Settings> 27 33 </SettingsFile> -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs
r12012 r12931 41 41 42 42 [OperationContract] 43 IEnumerable<Task> GetTasks();44 45 [OperationContract]46 IEnumerable<LightweightTask> GetLightweightTasks(IEnumerable<Guid> taskIds);47 48 [OperationContract]49 IEnumerable<LightweightTask> GetLightweightChildTasks(Guid? parentTaskId, bool recursive, bool includeParent);50 51 [OperationContract]52 43 IEnumerable<LightweightTask> GetLightweightJobTasks(Guid jobId); 53 44 … … 65 56 66 57 [OperationContract] 67 void DeleteTask(Guid taskId);68 69 [OperationContract]70 void DeleteChildTasks(Guid parentTaskId);71 72 [OperationContract]73 58 Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception); 74 59 #endregion … … 89 74 Job GetJob(Guid id); 90 75 91 /// <summary>92 /// Returns all task for the current user93 /// </summary>94 76 [OperationContract] 95 77 IEnumerable<Job> GetJobs(); 96 78 97 /// <summary>98 /// Returns all task in the hive (only for admins)99 /// </summary>100 /// <returns></returns>101 [OperationContract]102 IEnumerable<Job> GetAllJobs();103 104 79 [OperationContract] 105 80 Guid AddJob(Job jobDto); … … 122 97 IEnumerable<JobPermission> GetJobPermissions(Guid jobId); 123 98 99 // BackwardsCompatibility3.3 100 #region Backwards compatible code, remove with 3.4 124 101 [OperationContract] 125 102 bool IsAllowedPrivileged(); // current user may execute privileged task 126 103 #endregion 104 #endregion 127 105 128 106 #region Login Methods … … 142 120 [OperationContract] 143 121 Plugin GetPlugin(Guid pluginId); 144 145 [OperationContract]146 Plugin GetPluginByHash(byte[] hash);147 122 148 123 [OperationContract] … … 155 130 [OperationContract] 156 131 IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds); 157 158 [OperationContract]159 void DeletePlugin(Guid pluginId);160 132 #endregion 161 133 … … 171 143 #endregion 172 144 173 #region Resource Methods174 [OperationContract]175 IEnumerable<Resource> GetChildResources(Guid resourceId);176 #endregion177 178 145 #region Slave Methods 179 146 [OperationContract] … … 187 154 188 155 [OperationContract] 189 SlaveGroup GetSlaveGroup(Guid slaveGroupId);190 191 [OperationContract]192 156 IEnumerable<Slave> GetSlaves(); 193 157 … … 217 181 218 182 [OperationContract] 219 IEnumerable<Task> GetTasksByResourceId(Guid resourceId);220 221 [OperationContract]222 183 void TriggerEventManager(bool force); 223 184 … … 234 195 235 196 [OperationContract] 236 void UpdateDowntime(Downtime downtime );197 void UpdateDowntime(Downtime downtimeDto); 237 198 238 199 [OperationContract] … … 251 212 [OperationContract] 252 213 IEnumerable<UserPriority> GetUserPriorities(); 253 #endregion254 255 #region Statistics Methods256 [OperationContract]257 IEnumerable<Statistics> GetStatistics();258 [OperationContract]259 IEnumerable<Statistics> GetStatisticsForTimePeriod(DateTime from, DateTime to);260 214 #endregion 261 215 } -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/ServiceLocator.cs
r12012 r12931 21 21 22 22 using HeuristicLab.Services.Hive.DataAccess; 23 using HeuristicLab.Services.Hive.DataAccess.Interfaces; 24 using HeuristicLab.Services.Hive.DataAccess.Manager; 25 using HeuristicLab.Services.Hive.Manager; 23 26 24 27 namespace HeuristicLab.Services.Hive { 25 26 28 public class ServiceLocator : IServiceLocator { 27 29 private static IServiceLocator instance; … … 34 36 } 35 37 36 private IHiveDao hiveDao; 37 public IHiveDao HiveDao { 38 get { 39 if (hiveDao == null) hiveDao = new HiveDao(); 40 return hiveDao; 41 } 42 } 43 44 public IOptimizedHiveDao OptimizedHiveDao { 38 public IPersistenceManager PersistenceManager { 45 39 get { 46 40 var dataContext = HiveOperationContext.Current != null 47 41 ? HiveOperationContext.Current.DataContext 48 42 : new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); 49 return new OptimizedHiveDao(dataContext);43 return new PersistenceManager(dataContext); 50 44 } 51 45 } … … 75 69 } 76 70 77 private ITransactionManager transactionManager; 78 public ITransactionManager TransactionManager { 79 get { 80 if (transactionManager == null) transactionManager = new TransactionManager(); 81 return transactionManager; 82 } 71 private IStatisticsGenerator statisticsGenerator; 72 public IStatisticsGenerator StatisticsGenerator { 73 get { return statisticsGenerator ?? (statisticsGenerator = new HiveStatisticsGenerator()); } 83 74 } 84 75 -
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/app.config
r11623 r12931 29 29 <value>00:00:20</value> 30 30 </setting> 31 <setting name="ProfileServicePerformance" serializeAs="String"> 32 <value>True</value> 33 </setting> 34 <setting name="GenerateStatisticsInterval" serializeAs="String"> 35 <value>00:03:00</value> 36 </setting> 31 37 </HeuristicLab.Services.Hive.Properties.Settings> 32 38 </applicationSettings> 33 <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration> 39 <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup> 40 </configuration>
Note: See TracChangeset
for help on using the changeset viewer.