Skip to content
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 @@ -8,15 +8,13 @@
@Schema(description = "GPU 기종별 리소스 정보 응답 DTO")
public record GpuTypeResponseDTO(

@Schema(description = "GPU 모델명", example = "RTX 3090 D6")
String gpuModel,

@Schema(description = "GPU RAM 크기 (GB)", example = "24")
Integer ramGb,

@Schema(description = "GPU 그룹에 대한 상세 설명", example = "DGU AI LAB에서 가장 많이 사용하는 GPU 모델입니다.")
String description,

@Schema(description = "GPU가 속한 리소스 그룹명 (같은 스펙 묶음)", example = "RTX 3090")
@Schema(description = "GPU가 속한 리소스 그룹명 (GPU 모델명)", example = "RTX 3090")
String resourceGroupName,

@Schema(description = "리소스 그룹 ID", example = "1")
Expand All @@ -25,21 +23,21 @@ public record GpuTypeResponseDTO(
@Schema(description = "노드 ID", example = "LAB1")
String nodeId,

@Schema(description = "서버명", example = "서버01") // serverName 필드 추가
@Schema(description = "서버명", example = "서버01")
String serverName,

@Schema(description = "사용 가능한 노드(서버) 개수", example = "5")
Long availableNodes,

@Schema(description = "현재 사용 가능 여부 (true: 사용 가능, false: 사용 불가능)", example = "true")
Boolean isAvailable // TODO: 현재는 항상 true로 가정, 이후에 논의 후 수정 필요
Boolean isAvailable
) {
/**
* Object[] 형태의 쿼리 결과를 DTO로 변환하는 팩토리 메서드입니다.
* <p>
* 쿼리 결과의 순서는 다음과 같이 가정합니다:
* [0] gpuModel
* [1] ramGb
* [0] ramGb
* [1] description
* [2] resourceGroupName
* [3] availableNodes
* [4] rsgroupId
Expand All @@ -54,23 +52,23 @@ public static GpuTypeResponseDTO fromQueryResult(Object[] queryResult) {
if (queryResult == null || queryResult.length < 7) {
throw new IllegalArgumentException("Invalid query result format for GpuTypeResponseDTO. Expected at least 7 elements.");
}
String gpuModel = (String) queryResult[0];
Integer ramGb = (Integer) queryResult[1];
Integer ramGb = (Integer) queryResult[0];
String description = (String) queryResult[1];
String resourceGroupName = (String) queryResult[2];
Long availableNodes = ((Number) queryResult[3]).longValue();
Integer rsgroupId = (Integer) queryResult[4];
String nodeId = (String) queryResult[5];
String serverName = (String) queryResult[6];

return GpuTypeResponseDTO.builder()
.gpuModel(gpuModel)
.ramGb(ramGb)
.description(description)
.resourceGroupName(resourceGroupName)
.availableNodes(availableNodes)
.rsgroupId(rsgroupId)
.nodeId(nodeId)
.serverName(serverName)
.isAvailable(true) // 현재는 항상 true로 가정
.isAvailable(true)
.build();
}

Expand All @@ -85,9 +83,9 @@ public static GpuTypeResponseDTO fromQueryResult(Object[] queryResult) {
*/
public static GpuTypeResponseDTO fromSummary(GpuRepository.GpuSummary s) {
return GpuTypeResponseDTO.builder()
.gpuModel(s.getGpuModel())
.ramGb(s.getRamGb())
.description(s.getDescription())
.resourceGroupName(s.getResourceGroupName())
.availableNodes(s.getNodeCount())
.rsgroupId(s.getRsgroupId())
.nodeId(s.getNodeId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ public interface GpuRepository extends JpaRepository<Gpu, Long> {

// GPU 요약 프로젝션
interface GpuSummary {
String getGpuModel();
Integer getRamGb();
String getDescription();
String getResourceGroupName();
Long getNodeCount();
Integer getRsgroupId();
String getNodeId();
String getServerName();
}

@Query("""
SELECT g.gpuModel AS gpuModel,
g.ramGb AS ramGb,
SELECT g.ramGb AS ramGb,
rg.description AS description,
rg.resourceGroupName AS resourceGroupName,
COUNT(DISTINCT n.nodeId) AS nodeCount,
rg.rsgroupId AS rsgroupId,
n.nodeId AS nodeId,
rg.serverName AS serverName
FROM Gpu g
JOIN g.node n
JOIN n.resourceGroup rg
GROUP BY g.gpuModel, g.ramGb, rg.description, rg.rsgroupId, n.nodeId, rg.serverName
GROUP BY g.ramGb, rg.description, rg.resourceGroupName, rg.rsgroupId, n.nodeId, rg.serverName
""")
List<GpuSummary> findGpuSummary();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class Node {

/**
* ex. LAB1, FARM2 ...
* ex. LAB, FARM ...
*/
@Id
@Column(name = "node_id", length = 100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ public class ResourceGroup {
@Column(name = "rsgroup_id", nullable = false)
private Integer rsgroupId;

@Column(name = "resource_group_name", length = 300)
private String resourceGroupName; // ex. 3090ti ...

@Column(name = "description", length = 500)
private String description;

@Column(name = "server_name", length = 300)
private String serverName;
private String serverName; // ex. FARM, LAB
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<GpuTypeResponseDTO> getGpuTypeResources() {
List<GpuRepository.GpuSummary> gpuSummaries = gpuRepository.findGpuSummary();

for (GpuRepository.GpuSummary summary : gpuSummaries) {
System.out.println(summary.getGpuModel());
System.out.println(summary.getResourceGroupName());
System.out.println(summary.getRamGb());
System.out.println(summary.getDescription());
System.out.println(summary.getNodeCount());
Expand All @@ -41,7 +41,7 @@ public List<GpuTypeResponseDTO> getGpuTypeResources() {
throw new BusinessException(ErrorCode.NO_AVAILABLE_RESOURCES);
}

var summaries = gpuRepository.findGpuSummary(); // List<GpuSummary>
var summaries = gpuRepository.findGpuSummary();
var response = summaries.stream()
.map(GpuTypeResponseDTO::fromSummary)
.toList();
Expand Down