Skip to content

Commit

Permalink
Added jobbergate-composed subproject to demonstrate stand-alone Jobbe…
Browse files Browse the repository at this point in the history
…rgate
  • Loading branch information
dusktreader committed Sep 22, 2022
1 parent 55b995d commit e87c69d
Show file tree
Hide file tree
Showing 41 changed files with 3,636 additions and 236 deletions.
87 changes: 0 additions & 87 deletions docker-compose.yml

This file was deleted.

9 changes: 0 additions & 9 deletions examples/application-example/templates/dummy-script.py.j2

This file was deleted.

8 changes: 4 additions & 4 deletions examples/create-submit-job.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Note: Before running this demo, you will need::
- An Auth token in the same directory named "access.token". You may use the ``cli-login.py`` for this.
- An application created from the "application-example" directory. It may already exist.
- An application created from the "simple-application" example directory. It may already exist.
"""

import pathlib
Expand All @@ -30,10 +30,10 @@
def get_application_id(
base_api_url="https://armada-k8s.staging.omnivector.solutions/jobbergate",
access_token_file=pathlib.Path("./access.token"),
application_identifier="application-example",
application_identifier="simple-application",
):
"""
Get an application id for the application with the identifier "application-example".
Get an application id for the application with the identifier "simple-application".
"""
token = access_token_file.read_text()
response = httpx.get(
Expand All @@ -57,7 +57,7 @@ def create_job_script(
job_script_name="demo-job-script",
):
"""
Create a job-script from the "application-example".
Create a job-script from the "simple-application".
Application config params and sbatch params are hard-coded but may be easily modified as desired.
"""
Expand Down
25 changes: 25 additions & 0 deletions examples/motorbike-application/jobbergate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from jobbergate_cli.subapps.applications.application_base import JobbergateApplicationBase
from jobbergate_cli.subapps.applications.questions import Text, Integer

class JobbergateApplication(JobbergateApplicationBase):
def mainflow(self, *_, **__):
questions = []

questions.append(Text(
"partition",
message="Choose a partition",
default="compute"
))
questions.append(Integer(
"nodes",
message="Choose number of nodes for job",
default=2,
minval=1,
))
questions.append(Integer(
"ntasks",
message="Choose number of tasks per node for job",
default=6,
minval=1,
))
return questions
7 changes: 7 additions & 0 deletions examples/motorbike-application/jobbergate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
jobbergate_config:
default_template: job-script-template.py.j2
output_directory: .
application_config:
partition: compute
nodes: 2
ntasks: 1
80 changes: 80 additions & 0 deletions examples/motorbike-application/templates/job-script-template.py.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
#SBATCH --partition {{ data.partition }}
#SBATCH --nodes={{ data.nodes }}
#SBATCH --ntasks={{ data.ntasks }}
#SBATCH -J motorbike
#SBATCH --output=/nfs/R-%x.%j.out
#SBATCH --error=/nfs/R-%x.%j.err
#SBATCH -t 1:00:00

# clone OpenFOAM-10 if it is not available yet
OPENFOAM_DIR=/nfs/OpenFOAM-10
if [[ ! -d $OPENFOAM_DIR ]]
then
echo "Cloning OpenFOAM-10"
cd /nfs
git clone https://github.com/OpenFOAM/OpenFOAM-10.git
else
echo "Skipping clone process...we already have the OpenFOAM-10 source code"
fi

# create a working folder inside the shared directory
WORK_DIR=/nfs/$SLURM_JOB_NAME-Job-$SLURM_JOB_ID
mkdir -p $WORK_DIR
cd $WORK_DIR

# path to the openfoam singularity image
export SINGULARITY_IMAGE=/nfs/openfoam10.sif

# download the openfoam v10 singularity image if it is not available yet
if [[ ! -f $SINGULARITY_IMAGE ]]
then
echo "Fetching the singularity image for OpenFOAM-10"
curl -o $SINGULARITY_IMAGE --location "https://omnivector-public-assets.s3.us-west-2.amazonaws.com/singularity/openfoam10.sif"
else
echo "Skipping the image fetch process...we already have the singularity image"
fi


# copy motorBike folder
cp -r $OPENFOAM_DIR/tutorials/incompressible/simpleFoam/motorBike .

# enter motorBike folder
cd motorBike

# clear any previous execution
singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE ./Allclean

# copy motorBike geometry obj
cp $OPENFOAM_DIR/tutorials/resources/geometry/motorBike.obj.gz constant/geometry/

# define surface features inside the block mesh
singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE surfaceFeatures

# generate the first mesh
# mesh the environment (block around the model)
singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE blockMesh

# decomposition of mesh and initial field data
# according to the parameters in decomposeParDict located in the system
# create 6 domains by default
singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE decomposePar -copyZero

# mesh the motorcicle
# overwrite the new mesh files that are generated
srun singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE snappyHexMesh -overwrite -parallel

# write field and boundary condition info for each patch
srun singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE patchSummary -parallel

# potential flow solver
# solves the velocity potential to calculate the volumetric face-flux field
srun singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE potentialFoam -parallel

# steady-state solver for incompressible turbutent flows
srun singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE simpleFoam -parallel

# after a case has been run in parallel
# it can be reconstructed for post-processing
singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE reconstructParMesh -constant
singularity exec --bind $PWD:$HOME $SINGULARITY_IMAGE reconstructPar -latestTime
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions examples/simple-application/templates/dummy-script.py.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/python3

#SBATCH -J dummy_job
#SBATCH -t 60

print("Executing dummy job script")
with open("dummy-ouput.txt", mode="w") as dump_file:
print("I am a very, very dumb job script", file=dump_file)
print("foo={{ data['foo'] }}", file=dump_file)
print("bar={{ data['bar'] }}", file=dump_file)
print("baz={{ data['baz'] }}", file=dump_file)
31 changes: 11 additions & 20 deletions jobbergate-api/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim
FROM python:3.8-slim-buster

RUN apt-get -y update
RUN apt-get install -y --fix-missing build-essential cmake libpq-dev curl
RUN apt update && apt install -y curl libpq-dev gcc

RUN pip install 'poetry==1.1.7'
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
poetry config virtualenvs.create false

ENV MODULE_NAME="jobbergate_api.main"

COPY ./pyproject.toml /app/
COPY ./poetry.lock /app/
COPY ./dev_tools/entrypoint.sh /app/
RUN chmod +x /app/entrypoint.sh

ARG AWS_ACCESS_KEY_ID
ENV AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID

ARG AWS_SECRET_ACCESS_KEY
ENV AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY

RUN poetry config virtualenvs.create false --local
RUN poetry install
COPY ./pyproject.toml ./poetry.lock* ./README* ./LICENSE* /app/
WORKDIR /app
RUN poetry install --no-root

VOLUME /app/jobbergate_api
VOLUME /app/dev_tools
VOLUME /app/alembic

ENTRYPOINT /app/entrypoint.sh
ENTRYPOINT /app/dev_tools/entrypoint.sh
#CMD ["uvicorn", "jobbergate_api.main:app", "--host", "0.0.0.0", "--port", "80"]
25 changes: 7 additions & 18 deletions jobbergate-api/dev_tools/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import docker_gadgets
import typer
from alembic.config import Config
from alembic.command import upgrade as sqla_upgrade, revision as sqla_migrate
from loguru import logger

from jobbergate_api.config import settings
Expand Down Expand Up @@ -75,16 +77,8 @@ def migrate(
Create alembic migrations for a local database.
"""
logger.debug(f"Creating migration with message: {message}")
commands = [
"alembic",
"--config=alembic/alembic.ini",
"revision",
f"--message={message}",
]
if not blank:
commands.append("--autogenerate")

