Skip to content

Commit

Permalink
Merge pull request #28 from omnivector-solutions/1352853264_epilog_ex…
Browse files Browse the repository at this point in the history
…it_zero

don't enter the loop if no bookings and exit 0
  • Loading branch information
jamesbeedy authored Jun 4, 2021
2 parents 0b9a8d4 + 3d16ec6 commit 6a064d9
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions src/licensemanager2/workload_managers/slurm/slurmctld_epilog.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env python3
"""The SlurmctldEpilog executable.
"""
The EpilogSlurmctld executable.
This epilog is responsible for releasing the feature tokens
that have been booked for a job back to the pool after a job has completed.
"""
import sys

import asyncio
import httpx

Expand Down Expand Up @@ -44,40 +48,42 @@ async def main():

license_booking_request = await get_required_licenses_for_job(job_id)

# Create a list of tracked licenses in the form <product>.<feature>
tracked_licenses = list()
for license in get_license_server_features():
for feature in license["features"]:
tracked_licenses.append(f"{license['product']}.{feature}")

# If a license booking's product feature is tracked,
# update slurm's view of the token totals
for license_booking in license_booking_request.bookings:
product_feature = license_booking.product_feature
product, feature = product_feature.split(".")
license_server_type = license_booking.license_server_type
tokens_to_remove = license_booking.tokens
license = f"{product_feature}@{license_server_type}"

if product_feature in tracked_licenses:
total = await get_tokens_for_license(license, "Total")
update_resource = await sacctmgr_modify_resource(
product, feature, total - tokens_to_remove
)

if update_resource:
log.info("Slurmdbd updated successfully.")
else:
log.info("Slurmdbd update unsuccessful.")

# Attempt to remove the booking and log the result.
booking_removed = await _remove_booking_for_job(job_id)
if booking_removed:
log.debug(f"Booking for job id: {job_id} successfully deleted.")
else:
log.debug(f"Booking for job id: {job_id} not removed.")
if len(license_booking_request.bookings) > 0:
# Create a list of tracked licenses in the form <product>.<feature>
tracked_licenses = list()
for license in get_license_server_features():
for feature in license["features"]:
tracked_licenses.append(f"{license['product']}.{feature}")

# If a license booking's product feature is tracked,
# update slurm's view of the token totals
for license_booking in license_booking_request.bookings:
product_feature = license_booking.product_feature
product, feature = product_feature.split(".")
license_server_type = license_booking.license_server_type
tokens_to_remove = license_booking.tokens
license = f"{product_feature}@{license_server_type}"

if product_feature in tracked_licenses:
total = await get_tokens_for_license(license, "Total")
update_resource = await sacctmgr_modify_resource(
product, feature, total - tokens_to_remove
)

if update_resource:
log.info("Slurmdbd updated successfully.")
else:
log.info("Slurmdbd update unsuccessful.")

# Attempt to remove the booking and log the result.
booking_removed = await _remove_booking_for_job(job_id)
if booking_removed:
log.debug(f"Booking for job id: {job_id} successfully deleted.")
else:
log.debug(f"Booking for job id: {job_id} not removed.")
sys.exit(0)

# Initialize the logger
init_logging("slurmctld-epilog")
# Run main()
asyncio.run(main())
asyncio.run(main())

0 comments on commit 6a064d9

Please sign in to comment.