-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
84 lines (71 loc) · 2.62 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
from starlette.middleware.cors import CORSMiddleware
from controller import job_controller, download_controller
from config.log_config import create_log
logger = create_log()
app = FastAPI(
# title="Prometheus DB API Service",
# description="Prometheus DB API Service",
title="Spark Job API Service",
description="Spark Job API Service",
version="0.0.1",
# terms_of_service="http://example.com/terms/",
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
def custom_openapi():
if not app.openapi_schema:
app.openapi_schema = get_openapi(
title=app.title,
version=app.version,
openapi_version=app.openapi_version,
description=app.description,
terms_of_service=app.terms_of_service,
contact=app.contact,
license_info=app.license_info,
routes=app.routes,
tags=app.openapi_tags,
servers=app.servers,
)
for _, method_item in app.openapi_schema.get('paths').items():
for _, param in method_item.items():
responses = param.get('responses')
# remove 422 response, also can remove other status code
if '422' in responses:
del responses['422']
return app.openapi_schema
app.openapi = custom_openapi
''' http://localhost:8002/docs '''
@app.get("/", tags=['API'],
status_code=200,
description="Default GET API",
summary="Return Json")
async def root():
return {"message": "Hello World"}
'''
@app.get("/test", tags=['API'],
status_code=200,
description="Default GET Param API",
summary="Return GET Param Json")
async def root_with_arg(id):
logger.info('root_with_arg - {}'.format(id))
return {"message": "Hello World [{}]".format(id)}
@app.get("/test/{id}", tags=['API'],
status_code=200,
description="Default GET with Body API",
summary="Return GET with Body Json")
async def root_with_param(id):
logger.info('root_with_arg - {}'.format(id))
return {"message": "Hello World [{}]".format(id)}
'''
# router
''' Enter the host name of the master node in the spark cluster to collect the list of running spark jobs. '''
app.include_router(job_controller.app, tags=["SparkJob API"], )
'''Create Excel file after receiving a list of spark jobs running in the entire environment.. '''
app.include_router(download_controller.app, tags=["Download API"], )