diff --git a/deploy/README.md b/deploy/README.md index c368945..25ebe42 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -1,4 +1,4 @@ -# Connection-service +# connectivityserver This service provides a very simple flask based server to serve connection information to DAQ applications. @@ -11,7 +11,7 @@ docker buildx build --tag ghcr.io/dune-daq/connectivityserver:latest . ``` Or, if you want to specify a tag ```bash -docker buildx build --tag ghcr.io/dune-daq/connectivityserver:v1.2.0 --build-arg VERSION=v1.2.0 . +docker buildx build --tag ghcr.io/dune-daq/connectivityserver:v1.3.0 --build-arg VERSION=v1.3.0 . ``` Apply the kubernetes manifest from connectivityserver.yaml. This diff --git a/deploy/entrypoint.sh b/deploy/entrypoint.sh index 430a0f3..c808bbe 100755 --- a/deploy/entrypoint.sh +++ b/deploy/entrypoint.sh @@ -1,3 +1,3 @@ #!/bin/bash -exec gunicorn -b 0.0.0.0:5000 --workers=1 --worker-class=gthread --threads=2 --timeout 5000000000 --log-level=debug connection-service.connection-flask:app +exec gunicorn -b 0.0.0.0:5000 --workers=1 --worker-class=gthread --threads=2 --timeout 5000000000 --log-level=debug connectivityserver.connectionflask:app diff --git a/docs/README.md b/docs/README.md index 7e281e2..8028c69 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# Connection-service +# connectivityserver This service provides a very simple flask based server to serve connection information to DAQ applications. @@ -55,14 +55,14 @@ This uri should be used to remove published connections. The request should be J ### /retract-partition This uri should be used to remove all published connections from the -given partition. The request should be a urlencoded form with one field "partition" naming the partition to be retracted. +given partition. The request should be JSON encoded with one field "partition" naming the partition to be retracted. ## Running the server locally from the command line The server is intended to be run under the Gunicorn web server. ``` gunicorn -b 0.0.0.0:5000 --workers=1 --worker-class=gthread --threads=2 \ - --timeout 5000000000 connection-service.connection-flask:app + --timeout 5000000000 connectivityserver.connectionflask:app ``` Some debug information will be printed by the connection-flask if the diff --git a/gunicorn.conf.py b/gunicorn.conf.py index 0e8c7f9..724c6e1 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -3,4 +3,4 @@ worker_class="gthread" threads=2 timeout=5000000000 -wsgi_app="connection-service.connection-flask:app" +wsgi_app="connectivityserver.connectionflask:app" diff --git a/pyproject.toml b/pyproject.toml index 50797d2..fb53a2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,9 +3,9 @@ build-backend = "setuptools.build_meta" requires = ["setuptools>=61.0"] [project] -name = "connection-service" +name = "connectivityserver" description = "A very simple Flask based server to serve connection information to DAQ applications" -version = "1.2.0" +version = "1.3.0" readme = "docs/README.md" requires-python = ">=3.6" urls = { "homepage" = "https://github.com/DUNE-DAQ/connectivityserver" } diff --git a/src/connection-service/__init__.py b/src/connectivityserver/__init__.py similarity index 100% rename from src/connection-service/__init__.py rename to src/connectivityserver/__init__.py diff --git a/src/connection-service/connection-flask.py b/src/connectivityserver/connectionflask.py similarity index 90% rename from src/connection-service/connection-flask.py rename to src/connectivityserver/connectionflask.py index 561980f..f723816 100755 --- a/src/connection-service/connection-flask.py +++ b/src/connectivityserver/connectionflask.py @@ -5,15 +5,19 @@ # received with this code. # -import os import json +import logging +import os import re -from threading import Lock -from io import StringIO -from datetime import datetime, timedelta from collections import namedtuple -import logging -from flask import Flask, request, abort, make_response +from datetime import datetime, timedelta +from io import StringIO +from threading import Lock + +from flask import Flask, abort, make_response, request + +# Some functions exit with an abort(NNN) instead of return so don't complain! +#ruff: noqa RET503 partitions={} partlock=Lock() @@ -26,9 +30,9 @@ def convert_log_level(log_level): if log_level == 0: return logging.WARNING - elif log_level == 1: + if log_level == 1: return logging.INFO - elif log_level == 2: + if log_level == 2: return logging.DEBUG return logging.INFO @@ -55,8 +59,8 @@ def convert_log_level(log_level): def dump(): now=datetime.now() dstream=StringIO() - dstream.write(f'
") + dstream.write('
") if len(partitions)>0: pad=' style="padding-left: 1em;padding-right: 1em"' dstream.write(f'
| {p}' f' | {len(partitions[p])} |
')
@@ -76,8 +80,8 @@ def dump():
dstream.write(f'{k}: {v}')
dstream.write("
0 calls to publish" not in resp.data + + resp = client.get("/resetStats") + assert resp.status_code == 200 + assert b"
0 calls to publish" not in resp.data + + resp = client.get("/stats") + assert resp.status_code == 200 + assert b"
0 calls to publish" in resp.data + + +def test_reset(client): + resp = client.post("/publish", json=con) + assert resp.status_code == 200 + + resp = client.get("/stats") + assert resp.status_code == 200 + assert b"
0 calls to publish" not in resp.data + + resp = client.get("/resetService") + assert resp.status_code == 200 + + resp = client.get("/stats") + assert resp.status_code == 200 + assert b"
0 calls to publish" in resp.data