From 63e3e0bca431657fea7714bf204341b005aea810 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Mon, 7 Sep 2026 17:16:28 +0200 Subject: [PATCH 1/2] fix: removed endpoint from SpaceTokenOccupancyCache --- .../Systems/ResourceStatus/index.rst | 2 +- .../Client/ResourceManagementClient.py | 26 ++++++---------- .../Command/FreeDiskSpaceCommand.py | 25 ++++++--------- .../DB/ResourceManagementDB.py | 4 +-- .../Service/ResourceManagementHandler.py | 31 ++++++++++++++++--- .../Test_ResourceManagement.py | 26 +++++++--------- 6 files changed, 60 insertions(+), 54 deletions(-) diff --git a/docs/source/DeveloperGuide/Systems/ResourceStatus/index.rst b/docs/source/DeveloperGuide/Systems/ResourceStatus/index.rst index 65e2f3335ea..320053def2c 100644 --- a/docs/source/DeveloperGuide/Systems/ResourceStatus/index.rst +++ b/docs/source/DeveloperGuide/Systems/ResourceStatus/index.rst @@ -115,7 +115,7 @@ Cache tables for metrics used by policies. * - PolicyResult - Policy evaluation results (Element, Name, PolicyName, Status, Reason) * - SpaceTokenOccupancyCache - - Storage space usage (Endpoint, Token, Free, Guaranteed) + - Storage space usage (Token, Free, Guaranteed) * - TransferCache - Transfer quality metrics (SourceName, DestinationName, Metric, Value) diff --git a/src/DIRAC/ResourceStatusSystem/Client/ResourceManagementClient.py b/src/DIRAC/ResourceStatusSystem/Client/ResourceManagementClient.py index a76573318d1..b8aedd54b67 100644 --- a/src/DIRAC/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/src/DIRAC/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -654,13 +654,11 @@ def addOrModifyPolicyResult( # SpaceTokenOccupancyCache Methods ........................................... def selectSpaceTokenOccupancyCache( - self, endpoint=None, token=None, total=None, guaranteed=None, free=None, lastCheckTime=None, meta=None + self, token=None, total=None, guaranteed=None, free=None, lastCheckTime=None, meta=None ): """ Gets from SpaceTokenOccupancyCache all rows that match the parameters given. - :param endpoint: endpoint - :type endpoint: string, list :param token: name of the token :type token: string, list :param total: total terabytes @@ -675,19 +673,15 @@ def selectSpaceTokenOccupancyCache( For example: meta={'columns': ['Name']} will return only the 'Name' column. :return: S_OK() || S_ERROR() """ - columnNames = ["Endpoint", "Token", "Total", "Guaranteed", "Free", "LastCheckTime", "Meta"] - columnValues = [endpoint, token, total, guaranteed, free, lastCheckTime, meta] + columnNames = ["Token", "Total", "Guaranteed", "Free", "LastCheckTime", "Meta"] + columnValues = [token, total, guaranteed, free, lastCheckTime, meta] return self._getRPC().select("SpaceTokenOccupancyCache", prepareDict(columnNames, columnValues)) - def deleteSpaceTokenOccupancyCache( - self, endpoint=None, token=None, total=None, guaranteed=None, free=None, lastCheckTime=None - ): + def deleteSpaceTokenOccupancyCache(self, token=None, total=None, guaranteed=None, free=None, lastCheckTime=None): """ Deletes from SpaceTokenOccupancyCache all rows that match the parameters given. - :param endpoint: endpoint - :type endpoint: string, list :param token: name of the token :type token: string, list :param total: total terabytes @@ -700,20 +694,18 @@ def deleteSpaceTokenOccupancyCache( :type lastCheckTime: datetime, list :return: S_OK() || S_ERROR() """ - columnNames = ["Endpoint", "Token", "Total", "Guaranteed", "Free", "LastCheckTime"] - columnValues = [endpoint, token, total, guaranteed, free, lastCheckTime] + columnNames = ["Token", "Total", "Guaranteed", "Free", "LastCheckTime"] + columnValues = [token, total, guaranteed, free, lastCheckTime] return self._getRPC().delete("SpaceTokenOccupancyCache", prepareDict(columnNames, columnValues)) def addOrModifySpaceTokenOccupancyCache( - self, endpoint=None, token=None, total=None, guaranteed=None, free=None, lastCheckTime=None + self, token=None, total=None, guaranteed=None, free=None, lastCheckTime=None ): """ Adds or updates-if-duplicated to SpaceTokenOccupancyCache. Using `site` and `token` to query the database, decides whether to insert or update the table. - :param endpoint: endpoint - :type endpoint: string, list :param str token: name of the token :param int total: total terabytes :param int guaranteed: guaranteed terabytes @@ -721,8 +713,8 @@ def addOrModifySpaceTokenOccupancyCache( :param datetime lastCheckTime: time-stamp from which the result is effective :return: S_OK() || S_ERROR() """ - columnNames = ["Endpoint", "Token", "Total", "Guaranteed", "Free", "LastCheckTime"] - columnValues = [endpoint, token, total, guaranteed, free, lastCheckTime] + columnNames = ["Token", "Total", "Guaranteed", "Free", "LastCheckTime"] + columnValues = [token, total, guaranteed, free, lastCheckTime] return self._getRPC().addOrModify("SpaceTokenOccupancyCache", prepareDict(columnNames, columnValues)) diff --git a/src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py b/src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py index f96e45ee132..d4b5b2eabc0 100644 --- a/src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py +++ b/src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py @@ -1,10 +1,10 @@ -""" FreeDiskSpaceCommand - The Command gets the free space that is left in a Storage Element +"""FreeDiskSpaceCommand +The Command gets the free space that is left in a Storage Element - Note: there are, still, many references to "space tokens", - for example ResourceManagementClient().selectSpaceTokenOccupancyCache(token=elementName) - This is for historical reasons, and shoud be fixed one day. - For the moment, when you see "token" or "space token" here, just read "StorageElement". +Note: there are, still, many references to "space tokens", +for example ResourceManagementClient().selectSpaceTokenOccupancyCache(token=elementName) +This is for historical reasons, and shoud be fixed one day. +For the moment, when you see "token" or "space token" here, just read "StorageElement". """ @@ -80,7 +80,7 @@ def doNew(self, masterParams=None): free = occupancy["Free"] total = occupancy["Total"] - results = {"Endpoint": "Deprecated", "Free": free, "Total": total, "ElementName": elementName} + results = {"Free": free, "Total": total, "ElementName": elementName} result = self._storeCommand(results) if not result["OK"]: return result @@ -93,7 +93,6 @@ def _storeCommand(self, results): and adds records to the StorageOccupancy accounting. :param dict results: something like {'ElementName': 'CERN-HIST-EOS', - 'Endpoint': 'httpg://srm-eoslhcb-bis.cern.ch:8443/srm/v2/server', 'Free': 3264963586.10073, 'Total': 8000000000.0} :returns: S_OK/S_ERROR dict @@ -101,7 +100,6 @@ def _storeCommand(self, results): # Stores in cache res = self.rmClient.addOrModifySpaceTokenOccupancyCache( - endpoint=results["Endpoint"], lastCheckTime=DiracTime.utcnow(), free=results["Free"], total=results["Total"], @@ -117,8 +115,6 @@ def _storeCommand(self, results): return siteRes accountingDict = { - "StorageElement": results["ElementName"], - "Endpoint": results["Endpoint"], "Site": siteRes["Value"] if siteRes["Value"] else "unassigned", } @@ -192,10 +188,9 @@ def doMaster(self): return self._cleanCommand() def _cleanCommand(self, toDelete=None): - """Clean the spaceTokenOccupancy table from old endpoints + """Clean the spaceTokenOccupancy table from old SEs - :param tuple toDelete: endpoint to remove (endpoint, storage_element_name), - e.g. ('httpg://srm-lhcb.cern.ch:8443/srm/managerv2', CERN-RAW) + :param tuple toDelete: storage_element_name """ if not toDelete: toDelete = [] @@ -223,7 +218,7 @@ def _cleanCommand(self, toDelete=None): toDelete = [toDelete] for ep in toDelete: - res = self.rmClient.deleteSpaceTokenOccupancyCache(ep[0], ep[1]) + res = self.rmClient.deleteSpaceTokenOccupancyCache(ep) if not res["OK"]: self.log.warn("Could not delete entry from SpaceTokenOccupancyCache", res["Message"]) diff --git a/src/DIRAC/ResourceStatusSystem/DB/ResourceManagementDB.py b/src/DIRAC/ResourceStatusSystem/DB/ResourceManagementDB.py index 014d2755ef1..7d1e724840b 100644 --- a/src/DIRAC/ResourceStatusSystem/DB/ResourceManagementDB.py +++ b/src/DIRAC/ResourceStatusSystem/DB/ResourceManagementDB.py @@ -278,7 +278,6 @@ class SpaceTokenOccupancyCache(rmsBase): __tablename__ = "SpaceTokenOccupancyCache" __table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": "utf8mb4"} - endpoint = Column("Endpoint", String(128), nullable=False, primary_key=True) token = Column("Token", String(64), nullable=False, primary_key=True) guaranteed = Column("Guaranteed", Float(asdecimal=False), nullable=False, server_default="0") free = Column("Free", Float(asdecimal=False), nullable=False, server_default="0") @@ -293,7 +292,6 @@ def fromDict(self, dictionary): :type arguments: dict """ - self.endpoint = dictionary.get("Endpoint", self.endpoint) self.token = dictionary.get("Token", self.token) self.guaranteed = dictionary.get("Guaranteed", self.guaranteed) self.free = dictionary.get("Free", self.free) @@ -307,7 +305,7 @@ def fromDict(self, dictionary): def toList(self): """Simply returns a list of column values""" - return [self.endpoint, self.token, self.guaranteed, self.free, self.total, self.lastchecktime] + return [self.token, self.guaranteed, self.free, self.total, self.lastchecktime] class TransferCache(rmsBase): diff --git a/src/DIRAC/ResourceStatusSystem/Service/ResourceManagementHandler.py b/src/DIRAC/ResourceStatusSystem/Service/ResourceManagementHandler.py index 1eddad62a8f..2ea2dbc5ec2 100644 --- a/src/DIRAC/ResourceStatusSystem/Service/ResourceManagementHandler.py +++ b/src/DIRAC/ResourceStatusSystem/Service/ResourceManagementHandler.py @@ -1,11 +1,12 @@ -""" ResourceManagementHandler +"""ResourceManagementHandler - Module that allows users to access the ResourceManagementDB remotely. +Module that allows users to access the ResourceManagementDB remotely. """ -from DIRAC import gConfig, S_OK + +from DIRAC import S_OK, gConfig from DIRAC.Core.DISET.RequestHandler import RequestHandler, getServiceOption -from DIRAC.ResourceStatusSystem.Utilities import Synchronizer from DIRAC.ResourceStatusSystem.Service.ResourceStatusHandler import loadResourceStatusComponent +from DIRAC.ResourceStatusSystem.Utilities import Synchronizer class ResourceManagementHandlerMixin: @@ -25,6 +26,9 @@ class ResourceManagementHandlerMixin: Service are kept clean and tidied. """ + # Deprecated columns removed from SpaceTokenOccupancyCache (kept for backward compatibility) + _DEPRECATED_COLUMNS = {"SpaceTokenOccupancyCache": ["Endpoint"]} + @classmethod def initializeHandler(cls, serviceInfoDict): """ @@ -55,6 +59,21 @@ def __logResult(self, methodName, result): if not result["OK"]: self.log.error(f"{methodName} : {result['Message']}") + def _stripDeprecatedColumns(self, table, params): + """ + Remove deprecated columns from params for backward compatibility. + + :param str table: table name + :param dict params: query parameters + :return: cleaned params dict + """ + deprecatedCols = self._DEPRECATED_COLUMNS.get(table, []) + for col in deprecatedCols: + if col in params: + self.log.warn(f"Ignoring deprecated column '{col}' for table '{table}'") + params.pop(col) + return params + types_insert = [str, dict] def export_insert(self, table, params): @@ -71,6 +90,7 @@ def export_insert(self, table, params): :return: S_OK() || S_ERROR() """ + self._stripDeprecatedColumns(table, params) self.log.info(f"insert: {table} {params}") # remove unnecessary key generated by locals() @@ -97,6 +117,7 @@ def export_select(self, table, params): :return: S_OK() || S_ERROR() """ + self._stripDeprecatedColumns(table, params) params = {k: list(set(v)) if isinstance(v, list) else v for k, v in params.items()} self.log.info(f"select: {table} {params}") @@ -121,6 +142,7 @@ def export_delete(self, table, params): :return: S_OK() || S_ERROR() """ + self._stripDeprecatedColumns(table, params) self.log.info(f"delete: {table} {params}") res = self.db.delete(table, params) @@ -144,6 +166,7 @@ def export_addOrModify(self, table, params): :return: S_OK() || S_ERROR() """ + self._stripDeprecatedColumns(table, params) self.log.info(f"addOrModify: {table} {params}") res = self.db.addOrModify(table, params) diff --git a/tests/Integration/ResourceStatusSystem/Test_ResourceManagement.py b/tests/Integration/ResourceStatusSystem/Test_ResourceManagement.py index f721fdf871b..eb45edd4f06 100644 --- a/tests/Integration/ResourceStatusSystem/Test_ResourceManagement.py +++ b/tests/Integration/ResourceStatusSystem/Test_ResourceManagement.py @@ -228,40 +228,38 @@ def test_SpaceTokenOccupancy(rmClient): SpaceTokenOccupancy table """ - res = rmClient.deleteSpaceTokenOccupancyCache("endpoint", "token") # just making sure it's not there (yet) + res = rmClient.deleteSpaceTokenOccupancyCache("token") # just making sure it's not there (yet) assert res["OK"] is True, res["Message"] # TEST addOrModifySpaceTokenOccupancy - res = rmClient.addOrModifySpaceTokenOccupancyCache( - "endpoint", "token", 500.0, 1000.0, 200.0, datetime.datetime.now() - ) + res = rmClient.addOrModifySpaceTokenOccupancyCache("token", 500.0, 1000.0, 200.0, datetime.datetime.now()) assert res["OK"] is True, res["Message"] - res = rmClient.selectSpaceTokenOccupancyCache("endpoint", "token") + res = rmClient.selectSpaceTokenOccupancyCache("token") assert res["OK"] is True, res["Message"] # check if the name that we got is equal to the previously added 'token' - assert res["Value"][0][1] == "token" + assert res["Value"][0][0] == "token" - res = rmClient.addOrModifySpaceTokenOccupancyCache("endpoint", "token", free=100.0) + res = rmClient.addOrModifySpaceTokenOccupancyCache("token", free=100.0) assert res["OK"] is True, res["Message"] - res = rmClient.selectSpaceTokenOccupancyCache("endpoint", "token") + res = rmClient.selectSpaceTokenOccupancyCache("token") # check if the result has changed - assert res["Value"][0][3] == 100.0 + assert res["Value"][0][2] == 100.0 - res = rmClient.addOrModifySpaceTokenOccupancyCache("endpoint", "token", free=0.0) + res = rmClient.addOrModifySpaceTokenOccupancyCache("token", free=0.0) assert res["OK"] is True, res["Message"] - res = rmClient.selectSpaceTokenOccupancyCache("endpoint", "token") + res = rmClient.selectSpaceTokenOccupancyCache("token") # check if the result has changed - assert res["Value"][0][3] == 0.0 + assert res["Value"][0][2] == 0.0 # TEST deleteSpaceTokenOccupancy # ............................................................................... - res = rmClient.deleteSpaceTokenOccupancyCache("endpoint", "token") + res = rmClient.deleteSpaceTokenOccupancyCache("token") assert res["OK"] is True, res["Message"] - res = rmClient.selectSpaceTokenOccupancyCache("endpoint", "token") + res = rmClient.selectSpaceTokenOccupancyCache("token") assert res["OK"] is True, res["Message"] assert not res["Value"], res["Value"] From 0729ae062059a20576e4618548f321ede540b66d Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Tue, 8 Sep 2026 10:20:07 +0200 Subject: [PATCH 2/2] fix: Remove SpaceTokenOccupancyCache methods from ResourceManagementClient/Handler FreeDiskSpaceCommand now queries ResourceManagementDB directly instead of going through the client/handler/service layer. Added export_getSpaceTokenOccupancy to PublisherHandler as the only exposed endpoint for this table. Removed: - selectSpaceTokenOccupancyCache, deleteSpaceTokenOccupancyCache, addOrModifySpaceTokenOccupancyCache from ResourceManagementClient - _DEPRECATED_COLUMNS and _stripDeprecatedColumns from ResourceManagementHandler (only used for SpaceTokenOccupancyCache Endpoint column) - test_SpaceTokenOccupancy from integration tests --- .../Client/ResourceManagementClient.py | 67 ------------------- .../Command/FreeDiskSpaceCommand.py | 30 +++++---- .../Service/PublisherHandler.py | 22 +++++- .../Service/ResourceManagementHandler.py | 22 ------ .../Test_ResourceManagement.py | 41 ------------ 5 files changed, 37 insertions(+), 145 deletions(-) diff --git a/src/DIRAC/ResourceStatusSystem/Client/ResourceManagementClient.py b/src/DIRAC/ResourceStatusSystem/Client/ResourceManagementClient.py index b8aedd54b67..f8de8b63b80 100644 --- a/src/DIRAC/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/src/DIRAC/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -651,72 +651,5 @@ def addOrModifyPolicyResult( return self._getRPC().addOrModify("PolicyResult", prepareDict(columnNames, columnValues)) - # SpaceTokenOccupancyCache Methods ........................................... - - def selectSpaceTokenOccupancyCache( - self, token=None, total=None, guaranteed=None, free=None, lastCheckTime=None, meta=None - ): - """ - Gets from SpaceTokenOccupancyCache all rows that match the parameters given. - - :param token: name of the token - :type token: string, list - :param total: total terabytes - :type total: integer, list - :param guaranteed: guaranteed terabytes - :type guaranteed: integer, list - :param free: free terabytes - :type free: integer, list - :param lastCheckTime: time-stamp from which the result is effective - :type lastCheckTime: datetime, list - :param dict meta: metadata for the mysql query. Currently it is being used only for column selection. - For example: meta={'columns': ['Name']} will return only the 'Name' column. - :return: S_OK() || S_ERROR() - """ - columnNames = ["Token", "Total", "Guaranteed", "Free", "LastCheckTime", "Meta"] - columnValues = [token, total, guaranteed, free, lastCheckTime, meta] - - return self._getRPC().select("SpaceTokenOccupancyCache", prepareDict(columnNames, columnValues)) - - def deleteSpaceTokenOccupancyCache(self, token=None, total=None, guaranteed=None, free=None, lastCheckTime=None): - """ - Deletes from SpaceTokenOccupancyCache all rows that match the parameters given. - - :param token: name of the token - :type token: string, list - :param total: total terabytes - :type total: integer, list - :param guaranteed: guaranteed terabytes - :type guaranteed: integer, list - :param free: free terabytes - :type free: integer, list - :param lastCheckTime: time-stamp from which the result is effective - :type lastCheckTime: datetime, list - :return: S_OK() || S_ERROR() - """ - columnNames = ["Token", "Total", "Guaranteed", "Free", "LastCheckTime"] - columnValues = [token, total, guaranteed, free, lastCheckTime] - - return self._getRPC().delete("SpaceTokenOccupancyCache", prepareDict(columnNames, columnValues)) - - def addOrModifySpaceTokenOccupancyCache( - self, token=None, total=None, guaranteed=None, free=None, lastCheckTime=None - ): - """ - Adds or updates-if-duplicated to SpaceTokenOccupancyCache. Using `site` and `token` - to query the database, decides whether to insert or update the table. - - :param str token: name of the token - :param int total: total terabytes - :param int guaranteed: guaranteed terabytes - :param int free: free terabytes - :param datetime lastCheckTime: time-stamp from which the result is effective - :return: S_OK() || S_ERROR() - """ - columnNames = ["Token", "Total", "Guaranteed", "Free", "LastCheckTime"] - columnValues = [token, total, guaranteed, free, lastCheckTime] - - return self._getRPC().addOrModify("SpaceTokenOccupancyCache", prepareDict(columnNames, columnValues)) - # EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF diff --git a/src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py b/src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py index d4b5b2eabc0..525ac720e75 100644 --- a/src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py +++ b/src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py @@ -2,7 +2,7 @@ The Command gets the free space that is left in a Storage Element Note: there are, still, many references to "space tokens", -for example ResourceManagementClient().selectSpaceTokenOccupancyCache(token=elementName) +for example the SpaceTokenOccupancyCache table. This is for historical reasons, and shoud be fixed one day. For the moment, when you see "token" or "space token" here, just read "StorageElement". @@ -19,8 +19,8 @@ from DIRAC.Core.Utilities.TimeUtilities import DiracTime from DIRAC.DataManagementSystem.Utilities.DMSHelpers import DMSHelpers from DIRAC.Resources.Storage.StorageElement import StorageElement -from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient from DIRAC.ResourceStatusSystem.Command.Command import Command +from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB from DIRAC.ResourceStatusSystem.Utilities import CSHelpers @@ -32,7 +32,7 @@ class FreeDiskSpaceCommand(Command): def __init__(self, args=None, clients=None): super().__init__(args, clients=clients) - self.rmClient = ResourceManagementClient() + self.rmDB = ResourceManagementDB() def _prepareCommand(self): """ @@ -99,14 +99,17 @@ def _storeCommand(self, results): """ # Stores in cache - res = self.rmClient.addOrModifySpaceTokenOccupancyCache( - lastCheckTime=DiracTime.utcnow(), - free=results["Free"], - total=results["Total"], - token=results["ElementName"], + res = self.rmDB.addOrModify( + "SpaceTokenOccupancyCache", + { + "Token": results["ElementName"], + "Free": results["Free"], + "Total": results["Total"], + "LastCheckTime": DiracTime.utcnow(), + }, ) if not res["OK"]: - self.log.error("Error calling addOrModifySpaceTokenOccupancyCache", res["Message"]) + self.log.error("Error calling addOrModify on SpaceTokenOccupancyCache", res["Message"]) return res # Now proceed with the accounting @@ -147,7 +150,7 @@ def doCache(self): return params elementName, unit = params["Value"] - result = self.rmClient.selectSpaceTokenOccupancyCache(token=elementName) + result = self.rmDB.select("SpaceTokenOccupancyCache", {"Token": elementName}) if not result["OK"]: return result @@ -195,8 +198,9 @@ def _cleanCommand(self, toDelete=None): if not toDelete: toDelete = [] - res = self.rmClient.selectSpaceTokenOccupancyCache( - meta={"older": ["LastCheckTime", DiracTime.utcnow() - timedelta(hours=6)]} + res = self.rmDB.select( + "SpaceTokenOccupancyCache", + {"meta": {"older": ["LastCheckTime", DiracTime.utcnow() - timedelta(hours=6)]}}, ) if not res["OK"]: return res @@ -218,7 +222,7 @@ def _cleanCommand(self, toDelete=None): toDelete = [toDelete] for ep in toDelete: - res = self.rmClient.deleteSpaceTokenOccupancyCache(ep) + res = self.rmDB.delete("SpaceTokenOccupancyCache", {"Token": ep[0]}) if not res["OK"]: self.log.warn("Could not delete entry from SpaceTokenOccupancyCache", res["Message"]) diff --git a/src/DIRAC/ResourceStatusSystem/Service/PublisherHandler.py b/src/DIRAC/ResourceStatusSystem/Service/PublisherHandler.py index d99bd44eb10..59fa78a2f5e 100644 --- a/src/DIRAC/ResourceStatusSystem/Service/PublisherHandler.py +++ b/src/DIRAC/ResourceStatusSystem/Service/PublisherHandler.py @@ -9,13 +9,14 @@ from datetime import datetime, timedelta # DIRAC -from DIRAC import S_OK, gConfig, S_ERROR +from DIRAC import S_ERROR, S_OK, gConfig +from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getSiteCEMapping, getSites from DIRAC.Core.DISET.RequestHandler import RequestHandler from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader from DIRAC.Core.Utilities.SiteSEMapping import getSEHosts, getStorageElementsHosts from DIRAC.Core.Utilities.TimeUtilities import DiracTime -from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getSites, getSiteCEMapping from DIRAC.DataManagementSystem.Utilities.DMSHelpers import DMSHelpers +from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB class PublisherHandlerMixin: @@ -40,6 +41,8 @@ def initializeHandler(cls, serviceInfoDict): resourceManagementClientClass = result["Value"] cls.rmClient = resourceManagementClientClass() + cls.rmDB = ResourceManagementDB() + return S_OK() types_getSites = [] @@ -331,6 +334,21 @@ def export_getCachedDowntimes(self, element, elementType, name, severity): return result + types_selectSpaceTokenOccupancyCache = [(str, list, type(None))] + + @classmethod + def export_selectSpaceTokenOccupancyCache(cls, token): + """ + Gets space token occupancy from the SpaceTokenOccupancyCache table. + + :param token: name of the token (StorageElement) + :type token: str or list + :return: S_OK() || S_ERROR() + """ + + params = {"Token": token} if token else {} + return cls.rmDB.select("SpaceTokenOccupancyCache", params) + types_setStatus = [str] * 7 def export_setStatus(self, element, name, statusType, status, elementType, username, lastCheckTime): diff --git a/src/DIRAC/ResourceStatusSystem/Service/ResourceManagementHandler.py b/src/DIRAC/ResourceStatusSystem/Service/ResourceManagementHandler.py index 2ea2dbc5ec2..94ee26a3de8 100644 --- a/src/DIRAC/ResourceStatusSystem/Service/ResourceManagementHandler.py +++ b/src/DIRAC/ResourceStatusSystem/Service/ResourceManagementHandler.py @@ -26,9 +26,6 @@ class ResourceManagementHandlerMixin: Service are kept clean and tidied. """ - # Deprecated columns removed from SpaceTokenOccupancyCache (kept for backward compatibility) - _DEPRECATED_COLUMNS = {"SpaceTokenOccupancyCache": ["Endpoint"]} - @classmethod def initializeHandler(cls, serviceInfoDict): """ @@ -59,21 +56,6 @@ def __logResult(self, methodName, result): if not result["OK"]: self.log.error(f"{methodName} : {result['Message']}") - def _stripDeprecatedColumns(self, table, params): - """ - Remove deprecated columns from params for backward compatibility. - - :param str table: table name - :param dict params: query parameters - :return: cleaned params dict - """ - deprecatedCols = self._DEPRECATED_COLUMNS.get(table, []) - for col in deprecatedCols: - if col in params: - self.log.warn(f"Ignoring deprecated column '{col}' for table '{table}'") - params.pop(col) - return params - types_insert = [str, dict] def export_insert(self, table, params): @@ -90,7 +72,6 @@ def export_insert(self, table, params): :return: S_OK() || S_ERROR() """ - self._stripDeprecatedColumns(table, params) self.log.info(f"insert: {table} {params}") # remove unnecessary key generated by locals() @@ -117,7 +98,6 @@ def export_select(self, table, params): :return: S_OK() || S_ERROR() """ - self._stripDeprecatedColumns(table, params) params = {k: list(set(v)) if isinstance(v, list) else v for k, v in params.items()} self.log.info(f"select: {table} {params}") @@ -142,7 +122,6 @@ def export_delete(self, table, params): :return: S_OK() || S_ERROR() """ - self._stripDeprecatedColumns(table, params) self.log.info(f"delete: {table} {params}") res = self.db.delete(table, params) @@ -166,7 +145,6 @@ def export_addOrModify(self, table, params): :return: S_OK() || S_ERROR() """ - self._stripDeprecatedColumns(table, params) self.log.info(f"addOrModify: {table} {params}") res = self.db.addOrModify(table, params) diff --git a/tests/Integration/ResourceStatusSystem/Test_ResourceManagement.py b/tests/Integration/ResourceStatusSystem/Test_ResourceManagement.py index eb45edd4f06..f21389a8b3c 100644 --- a/tests/Integration/ResourceStatusSystem/Test_ResourceManagement.py +++ b/tests/Integration/ResourceStatusSystem/Test_ResourceManagement.py @@ -223,47 +223,6 @@ def test_PolicyResult(rmClient): assert not res["Value"], res["Value"] -def test_SpaceTokenOccupancy(rmClient): - """ - SpaceTokenOccupancy table - """ - - res = rmClient.deleteSpaceTokenOccupancyCache("token") # just making sure it's not there (yet) - assert res["OK"] is True, res["Message"] - - # TEST addOrModifySpaceTokenOccupancy - res = rmClient.addOrModifySpaceTokenOccupancyCache("token", 500.0, 1000.0, 200.0, datetime.datetime.now()) - assert res["OK"] is True, res["Message"] - - res = rmClient.selectSpaceTokenOccupancyCache("token") - assert res["OK"] is True, res["Message"] - # check if the name that we got is equal to the previously added 'token' - assert res["Value"][0][0] == "token" - - res = rmClient.addOrModifySpaceTokenOccupancyCache("token", free=100.0) - assert res["OK"] is True, res["Message"] - - res = rmClient.selectSpaceTokenOccupancyCache("token") - # check if the result has changed - assert res["Value"][0][2] == 100.0 - - res = rmClient.addOrModifySpaceTokenOccupancyCache("token", free=0.0) - assert res["OK"] is True, res["Message"] - - res = rmClient.selectSpaceTokenOccupancyCache("token") - # check if the result has changed - assert res["Value"][0][2] == 0.0 - - # TEST deleteSpaceTokenOccupancy - # ............................................................................... - res = rmClient.deleteSpaceTokenOccupancyCache("token") - assert res["OK"] is True, res["Message"] - - res = rmClient.selectSpaceTokenOccupancyCache("token") - assert res["OK"] is True, res["Message"] - assert not res["Value"], res["Value"] - - def test_Transfer(rmClient): """ TransferOccupancy table