-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
320 additions
and
32 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...re/src/main/java/kr/hakdang/cassdio/core/domain/cluster/compaction/CompactionHistory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package kr.hakdang.cassdio.core.domain.cluster.compaction; | ||
|
||
import com.datastax.oss.driver.api.core.cql.Row; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Map; | ||
import java.util.TimeZone; | ||
import java.util.UUID; | ||
|
||
/** | ||
* CompactionHistory | ||
* | ||
* @author seungh0 | ||
* @since 2024-07-25 | ||
*/ | ||
@ToString | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class CompactionHistory { | ||
|
||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
|
||
private UUID id; | ||
private long bytesIn; | ||
private long bytesOut; | ||
private String columnFamilyName; | ||
private LocalDateTime compactedAt; | ||
private String keyspaceName; | ||
private Map<Integer, Long> rowMerged; | ||
|
||
@Builder | ||
private CompactionHistory(UUID id, long bytesIn, long bytesOut, String columnFamilyName, LocalDateTime compactedAt, String keyspaceName, Map<Integer, Long> rowMerged) { | ||
this.id = id; | ||
this.bytesIn = bytesIn; | ||
this.bytesOut = bytesOut; | ||
this.columnFamilyName = columnFamilyName; | ||
this.compactedAt = compactedAt; | ||
this.keyspaceName = keyspaceName; | ||
this.rowMerged = rowMerged; | ||
} | ||
|
||
public static CompactionHistory from(Row row) { | ||
return CompactionHistory.builder() | ||
.id(row.getUuid("id")) | ||
.bytesIn(row.getLong("bytes_in")) | ||
.bytesOut(row.getLong("bytes_out")) | ||
.compactedAt(LocalDateTime.ofInstant(row.get("compacted_at", Instant.class), TimeZone.getDefault().toZoneId())) | ||
.columnFamilyName(row.getString("columnfamily_name")) | ||
.keyspaceName(row.getString("keyspace_name")) | ||
.rowMerged(row.getMap("rows_merged", Integer.class, Long.class)) | ||
.build(); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...ava/kr/hakdang/cassdio/core/domain/cluster/compaction/CompactionHistoryListCommander.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package kr.hakdang.cassdio.core.domain.cluster.compaction; | ||
|
||
import com.datastax.oss.driver.api.core.CqlSession; | ||
import com.datastax.oss.driver.api.core.cql.ResultSet; | ||
import com.datastax.oss.driver.api.core.cql.SimpleStatement; | ||
import com.datastax.oss.driver.api.querybuilder.QueryBuilder; | ||
import kr.hakdang.cassdio.core.domain.cluster.BaseClusterCommander; | ||
import kr.hakdang.cassdio.core.domain.cluster.keyspace.CassandraSystemKeyspace; | ||
import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.CassandraSystemTable; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
/** | ||
* CompactionHistoryListCommander | ||
* | ||
* @author seungh0 | ||
* @since 2024-07-25 | ||
*/ | ||
@Service | ||
public class CompactionHistoryListCommander extends BaseClusterCommander { | ||
|
||
public CompactionHistoryListResult listCompactionHistory(CqlSession session, String keyspace) { | ||
SimpleStatement statement = QueryBuilder | ||
.selectFrom(CassandraSystemKeyspace.SYSTEM.getKeyspaceName(), CassandraSystemTable.SYSTEM_COMPACTION_HISTORY.getTableName()) | ||
.all() | ||
.build(); | ||
|
||
ResultSet rs = session.execute(statement); | ||
|
||
List<CompactionHistory> historyList = StreamSupport.stream(rs.spliterator(), false) | ||
.map(CompactionHistory::from) | ||
.filter(history -> StringUtils.isBlank(keyspace) || history.getKeyspaceName().equals(keyspace)) | ||
.sorted(Comparator.comparing(CompactionHistory::getCompactedAt).reversed()) | ||
.collect(Collectors.toList()); | ||
|
||
return CompactionHistoryListResult.builder() | ||
.histories(historyList) | ||
.build(); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...n/java/kr/hakdang/cassdio/core/domain/cluster/compaction/CompactionHistoryListResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package kr.hakdang.cassdio.core.domain.cluster.compaction; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* ClusterTable | ||
* | ||
* @author seungh0 | ||
* @since 2024-07-01 | ||
*/ | ||
@ToString | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class CompactionHistoryListResult { | ||
|
||
private List<CompactionHistory> histories; | ||
|
||
@Builder | ||
public CompactionHistoryListResult(List<CompactionHistory> histories) { | ||
this.histories = histories; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
...in/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetResult2.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...c/main/java/kr/hakdang/cassdio/web/route/cluster/compaction/CompactionHistoryListApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package kr.hakdang.cassdio.web.route.cluster.compaction; | ||
|
||
import com.datastax.oss.driver.api.core.CqlSession; | ||
import kr.hakdang.cassdio.core.domain.cluster.ClusterConnector; | ||
import kr.hakdang.cassdio.core.domain.cluster.compaction.CompactionHistoryListCommander; | ||
import kr.hakdang.cassdio.core.domain.cluster.compaction.CompactionHistoryListResult; | ||
import kr.hakdang.cassdio.web.common.dto.response.ApiResponse; | ||
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; | ||
|
||
/** | ||
* CompactionHistoryListApi | ||
* | ||
* @author seungh0 | ||
* @since 2024-07-25 | ||
*/ | ||
@RequestMapping("/api/cassandra/cluster/{clusterId}") | ||
@RestController | ||
public class CompactionHistoryListApi { | ||
|
||
private final ClusterConnector clusterConnector; | ||
private final CompactionHistoryListCommander compactionHistoryListCommander; | ||
|
||
public CompactionHistoryListApi(ClusterConnector clusterConnector, CompactionHistoryListCommander compactionHistoryListCommander) { | ||
this.clusterConnector = clusterConnector; | ||
this.compactionHistoryListCommander = compactionHistoryListCommander; | ||
} | ||
|
||
@GetMapping("/compaction-history") | ||
public ApiResponse<CompactionHistoryListResult> getCompactionHistories( | ||
@PathVariable String clusterId, | ||
@RequestParam(required = false) String keyspace | ||
) { | ||
try (CqlSession session = clusterConnector.makeSession(clusterId)) { | ||
CompactionHistoryListResult result = compactionHistoryListCommander.listCompactionHistory(session, keyspace); | ||
return ApiResponse.ok(result); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
cassdio-web/src/main/webapp/src/pages/cluster/components/compaction-home.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import {useParams} from "react-router-dom"; | ||
import {useEffect, useState} from "react"; | ||
import axios from "axios"; | ||
import Spinner from "components/spinner"; | ||
import useCassdio from "commons/hooks/useCassdio"; | ||
import {ByteFormatUtils} from "../../../utils/byteFormat"; | ||
|
||
const CompactionHome = () => { | ||
|
||
const routeParams = useParams(); | ||
const {errorCatch} = useCassdio(); | ||
|
||
const [loading, setLoading] = useState(false); | ||
const [histories, setHistories] = useState([]); | ||
|
||
useEffect(() => { | ||
console.log(routeParams.keyspaceName) | ||
setLoading(true) | ||
axios({ | ||
method: "GET", | ||
url: `/api/cassandra/cluster/${routeParams.clusterId}/compaction-history`, | ||
params: { | ||
keyspace: routeParams.keyspaceName | ||
} | ||
}).then((response) => { | ||
setHistories(response.data.result.histories) | ||
}).catch((error) => { | ||
errorCatch(error) | ||
}).finally(() => { | ||
setLoading(false) | ||
}); | ||
|
||
return () => { | ||
}; | ||
}, [routeParams.clusterId, routeParams.keyspaceName]); | ||
|
||
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"> | ||
Compaction History | ||
</h2> | ||
</div> | ||
|
||
<Spinner loading={loading}> | ||
<div className="table-responsive small"> | ||
<table className="table table-sm table-hover"> | ||
<thead> | ||
<tr className={"table-dark"}> | ||
<th className={"text-center"} scope="col">Keyspace</th> | ||
<th className={"text-center"} scope="col">Table</th> | ||
<th className={"text-center"} scope="col">Compacted At</th> | ||
<th className={"text-center"} scope="col">Bytes In</th> | ||
<th className={"text-center"} scope="col">Bytes Out</th> | ||
<th className={"text-center"} scope="col">Row Merged</th> | ||
</tr> | ||
</thead> | ||
<tbody className="table-group-divider"> | ||
{ | ||
histories && histories.length > 0 && histories.map((compaction, infoIndex) => { | ||
return ( | ||
<tr key={infoIndex}> | ||
<td className={"text-center"}> | ||
{compaction.keyspaceName} | ||
</td> | ||
<td className={"text-center"}> | ||
{compaction.columnFamilyName} | ||
</td> | ||
<td className={"text-center"}> | ||
{compaction.compactedAt} | ||
</td> | ||
<td className={"text-center"}> | ||
{ByteFormatUtils.formatBytes(compaction.bytesIn)} | ||
</td> | ||
<td className={"text-center"}> | ||
{ByteFormatUtils.formatBytes(compaction.bytesOut)} | ||
</td> | ||
<td className={"text-center"}> | ||
{JSON.stringify(compaction.rowMerged)} | ||
</td> | ||
</tr> | ||
) | ||
}) | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
</Spinner> | ||
</> | ||
) | ||
} | ||
|
||
export default CompactionHome; |
Oops, something went wrong.