Skip to content

Commit e87844d

Browse files
authored
Merge pull request #7258 from chrisburr/legacy-adaptor-selector
[9.0] Support selecting legacy adaptor client
2 parents f2fc2f1 + e18eb7c commit e87844d

File tree

13 files changed

+106
-23
lines changed

13 files changed

+106
-23
lines changed

dirac.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ DiracX
134134
URL = https://diracx.invalid:8000
135135
# A key used to have priviledged interactions with diracx. see
136136
LegacyExchangeApiKey = diracx:legacy:InsecureChangeMe
137-
# List of VOs which should use DiracX via the legacy compatibility mechanism
138-
EnabledVOs = gridpp,cta
137+
# List of VOs which should not use DiracX via the legacy compatibility mechanism
138+
DisabledVOs = dteam,cta
139139
}
140140
### Registry section:
141141
# Sections to register VOs, groups, users and hosts

docs/source/AdministratorGuide/ServerInstallations/environment_variable_configuration.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ DIRAC_DEPRECATED_FAIL
1818
If set, the use of functions or objects that are marked ``@deprecated`` will fail. Useful for example in continuous
1919
integration tests against future versions of DIRAC
2020

21-
DIRAC_ENABLE_DIRACX_JOB_MONITORING
22-
If set, calls the diracx job monitoring service. Off by default.
23-
2421
DIRAC_FEWER_CFG_LOCKS
2522
If ``true`` or ``yes`` or ``on`` or ``1`` or ``y`` or ``t``, DIRAC will reduce the number of locks used when accessing the CS for better performance (default, ``no``).
2623

integration_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"DIRAC_USE_JSON_ENCODE": None,
3636
"INSTALLATION_BRANCH": "",
3737
}
38-
DIRACX_OPTIONS = ("DIRAC_ENABLE_DIRACX_JOB_MONITORING",)
38+
DIRACX_OPTIONS = ()
3939
DEFAULT_MODULES = {"DIRAC": Path(__file__).parent.absolute()}
4040

4141
# Static configuration

src/DIRAC/ConfigurationSystem/Client/PathFinder.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,19 @@ def getServiceURLs(system, service=None, setup=False, failover=False):
248248
return resList
249249

250250

