Skip to content
Snippets Groups Projects
Commit 16a32302 authored by Jan Müller's avatar Jan Müller
Browse files

Get SimulationNodes from database

parent 92c0a9ce
Branches
Tags
1 merge request!4Feature/add arbor support
Pipeline #163336 canceled
...@@ -8,13 +8,16 @@ from flask_cors import CORS ...@@ -8,13 +8,16 @@ from flask_cors import CORS
from access_node.models.nodes import nodes from access_node.models.nodes import nodes
import json import json
import time
import requests import requests
import psycopg2 import psycopg2
def ConnectToDatabase():
return psycopg2.connect(database="postgres", user=postgres_username,
password=postgres_password, host="database", port=str(port))
def SetupNestTables(postgres_username, postgres_password, port): def SetupNestTables(postgres_username, postgres_password, port):
con = psycopg2.connect(database="postgres", user=postgres_username, con = ConnectToDatabase()
password=postgres_password, host="database", port=str(port))
print("Database connection opened successfully!") print("Database connection opened successfully!")
cur = con.cursor() cur = con.cursor()
...@@ -26,7 +29,7 @@ def SetupNestTables(postgres_username, postgres_password, port): ...@@ -26,7 +29,7 @@ def SetupNestTables(postgres_username, postgres_password, port):
cur.execute('''CREATE TABLE SIMULATION_NODES ( cur.execute('''CREATE TABLE SIMULATION_NODES (
NODE_ID INT PRIMARY KEY NOT NULL UNIQUE, NODE_ID INT PRIMARY KEY NOT NULL UNIQUE,
ADDRESS VARCHAR(25), ADDRESS VARCHAR(50),
CURRENT_SIM_TIME FLOAT);''') CURRENT_SIM_TIME FLOAT);''')
cur.execute('''CREATE TABLE MULTIMETERS ( cur.execute('''CREATE TABLE MULTIMETERS (
...@@ -51,8 +54,7 @@ def SetupNestTables(postgres_username, postgres_password, port): ...@@ -51,8 +54,7 @@ def SetupNestTables(postgres_username, postgres_password, port):
print("Nest tables created successfully!\n") print("Nest tables created successfully!\n")
def SetupArborTables(postgres_username, postgres_password, port): def SetupArborTables(postgres_username, postgres_password, port):
con = psycopg2.connect(database="postgres", user=postgres_username, con = ConnectToDatabase()
password=postgres_password, host="database", port=str(port))
print("Database connection opened successfully!") print("Database connection opened successfully!")
cur = con.cursor() cur = con.cursor()
cur.execute("DROP TABLE IF EXISTS PROBES CASCADE") cur.execute("DROP TABLE IF EXISTS PROBES CASCADE")
...@@ -62,7 +64,7 @@ def SetupArborTables(postgres_username, postgres_password, port): ...@@ -62,7 +64,7 @@ def SetupArborTables(postgres_username, postgres_password, port):
cur.execute('''CREATE TABLE ARBOR_SIMULATION_NODES ( cur.execute('''CREATE TABLE ARBOR_SIMULATION_NODES (
NODE_ID INT PRIMARY KEY NOT NULL UNIQUE, NODE_ID INT PRIMARY KEY NOT NULL UNIQUE,
ADDRESS VARCHAR(25), ADDRESS VARCHAR(50),
CURRENT_SIM_TIME FLOAT);''') CURRENT_SIM_TIME FLOAT);''')
cur.execute('''CREATE TABLE CELLS ( cur.execute('''CREATE TABLE CELLS (
...@@ -102,19 +104,23 @@ def SetupArborTables(postgres_username, postgres_password, port): ...@@ -102,19 +104,23 @@ def SetupArborTables(postgres_username, postgres_password, port):
def main(): def main():
# Connect to the Database and initalize basic Table structure # Connect to the Database and initalize basic Table structure
SetupNestTables('postgres', 'docker', 5432) SetupNestTables('postgres', 'docker', 5432)
#SetupArborTables('postgres', 'docker', 5432)
# Wait for simulation nodes to post to database
time.sleep(10)
# get info node
with open('access_node//info_node.json', 'r') as f:
info = json.load(f)
nodes.info_node = info['address']
# get simulation nodes # get simulation nodes
node_type = 'nest_simulation' con = ConnectToDatabase()
nodes.nest_simulation_nodes = requests.get( cur = con.cursor()
nodes.info_node+'/nodes', params={"node_type": node_type}).json() # NEST
node_type = 'arbor_simulation' cur.execute("SELECT ADDRESS FROM SIMULATION_NODES")
nodes.arbor_simulation_nodes = requests.get( nodes.nest_simulation_nodes = [i[0] for i in cur.fetchall()]
nodes.info_node+'/nodes', params={"node_type": node_type}).json() # Arbor
#cur.execute("SELECT ADDRESS FROM SIMULATION_NODES")
#nodes.nest_simulation_nodes = [i[0] for i in cur.fetchall()]
con.close()
# run acces_node # run acces_node
app = connexion.App(__name__, specification_dir='./swagger/') app = connexion.App(__name__, specification_dir='./swagger/')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment