Skip to content

Commit e5e2e84

Browse files
committed
feat: removed SandboxStore.unassignEntities
1 parent 3ba5efe commit e5e2e84

File tree

5 files changed

+9
-65
lines changed

5 files changed

+9
-65
lines changed

src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
from DIRAC.RequestManagementSystem.Client.Request import Request
3737
from DIRAC.WorkloadManagementSystem.Client import JobStatus
3838
from DIRAC.WorkloadManagementSystem.Client.JobMonitoringClient import JobMonitoringClient
39-
from DIRAC.WorkloadManagementSystem.Client.SandboxStoreClient import SandboxStoreClient
4039
from DIRAC.WorkloadManagementSystem.Client.WMSClient import WMSClient
4140
from DIRAC.WorkloadManagementSystem.DB.JobDB import JobDB
41+
from DIRAC.WorkloadManagementSystem.DB.SandboxMetadataDB import SandboxMetadataDB
4242

4343

4444
class JobCleaningAgent(AgentModule):
@@ -152,10 +152,12 @@ def removeDeletedJobs(self):
152152
return S_OK()
153153

154154
self.log.info("Unassigning sandboxes from soon to be deleted jobs", f"({len(jobList)})")
155-
result = SandboxStoreClient(useCertificates=True).unassignJobs(jobList)
156-
if not result["OK"]:
157-
self.log.error("Cannot unassign jobs to sandboxes", result["Message"])
158-
return result
155+
156+
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
159161

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

src/DIRAC/WorkloadManagementSystem/Client/SandboxStoreClient.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,6 @@ def assignSandboxesToJob(self, jobId, sbList, ownerName="", ownerGroup=""):
241241
return SandboxStoreClient.__smdb.assignSandboxesToEntities({eId: sbList}, ownerName, ownerGroup)
242242
return self.__getRPCClient().assignSandboxesToEntities({eId: sbList}, ownerName, ownerGroup)
243243

244-
def unassignJobs(self, jobIdList):
245-
"""Unassign SB to a job"""
246-
if isinstance(jobIdList, int):
247-
jobIdList = [jobIdList]
248-
entitiesList = []
249-
for jobId in jobIdList:
250-
entitiesList.append(f"Job:{jobId}")
251-
return self.__getRPCClient().unassignEntities(entitiesList)
252-
253244
def downloadSandboxForJob(self, jobId, sbType, destinationPath="", inMemory=False, unpack=True):
254245
"""Download SB for a job"""
255246
result = self.__getRPCClient().getSandboxesAssignedToEntity(f"Job:{jobId}")

src/DIRAC/WorkloadManagementSystem/DB/SandboxMetadataDB.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -220,48 +220,22 @@ def assignSandboxesToEntities(self, enDict, requesterName, requesterGroup, owner
220220
return result
221221
return S_OK(assigned)
222222

223-
def __entitiesByRequesterCond(self, requesterName, requesterGroup):
224-
sqlCond = []
225-
requesterProps = Registry.getPropertiesForEntity(requesterGroup, name=requesterName)
226-
if Properties.JOB_ADMINISTRATOR in requesterProps:
227-
# Do nothing, just ensure it doesn't fit in the other cases
228-
pass
229-
elif Properties.JOB_SHARING in requesterProps:
230-
sqlCond.append(f"o.OwnerGroup='{requesterGroup}'")
231-
elif Properties.NORMAL_USER in requesterProps:
232-
sqlCond.append(f"o.OwnerGroup='{requesterGroup}'")
233-
sqlCond.append(f"o.Owner='{requesterName}'")
234-
else:
235-
return S_ERROR("Not authorized to access sandbox")
236-
return sqlCond
237-
238223
@convertToReturnValue
239-
def unassignEntities(self, entities, requesterName, requesterGroup):
224+
def unassignEntities(self, entities: list):
240225
"""
241-
Unassign jobs to sandboxes
226+
Unassign entities to sandboxes. Entities are a list of strings, e.g. ['job:1234', 'job:5678'].
242227
243228
:param list entities: list of entities to unassign
244229
"""
245230
if not entities:
246231
return None
247-
conds = self.__entitiesByRequesterCond(requesterName, requesterGroup)
248232

249233
sqlCmd = "CREATE TEMPORARY TABLE to_delete_EntityId (EntityId VARCHAR(128) NOT NULL, PRIMARY KEY (EntityId)) ENGINE=MEMORY;"
250234
returnValueOrRaise(self._update(sqlCmd))
251235
try:
252236
sqlCmd = "INSERT INTO to_delete_EntityId (EntityId) VALUES ( %s )"
253237
returnValueOrRaise(self._updatemany(sqlCmd, [(e,) for e in entities]))
254238
sqlCmd = "DELETE m from `sb_EntityMapping` m JOIN to_delete_EntityId t USING (EntityId)"
255-
if conds:
256-
sqlCmd = " ".join(
257-
[
258-
sqlCmd,
259-
"JOIN `sb_SandBoxes` s ON s.SBId = m.SBId",
260-
"JOIN `sb_Owners` o ON s.OwnerId = o.OwnerId",
261-
"WHERE",
262-
" AND ".join(conds),
263-
]
264-
)
265239
returnValueOrRaise(self._update(sqlCmd))
266240
finally:
267241
sqlCmd = "DROP TEMPORARY TABLE to_delete_EntityId"

src/DIRAC/WorkloadManagementSystem/Service/SandboxStoreHandler.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,6 @@ def export_assignSandboxesToEntities(self, enDict, ownerName="", ownerGroup=""):
343343
enDict, credDict["username"], credDict["group"], ownerName, ownerGroup
344344
)
345345

346-
##################
347-
# Unassign sbs to jobs
348-
349-
types_unassignEntities = [(list, tuple)]
350-
351-
def export_unassignEntities(self, entitiesList):
352-
"""
353-
Unassign a list of jobs
354-
"""
355-
credDict = self.getRemoteCredentials()
356-
return self.sandboxDB.unassignEntities(entitiesList, credDict["username"], credDict["group"])
357-
358346
##################
359347
# Getting assigned sandboxes
360348

tests/Integration/WorkloadManagementSystem/Test_SandboxStoreClient.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,15 @@
3838
from DIRAC.tests.Utilities.utils import find_all
3939
from DIRAC.WorkloadManagementSystem.Client.SandboxStoreClient import SandboxStoreClient
4040

41-
4241
gLogger.setLevel("DEBUG")
4342

4443

4544
def test_SSCChain():
4645
"""full test of functionalities"""
4746
ssc = SandboxStoreClient()
4847

49-
jobId = 1
50-
5148
exeScriptLocation = find_all("exe-script.py", "../..", "/DIRAC/tests/Integration")[0]
5249
fileList = [exeScriptLocation]
5350

5451
res = ssc.uploadFilesAsSandbox(fileList)
5552
assert res["OK"], res["Message"]
56-
57-
# TODO : FIXME
58-
# res = ssc.downloadSandboxForJob(jobId, "Input") # to run this we need the RSS on
59-
# print(res) # for debug...
60-
# assert res["OK"], res["Message"]
61-
62-
res = ssc.unassignJobs([jobId])
63-
assert res["OK"], res["Message"]

0 commit comments

Comments
 (0)