Skip to content

Commit ebae9d0

Browse files
authored
API for solvers with fake backend (#1866)
New extension of the API to run solvers. Adds three new resources: jobs, solves and files. Current implementation of the backend uses a faker data and services.
1 parent deffa4b commit ebae9d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3994
-446
lines changed

packages/models-library/src/models_library/services.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
python -c "from models_library.services import ServiceDockerData as cls; print(cls.schema_json(indent=2))" > services-schema.json
55
"""
66
from enum import Enum
7-
from typing import Dict, List, Optional, Union, Any
7+
from typing import Any, Dict, List, Optional, Union
88

99
from pydantic import (
1010
BaseModel,
@@ -22,7 +22,9 @@
2222

2323
from .basic_regex import VERSION_RE
2424

25+
# NOTE: needs to end with / !!
2526
SERVICE_KEY_RE = r"^(simcore)/(services)/(comp|dynamic|frontend)(/[\w/-]+)+$"
27+
COMPUTATIONAL_SERVICE_KEY_RE = r"^(simcore)/(services)/comp(/[\w/-]+)+$"
2628
KEY_RE = SERVICE_KEY_RE # TODO: deprecate this global constant by SERVICE_KEY_RE
2729

2830
PROPERTY_TYPE_RE = r"^(number|integer|boolean|string|data:([^/\s,]+/[^/\s,]+|\[[^/\s,]+/[^/\s,]+(,[^/\s]+/[^/,\s]+)*\]))$"

packages/pytest-simcore/src/pytest_simcore/repository_paths.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# pylint: disable=redefined-outer-name
2-
32
import sys
43
from pathlib import Path
54

@@ -88,3 +87,26 @@ def pylintrc(osparc_simcore_root_dir: Path) -> Path:
8887
pylintrc = osparc_simcore_root_dir / ".pylintrc"
8988
assert pylintrc.exists()
9089
return pylintrc
90+
91+
92+
@pytest.fixture(scope="session")
93+
def tests_dir() -> Path:
94+
tdir = (current_dir / "..").resolve()
95+
assert tdir.exists()
96+
assert tdir.name == "tests"
97+
return tdir
98+
99+
100+
## PACKAGE and SERVICE DIRECTORY STRUCTURE
101+
102+
103+
@pytest.fixture(scope="session")
104+
def project_slug_dir() -> Path:
105+
raise NotImplementedError("Override fixture in project's tests/conftest.py")
106+
107+
108+
@pytest.fixture(scope="session")
109+
def project_tests_dir(project_slug_dir: Path) -> Path:
110+
test_dir = project_slug_dir / "tests"
111+
assert test_dir.exists()
112+
return test_dir

scripts/common-service.Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ shell: ## runs shell in production container
7070

7171
.PHONY: tail
7272
tail: ## tails log of $(APP_NAME) container
73-
docker logs --follow $(shell docker ps -f "name=$(APP_NAME)*" --format {{.ID}}) > $(APP_NAME).log 2>&1
73+
docker logs --follow $(shell docker ps -f "name=$(APP_NAME)*" --format {{.ID}}) 2>&1
7474

7575

7676
.PHONY: info

scripts/common.Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ VCS_REF := $(shell git rev-parse --short HEAD)
3535
NOW_TIMESTAMP := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
3636
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
3737

38+
# relevant repo folders
39+
SCRIPTS_DIR := $(abspath $(REPO_BASE_DIR)/scripts)
40+
3841
# virtual env
3942
VENV_DIR := $(abspath $(REPO_BASE_DIR)/.venv)
4043

services/api-server/.env-devel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#
22
# Environment variables used to configure this service
33
#
4+
FAKE_API_SERVER_ENABLED=0
5+
DEBUG=0
46

57
# SEE services/api-server/src/simcore_service_api_server/auth_security.py
68
SECRET_KEY=d0d0397de2c85ad26ffd4a0f9643dfe3a0ca3937f99cf3c2e174e11b5ef79880
@@ -22,3 +24,14 @@ WEBSERVER_ENABLED=1
2224
WEBSERVER_HOST=webserver
2325
# Take from general .env-devel
2426
WEBSERVER_SESSION_SECRET_KEY=REPLACE ME with a key of at least length 32.
27+
28+
29+
# catalog
30+
CATALOG_ENABLED=1
31+
CATALOG_HOST=catalog
32+
33+
# storage
34+
STORAGE_HOST=storage
35+
36+
# director
37+
DIRECTO2_HOST=director-v2
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Environment variables used to configure this service stand-alone in FAKE mode
3+
#
4+
FAKE_API_SERVER_ENABLED=1
5+
6+
# SEE services/api-server/src/simcore_service_api_server/auth_security.py
7+
SECRET_KEY=d0d0397de2c85ad26ffd4a0f9643dfe3a0ca3937f99cf3c2e174e11b5ef79880
8+
9+
# SEE services/api-server/src/simcore_service_api_server/settings.py
10+
LOG_LEVEL=DEBUG
11+
12+
POSTGRES_ENABLED=0
13+
POSTGRES_USER=test
14+
POSTGRES_PASSWORD=test
15+
POSTGRES_DB=test
16+
POSTGRES_HOST=localhost
17+
18+
# Enables debug
19+
SC_BOOT_MODE=production
20+
21+
22+
# webserver
23+
WEBSERVER_ENABLED=0
24+
WEBSERVER_HOST=webserver
25+
# Take from general .env-devel
26+
WEBSERVER_SESSION_SECRET_KEY=REPLACE ME with a key of at least length 32.
27+
28+
29+
# catalog
30+
CATALOG_ENABLED=0
31+
CATALOG_HOST=catalog
32+
33+
# storage
34+
STORAGE_ENABLED=0
35+
STORAGE_HOST=storage
36+
37+
# director
38+
DIRECTOR2_ENABLED=0
39+
DIRECTO2_HOST=director-v2

services/api-server/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
# outputs from makefile
22
client
3-
docker-compose.yml
4-
.env

services/api-server/Makefile

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,98 @@
44
include ../../scripts/common.Makefile
55
include ../../scripts/common-service.Makefile
66

7-
87
.PHONY: reqs
98
reqs: ## compiles pip requirements (.in -> .txt)
109
@$(MAKE_C) requirements reqs
1110

1211

13-
14-
15-
# DEVELOPMENT TOOLS ########
12+
# DEVELOPMENT TOOLS ###########################################################################
1613

1714
.env:
1815
cp .env-devel $@
1916

20-
docker-compose.yml:
17+
DOCKER_COMPOSE_EXTRA_FILE:=.docker-compose-extra-ignore.yml
18+
$(DOCKER_COMPOSE_EXTRA_FILE):
2119
cp $(CURDIR)/tests/utils/docker-compose.yml $@
2220

23-
.PHONY: run-devel down
24-
run-devel: .env docker-compose.yml down ## runs app on host with pg fixture for development [for development]
25-
# Starting db (under $<)
26-
docker-compose up --detach
27-
# Creating db-tables: user=key, password=secret
28-
@$(MAKE) db-tables
29-
# start app (under $<)
30-
uvicorn simcore_service_api_server.__main__:the_app \
31-
--reload --reload-dir $(SRC_DIR) \
32-
--port=8000 --host=0.0.0.0
3321

3422
.PHONY: db-tables
3523
db-tables: .env ## upgrades and create tables [for development]
3624
# Upgrading and creating tables
3725
export $(shell grep -v '^#' $< | xargs -d '\n'); \
3826
python3 tests/utils/init-pg.py
3927

28+
29+
4030
.PHONY: db-migration
4131
db-migration: .env ## runs discover and upgrade on running pg-db [for development]
4232
# Creating tables
4333
export $(shell grep -v '^#' $< | xargs -d '\n'); \
4434
sc-pg discover && sc-pg upgrade
4535

46-
down: docker-compose.yml ## stops pg fixture
36+
37+
.PHONY: down
38+
down: $(DOCKER_COMPOSE_EXTRA_FILE)## stops pg fixture
4739
# stopping extra services
4840
-@docker-compose -f $< down
49-
# killing any process using port 8000
41+
# killing any process using port 8000 (app) and 3000 (debug)
5042
-@fuser --kill --verbose --namespace tcp 8000
43+
-@fuser --kill --verbose --namespace tcp 3000
5144

5245

46+
# TODO: These are all different ways to run the server for dev-purposes .
47+
48+
.PHONY: run-devel
49+
run-devel: .env $(DOCKER_COMPOSE_EXTRA_FILE) down
50+
# Starting db (under $<)
51+
docker-compose --file $(DOCKER_COMPOSE_EXTRA_FILE) up --detach
52+
sleep 2
53+
# Creating db-tables: user=key, password=secret
54+
@$(MAKE) db-tables
55+
# start app (under $<)
56+
uvicorn simcore_service_api_server.__main__:the_app \
57+
--reload --reload-dir $(SRC_DIR) \
58+
--port=8000 --host=0.0.0.0 \
59+
--log-level debug
60+
61+
62+
.PHONY: run-fake run-fake-devel
63+
run-fake: # starts a fake server in a container
64+
docker run -it \
65+
--env-file .env-fake-standalone \
66+
--publish 8000:8000 \
67+
local/${APP_NAME}:production
68+
# Open http://172.0.0.1:8000/dev/doc
5369

54-
# BUILD ########
70+
71+
run-fake-devel: # starts a fake server in a dev-container
72+
docker run -it \
73+
--env-file .env-fake-standalone \
74+
--env SC_BOOT_MODE=debug-ptvsd \
75+
--env LOG_LEVEL=debug \
76+
--env DEBUG=true \
77+
--publish 8000:8000 \
78+
--publish 3006:3000 \
79+
--volume $(REPO_BASE_DIR)/services/api-server:/devel/services/api-server \
80+
--volume $(REPO_BASE_DIR)/packages:/devel/packages \
81+
local/${APP_NAME}:development
82+
# Open http://172.0.0.1:8000/dev/doc
83+
84+
85+
# BUILD ###########################################################################
5586

5687
.PHONY: openapi-specs openapi.json
5788
openapi-specs: openapi.json
5889
openapi.json: .env
5990
# generating openapi specs file
6091
python3 -c "import json; from $(APP_PACKAGE_NAME).__main__ import *; print( json.dumps(the_app.openapi(), indent=2) )" > $@
92+
# validates OAS file: $@
93+
@cd $(CURDIR); \
94+
$(SCRIPTS_DIR)/openapi-generator-cli.bash validate --input-spec /local/$@
6195

6296

63-
# GENERATION python client ########
97+
98+
# GENERATION python client ###########################################################################
6499
.PHONY: python-client generator-help
65100

66101
# SEE https://openapi-generator.tech/docs/usage#generate
@@ -69,12 +104,10 @@ openapi.json: .env
69104
# TODO: put instead to additional-props.yaml and --config=openapi-generator/python-config.yaml
70105
# TODO: copy this code to https://github.com/ITISFoundation/osparc-simcore-python-client/blob/master/Makefile
71106
#
72-
73107
# NOTE: assumes this repo exists
74108
GIT_USER_ID := ITISFoundation
75109
GIT_REPO_ID := osparc-simcore-python-client
76110

77-
SCRIPTS_DIR := $(abspath $(CURDIR)/../../scripts)
78111
GENERATOR_NAME := python
79112

80113
ADDITIONAL_PROPS := \
@@ -94,23 +127,28 @@ comma := ,
94127
client:
95128
# cloning $(GIT_USER_ID)/$(GIT_REPO_ID) -> $@
96129
git clone [email protected]:$(GIT_USER_ID)/$(GIT_REPO_ID).git $@
97-
cd client; git checkout -b "upgrade-${APP_VERSION}"
130+
# TODO: if fails, add -b
131+
cd client; git checkout "upgrade-${APP_VERSION}"
98132

99133

100134
python-client: client openapi.json ## runs python client generator
135+
# copies latest version of the openapi
136+
@cp openapi.json client/api/
137+
# generates
101138
cd $(CURDIR); \
102139
$(SCRIPTS_DIR)/openapi-generator-cli.bash generate \
103140
--generator-name=$(GENERATOR_NAME) \
104141
--git-user-id=$(GIT_USER_ID)\
105142
--git-repo-id=$(GIT_REPO_ID)\
106-
--http-user-agent="osparc-api/{packageVersion}/{language}"\
143+
--http-user-agent="osparc-api/$(APP_VERSION)/python"\
107144
--input-spec=/local/openapi.json \
108145
--output=/local/client \
109146
--additional-properties=$(subst $(space),$(comma),$(strip $(ADDITIONAL_PROPS)))\
110147
--package-name=osparc\
111148
--release-note="Updated to $(APP_VERSION)"
112149

113150

151+
114152
generator-help: ## help on client-api generator
115153
# generate help
116154
@$(SCRIPTS_DIR)/openapi-generator-cli.bash help generate

services/api-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Setup environment
2121
```cmd
2222
make devenv
2323
source .venv/bin/activate
24-
cd services/api-service
24+
cd services/api-server
2525
make install-dev
2626
```
2727
Then

services/api-server/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0
1+
0.4.0

services/api-server/docker/boot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if [ "${SC_BOOT_MODE}" = "debug-ptvsd" ]
3030
then
3131
# NOTE: ptvsd is programmatically enabled inside of the service
3232
# this way we can have reload in place as well
33-
exec uvicorn simcore_service_api_server.__main__:the_app --reload --host 0.0.0.0
33+
exec uvicorn simcore_service_api_server.__main__:the_app --reload --host 0.0.0.0 --reload-dir services/api-server/src/simcore_service_api_server
3434
else
3535
exec simcore-service-api-server
3636
fi

0 commit comments

Comments
 (0)