Skip to content

Commit

Permalink
feat: added new requirements and endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
SteBaum committed Nov 28, 2023
1 parent eb017c6 commit 6594881
Show file tree
Hide file tree
Showing 26 changed files with 1,129 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
__pycache__
.python-version
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# TDP Server

`tdp-server` provides a server to interact with [`tdp-lib`](https://github.com/tOSIT-IO/tdp-lib).

## Requirements

The server is made with Python. The following is required:

- [Python](https://www.python.org/) `3.9.5`
- [Poetry](https://python-poetry.org/) `1.7.1`
- [tdp-lib](https://github.com/tOSIT-IO/tdp-lib) and its dependencies as the server imports classes from it.

## Installation

Install the `tdp-server` dependencies in the pyproject.toml as follows:

```bash
poetry install
```

## Usage

Start the server as follows:

```bash
uvicorn tdp_server.main:app --reload
```
471 changes: 471 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "tdp-server"
version = "0.1.0"
description = ""
authors = ["SteBaum <stephan.baum@edu.dsti.institute>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
uvicorn = "^0.24.0.post1"
fastapi = "^0.104.1"
pydantic = "^2.5.1"
sqlalchemy = "^2.0.23"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file added tdp_server/__init__.py
Empty file.
Empty file added tdp_server/api/__init__.py
Empty file.
Empty file added tdp_server/api/v1/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions tdp_server/api/v1/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from fastapi import APIRouter
from tdp_server.api.v1.endpoints import (
components,
services,
deployments,
operations,
planification,
status,
variables,
)


api_router = APIRouter()

api_router.include_router(services.router, prefix="/services", tags=["services"])
api_router.include_router(
components.router, prefix="/services/{service_id}/components", tags=["components"]
)
api_router.include_router(
deployments.router, prefix="/deployments", tags=["deployments"]
)
api_router.include_router(variables.router, prefix="/variables", tags=["variables"])
api_router.include_router(operations.router, prefix="/operations", tags=["operations"])
api_router.include_router(status.router, prefix="/status", tags=["status"])
api_router.include_router(
planification.router, prefix="/planification", tags=["planification"]
)
58 changes: 58 additions & 0 deletions tdp_server/api/v1/dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
COMMON_RESPONSES = {
401: {
"description": "Unauthenticated",
"content": {
"application/json": {
"example": {"detail": "Error during authentication validation (reason)"}
}
},
},
403: {
"description": "Not enough privileges",
"headers": {
"WWW-Authenticate": {
"schema": {"type": "string"},
"description": "Authentication method to use",
}
},
"content": {
"application/json": {"example": {"detail": "Not enough permissions"}}
},
},
}

SERVICE_ID_DOES_NOT_EXIST_ERROR = {
400: {
"description": "Service id does not exist",
"content": {
"application/json": {"example": {"detail": "{service_id} does not exist"}}
},
}
}

COMPONENT_ID_DOES_NOT_EXIST_ERROR = {
400: {
"description": "Component id does not exist",
"content": {
"application/json": {"example": {"detail": "{component_id} does not exist"}}
},
}
}

COMMON_DEPLOYMENT_ARGS = {
409: {
"description": "Another deployment is still running, only one deployment at a time is allowed",
"content": {
"application/json": {
"example": {"detail": "another deployment is still running"}
}
},
}
}

IMPORT_FILE_DOES_NOT_EXIST = {
400: {
"description": "File does not exist",
"content": {"application/json": {"example": {"detail": "File does not exist"}}},
}
}
Empty file.
42 changes: 42 additions & 0 deletions tdp_server/api/v1/endpoints/components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from fastapi import APIRouter

from tdp_server.api.v1 import dependencies
from tdp_server.schemas.components import Component, ComponentUpdateResponse

router = APIRouter()


@router.get(
"/{component_id}",
response_model=Component,
responses={
**dependencies.COMMON_RESPONSES,
**dependencies.COMPONENT_ID_DOES_NOT_EXIST_ERROR,
},
)
def get_component():
pass


@router.put(
"/{component_id}",
response_model=ComponentUpdateResponse,
responses={
**dependencies.COMMON_RESPONSES,
**dependencies.COMPONENT_ID_DOES_NOT_EXIST_ERROR,
},
)
def put_component():
pass


@router.patch(
"/{component_id}",
response_model=ComponentUpdateResponse,
responses={
**dependencies.COMMON_RESPONSES,
**dependencies.COMPONENT_ID_DOES_NOT_EXIST_ERROR,
},
)
def patch_component():
pass
97 changes: 97 additions & 0 deletions tdp_server/api/v1/endpoints/deployments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from fastapi import APIRouter
from typing import List

from tdp_server.api.v1 import dependencies
from tdp_server.schemas.deployments import (
DeploymentLog,
DeploymentLogWithOperations,
DeployStatus,
)
from tdp_server.schemas.operations import OperationLog


router = APIRouter()


@router.get(
"/",
response_model=List[DeploymentLog],
responses={**dependencies.COMMON_RESPONSES},
)
def get_deployments():
pass


@router.get(
"/{deployement_id}",
response_model=DeploymentLogWithOperations,
responses={**dependencies.COMMON_RESPONSES},
)
def get_deployment():
pass


@router.get(
"/{deployement_id}/operation/{operation}",
response_model=OperationLog,
responses={**dependencies.COMMON_RESPONSES},
)
def get_deployment_operation():
pass


@router.get(
"/status",
response_model=DeployStatus,
responses={**dependencies.COMMON_RESPONSES},
)
def get_deployment_status():
pass


@router.post(
"/dag",
response_model=DeploymentLog,
responses={
**dependencies.COMMON_RESPONSES,
**dependencies.COMMON_DEPLOYMENT_ARGS,
},
)
def post_dag():
pass


@router.post(
"/operations",
response_model=DeploymentLog,
responses={
**dependencies.COMMON_RESPONSES,
**dependencies.COMMON_DEPLOYMENT_ARGS,
},
)
def post_operations():
pass


@router.post(
"/resumption",
response_model=DeploymentLog,
responses={
**dependencies.COMMON_RESPONSES,
**dependencies.COMMON_DEPLOYMENT_ARGS,
},
)
def post_resumumption():
pass


@router.post(
"/reconfiguration",
response_model=DeploymentLog,
responses={
**dependencies.COMMON_RESPONSES,
**dependencies.COMMON_DEPLOYMENT_ARGS,
},
)
def post_reconfiguration():
pass
34 changes: 34 additions & 0 deletions tdp_server/api/v1/endpoints/operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from fastapi import APIRouter

from tdp_server.api.v1 import dependencies
from tdp_server.schemas.operations import Operation


router = APIRouter()


@router.get(
"/",
response_model=Operation,
responses={**dependencies.COMMON_RESPONSES},
)
def get_operations():
pass


@router.get(
"/dag",
response_model=Operation,
responses={**dependencies.COMMON_RESPONSES},
)
def get_dag_operations():
pass


@router.get(
"/other",
response_model=Operation,
responses={**dependencies.COMMON_RESPONSES},
)
def get_other_operations():
pass
55 changes: 55 additions & 0 deletions tdp_server/api/v1/endpoints/planification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from fastapi import APIRouter
from typing import List

from tdp_server.api.v1 import dependencies
from tdp_server.schemas.operations import Operation

router = APIRouter()


@router.post(
"/dag",
response_model=List[Operation],
responses={**dependencies.COMMON_RESPONSES},
)
def post_plan_dag():
pass


@router.post(
"/operations",
response_model=List[Operation],
responses={**dependencies.COMMON_RESPONSES},
)
def post_plan_operations():
pass


@router.post(
"/resumption",
response_model=List[Operation],
responses={**dependencies.COMMON_RESPONSES},
)
def post_plan_resumption():
pass


@router.post(
"/reconfiguration",
response_model=List[Operation],
responses={**dependencies.COMMON_RESPONSES},
)
def post_plan_reconfiguration():
pass


@router.post(
"/importation",
response_model=List[Operation],
responses={
**dependencies.COMMON_RESPONSES,
**dependencies.IMPORT_FILE_DOES_NOT_EXIST,
},
)
def post_importation():
pass
Loading

0 comments on commit 6594881

Please sign in to comment.