-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from lsst-dm/tickets/DM-37511
DM-37511: Summarize Header Service into ConsDB.
- Loading branch information
Showing
13 changed files
with
725 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI build of all containers | ||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- "*" | ||
pull_request: | ||
|
||
jobs: | ||
push: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build hinfo | ||
uses: lsst-sqre/build-and-push-to-ghcr@v1 | ||
with: | ||
image: ${{ github.repository }}-hinfo | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
dockerfile: Dockerfile.hinfo |
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,22 @@ | ||
ARG RUBINENV_VERSION=8.0.0 | ||
FROM lsstsqre/newinstall:${RUBINENV_VERSION} | ||
ARG OBS_LSST_VERSION | ||
ENV OBS_LSST_VERSION=${OBS_LSST_VERSION:-w_2024_06} | ||
USER lsst | ||
RUN source loadLSST.bash && mamba install aiokafka httpx | ||
RUN source loadLSST.bash && pip install kafkit | ||
RUN source loadLSST.bash && eups distrib install -t "${OBS_LSST_VERSION}" obs_lsst | ||
COPY python/lsst/consdb/hinfo.py ./hinfo/ | ||
|
||
# Environment variables that must be set: | ||
# INSTRUMENT: LATISS, LSSTComCam, LSSTComCamSim, LSSTCam | ||
# POSTGRES_URL: SQLAlchemy connection URL | ||
# KAFKA_BOOTSTRAP: host:port of bootstrap server | ||
# KAFKA_PASSWORD: password for SASL_PLAIN authentication | ||
# SCHEMA_URL: Kafkit registry schema URL | ||
# Optional environment variables: | ||
# BUCKET_PREFIX: set to "rubin:" at USDF, default is "" | ||
# KAFKA_GROUP_ID: name of consumer group, default is "consdb-consumer" | ||
# KAFKA_USERNAME: username for SASL_PLAIN authentication, default is "consdb" | ||
|
||
ENTRYPOINT [ "bash", "-c", "source loadLSST.bash; setup obs_lsst; python ./hinfo/hinfo.py" ] |
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,8 @@ | ||
FROM python:3.11 | ||
RUN pip install flask gunicorn sqlalchemy | ||
WORKDIR /consdb-server | ||
COPY src/server.py /consdb-server/ | ||
# Environment variables that must be set: | ||
# POSTGRES_URL | ||
ENTRYPOINT [ "gunicorn", "-b", "0.0.0.0:8000", "-w", "2", "server: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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,58 @@ | ||
import os | ||
from pandas import DataFrame | ||
import requests | ||
from requests.exceptions import RequestException | ||
from typing import Any, Iterable | ||
from urllib.parse import urljoin | ||
|
||
session = requests.Session() | ||
base_url = os.environ["CONSDB_URL"] | ||
|
||
|
||
def insert(table: str, values: dict[str, Any], **kwargs): | ||
values.update(kwargs) | ||
# check values against schema for table | ||
data = {"table": table, "values": values} | ||
url = urljoin(base_url, "insert") | ||
try: | ||
response = requests.post(url, json=data) | ||
except RequestException as e: | ||
raise e | ||
response.raise_for_status() | ||
|
||
|
||
def query( | ||
tables: str | Iterable[str], | ||
columns: str | Iterable[str], | ||
*, | ||
where: str | None = None, | ||
join: str | None = None | ||
) -> list[Any]: | ||
if isinstance(tables, str): | ||
tables = [tables] | ||
if isinstance(columns, str): | ||
columns = [columns] | ||
url = urljoin(base_url, "query") | ||
data = {"tables": tables, "columns": columns, "where": where, "join": join} | ||
try: | ||
response = requests.post(url, json=data) | ||
except RequestException as e: | ||
raise e | ||
try: | ||
response.raise_for_status() | ||
except Exception as ex: | ||
print(response.content.decode()) | ||
raise ex | ||
arr = response.json() | ||
return DataFrame(arr[1:], columns=arr[0]) | ||
|
||
|
||
def schema(table: str): | ||
url = urljoin(base_url, "schema/") | ||
url = urljoin(url, table) | ||
try: | ||
response = requests.get(url) | ||
except RequestException as e: | ||
raise e | ||
response.raise_for_status() | ||
return response.json() |
Oops, something went wrong.