Skip to content

Commit 6b0e667

Browse files
committed
feat: removed SandboxStore.assignSandboxesToEntities
1 parent e5e2e84 commit 6b0e667

File tree

4 files changed

+9
-53
lines changed

4 files changed

+9
-53
lines changed

src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ def removeDeletedJobs(self):
154154
self.log.info("Unassigning sandboxes from soon to be deleted jobs", f"({len(jobList)})")
155155

156156
entitiesList = [f"Job:{jobId}" for jobId in jobList]
157-
res = SandboxMetadataDB().unassignEntities(entitiesList)
158-
if not res["OK"]:
159-
self.log.error("Cannot unassign jobs to sandboxes", res["Message"])
160-
return res
157+
if not (result := SandboxMetadataDB().unassignEntities(entitiesList))["OK"]:
158+
self.log.error("Cannot unassign jobs to sandboxes", result["Message"])
159+
return result
161160

162161
self.log.info("Attempting to remove deleted jobs", f"({len(jobList)})")
163162

src/DIRAC/WorkloadManagementSystem/Client/SandboxStoreClient.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
class SandboxStoreClient:
2222
__validSandboxTypes = ("Input", "Output")
23-
__smdb = None
2423

2524
def __init__(self, rpcClient=None, transferClient=None, smdb=False, **kwargs):
2625
"""Constructor
@@ -37,21 +36,8 @@ def __init__(self, rpcClient=None, transferClient=None, smdb=False, **kwargs):
3736
self.__transferClient = transferClient
3837
self.__kwargs = kwargs
3938
self.__vo = None
40-
SandboxStoreClient.__smdb = smdb
4139
if "delegatedGroup" in kwargs:
4240
self.__vo = getVOForGroup(kwargs["delegatedGroup"])
43-
if SandboxStoreClient.__smdb is True:
44-
try:
45-
from DIRAC.WorkloadManagementSystem.DB.SandboxMetadataDB import SandboxMetadataDB
46-
47-
SandboxStoreClient.__smdb = SandboxMetadataDB()
48-
result = SandboxStoreClient.__smdb._getConnection() # pylint: disable=protected-access
49-
if not result["OK"]:
50-
SandboxStoreClient.__smdb = False
51-
else:
52-
result["Value"].close()
53-
except (ImportError, RuntimeError, AttributeError):
54-
SandboxStoreClient.__smdb = False
5541

5642
def __getRPCClient(self):
5743
"""Get an RPC client for SB service"""
@@ -227,20 +213,6 @@ def downloadSandbox(self, sbLocation, destinationDir="", inMemory=False, unpack=
227213
##############
228214
# Jobs
229215

230-
def assignSandboxesToJob(self, jobId, sbList, ownerName="", ownerGroup=""):
231-
"""
232-
Assign sandboxes to a job.
233-
sbList must be a list of sandboxes and relation types
234-
sbList = [ ( "SB:SEName|SEPFN", "Input" ), ( "SB:SEName|SEPFN", "Output" ) ]
235-
"""
236-
eId = f"Job:{jobId}"
237-
for sbT in sbList:
238-
if sbT[1] not in self.__validSandboxTypes:
239-
return S_ERROR(f"Invalid Sandbox type {sbT[1]}")
240-
if SandboxStoreClient.__smdb and ownerName and ownerGroup:
241-
return SandboxStoreClient.__smdb.assignSandboxesToEntities({eId: sbList}, ownerName, ownerGroup)
242-
return self.__getRPCClient().assignSandboxesToEntities({eId: sbList}, ownerName, ownerGroup)
243-
244216
def downloadSandboxForJob(self, jobId, sbType, destinationPath="", inMemory=False, unpack=True):
245217
"""Download SB for a job"""
246218
result = self.__getRPCClient().getSandboxesAssignedToEntity(f"Job:{jobId}")

src/DIRAC/WorkloadManagementSystem/Executor/JobSanity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
""" The Job Sanity executor assigns sandboxes to the job """
22
from DIRAC import S_OK
3-
from DIRAC.WorkloadManagementSystem.Client.SandboxStoreClient import SandboxStoreClient
3+
from DIRAC.WorkloadManagementSystem.DB.SandboxMetadataDB import SandboxMetadataDB
44
from DIRAC.WorkloadManagementSystem.Executor.Base.OptimizerExecutor import OptimizerExecutor
55

66

@@ -15,7 +15,6 @@ class JobSanity(OptimizerExecutor):
1515
@classmethod
1616
def initializeOptimizer(cls):
1717
"""Initialize specific parameters for JobSanityAgent."""
18-
cls.sandboxClient = SandboxStoreClient(useCertificates=True, smdb=True)
1918
return S_OK()
2019

2120
def optimizeJob(self, jid, jobState):
@@ -57,7 +56,8 @@ def checkInputSandbox(self, jobState, manifest):
5756
if not numSBsToAssign:
5857
return S_OK(0)
5958
self.jobLog.info("Assigning sandboxes", f"({numSBsToAssign} on behalf of {ownerName}@{ownerGroup}@{vo})")
60-
result = self.sandboxClient.assignSandboxesToJob(jobState.jid, sbsToAssign, ownerName, ownerGroup)
59+
eId = f"Job:{jobState.jid}"
60+
result = SandboxMetadataDB().assignSandboxesToEntities({eId: sbsToAssign}, ownerName, ownerGroup)
6161
if not result["OK"]:
6262
self.jobLog.error("Could not assign sandboxes in the SandboxStore")
6363
return result

src/DIRAC/WorkloadManagementSystem/Service/SandboxStoreHandler.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _getFromClient(self, fileId, token, fileSize, fileHelper=None, data=""):
139139
gLogger.debug("Sandbox already exists in storage backend", res.pfn)
140140

141141
assignTo = {key: [(res.pfn, assignTo[key])] for key in assignTo}
142-
result = self.export_assignSandboxesToEntities(assignTo)
142+
result = self.sandboxDB.assignSandboxesToEntities(assignTo, credDict["username"], credDict["group"])
143143
if not result["OK"]:
144144
return result
145145
return S_OK(res.pfn)
@@ -153,7 +153,7 @@ def _getFromClient(self, fileId, token, fileSize, fileHelper=None, data=""):
153153
fileHelper.markAsTransferred()
154154
sbURL = f"SB:{self.__localSEName}|{sbPath}"
155155
assignTo = {key: [(sbURL, assignTo[key])] for key in assignTo}
156-
result = self.export_assignSandboxesToEntities(assignTo)
156+
result = self.sandboxDB.assignSandboxesToEntities(assignTo, credDict["username"], credDict["group"])
157157
if not result["OK"]:
158158
return result
159159
return S_OK(sbURL)
@@ -210,7 +210,7 @@ def _getFromClient(self, fileId, token, fileSize, fileHelper=None, data=""):
210210

211211
sbURL = f"SB:{self.__localSEName}|{sbPath}"
212212
assignTo = {key: [(sbURL, assignTo[key])] for key in assignTo}
213-
if not (result := self.export_assignSandboxesToEntities(assignTo))["OK"]:
213+
if not (result := self.sandboxDB.assignSandboxesToEntities(assignTo, credDict["username"], credDict["group"]))["OK"]:
214214
return result
215215
return S_OK(sbURL)
216216

@@ -328,21 +328,6 @@ def __moveToFinalLocation(self, localFilePath, sbPath):
328328

329329
return result
330330

331-
##################
332-
# Assigning sbs to jobs
333-
334-
types_assignSandboxesToEntities = [dict]
335-
336-
def export_assignSandboxesToEntities(self, enDict, ownerName="", ownerGroup=""):
337-
"""
338-
Assign sandboxes to jobs.
339-
Expects a dict of { entityId : [ ( SB, SBType ), ... ] }
340-
"""
341-
credDict = self.getRemoteCredentials()
342-
return self.sandboxDB.assignSandboxesToEntities(
343-
enDict, credDict["username"], credDict["group"], ownerName, ownerGroup
344-
)
345-
346331
##################
347332
# Getting assigned sandboxes
348333

0 commit comments

Comments
 (0)