diff --git a/.env b/.env new file mode 100644 index 0000000..e4a7fd9 --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +VITE_API_URL=http://localhost:3000/api/v1 + +NODE_ENV=development + +#Database Configuration +DB_NAME=ve_router_db diff --git a/docker-compose.yml b/docker-compose.yml index 07f9cab..ac8588a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,35 +4,39 @@ services: frontend: build: context: ./router-dashboard - dockerfile: Dockerfile + dockerfile: dockerfile ports: - "5173:5173" environment: - - VITE_API_URL=http://localhost:3001/api/v1 + - VITE_API_URL=${VITE_API_URL} + restart: always depends_on: - - backend - volumes: - - ./router-dashboard:/app - - /app/node_modules - + backend: + condition: service_healthy + backend: build: context: ./ve-router-backend - dockerfile: Dockerfile + dockerfile: dockerfile ports: - - "3001:3000" + - "3000:3000" environment: - - NODE_ENV=development + - NODE_ENV=${NODE_ENV} - DB_HOST=host.docker.internal - - DB_PORT=3307 + - DB_PORT=3306 - DB_USER=ve_router_user - DB_PASSWORD=ve_router_password - - DB_NAME=ve_router_db + - DB_NAME=${DB_NAME} + restart: always depends_on: - - mysql - volumes: - - ./ve-router-backend:/app - - /app/node_modules + mysql: + condition: service_healthy + healthcheck: + test: ["CMD", "nc", "-z", "localhost", "3000"] # Netcat check to see if port 3000 is open + interval: 30s # Check every 30 seconds + retries: 3 # Retry 3 times before marking unhealthy + start_period: 30s # Wait 30 seconds before starting health checks + timeout: 10s # Wait for 10 seconds for each health check to respond mysql: image: mysql:8.0 @@ -44,11 +48,11 @@ services: volumes: - mysql_data:/var/lib/mysql # Correct paths for init scripts - - ./router-dashboard/sql/init.sql:/docker-entrypoint-initdb.d/01-init.sql - - ./router-dashboard/sql/seed_data.sql:/docker-entrypoint-initdb.d/02-seed_data.sql + - ./sql:/docker-entrypoint-initdb.d ports: - - "3307:3306" + - "3306:3306" command: --default-authentication-plugin=mysql_native_password + restart: always healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "ve_router_user", "-pve_router_password"] interval: 10s @@ -57,4 +61,4 @@ services: start_period: 30s volumes: - mysql_data: + mysql_data: \ No newline at end of file diff --git a/router-dashboard/.env b/router-dashboard/.env index 3308736..983a024 100644 --- a/router-dashboard/.env +++ b/router-dashboard/.env @@ -1,2 +1,2 @@ -VITE_API_URL=http://localhost:3001/api/v1 +VITE_API_URL=http://localhost:3000/api/v1 VITE_NODE_ENV=development \ No newline at end of file diff --git a/router-dashboard/dockerfile b/router-dashboard/dockerfile index 4b547bf..0aa269c 100644 --- a/router-dashboard/dockerfile +++ b/router-dashboard/dockerfile @@ -8,7 +8,7 @@ RUN npm install COPY . . -ENV VITE_API_URL=http://localhost:3001/api/v1 +ENV VITE_API_URL=http://localhost:3000/api/v1 EXPOSE 5173 diff --git a/router-dashboard/src/config/env.ts b/router-dashboard/src/config/env.ts index 62d0c27..7d59074 100644 --- a/router-dashboard/src/config/env.ts +++ b/router-dashboard/src/config/env.ts @@ -5,7 +5,7 @@ interface Config { } const config: Config = { - apiUrl: import.meta.env.VITE_API_URL || 'http://localhost:3001/api/v1', + apiUrl: import.meta.env.VITE_API_URL || 'http://localhost:3000/api/v1', environment: import.meta.env.VITE_NODE_ENV || 'development', }; diff --git a/router-dashboard/src/services/api.service.ts b/router-dashboard/src/services/api.service.ts index 1ca95e9..65d77b6 100644 --- a/router-dashboard/src/services/api.service.ts +++ b/router-dashboard/src/services/api.service.ts @@ -1,7 +1,7 @@ // router-dashboard/src/services/api.service.ts import { RouterData, FilterType, BackendRouter } from '../types'; -const API_BASE_URL = 'http://localhost:3001/api/v1'; +const API_BASE_URL = 'http://localhost:3000/api/v1'; // Default request options for all API calls const DEFAULT_OPTIONS = { diff --git a/sql/init.sql b/sql/01-init.sql similarity index 99% rename from sql/init.sql rename to sql/01-init.sql index 649e9c8..dcbd0cf 100644 --- a/sql/init.sql +++ b/sql/01-init.sql @@ -118,7 +118,7 @@ CREATE TABLE IF NOT EXISTS status_type ( category_id VARCHAR(50), name VARCHAR(100), code VARCHAR(100), - description VARCHAR(20), + description VARCHAR(150), severity INT ); diff --git a/sql/02-seed_data.sql b/sql/02-seed_data.sql new file mode 100644 index 0000000..1c940cf --- /dev/null +++ b/sql/02-seed_data.sql @@ -0,0 +1,121 @@ +DELIMITER // + +CREATE PROCEDURE seed_complete_router_system() +BEGIN + DECLARE done INT DEFAULT 0; + DECLARE table_name VARCHAR(64); + DECLARE table_cursor CURSOR FOR + SELECT table_name + FROM information_schema.tables + WHERE table_schema = DATABASE() + AND table_name IN ( + 'auth_log', 'user_sessions', 'user_router_access', 'users', + 'container_status_history', 'router_status_history', + 'container_status', 'vm_details', 'dicom_study_overview', + 'system_status', 'router_settings_history', 'router_settings', + 'routers', 'status_type', 'status_category' + ); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + -- Disable foreign key checks + SET FOREIGN_KEY_CHECKS=0; + + -- Truncate all tables dynamically + OPEN table_cursor; + truncate_loop: LOOP + FETCH table_cursor INTO table_name; + IF done THEN + LEAVE truncate_loop; + END IF; + + SET @query = CONCAT('TRUNCATE TABLE ', table_name); + PREPARE stmt FROM @query; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + END LOOP; + CLOSE table_cursor; + + -- Re-enable foreign key checks + SET FOREIGN_KEY_CHECKS=1; + + -- Insert Status Categories + INSERT INTO status_category (name, description) + VALUES + ('Network', 'Network related statuses'), + ('Disk', 'Disk related statuses'), + ('VPN', 'VPN connection statuses'), + ('License', 'License statuses'), + ('Container', 'Container related statuses') + ON DUPLICATE KEY UPDATE id = id; + + -- Insert Status Types + INSERT INTO status_type (category_id, name, code, description, severity) + VALUES + (1, 'Online', 'NET_ONLINE', 'System is online', 1), + (1, 'Offline', 'NET_OFFLINE', 'System is offline', 5), + (2, 'Normal', 'DISK_NORMAL', 'Disk usage is normal', 1), + (2, 'Warning', 'DISK_WARNING', 'Disk usage is high', 3), + (2, 'Critical', 'DISK_CRITICAL', 'Disk usage is critical', 5), + (3, 'Connected', 'VPN_CONNECTED', 'VPN is connected', 1), + (3, 'Disconnected', 'VPN_DISCONNECTED', 'VPN is disconnected', 5), + (5, 'Running', 'CONTAINER_RUNNING', 'Container is running', 1), + (5, 'Stopped', 'CONTAINER_STOPPED', 'Container is stopped', 5) + ON DUPLICATE KEY UPDATE id = id; + + -- Insert Routers + INSERT INTO routers (router_id, facility, router_alias, last_seen, vpn_status_code, disk_status_code, license_status, free_disk, total_disk, disk_usage) + VALUES + ('RTR001', 'Main Hospital', 'MAIN_RAD', NOW(), 'VPN_CONNECTED', 'DISK_NORMAL', 'active', 500000000000, 1000000000000, 50.00), + ('RTR002', 'Emergency Center', 'ER_RAD', NOW(), 'VPN_CONNECTED', 'DISK_WARNING', 'active', 400000000000, 1000000000000, 60.00), + ('RTR003', 'Imaging Center', 'IMG_CENTER', NOW(), 'VPN_CONNECTED', 'DISK_NORMAL', 'active', 600000000000, 1000000000000, 40.00) + ON DUPLICATE KEY UPDATE id = id; + + -- Store Router IDs + SET @router1_id = (SELECT id FROM routers WHERE router_id = 'RTR001'); + SET @router2_id = (SELECT id FROM routers WHERE router_id = 'RTR002'); + SET @router3_id = (SELECT id FROM routers WHERE router_id = 'RTR003'); + + -- Insert System Status + INSERT INTO system_status (router_id) + VALUES + (@router1_id), + (@router2_id), + (@router3_id) + ON DUPLICATE KEY UPDATE id = id; + + -- Insert Container Status + INSERT INTO container_status (system_status_id, container_number, status_code) + VALUES + (1, 1, 'CONTAINER_RUNNING'), + (1, 2, 'CONTAINER_RUNNING'), + (2, 1, 'CONTAINER_RUNNING'), + (2, 2, 'CONTAINER_STOPPED'), + (3, 1, 'CONTAINER_RUNNING') + ON DUPLICATE KEY UPDATE id = id; + + -- Insert VM Details + INSERT INTO vm_details (router_id, vm_number, status_code) + VALUES + (@router1_id, 1, 'NET_ONLINE'), + (@router2_id, 1, 'NET_ONLINE'), + (@router3_id, 1, 'NET_ONLINE') + ON DUPLICATE KEY UPDATE id = id; + + -- Insert DICOM Study Overview + INSERT INTO dicom_study_overview ( + router_id, study_instance_uid, patient_id, patient_name, + accession_number, study_date, modality, study_description, + series_instance_uid, procedure_code, referring_physician_name + ) + VALUES + (@router1_id, '1.2.840.113619.2.55.3.283116435.276.1543707218.134', 'P1', 'John Doe', 'ACC1234', '2024-03-15', 'CT', 'Chest CT', '1.2.840.113619.2.55.3.283116435.276.1543707219.135', 'CT001', 'Dr. Smith'), + (@router2_id, '1.2.840.113619.2.55.3.283116435.276.1543707218.136', 'P2', 'Jane Doe', 'ACC1235', '2024-03-15', 'MR', 'Brain MRI', '1.2.840.113619.2.55.3.283116435.276.1543707219.137', 'MR001', 'Dr. Johnson') + ON DUPLICATE KEY UPDATE id = id; + +END // + +DELIMITER ; + +-- Automatically call the procedure after creation +CALL seed_complete_router_system(); \ No newline at end of file diff --git a/sql/seed_data.sql b/sql/seed_data.sql deleted file mode 100644 index ccff93b..0000000 --- a/sql/seed_data.sql +++ /dev/null @@ -1,267 +0,0 @@ -DELIMITER // - -CREATE PROCEDURE seed_complete_router_system() -BEGIN - -- Disable foreign key checks and start fresh - SET FOREIGN_KEY_CHECKS=0; - - -- Conditionally clear existing data, only if the table exists - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'auth_log') THEN - TRUNCATE TABLE auth_log; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'user_sessions') THEN - TRUNCATE TABLE user_sessions; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'user_router_access') THEN - TRUNCATE TABLE user_router_access; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'users') THEN - TRUNCATE TABLE users; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'container_status_history') THEN - TRUNCATE TABLE container_status_history; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'router_status_history') THEN - TRUNCATE TABLE router_status_history; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'container_status') THEN - TRUNCATE TABLE container_status; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'vm_details') THEN - TRUNCATE TABLE vm_details; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'dicom_study_overview') THEN - TRUNCATE TABLE dicom_study_overview; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'system_status') THEN - TRUNCATE TABLE system_status; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'router_settings_history') THEN - TRUNCATE TABLE router_settings_history; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'router_settings') THEN - TRUNCATE TABLE router_settings; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'routers') THEN - TRUNCATE TABLE routers; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'status_type') THEN - TRUNCATE TABLE status_type; - END IF; - - IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'status_category') THEN - TRUNCATE TABLE status_category; - END IF; - - -- Re-enable foreign key checks - SET FOREIGN_KEY_CHECKS=1; - - -- Insert status categories - INSERT INTO status_category (name, description) - VALUES - ('Network', 'Network related statuses'), - ('Disk', 'Disk related statuses'), - ('VPN', 'VPN connection statuses'), - ('License', 'License statuses'), - ('Container', 'Container related statuses') - ON DUPLICATE KEY UPDATE id = id; - - -- Insert status types - INSERT INTO status_type (category_id, name, code, description, severity) - VALUES - (1, 'Online', 'NET_ONLINE', 'System is online', 1), - (1, 'Offline', 'NET_OFFLINE', 'System is offline', 5), - (2, 'Normal', 'DISK_NORMAL', 'Disk usage is normal', 1), - (2, 'Warning', 'DISK_WARNING', 'Disk usage is high', 3), - (2, 'Critical', 'DISK_CRITICAL', 'Disk usage is critical', 5), - (3, 'Connected', 'VPN_CONNECTED', 'VPN is connected', 1), - (3, 'Disconnected', 'VPN_DISCONNECTED', 'VPN is disconnected', 5), - (5, 'Running', 'CONTAINER_RUNNING', 'Container is running', 1), - (5, 'Stopped', 'CONTAINER_STOPPED', 'Container is stopped', 5) - ON DUPLICATE KEY UPDATE id = id; - - -- Insert routers - INSERT INTO routers (router_id, facility, router_alias, last_seen, vpn_status_code, disk_status_code, license_status, free_disk, total_disk, disk_usage) - VALUES - ('RTR001', 'Main Hospital', 'MAIN_RAD', NOW(), 'VPN_CONNECTED', 'DISK_NORMAL', 'active', 500000000000, 1000000000000, 50.00), - ('RTR002', 'Emergency Center', 'ER_RAD', NOW(), 'VPN_CONNECTED', 'DISK_WARNING', 'active', 400000000000, 1000000000000, 60.00), - ('RTR003', 'Imaging Center', 'IMG_CENTER', NOW(), 'VPN_CONNECTED', 'DISK_NORMAL', 'active', 600000000000, 1000000000000, 40.00) - ON DUPLICATE KEY UPDATE id = id; - - -- Store router IDs for later use - SET @router1_id = (SELECT id FROM routers WHERE router_id = 'RTR001'); - SET @router2_id = (SELECT id FROM routers WHERE router_id = 'RTR002'); - SET @router3_id = (SELECT id FROM routers WHERE router_id = 'RTR003'); - - -- Insert system status - INSERT INTO system_status (router_id) - VALUES - (@router1_id), - (@router2_id), - (@router3_id) - ON DUPLICATE KEY UPDATE id = id; - - -- Insert container status - INSERT INTO container_status (system_status_id, container_number, status_code) - VALUES - (1, 1, 'CONTAINER_RUNNING'), - (1, 2, 'CONTAINER_RUNNING'), - (2, 1, 'CONTAINER_RUNNING'), - (2, 2, 'CONTAINER_STOPPED'), - (3, 1, 'CONTAINER_RUNNING') - ON DUPLICATE KEY UPDATE id = id; - - -- Insert VM details - INSERT INTO vm_details (router_id, vm_number, status_code) - VALUES - (@router1_id, 1, 'NET_ONLINE'), - (@router2_id, 1, 'NET_ONLINE'), - (@router3_id, 1, 'NET_ONLINE') - ON DUPLICATE KEY UPDATE id = id; - - -- Insert DICOM studies - INSERT INTO dicom_study_overview ( - router_id, - study_instance_uid, - patient_id, - patient_name, - accession_number, - study_date, - modality, - study_description, - series_instance_uid, - procedure_code, - referring_physician_name - ) - VALUES - (@router1_id, '1.2.840.113619.2.55.3.283116435.276.1543707218.134', 'P1', 'John Doe', 'ACC1234', '2024-03-15', 'CT', 'Chest CT', '1.2.840.113619.2.55.3.283116435.276.1543707219.135', 'CT001', 'Dr. Smith'), - (@router2_id, '1.2.840.113619.2.55.3.283116435.276.1543707218.136', 'P2', 'Jane Doe', 'ACC1235', '2024-03-15', 'MR', 'Brain MRI', '1.2.840.113619.2.55.3.283116435.276.1543707219.137', 'MR001', 'Dr. Johnson') - ON DUPLICATE KEY UPDATE id = id; - - -- Insert router settings for each router (calls to upsert_router_settings are disabled) - -- Main Hospital Router - -- CALL upsert_router_settings( - -- @router1_id, - -- 'client', - -- '{ - -- "dicom": { - -- "local": { - -- "aet": "MAIN_RAD", - -- "port": 104, - -- "file_directory": "/dicom_images", - -- "wait_time": 2, - -- "receiver_wait_time": 5000 - -- }, - -- "association": { - -- "acse_timeout": 5, - -- "dimse_timeout": 1000, - -- "network_timeout": 1000, - -- "retry": { - -- "attempts": 3, - -- "interval": 10 - -- } - -- } - -- }, - -- "rabbitmq": { - -- "local": { - -- "hostname": "router-rabbitmq", - -- "port": 5672, - -- "credentials": { - -- "username": "vitalengine", - -- "password": "vitalengine" - -- }, - -- "settings": { - -- "durable": true, - -- "auto_delete": false, - -- "exchange_type": "direct", - -- "heartbeat": 50 - -- } - -- } - -- }, - -- "scp_connections": { - -- "pacs_nodes": [ - -- { - -- "host": "pacsmain.example.com", - -- "port": 104 - -- }, - -- { - -- "host": "pacsbackup.example.com", - -- "port": 104 - -- } - -- ] - -- } - -- }', - -- 'system', - -- 'Initial client configuration for Main Hospital' - -- ); - - -- Emergency Center Router - -- CALL upsert_router_settings( - -- @router2_id, - -- 'client', - -- '{ - -- "dicom": { - -- "local": { - -- "aet": "ER_RAD", - -- "port": 104, - -- "file_directory": "/dicom_images", - -- "wait_time": 2, - -- "receiver_wait_time": 5000 - -- }, - -- "association": { - -- "acse_timeout": 5, - -- "dimse_timeout": 1000, - -- "network_timeout": 1000, - -- "retry": { - -- "attempts": 3, - -- "interval": 10 - -- } - -- } - -- }, - -- "rabbitmq": { - -- "local": { - -- "hostname": "router-rabbitmq", - -- "port": 5672, - -- "credentials": { - -- "username": "vitalengine", - -- "password": "vitalengine" - -- }, - -- "settings": { - -- "durable": true, - -- "auto_delete": false, - -- "exchange_type": "direct", - -- "heartbeat": 50 - -- } - -- } - -- }, - -- "scp_connections": { - -- "pacs_nodes": [ - -- { - -- "host": "pacsemergency.example.com", - -- "port": 104 - -- } - -- ] - -- } - -- }', - -- 'system', - -- 'Initial client configuration for Emergency Center' - -- ); - - -- Insert settings for other routers as needed... - -END // - -DELIMITER ; diff --git a/ve-router-backend/.env b/ve-router-backend/.env index bf9c3fc..913657a 100644 --- a/ve-router-backend/.env +++ b/ve-router-backend/.env @@ -7,7 +7,7 @@ CORS_ORIGIN=http://localhost:5173,http://localhost:3000 # Database Configuration DB_HOST=localhost -DB_PORT=3307 +DB_PORT=3306 DB_USER=root DB_PASSWORD=rootpassword DB_NAME=ve_router_db