Skip to content

Commit

Permalink
Table 및 기타 수정 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
akageun authored Jul 4, 2024
1 parent 7dd1aa2 commit 7118f71
Show file tree
Hide file tree
Showing 14 changed files with 283 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public static class ClusterTableGetArgs {

private String keyspace;
private String table;
private boolean withTableDescribe = false;

@Builder
private ClusterTableGetArgs(String keyspace, String table) {
private ClusterTableGetArgs(String keyspace, String table, boolean withTableDescribe) {
this.keyspace = keyspace;
this.table = table;
this.withTableDescribe = withTableDescribe;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata;
import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
import kr.hakdang.cadio.core.domain.cluster.BaseClusterCommander;
import kr.hakdang.cadio.core.domain.cluster.keyspace.CassandraSystemKeyspace;
Expand All @@ -11,6 +13,7 @@
import kr.hakdang.cadio.core.domain.cluster.keyspace.table.column.Column;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -26,21 +29,35 @@
public class ClusterTableGetCommander extends BaseClusterCommander {

public ClusterTableGetResult getTable(CqlSession session, ClusterTableGetArgs args) {
int limit = 1;
SimpleStatement statement = QueryBuilder
.selectFrom(CassandraSystemKeyspace.SYSTEM_SCHEMA.getKeyspaceName(), CassandraSystemTable.SYSTEM_SCHEMA_TABLES.getTableName())
.all()
.whereColumn(CassandraSystemTablesColumn.TABLES_KEYSPACE_NAME.getColumnName()).isEqualTo(bindMarker())
.whereColumn(CassandraSystemTablesColumn.TABLES_TABLE_NAME.getColumnName()).isEqualTo(bindMarker())
.limit(1)
.build(args.getKeyspace(), args.getTable());
.limit(limit)
.build(args.getKeyspace(), args.getTable())
.setPageSize(limit)
.setTimeout(Duration.ofSeconds(3));

Row tableRow = session.execute(statement).one();
if (tableRow == null) {
throw new IllegalArgumentException(String.format("not found table(%s) in keyspace(%s)", args.getTable(), args.getKeyspace()));
}

String tableDescribe = "";
if (args.isWithTableDescribe()) {
TableMetadata tableMetadata = session.getMetadata().getKeyspace(args.getKeyspace())
.orElseThrow(() -> new RuntimeException("not found keyspace"))
.getTable(args.getTable())
.orElseThrow(() -> new RuntimeException("not found table"));

tableDescribe = tableMetadata.describe(true);
}

return ClusterTableGetResult.builder()
.table(ClusterTable.from(tableRow))
.tableDescribe(tableDescribe)
.columns(getColumnsInTable(session, args))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
public class ClusterTableGetResult {

private ClusterTable table;
private String tableDescribe;
private List<Column> columns;

@Builder
private ClusterTableGetResult(ClusterTable table, List<Column> columns) {
private ClusterTableGetResult(ClusterTable table, String tableDescribe, List<Column> columns) {
this.table = table;
this.tableDescribe = tableDescribe;
this.columns = columns;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
Expand All @@ -27,7 +28,7 @@
*/
@RestController
@RequestMapping("/api/cassandra/cluster/{clusterId}/keyspace/{keyspace}")
public class ClusterTableApi {
public class ClusterTableApi {

private final TempClusterConnector tempClusterConnector;
private final ClusterTableListCommander clusterTableListCommander;
Expand Down Expand Up @@ -63,12 +64,14 @@ public ApiResponse<ItemListWithCursorResponse<ClusterTable, String>> listTables(
public ApiResponse<ClusterTableGetResult> getTable(
@PathVariable String clusterId,
@PathVariable String keyspace,
@PathVariable String table
@PathVariable String table,
@RequestParam(required = false, defaultValue = "false") boolean withTableDescribe
) {
try (CqlSession session = tempClusterConnector.makeSession(clusterId)) {
ClusterTableGetResult result = clusterTableGetCommander.getTable(session, ClusterTableGetArgs.builder()
.keyspace(keyspace)
.table(table)
.withTableDescribe(withTableDescribe)
.build());
return ApiResponse.ok(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import kr.hakdang.cadio.core.domain.cluster.keyspace.table.ClusterTablePureSelectResult;
import kr.hakdang.cadio.web.common.dto.response.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -27,14 +26,20 @@
@RequestMapping("/api/cassandra/cluster/{clusterId}/keyspace/{keyspace}")
public class ClusterTablePureSelectApi {

@Autowired
private ClusterTableCommander clusterTableCommander;
private final ClusterTableCommander clusterTableCommander;

@Autowired
private TempClusterConnector tempClusterConnector;
private final TempClusterConnector tempClusterConnector;

@PostMapping("/table/{table}/query")
public ApiResponse<Map<String, Object>> clusterQueryCommand(
public ClusterTablePureSelectApi(
ClusterTableCommander clusterTableCommander,
TempClusterConnector tempClusterConnector
) {
this.clusterTableCommander = clusterTableCommander;
this.tempClusterConnector = tempClusterConnector;
}

@PostMapping("/table/{table}/row")
public ApiResponse<Map<String, Object>> tablePureTableSelect(
@PathVariable String clusterId,
@PathVariable String keyspace,
@PathVariable String table,
Expand All @@ -48,9 +53,7 @@ public ApiResponse<Map<String, Object>> clusterQueryCommand(
map.put("nextCursor", result1.getNextCursor());
map.put("rows", result1.getRows());
map.put("columnNames", result1.getColumnNames());
} catch (Exception e) {
log.error("error : {}", e.getMessage(), e);
throw e;

}

return ApiResponse.ok(map);
Expand Down
22 changes: 15 additions & 7 deletions cadio-web/src/main/webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'bootstrap-icons/font/bootstrap-icons.css'

import ConsoleNavbar from "./components/layout/console-navbar";
import {BrowserRouter, Route, Routes} from "react-router-dom";
import Home from "./pages/home";
import HomeView from "./pages/home-view";
import NotFound from "./pages/not-found";
import ClusterView from "./pages/cluster/cluster-view";
import KeyspaceHome from "./pages/cluster/components/keyspace/keyspace-home";
Expand All @@ -16,10 +16,10 @@ import MetricsHome from "./pages/cluster/components/metrics-home";
import {useEffect} from "react";
import useCadio from "./pages/commons/hooks/useCadio";
import {useCadioState} from "./pages/commons/context/cadioContext";
import InitializeView from "./pages/commons/initialize-view";
import InitializeView from "./pages/initialize-view";
import NodesHome from "./pages/cluster/components/nodes-home";
import SystemView from "./pages/system/system-view";
import TableRows from "./pages/cluster/components/keyspace/table/table-rows";
import TableRow from "./pages/cluster/components/keyspace/table/table-row";
import TableInformation from "./pages/cluster/components/keyspace/table/table-information";
import TableImport from "./pages/cluster/components/keyspace/table/table-import";
import TableExport from "./pages/cluster/components/keyspace/table/table-export";
Expand Down Expand Up @@ -49,7 +49,6 @@ function App() {
systemAvailable && <ConsoleNavbar/>
}


<div className="container-fluid">
<div className="row">

Expand All @@ -58,7 +57,7 @@ function App() {
systemAvailable === false ?
<InitializeView/> :
<Routes>
<Route path="/" element={<Home/>}></Route>
<Route path="/" element={<HomeView/>}></Route>
<Route path="/cluster/:clusterId"
element={<ClusterView><ClusterHome/></ClusterView>}></Route>
<Route path="/cluster/:clusterId/nodes"
Expand All @@ -75,10 +74,10 @@ function App() {
element={
<ClusterView><TableHome
submenu={"HOME"}><TableInformation/></TableHome></ClusterView>}></Route>
<Route path="/cluster/:clusterId/keyspace/:keyspaceName/table/:tableName/rows"
<Route path="/cluster/:clusterId/keyspace/:keyspaceName/table/:tableName/row"
element={
<ClusterView><TableHome
submenu={"ROWS"}><TableRows/></TableHome></ClusterView>}></Route>
submenu={"ROW"}><TableRow/></TableHome></ClusterView>}></Route>
<Route path="/cluster/:clusterId/keyspace/:keyspaceName/table/:tableName/import"
element={
<ClusterView><TableHome submenu={"IMPORT"}><TableImport/></TableHome></ClusterView>}></Route>
Expand All @@ -100,7 +99,16 @@ function App() {

</div>
</div>

</BrowserRouter>
<div className="container">
<footer className="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
<div className="col-md-4 d-flex align-items-center">
<span className="mb-3 mb-md-0 text-body-secondary">&copy; 2024 Company, Inc</span>
</div>

</footer>
</div>
</div>
)
}
Expand Down
45 changes: 29 additions & 16 deletions cadio-web/src/main/webapp/src/components/layout/console-navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@ import {Link} from "react-router-dom";
const ConsoleNavbar = () => {

return (
<header className="navbar sticky-top bg-dark flex-md-nowrap shadow" data-bs-theme="dark">
<Link className={`navbar-brand col-md-3 col-lg-2 me-0 px-3 fs-6 text-white`}
to="/">
Cadio
</Link>
<nav className="navbar navbar-dark bg-dark">
<div className="container-fluid">
<a className="navbar-brand" href="#">Never expand</a>
<button className="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsExample01" aria-controls="navbarsExample01" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>

<ul className="navbar-nav flex-row d-md-none">
<li className="nav-item text-nowrap">
<button className="nav-link px-3 text-white" type="button" data-bs-toggle="offcanvas"
data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false"
aria-label="Toggle navigation">
<i className="bi bi-list"></i>
</button>
</li>
</ul>

</header>
<div className="collapse navbar-collapse" id="navbarsExample01">
<ul className="navbar-nav me-auto mb-2">
<li className="nav-item">
<a className="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">Link</a>
</li>
<li className="nav-item">
<a className="nav-link disabled" aria-disabled="true">Disabled</a>
</li>
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</a>
<ul className="dropdown-menu">
<li><a className="dropdown-item" href="#">Action</a></li>
<li><a className="dropdown-item" href="#">Another action</a></li>
<li><a className="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const KeyspaceDetailDescribe = ({describe}) => {
{/*</div>*/}
</div>

<code>
{describe.replace(/(?:\r\n|\r|\n)/g, '<br>')}
<code style={{whiteSpace: "pre"}}>
{describe}
</code>
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {useClusterState} from "../../../context/clusterContext";
import {useEffect} from "react";

const TableHome = (props) => {
console.log("props : ", props.submenu);
const routeParams = useParams();

//const {doGetKeyspaceList} = useCluster();
Expand Down Expand Up @@ -76,8 +75,8 @@ const TableHome = (props) => {
</li>
<li className="nav-item">
<Link
to={`/cluster/${routeParams.clusterId}/keyspace/${routeParams.keyspaceName}/table/${routeParams.tableName}/rows`}
className={`nav-link link-body-emphasis text-decoration-none ${props.submenu === 'ROWS' && `active`}`}>
to={`/cluster/${routeParams.clusterId}/keyspace/${routeParams.keyspaceName}/table/${routeParams.tableName}/row`}
className={`nav-link link-body-emphasis text-decoration-none ${props.submenu === 'ROW' && `active`}`}>
Rows
</Link>
</li>
Expand Down
Loading

0 comments on commit 7118f71

Please sign in to comment.