From 2861ba129114904af95400f3a9dd2bc4eabf5cd4 Mon Sep 17 00:00:00 2001 From: Christophe Haen Date: Wed, 30 Aug 2023 16:06:59 +0200 Subject: [PATCH] import cleanup --- .../Service/ProxyManagerHandler.py | 2 +- .../FutureClient/JobMonitoringClient.py | 52 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py b/src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py index fc2acca1313..19193be27e0 100644 --- a/src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py +++ b/src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py @@ -411,7 +411,7 @@ def export_getVOMSProxyWithToken(self, userDN, userGroup, requestPem, requiredLi def export_exchangeProxyForToken(self): try: - from diracx.routers.auth import ( + from diracx.routers.auth import ( # pylint: disable=import-error AuthSettings, create_access_token, TokenResponse, diff --git a/src/DIRAC/WorkloadManagementSystem/FutureClient/JobMonitoringClient.py b/src/DIRAC/WorkloadManagementSystem/FutureClient/JobMonitoringClient.py index 5759a8e7fed..dfbf98c3d54 100644 --- a/src/DIRAC/WorkloadManagementSystem/FutureClient/JobMonitoringClient.py +++ b/src/DIRAC/WorkloadManagementSystem/FutureClient/JobMonitoringClient.py @@ -1,34 +1,36 @@ # pylint: disable=import-error -from diracx.client import Dirac -from diracx.client.models import JobSearchParams +import os -from diracx.cli.utils import get_auth_headers -from diracx.core.preferences import DiracxPreferences +if os.getenv("DIRAC_ENABLE_DIRACX_JOB_MONITORING", "No").lower() in ("yes", "true"): + from diracx.client import Dirac + from diracx.client.models import JobSearchParams -from DIRAC.Core.Utilities.ReturnValues import convertToReturnValue + from diracx.cli.utils import get_auth_headers + from diracx.core.preferences import DiracxPreferences + from DIRAC.Core.Utilities.ReturnValues import convertToReturnValue -class JobMonitoringClient: - def __init__(self, *args, **kwargs): - self.endpoint = DiracxPreferences().url + class JobMonitoringClient: + def __init__(self, *args, **kwargs): + self.endpoint = DiracxPreferences().url - def fetch(self, parameters, jobIDs): - with Dirac(endpoint=self.endpoint) 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} + def fetch(self, parameters, jobIDs): + with Dirac(endpoint=self.endpoint) 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} - @convertToReturnValue - def getJobsMinorStatus(self, jobIDs): - return self.fetch(["MinorStatus"], jobIDs) + @convertToReturnValue + def getJobsMinorStatus(self, jobIDs): + return self.fetch(["MinorStatus"], jobIDs) - @convertToReturnValue - def getJobsStates(self, jobIDs): - return self.fetch(["Status", "MinorStatus", "ApplicationStatus"], jobIDs) + @convertToReturnValue + def getJobsStates(self, jobIDs): + return self.fetch(["Status", "MinorStatus", "ApplicationStatus"], jobIDs) - @convertToReturnValue - def getJobsSites(self, jobIDs): - return self.fetch(["Site"], jobIDs) + @convertToReturnValue + def getJobsSites(self, jobIDs): + return self.fetch(["Site"], jobIDs)