-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,309 additions
and
364 deletions.
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
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,109 @@ | ||
#!/usr/bin/env python | ||
# This file is part of ctrl_oods | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://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 <https://www.gnu.org/licenses/>. | ||
|
||
import asyncio | ||
import logging | ||
import os | ||
|
||
import lsst.log as lsstlog | ||
import yaml | ||
from lsst.ctrl.oods.msgIngester import MsgIngester | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
F = "%(levelname) -10s %(asctime)s.%(msecs)03dZ %(name) -30s %(funcName) -35s %(lineno) -5d: %(message)s" | ||
logging.basicConfig(level=logging.INFO, format=F, datefmt="%Y-%m-%d %H:%M:%S") | ||
|
||
|
||
class Standalone(object): | ||
"""Standalone class to run tests without CSC requirements.""" | ||
|
||
def __init__(self): | ||
self.config = None | ||
# import YAML file here | ||
if "CTRL_OODS_CONFIG_FILE" in os.environ: | ||
filename = os.environ["CTRL_OODS_CONFIG_FILE"] | ||
LOGGER.info("using configuration %s", filename) | ||
with open(filename, "r") as f: | ||
self.config = yaml.safe_load(f) | ||
else: | ||
raise FileNotFoundError("CTRL_OODS_CONFIG_FILE is not set") | ||
|
||
self.task_list = None | ||
|
||
self.ingester_config = self.config["ingester"] | ||
|
||
async def send_imageInOODS(self, info): | ||
"""Send SAL message that the images has been ingested into the OODS | ||
Parameters | ||
---------- | ||
info : `dict` | ||
information about the image | ||
""" | ||
camera = info["CAMERA"] | ||
obsid = info["OBSID"] | ||
raft = "undef" | ||
if "RAFT" in info: | ||
raft = info["RAFT"] | ||
sensor = "undef" | ||
if "SENSOR" in info: | ||
sensor = info["SENSOR"] | ||
status_code = info["STATUS_CODE"] | ||
description = info["DESCRIPTION"] | ||
|
||
s = f"would send camera={camera} obsid={obsid} raft={raft} sensor={sensor} " | ||
s = s + f"statusCode={status_code}, description={description}" | ||
LOGGER.info(s) | ||
|
||
async def start_services(self): | ||
"""Start all cleanup and archiving services""" | ||
|
||
# self added here, and by the time it's utilized by MsgIngester | ||
# the CSC will be up and running | ||
self.ingester = MsgIngester(self.config, self) | ||
|
||
self.task_list = self.ingester.run_tasks() | ||
|
||
async def stop_services(self): | ||
"""Stop all cleanup and archiving services""" | ||
print("calling stop_tasks") | ||
self.ingester.stop_tasks() | ||
|
||
async def done(self): | ||
print("waiting...") | ||
while True: | ||
await asyncio.sleep(3600) | ||
print("done!") | ||
|
||
async def main(self): | ||
await self.start_services() | ||
group = asyncio.gather(self.done()) | ||
print("gathering") | ||
await group | ||
print("finished") | ||
await self.stop_services() | ||
print("complete") | ||
|
||
|
||
if __name__ == "__main__": | ||
alone = Standalone() | ||
asyncio.run(alone.main()) |
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,30 @@ | ||
defaultInterval: &interval | ||
days: 0 | ||
hours: 0 | ||
minutes: 0 | ||
seconds: 0 | ||
|
||
ingester: | ||
kafka: | ||
brokers: | ||
- kafka:9092 | ||
topics: | ||
- atoods | ||
group_id: ATOODS | ||
max_messages: 10 | ||
butlers: | ||
- butler: | ||
instrument: lsst.obs.lsst.Latiss | ||
class: | ||
import : lsst.ctrl.oods.messageAttendant | ||
name : MessageAttendant | ||
repoDirectory : /tmp/repo/LATISS | ||
collections: | ||
- LATISS/raw/all | ||
scanInterval: | ||
<<: *interval | ||
seconds: 10 | ||
filesOlderThan: | ||
<<: *interval | ||
seconds: 30 | ||
batchSize: 20 |
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,60 @@ | ||
# This file is part of ctrl_oods | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://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 <https://www.gnu.org/licenses/>. | ||
|
||
import json | ||
import logging | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class BucketMessage(object): | ||
"""Report on new messages | ||
Parameters | ||
---------- | ||
message: `str` | ||
json string | ||
""" | ||
|
||
def __init__(self, message): | ||
self.message = message | ||
|
||
def extract_urls(self): | ||
"""Extract object IDs from an S3 notification. | ||
If one record is invalid, an error is logged but the function tries to | ||
process the remaining records. | ||
Yields | ||
------ | ||
oid : `str` | ||
The filename referred to by each message. | ||
""" | ||
msg = json.loads(self.message) | ||
for record in msg["Records"]: | ||
try: | ||
bucket_name = record["s3"]["bucket"]["name"] | ||
key = record["s3"]["object"]["key"] | ||
url = f"s3://{bucket_name}/{key}" | ||
yield url | ||
except KeyError as e: | ||
LOGGER.error(f"Invalid msg: Couldn't find key in {record=}") | ||
raise e |
Oops, something went wrong.