feat:
--ADDED create cluster api
This commit is contained in:
1 parent
96be1fc94e
commit
d0e1d31093
3 files changed
+146
-7
No files matched your search
@@ -64,6 +64,12 @@ class NodeLinkRequest(BaseModel):
|
||||
from_node: str
|
||||
to_node: str
|
||||
|
||||
|
||||
class ClusterRequest(BaseModel):
|
||||
cluster_name: str
|
||||
links: list[tuple[str, str]]
|
||||
|
||||
|
||||
#POST /register-node
|
||||
# {
|
||||
# "node_name": "node2",
|
||||
@@ -601,8 +607,8 @@ def delete_node_interface(
|
||||
conn.close()
|
||||
|
||||
|
||||
@app.post("/spock/link-nodes-abstract")
|
||||
def link_nodes_abstract(data: NodeLinkRequest,db: Session = Depends(get_db),token_data: dict = Depends(verify_token)):
|
||||
# @app.post("/spock/link-nodes-abstract")
|
||||
def link_nodes_abstract(data: NodeLinkRequest,db: Session):
|
||||
|
||||
|
||||
try:
|
||||
@@ -663,7 +669,7 @@ def link_nodes_abstract(data: NodeLinkRequest,db: Session = Depends(get_db),toke
|
||||
|
||||
# Call internal function
|
||||
result = link_nodes(link_data)
|
||||
|
||||
print("Linking Result:", result["status"])
|
||||
#==============================================================================
|
||||
|
||||
|
||||
@@ -689,4 +695,66 @@ def link_nodes_abstract(data: NodeLinkRequest,db: Session = Depends(get_db),toke
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail="Internal server error"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
@app.post("/spock/create_cluster")
|
||||
# INPUT EXAMPLE
|
||||
# {
|
||||
# "cluster_name": "cluster1",
|
||||
# "links": [
|
||||
# ["node1", "node2"],
|
||||
# ["node2", "node1"]
|
||||
# ]
|
||||
# }
|
||||
def create_cluster(data: ClusterRequest,db: Session = Depends(get_db),token_data: dict = Depends(verify_token)):
|
||||
try:
|
||||
print("Cluster Name:", data.cluster_name)
|
||||
print("Links:", data.links)
|
||||
results = []
|
||||
for from_node, to_node in data.links:
|
||||
print(f"{from_node} -> {to_node}")
|
||||
#=================
|
||||
link_request = NodeLinkRequest(
|
||||
from_node=from_node,
|
||||
to_node=to_node
|
||||
)
|
||||
|
||||
result = link_nodes_abstract(
|
||||
link_request,
|
||||
db
|
||||
)
|
||||
|
||||
print(
|
||||
f"Successfully linked {from_node} -> {to_node}"
|
||||
)
|
||||
|
||||
results.append({
|
||||
"from_node": from_node,
|
||||
"to_node": to_node,
|
||||
"status": "success"
|
||||
})
|
||||
|
||||
|
||||
|
||||
return {
|
||||
"cluster_name": data.cluster_name,
|
||||
"links": data.links,
|
||||
"cluster_name": data.cluster_name,
|
||||
"links": results
|
||||
}
|
||||
except HTTPException:
|
||||
raise
|
||||
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Cluster creation failed:", str(e))
|
||||
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail="Cluster creation failed"
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user