-
Notifications
You must be signed in to change notification settings - Fork 0
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
DM-39022: Add group name presence server. #54
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3ec208f
Fix ingest exception handling.
ktlim 5e6caa8
Add group presence recording.
ktlim 83b818d
Add presence server.
ktlim 98e406a
Add build for presence service.
ktlim d358c8f
Update default versions for manual ingest build.
ktlim 5a66a64
Protect against JSON arriving without FITS.
ktlim 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 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 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 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This file is part of embargo_butler. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (http://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Dockerfile for presence service. | ||
|
||
FROM python:3.11 | ||
RUN pip install redis gunicorn flask | ||
WORKDIR /presence | ||
COPY src/presence.py src/utils.py /presence/ | ||
# environment variables that must be set: | ||
# REDIS_HOST REDIS_PASSWORD | ||
# optional: | ||
# DELETE_SEEN | ||
ENTRYPOINT [ "gunicorn", "-b", "0.0.0.0:8000", "-w", "2", "presence:app" ] |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# This file is part of embargo_butler. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (http://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
""" | ||
Presence service to translate group names to image URIs. | ||
""" | ||
import os | ||
import re | ||
|
||
from flask import Flask | ||
|
||
from utils import setup_logging, setup_redis | ||
|
||
logger = setup_logging(__name__) | ||
r = setup_redis() | ||
|
||
# Delete image key when seen, before it expires, to save space | ||
delete_seen = os.environ.get("DELETE_SEEN") is not None | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.get("/presence/<instrument>/<group_name>/<int:snap_index>/<detector_name>") | ||
def presence(instrument: str, group_name: str, snap_index: int, detector_name: str) -> dict | tuple: | ||
"""Return the presence and URI of an image matching the parameters. | ||
|
||
Parameters | ||
---------- | ||
instrument: `str` | ||
Name of the instrument taking the image. | ||
group_name: `str` | ||
Name of the group (from the GROUPID FITS header). | ||
snap_index: `int` | ||
Number of the snap (zero-based). | ||
detector_name: `str` | ||
Name of the detector ("RNN_SNN"). | ||
|
||
Returns | ||
------- | ||
json: `dict` | ||
JSON with "error", "present", "uri", and/or "message" keys. | ||
""" | ||
|
||
try: | ||
if instrument not in ("LATISS", "LSSTComCam", "LSSTComCamSim", "LSSTCam", "LSST-TS8"): | ||
return ({"error": True, "message": f"Unknown instrument {instrument}"}, 400) | ||
if not re.match(r"R\d\d_S\d\d", detector_name): | ||
return ({"error": True, "message": f"Unrecognized detector name {detector_name}"}, 400) | ||
key = f"GROUP:{instrument}:{group_name}:{snap_index}:{detector_name}" | ||
result = r.get(key) | ||
if result: | ||
logger.info(f"Found key {key}") | ||
if delete_seen: | ||
r.delete(key) | ||
return {"error": False, "present": True, "uri": result.decode()} | ||
else: | ||
logger.debug(f"No key {key}") | ||
return {"error": False, "present": False} | ||
except Exception as e: | ||
return ({"error": True, "message": str(e)}, 500) |
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.
Why is this needed with this commit?
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.
This is actually a separate fix that prevents visit definition (and Rucio registration) from trying to run if an exception occurred in ingest. I'll split it out into a separate commit.