Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Computing API Components #28

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
338384f
changed license to 2024
TibbersHao Mar 25, 2024
95f4ede
added database/
TibbersHao Mar 25, 2024
bc6aca0
added a copy from the main mlex repo
TibbersHao Mar 25, 2024
7360ae7
added mongo service, restricted only local hosts for port exposure
TibbersHao Mar 25, 2024
f251997
added example .env file
TibbersHao Mar 25, 2024
6c898f4
deleted init_db.sh as no longer used in docker-compose
TibbersHao Mar 25, 2024
6c2b9da
updated readme with new instruction
TibbersHao Mar 25, 2024
c72a9a9
took out box of apps, cleared layout
TibbersHao Mar 25, 2024
f041a60
took out job related callbacks, cleared prints and commented codes
TibbersHao Mar 25, 2024
be264e0
cleared prints and unused codes
TibbersHao Mar 25, 2024
7a8914d
added gh action
TibbersHao Mar 25, 2024
80e672d
added pre-commit files for formatting
TibbersHao Mar 25, 2024
f9074cd
added pyproject
TibbersHao Mar 25, 2024
38d5688
added for dev test
TibbersHao Mar 26, 2024
d034266
reformatting
TibbersHao Mar 26, 2024
aa9edf2
took out pre-requisition
TibbersHao Mar 27, 2024
5d10b95
trimmed out unnecessary package installation
TibbersHao Mar 28, 2024
6929433
changed env var readout
TibbersHao Mar 28, 2024
47f984e
trimmed job related callbacks and layouts
TibbersHao Mar 28, 2024
b9d7e2a
changed file name
TibbersHao Mar 28, 2024
9c5b564
fixed typo
TibbersHao Mar 28, 2024
d5700f8
renamed mongodb name to be content registry specific
TibbersHao Mar 29, 2024
c07f840
reverted back to original container name
TibbersHao Apr 1, 2024
6892123
added notes for database purging
TibbersHao Apr 9, 2024
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
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
# 127 is width of the Github code viewer,
# black default is 88 so this will only warn about comments >127
max-line-length = 127
# Ignore errors due to incompatibility with black
#https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html
extend-ignore = E203,E701
31 changes: 31 additions & 0 deletions .github/workflows/format-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: format-and-lint

on: pull_request

jobs:
test-and-lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.9.16
uses: actions/setup-python@v3
with:
python-version: '3.9.16'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run isort
uses: isort/isort-action@master
- name: Test formatting with black
run: |
black . --check
45 changes: 45 additions & 0 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Create and publish image

on:
push:
branches: ['main']
tags: ['v*']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# ggshield
.cache_ggshield

