Skip to content

Commit

Permalink
feat: Support using both HTTPS and DiracX
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Oct 30, 2023
1 parent 90ec210 commit 0d72a7d
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 20 deletions.
4 changes: 2 additions & 2 deletions dirac.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ DiracX
URL = https://diracx.invalid:8000
# A key used to have priviledged interactions with diracx. see
LegacyExchangeApiKey = diracx:legacy:InsecureChangeMe
# List of VOs which should use DiracX via the legacy compatibility mechanism
EnabledVOs = gridpp,cta
# List of VOs which should not use DiracX via the legacy compatibility mechanism
DisabledVOs = dteam,cta
}
### Registry section:
# Sections to register VOs, groups, users and hosts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ DIRAC_DEPRECATED_FAIL
If set, the use of functions or objects that are marked ``@deprecated`` will fail. Useful for example in continuous
integration tests against future versions of DIRAC

DIRAC_ENABLE_DIRACX_JOB_MONITORING
If set, calls the diracx job monitoring service. Off by default.

DIRAC_FEWER_CFG_LOCKS
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``).

Expand Down
2 changes: 1 addition & 1 deletion integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"DIRAC_USE_JSON_ENCODE": None,
"INSTALLATION_BRANCH": "",
}
DIRACX_OPTIONS = ("DIRAC_ENABLE_DIRACX_JOB_MONITORING",)
DIRACX_OPTIONS = ()
DEFAULT_MODULES = {"DIRAC": Path(__file__).parent.absolute()}

# Static configuration
Expand Down
19 changes: 19 additions & 0 deletions src/DIRAC/ConfigurationSystem/Client/PathFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ def getServiceURLs(system, service=None, setup=False, failover=False):
return resList


def useLegacyAdapter(system, service=None) -> bool:
"""Should DiracX be used for this service via the legacy adapter mechanism
:param str system: system name or full name e.g.: Framework/ProxyManager
:param str service: service name, like 'ProxyManager'.
:return: bool -- True if DiracX should be used
"""
system, service = divideFullName(system, service)
value = gConfigurationData.extractOptionFromCFG(f"/DiracX/LegacyClientEnabled/{system}/{service}")
return (value or "no").lower() in ("y", "yes", "true", "1")


def getServiceURL(system, service=None, setup=False):
"""Generate url.
Expand Down Expand Up @@ -297,3 +310,9 @@ def getGatewayURLs(system="", service=None):
return False
gateways = List.randomize(List.fromChar(gateways, ","))
return [checkComponentURL(u, system, service) for u in gateways if u] if system and service else gateways


def getDisabledDiracxVOs() -> list[str]:
"""Get the list of VOs for which DiracX is enabled"""
vos = gConfigurationData.extractOptionFromCFG("/DiracX/DisabledVOs")
return List.fromChar(vos or "", ",")
5 changes: 4 additions & 1 deletion src/DIRAC/Core/Base/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def _getRPC(self, rpc=None, url="", timeout=None):
timeout = self.timeout

self.__kwargs["timeout"] = timeout
rpc = RPCClientSelector(url, httpsClient=self.httpsClient, **self.__kwargs)

rpc = RPCClientSelector(
url, httpsClient=self.httpsClient, diracxClient=getattr(self, "diracxClient", None), **self.__kwargs
)
return rpc


Expand Down
10 changes: 9 additions & 1 deletion src/DIRAC/Core/Tornado/Client/ClientSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import functools

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

tornadoClient = kwargs.pop("httpsClient", TornadoClient)
diracxClient = kwargs.pop("diracxClient", None)

# We have to make URL resolution BEFORE the RPCClient or TornadoClient to determine which one we want to use
# URL is defined as first argument (called serviceName) in RPCClient
Expand All @@ -65,6 +66,13 @@ def ClientSelector(disetClient, *args, **kwargs): # We use same interface as RP
# If we are not already given a URL, resolve it
if serviceName.startswith(("http", "dip")):
completeUrl = serviceName
elif useLegacyAdapter(serviceName):
sLog.debug(f"Using legacy adapter for service {serviceName}")
if diracxClient is None:
raise NotImplementedError(
"DiracX is enabled but no diracxClient is provided, do you need to update your client?"
)
return diracxClient()
else:
completeUrl = getServiceURL(serviceName)
sLog.debug(f"URL resolved: {completeUrl}")
Expand Down
4 changes: 2 additions & 2 deletions src/DIRAC/FrameworkSystem/scripts/dirac_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ def loginWithCertificate(self):

# Get a token for use with diracx
vo = getVOMSVOForGroup(self.group)
enabledVOs = gConfig.getValue("/DiracX/EnabledVOs", [])
if vo in enabledVOs:
disabledVOs = gConfig.getValue("/DiracX/DisabledVOs", [])
if vo not in disabledVOs:
from diracx.core.utils import write_credentials # pylint: disable=import-error
from diracx.core.models import TokenResponse # pylint: disable=import-error
from diracx.core.preferences import DiracxPreferences # pylint: disable=import-error
Expand Down
4 changes: 2 additions & 2 deletions src/DIRAC/FrameworkSystem/scripts/dirac_proxy_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def doTheMagic(self):
return resultProxyUpload

vo = Registry.getVOMSVOForGroup(self.__piParams.diracGroup)
enabledVOs = gConfig.getValue("/DiracX/EnabledVOs", [])
if vo in enabledVOs:
disabledVOs = gConfig.getValue("/DiracX/DisabledVOs", [])
if vo not in disabledVOs:
from diracx.core.utils import write_credentials # pylint: disable=import-error
from diracx.core.models import TokenResponse # pylint: disable=import-error
from diracx.core.preferences import DiracxPreferences # pylint: disable=import-error
Expand Down
14 changes: 8 additions & 6 deletions src/DIRAC/WorkloadManagementSystem/Client/JobMonitoringClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
from DIRAC.Core.Utilities.DEncode import ignoreEncodeWarning
from DIRAC.Core.Utilities.JEncode import strToIntDict

try:
from DIRAC.WorkloadManagementSystem.FutureClient.JobMonitoringClient import (
JobMonitoringClient as futureJobMonitoringClient,
)
except ImportError:
futureJobMonitoringClient = None


@createClient("WorkloadManagement/JobMonitoring")
class JobMonitoringClient(Client):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.setServer("WorkloadManagement/JobMonitoring")

if os.getenv("DIRAC_ENABLE_DIRACX_JOB_MONITORING", "No").lower() in ("yes", "true"):
from DIRAC.WorkloadManagementSystem.FutureClient.JobMonitoringClient import (
JobMonitoringClient as futureJobMonitoringClient,
)

httpsClient = futureJobMonitoringClient
diracxClient = futureJobMonitoringClient

@ignoreEncodeWarning
def getJobsStatus(self, jobIDs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def _getFromClient(self, fileId, token, fileSize, fileHelper=None, data=""):
credDict = self.getRemoteCredentials()
vo = Registry.getVOForGroup(credDict["group"])

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

Expand Down

0 comments on commit 0d72a7d

Please sign in to comment.