Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0] Change TS addFile logic for Deleted files #7758

Closed
wants to merge 9 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
PROB_IN_FC = "ProbInFC"
#:
REMOVED = "Removed"
#:
DELETED = "Deleted"

# below ones are for inherited transformations
#:
Expand Down
45 changes: 43 additions & 2 deletions src/DIRAC/TransformationSystem/DB/TransformationDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from DIRAC import gLogger, S_OK, S_ERROR
from DIRAC.Core.Base.DB import DB
from DIRAC.Core.Utilities.DErrno import cmpError
from DIRAC.TransformationSystem.Client import TransformationFilesStatus
from DIRAC.Resources.Catalog.FileCatalog import FileCatalog
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
from DIRAC.Core.Utilities.List import stringListToString, intListToString, breakListIntoChunks
Expand Down Expand Up @@ -1126,7 +1127,7 @@ def __addMetaQuery(self, transID, queryDict, queryType, author="", connection=Fa

for parameterName in sorted(queryDict):
parameterValue = queryDict[parameterName]
if not parameterValue:
if parameterValue is None:
continue
parameterType = "String"
if isinstance(parameterValue, (list, tuple)):
Expand All @@ -1138,6 +1139,9 @@ def __addMetaQuery(self, transID, queryDict, queryType, author="", connection=Fa
if isinstance(parameterValue, int):
parameterType = "Integer"
parameterValue = str(parameterValue)
if isinstance(parameterValue, float):
parameterType = "Float"
parameterValue = str(parameterValue)
if isinstance(parameterValue, dict):
parameterType = "Dict"
parameterValue = str(parameterValue)
Expand Down Expand Up @@ -1617,6 +1621,26 @@ def addFile(self, fileDicts, force=False, connection=False):
gLogger.info("Files to add to transformations:", filesToAdd)
if filesToAdd:
for transID, lfns in transFiles.items():
# Check if file is already in the Transformation and if is in Deleted Status
res = self.getTransformationFiles(
condDict={"TransformationID": transID, "LFN": lfns}, connection=connection
)
if not res["OK"]:
return res
for fileDict in res["Value"]:
if fileDict["Status"] == TransformationFilesStatus.DELETED:
res = self.__setTransformationFileStatus(
list([fileDict["FileID"]]), TransformationFilesStatus.UNUSED, connection=connection
)
if not res["OK"]:
return res
if not (
res := self.__setDataFileStatus(
list([fileDict["FileID"]]), "New", connection=connection
)["OK"]
):
return res

res = self.addFilesToTransformation(transID, lfns)
if not res["OK"]:
gLogger.error("Failed to add files to transformation", f"{transID} {res['Message']}")
Expand Down Expand Up @@ -1689,7 +1713,7 @@ def __addDirectory(self, path, force):
successful.append(lfn)
return {"OK": True, "Value": len(res["Value"]["Successful"]), "Successful": successful, "Failed": failed}

def setMetadata(self, path, usermetadatadict):
def setMetadata(self, path, usermetadatadict, connection=False):
"""
It can be applied to a file or to a directory (path).
For a file, add the file to Transformations if the updated metadata dictionary passes the filter.
Expand Down Expand Up @@ -1747,6 +1771,23 @@ def setMetadata(self, path, usermetadatadict):
gLogger.info("Files to add to transformations:", filesToAdd)
if filesToAdd:
for transID, lfns in transFiles.items():
# Check if file is already in the Transformation and if is in Deleted Status
res = self.getTransformationFiles(
condDict={"TransformationID": transID, "LFN": lfns}, connection=connection
)
if not res["OK"]:
return res
for fileDict in res["Value"]:
if fileDict["Status"] == TransformationFilesStatus.DELETED:
res = self.__setTransformationFileStatus(
list([fileDict["FileID"]]), TransformationFilesStatus.UNUSED, connection=connection
)
if not res["OK"]:
return res
res = self.__setDataFileStatus(list([fileDict["FileID"]]), "New", connection=connection)
if not res["OK"]:
return res

res = self.addFilesToTransformation(transID, lfns)
if not res["OK"]:
gLogger.error("Failed to add files to transformation", f"{transID} {res['Message']}")
Expand Down
Loading