Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Adding support for local computing (HPC cluster simulation)

See merge request ADAS-Private/HEAppE/heappe-core!71
  • Loading branch information
vsvaton committed Apr 11, 2022
2 parents 2c824fd + 995ff66 commit 9036bcc
Show file tree
Hide file tree
Showing 243 changed files with 12,415 additions and 8,093 deletions.
23 changes: 23 additions & 0 deletions BackgroundThread/Configuration/BackGroundThreadConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace HEAppE.BackgroundThread.Configuration
{
/// <summary>
/// Background Thread configuration
/// </summary>
public sealed class BackGroundThreadConfiguration
{
/// <summary>
/// Get all jobs information check in seconds
/// </summary>
public static int GetAllJobsInformationCheck { get; set; } = 30;

/// <summary>
/// Close connection to finished jobs check in seconds
/// </summary>
public static int CloseConnectionToFinishedJobsCheck { get; set; } = 30;

/// <summary>
/// Cluster account rotation job check in seconds
/// </summary>
public static int ClusterAccountRotationJobCheck { get; set; } = 30;
}
}
61 changes: 35 additions & 26 deletions BackgroundThread/MiddlewareBackgroundTaskRunner.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
using System;
using System.Collections.Generic;
using HEAppE.BackgroundThread.Configuration;
using HEAppE.BackgroundThread.Tasks;
using HEAppE.BusinessLogicTier.Configuration;

