Skip to content

Commit

Permalink
Node List Refresh 추가 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
seungh0 authored Jul 4, 2024
1 parent 1eac848 commit 7dd1aa2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const KeyspaceHome = () => {
console.log("res ", response);
setDescribe(response.data.describe)
}).catch((error) => {
//TODO : error catch
console.error(error)
}).finally(() => {
setDetailLoading(false)
});
Expand All @@ -56,8 +56,6 @@ const KeyspaceHome = () => {
setTableCursor(response.data.result.cursor.next)
}
}).catch((error) => {
console.log(error)
//TODO : error catch
axiosCatch(error)
}).finally(() => {
setTableLoading(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {useEffect, useState} from "react";
import axios from "axios";
import {DateUtils} from "../../../utils/timeUtils";
import Spinner from "../../../components/spinner";
import {axiosCatch} from "../../../utils/axiosUtils";

const NodesHome = () => {

Expand All @@ -16,32 +17,15 @@ const NodesHome = () => {
useEffect(() => {
//show component
setNodeList([])

setNodeLoading(true)
axios({
method: "GET",
url: `/api/cassandra/cluster/${routeParams.clusterId}/node`,
}).then((response) => {
console.log("res ", response);
const nodes = response.data.result.items
setNodeList(nodes)
setTotalNodeSize(nodes.length)
setAvailableNodeSize(nodes.filter(node => node.nodeState === 'UP').length)
}).catch((error) => {
console.log(error)
//TODO : error catch
}).finally(() => {
setNodeLoading(false)
});

getNodes(routeParams.clusterId)
return () => {
//hide component

};
}, [routeParams.clusterId, routeParams.keyspaceName]);

const nodesByDcAndRack = nodeList.reduce((acc, node) => {
const { datacenter, rack } = node;
const {datacenter, rack} = node;
if (!acc[datacenter]) {
acc[datacenter] = {};
}
Expand All @@ -52,11 +36,34 @@ const NodesHome = () => {
return acc;
}, {});

function getNodes(clusterId) {
setNodeLoading(true)

axios({
method: "GET",
url: `/api/cassandra/cluster/${clusterId}/node`,
}).then((response) => {
const nodes = response.data.result.items
setNodeList(nodes)
setTotalNodeSize(nodes.length)
setAvailableNodeSize(nodes.filter(node => node.nodeState === 'UP').length)
}).catch((error) => {
axiosCatch(error)
}).finally(() => {
setNodeLoading(false)
});
}

return (
<>
<div
className="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h2 className="h2">Node List</h2>
<div className="btn-group me-2">
<button type="button" className="btn btn-sm btn-outline-secondary"
onClick={() => getNodes(routeParams.clusterId)}>Refresh
</button>
</div>
</div>

<div
Expand All @@ -75,23 +82,20 @@ const NodesHome = () => {
<table className="table table-striped table-sm">
<thead>
<tr>
<th className="text-center" scope="col">ID</th>
<th className="text-center" scope="col">Node ID</th>
<th className="text-center" scope="col">Node State</th>
<th className="text-center" scope="col">Host IP</th>
<th className="text-center" scope="col">DC</th>
<th className="text-center" scope="col">Rack</th>
<th className="text-center" scope="col">Host</th>
<th className="text-center" scope="col">Cassandra Version</th>
<th className="text-center" scope="col">Up-Time</th>
<th className="text-center" scope="col">UpTime</th>
</tr>
</thead>
<tbody>
{nodesByDcAndRack[datacenter][rack].map((node) => (
<tr key={node.nodeId} className={node.nodeState !== 'UP' ? 'table-danger' : ''}>
<tr key={node.nodeId}
className={node.nodeState !== 'UP' ? 'table-danger' : ''}>
<td className="text-center">{node.nodeId}</td>
<td className="text-center">{node.nodeState}</td>
<td className="text-center">{node.hostIp}</td>
<td className="text-center">{node.datacenter}</td>
<td className="text-center">{node.rack}</td>
<td className="text-center">{node.hostIp.replace('/', '')}</td>
<td className="text-center">{node.cassandraVersion}</td>
<td className="text-center">{DateUtils.yyyyMMDDHHmmss(node.upSinceMillis)}</td>
</tr>
Expand Down

0 comments on commit 7dd1aa2

Please sign in to comment.