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
25 changes: 6 additions & 19 deletions src/DIRAC/DataManagementSystem/scripts/dirac_admin_allow_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def main():
DIRAC.exit()

STATUS_TYPES = ["ReadAccess", "WriteAccess", "CheckAccess", "RemoveAccess"]
ALLOWED_STATUSES = ["Unknown", "InActive", "Banned", "Probing", "Degraded", "Error"]

statusAllowedDict = {}
for statusType in STATUS_TYPES:
Expand All @@ -123,26 +122,14 @@ def main():
# InActive is used on the CS model, Banned is the equivalent in RSS
for statusType in STATUS_TYPES:
if statusFlagDict[statusType]:
if seOptions.get(statusType) == "Active":
gLogger.notice(f"{statusType} status of {se} is already Active")
continue
if statusType in seOptions:
if not seOptions[statusType] in ALLOWED_STATUSES:
gLogger.notice(
"%s option for %s is %s, instead of %s"
% (statusType, se, seOptions["ReadAccess"], ALLOWED_STATUSES)
)
gLogger.notice("Try specifying the command switches")
resR = resourceStatus.setElementStatus(se, "StorageElement", statusType, "Active", reason, userName)
if not resR["OK"]:
gLogger.fatal(f"Failed to update {se} {statusType} to Active, exit -", resR["Message"])
DIRAC.exit(-1)
else:
resR = resourceStatus.setElementStatus(
se, "StorageElement", statusType, "Active", reason, userName
)
if not resR["OK"]:
gLogger.fatal(f"Failed to update {se} {statusType} to Active, exit -", resR["Message"])
DIRAC.exit(-1)
else:
gLogger.notice(f"Successfully updated {se} {statusType} to Active")
statusAllowedDict[statusType].append(se)
gLogger.notice(f"Successfully updated {se} {statusType} to Active")
statusAllowedDict[statusType].append(se)

totalAllowed = 0
totalAllowedSEs = []
Expand Down
88 changes: 24 additions & 64 deletions src/DIRAC/DataManagementSystem/scripts/dirac_admin_ban_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,83 +113,43 @@ def main():

# Eventually, we will get rid of the notion of InActive, as we always write Banned.
if read and "ReadAccess" in seOptions:
if seOptions["ReadAccess"] == "Banned":
gLogger.notice("Read access already banned", se)
resR["OK"] = True
elif not seOptions["ReadAccess"] in ["Active", "Degraded", "Probing", "Error"]:
gLogger.notice(
"Read option for %s is %s, instead of %s"
% (se, seOptions["ReadAccess"], ["Active", "Degraded", "Probing", "Error"])
)
gLogger.notice("Try specifying the command switches")
resR = resourceStatus.setElementStatus(se, "StorageElement", "ReadAccess", "Banned", reason, userName)
# res = csAPI.setOption( "%s/%s/ReadAccess" % ( storageCFGBase, se ), "InActive" )
if not resR["OK"]:
gLogger.error(f"Failed to update {se} read access to Banned")
else:
resR = resourceStatus.setElementStatus(se, "StorageElement", "ReadAccess", "Banned", reason, userName)
# res = csAPI.setOption( "%s/%s/ReadAccess" % ( storageCFGBase, se ), "InActive" )
if not resR["OK"]:
gLogger.error(f"Failed to update {se} read access to Banned")
else:
gLogger.notice(f"Successfully updated {se} read access to Banned")
readBanned.append(se)
gLogger.notice(f"Successfully updated {se} read access to Banned")
readBanned.append(se)

# Eventually, we will get rid of the notion of InActive, as we always write Banned.
if write and "WriteAccess" in seOptions:
if seOptions["WriteAccess"] == "Banned":
gLogger.notice("Write access already banned", se)
resW["OK"] = True
elif not seOptions["WriteAccess"] in ["Active", "Degraded", "Probing"]:
gLogger.notice(
"Write option for %s is %s, instead of %s"
% (se, seOptions["WriteAccess"], ["Active", "Degraded", "Probing"])
)
gLogger.notice("Try specifying the command switches")
resW = resourceStatus.setElementStatus(se, "StorageElement", "WriteAccess", "Banned", reason, userName)
# res = csAPI.setOption( "%s/%s/WriteAccess" % ( storageCFGBase, se ), "InActive" )
if not resW["OK"]:
gLogger.error(f"Failed to update {se} write access to Banned")
else:
resW = resourceStatus.setElementStatus(se, "StorageElement", "WriteAccess", "Banned", reason, userName)
# res = csAPI.setOption( "%s/%s/WriteAccess" % ( storageCFGBase, se ), "InActive" )
if not resW["OK"]:
gLogger.error(f"Failed to update {se} write access to Banned")
else:
gLogger.notice(f"Successfully updated {se} write access to Banned")
writeBanned.append(se)
gLogger.notice(f"Successfully updated {se} write access to Banned")
writeBanned.append(se)

