Skip to content

Commit edbe558

Browse files
authored
Merge pull request #6450 from fstagni/81_addHTTPS
[8.1] Add few Framework Tornado handlers
2 parents 915653a + be64a0c commit edbe558

10 files changed

+136
-32
lines changed

src/DIRAC/Core/Utilities/DictCache.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class MockLockRing:
2727

2828
def doNothing(self, *args, **kwargs):
2929
"""Really does nothing !"""
30-
pass
3130

3231
acquire = release = doNothing
3332

@@ -105,9 +104,9 @@ def exists(self, cKey, validSeconds=0):
105104
# If it's valid return True!
106105
if expTime > datetime.datetime.now() + datetime.timedelta(seconds=validSeconds):
107106
return True
108-
else:
109-
# Delete expired
110-
self.delete(cKey)
107+
108+
# Delete expired
109+
self.delete(cKey)
111110
return False
112111
finally:
113112
self.lock.release()
@@ -159,9 +158,9 @@ def get(self, cKey, validSeconds=0):
159158
# If it's valid return True!
160159
if expTime > datetime.datetime.now() + datetime.timedelta(seconds=validSeconds):
161160
return self.__cache[cKey]["value"]
162-
else:
163-
# Delete expired
164-
self.delete(cKey)
161+
162+
# Delete expired
163+
self.delete(cKey)
165164
return None
166165
finally:
167166
self.lock.release()
@@ -174,11 +173,11 @@ def showContentsInString(self):
174173
self.lock.acquire()
175174
try:
176175
data = []
177-
for cKey in self.__cache:
178-
data.append("%s:" % str(cKey))
179-
data.append("\tExp: %s" % self.__cache[cKey]["expirationTime"])
180-
if self.__cache[cKey]["value"]:
181-
data.append("\tVal: %s" % self.__cache[cKey]["value"])
176+
for cKey, cValue in self.__cache.items():
177+
data.append(f"{cKey}:")
178+
data.append(f"\tExp: {cValue['expirationTime']}")
179+
if cValue["value"]:
180+
data.append(f"\tVal: {cValue['Value']}")
182181
return "\n".join(data)
183182
finally:
184183
self.lock.release()
@@ -194,8 +193,8 @@ def getKeys(self, validSeconds=0):
194193
try:
195194
keys = []
196195
limitTime = datetime.datetime.now() + datetime.timedelta(seconds=validSeconds)
197-
for cKey in self.__cache:
198-
if self.__cache[cKey]["expirationTime"] > limitTime:
196+
for cKey, cValue in self.__cache.items():
197+
if cValue["expirationTime"] > limitTime:
199198
keys.append(cKey)
200199
return keys
201200
finally:
@@ -210,13 +209,13 @@ def purgeExpired(self, expiredInSeconds=0):
210209
try:
211210
keys = []
212211
limitTime = datetime.datetime.now() + datetime.timedelta(seconds=expiredInSeconds)
213-
for cKey in self.__cache:
214-
if self.__cache[cKey]["expirationTime"] < limitTime:
212+
for cKey, cValue in self.__cache.items():
213+
if cValue["expirationTime"] < limitTime:
215214
keys.append(cKey)
216-
for cKey in keys:
215+
for key in keys:
217216
if self.__deleteFunction:
218-
self.__deleteFunction(self.__cache[cKey]["value"])
219-
del self.__cache[cKey]
217+
self.__deleteFunction(self.__cache[key]["value"])
218+
del self.__cache[key]
220219
finally:
221220
self.lock.release()
222221

