Spaces:
Running
Running
File size: 2,233 Bytes
926928e |
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 |
from fastapi import APIRouter, Request, HTTPException
import requests
from service_config import ServiceConfig
router = APIRouter()
service_config = ServiceConfig()
service_config.load()
@router.post("/startup")
async def spark_startup(request: Request):
data = await request.json()
spark_url = service_config.spark_endpoint + "/startup"
try:
response = requests.post(spark_url, json=data, timeout=30)
response.raise_for_status()
return response.json()
except Exception as e:
raise HTTPException(status_code=500, detail=f"Spark startup error: {e}")
@router.get("/project_list")
def spark_project_list():
spark_url = service_config.spark_endpoint + "/project/list"
try:
response = requests.get(spark_url, timeout=30)
response.raise_for_status()
return response.json()
except Exception as e:
raise HTTPException(status_code=500, detail=f"Spark project list error: {e}")
@router.post("/enable")
async def spark_enable_project(request: Request):
data = await request.json()
spark_url = service_config.spark_endpoint + "/project/enable"
try:
response = requests.post(spark_url, json=data, timeout=30)
response.raise_for_status()
return response.json()
except Exception as e:
raise HTTPException(status_code=500, detail=f"Spark enable error: {e}")
@router.post("/disable")
async def spark_disable_project(request: Request):
data = await request.json()
spark_url = service_config.spark_endpoint + "/project/disable"
try:
response = requests.post(spark_url, json=data, timeout=30)
response.raise_for_status()
return response.json()
except Exception as e:
raise HTTPException(status_code=500, detail=f"Spark disable error: {e}")
@router.delete("/delete")
async def spark_delete_project(request: Request):
data = await request.json()
spark_url = service_config.spark_endpoint + "/project"
try:
response = requests.delete(spark_url, json=data, timeout=30)
response.raise_for_status()
return response.json()
except Exception as e:
raise HTTPException(status_code=500, detail=f"Spark delete error: {e}")
|