Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/table view deco #21

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
public class ClusterTableCommander extends BaseClusterCommander {

public ClusterTablePureSelectResult pureSelect(CqlSession session, ClusterTablePureSelectArgs args) {
SimpleStatement statement = QueryBuilder.selectFrom(args.getKeyspace(), args.getTable()).all().build().setPageSize(args.getLimit()).setTimeout(Duration.ofSeconds(3)) // 3s timeout
SimpleStatement statement = QueryBuilder.selectFrom(args.getKeyspace(), args.getTable())
.all()
.build()
.setPageSize(args.getPageSize())
.setTimeout(Duration.ofSeconds(3)) // 3s timeout
.setPagingState(StringUtils.isNotBlank(args.getCursor()) ? Bytes.fromHexString(args.getCursor()) : null);

ResultSet resultSet = session.execute(statement);
Expand All @@ -47,7 +51,6 @@ public ClusterTablePureSelectResult pureSelect(CqlSession session, ClusterTableP
rows.add(convertMap(definitions, page1Iter.next()));
}

String previewCursor = args.getCursor();
String nextCursor = "";
ByteBuffer pagingState = resultSet.getExecutionInfo().getPagingState();
if (pagingState != null) {
Expand All @@ -63,8 +66,7 @@ public ClusterTablePureSelectResult pureSelect(CqlSession session, ClusterTableP
.wasApplied(resultSet.wasApplied())
.columnNames(columnNames)
.rows(rows)
.nextToken(nextCursor)
.previewToken(previewCursor)
.nextCursor(nextCursor)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class ClusterTablePureSelectArgs {
private String keyspace;
private String table;

private int limit; //TODO : max check
private int pageSize; //TODO : max check

private String cursor;

@Builder
public ClusterTablePureSelectArgs(String keyspace, String table, int limit, String cursor) {
public ClusterTablePureSelectArgs(String keyspace, String table, int pageSize, String cursor) {
this.keyspace = keyspace;
this.table = table;
this.limit = limit;
this.pageSize = pageSize;
this.cursor = cursor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ public class ClusterTablePureSelectResult {
private boolean wasApplied;
private List<String> columnNames;
private List<Map<String, Object>> rows;
private String previewToken;
private String nextToken;
private String nextCursor;

@Builder
public ClusterTablePureSelectResult(boolean wasApplied, List<String> columnNames, List<Map<String, Object>> rows, String previewToken, String nextToken) {
public ClusterTablePureSelectResult(boolean wasApplied, List<String> columnNames, List<Map<String, Object>> rows, String nextCursor) {
this.wasApplied = wasApplied;
this.columnNames = columnNames;
this.rows = rows;
this.previewToken = previewToken;
this.nextToken = nextToken;
this.nextCursor = nextCursor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* ClusterQueryResponse
* TODO : 변경필요
*
* @author akageun
* @since 2024-07-03
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package kr.hakdang.cadio.web.route.cluster.table.pureselect;

import com.datastax.oss.driver.api.core.CqlSession;
import kr.hakdang.cadio.core.domain.cluster.ClusterQueryCommanderResult;
import kr.hakdang.cadio.core.domain.cluster.keyspace.table.ClusterTableCommander;
import kr.hakdang.cadio.core.domain.cluster.keyspace.table.ClusterTablePureSelectResult;
import kr.hakdang.cadio.web.common.dto.response.ApiResponse;
import kr.hakdang.cadio.web.route.BaseSample;
import kr.hakdang.cadio.web.route.cluster.query.ClusterQueryRequest;
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;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
* ClusterTablePureSelectApi
*
* @author akageun
* @since 2024-07-03
*/
@Slf4j
@RestController
@RequestMapping("/api/cassandra/cluster/{clusterId}/keyspace/{keyspace}")
public class ClusterTablePureSelectApi extends BaseSample {

@Autowired
private ClusterTableCommander clusterTableCommander;

@PostMapping("/table/{table}/query")
public ApiResponse<Map<String, Object>> clusterQueryCommand(
@PathVariable String clusterId,
@PathVariable String keyspace,
@PathVariable String table,
@RequestBody ClusterTablePureSelectRequest request
) {
Map<String, Object> map = new HashMap<>();
try (CqlSession session = makeSession()) { //TODO : interface 작업할 때 facade layer 로 변경 예정
ClusterTablePureSelectResult result1 = clusterTableCommander.pureSelect(session, request.makeArgs(keyspace, table));

map.put("wasApplied", result1.isWasApplied());
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package kr.hakdang.cadio.web.route.cluster.table.pureselect;

import kr.hakdang.cadio.core.domain.cluster.keyspace.table.ClusterTablePureSelectArgs;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* ClusterTablePureSelectRequest
*
* @author akageun
* @since 2024-07-03
*/
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ClusterTablePureSelectRequest {
private String cursor;
private int pageSize;

@Builder
public ClusterTablePureSelectRequest(String cursor, int pageSize) {
this.cursor = cursor;
this.pageSize = pageSize;
}

public ClusterTablePureSelectArgs makeArgs(String keyspace, String table) {
return ClusterTablePureSelectArgs.builder()
.keyspace(keyspace)
.table(table)
.cursor(cursor)
.pageSize(pageSize)
.build();
}
}
19 changes: 17 additions & 2 deletions cadio-web/src/main/webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {useCadioState} from "./pages/commons/context/cadioContext";
import InitializeView from "./pages/commons/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 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";

function App() {
const {doBootstrap} = useCadio();
Expand Down Expand Up @@ -68,8 +72,19 @@ function App() {
<Route path="/cluster/:clusterId/keyspace/:keyspaceName"
element={<ClusterView><KeyspaceHome/></ClusterView>}></Route>
<Route path="/cluster/:clusterId/keyspace/:keyspaceName/table/:tableName"
element={<ClusterView><TableHome/></ClusterView>}></Route>

element={
<ClusterView><TableHome
submenu={"HOME"}><TableInformation/></TableHome></ClusterView>}></Route>
<Route path="/cluster/:clusterId/keyspace/:keyspaceName/table/:tableName/rows"
element={
<ClusterView><TableHome
submenu={"ROWS"}><TableRows/></TableHome></ClusterView>}></Route>
<Route path="/cluster/:clusterId/keyspace/:keyspaceName/table/:tableName/import"
element={
<ClusterView><TableHome submenu={"IMPORT"}><TableImport/></TableHome></ClusterView>}></Route>
<Route path="/cluster/:clusterId/keyspace/:keyspaceName/table/:tableName/export"
element={
<ClusterView><TableHome submenu={"EXPORT"}><TableExport/></TableHome></ClusterView>}></Route>
<Route path="/system"
element={<SystemView/>}></Route>
{/* 상단에 위치하는 라우트들의 규칙을 모두 확인, 일치하는 라우트가 없는경우 처리 */}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const TableExport = () => {

return (
<>
Export
</>
)
}

export default TableExport;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {Link, useParams} from "react-router-dom";
import {useClusterState} from "../../../context/clusterContext";
import {useEffect} from "react";

const TableHome = () => {

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

//const {doGetKeyspaceList} = useCluster();
Expand Down Expand Up @@ -68,68 +68,52 @@ const TableHome = () => {

<ul className="nav nav-tabs">
<li className="nav-item">
<a className="nav-link active" aria-current="page" href="#">Home</a>
<Link
to={`/cluster/${routeParams.clusterId}/keyspace/${routeParams.keyspaceName}/table/${routeParams.tableName}`}
className={`nav-link link-body-emphasis text-decoration-none ${props.submenu === 'HOME' && `active`}`}>
Home
</Link>
</li>
<li className="nav-item">
<a className="nav-link" aria-current="page" href="#">Detail</a>
<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`}`}>
Rows
</Link>
</li>
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button"
<li className="nav-item dropdown ">
<a className={`nav-link dropdown-toggle link-body-emphasis text-decoration-none`} data-bs-toggle="dropdown" role="button"
aria-expanded="false">Data</a>
<ul className="dropdown-menu">
<li><a className="dropdown-item" href="#">Export</a></li>
<li><a className="dropdown-item" href="#">Import</a></li>
<li><a className="dropdown-item" href="#">Something else here</a></li>
<li>
<hr className="dropdown-divider"/>
<Link
to={`/cluster/${routeParams.clusterId}/keyspace/${routeParams.keyspaceName}/table/${routeParams.tableName}/export`}
className={`dropdown-item ${props.submenu === 'EXPORT' && `active`}`}>
Export
</Link>
</li>
<li>
<Link
to={`/cluster/${routeParams.clusterId}/keyspace/${routeParams.keyspaceName}/table/${routeParams.tableName}/import`}
className={`dropdown-item ${props.submenu === 'IMPORT' && `active`}`}>
Import
</Link>
</li>
<li><a className="dropdown-item" href="#">Separated link</a></li>
{/*<li>*/}
{/* <hr className="dropdown-divider"/>*/}
{/*</li>*/}
{/*<li><a className="dropdown-item" href="#">Separated link</a></li>*/}
</ul>
</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">*/}
{/* <a className="nav-link" href="#">Link</a>*/}
{/*</li>*/}
{/*<li className="nav-item">*/}
{/* <a className="nav-link disabled" aria-disabled="true">Disabled</a>*/}
{/*</li>*/}
</ul>

<div className="table-responsive small">
<table className="table table-striped table-sm">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Header</th>
<th scope="col">Header</th>
<th scope="col">Header</th>
<th scope="col">Header</th>
</tr>
</thead>
<tbody>
{
new Array(1000).fill({
t1: "test",
t2: "value",
t3: "tttt",
t4: "adfasdfasd"
}).map((info, infoIndex) => {
return (
<tr>
<td>{info.t1}</td>
<td>{info.t2}</td>
<td>{info.t3}</td>
<td>{info.t4}</td>
<td></td>
</tr>
)
})
}

</tbody>
</table>
</div>


{props.children}
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const TableImport = () => {

return (
<>
Infomation
</>
)
}

export default TableImport;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const TableInformation = () => {

return (
<>
Infomation
</>
)
}

export default TableInformation;
Loading
Loading