Skip to content

Commit dccccae

Browse files
committed
Update postprocessing and add fake test server for ONCat
1 parent 63aa59b commit dccccae

File tree

6 files changed

+101
-9
lines changed

6 files changed

+101
-9
lines changed

Dockerfile.autoreducer

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ RUN ls ${DATA_TARBALL}
2525
RUN mkdir /SNS
2626
RUN cd /SNS && tar xzf ${DATA_TARBALL}
2727

28+
# install pyoncat
29+
COPY tests/python3-pyoncat-2.1-1.noarch.rpm /tmp/
30+
RUN dnf install -y /tmp/python3-pyoncat-2.1-1.noarch.rpm
31+
2832
# install postprocessing
29-
RUN dnf install -y https://github.com/neutrons/post_processing_agent/releases/download/v4.0.0/postprocessing-4.0.0-1.el9.noarch.rpm
33+
RUN dnf install -y https://github.com/neutrons/post_processing_agent/releases/download/v4.1.0/postprocessing-4.1.0-1.el9.noarch.rpm
3034

3135
# Install dependencies
3236
ARG PLOTLY_VERSION=5
@@ -40,17 +44,13 @@ RUN pip3 install git+https://github.com/neutrons/plot_publisher.git@main
4044

4145
# Install specific plotly version based on build arg
4246
RUN if [ "$PLOTLY_VERSION" = "5" ]; then \
43-
pip3 install plotly==5.17.0; \
47+
pip3 install plotly==5.17.0; \
4448
elif [ "$PLOTLY_VERSION" = "6" ]; then \
45-
pip3 install plotly==6.0.0; \
49+
pip3 install plotly==6.0.0; \
4650
else \
47-
pip3 install plotly==5.17.0; \
51+
pip3 install plotly==5.17.0; \
4852
fi
4953

50-
# add fake ONCat ingest scripts
51-
RUN touch /opt/postprocessing/scripts/oncat_ingest.py && \
52-
touch /opt/postprocessing/scripts/oncat_reduced_ingest.py
53-
5454
# create startup script
5555
# add updating certificates to add self-signed certificate for local testing
5656
RUN echo "#!/bin/bash" > /usr/bin/run_postprocessing && \

Dockerfile.oncat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM python:3-alpine
2+
COPY tests/oncat_server.py .
3+
RUN mkdir -p /SNS/ARCS/IPTS-27800/nexus && \
4+
touch /SNS/ARCS/IPTS-27800/nexus/ARCS_214583.nxs.h5
5+
CMD ["python", "oncat_server.py"]

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ services:
224224
activemq:
225225
condition: service_healthy
226226

227+
oncat:
228+
build:
229+
context: .
230+
dockerfile: Dockerfile.oncat
231+
227232
autoheal:
228233
restart: always
229234
image: willfarrell/autoheal

tests/configuration/post_process_consumer.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@
3030
"publisher_password": "workflow",
3131
"system_mem_limit_perc": 5,
3232
"mem_check_interval_sec": 0.01,
33-
"task_time_limit_minutes": 0.1
33+
"task_time_limit_minutes": 0.1,
34+
"oncat_url": "http://oncat:8000",
35+
"oncat_api_token": "test-token"
3436
}

tests/oncat_server.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import json
2+
import logging
3+
import os
4+
from http.server import BaseHTTPRequestHandler, HTTPServer
5+
6+
logging.basicConfig(filename="oncat_server.log", level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
7+
8+
9+
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
10+
"""Fake ONCat server for testing purposes"""
11+
12+
def do_POST(self):
13+
if self.headers.get("Authorization") != "Bearer test-token":
14+
self.send_response(403)
15+
self.send_header("Content-type", "application/json")
16+
self.end_headers()
17+
response = {"error": "Forbidden"}
18+
self.wfile.write(json.dumps(response).encode("utf-8"))
19+
return
20+
21+
if self.path.startswith("/api/datafiles/"):
22+
location = self.path.replace("/api/datafiles", "").replace("/ingest", "")
23+
logging.info("Received datafile ingest request for %s", location)
24+
elif self.path.startswith("/api/reductions/"):
25+
location = self.path.replace("/api/reductions", "").replace("/ingest", "")
26+
logging.info("Received reduction ingest request for %s", location)
27+
else:
28+
self.send_response(400)
29+
self.send_header("Content-type", "application/json")
30+
self.end_headers()
31+
logging.error("Unknown endpoint: %s", self.path)
32+
response = {"error": "Unknown endpoint"}
33+
self.wfile.write(json.dumps(response).encode("utf-8"))
34+
return
35+
36+
if not os.path.isfile(location):
37+
self.send_response(404)
38+
self.send_header("Content-type", "application/json")
39+
self.end_headers()
40+
logging.error("File not found: %s", location)
41+
response = {"error": "File not found"}
42+
self.wfile.write(json.dumps(response).encode("utf-8"))
43+
return
44+
45+
try:
46+
# assume the format /facility/instrument/experiment/nexus/instrument_run_number.nxs.h5
47+
# the real server would be more complex
48+
_, facility, instrument, experiment, *_, filename = location.split("/")
49+
run_number = int(filename.split("_")[-1].split(".")[0])
50+
except Exception:
51+
self.send_response(400)
52+
self.send_header("Content-type", "application/json")
53+
self.end_headers()
54+
logging.error("Invalid path format: %s", location)
55+
response = {"error": "Invalid path format"}
56+
self.wfile.write(json.dumps(response).encode("utf-8"))
57+
return
58+
59+
# Send response
60+
self.send_response(200)
61+
self.send_header("Content-type", "application/json")
62+
self.end_headers()
63+
response = {
64+
"location": location,
65+
"facility": facility,
66+
"instrument": instrument,
67+
"experiment": experiment,
68+
"indexed": {"run_number": run_number},
69+
}
70+
self.wfile.write(json.dumps(response).encode("utf-8"))
71+
72+
73+
def run(server_class=HTTPServer, handler_class=SimpleHTTPRequestHandler, port=8000):
74+
server_address = ("", port)
75+
httpd = server_class(server_address, handler_class)
76+
httpd.serve_forever()
77+
78+
79+
if __name__ == "__main__":
80+
run()
27 KB
Binary file not shown.

0 commit comments

Comments
 (0)