# Eventually, we will get rid of the notion of InActive, as we always write Banned.
if check and "CheckAccess" in seOptions:
if seOptions["CheckAccess"] == "Banned":
gLogger.notice("Check access already banned", se)
resC["OK"] = True
elif not seOptions["CheckAccess"] in ["Active", "Degraded", "Probing"]:
gLogger.notice(
"Check option for %s is %s, instead of %s"
% (se, seOptions["CheckAccess"], ["Active", "Degraded", "Probing"])
)
gLogger.notice("Try specifying the command switches")
resC = resourceStatus.setElementStatus(se, "StorageElement", "CheckAccess", "Banned", reason, userName)
# res = csAPI.setOption( "%s/%s/CheckAccess" % ( storageCFGBase, se ), "InActive" )
if not resC["OK"]:
gLogger.error(f"Failed to update {se} check access to Banned")
else:
resC = resourceStatus.setElementStatus(se, "StorageElement", "CheckAccess", "Banned", reason, userName)
# res = csAPI.setOption( "%s/%s/CheckAccess" % ( storageCFGBase, se ), "InActive" )
if not resC["OK"]:
gLogger.error(f"Failed to update {se} check access to Banned")
else:
gLogger.notice(f"Successfully updated {se} check access to Banned")
checkBanned.append(se)
gLogger.notice(f"Successfully updated {se} check access to Banned")
checkBanned.append(se)

# Eventually, we will get rid of the notion of InActive, as we always write Banned.
if remove and "RemoveAccess" in seOptions:
if seOptions["RemoveAccess"] == "Banned":
gLogger.notice("Remove access already banned", se)
resC["OK"] = True
elif not seOptions["RemoveAccess"] in ["Active", "Degraded", "Probing"]:
gLogger.notice(
"Remove option for %s is %s, instead of %s"
% (se, seOptions["RemoveAccess"], ["Active", "Degraded", "Probing"])
)
gLogger.notice("Try specifying the command switches")
resC = resourceStatus.setElementStatus(se, "StorageElement", "RemoveAccess", "Banned", reason, userName)
# res = csAPI.setOption( "%s/%s/CheckAccess" % ( storageCFGBase, se ), "InActive" )
if not resC["OK"]:
gLogger.error(f"Failed to update {se} remove access to Banned")
else:
resC = resourceStatus.setElementStatus(se, "StorageElement", "RemoveAccess", "Banned", reason, userName)
# res = csAPI.setOption( "%s/%s/CheckAccess" % ( storageCFGBase, se ), "InActive" )
if not resC["OK"]:
gLogger.error(f"Failed to update {se} remove access to Banned")
else:
gLogger.notice(f"Successfully updated {se} remove access to Banned")
removeBanned.append(se)
gLogger.notice(f"Successfully updated {se} remove access to Banned")
removeBanned.append(se)

if not (resR["OK"] or resW["OK"] or resC["OK"]):
DIRAC.exit(-1)
Expand Down
28 changes: 4 additions & 24 deletions src/DIRAC/Interfaces/API/DiracAdmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def getSiteMask(self, printOutput=False, status="Active"):

#############################################################################
def getBannedSites(self, printOutput=False):
"""Retrieve current list of banned and probing sites.
"""Retrieve current list of banned sites.

Example usage:

Expand All @@ -122,16 +122,12 @@ def getBannedSites(self, printOutput=False):
if not bannedSites["OK"]:
return bannedSites

probingSites = self.sitestatus.getSites(siteState="Probing")
if not probingSites["OK"]:
return probingSites

mergedList = sorted(bannedSites["Value"] + probingSites["Value"])
bannedList = sorted(bannedSites["Value"])

if printOutput:
gLogger.notice("\n".join(mergedList))
gLogger.notice("\n".join(bannedList))

