|
| 1 | +from DIRAC.Core.Security.DiracX import DiracXClient, FutureClient |
| 2 | +from DIRAC.Core.Utilities.ReturnValues import convertToReturnValue |
| 3 | + |
| 4 | + |
| 5 | +class PilotManagerClient(FutureClient): |
| 6 | + @convertToReturnValue |
| 7 | + def addPilotReferences( |
| 8 | + self, |
| 9 | + pilot_reference: str, |
| 10 | + VO: str, |
| 11 | + grid_type: str = "DIRAC", |
| 12 | + pilot_stamp_dict: dict = {}, |
| 13 | + grid_site: str = "Unknown", |
| 14 | + destination_site: str = "NotAssigned", |
| 15 | + ): |
| 16 | + """Add a new pilot to the database. |
| 17 | + Uses pilots/management/register_pilot |
| 18 | + """ |
| 19 | + |
| 20 | + with DiracXClient() as api: |
| 21 | + api.pilots.register_pilot( |
| 22 | + pilot_stamp=pilot_stamp_dict[pilot_reference], |
| 23 | + vo=VO, |
| 24 | + grid_type=grid_type, |
| 25 | + grid_site=grid_site, |
| 26 | + destination_site=destination_site, |
| 27 | + ) |
| 28 | + |
| 29 | + @convertToReturnValue |
| 30 | + def getPilotInfo(self, pilot_reference: str): |
| 31 | + """Get the info about a given pilot job reference""" |
| 32 | + |
| 33 | + # with DiracXClient() as api: |
| 34 | + |
| 35 | + @convertToReturnValue |
| 36 | + def selectPilots(self, conditions_dict: dict): |
| 37 | + """Select pilots given the selection conditions""" |
| 38 | + |
| 39 | + # with DiracXClient() as api: |
| 40 | + |
| 41 | + @convertToReturnValue |
| 42 | + def getPilotSummary(self, start_date: str, end_date: str): |
| 43 | + """Get summary of the status of the Pilot Jobs""" |
| 44 | + |
| 45 | + # with DiracXClient() as api: |
| 46 | + |
| 47 | + @convertToReturnValue |
| 48 | + def getPilots(self, job_id: str | int): |
| 49 | + """Get pilots executing/having executed a Job""" |
| 50 | + |
| 51 | + # with DiracXClient() as api: |
| 52 | + |
| 53 | + @convertToReturnValue |
| 54 | + def setPilotStatus( |
| 55 | + self, |
| 56 | + pilot_reference: str, |
| 57 | + status: str, |
| 58 | + destination: str | None = None, |
| 59 | + reason: str | None = None, |
| 60 | + grid_site: str | None = None, |
| 61 | + queue: str | None = None, |
| 62 | + pilot_stamp: str | None = None, |
| 63 | + ): |
| 64 | + """Set the pilot status""" |
| 65 | + |
| 66 | + with DiracXClient() as api: |
| 67 | + values_dict = ( |
| 68 | + { |
| 69 | + "PilotStamp": pilot_stamp, |
| 70 | + "Status": status, |
| 71 | + "DestinationSite": destination, |
| 72 | + "StatusReason": reason, |
| 73 | + "GridSite": grid_site, |
| 74 | + "Queue": queue, |
| 75 | + }, |
| 76 | + ) |
| 77 | + |
| 78 | + return api.pilots.update_pilot_metadata(pilot_stamps_to_fields_mapping=[values_dict]) |
0 commit comments