Skip to content

Commit c23ee07

Browse files
committed
refactor: moved threadScheduler out of ProxyManagerHandler. Agent ProxyRenewalAgent now necessary
1 parent cb49c1e commit c23ee07

File tree

10 files changed

+100
-112
lines changed

10 files changed

+100
-112
lines changed

docs/source/AdministratorGuide/Configuration/ConfReference/Systems/Framework/Agents/MyProxyRenewalAgent/index.rst

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/source/AdministratorGuide/Configuration/ConfReference/Systems/Framework/Agents/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,3 @@ Agents associated with Framework System:
3939
:maxdepth: 2
4040

4141
CAUpdateAgent/index
42-
MyProxyRenewalAgent/index

src/DIRAC/ConfigurationSystem/test/Test_agentOptions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
("DIRAC.DataManagementSystem.Agent.FTS3Agent", {}),
1818
("DIRAC.FrameworkSystem.Agent.CAUpdateAgent", {}),
1919
("DIRAC.FrameworkSystem.Agent.ComponentSupervisionAgent", {}),
20-
(
21-
"DIRAC.FrameworkSystem.Agent.MyProxyRenewalAgent",
22-
{"IgnoreOptions": ["MinValidity", "ValidityPeriod", "MinimumLifeTime", "RenewedLifeTime"]},
23-
),
20+
("DIRAC.FrameworkSystem.Agent.ProxyRenewalAgent", {}),
2421
("DIRAC.RequestManagementSystem.Agent.CleanReqDBAgent", {}),
2522
(
2623
"DIRAC.RequestManagementSystem.Agent.RequestExecutingAgent",

src/DIRAC/FrameworkSystem/Agent/MyProxyRenewalAgent.py

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
""" ProxyRenewalAgent keeps the proxy repository clean.
2+
3+
.. literalinclude:: ../ConfigTemplate.cfg
4+
:start-after: ##BEGIN MyProxyRenewalAgent
5+
:end-before: ##END
6+
:dedent: 2
7+
:caption: MyProxyRenewalAgent options
8+
"""
9+
import concurrent.futures
10+
11+
from DIRAC import S_OK
12+
13+
from DIRAC.Core.Base.AgentModule import AgentModule
14+
from DIRAC.FrameworkSystem.DB.ProxyDB import ProxyDB
15+
16+
DEFAULT_MAIL_FROM = "[email protected]"
17+
18+
19+
class ProxyRenewalAgent(AgentModule):
20+
def initialize(self):
21+
22+
requiredLifeTime = self.am_getOption("MinimumLifeTime", 3600)
23+
renewedLifeTime = self.am_getOption("RenewedLifeTime", 54000)
24+
mailFrom = self.am_getOption("MailFrom", DEFAULT_MAIL_FROM)
25+
self.useMyProxy = self.am_getOption("UseMyProxy", False)
26+
self.proxyDB = ProxyDB(useMyProxy=self.useMyProxy, mailFrom=mailFrom)
27+
28+
self.log.info(f"Minimum Life time : {requiredLifeTime}")
29+
self.log.info(f"Life time on renew : {renewedLifeTime}")
30+
if self.useMyProxy:
31+
self.log.info(f"MyProxy server : {self.proxyDB.getMyProxyServer()}")
32+
self.log.info(f"MyProxy max proxy time : {self.proxyDB.getMyProxyMaxLifeTime()}")
33+
34+
return S_OK()
35+
36+
def __renewProxyForCredentials(self, userDN, userGroup):
37+
lifeTime = self.am_getOption("RenewedLifeTime", 54000)
38+
self.log.info(f"Renewing for {userDN}@{userGroup} {lifeTime} secs")
39+
res = self.proxyDB.renewFromMyProxy(userDN, userGroup, lifeTime=lifeTime)
40+
if not res["OK"]:
41+
self.log.error("Failed to renew proxy", f"for {userDN}@{userGroup} : {res['Message']}")
42+
else:
43+
self.log.info(f"Renewed proxy for {userDN}@{userGroup}")
44+
45+
def execute(self):
46+
"""The main agent execution method"""
47+
self.log.verbose("Purging expired requests")
48+
res = self.proxyDB.purgeExpiredRequests()
49+
if not res["OK"]:
50+
self.log.error(res["Message"])
51+
else:
52+
self.log.info(f"Purged {res['Value']} requests")
53+
54+
self.log.verbose("Purging expired tokens")
55+
res = self.proxyDB.purgeExpiredTokens()
56+
if not res["OK"]:
57+
self.log.error(res["Message"])
58+
else:
59+
self.log.info(f"Purged {res['Value']} tokens")
60+
61+
self.log.verbose("Purging expired proxies")
62+
res = self.proxyDB.purgeExpiredProxies()
63+
if not res["OK"]:
64+
self.log.error(res["Message"])
65+
else:
66+
self.log.info(f"Purged {res['Value']} proxies")
67+
68+
self.log.verbose("Purging logs")
69+
res = self.proxyDB.purgeLogs()
70+
if not res["OK"]:
71+
self.log.error(res["Message"])
72+
73+
if self.useMyProxy:
74+
res = self.proxyDB.getCredentialsAboutToExpire(self.am_getOption("MinimumLifeTime", 3600))
75+
if not res["OK"]:
76+
return res
77+
data = res["Value"]
78+
self.log.info(f"Renewing {len(data)} proxies...")
79+
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
80+
futures = []
81+
for record in data:
82+
userDN = record[0]
83+
userGroup = record[1]
84+
futures.append(executor.submit(self.__renewProxyForCredentials, userDN, userGroup))
85+
return S_OK()

src/DIRAC/FrameworkSystem/ConfigTemplate.cfg

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ Services
7777
TornadoProxyManager
7878
{
7979
Protocol = https
80-
MaxThreads = 100
8180
# Flag to use myproxy server
8281
UseMyProxy = False
8382
# Email to use as a sender for the expiration reminder
@@ -154,7 +153,7 @@ Services
154153
Default = authenticated
155154
FileTransfer
156155
{
157-
Default = authenticated
156+
Default = authenticated
158157
}
159158
}
160159
}
@@ -218,15 +217,16 @@ Services
218217
}
219218
Agents
220219
{
221-
##BEGIN MyProxyRenewalAgent
222-
MyProxyRenewalAgent
220+
##BEGIN ProxyRenewalAgent
221+
ProxyRenewalAgent
223222
{
224-
PollingTime = 1800
225-
MinValidity = 10000
226-
#The period for which the proxy will be extended. The value is in hours
227-
ValidityPeriod = 15
223+
PollingTime = 900
228224
# Email to use as a sender for the expiration reminder
229225
MailFrom = [email protected]
226+
# Renew, or not, the proxies stored on the MyProxy service
227+
UseMyProxy = False
228+
MinimumLifeTime = 3600
229+
RenewedLifeTime = 54000
230230
}
231231
##END
232232
CAUpdateAgent

src/DIRAC/FrameworkSystem/DB/ProxyDB.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from DIRAC.Core.Security.X509Request import X509Request # pylint: disable=import-error
2828
from DIRAC.Core.Security.X509Chain import X509Chain, isPUSPdn # pylint: disable=import-error
2929
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
30-
from DIRAC.ConfigurationSystem.Client.PathFinder import getDatabaseSection
3130
from DIRAC.FrameworkSystem.Client.NotificationClient import NotificationClient
3231
from DIRAC.Resources.ProxyProvider.ProxyProviderFactory import ProxyProviderFactory
3332

@@ -1192,8 +1191,9 @@ def purgeLogs(self):
11921191
11931192
:return: S_OK()/S_ERROR()
11941193
"""
1195-
cmd = "DELETE FROM `ProxyDB_Log` WHERE TIMESTAMPDIFF( SECOND, Timestamp, UTC_TIMESTAMP() ) > 15552000"
1196-
return self._update(cmd)
1194+
return self._update(
1195+
"DELETE FROM `ProxyDB_Log` WHERE TIMESTAMPDIFF( SECOND, Timestamp, UTC_TIMESTAMP() ) > 15552000"
1196+
)
11971197

11981198
def getLogsContent(self, selDict, sortList, start=0, limit=0):
11991199
"""

src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from DIRAC import gLogger, S_OK, S_ERROR
1010
from DIRAC.Core.DISET.RequestHandler import RequestHandler, getServiceOption
1111
from DIRAC.Core.Security import Properties
12-
from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler
1312
from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader
1413
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
1514

@@ -37,11 +36,7 @@ def initializeHandler(cls, serviceInfoDict):
3736
cls.__proxyDB = dbClass(useMyProxy=useMyProxy, mailFrom=mailFrom)
3837

3938
except RuntimeError as excp:
40-
return S_ERROR("Can't connect to ProxyDB: %s" % excp)
41-
gThreadScheduler.addPeriodicTask(900, cls.__proxyDB.purgeExpiredTokens, elapsedTime=900)
42-
gThreadScheduler.addPeriodicTask(900, cls.__proxyDB.purgeExpiredRequests, elapsedTime=900)
43-
gThreadScheduler.addPeriodicTask(21600, cls.__proxyDB.purgeLogs)
44-
gThreadScheduler.addPeriodicTask(3600, cls.__proxyDB.purgeExpiredProxies)
39+
return S_ERROR("Can't connect to ProxyDB", repr(excp))
4540
if useMyProxy:
4641
gLogger.info("MyProxy: %s\n MyProxy Server: %s" % (useMyProxy, cls.__proxyDB.getMyProxyServer()))
4742
return S_OK()

src/DIRAC/WorkloadManagementSystem/DB/ElasticJobParametersDB.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
CREATE TABLE `JobParameters` (
77
`JobID` INT(11) UNSIGNED NOT NULL,
88
`Name` VARCHAR(100) NOT NULL,
9-
`Value` TEXT NOT NULL,
9+
`Value` TEXT NOT NULL,
1010
PRIMARY KEY (`JobID`,`Name`),
1111
FOREIGN KEY (`JobID`) REFERENCES `Jobs`(`JobID`)
1212
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

tests/Jenkins/install.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LocalInstallation
1010
InstanceName = Production
1111
SkipCADownload = yes
1212
UseServerCertificate = yes
13-
# ConfigurationServer = dips://myprimaryserver.name:9135/Configuration/Server
13+
# ConfigurationServer = https://myprimaryserver.name:8443/Configuration/Server
1414
ConfigurationName = Production
1515
#LogLevel of the installed components
1616
LogLevel = DEBUG

0 commit comments

Comments
 (0)