From 10aad7f6aec28329333f78f5aa08273e82b43583 Mon Sep 17 00:00:00 2001 From: yadhap Dahal Date: Thu, 5 Dec 2024 09:25:32 -0500 Subject: [PATCH 1/4] Used new cluster route to fetch cluster information when application loads. It was using the old method which was not returning metaData information --- Tombolo/client-reactjs/src/redux/actions/Application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tombolo/client-reactjs/src/redux/actions/Application.js b/Tombolo/client-reactjs/src/redux/actions/Application.js index 5e2da9c65..bb89e979d 100644 --- a/Tombolo/client-reactjs/src/redux/actions/Application.js +++ b/Tombolo/client-reactjs/src/redux/actions/Application.js @@ -63,7 +63,7 @@ function updateApplicationAddButtonTourShown(shown) { function getClusters() { return (dispatch) => { - fetch('/api/hpcc/read/getClusters', { headers: authHeader() }) + fetch('/api/cluster', { headers: authHeader() }) .then((response) => (response.ok ? response.json() : handleError(response))) .then((clusters) => { //if there are no clusters, set this to null for later checks From 1b457c404e0cddf9247fbf7363a63d6d84124e30 Mon Sep 17 00:00:00 2001 From: yadhap Dahal Date: Thu, 5 Dec 2024 09:58:14 -0500 Subject: [PATCH 2/4] Changed the backend get cluster routes so it does not send all metaData to client. the metaData could include cluster usage history which is unnecessary most of the time and just bugs down client. To get cluster usage history we have a dedicated route --- .../server/controllers/clusterController.js | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Tombolo/server/controllers/clusterController.js b/Tombolo/server/controllers/clusterController.js index 6ed64bd1a..fa155f65a 100644 --- a/Tombolo/server/controllers/clusterController.js +++ b/Tombolo/server/controllers/clusterController.js @@ -1,4 +1,5 @@ const { clusters } = require("../cluster-whitelist.js"); +const { Sequelize } = require("sequelize"); const { AccountService, TopologyService, @@ -304,7 +305,21 @@ const getClusters = async (req, res) => { try { // Get clusters ASC by name const clusters = await Cluster.findAll({ - attributes: { exclude: ["hash"] }, + attributes: { + exclude: ["hash", "metaData"], + include: [ + [ + Sequelize.literal(` + CASE + WHEN metaData IS NOT NULL AND JSON_EXTRACT(metaData, '$.reachabilityInfo') IS NOT NULL + THEN JSON_EXTRACT(metaData, '$.reachabilityInfo') + ELSE '{}' + END + `), + "reachabilityInfo", + ], + ], + }, order: [["name", "ASC"]], }); res.status(200).json({ success: true, data: clusters }); @@ -322,7 +337,10 @@ const getCluster = async (req, res) => { // Get one cluster by id const cluster = await Cluster.findOne({ where: { id: req.params.id }, - attributes: { exclude: ["hash"] }, + attributes: { + exclude: ["hash"], + + }, }); if (!cluster) throw new CustomError("Cluster not found", 404); res.status(200).json({ success: true, data: cluster }); From bb9e8d9c463aff14c368224ed21a81741289dfbc Mon Sep 17 00:00:00 2001 From: yadhap Dahal Date: Thu, 5 Dec 2024 10:02:12 -0500 Subject: [PATCH 3/4] removed unnecessary line breaks from clusterController find one cluster function --- Tombolo/server/controllers/clusterController.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Tombolo/server/controllers/clusterController.js b/Tombolo/server/controllers/clusterController.js index fa155f65a..f9364163f 100644 --- a/Tombolo/server/controllers/clusterController.js +++ b/Tombolo/server/controllers/clusterController.js @@ -337,10 +337,7 @@ const getCluster = async (req, res) => { // Get one cluster by id const cluster = await Cluster.findOne({ where: { id: req.params.id }, - attributes: { - exclude: ["hash"], - - }, + attributes: { exclude: ["hash"] }, }); if (!cluster) throw new CustomError("Cluster not found", 404); res.status(200).json({ success: true, data: cluster }); From 6113100b9e5d20aa352cc4e60ab637aa2eea2176 Mon Sep 17 00:00:00 2001 From: yadhap Dahal Date: Thu, 5 Dec 2024 10:46:59 -0500 Subject: [PATCH 4/4] Send cluster reachability information in JSON object and not in JSON string --- Tombolo/server/controllers/clusterController.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tombolo/server/controllers/clusterController.js b/Tombolo/server/controllers/clusterController.js index f9364163f..5f87bdbc0 100644 --- a/Tombolo/server/controllers/clusterController.js +++ b/Tombolo/server/controllers/clusterController.js @@ -322,7 +322,14 @@ const getClusters = async (req, res) => { }, order: [["name", "ASC"]], }); - res.status(200).json({ success: true, data: clusters }); + // Parse the JSON string into a JavaScript object + const parsedClusters = clusters.map((cluster) => { + const clusterData = cluster.get({ plain: true }); + clusterData.reachabilityInfo = JSON.parse(clusterData.reachabilityInfo); + return clusterData; + }); + + res.status(200).json({ success: true, data: parsedClusters }); } catch (err) { logger.error(`Get clusters: ${err.message}`); res