subprocess.run(commands)
config = Config(file_="alembic/alembic.ini")
sqla_migrate(config, message=message, autogenerate=not blank)


@app.command()
Expand All @@ -93,11 +87,6 @@ def upgrade(target: str = typer.Option("head", help="The migration to which the
Apply alembic migrations to a local database.
"""
logger.debug("Upgrading database...")
commands = [
"alembic",
"--config=alembic/alembic.ini",
"upgrade",
target,
]

subprocess.run(commands)

config = Config(file_="alembic/alembic.ini")
sqla_upgrade(config, target)
1 change: 1 addition & 0 deletions jobbergate-api/dev_tools/dev_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def dev_server(
Start a development server locally.
"""
try:
logger.info("Waiting for the database")
_wait_for_db(db_wait_count, db_wait_interval)
except Exception:
logger.error("Database is not available")
Expand Down
6 changes: 3 additions & 3 deletions jobbergate-api/dev_tools/entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -e
cd /app
poetry run dev-tools db upgrade
poetry run dev-tools dev-server --port=8000

tail -f /dev/null
poetry run dev-tools dev-server --port=80
5 changes: 3 additions & 2 deletions jobbergate-api/dev_tools/show_env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Provide command for showing the current environment.
"""
import json

import typer

Expand All @@ -10,11 +11,11 @@


@app.command()
def show_env(json: bool = typer.Option(False, help="Dump as JSON")):
def show_env(use_json: bool = typer.Option(False, "--json", help="Dump as JSON")):
"""
Print out the current environment settings.
"""
if json:
if use_json:
output = json.dumps(settings.dict())
else:
output = "\n ".join(
Expand Down
3 changes: 2 additions & 1 deletion jobbergate-api/jobbergate_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Settings(BaseSettings):

DEPLOY_ENV: str = "LOCAL"

LOG_LEVEL: LogLevelEnum = LogLevelEnum.INFO
LOG_LEVEL: LogLevelEnum = LogLevelEnum.DEBUG

# Database settings # Default to values from docker-compose.yml
DATABASE_HOST: str = "localhost"
Expand All @@ -61,6 +61,7 @@ class Settings(BaseSettings):

# Security Settings. For details, see https://github.com/omnivector-solutions/armasec
ARMASEC_DOMAIN: str
ARMASEC_USE_HTTPS: bool = Field(True)
ARMASEC_AUDIENCE: Optional[HttpUrl]
ARMASEC_DEBUG: bool = Field(False)
ARMASEC_ADMIN_DOMAIN: Optional[str]
Expand Down

0 comments on commit e87c69d

Please sign in to comment.