namespace HEAppE.BackgroundThread {
public class MiddlewareBackgroundTaskRunner {
private readonly List<IBackgroundTask> tasks;

public MiddlewareBackgroundTaskRunner() {
tasks = new List<IBackgroundTask>();
tasks.Add(new GetAllJobsInfo(new TimeSpan(0, 0, 30)));
//tasks.Add(new SynchronizeJobFileContents(new TimeSpan(0, 0, 30)));
tasks.Add(new CloseConnectionToFinishedJobs(new TimeSpan(0, 0, 30)));
tasks.Add(new ClusterAccountRotationJob(new TimeSpan(0, 0, 30)));
}
using System;
using System.Collections.Generic;

public void Start() {
foreach (var task in tasks) {
task.StartTimer();
}
}
namespace HEAppE.BackgroundThread
{
public class MiddlewareBackgroundTaskRunner
{
#region Instances
private readonly List<IBackgroundTask> _tasks = new();
#endregion
#region Constructors
public MiddlewareBackgroundTaskRunner()
{
_tasks.Add(new GetAllJobsInfo(TimeSpan.FromSeconds(BackGroundThreadConfiguration.GetAllJobsInformationCheck)));
_tasks.Add(new CloseConnectionToFinishedJobs(TimeSpan.FromSeconds(BackGroundThreadConfiguration.CloseConnectionToFinishedJobsCheck)));
_tasks.Add(new ClusterAccountRotationJob(TimeSpan.FromSeconds(BackGroundThreadConfiguration.ClusterAccountRotationJobCheck)));
}
#endregion
#region Methods
public void Start()
{
foreach (var task in _tasks)
{
task.StartTimer();
}
}

public void Stop() {
foreach (var task in tasks) {
task.StopTimer();
}
}
}
public void Stop()
{
foreach (var task in _tasks)
{
task.StopTimer();
}
}
#endregion
}
}
74 changes: 43 additions & 31 deletions BackgroundThread/Tasks/AbstractTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,54 @@
using log4net;
using Timer = System.Timers.Timer;

namespace HEAppE.BackgroundThread.Tasks {
internal abstract class AbstractTask : IBackgroundTask {
protected readonly ILog log;
private readonly Timer taskTimer;
private static readonly Object lockObj = new Object();
namespace HEAppE.BackgroundThread.Tasks
{
internal abstract class AbstractTask : IBackgroundTask
{
protected readonly ILog _log;
private readonly Timer _taskTimer;
private static readonly object _lockObj = new();

public AbstractTask(TimeSpan interval) {
this.log = LogManager.GetLogger(this.GetType());
this.taskTimer = new Timer(interval.TotalMilliseconds);
this.taskTimer.Elapsed += taskTimer_Elapsed;
}
public AbstractTask(TimeSpan interval)
{
_log = LogManager.GetLogger(GetType());
_taskTimer = new Timer(interval.TotalMilliseconds);
_taskTimer.Elapsed += TaskTimerElapsed;
}

public void StartTimer() {
this.taskTimer.Start();
}
public void StartTimer()
{
_taskTimer.Start();
}

public void StopTimer() {
this.taskTimer.Stop();
}
public void StopTimer()
{
_taskTimer.Stop();
}

private void taskTimer_Elapsed(object sender, ElapsedEventArgs e) {
// Run the task in its own thread
Thread thread = new Thread(delegate() {
try {
lock (lockObj) {
private void TaskTimerElapsed(object sender, ElapsedEventArgs e)
{
// Run the task in its own thread
Thread thread = new(delegate ()
{
try
{
lock (_lockObj)
{
RunTask();
}
}
catch (Exception ex) {
log.Error("An error occured during execution of the background task: {0}", ex);
}
});
thread.Name = "Timer - " + this.GetType().ToString();
thread.Start();
}
}
catch (Exception ex)
{
_log.Error("An error occured during execution of the background task: {0}", ex);
}
})
{
Name = $"Timer - {GetType()}"
};
thread.Start();
}

protected abstract void RunTask();
}
protected abstract void RunTask();
}
}
53 changes: 25 additions & 28 deletions BackgroundThread/Tasks/CloseConnectionToFinishedJobs.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
using System;
using System.Collections.Generic;
using HEAppE.BusinessLogicTier.Factory;
using HEAppE.BusinessLogicTier.Factory;
using HEAppE.DataAccessTier.UnitOfWork;
using HEAppE.DomainObjects.JobManagement.JobInformation;
using HEAppE.ServiceTier.JobManagement;
using HEAppE.ServiceTier.DataTransfer;
using HEAppE.BusinessLogicTier.Logic.DataTransfer;
using System;
using System.Linq;

namespace HEAppE.BackgroundThread.Tasks {
/// <summary>
/// Close all open sockets to finished/failed/canceled jobs
/// </summary>
internal class CloseConnectionToFinishedJobs : AbstractTask, IBackgroundTask {
public CloseConnectionToFinishedJobs(TimeSpan interval) : base(interval) { }
namespace HEAppE.BackgroundThread.Tasks
{
/// <summary>
/// Close all open sockets to finished/failed/canceled jobs
/// </summary>
internal class CloseConnectionToFinishedJobs : AbstractTask, IBackgroundTask
{
public CloseConnectionToFinishedJobs(TimeSpan interval) : base(interval)
{

protected override void RunTask() {
using (IUnitOfWork unitOfWork = new DatabaseUnitOfWork()) {
List<long> jobIds = LogicFactory.GetLogicFactory().CreateDataTransferLogic(unitOfWork).GetJobIdsForOpenTunnels();
foreach (long jobId in jobIds)
{
//check the job's status
SubmittedJobInfo jobInfo = unitOfWork.SubmittedJobInfoRepository.GetById(jobId);
if (jobInfo.State >= JobState.Finished && jobInfo.State != JobState.WaitingForServiceAccount)
{
LogicFactory.GetLogicFactory().CreateDataTransferLogic(unitOfWork).CloseAllConnectionsForJob(jobInfo);
}
}
}
}
}

}
protected override void RunTask()
{
using IUnitOfWork unitOfWork = new DatabaseUnitOfWork();
var dataTransferLogic = LogicFactory.GetLogicFactory().CreateDataTransferLogic(unitOfWork);

var taskIds = dataTransferLogic.GetTaskIdsWithOpenTunnels();
LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork).GetAllFinishedTaskInfos(taskIds)
.ToList()
.ForEach(f => dataTransferLogic.CloseAllTunnelsForTask(f));
}

}
}
6 changes: 4 additions & 2 deletions BackgroundThread/Tasks/ClusterAccountRotationJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace HEAppE.BackgroundThread.Tasks
/// </summary>
internal class ClusterAccountRotationJob : AbstractTask, IBackgroundTask
{
public ClusterAccountRotationJob(TimeSpan interval) : base(interval) { }
public ClusterAccountRotationJob(TimeSpan interval) : base(interval)
{
}

protected override void RunTask()
{
Expand All @@ -21,7 +23,7 @@ protected override void RunTask()
using IUnitOfWork unitOfWork = new DatabaseUnitOfWork();

//Get all jobs in state - waiting for user
IEnumerable<SubmittedJobInfo> allWaitingJobs = unitOfWork.SubmittedJobInfoRepository.ListAllWaitingForServiceAccount();
IEnumerable<SubmittedJobInfo> allWaitingJobs = unitOfWork.SubmittedJobInfoRepository.GetAllWaitingForServiceAccount();

//Try to submit them again
foreach (SubmittedJobInfo job in allWaitingJobs)
Expand Down
34 changes: 18 additions & 16 deletions BackgroundThread/Tasks/GetAllJobsInfo.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
using System;
using System.Collections.Generic;
using HEAppE.BusinessLogicTier.Factory;
using HEAppE.BusinessLogicTier.Factory;
using HEAppE.DataAccessTier.UnitOfWork;
using HEAppE.DomainObjects.JobManagement.JobInformation;
using HEAppE.ServiceTier.JobManagement;
using System;

namespace HEAppE.BackgroundThread.Tasks {
/// <summary>
/// Get all unfinished jobs from db and load their status from cluster
/// and updates their status in DB
/// </summary>
internal class GetAllJobsInfo : AbstractTask, IBackgroundTask {
public GetAllJobsInfo(TimeSpan interval) : base(interval) {}
namespace HEAppE.BackgroundThread.Tasks
{
/// <summary>
/// Get all unfinished jobs from db and load their status from cluster
/// and updates their status in DB
/// </summary>
internal class GetAllJobsInfo : AbstractTask, IBackgroundTask
{
public GetAllJobsInfo(TimeSpan interval) : base(interval)
{
}

protected override void RunTask() {
using IUnitOfWork unitOfWork = new DatabaseUnitOfWork();
LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork).UpdateCurrentStateOfUnfinishedJobs();
protected override void RunTask()
{
using IUnitOfWork unitOfWork = new DatabaseUnitOfWork();
LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork).UpdateCurrentStateOfUnfinishedJobs();
}
}
}
}
6 changes: 4 additions & 2 deletions BackgroundThread/Tasks/IBackgroundTask.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace HEAppE.BackgroundThread.Tasks {
internal interface IBackgroundTask {
namespace HEAppE.BackgroundThread.Tasks
{
internal interface IBackgroundTask
{
void StartTimer();
void StopTimer();
}
Expand Down
21 changes: 0 additions & 21 deletions BackgroundThread/Tasks/SynchronizeJobFileContents.cs

This file was deleted.

4 changes: 2 additions & 2 deletions BusinessLogicTier/BusinessLogicTier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="log4net" Version="2.0.14" />
<PackageReference Include="RestSharp" Version="107.3.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -16,7 +17,6 @@
<ProjectReference Include="..\DomainObjects\DomainObjects.csproj" />
<ProjectReference Include="..\FileTransferFramework\FileTransferFramework.csproj" />
<ProjectReference Include="..\HpcConnectionFramework\HpcConnectionFramework.csproj" />
<ProjectReference Include="..\MiddlewareUtils\MiddlewareUtils.csproj" />
<ProjectReference Include="..\KeycloakOpenIdAuthentication\KeycloakOpenIdAuthentication.csproj" />
<ProjectReference Include="..\OpenStackAPI\OpenStackAPI.csproj" />
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions BusinessLogicTier/Configuration/BusinessLogicConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public sealed class BusinessLogicConfiguration
/// Account rotation
/// </summary>
public static bool ClusterAccountRotation { get; set; }

/// <summary>
/// HTTP requeues connection timeout
/// </summary>
public static int HTTPRequestConnectionTimeout { get; set; } = 10000;
#endregion
}
}
2 changes: 2 additions & 0 deletions BusinessLogicTier/Factory/LogicFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using HEAppE.BusinessLogicTier.Logic.FileTransfer;
using HEAppE.BusinessLogicTier.Logic.JobManagement;
using HEAppE.BusinessLogicTier.Logic.JobReporting;
using HEAppE.BusinessLogicTier.Logic.Management;
using HEAppE.BusinessLogicTier.Logic.Notifications;
using HEAppE.BusinessLogicTier.Logic.UserAndLimitationManagement;
using HEAppE.DataAccessTier.UnitOfWork;
Expand Down Expand Up @@ -50,6 +51,7 @@ private static LogicFactory CreateLogicFactory(BusinessLogicType type) {
public abstract IJobReportingLogic CreateJobReportingLogic(IUnitOfWork unitOfWork);
public abstract INotificationLogic CreateNotificationLogic(IUnitOfWork unitOfWork);
public abstract IUserAndLimitationManagementLogic CreateUserAndLimitationManagementLogic(IUnitOfWork unitOfWork);
public abstract IManagementLogic CreateManagementLogic(IUnitOfWork unitOfWork);
#endregion
}
}
7 changes: 7 additions & 0 deletions BusinessLogicTier/Factory/PocoLogicFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using HEAppE.BusinessLogicTier.Logic.FileTransfer;
using HEAppE.BusinessLogicTier.Logic.JobManagement;
using HEAppE.BusinessLogicTier.Logic.JobReporting;
using HEAppE.BusinessLogicTier.Logic.Management;
using HEAppE.BusinessLogicTier.Logic.Notifications;
using HEAppE.BusinessLogicTier.Logic.UserAndLimitationManagement;
using HEAppE.DataAccessTier.Factory.UnitOfWork;
Expand Down Expand Up @@ -53,5 +54,11 @@ public override IUserAndLimitationManagementLogic CreateUserAndLimitationManagem
{
return new UserAndLimitationManagementLogic(unitOfWork);
}

public override IManagementLogic CreateManagementLogic(IUnitOfWork unitOfWork)
{
return new ManagementLogic(unitOfWork);

}
}
}
Loading

0 comments on commit 9036bcc

Please sign in to comment.