Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using HaaSMiddleware.BusinessLogicTier.Logic.JobManagement.Exceptions;
using HaaSMiddleware.DataAccessTier.UnitOfWork;
using HaaSMiddleware.DomainObjects.ClusterInformation;
using HaaSMiddleware.DomainObjects.UserAndLimitationManagement;
using HaaSMiddleware.HpcConnectionFramework;
using log4net;
namespace HaaSMiddleware.BusinessLogicTier.Logic.ClusterInformation {
internal class ClusterInformationLogic : IClusterInformationLogic {
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly IUnitOfWork unitOfWork;
internal ClusterInformationLogic(IUnitOfWork unitOfWork) {
this.unitOfWork = unitOfWork;
}
public IList<Cluster> ListAvailableClusters() {
return unitOfWork.ClusterRepository.GetAll().ToList();
}
public ClusterNodeUsage GetCurrentClusterNodeUsage(long clusterNodeId, AdaptorUser loggedUser) {
ClusterNodeType nodeType = GetClusterNodeTypeById(clusterNodeId);
IRexScheduler scheduler = SchedulerFactory.GetInstance(nodeType.Cluster.SchedulerType).CreateScheduler(nodeType.Cluster);
return scheduler.GetCurrentClusterNodeUsage(nodeType);
}
public ClusterAuthenticationCredentials GetNextAvailableUserCredentials(long clusterId) {
// Get credentials for cluster
Cluster cluster = unitOfWork.ClusterRepository.GetById(clusterId);
if (cluster == null) {
log.Error("Requested cluster with Id=" + clusterId + " does not exist in the system.");
throw new RequestedObjectDoesNotExistException("Requested cluster with Id=" + clusterId + " does not exist in the system.");
}
List<ClusterAuthenticationCredentials> credentials =
(from account in cluster.AuthenticationCredentials where account != cluster.ServiceAccountCredentials orderby account.Id ascending select account).ToList();
long lastUsedId = ClusterUserCache.GetLastUserId(cluster);
if (lastUsedId == 0)
{ // No user has been used from this cluster
// return first usable account
ClusterUserCache.SetLastUserId(cluster, credentials[0].Id);
log.DebugFormat("Using initial cluster account: {0}", credentials[0].Username);
return credentials[0];
}
else
{
// Return first user with Id higher than the last one
ClusterAuthenticationCredentials creds = (from account in credentials where account.Id > lastUsedId select account).FirstOrDefault();
if (creds == null)
{
// No credentials with Id higher than last used found
// use first usable account
creds = credentials[0];
}
ClusterUserCache.SetLastUserId(cluster, creds.Id);
log.DebugFormat("Using cluster account: {0}", creds.Username);
return creds;
}
}
public ClusterNodeType GetClusterNodeTypeById(long clusterNodeTypeId) {
ClusterNodeType nodeType = unitOfWork.ClusterNodeTypeRepository.GetById(clusterNodeTypeId);
if (nodeType == null) {
log.Error("Requested cluster node type with Id=" + clusterNodeTypeId + " does not exist in the system.");
throw new RequestedObjectDoesNotExistException("Requested cluster node type with Id=" + clusterNodeTypeId + " does not exist in the system.");
}
return nodeType;
}
public IList<ClusterNodeType> ListClusterNodeTypes() {
return unitOfWork.ClusterNodeTypeRepository.GetAll();
}
}
}