# Dirctory
.DS_Store
content-api/src/__pycache__/*
content-regist/src/__pycache__/*
content-regist/src/kwarg_editor_copy.py
database/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- repo: https://github.com/gitguardian/ggshield
rev: v1.25.0
hooks:
- id: ggshield
language_version: python3
stages: [commit]
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MLExchange Copyright (c) 2021, The Regents of the University of California,
MLExchange Copyright (c) 2024, The Regents of the University of California,
through Lawrence Berkeley National Laboratory (subject to receipt of
any required approvals from the U.S. Dept. of Energy). All rights reserved.

Expand Down
71 changes: 34 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,77 @@
# MLExchange Content Registry
This is the first Dash 2 version of Content Registry.
This is the first Dash 2 version of Content Registry.

Content registry and its API for the MLExchange platform.
The architecture looks like below.

![image info](./assets/content_registry_v2.png)

Contents include:
- models
- apps
- workflows
- assets (metadata, e.g., tags, trained models etc.)
-
Contents include:
- models
- apps
- workflows
- assets (metadata, e.g., tags, trained models etc.)
-

### GUI
![image info](./assets/gui.png)


## How to use

Prerequisite: install [mlex\_compute\_api](https://github.com/mlexchange/mlex_computing_api)
Note: the current version of content registry no longer requires installing [mlex\_compute\_api](https://github.com/mlexchange/mlex_computing_api) as a pre-requisition.
taxe10 marked this conversation as resolved.
Show resolved Hide resolved

**Note:** This version connects to a local mongodb container named `mongodb` with a port number `27017`. Please checkout the `atlas` branch for using our cloud mongodb service.

**Running content registry**.
**Running content registry**.

1. Create the same environmental file (.env) as the one used in the compute api.
1. Create an environmental file (.env) from the `.env.example` provided in the repository.

```
MONGO_DB_USERNAME=your_username
MONGO_DB_PASSWORD=your_password
```
2. If it was the first time running MLExchange content registry, you need to initialize its database using the command `./init_db.sh`. If the error msg says 'duplicate key error collection', it means the content database is already existent.
```
MONGO_DB_USERNAME=your_username
MONGO_DB_PASSWORD=your_password
```

**Note:** to re-initialize the database, it is suggested to first clean `/dump` folder in the local mongodb container.

3. Run `docker-compose up --build`.
2. Run `docker-compose up --build`.

**Viewing existing contents**
**Viewing existing contents**
Scroll down to the bottom of the page, click on **Refresh** button.

**Delete existing contents**
**Delete existing contents**
Select contents from the table and click **Delete** button.

**Modify existing contents**
Currently, the **Modify** button is deprecated.
**Modify existing contents**
Currently, the **Modify** button is deprecated.
Therefore, the easiest way to modify an existing registration is to delete the content, then either register a new content by filling out the forms or upload the revised JSON document again (drag and drop, click **Validate** button first, then click the **Upload** button).


## Adaptive Dash GUI component
**name**: a unique string, equivalent to the `id` in each Dash component
**param_key**: a parameter key generally used to construct the `cmd` in job dictionary for MLExchange compute api
**name**: a unique string, equivalent to the `id` in each Dash component
**param_key**: a parameter key generally used to construct the `cmd` in job dictionary for MLExchange compute api

## API calls
get\_models()
get\_model(uid)
get\_models()
get\_model(uid)


get\_apps()
get\_app(uid)
get\_apps()
get\_app(uid)


get\_workflows()
get\_workflow(uid)
get\_workflows()
get\_workflow(uid)


post\_assets(data)
post\_asset(data)
get\_assets()
get\_asset(uid)
delete\_assets(query)
delete\_asset(uid)
post\_assets(data)
post\_asset(data)
get\_assets()
get\_asset(uid)
delete\_assets(query)
delete\_asset(uid)


## License
MLExchange Copyright (c) 2021, The Regents of the University of California,
MLExchange Copyright (c) 2024, The Regents of the University of California,
through Lawrence Berkeley National Laboratory (subject to receipt of
any required approvals from the U.S. Dept. of Energy). All rights reserved.

Expand Down
6 changes: 3 additions & 3 deletions content-api/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ MAINTAINER THE MLEXCHANGE TEAM

RUN apt-get update && apt-get install -y --no-install-recommends \
taxe10 marked this conversation as resolved.
Show resolved Hide resolved
python3-pip\
libxext6
libxext6


COPY docker/requirements.txt requirements.txt

RUN pip3 install --upgrade pip &&\
pip3 install --timeout=5000 -r requirements.txt
pip3 install --timeout=5000 -r requirements.txt
taxe10 marked this conversation as resolved.
Show resolved Hide resolved


WORKDIR /app/api
Expand All @@ -20,4 +20,4 @@ ENV PYTHONUNBUFFERED=1

CMD bash
WORKDIR /app/api/src
CMD uvicorn content_api:app --host 0.0.0.0 --port 8000 --reload
CMD uvicorn content_api:app --host 0.0.0.0 --port 8000 --reload
36 changes: 16 additions & 20 deletions content-api/src/api_util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import configparser
import os

import requests

config = configparser.ConfigParser()
config.read(os.path.join(os.path.dirname(__file__), "config.ini"))
WEBHOOK_RECEIVER_URL = 'http://%s' % config['webhook']['RECEIVER']
WEBHOOK_RECEIVER_URL = "http://%s" % config["webhook"]["RECEIVER"]


def send_webhook(msg):
"""
Expand All @@ -14,23 +16,17 @@ def send_webhook(msg):
"""
try:
# Post a webhook message
# default is a function applied to objects that are not serializable = it converts them to str
resp = requests.post(WEBHOOK_RECEIVER_URL, json=msg, headers={'Content-Type': 'application/json'}, timeout=1.0)
# Returns an HTTPError if an error has occurred during the process (used for debugging).
resp = requests.post(
WEBHOOK_RECEIVER_URL,
json=msg,
headers={"Content-Type": "application/json"},
timeout=1.0,
)
# Returns an HTTPError if an error has occurred
# during the process (used for debugging).
resp.raise_for_status()
except requests.exceptions.HTTPError as err:
#print("An HTTP Error occurred",repr(err))
pass
except requests.exceptions.ConnectionError as err:
#print("An Error Connecting to the API occurred", repr(err))
pass
except requests.exceptions.Timeout as err:
#print("A Timeout Error occurred", repr(err))
pass
except requests.exceptions.RequestException as err:
#print("An Unknown Error occurred", repr(err))
pass
except:
pass
except Exception as err:
print(err)
return False
else:
return resp.status_code
return resp.ok
2 changes: 1 addition & 1 deletion content-api/src/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RECEIVER = content-api:8000/api/v0/receiver
USER_API_PORT = 5003

[search api port]
SEARCH_API_PORT = 8060
SEARCH_API_PORT = 8060
Loading
Loading