Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -724,13 +724,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
Expand All @@ -745,19 +743,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
Expand All @@ -770,29 +764,27 @@ 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
:param int free: free terabytes
: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))

Expand Down
13 changes: 4 additions & 9 deletions src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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
Expand All @@ -92,15 +92,13 @@ 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
"""

# Stores in cache
res = self.rmClient.addOrModifySpaceTokenOccupancyCache(
endpoint=results["Endpoint"],
lastCheckTime=datetime.utcnow(),
free=results["Free"],
total=results["Total"],
Expand All @@ -116,8 +114,6 @@ def _storeCommand(self, results):
return siteRes

accountingDict = {
"StorageElement": results["ElementName"],
"Endpoint": results["Endpoint"],
"Site": siteRes["Value"] if siteRes["Value"] else "unassigned",
}

Expand Down Expand Up @@ -189,10 +185,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 = []
Expand Down Expand Up @@ -220,7 +215,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"])

Expand Down
4 changes: 1 addition & 3 deletions src/DIRAC/ResourceStatusSystem/DB/ResourceManagementDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,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")
Expand All @@ -337,7 +336,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)
Expand All @@ -351,7 +349,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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,33 +266,31 @@ 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

# 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"]

Expand Down
Loading