Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
7aeaad2
preliminarily migrated class BaseImageTagsHandler(APIHandler)
AndyBRoswell May 21, 2024
a533cfa
adding keycloak token auth
AndyBRoswell May 26, 2024
16eb318
keycloak token auth with unit test
AndyBRoswell May 26, 2024
65311fc
keycloak token auth with unit test
AndyBRoswell May 26, 2024
4047217
keycloak token auth with unit test
AndyBRoswell May 26, 2024
2cc5af4
keycloak token auth with unit test
AndyBRoswell May 26, 2024
c9b4ce8
keycloak token auth with unit test
AndyBRoswell May 27, 2024
cc0ad39
api/containerizer/baseimagetags test
AndyBRoswell May 28, 2024
1909e86
[bugfix] backoff factor of auto retry;
AndyBRoswell May 29, 2024
af97e95
enable TokenAuthentication & IsAuthenticated
AndyBRoswell May 29, 2024
3212e36
StaticTokenAuthentication
AndyBRoswell May 30, 2024
4ef15fb
[StaticTokenAuthentication] remove hardcoded password
AndyBRoswell May 31, 2024
fb94493
porting ExtractorHandler
AndyBRoswell Jun 4, 2024
2392d86
porting ExtractorHandler
AndyBRoswell Jun 4, 2024
297747b
test_extractor.py migration preliminarily completed
AndyBRoswell Jun 5, 2024
72b5b53
test_extractor.py migration preliminarily completed
AndyBRoswell Jun 6, 2024
cfd21d8
test_extractor.py migration preliminarily completed
AndyBRoswell Jun 6, 2024
db0ee1e
migrating TypesHandler, BaseImageHandler, CellsHandler
AndyBRoswell Jun 6, 2024
13b8e84
migrating TypesHandler, BaseImageHandler, CellsHandler
AndyBRoswell Jun 7, 2024
90ca89c
migrating TypesHandler, BaseImageHandler, CellsHandler
AndyBRoswell Jun 7, 2024
fd5cbdd
migrating TypesHandler, BaseImageHandler, CellsHandler
AndyBRoswell Jun 10, 2024
deaaf0a
[bugfix] migrating TypesHandler, BaseImageHandler, CellsHandler
AndyBRoswell Jun 10, 2024
2785dc2
[bugfix] migrating TypesHandler, BaseImageHandler, CellsHandler
AndyBRoswell Jun 10, 2024
77e92f8
[bugfix] migrating TypesHandler, BaseImageHandler, CellsHandler
AndyBRoswell Jun 11, 2024
32c7d56
migrating TypesHandler, BaseImageHandler, CellsHandler
AndyBRoswell Jun 11, 2024
fe4c9d2
migrating TypesHandler, BaseImageHandler, CellsHandler
AndyBRoswell Jun 11, 2024
53b9fdb
[bugfix] containerizer/tests.py
AndyBRoswell Jun 12, 2024
61a757d
[bugfix]
AndyBRoswell Jun 12, 2024
9f09daa
[bugfix] refined tests
AndyBRoswell Jun 12, 2024
ab385ac
[bugfix] BaseImageHandler, Logger
AndyBRoswell Jun 12, 2024
36fac0f
[bugfix] BaseImageHandler, Logger
AndyBRoswell Jun 13, 2024
2716ebc
[bugfix] CellsHandler
AndyBRoswell Jun 14, 2024
7f8b842
del obsolete cells app
AndyBRoswell Jun 14, 2024
8251c3e
[tbc] psql adaptation
AndyBRoswell Jun 16, 2024
ed9dcbb
corrected CellsHandler unit test case
AndyBRoswell Jun 17, 2024
7effc3e
[bugfix] class Cell(models.Model)
AndyBRoswell Jun 17, 2024
c8621ff
[bugfix] CellsHandler, CellsHandlerTestCase
AndyBRoswell Jun 17, 2024
2dfa183
[bugfix] CellsHandler
AndyBRoswell Jun 17, 2024
9f325a1
[bugfix] CellsHandler
AndyBRoswell Jun 17, 2024
1a29ad6
[bugfix] CellsHandlerTestCase
AndyBRoswell Jun 18, 2024
8a7996b
removed obsolete catalog.py
AndyBRoswell Jun 18, 2024
66d38cc
removed obsolete files: catalog.py, cells.py
AndyBRoswell Jun 18, 2024
41734a9
[bugfix] Cell.toJSON
AndyBRoswell Jun 19, 2024
27bc04d
[bugfix] CellsHandler
AndyBRoswell Jun 21, 2024
3d9fb64
[bugfix] CellsHandler
AndyBRoswell Jun 21, 2024
c48f0ed
[bugfix]
AndyBRoswell Jun 21, 2024
96ee056
refined emulated frontend test
AndyBRoswell Jun 22, 2024
17e9abe
refined emulated frontend test
AndyBRoswell Jun 22, 2024
eac72b8
refined emulated frontend test
AndyBRoswell Jun 22, 2024
b7550c0
adding rmd support
AndyBRoswell Jul 23, 2024
b1f9588
adding rmd support: type hints
AndyBRoswell Jul 23, 2024
e5e13b9
adding rmd support
AndyBRoswell Jul 23, 2024
89d9e9f
adding rmd support
AndyBRoswell Jul 24, 2024
9be46cd
adding rmd support: correcting cell_index
AndyBRoswell Jul 25, 2024
ae3f3c2
adding rmd support:
AndyBRoswell Jul 25, 2024
56f4fe9
adding rmd support:
AndyBRoswell Jul 25, 2024
7d872dc
adding rmd support:
AndyBRoswell Jul 25, 2024
6498131
adding rmd support:
AndyBRoswell Jul 25, 2024
604a5ae
adding rmd support:
AndyBRoswell Jul 26, 2024
f1da57c
adding rmd support:
AndyBRoswell Aug 6, 2024
f6cf9b5
comments on rmd support
AndyBRoswell Aug 6, 2024
175eb05
slight modifications
AndyBRoswell Aug 8, 2024
3b0f718
[bugfix] if do_dispatch_github_workflow
AndyBRoswell Aug 12, 2024
71240cf
[bugfix] RContainerizer.py
AndyBRoswell Aug 26, 2024
a5ba124
fixing `Error: rpy2 in API mode cannot be built without R in the PATH…
AndyBRoswell Aug 26, 2024
7100c69
Update ci-pipeline.yml: timeout 300 for waiting for healthy app
AndyBRoswell Aug 26, 2024
70952b1
Update ci-pipeline.yml: try to capture docker logs
AndyBRoswell Aug 26, 2024
2345cb3
Update ci-pipeline.yml: try to capture docker logs
AndyBRoswell Aug 26, 2024
f2d7406
Update ci-pipeline.yml: try to capture docker log
AndyBRoswell Aug 26, 2024
7e465e0
Update ci-pipeline.yml: capture logs only if failed; refresh envvar
AndyBRoswell Aug 27, 2024
1d91783
Update ci-pipeline.yml: add envvar
AndyBRoswell Aug 27, 2024
568b361
Update ci-pipeline.yml: add envvar
AndyBRoswell Aug 27, 2024
e003def
Update ci-pipeline.yml: envvar chk
AndyBRoswell Aug 27, 2024
47d47dc
Update ci-pipeline.yml: envvar chk
AndyBRoswell Aug 27, 2024
91a61b0
Update ci-pipeline.yml: envvar chk
AndyBRoswell Aug 27, 2024
9b235b4
Update ci-pipeline.yml
AndyBRoswell Aug 27, 2024
5fbb1f9
envvar check for github workflow
AndyBRoswell Aug 27, 2024
3951ac1
Merge remote-tracking branch 'origin/cell-containerization-ExtractorH…
AndyBRoswell Aug 27, 2024
2604f6e
Update ci-pipeline.yml: envvar chk
AndyBRoswell Aug 27, 2024
e82f546
Update ci-pipeline.yml: envvar chk
AndyBRoswell Aug 27, 2024
9fe029a
Update ci-pipeline.yml: envvar chk
AndyBRoswell Aug 27, 2024
c697bb2
Update ci-pipeline.yml: envvar chk
AndyBRoswell Aug 27, 2024
9a16b1c
Update ci-pipeline.yml: envvar
AndyBRoswell Aug 27, 2024
14e59f0
Update ci-pipeline.yml: envvar
AndyBRoswell Aug 27, 2024
7629bc5
Update ci-pipeline.yml: envvar chk
AndyBRoswell Aug 27, 2024
e7c022e
envvar check for github workflow
AndyBRoswell Aug 27, 2024
63a7f09
Merge remote-tracking branch 'origin/cell-containerization-ExtractorH…
AndyBRoswell Aug 27, 2024
1b9f793
Update ci-pipeline.yml: envchk
AndyBRoswell Aug 27, 2024
8a9373d
Update ci-pipeline.yml: envchk
AndyBRoswell Aug 27, 2024
3164f79
revert docker-compose.yaml
AndyBRoswell Aug 27, 2024
e38f990
Merge remote-tracking branch 'origin/cell-containerization-ExtractorH…
AndyBRoswell Aug 27, 2024
d06d469
Update ci-pipeline.yml: chkenv
AndyBRoswell Aug 27, 2024
5ee56c1
Update ci-pipeline.yml: chkenv
AndyBRoswell Aug 27, 2024
5a85210
Update ci-pipeline.yml: chkenv
AndyBRoswell Aug 27, 2024
7a6faf3
Update ci-pipeline.yml: chkenv
AndyBRoswell Aug 28, 2024
16cfaea
chkenv
AndyBRoswell Aug 28, 2024
a1bfea5
Merge remote-tracking branch 'origin/cell-containerization-ExtractorH…
AndyBRoswell Aug 28, 2024
58cf6b9
chkenv
AndyBRoswell Sep 4, 2024
3c728a6
try to add CELL_GITHUB_TOKEN to docker-compose.yaml to read this secr…
AndyBRoswell Sep 4, 2024
9ccfed3
extra chkenv
AndyBRoswell Sep 4, 2024
c3d6aaa
revert extra chkenv
AndyBRoswell Sep 4, 2024
febf60c
slight modification
AndyBRoswell Sep 4, 2024
81d8c63
slight modification
AndyBRoswell Sep 4, 2024
ef180f8
add simple emulated frontend test for endpoint baseimagetags
AndyBRoswell Nov 13, 2024
ea37ff6
handle JUPYTERHUB_USER in task title
AndyBRoswell Nov 22, 2024
619258d
[bugfix] install R dependencies used by rpy2 during image build
AndyBRoswell Nov 29, 2024
4162e64
trying to fix action failures caused by non-existing r pkgs
AndyBRoswell Dec 1, 2024
956801a
trying to fix action failures caused by non-existing r pkgs
AndyBRoswell Dec 1, 2024
66d570f
fixed type inference for py cells
AndyBRoswell Dec 3, 2024
ee76a66
adding support for export in legacy db schema [for the old tinydb]
AndyBRoswell Dec 4, 2024
b373e4a
adding support for export in legacy db schema [for the old tinydb]
AndyBRoswell Dec 4, 2024
4ab0e59
adding support for export in legacy db schema [for the old tinydb]
AndyBRoswell Dec 5, 2024
dfa5834
adding support for export in legacy db schema [for the old tinydb]
AndyBRoswell Dec 5, 2024
7c4c53d
fixed authn token issue
AndyBRoswell Dec 6, 2024
52e2751
.dockerignore
AndyBRoswell Dec 6, 2024
bfc6f69
added some handy scripts to export cells from psql pod in legacy db s…
AndyBRoswell Dec 8, 2024
83fcf1b
added some handy scripts to export cells from psql pod in legacy db s…
AndyBRoswell Dec 8, 2024
ef0b9f3
added some handy scripts to convert some test data to ipynb/rmd
AndyBRoswell Dec 15, 2024
171f0bb
added some handy scripts to convert some test data to ipynb/rmd
AndyBRoswell Dec 15, 2024
523e5e7
handy scripts for database dump
AndyBRoswell Dec 19, 2024
a6e658e
bugfixes for test; elim CSRF_TRUSTED_ORIGINS
AndyBRoswell Feb 5, 2025
0b62691
script for pf test
AndyBRoswell Feb 11, 2025
e0ba654
script for pf test
AndyBRoswell Feb 12, 2025
11c3366
script for pf test
AndyBRoswell Feb 12, 2025
923adcd
script for pf test
AndyBRoswell Feb 14, 2025
04c0843
script for pf test
AndyBRoswell Feb 21, 2025
6299146
script for pf test
AndyBRoswell Feb 21, 2025
4e844da
script for pf test
AndyBRoswell Feb 21, 2025
506c73e
script for pf test
AndyBRoswell Feb 21, 2025
390f42a
script for pf test
AndyBRoswell Feb 21, 2025
b46064a
script for pf test
AndyBRoswell Feb 21, 2025
3f78f28
script for pf test
AndyBRoswell Feb 23, 2025
b544b94
script for pf test
AndyBRoswell Feb 23, 2025
d6190cc
script for pf test
AndyBRoswell Feb 24, 2025
bc2135e
script for pf test
AndyBRoswell Feb 24, 2025
4a5e386
script for pf test
AndyBRoswell Feb 24, 2025
3ffaeea
script for pf test
AndyBRoswell Feb 25, 2025
cf08947
script for pf test
AndyBRoswell Feb 26, 2025
72c5215
[pf test] DEBUG = False
AndyBRoswell Apr 3, 2025
f84153b
comment
AndyBRoswell Apr 3, 2025
fb9ba2b
refined performance recording script
AndyBRoswell Jul 1, 2025
18d4a9a
refined performance recording script
AndyBRoswell Jul 2, 2025
9798355
refined performance recording script
AndyBRoswell Jul 2, 2025
8051c64
refined performance recording script
AndyBRoswell Jul 2, 2025
c5271da
refined performance recording script
AndyBRoswell Jul 2, 2025
daf2766
refined performance recording script
AndyBRoswell Jul 2, 2025
fac14d2
refined performance recording script
AndyBRoswell Jul 2, 2025
6ae3308
refined performance recording script
AndyBRoswell Jul 2, 2025
31435ba
refined performance recording script
AndyBRoswell Jul 2, 2025
3b672a7
refined test notebook generation script
AndyBRoswell Jul 4, 2025
8d61260
refined test notebook generation script
AndyBRoswell Jul 4, 2025
9a7547e
refined test notebook generation script
AndyBRoswell Jul 4, 2025
6d0058d
refined cpu/mem util recording script
AndyBRoswell Jul 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ env:
DOCKER_FOLDER: ${{ inputs.docker_folder }}
TAG: ${{ inputs.tag }}
DOCKERHUB_IMAGE_ID: "qcdis/"
CELL_GITHUB: "https://github.com/QCDIS/NaaVRE-cells-test-3"
CELL_GITHUB_TOKEN: ${{ secrets.CELL_GITHUB_TOKEN }}

jobs:
build:
Expand All @@ -33,21 +35,40 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: chkenv
run: python -c "import os; print(os.getenv('CELL_GITHUB')); print(os.getenv('BASE_PATH'))"

- name: Build docker
run: |
echo '-> envvar:'
env
cd $DOCKER_FOLDER && docker build . --file Dockerfile -t $TAG --build-arg "NODE_ENV=${{ inputs.environment }}"

- name: Run docker compose
uses: isbang/compose-action@v1.5.1
# uses: isbang/compose-action@v1.5.1
uses: hoverkraft-tech/compose-action@v2.0.1
with:
compose-file: "${{ inputs.docker_folder }}/docker-compose.yaml"

- name: chkenv2
run: python -c "import os; print(os.getenv('CELL_GITHUB')); print(os.getenv('BASE_PATH'))"

- name: Wait for healthy app
uses: raschmitt/wait-for-healthy-container/@v1
with:
container-name: app
timeout: 120

- name: chkenv3
if: always()
run: python -c "import os; print(os.getenv('CELL_GITHUB')); print(os.getenv('BASE_PATH'))"

- name: Capture Docker Logs
if: failure()
run: |
echo '-> Capturing Docker logs ...'
docker logs app

- name: Login to github Registry
if: ${{ inputs.push }}
uses: docker/login-action@v3
Expand Down
9 changes: 7 additions & 2 deletions tilt/vreapis/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM python:3.12.2-slim
# FROM python:3.12.2-slim
FROM python:3.11.9-slim
# Dependency pytype [used by PyExtractor] complains 'Python versions > 3.11 are not yet supported'

WORKDIR /app

RUN apt update && \
apt install -y libpq-dev gcc gdal-bin curl net-tools iputils-ping
apt install -y libpq-dev gcc gdal-bin curl net-tools iputils-ping r-base

# Install rysnc for Tilt syncback
RUN apt install -y rsync
Expand All @@ -14,6 +16,9 @@ RUN /opt/venv/bin/pip install pip --upgrade
COPY ./vreapis/requirements.txt /app
RUN /opt/venv/bin/pip install -r requirements.txt

# Set another directory for installation of R packages to avoid permission problem
# RUN echo 'R_LIBS_USER="~/R/library"' >> ~/.Renviron

COPY ./vreapis /app
RUN chmod +x entrypoint.dev.sh

Expand Down
6 changes: 6 additions & 0 deletions vreapis/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.env
export_VARS
.idea
.pytest_cache
__pycache__
NaaVRE_db.json
7 changes: 5 additions & 2 deletions vreapis/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
FROM python:3.12.2-slim
# FROM python:3.12.2-slim
FROM python:3.11.9-slim

WORKDIR /app

RUN apt update && \
apt install -y libpq-dev gcc gdal-bin curl net-tools iputils-ping
apt install -y libpq-dev gcc gdal-bin curl net-tools iputils-ping r-base

RUN python3 -m venv /opt/venv
RUN /opt/venv/bin/pip install pip --upgrade

COPY ./requirements.txt /app
RUN /opt/venv/bin/pip install -r requirements.txt

RUN Rscript -e "install.packages(c('rlang', 'lobstr', 'purrr', 'renv'), repos = 'https://cloud.r-project.org')"

COPY . /app
RUN chmod +x entrypoint.sh

Expand Down
48 changes: 48 additions & 0 deletions vreapis/auth/Keycloak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
from requests.exceptions import RequestException
from rest_framework.authentication import BaseAuthentication
from rest_framework.exceptions import AuthenticationFailed
from django.contrib.auth.models import User
from django.http import HttpRequest
from django.conf import settings
import jwt
import jwt.algorithms

import common


class KeycloakAuthentication(BaseAuthentication):
@staticmethod
def get_verif_inf() -> dict[str, any]:
return common.session.get(settings.KEYCLOAK_VERIF_URL, verify=settings.ALLOW_INSECURE_TLS).json()

def authenticate(self, request: HttpRequest):
received_token: str = request.headers.get('Authorization', '')
if received_token == '':
raise AuthenticationFailed('Authorization header not found. Login using Keycloak to get an access token.')
token_header: dict[str, any] = jwt.get_unverified_header(received_token)
try:
verif_inf: dict[str, any] = KeycloakAuthentication.get_verif_inf()
except RequestException as e:
common.logger.error(f'[{e.response.status_code}] Error while getting Keycloak public key.')
return None
kid: str = token_header.get('kid', '')
if kid == '':
common.logger.error(f'JWT Key ID (kid) not found:{os.linesep}{received_token}')
raise AuthenticationFailed(f'Invalid token format: JWT Key ID (kid) not found.')
verif_keys: list[dict[str, any]] = verif_inf.get('keys', [])
key = next((key for key in verif_keys if key['kid'] == kid), None)
if key is None:
common.logger.error(f'Keycloak public key not found.')
return None
pub_key = jwt.algorithms.RSAAlgorithm.from_jwk(key)
access_token: dict[str, any] = jwt.decode(received_token, pub_key, algorithms=key['alg'], audience='account')
username: str = access_token.get('preferred_username', '')
if username == '':
common.logger.error(f'Username (preferred_username) not found in token:{os.linesep}{received_token}')
raise AuthenticationFailed(f'Invalid token format: Username (preferred_username) not found.')
try:
user: User | None = User.objects.get(username=username)
except User.DoesNotExist:
user: User = User.objects.create_user(username)
return user, None
24 changes: 24 additions & 0 deletions vreapis/auth/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from rest_framework.authentication import BaseAuthentication
from rest_framework.exceptions import AuthenticationFailed
from django.contrib.auth.models import User
from django.http import HttpRequest
from django.conf import settings
import string
import random


class StaticTokenAuthentication(BaseAuthentication):
dummy_user: User

def __init__(self):
try:
StaticTokenAuthentication.dummy_user = User.objects.get(username=settings.NAAVRE_API_TOKEN)
except User.DoesNotExist:
StaticTokenAuthentication.dummy_user = User.objects.create_user(settings.NAAVRE_API_TOKEN, password=''.join(random.choice(string.printable) for _ in range(32)))

def authenticate(self, request: HttpRequest):
access_token: str = request.headers.get('Authorization', '')
print(access_token == f'Token {settings.NAAVRE_API_TOKEN}')
if access_token != f'Token {settings.NAAVRE_API_TOKEN}':
raise AuthenticationFailed(f'Invalid NaaVRE API token')
return StaticTokenAuthentication.dummy_user, None
18 changes: 18 additions & 0 deletions vreapis/auth/test_Keycloak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.test import TestCase, RequestFactory
from django.conf import settings
from urllib.parse import urlencode
from auth.Keycloak import KeycloakAuthentication
import common


class KeycloakAuthenticationTestCase(TestCase):
def test_authenticate(self): # todo. what if authentication failed? what if refresh token is used?
post_data: dict[str, str] = {'client_id': settings.KEYCLOAK_CLIENT_ID, 'grant_type': 'password', 'scope': 'openid', 'username': 'u', 'password': 'u'}
response_body: dict[str, any] = common.session.post(settings.KEYCLOAK_LOGIN_URL, headers={'Content-Type': 'application/x-www-form-urlencoded'}, data=urlencode(post_data), verify=settings.ALLOW_INSECURE_TLS).json()
access_token: str = response_body['access_token']

request_factory = RequestFactory()
request = request_factory.post('', HTTP_AUTHORIZATION=access_token)
authenticator = KeycloakAuthentication()
user, _ = authenticator.authenticate(request)
assert user.username == post_data['username']
21 changes: 21 additions & 0 deletions vreapis/auth/test_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.test import TestCase, RequestFactory
from django.conf import settings
from rest_framework.exceptions import AuthenticationFailed

from auth.simple import StaticTokenAuthentication


class StaticTokenAuthenticationTestCase(TestCase):
tokens_accepted = [f'Token {settings.NAAVRE_API_TOKEN}', ]
tokens_not_accepted = [f'{settings.NAAVRE_API_TOKEN}', f'', f'0123456789abcdef0123456789abcdef01234567', ]

def test_authenticate(self):
request_factory = RequestFactory()
authenticator = StaticTokenAuthentication()
print(StaticTokenAuthenticationTestCase.tokens_accepted)
for token in StaticTokenAuthenticationTestCase.tokens_accepted:
request = request_factory.post('', HTTP_AUTHORIZATION=token)
user, _ = authenticator.authenticate(request)
for token in StaticTokenAuthenticationTestCase.tokens_not_accepted:
request = request_factory.post('', HTTP_AUTHORIZATION=token)
self.assertRaises(AuthenticationFailed, authenticator.authenticate, request)
File renamed without changes.
7 changes: 7 additions & 0 deletions vreapis/catalog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin

from . import models

# Register your models here.

admin.site.register(models.Cell)
4 changes: 2 additions & 2 deletions vreapis/cells/apps.py → vreapis/catalog/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.apps import AppConfig


class CellsConfig(AppConfig):
class CatalogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'cells'
name = 'catalog'
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$cwd = $PWD

$project_root = Resolve-Path "$PSScriptRoot/../../.."

$vreapi_pod_inf = kubectl get pod | sls '^vrepaas-vreapi-\w+-\w+'
$vreapi_pod_name = $vreapi_pod_inf.Matches.Value
$psql_pod_inf = kubectl get pod -owide | sls '^vrepaas-postgresql-0'
$psql_pod_IP = ($psql_pod_inf.Line | sls '\d+\.\d+\.\d+\.\d+').Matches.Value

cd $project_root
$var = Get-Content export_VARS
$off_DB_HOST = ($var | sls '^export DB_HOST=').LineNumber - 1
$off_DB_NAME = ($var | sls '^export DB_NAME=').LineNumber - 1
$off_DB_USER = ($var | sls '^export DB_USER=').LineNumber - 1
$off_DB_PASSWORD = ($var | sls '^export DB_PASSWORD=').LineNumber - 1
$var[$off_DB_HOST] = "export DB_HOST=$psql_pod_IP"
$var[$off_DB_NAME] = "export DB_NAME=vrepaas"
$var[$off_DB_USER] = "export DB_USER=vrepaas"
$var[$off_DB_PASSWORD] = "export DB_PASSWORD=vrepaas"

$var > /tmp/export_VARS
kubectl cp /tmp/export_VARS "${vreapi_pod_name}:/tmp"
kubectl cp "$PSScriptRoot/export-from-psql-pod-in-legacy-db-schema.sh" "${vreapi_pod_name}:/tmp"

kubectl cp ~/NaaVRE/NaaVRE_db.json "${vreapi_pod_name}:/app"
kubectl exec -it $vreapi_pod_name -- bash "/tmp/export-from-psql-pod-in-legacy-db-schema.sh"

kubectl cp "${vreapi_pod_name}:/app/NaaVRE_db.json" ~/NaaVRE/NaaVRE_db.json

cd $cwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source /opt/venv/bin/activate
source /tmp/export_VARS
python manage.py export_in_legacy_db_schema Cell
39 changes: 39 additions & 0 deletions vreapis/catalog/management/commands/export_in_legacy_db_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json

from django.core.management import CommandParser
from django.core.management.base import BaseCommand, CommandError
from django.db.models import QuerySet

import common
from catalog.models import Cell
from catalog.serializers import CellSerializer


class Command(BaseCommand):
help: str = 'Export designated tables in legacy db schema'


def add_arguments(self, parser: CommandParser):
parser.add_argument('tables', type=str, nargs='+', help='Tables to export')

def handle(self, *args, **options):
for table in options['tables']:
match table:
case 'Cell':
queryset: QuerySet = Cell.objects.all().order_by('task_name')
print(f'Cell count: {queryset.count()}')
no: int = 1
cells: dict[str, dict] = {}
for cell in queryset:
serializer = CellSerializer(cell)
print(f'task_name: {cell.task_name}')
cells[str(no)] = serializer.data
no += 1
db_file: str = f'{common.project_root}/NaaVRE_db.json'
with open(db_file) as f:
db = json.load(f)
db['cells'] = cells
with open(db_file, 'w') as f:
json.dump(db, f)
case _:
raise CommandError(f"Table {table} is not supported")
37 changes: 37 additions & 0 deletions vreapis/catalog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 5.0.3 on 2024-06-17 18:52

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Cell',
fields=[
('title', models.CharField(max_length=255)),
('task_name', models.CharField(max_length=255)),
('original_source', models.CharField(max_length=255)),
('types', models.JSONField(blank=True, default=dict, null=True)),
('base_image', models.JSONField(blank=True, null=True)),
('inputs', models.JSONField(blank=True, default=list, null=True)),
('outputs', models.JSONField(blank=True, default=list, null=True)),
('params', models.JSONField(blank=True, default=list, null=True)),
('param_values', models.JSONField(blank=True, null=True)),
('confs', models.JSONField(blank=True, null=True)),
('dependencies', models.JSONField(blank=True, null=True)),
('chart_obj', models.JSONField(blank=True, null=True)),
('node_id', models.CharField(max_length=255, primary_key=True, serialize=False)),
('container_source', models.CharField(max_length=255)),
('global_conf', models.JSONField(blank=True, null=True)),
('kernel', models.CharField(max_length=255)),
('notebook_dict', models.JSONField(blank=True, null=True)),
('image_version', models.CharField(max_length=255)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.3 on 2024-06-17 19:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('catalog', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='cell',
name='container_source',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='cell',
name='image_version',
field=models.CharField(blank=True, max_length=255, null=True),
),
]
Loading