return S_OK(mergedList)
return S_OK(bannedList)

#############################################################################
def getSiteSection(self, site, printOutput=False):
Expand Down Expand Up @@ -170,14 +166,6 @@ def allowSite(self, site, comment, printOutput=False, days=1):
if not (result := self._checkSiteIsValid(site))["OK"]:
return result

if not (result := self.getSiteMask(status="Active"))["OK"]:
return result
siteMask = result["Value"]
if site in siteMask:
if printOutput:
gLogger.notice(f"Site {site} is already Active")
return S_OK(f"Site {site} is already Active")

tokenLifetime = int(days)
if tokenLifetime <= 0:
tokenExpiration = datetime.max
Expand Down Expand Up @@ -246,14 +234,6 @@ def banSite(self, site, comment, printOutput=False, days=1):
"""
if not (result := self._checkSiteIsValid(site))["OK"]:
return result
mask = self.getSiteMask(status="Banned")
if not mask["OK"]:
return mask
siteMask = mask["Value"]
if site in siteMask:
if printOutput:
gLogger.notice(f"Site {site} is already Banned")
return S_OK(f"Site {site} is already Banned")

tokenLifetime = int(days)
if tokenLifetime <= 0:
Expand Down
11 changes: 5 additions & 6 deletions src/DIRAC/ResourceStatusSystem/Client/ResourceStatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from DIRAC.ResourceStatusSystem.Utilities.InfoGetter import getPoliciesThatApply
from DIRAC.ResourceStatusSystem.Utilities.RSSCacheNoThread import RSSCache
from DIRAC.ResourceStatusSystem.Utilities.RssConfiguration import RssConfiguration
from DIRAC.ResourceStatusSystem.PolicySystem.StateMachine import resolveElementStatus


class ResourceStatus(metaclass=DIRACSingleton):
Expand Down Expand Up @@ -66,13 +67,13 @@ def getElementStatus(self, elementName, elementType, statusType=None, default=No
>>> getElementStatus('SE1', 'StorageElement', ['ReadAccess', 'WriteAccess'])
S_OK( { 'SE1': { 'ReadAccess': 'Banned' , 'WriteAccess': 'Active'} } } )
>>> getElementStatus('SE1', 'StorageElement')
S_OK( { 'SE1': { 'ReadAccess': 'Probing' ,
S_OK( { 'SE1': { 'ReadAccess': 'Banned' ,
'WriteAccess': 'Active',
'CheckAccess': 'Degraded',
'CheckAccess': 'Active',
'RemoveAccess': 'Banned'} } } )
>>> getElementStatus(['CE1', 'CE2'], 'ComputingElement')
S_OK( {'CE1': {'all': 'Active'},
'CE2': {'all': 'Probing'}}}
'CE2': {'all': 'Banned'}}}
"""

allowedParameters = ["StorageElement", "ComputingElement", "FTS"]
Expand Down Expand Up @@ -257,9 +258,7 @@ def getCacheDictFromRawData(rawList):

:return: dict of the form { ( elementName, elementType, statusType, vO ) : status, ... }
"""

res = {}
for entry in rawList:
res.update({(entry[0], entry[1], entry[2], entry[4]): entry[3]})

res[(entry[0], entry[1], entry[2], entry[4])] = resolveElementStatus(entry[3])
return res
11 changes: 5 additions & 6 deletions src/DIRAC/ResourceStatusSystem/Client/SiteStatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient
from DIRAC.ResourceStatusSystem.Utilities.RSSCacheNoThread import RSSCache
from DIRAC.ResourceStatusSystem.Utilities.RssConfiguration import RssConfiguration
from DIRAC.ResourceStatusSystem.PolicySystem.StateMachine import resolveElementStatus


class SiteStatus(metaclass=DIRACSingleton):
Expand Down Expand Up @@ -125,7 +126,7 @@ def __getRSSSiteStatus(self, siteName=None):
def getUsableSites(self, siteNames=None):
"""
Returns all sites that are usable if their
statusType is either Active or Degraded; in a list.
statusType is either Active; in a list.

