Spaces:
Building
Building
Delete spark_controller.py
Browse files- spark_controller.py +0 -48
spark_controller.py
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
from fastapi import APIRouter, Depends, HTTPException
|
2 |
-
from config_provider import get_config, ServiceConfig
|
3 |
-
from utils import save_service_config, log
|
4 |
-
import requests
|
5 |
-
|
6 |
-
router = APIRouter()
|
7 |
-
|
8 |
-
@router.get("/spark/projects")
|
9 |
-
def get_spark_projects(config: ServiceConfig = Depends(get_config)):
|
10 |
-
try:
|
11 |
-
spark_url = config.spark_endpoint + "/projects"
|
12 |
-
response = requests.get(spark_url, timeout=5)
|
13 |
-
response.raise_for_status()
|
14 |
-
projects = response.json()
|
15 |
-
return { "projects": projects }
|
16 |
-
except Exception as e:
|
17 |
-
log(f"⚠️ Spark service unreachable: {str(e)}")
|
18 |
-
return { "error": True, "projects": [] }
|
19 |
-
|
20 |
-
@router.post("/spark/enable")
|
21 |
-
def enable_project(project_name: str, config: ServiceConfig = Depends(get_config)):
|
22 |
-
project = next((p for p in config.data['projects'] if p['name'] == project_name), None)
|
23 |
-
if not project:
|
24 |
-
raise HTTPException(status_code=404, detail="Project not found")
|
25 |
-
project['enabled'] = True
|
26 |
-
save_service_config(config)
|
27 |
-
log(f"✅ Project '{project_name}' enabled")
|
28 |
-
return { "status": "enabled" }
|
29 |
-
|
30 |
-
@router.post("/spark/disable")
|
31 |
-
def disable_project(project_name: str, config: ServiceConfig = Depends(get_config)):
|
32 |
-
project = next((p for p in config.data['projects'] if p['name'] == project_name), None)
|
33 |
-
if not project:
|
34 |
-
raise HTTPException(status_code=404, detail="Project not found")
|
35 |
-
project['enabled'] = False
|
36 |
-
save_service_config(config)
|
37 |
-
log(f"✅ Project '{project_name}' disabled")
|
38 |
-
return { "status": "disabled" }
|
39 |
-
|
40 |
-
@router.post("/spark/delete")
|
41 |
-
def delete_project_spark(project_name: str, config: ServiceConfig = Depends(get_config)):
|
42 |
-
project = next((p for p in config.data['projects'] if p['name'] == project_name), None)
|
43 |
-
if not project:
|
44 |
-
raise HTTPException(status_code=404, detail="Project not found")
|
45 |
-
config.data['projects'].remove(project)
|
46 |
-
save_service_config(config)
|
47 |
-
log(f"🗑️ Project '{project_name}' deleted from Spark")
|
48 |
-
return { "status": "deleted" }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|