Skip to content

Commit 9432945

Browse files
Merge pull request #14 from agile-learning-institute/add-load-and-validate-error-handling
Add load and validate error handling
2 parents 63503d0 + 8d18077 commit 9432945

File tree

10 files changed

+151
-155
lines changed

10 files changed

+151
-155
lines changed

CONTRIBUTING.md

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,30 @@ This project follows the [Stage0 development standards](https://github.com/agile
4444

4545
- Stage0 [Developers Edition](https://github.com/agile-learning-institute/stage0/blob/main/developer_edition/README.md)
4646

47-
### Installation
47+
### Quick Start
4848

4949
```bash
5050
# Clone the repository
51-
git clone <repository-url>
51+
git clone [email protected]:agile-learning-institute/stage0_mongodb_api.git
5252
cd stage0_mongodb_api
53+
pipenv run service
54+
# Open http://localhost:8082/
5355
```
5456

5557
### Developer Commands
5658

5759
```bash
60+
# Configure environment for testing
61+
export MONGO_DB_NAME=test_database
62+
export MONGO_CONNECTION_STRING=mongodb://localhost:27017/?replicaSet=rs0
63+
64+
# Select a test_case for the server
65+
export INPUT_FOLDER=./tests/test_cases/small_sample
66+
export INPUT_FOLDER=./tests/test_cases/large_sample
67+
68+
# Set Debug Mode if needed
69+
export LOGGING_LEVEL=DEBUG
70+
5871
# Install dependencies
5972
pipenv install --dev
6073

@@ -64,64 +77,55 @@ pipenv run test
6477
# Run a backing mongo database
6578
pipenv run database
6679

67-
# Change the testing database name
68-
export MONGO_DB_NAME=test_database
69-
# NOTE: Must be test_database for db-compare to work
70-
71-
# Select a test_case for the server
72-
export INPUT_FOLDER=./tests/test_cases/small_sample
73-
export INPUT_FOLDER=./tests/test_cases/large_sample
74-
75-
# Set Debug Mode
76-
export LOGGING_LEVEL=DEBUG
77-
78-
# Start API server if database is already running
80+
## All run locally commands assume the database is running
81+
# Start server locally**
7982
pipenv run local
8083

81-
# Start with debugging
82-
pipenv run debug
84+
# Start locally with debugging
85+
pipenv run debug
8386

84-
# Run in Batch mode (process and shut down)
87+
# Run locally in Batch mode (process and shut down)
8588
pipenv run batch
8689

87-
#####################
88-
# Black Box Testing #
90+
# Build container after code changes
91+
pipenv run build
8992

90-
# Silent drop MONGO_DB_NAME for automation
91-
pipenv run db-drop-silent
93+
# Start Containerized Stack (Database, API, and SPA)
94+
pipenv run service
9295

93-
# Compare with INPUT_FOLDER/MONGO_DB_NAME
94-
pipenv run db-compare
96+
# Stop the testing containers
97+
pipenv run down
9598

96-
# Harvest current state to INPUT_FOLDER/MONGO_DB_NAME
97-
pipenv run db-harvest
99+
#####################
100+
# Black Box Testing #
98101

99-
# Combine DB actions with Batch testing
100-
pipenv run db-drop-silent
101-
pipenv run batch
102-
pipenv run db-compare
102+
# MongoDB Utilities
103+
pipenv run db-drop-silent # drop the testing database
104+
pipenv run db-compare # Compare the database to a know set of data
105+
pipenv run db-harvest # Update the set of known data from the database
103106

104107
# Run StepCI black box testing
105108
pipenv run stepci-observability
106109
pipenv run stepci-small
107110
pipenv run stepci-large
108111

109-
# Combine DB actions with StepCI testing
110-
export INPUT_FOLDER=./tests/test_cases/large_sample
111-
pipenv run local
112-
# Then in a different window
112+
# Combine DB actions with Batch testing
113113
pipenv run db-drop-silent
114-
pipenv run stepci-large
115-
pipenv run db-compare
116-
117-
# Build the API Docker Image
118-
pipenv run build
114+
pipenv run db-compare # Should fail
115+
pipenv run batch
116+
pipenv run db-compare # Should pass
119117

120-
# Run API Docker Image + a MongoDB Image
121-
pipenv run container
118+
# Combine DB actions, containerized runtime, and StepCI testing
119+
pipenv run service
120+
pipenv run db-compare # Should fail
121+
pipenv run stepci-large
122+
pipenv run db-compare # Should pass
122123

123-
# Stop the API and DB containers
124-
pipenv run down
124+
# Use the SPA to find errors and test configuration
125+
pipenv run service # if it's not already running
126+
pipenv run db-compare # Should fail
127+
# visit http://localhost:8082 and "process all"
128+
pipenv run db-compare # Should pass
125129

126130
```
127131

Pipfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ db-drop-silent = "python tests/db_util.py drop --passphrase DROP_DROWSSAP_YEK"
1616
db-compare = "python tests/db_util.py compare"
1717
db-harvest = "python tests/db_util.py harvest"
1818
build = "docker build --tag ghcr.io/agile-learning-institute/stage0_mongodb_api:latest ."
19-
database = "docker compose --profile mongodb up --detach"
20-
container = "docker compose --profile all up --detach"
21-
down = "docker compose down stage0_mongodb_api mongodb"
19+
service = "sh -c 'pipenv run down && docker compose --profile mongodb up --detach && echo `Visit http://localhost:8082/`'"
20+
database = "sh -c 'pipenv run down && docker compose --profile mongodb-only up --detach'"
21+
down = "docker compose down mongodb_spa mongodb_api mongodb"
2222

2323
[packages]
2424
python-dotenv = "*"

docker-compose.yaml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# docker-compose.yaml for stage0_mongodb_api testing
22

33
services:
4+
##################################
5+
# MongoDB Backing Service
6+
##################################
47
mongodb:
58
image: mongo:7.0.5
69
ports:
@@ -15,23 +18,42 @@ services:
1518
retries: 30
1619
command: ["--replSet", "rs0", "--bind_ip_all", "--port", "27017"]
1720
profiles:
21+
- mongodb-only
22+
- mongodb-api
1823
- mongodb
19-
- all
2024

21-
stage0_mongodb_api:
22-
image: ghcr.io/agile-learning-institute/stage0_mongodb_api:latest
25+
##################################
26+
# MongoDB configuration Service
27+
##################################
28+
mongodb_api:
29+
image: ghcr.io/agile-learning-institute/stage0_mongo_api:latest
2330
restart: no
2431
ports:
25-
- "8081:8081"
26-
volumes:
27-
- ./tests/test_cases/large_sample:/input
32+
- 8081:8081
2833
environment:
2934
MONGO_CONNECTION_STRING: mongodb://mongodb:27017/?replicaSet=rs0
30-
MONGO_DB_NAME: test_database
31-
AUTO_PROCESS: True
35+
AUTO_PROCESS: False
3236
LOAD_TEST_DATA: True
37+
MONGO_DB_NAME: test_database
38+
volumes:
39+
- ${INPUT_FOLDER:-./tests/test_cases/large_sample}:/input
3340
depends_on:
3441
mongodb:
3542
condition: service_healthy
3643
profiles:
37-
- all
44+
- mongodb-api
45+
- mongodb
46+
47+
mongodb_spa:
48+
image: ghcr.io/agile-learning-institute/stage0_mongodb_spa:latest
49+
restart: no
50+
environment:
51+
MONGODB_API_HOST: stage0_mongodb_api
52+
MONGODB_API_PORT: 8081
53+
MONGODB_SPA_PORT: 8082
54+
ports:
55+
- 8082:8082
56+
depends_on:
57+
- mongodb_api
58+
profiles:
59+
- mongodb

docs/openapi.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ info:
99
name: Apache 2.0
1010
url: http://www.apache.org/licenses/LICENSE-2.0.html
1111
paths:
12-
/api/collections:
12+
/api/collections/:
1313
get:
1414
summary: List all Configured Collections
1515
operationId: list_collections
@@ -46,7 +46,7 @@ paths:
4646
type: array
4747
items:
4848
type: object
49-
/api/collections/{name}:
49+
/api/collections/{name}/:
5050
get:
5151
summary: Get a collection configuration
5252
operationId: get_collection
@@ -108,7 +108,7 @@ paths:
108108
items:
109109
type: object
110110

111-
/api/render/json_schema/{schema_name}:
111+
/api/render/json_schema/{schema_name}/:
112112
get:
113113
summary: Get a Json Schema rendered for a schema
114114
description: Json Schema for a specific schema version (e.g., "collection.1.0.0.1")
@@ -142,7 +142,7 @@ paths:
142142
items:
143143
type: object
144144

145-
/api/render/bson_schema/{schema_name}:
145+
/api/render/bson_schema/{schema_name}/:
146146
get:
147147
summary: Get a Bson Schema rendered for a schema
148148
description: Bson Schema for a specific schema version (e.g., "collection.1.0.0.1")
@@ -176,7 +176,7 @@ paths:
176176
items:
177177
type: object
178178

179-
/api/render/openapi/{schema_name}:
179+
/api/render/openapi/{schema_name}/:
180180
get:
181181
summary: Get a OpenAPI rendered for a schema
182182
description: OpenAPI Specification for a specific schema version (e.g., "collection.1.0.0.1")
@@ -248,6 +248,9 @@ components:
248248
type: string
249249
version:
250250
type: string
251+
targeted_version:
252+
type: string
253+
description: The target version (last version) for this collection
251254
collection:
252255
description: SchemaManager Collection Configuration
253256
type: object

stage0_mongodb_api/routes/render_routes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def create_render_routes():
1111
blueprint = Blueprint('renders', __name__)
1212

13-
@blueprint.route('json_schema/<schema_name>', methods=['GET'])
13+
@blueprint.route('json_schema/<schema_name>/', methods=['GET'])
1414
def render_json_schema(schema_name):
1515
"""Render Json Schema for a schema"""
1616
token = create_flask_token()
@@ -34,7 +34,7 @@ def render_json_schema(schema_name):
3434
"message": str(e)
3535
}]), 500
3636