examples
>>> siteStatus.getUsableSites( ['test1.test1.uk', 'test2.test2.net', 'test3.test3.org'] )
Expand All @@ -147,7 +148,7 @@ def getUsableSites(self, siteNames=None):
return siteStatusDictRes
if not siteStatusDictRes["Value"]:
return S_OK([])
return S_OK([x[0] for x in siteStatusDictRes["Value"].items() if x[1] in ["Active", "Degraded"]])
return S_OK([x[0] for x in siteStatusDictRes["Value"].items() if x[1] == "Active"])

def getSites(self, siteState="Active"):
"""
Expand Down Expand Up @@ -188,7 +189,7 @@ def getSites(self, siteState="Active"):
else:
# fix case sensitive string
siteState = siteState.capitalize()
allowedStateList = ["Active", "Banned", "Degraded", "Probing", "Error", "Unknown"]
allowedStateList = ["Active", "Banned"]
if siteState not in allowedStateList:
return S_ERROR(errno.EINVAL, "Not a valid status, parameter rejected")

Expand Down Expand Up @@ -275,9 +276,7 @@ def getCacheDictFromRawData(rawList):

:return: dict of the form { ( elementName ) : status, ... }
"""

res = {}
for entry in rawList:
res.update({(entry[0]): entry[1]})

res[entry[0]] = resolveElementStatus(entry[1])
return res
18 changes: 18 additions & 0 deletions src/DIRAC/ResourceStatusSystem/PolicySystem/StateMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,21 @@ def getLevelOfPolicyState(self, policyResult):
"""

return self.getLevelOfState(policyResult["Status"])


def resolveElementStatus(status):
"""
Maps an internal RSS status onto the simplified 'Active' / 'Banned' status
exposed to clients.

examples:
>>> resolveElementStatus( 'Degraded' )
'Active'
>>> resolveElementStatus( 'Unknown' )
'Banned'

:param str status: the internal RSS status
:return: str, 'Active' or 'Banned'
"""
ALLOWED = {"Active", "Degraded"}
return "Active" if status in ALLOWED else "Banned"
16 changes: 4 additions & 12 deletions src/DIRAC/Resources/Storage/StorageElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,21 +547,13 @@ def status(self):

# If nothing is defined in the CS Access is allowed
# If something is defined, then it must be set to Active
retDict["Read"] = not (
"ReadAccess" in self.options and self.options["ReadAccess"] not in ("Active", "Degraded")
)
retDict["Write"] = not (
"WriteAccess" in self.options and self.options["WriteAccess"] not in ("Active", "Degraded")
)
retDict["Remove"] = not (
"RemoveAccess" in self.options and self.options["RemoveAccess"] not in ("Active", "Degraded")
)
retDict["Read"] = not ("ReadAccess" in self.options and self.options["ReadAccess"] != "Active")
retDict["Write"] = not ("WriteAccess" in self.options and self.options["WriteAccess"] != "Active")
retDict["Remove"] = not ("RemoveAccess" in self.options and self.options["RemoveAccess"] != "Active")
if retDict["Read"]:
retDict["Check"] = True
else:
retDict["Check"] = not (
"CheckAccess" in self.options and self.options["CheckAccess"] not in ("Active", "Degraded")
)
retDict["Check"] = not ("CheckAccess" in self.options and self.options["CheckAccess"] != "Active")
diskSE = True
tapeSE = False
if "SEType" in self.options:
Expand Down
2 changes: 1 addition & 1 deletion src/DIRAC/WorkloadManagementSystem/Agent/SiteDirector.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _buildQueueDict(
self.log.error("Can not get the status of computing elements: ", result["Message"])
return result
# Try to get CEs which have been probed and those unprobed (vO='all').
ceMaskList = [ceName for ceName in result["Value"] if result["Value"][ceName]["all"] in ("Active", "Degraded")]
ceMaskList = [ceName for ceName in result["Value"] if result["Value"][ceName]["all"] == "Active"]

# Filter the unusable queues
for queueName in list(self.queueDict.keys()):
Expand Down
4 changes: 0 additions & 4 deletions src/DIRAC/WorkloadManagementSystem/DB/JobDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,10 +1094,6 @@ def getSiteSummaryWeb(self, selectDict, sortList, startItem, maxItems):

# Get the site mask status
siteMask = {}
resultMask = self.siteClient.getSites("All")
if resultMask["OK"]:
for site in resultMask["Value"]:
siteMask[site] = "NoMask"
resultMask = self.siteClient.getSites("Active")
if resultMask["OK"]:
for site in resultMask["Value"]:
Expand Down
Loading
Loading