From e8f6edac73a95ec3c11d027ee26590f0766a322b Mon Sep 17 00:00:00 2001 From: Christophe Haen Date: Fri, 19 May 2023 17:12:39 +0200 Subject: [PATCH] start lgacy client and integration tests --- .../Core/Tornado/Client/ClientSelector.py | 1 + .../Client/JobMonitoringClient.py | 6 ++++ .../FutureClient/JobMonitoringClient.py | 34 +++++++++++++++++++ .../FutureClient/__init__.py | 0 tests/CI/docker-compose.yml | 7 ++++ 5 files changed, 48 insertions(+) create mode 100644 src/DIRAC/WorkloadManagementSystem/FutureClient/JobMonitoringClient.py create mode 100644 src/DIRAC/WorkloadManagementSystem/FutureClient/__init__.py diff --git a/src/DIRAC/Core/Tornado/Client/ClientSelector.py b/src/DIRAC/Core/Tornado/Client/ClientSelector.py index db64d438dac..d22d41a5484 100644 --- a/src/DIRAC/Core/Tornado/Client/ClientSelector.py +++ b/src/DIRAC/Core/Tornado/Client/ClientSelector.py @@ -77,6 +77,7 @@ def ClientSelector(disetClient, *args, **kwargs): # We use same interface as RP except Exception as e: # pylint: disable=broad-except # If anything went wrong in the resolution, we return default RPCClient # So the behaviour is exactly the same as before implementation of Tornado + # breakpoint() sLog.warn("Could not select DISET or Tornado client", f"{repr(e)}") rpc = disetClient(*args, **kwargs) return rpc diff --git a/src/DIRAC/WorkloadManagementSystem/Client/JobMonitoringClient.py b/src/DIRAC/WorkloadManagementSystem/Client/JobMonitoringClient.py index 288b89143fe..2a2f1505071 100755 --- a/src/DIRAC/WorkloadManagementSystem/Client/JobMonitoringClient.py +++ b/src/DIRAC/WorkloadManagementSystem/Client/JobMonitoringClient.py @@ -4,6 +4,10 @@ from DIRAC.Core.Utilities.DEncode import ignoreEncodeWarning from DIRAC.Core.Utilities.JEncode import strToIntDict +from DIRAC.WorkloadManagementSystem.FutureClient.JobMonitoringClient import ( + JobMonitoringClient as futureJobMonitoringClient, +) + @createClient("WorkloadManagement/JobMonitoring") class JobMonitoringClient(Client): @@ -11,6 +15,8 @@ def __init__(self, **kwargs): super().__init__(**kwargs) self.setServer("WorkloadManagement/JobMonitoring") + httpsClient = futureJobMonitoringClient + @ignoreEncodeWarning def getJobsStatus(self, jobIDs): res = self._getRPC().getJobsStatus(jobIDs) diff --git a/src/DIRAC/WorkloadManagementSystem/FutureClient/JobMonitoringClient.py b/src/DIRAC/WorkloadManagementSystem/FutureClient/JobMonitoringClient.py new file mode 100644 index 00000000000..b85531664bb --- /dev/null +++ b/src/DIRAC/WorkloadManagementSystem/FutureClient/JobMonitoringClient.py @@ -0,0 +1,34 @@ +from diracx.client import Dirac +from diracx.client.models import JobSearchParams + +from diracx.cli.utils import get_auth_headers + +from DIRAC.Core.Utilities.ReturnValues import convertToReturnValue + + +def fetch(parameters, jobIDs): + # breakpoint() + with Dirac(endpoint="http://localhost:8000") as api: + jobs = api.jobs.search( + parameters=["JobID"] + parameters, + search=[{"parameter": "JobID", "operator": "in", "values": jobIDs}], + headers=get_auth_headers(), + ) + return {j["JobID"]: {param: j[param] for param in parameters} for j in jobs} + + +class JobMonitoringClient: + def __init__(self, *args, **kwargs): + """TODO""" + + @convertToReturnValue + def getJobsMinorStatus(self, jobIDs): + return fetch(["MinorStatus"], jobIDs) + + @convertToReturnValue + def getJobsStates(self, jobIDs): + return fetch(["Status", "MinorStatus", "ApplicationStatus"], jobIDs) + + @convertToReturnValue + def getJobsSites(self, jobIDs): + return fetch(["Site"], jobIDs) diff --git a/src/DIRAC/WorkloadManagementSystem/FutureClient/__init__.py b/src/DIRAC/WorkloadManagementSystem/FutureClient/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/CI/docker-compose.yml b/tests/CI/docker-compose.yml index e3de9efb188..b37dc7d3281 100644 --- a/tests/CI/docker-compose.yml +++ b/tests/CI/docker-compose.yml @@ -42,6 +42,13 @@ services: retries: 15 start_period: 60s + diracx: + image: gitlab-registry.cern.ch/chaen/chrissquare-hack-a-ton/diracx + container_name: diracx + environment: + - DIRAC_CS_SOURCE=todo + ports: + - 80:80 # Mock of an S3 storage s3-direct: