-
Notifications
You must be signed in to change notification settings - Fork 183
[9.0] feat: Add diracx secrets in SiteDirector #8239
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
Closed
Robin-Van-de-Merghel
wants to merge
8
commits into
DIRACGrid:integration
from
Robin-Van-de-Merghel:robin-add-diracx-auth
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5f54d5a
feat: Add DiracX support into the database
Robin-Van-de-Merghel 979ac4c
feat: Migrating client toward DiracX
Robin-Van-de-Merghel 356211a
fix: Fix lint, and removed generated code
Robin-Van-de-Merghel 73a4f94
fix: Small fixes to use search function
Robin-Van-de-Merghel 8accb51
fix: Remove DB changes to split PRs and allow merging sooner
e413b2b
fix: Small typo in dirac admin add pilot
b96dbdd
feat: Add secrets in Arex CE
3cd62e8
feat: Allow to add envMapping into a wrapper
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
from DIRAC.WorkloadManagementSystem.Client.PilotScopes import PILOT_SCOPES | ||
from DIRAC.WorkloadManagementSystem.Client.ServerUtils import getPilotAgentsDB | ||
from DIRAC.WorkloadManagementSystem.private.ConfigHelper import findGenericPilotCredentials | ||
from DIRAC.WorkloadManagementSystem.Client.PilotManagerClient import PilotManagerClient | ||
from DIRAC.WorkloadManagementSystem.Utilities.PilotWrapper import ( | ||
_writePilotWrapperFile, | ||
getPilotFilesCompressedEncodedDict, | ||
|
@@ -103,6 +104,7 @@ def initialize(self): | |
self.rssClient = ResourceStatus() | ||
self.pilotAgentsDB = getPilotAgentsDB() | ||
self.matcherClient = MatcherClient() | ||
self.pilotManagementClient = PilotManagerClient() | ||
|
||
return S_OK() | ||
|
||
|
@@ -348,15 +350,15 @@ def _submitPilotsPerQueue(self, queueName: str): | |
if not result["OK"]: | ||
self.log.info("Failed pilot submission", f"Queue: {queueName}") | ||
return result | ||
pilotList, stampDict = result["Value"] | ||
stampDict, secretDict = result["Value"] | ||
|
||
# updating the pilotAgentsDB... done by default but maybe not strictly necessary | ||
result = self._addPilotReferences(queueName, pilotList, stampDict) | ||
submittedPilots = len(stampDict) | ||
self.log.info("Total number of pilots submitted", f"to {queueName}: {submittedPilots}") | ||
|
||
result = self._addPilotReferences(queueName, stampDict, secretDict) | ||
if not result["OK"]: | ||
return result | ||
|
||
submittedPilots = len(pilotList) | ||
self.log.info("Total number of pilots submitted", f"to {queueName}: {submittedPilots}") | ||
return S_OK(submittedPilots) | ||
|
||
def _getQueueSlots(self, queue: str): | ||
|
@@ -460,8 +462,32 @@ def _submitPilotsToQueue(self, pilotsToSubmit: int, ce: ComputingElement, queue: | |
jobProxy = result["Value"] | ||
executable = self._getExecutable(queue, proxy=jobProxy, jobExecDir=jobExecDir, envVariables=envVariables) | ||
|
||
# ----------- Generate additionnal env variables ----------- | ||
|
||
additionalEnv = [] | ||
|
||
# First, create secrets | ||
resultSecrets = self.pilotManagementClient.createNSecrets(vo=self.vo, n=pilotsToSubmit) | ||
if not resultSecrets["OK"]: | ||
self.log.error("Couldn't fetch secrets.") | ||
secrets = [] | ||
else: | ||
secrets = [{"DIRACX_SECRET": secret["pilot_secret"]} for secret in resultSecrets["Value"]] | ||
|
||
# --- | ||
# More env? | ||
# --- | ||
|
||
# Could be secrets, but also other things, increase in the for loop... | ||
for i, el in enumerate(secrets): | ||
additionalEnv[i].update(el) | ||
|
||
# ---------------------------------------------------------- | ||
|
||
# Submit the job | ||
submitResult = ce.submitJob(executable, "", pilotsToSubmit) | ||
# NOTE FOR DIRACX /!\ : We need in each CE to create a secret | ||
submitResult = ce.submitJob(executable, "", pilotsToSubmit, additionalEnv=additionalEnv) | ||
|
||
# In case the CE does not need the executable after the submission, we delete it | ||
# Else, we keep it, the CE will delete it after the end of the pilot execution | ||
if submitResult.get("ExecutableToKeep") != executable: | ||
|
@@ -531,34 +557,66 @@ def _submitPilotsToQueue(self, pilotsToSubmit: int, ce: ComputingElement, queue: | |
if not result["OK"]: | ||
self.log.error("Failure submitting Monitoring report", result["Message"]) | ||
|
||
return S_OK((pilotList, stampDict)) | ||
secrets_request_body = {} | ||
if "EnvMapping" in submitResult: | ||
# TODO: Update this comment as we add DiracX support | ||
# V9+, only for: | ||
# 1. Arex | ||
|
||
def _addPilotReferences(self, queue: str, pilotList: list[str], stampDict: dict[str, str]): | ||
# EnvMapping body: { "Stamp1": { "DIRACX_SECRET": "I_luv_strawberries", "...": "..." }, "Stamp2": {...} } | ||
# Request body for secrets: {"I_luv_stawberries": ["Stamp1", "..."]} | ||
envMapping = submitResult["SecretDict"] | ||
secrets_request_body = {} | ||
|
||
for stamp, envVariables in envMapping.items(): | ||
diracx_secret = envVariables.get("DIRACX_SECRET") | ||
if diracx_secret: | ||
if not diracx_secret in secrets_request_body: | ||
secrets_request_body[diracx_secret] = [] | ||
secrets_request_body[diracx_secret].append(stamp) | ||
|
||
# We reverse the ref-stamp dictionnary (DiracX behaviour) | ||
references = stampDict.keys() | ||
stamps = stampDict.values() | ||
stampDict = dict(zip(stamps, references)) | ||
|
||
return S_OK((stampDict, secrets_request_body)) | ||
|
||
def _addPilotReferences(self, queue: str, stampDict: dict[str, str], secretDict: dict[str, str]): | ||
"""Add pilotReference to pilotAgentsDB | ||
|
||
:param queue: the queue name | ||
:param pilotList: list of pilots | ||
:param stampDict: dictionary of pilots timestamps | ||
:param refDict: dictionary {"pilotstamp":"pilotref"} | ||
:param secretDict: dictionary {"pilotstamp":"secret"} | ||
""" | ||
result = self.pilotAgentsDB.addPilotReferences( | ||
pilotList, | ||
self.vo, | ||
self.queueDict[queue]["CEType"], | ||
stampDict, | ||
# FIXME: Change for a client or at least request to DiracX | ||
|
||
# First, create pilots | ||
stamps = stampDict.keys() | ||
result = self.pilotManagementClient.addPilotReferences( | ||
stamps, self.vo, self.queueDict[queue]["CEType"], stampDict | ||
) | ||
if not result["OK"]: | ||
self.log.error("Failed add pilots to the PilotAgentsDB", result["Message"]) | ||
return result | ||
|
||
for pilot in pilotList: | ||
result = self.pilotAgentsDB.setPilotStatus( | ||
pilot, | ||
PilotStatus.SUBMITTED, | ||
self.queueDict[queue]["CEName"], | ||
"Successfully submitted by the SiteDirector", | ||
self.queueDict[queue]["Site"], | ||
self.queueDict[queue]["QueueName"], | ||
# We associate all of the pilots with their secrets | ||
if secretDict: | ||
result = self.pilotManagementClient.associatePilotWithSecret(secretDict) | ||
if not result["OK"]: | ||
return result | ||
|
||
for stamp in stamps: | ||
result = self.pilotManagementClient.set_pilot_field( | ||
stamp, | ||
{ | ||
"DestinationSite": self.queueDict[queue]["CEName"], | ||
"StatusReason": "Successfully submitted by the SiteDirector", | ||
"GridSite": self.queueDict[queue]["Site"], | ||
"Queue": self.queueDict[queue]["QueueName"], | ||
}, | ||
) | ||
|
||
if not result["OK"]: | ||
self.log.error("Failed to set pilot status", result["Message"]) | ||
return result | ||
|
@@ -591,14 +649,13 @@ def _getExecutable(self, queue: str, proxy: X509Chain, jobExecDir: str = "", env | |
ce = self.queueCECache[queue]["CE"] | ||
workingDirectory = getattr(ce, "workingDirectory", self.workingDirectory) | ||
|
||
executable = self._writePilotScript( | ||
return self._writePilotScript( | ||
workingDirectory=workingDirectory, | ||
pilotOptions=pilotOptions, | ||
proxy=proxy, | ||
pilotExecDir=jobExecDir, | ||
envVariables=envVariables, | ||
) | ||
return executable | ||
|
||
def _getPilotOptions(self, queue: str) -> list[str]: | ||
"""Prepare pilot options | ||
|
@@ -680,6 +737,13 @@ def _getPilotOptions(self, queue: str) -> list[str]: | |
if "PipInstallOptions" in queueDict: | ||
pilotOptions.append(f"--pipInstallOptions={queueDict['PipInstallOptions']}") | ||
|
||
# FIXME: Get secret | ||
# if "secret" in queueDict: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be removed |
||
# pilotOptions.append(f"--pilotSecret={queueDict['...']}") | ||
# FIXME: Get clientID | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone has an idea. |
||
# pilotOptions.append(f"--clientID={opsHelper.getValue('TO CHANGE')}) | ||
pilotOptions.append(f"--diracx_URL={DIRAC.gConfig.getValue('/DiracX/URL')}") | ||
|
||
return pilotOptions | ||
|
||
def _writePilotScript( | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See if we need also
\"