feat:
--Cluster management table api added to create cluster
This commit is contained in:
1 parent
d0e1d31093
commit
448771cd88
3 files changed
+49
-4
No files matched your search
@@ -176,6 +176,12 @@ SELECT spock.sub_create(
|
||||
provider_dsn := 'host=172.16.10.123 port=5444 dbname=postgres user=postgres password=postgres'
|
||||
);
|
||||
|
||||
|================|
|
||||
|DELETE Node LINK|
|
||||
|================|
|
||||
SELECT spock.sub_drop('node1_from_node2');
|
||||
|
||||
|
||||
|======|
|
||||
|RESULT|
|
||||
|======|
|
||||
|
||||
@@ -12,7 +12,7 @@ from database import Base, engine,SessionLocal,get_db
|
||||
from uuid import UUID
|
||||
# import models
|
||||
from sqlalchemy.orm import Session
|
||||
from models import NodeInterface
|
||||
from models import NodeInterface, Cluster
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
@@ -714,6 +714,7 @@ def create_cluster(data: ClusterRequest,db: Session = Depends(get_db),token_data
|
||||
print("Cluster Name:", data.cluster_name)
|
||||
print("Links:", data.links)
|
||||
results = []
|
||||
node_names = set()
|
||||
for from_node, to_node in data.links:
|
||||
print(f"{from_node} -> {to_node}")
|
||||
#=================
|
||||
@@ -731,30 +732,56 @@ def create_cluster(data: ClusterRequest,db: Session = Depends(get_db),token_data
|
||||
f"Successfully linked {from_node} -> {to_node}"
|
||||
)
|
||||
|
||||
node_names.add(from_node)
|
||||
node_names.add(to_node)
|
||||
|
||||
results.append({
|
||||
"from_node": from_node,
|
||||
"to_node": to_node,
|
||||
"status": "success"
|
||||
})
|
||||
|
||||
cluster = Cluster(
|
||||
cluster_name=data.cluster_name
|
||||
)
|
||||
|
||||
db.add(cluster)
|
||||
db.flush()
|
||||
|
||||
nodes = (
|
||||
db.query(NodeInterface)
|
||||
.filter(NodeInterface.if_name.in_(node_names))
|
||||
.all()
|
||||
)
|
||||
|
||||
if len(nodes) != len(node_names):
|
||||
found_nodes = {node.if_name for node in nodes}
|
||||
missing_nodes = node_names - found_nodes
|
||||
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"Nodes not found: {list(missing_nodes)}"
|
||||
)
|
||||
|
||||
for node in nodes:
|
||||
node.cluster = cluster
|
||||
db.commit()
|
||||
|
||||
return {
|
||||
"cluster_name": data.cluster_name,
|
||||
"links": data.links,
|
||||
"cluster_name": data.cluster_name,
|
||||
"links": results
|
||||
}
|
||||
except HTTPException:
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
|
||||
except Exception as e:
|
||||
|
||||
db.rollback()
|
||||
print("Cluster creation failed:", str(e))
|
||||
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail="Cluster creation failed"
|
||||
)
|
||||
|
||||
@@ -116,3 +116,15 @@ def add_cluster_id_column():
|
||||
"""))
|
||||
|
||||
# add_cluster_id_column()
|
||||
|
||||
|
||||
# ALTER TABLE "fastAPI_node_interface"
|
||||
# DROP CONSTRAINT fk_node_interface_cluster;
|
||||
|
||||
# ALTER TABLE "fastAPI_node_interface"
|
||||
# ADD CONSTRAINT fk_node_interface_cluster
|
||||
# FOREIGN KEY (cluster_id)
|
||||
# REFERENCES "fastAPI_cluster"(uuid)
|
||||
# ON DELETE SET NULL;
|
||||
|
||||
#\d "fastAPI_node_interface"
|
||||
Reference in new issue
Block a user