src/DIRAC/FrameworkSystem/ConfigTemplate.cfg

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ Services
116116
Default = authenticated
117117
}
118118
}
119+
##BEGIN TornadoUserProfileManager:
120+
# Section to describe UserProfileManager service
121+
TornadoUserProfileManager
122+
{
123+
Protocol = https
124+
Authorization
125+
{
126+
Default = authenticated
127+
}
128+
}
129+
##END
119130
BundleDelivery
120131
{
121132
Port = 9158
@@ -155,6 +166,24 @@ Services
155166
ping = authenticated
156167
}
157168
}
169+
##BEGIN TornadoNotification:
170+
# Section to describe Notification service
171+
TornadoNotification
172+
{
173+
Protocol = https
174+
SMSSwitch = sms.switch.ch
175+
Authorization
176+
{
177+
Default = AlarmsManagement
178+
sendMail = authenticated
179+
sendSMS = authenticated
180+
removeNotificationsForUser = authenticated
181+
markNotificationsAsRead = authenticated
182+
getNotifications = authenticated
183+
ping = authenticated
184+
}
185+
}
186+
##END
158187
ComponentMonitoring
159188
{
160189
Port = 9190
@@ -170,6 +199,24 @@ Services
170199
updateLog = Operator
171200
}
172201
}
202+
##BEGIN TornadoComponentMonitoring:
203+
# Section to describe ComponentMonitoring service
204+
TornadoComponentMonitoring
205+
{
206+
Protocol = https
207+
Authorization
208+
{
209+
Default = ServiceAdministrator
210+
componentExists = authenticated
211+
getComponents = authenticated
212+
hostExists = authenticated
213+
getHosts = authenticated
214+
installationExists = authenticated
215+
getInstallations = authenticated
216+
updateLog = Operator
217+
}
218+
}
219+
##END
173220
RabbitMQSync
174221
{
175222
Port = 9192

src/DIRAC/FrameworkSystem/Service/BundleDeliveryHandler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ def updateBundles(self):
8383
class BundleDeliveryHandlerMixin:
8484
@classmethod
8585
def initializeHandler(cls, serviceInfoDict):
86+
87+
## FIXME: move to an agent
8688
csPath = serviceInfoDict["serviceSectionPath"]
8789
cls.bundleManager = BundleManager(csPath)
8890
updateBundleTime = gConfig.getValue("%s/BundlesLifeTime" % csPath, 3600 * 6)
8991
gLogger.info("Bundles will be updated each %s secs" % updateBundleTime)
9092
gThreadScheduler.addPeriodicTask(updateBundleTime, cls.bundleManager.updateBundles)
93+
##
94+
9195
return S_OK()
9296

9397
types_getListOfBundles = []

src/DIRAC/FrameworkSystem/Service/ComponentMonitoringHandler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from DIRAC.Core.DISET.RequestHandler import RequestHandler
1515

1616

17-
class ComponentMonitoringHandler(RequestHandler):
17+
class ComponentMonitoringHandlerMixin:
1818
@classmethod
1919
def initializeHandler(cls, serviceInfo):
2020
"""
@@ -330,3 +330,7 @@ def export_removeLogs(self, fields):
330330
return S_ERROR("Host does not exist")
331331

332332
return ComponentMonitoringHandler.db.removeLogs(fields)
333+
334+
335+
class ComponentMonitoringHandler(ComponentMonitoringHandlerMixin, RequestHandler):
336+
pass

src/DIRAC/FrameworkSystem/Service/NotificationHandler.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,23 @@
1212
It can also be used to set alarms to be promptly forwarded to those
1313
subscribing to them.
1414
"""
15-
from DIRAC import gConfig, S_OK, S_ERROR
16-
15+
from DIRAC import S_ERROR, S_OK, gConfig
16+
from DIRAC.ConfigurationSystem.Client import PathFinder
1717
from DIRAC.Core.DISET.RequestHandler import RequestHandler
18-
from DIRAC.Core.Utilities.Mail import Mail
19-
from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler
2018
from DIRAC.Core.Security import Properties
21-
from DIRAC.ConfigurationSystem.Client import PathFinder
22-
from DIRAC.FrameworkSystem.DB.NotificationDB import NotificationDB
2319
from DIRAC.Core.Utilities.DictCache import DictCache
20+
from DIRAC.Core.Utilities.Mail import Mail
21+
from DIRAC.FrameworkSystem.DB.NotificationDB import NotificationDB
2422

2523

26-
class NotificationHandler(RequestHandler):
24+
class NotificationHandlerMixin:
2725
@classmethod
2826
def initializeHandler(cls, serviceInfo):
2927
"""Handler initialization"""
30-
cls.notDB = NotificationDB()
28+
3129
cls.mailCache = DictCache()
32-
gThreadScheduler.addPeriodicTask(3600, cls.notDB.purgeExpiredNotifications)
33-
gThreadScheduler.addPeriodicTask(3600, cls.mailCache.purgeExpired())
30+
cls.notDB = NotificationDB()
31+
3432
return S_OK()
3533

3634
def initialize(self):
@@ -40,6 +38,8 @@ def initialize(self):
4038
self.clientProperties = credDict["properties"]
4139
self.client = credDict["username"]
4240

41+
self.notDB.purgeExpiredNotifications()
42+
4343
###########################################################################
4444
types_sendMail = [str, str, str, str]
4545

@@ -270,3 +270,7 @@ def export_getNotifications(self, selectDict, sortList, startItem, maxItems):
270270
if Properties.ALARMS_MANAGEMENT not in credDict["properties"]:
271271
selectDict["user"] = [credDict["username"]]
272272
return self.notDB.getNotifications(selectDict, sortList, startItem, maxItems)
273+
274+
275+
class NotificationHandler(NotificationHandlerMixin, RequestHandler):
276+
pass
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
""" TornadoComponentMonitoring is the implementation of the ComponentMonitoringent service in HTTPS
2+
3+
.. literalinclude:: ../ConfigTemplate.cfg
4+
:start-after: ##BEGIN TornadoComponentMonitoring:
5+
:end-before: ##END
6+
:dedent: 2
7+
:caption: TornadoComponentMonitoring options
8+
"""
9+
from DIRAC.Core.Tornado.Server.TornadoService import TornadoService
10+
from DIRAC.FrameworkSystem.Service.ComponentMonitoringHandler import ComponentMonitoringHandlerMixin
11+
12+
13+
class TornadoComponentMonitoringHandler(ComponentMonitoringHandlerMixin, TornadoService):
14+
pass
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
""" TornadoNotification is the implementation of the Notification service in HTTPS
2+
3+
.. literalinclude:: ../ConfigTemplate.cfg
4+
:start-after: ##BEGIN TornadoNotification:
5+
:end-before: ##END
6+
:dedent: 2
7+
:caption: TornadoNotification options
8+
"""
9+
from DIRAC.Core.Tornado.Server.TornadoService import TornadoService
10+
from DIRAC.FrameworkSystem.Service.NotificationHandler import NotificationHandlerMixin
11+
12+
13+
class TornadoNotificationHandler(NotificationHandlerMixin, TornadoService):
14+
pass
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
""" TornadoUserProfileManager is the implementation of the UserProfileManager service in HTTPS
2+
3+
.. literalinclude:: ../ConfigTemplate.cfg
4+
:start-after: ##BEGIN TornadoUserProfileManager:
5+
:end-before: ##END
6+
:dedent: 2
7+
:caption: TornadoUserProfileManager options
8+
"""
9+
from DIRAC.Core.Tornado.Server.TornadoService import TornadoService
10+
from DIRAC.FrameworkSystem.Service.UserProfileManagerHandler import UserProfileManagerHandlerMixin
11+
12+
13+
class TornadoUserProfileManagerHandler(UserProfileManagerHandlerMixin, TornadoService):
14+
pass

src/DIRAC/FrameworkSystem/Service/UserProfileManagerHandler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from DIRAC.Core.Security import Properties
88

99

10-
class UserProfileManagerHandler(RequestHandler):
10+
class UserProfileManagerHandlerMixin:
1111
@classmethod
1212
def initializeHandler(cls, serviceInfo):
1313
"""Handler initialization"""
@@ -145,3 +145,7 @@ def export_getUserProfileNames(self, permission):
145145
it returns the available profile names by not taking account the permission: ReadAccess and PublishAccess
146146
"""
147147
return self.upDB.getUserProfileNames(permission)
148+
149+
150+
class UserProfileManagerHandler(UserProfileManagerHandlerMixin, RequestHandler):
151+
pass

tests/CI/install_server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ then
100100
dirac-restart-component Configuration Server "$DEBUG"
101101
sleep 5
102102
dirac-restart-component Tornado Tornado -ddd
103-
done< <(python -m DIRAC.Core.Utilities.Extensions findServices | grep Tornado | grep -v Configuration | sed -e 's/Handler//g' -e 's/System//g')
103+
done< <(python -m DIRAC.Core.Utilities.Extensions findServices | grep Tornado | grep -v Configuration | grep -v ComponentMonitoring | sed -e 's/Handler//g' -e 's/System//g')
104104

105105
echo -e "*** $(date -u) **** DONE Installing Tornado services"
106106
fi

0 commit comments

Comments
 (0)