Ignore:
Timestamp:
08/18/15 10:08:58 (6 years ago)
Author:
ascheibe
Message:

#2388 merged hive statistics branch into trunk

Location:
trunk/sources
Files:
9 deleted
11 edited
8 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Services.Hive

  • trunk/sources/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj

    r11623 r12878  
    118118  </ItemGroup>
    119119  <ItemGroup>
    120     <Compile Include="Convert.cs" />
     120    <Compile Include="Converter.cs" />
    121121    <Compile Include="DataTransfer\Command.cs" />
    122122    <Compile Include="DataTransfer\UserPriority.cs" />
     
    139139    <Compile Include="DataTransfer\SlaveGroup.cs" />
    140140    <Compile Include="DataTransfer\SlaveState.cs" />
    141     <Compile Include="DataTransfer\SlaveStatistics.cs" />
    142141    <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" />
    147144    <Compile Include="HiveJanitor.cs" />
    148145    <Compile Include="HiveOperationContext.cs" />
    149     <Compile Include="Interfaces\IOptimizedHiveDao.cs" />
    150     <Compile Include="Interfaces\IHiveDao.cs" />
    151146    <Compile Include="Interfaces\ITaskScheduler.cs" />
     147    <Compile Include="PerformanceLogger.cs" />
    152148    <Compile Include="Scheduler\TaskInfoForScheduler.cs" />
    153149    <Compile Include="Scheduler\JobInfoForScheduler.cs" />
    154150    <Compile Include="Scheduler\RoundRobinTaskScheduler.cs" />
    155     <Compile Include="Settings.cs" />
    156151    <None Include="app.config" />
    157152    <None Include="Plugin.cs.frame" />
     
    182177  </ItemGroup>
    183178  <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>
    184183    <ProjectReference Include="..\..\HeuristicLab.Services.Access\3.3\HeuristicLab.Services.Access-3.3.csproj">
    185184      <Project>{9FAC0B23-2730-452A-9BA0-D7CA1746C541}</Project>
  • trunk/sources/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs

    r12012 r12878  
    2323using System.Threading;
    2424using HeuristicLab.Services.Hive.DataAccess;
     25using HeuristicLab.Services.Hive.DataAccess.Interfaces;
    2526
    2627namespace HeuristicLab.Services.Hive {
    2728  public class HiveJanitor {
    2829    private bool stop;
    29     private AutoResetEvent waitHandle;
     30    private AutoResetEvent cleanupWaitHandle;
     31    private AutoResetEvent generateStatisticsWaitHandle;
    3032
    31     private DataAccess.ITransactionManager trans {
    32       get { return ServiceLocator.Instance.TransactionManager; }
     33    private IPersistenceManager PersistenceManager {
     34      get { return ServiceLocator.Instance.PersistenceManager; }
    3335    }
    34 
    35     private IEventManager eventManager {
     36    private IEventManager EventManager {
    3637      get { return ServiceLocator.Instance.EventManager; }
    3738    }
    3839
    39     private IHiveDao dao {
    40       get { return ServiceLocator.Instance.HiveDao; }
     40    private IStatisticsGenerator StatisticsGenerator {
     41      get { return ServiceLocator.Instance.StatisticsGenerator; }
    4142    }
    4243
    4344    public HiveJanitor() {
    4445      stop = false;
    45       waitHandle = new AutoResetEvent(true);
     46      cleanupWaitHandle = new AutoResetEvent(false);
     47      generateStatisticsWaitHandle = new AutoResetEvent(false);
    4648    }
    4749
    4850    public void StopJanitor() {
    4951      stop = true;
    50       waitHandle.Set();
     52      cleanupWaitHandle.Set();
     53      generateStatisticsWaitHandle.Set();
    5154    }
    5255
    53     public void Run() {
     56    public void RunCleanup() {
     57      var pm = PersistenceManager;
    5458      while (!stop) {
    5559        try {
    56           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup");
     60          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup.");
    5761          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();
    6269              cleanup = true;
    6370            }
     71            pm.SubmitChanges();
    6472          }, true);
    6573
    6674          if (cleanup) {
    67             eventManager.Cleanup();
     75            EventManager.Cleanup();
    6876          }
    69           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished");
     77          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished.");
    7078        }
    7179        catch (Exception e) {
    7280          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e.ToString()));
    7381        }
    74         waitHandle.WaitOne(HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval);
     82        cleanupWaitHandle.WaitOne(Properties.Settings.Default.CleanupInterval);
    7583      }
    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();
    77102    }
    78103  }
  • trunk/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IServiceLocator.cs

    r12012 r12878  
    2020#endregion
    2121
    22 using HeuristicLab.Services.Hive.DataAccess;
     22using HeuristicLab.Services.Hive.DataAccess.Interfaces;
     23using HeuristicLab.Services.Hive.Manager;
    2324
    2425namespace HeuristicLab.Services.Hive {
     
    2627    Access.IRoleVerifier RoleVerifier { get; }
    2728    IAuthorizationManager AuthorizationManager { get; }
    28     IHiveDao HiveDao { get; }
    29     IOptimizedHiveDao OptimizedHiveDao { get; }
     29    IPersistenceManager PersistenceManager { get; }
    3030    IEventManager EventManager { get; }
    31     ITransactionManager TransactionManager { get; }
     31    IStatisticsGenerator StatisticsGenerator { get; }
    3232    Access.IUserManager UserManager { get; }
    3333    HeartbeatManager HeartbeatManager { get; }
  • trunk/sources/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs

    r12012 r12878  
    2222using System;
    2323using System.Security;
     24using HeuristicLab.Services.Access;
    2425using HeuristicLab.Services.Hive.DataAccess;
     26using HeuristicLab.Services.Hive.DataAccess.Interfaces;
     27using DA = HeuristicLab.Services.Hive.DataAccess;
    2528using DT = HeuristicLab.Services.Hive.DataTransfer;
    2629
     
    2831namespace HeuristicLab.Services.Hive {
    2932  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
    3047    public void Authorize(Guid userId) {
    3148      if (userId != ServiceLocator.Instance.UserManager.CurrentUserId)
    32         throw new SecurityException("Current user is not authorized to access object");
     49        throw new SecurityException(NOT_AUTHORIZED);
    3350    }
    3451
    3552    public void AuthorizeForTask(Guid taskId, DT.Permission requiredPermission) {
    3653      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      });
    4161    }
    4262
    4363    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      });
    4768    }
    4869
    4970    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      }
    53101    }
    54102  }
  • trunk/sources/HeuristicLab.Services.Hive/3.3/Properties/Settings.Designer.cs

    r11623 r12878  
    11//------------------------------------------------------------------------------
    22// <auto-generated>
    3 //     This code was generated by a tool.
    4 //     Runtime Version:4.0.30319.34014
     3//     Dieser Code wurde von einem Tool generiert.
     4//     Laufzeitversion:4.0.30319.42000
    55//
    6 //     Changes to this file may cause incorrect behavior and will be lost if
    7 //     the code is regenerated.
     6//     Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
     7//     der Code erneut generiert wird.
    88// </auto-generated>
    99//------------------------------------------------------------------------------
     
    1313   
    1414    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    15     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
     15    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
    1616    public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
    1717       
     
    8686            }
    8787        }
     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        }
    88106    }
    89107}
  • trunk/sources/HeuristicLab.Services.Hive/3.3/Properties/Settings.settings

    r9123 r12878  
    2424      <Value Profile="(Default)">00:00:20</Value>
    2525    </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>
    2632  </Settings>
    2733</SettingsFile>
  • trunk/sources/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs

    r12012 r12878  
    4141
    4242    [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]
    5243    IEnumerable<LightweightTask> GetLightweightJobTasks(Guid jobId);
    5344
     
    6556
    6657    [OperationContract]
    67     void DeleteTask(Guid taskId);
    68 
    69     [OperationContract]
    70     void DeleteChildTasks(Guid parentTaskId);
    71 
    72     [OperationContract]
    7358    Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception);
    7459    #endregion
     
    8974    Job GetJob(Guid id);
    9075
    91     /// <summary>
    92     /// Returns all task for the current user
    93     /// </summary>
    9476    [OperationContract]
    9577    IEnumerable<Job> GetJobs();
    9678
    97     /// <summary>
    98     /// Returns all task in the hive (only for admins)
    99     /// </summary>
    100     /// <returns></returns>
    101     [OperationContract]
    102     IEnumerable<Job> GetAllJobs();
    103 
    10479    [OperationContract]
    10580    Guid AddJob(Job jobDto);
     
    142117    [OperationContract]
    143118    Plugin GetPlugin(Guid pluginId);
    144 
    145     [OperationContract]
    146     Plugin GetPluginByHash(byte[] hash);
    147119
    148120    [OperationContract]
     
    155127    [OperationContract]
    156128    IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds);
    157 
    158     [OperationContract]
    159     void DeletePlugin(Guid pluginId);
    160129    #endregion
    161130
     
    171140    #endregion
    172141
    173     #region Resource Methods
    174     [OperationContract]
    175     IEnumerable<Resource> GetChildResources(Guid resourceId);
    176     #endregion
    177 
    178142    #region Slave Methods
    179143    [OperationContract]
     
    187151
    188152    [OperationContract]
    189     SlaveGroup GetSlaveGroup(Guid slaveGroupId);
    190 
    191     [OperationContract]
    192153    IEnumerable<Slave> GetSlaves();
    193154
     
    217178
    218179    [OperationContract]
    219     IEnumerable<Task> GetTasksByResourceId(Guid resourceId);
    220 
    221     [OperationContract]
    222180    void TriggerEventManager(bool force);
    223181
     
    234192
    235193    [OperationContract]
    236     void UpdateDowntime(Downtime downtime);
     194    void UpdateDowntime(Downtime downtimeDto);
    237195
    238196    [OperationContract]
     
    251209    [OperationContract]
    252210    IEnumerable<UserPriority> GetUserPriorities();
    253     #endregion
    254 
    255     #region Statistics Methods
    256     [OperationContract]
    257     IEnumerable<Statistics> GetStatistics();
    258     [OperationContract]
    259     IEnumerable<Statistics> GetStatisticsForTimePeriod(DateTime from, DateTime to);
    260211    #endregion
    261212  }
  • trunk/sources/HeuristicLab.Services.Hive/3.3/ServiceLocator.cs

    r12012 r12878  
    2121
    2222using HeuristicLab.Services.Hive.DataAccess;
     23using HeuristicLab.Services.Hive.DataAccess.Interfaces;
     24using HeuristicLab.Services.Hive.DataAccess.Manager;
     25using HeuristicLab.Services.Hive.Manager;
    2326
    2427namespace HeuristicLab.Services.Hive {
    25 
    2628  public class ServiceLocator : IServiceLocator {
    2729    private static IServiceLocator instance;
     
    3436    }
    3537
    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 {
    4539      get {
    4640        var dataContext = HiveOperationContext.Current != null
    4741                            ? HiveOperationContext.Current.DataContext
    4842                            : new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString);
    49         return new OptimizedHiveDao(dataContext);
     43        return new PersistenceManager(dataContext);
    5044      }
    5145    }
     
    7569    }
    7670
    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()); }
    8374    }
    8475
  • trunk/sources/HeuristicLab.Services.Hive/3.3/app.config

    r11623 r12878  
    2929                <value>00:00:20</value>
    3030            </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>
    3137        </HeuristicLab.Services.Hive.Properties.Settings>
    3238    </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.