37-
@blueprint.route('bson_schema/<schema_name>', methods=['GET'])
37+
@blueprint.route('bson_schema/<schema_name>/', methods=['GET'])
3838
def render_bson_schema(schema_name):
3939
"""Render Bson Schema for a schema"""
4040
token = create_flask_token()
@@ -58,7 +58,7 @@ def render_bson_schema(schema_name):
5858
"message": str(e)
5959
}]), 500
6060

61-
@blueprint.route('openapi/<schema_name>', methods=['GET'])
61+
@blueprint.route('openapi/<schema_name>/', methods=['GET'])
6262
def render_openapi(schema_name):
6363
"""Render OpenAPI for a schema"""
6464
token = create_flask_token()

stage0_mongodb_api/services/collection_service.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def list_collections(token: Dict = None) -> List[Dict]:
3333
token: Authentication token for RBAC enforcement
3434
3535
Returns:
36-
List of dictionaries with collection_name and version
36+
List of dictionaries with collection_name, version, and targeted_version
3737
3838
Raises:
3939
CollectionProcessingError: If there are load or validation errors
@@ -52,9 +52,17 @@ def list_collections(token: Dict = None) -> List[Dict]:
5252
# Create a list of collection objects matching the OpenAPI schema
5353
collections = []
5454
for collection_name, collection in config_manager.collection_configs.items():
55+
# Get current version
56+
current_version = VersionManager.get_current_version(collection_name)
57+
58+
# Get targeted version (last version in the versions array)
59+
versions = collection.get("versions", [])
60+
targeted_version = f"{collection_name}.{versions[-1]['version']}" if versions else None
61+
5562
collections.append({
5663
"collection_name": collection_name,
57-
"version": VersionManager.get_current_version(collection_name)
64+
"version": current_version,
65+
"targeted_version": targeted_version
5866
})
5967
return collections
6068

0 commit comments

Comments
 (0)