Skip to content
Snippets Groups Projects
Commit e6f1aafb authored by 천 진강's avatar 천 진강
Browse files

fix: 포트포워딩 파일을 수정하지 않던 문제, 생성일/수정일 필드가 제대로 적용되지 않던 문제 해결

parent b96e7708
No related branches found
No related tags found
2 merge requests!15Feat/certificate,!7Feat/forwarding 포트포워딩 CRUD
......@@ -2,8 +2,10 @@ package com.aolda.itda;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@SpringBootApplication
@EnableJpaAuditing
public class ItdaApplication {
public static void main(String[] args) {
......
......@@ -16,6 +16,7 @@ public enum ErrorCode {
//Forwarding
FAIL_CREATE_CONF(HttpStatus.BAD_REQUEST, "Conf 파일을 생성하지 못했습니다"),
FAIL_UPDATE_CONF(HttpStatus.BAD_REQUEST, "Conf 파일을 수정하지 못했습니다"),
NOT_FOUND_FORWARDING(HttpStatus.BAD_REQUEST, "포트포워딩 파일이 존재하지 않습니다"),
INVALID_CONF_INPUT(HttpStatus.BAD_REQUEST, "잘못된 입력이 존재합니다"),
DUPLICATED_INSTANCE_INFO(HttpStatus.BAD_REQUEST, "중복된 인스턴스 IP와 포트입니다"),
......
......@@ -115,17 +115,42 @@ public class ForwardingService {
Forwarding forwarding = forwardingRepository.findByForwardingIdAndIsDeleted(forwardingId, false)
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_FORWARDING));
forwarding.edit(dto);
/* 중복 검증 */
if (forwardingRepository.existsByInstanceIpAndInstancePortAndIsDeleted(dto.getInstanceIp(), dto.getInstancePort(), false)) {
if (!(dto.getInstanceIp() == null && dto.getInstancePort() == null) &&
forwardingRepository.existsByInstanceIpAndInstancePortAndIsDeleted(forwarding.getInstanceIp()
, forwarding.getInstancePort()
, false)) {
throw new CustomException(ErrorCode.DUPLICATED_INSTANCE_INFO);
}
if (forwardingRepository.existsByServerPortAndIsDeleted(dto.getServerPort(), false)) {
if (dto.getServerPort() != null && forwardingRepository.existsByServerPortAndIsDeleted(dto.getServerPort(), false)) {
throw new CustomException(ErrorCode.DUPLICATED_SERVER_PORT);
}
/* 정보 수정 */
forwarding.edit(dto);
/* 파일 수정 */
String content = forwardingTemplate.getPortForwardingWithTCP(forwarding.getServerPort(),
forwarding.getInstanceIp(),
forwarding.getInstancePort(),
forwarding.getName());
String confPath = "/data/nginx/stream/" + forwarding.getForwardingId() + ".conf";
File file = new File(confPath);
if (!file.exists()) {
throw new CustomException(ErrorCode.NOT_FOUND_FORWARDING, "Conf 파일이 존재하지 않아 수정할 수 없습니다");
}
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); // 예외처리 필요
bw.write(content);
bw.flush();
bw.close();
} catch (Exception e) {
e.printStackTrace();
throw new CustomException(ErrorCode.FAIL_UPDATE_CONF, "포트포워딩 Conf 파일을 수정하지 못했습니다");
}
/* DB 정보 수정 */
forwardingRepository.save(forwarding);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment