Skip to content
Open
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 @@ -301,7 +301,7 @@ private void resolveOwners(List<Sample> procMem, Map<String, Owner> podOwners, M
Map<String, Owner> ownerByPod = new HashMap<>();
for (Request r : requestRepository.findAllByPodNameIn(new HashSet<>(podByContainer.values()))) {
ownerByPod.put(r.getPodName(), new Owner(ownerKey(r), r.getUser().getUserId(), r.getUser().getName(),
r.getUser().getUbuntuUsername(), r.getRequestId()));
r.getUbuntuUsername(), r.getRequestId()));
}
podByContainer.forEach((cid, pod) -> {
if (ownerByPod.containsKey(pod)) podOwners.put(cid, ownerByPod.get(pod));
Expand Down Expand Up @@ -341,7 +341,7 @@ private void fillPodRam(Map<String, String> podByContainer, Map<String, Double>

/** 같은 사용자는 Pod든 옛 Docker 컨테이너든 같은 키가 되도록 우분투 계정을 쓴다. */
static String ownerKey(Request r) {
String name = r.getUser().getUbuntuUsername();
String name = r.getUbuntuUsername();
return name != null && !name.isBlank() ? name : "id:" + r.getUser().getUserId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public SaveRequestResponseDTO createRequest(Long userId, SaveRequestRequestDTO d
.orElseThrow(() -> new BusinessException(ErrorCode.RESOURCE_NOT_FOUND));

// 유저네임은 신청마다 고르는 값이 아니라 가입 시 정해진 웹 계정의 고정값이다.
String ubuntuUsername = user.getUbuntuUsername();
String ubuntuUsername = user.ubuntuUsernameOn(rg.getServerName());
if (ubuntuUsername == null || ubuntuUsername.isBlank()) {
throw new BusinessException(ErrorCode.UBUNTU_USERNAME_NOT_ASSIGNED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import DGU_AI_LAB.admin_be.error.ErrorCode;
import DGU_AI_LAB.admin_be.error.exception.BusinessException;
import DGU_AI_LAB.admin_be.global.common.BaseTimeEntity;
import DGU_AI_LAB.admin_be.global.event.RequestRowChangeListener;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -14,6 +15,7 @@
* 같은 번호·같은 홈으로 돌아온다.
*/
@Entity
@EntityListeners(RequestRowChangeListener.class)
@Table(name = "ubuntu_accounts", uniqueConstraints = {
@UniqueConstraint(name = "uk_ubuntu_accounts_user_server", columnNames = {"user_id", "server_name"}),
@UniqueConstraint(name = "uk_ubuntu_accounts_server_username", columnNames = {"server_name", "username"}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private Request request(Long userId, String pod, String node) {
when(user.getUbuntuUsername()).thenReturn("u" + userId);
Request r = mock(Request.class);
when(r.getUser()).thenReturn(user);
when(r.getUbuntuUsername()).thenReturn("u" + userId);
when(r.getPodName()).thenReturn(pod);
when(r.getNodeName()).thenReturn(node);
when(r.getStatus()).thenReturn(Status.FULFILLED);
Expand Down Expand Up @@ -305,4 +306,15 @@ void metricsFailureMeansEmpty() {
// 빈 목록('GPU 없음')으로 숨기지 않고 오류로 알린다.
assertThatThrownBy(() -> service.getMyGpuUsage(10L, 1L)).isInstanceOf(BusinessException.class);
}

@Test
@DisplayName("소유자 키는 신청의 서버 기준 유저네임이다 — 서버마다 이름이 다른 사람도 그 서버 컨테이너에서 같은 키가 된다")
void ownerKeyUsesRequestServerUsername() {
Request r = request(7L, "pod-lab", "node-a");
when(r.getUbuntuUsername()).thenReturn("lab_name");
assertThat(MyGpuUsageService.ownerKey(r)).isEqualTo("lab_name");

when(r.getUbuntuUsername()).thenReturn(" ");
assertThat(MyGpuUsageService.ownerKey(r)).isEqualTo("id:7");
}
}
Loading