251+
def useLegacyAdapter(system, service=None) -> bool:
252+
"""Should DiracX be used for this service via the legacy adapter mechanism
253+
254+
:param str system: system name or full name e.g.: Framework/ProxyManager
255+
:param str service: service name, like 'ProxyManager'.
256+
257+
:return: bool -- True if DiracX should be used
258+
"""
259+
system, service = divideFullName(system, service)
260+
value = gConfigurationData.extractOptionFromCFG(f"/DiracX/LegacyClientEnabled/{system}/{service}")
261+
return (value or "no").lower() in ("y", "yes", "true", "1")
262+
263+
251264
def getServiceURL(system, service=None, setup=False):
252265
"""Generate url.
253266
@@ -297,3 +310,9 @@ def getGatewayURLs(system="", service=None):
297310
return False
298311
gateways = List.randomize(List.fromChar(gateways, ","))
299312
return [checkComponentURL(u, system, service) for u in gateways if u] if system and service else gateways
313+
314+
315+
def getDisabledDiracxVOs() -> list[str]:
316+
"""Get the list of VOs for which DiracX is enabled"""
317+
vos = gConfigurationData.extractOptionFromCFG("/DiracX/DisabledVOs")
318+
return List.fromChar(vos or "", ",")

src/DIRAC/Core/Base/Client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ def _getRPC(self, rpc=None, url="", timeout=None):
109109
timeout = self.timeout
110110

111111
self.__kwargs["timeout"] = timeout
112-
rpc = RPCClientSelector(url, httpsClient=self.httpsClient, **self.__kwargs)
112+
113+
rpc = RPCClientSelector(
114+
url, httpsClient=self.httpsClient, diracxClient=getattr(self, "diracxClient", None), **self.__kwargs
115+
)
113116
return rpc
114117

115118

src/DIRAC/Core/Tornado/Client/ClientSelector.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import functools
1313

1414
from DIRAC import gLogger
15-
from DIRAC.ConfigurationSystem.Client.PathFinder import getServiceURL
15+
from DIRAC.ConfigurationSystem.Client.PathFinder import getServiceURL, useLegacyAdapter
1616
from DIRAC.Core.DISET.RPCClient import RPCClient
1717
from DIRAC.Core.DISET.TransferClient import TransferClient
1818
from DIRAC.Core.Tornado.Client.TornadoClient import TornadoClient
@@ -54,6 +54,7 @@ def ClientSelector(disetClient, *args, **kwargs): # We use same interface as RP
5454
# We detect if we need to use a specific class for the HTTPS client
5555

5656
tornadoClient = kwargs.pop("httpsClient", TornadoClient)
57+
diracxClient = kwargs.pop("diracxClient", None)
5758

5859
# We have to make URL resolution BEFORE the RPCClient or TornadoClient to determine which one we want to use
5960
# URL is defined as first argument (called serviceName) in RPCClient
@@ -65,6 +66,13 @@ def ClientSelector(disetClient, *args, **kwargs): # We use same interface as RP
6566
# If we are not already given a URL, resolve it
6667
if serviceName.startswith(("http", "dip")):
6768
completeUrl = serviceName
69+
elif useLegacyAdapter(serviceName):
70+
sLog.debug(f"Using legacy adapter for service {serviceName}")
71+
if diracxClient is None:
72+
raise NotImplementedError(
73+
"DiracX is enabled but no diracxClient is provided, do you need to update your client?"
74+
)
75+
return diracxClient()
6876
else:
6977
completeUrl = getServiceURL(serviceName)
7078
sLog.debug(f"URL resolved: {completeUrl}")

src/DIRAC/FrameworkSystem/scripts/dirac_login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ def loginWithCertificate(self):
315315

316316
# Get a token for use with diracx
317317
vo = getVOMSVOForGroup(self.group)
318-
enabledVOs = gConfig.getValue("/DiracX/EnabledVOs", [])
319-
if vo in enabledVOs:
318+
disabledVOs = gConfig.getValue("/DiracX/DisabledVOs", [])
319+
if vo not in disabledVOs:
320320
from diracx.core.utils import write_credentials # pylint: disable=import-error
321321
from diracx.core.models import TokenResponse # pylint: disable=import-error
322322
from diracx.core.preferences import DiracxPreferences # pylint: disable=import-error

src/DIRAC/FrameworkSystem/scripts/dirac_proxy_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ def doTheMagic(self):
239239
return resultProxyUpload
240240

241241
vo = Registry.getVOMSVOForGroup(self.__piParams.diracGroup)
242-
enabledVOs = gConfig.getValue("/DiracX/EnabledVOs", [])
243-
if vo in enabledVOs:
242+
disabledVOs = gConfig.getValue("/DiracX/DisabledVOs", [])
243+
if vo not in disabledVOs:
244244
from diracx.core.utils import write_credentials # pylint: disable=import-error
245245
from diracx.core.models import TokenResponse # pylint: disable=import-error
246246
from diracx.core.preferences import DiracxPreferences # pylint: disable=import-error

src/DIRAC/WorkloadManagementSystem/Client/JobMonitoringClient.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
from DIRAC.Core.Utilities.DEncode import ignoreEncodeWarning
66
from DIRAC.Core.Utilities.JEncode import strToIntDict
77

8+
try:
9+
from DIRAC.WorkloadManagementSystem.FutureClient.JobMonitoringClient import (
10+
JobMonitoringClient as futureJobMonitoringClient,
11+
)
12+
except ImportError:
13+
futureJobMonitoringClient = None
14+
815

916
@createClient("WorkloadManagement/JobMonitoring")
1017
class JobMonitoringClient(Client):
1118
def __init__(self, **kwargs):
1219
super().__init__(**kwargs)
1320
self.setServer("WorkloadManagement/JobMonitoring")
1421

15-
if os.getenv("DIRAC_ENABLE_DIRACX_JOB_MONITORING", "No").lower() in ("yes", "true"):
16-
from DIRAC.WorkloadManagementSystem.FutureClient.JobMonitoringClient import (
17-
JobMonitoringClient as futureJobMonitoringClient,
18-
)
19-
20-
httpsClient = futureJobMonitoringClient
22+
diracxClient = futureJobMonitoringClient
2123

2224
@ignoreEncodeWarning
2325
def getJobsStatus(self, jobIDs):

src/DIRAC/WorkloadManagementSystem/Service/SandboxStoreHandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def _getFromClient(self, fileId, token, fileSize, fileHelper=None, data=""):
111111
credDict = self.getRemoteCredentials()
112112
vo = Registry.getVOForGroup(credDict["group"])
113113

114-
enabledVOs = gConfig.getValue("/DiracX/EnabledVOs", [])
115-
if self._useDiracXBackend and vo in enabledVOs:
114+
disabledVOs = gConfig.getValue("/DiracX/DisabledVOs", [])
115+
if self._useDiracXBackend and vo not in disabledVOs:
116116
from DIRAC.FrameworkSystem.Utilities.diracx import TheImpersonator
117117
from diracx.client.models import SandboxInfo # pylint: disable=import-error
118118

0 commit comments

Comments
 (0)