Skip to content

Commit 70f903b

Browse files
authored
Merge pull request #333 from Kernel360/chore/#305-에뮬레이터-각기-다른-gpx-파일로-컨테이너-만들기
chore: 에뮬레이터 각기 다른 gpx 파일로 컨테이너 만들기
2 parents 2e63877 + 413955f commit 70f903b

File tree

18 files changed

+42589
-71
lines changed

18 files changed

+42589
-71
lines changed

monicar-control-center/src/main/resources/data/init-data.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ VALUES (1, '카카오', '123-45-67890', '2025-01-01 09:00:00', '2025-01-01 09:00
1818

1919
INSERT INTO vehicle_information
2020
(vehicle_id, company_id, vehicle_type_id, vehicle_number, mdn, tid, mid, pv, did, driving_days, sum, lat, lng, status, delivery_date, created_at, updated_at, deleted_at)
21-
values (1, 1, 2, '123나1234', 1234567890, 'TID002', 4, 6, 6, 360, 0, 37565557, 127018624, 'NOT_DRIVEN', '2025-02-06', '2025-02-06 02:31:59', '2025-02-06 02:31:59', null),
22-
(2, 1, 1, '657가5202', 2254690422, 'TID003', 3, 1, 5, 927, 0, 37567987, 127014246, 'NOT_DRIVEN', '2025-02-06', '2025-02-06 20:25:59', '2025-02-06 20:25:59', null),
23-
(3, 1, 2, '309가9777', 5246479703, 'TID004', 5, 8, 5, 20, 73907, 37559948, 126968317, 'NOT_REGISTERED', '2025-02-06', '2025-02-06 03:20:59', '2025-02-06 03:20:59', null),
24-
(4, 1, 2, '530가4820', 6459804235, 'TID005', 8, 10, 7, 142, 86586, 37561026, 126977640, 'NOT_DRIVEN', '2025-02-06', '2025-02-06 04:19:59', '2025-02-06 04:19:59', null),
21+
values (1, 1, 2, '123나1234', 1234567890, 'TID002', 4, 6, 6, 360, 0, 37565557, 127018624, 'NOT_DRIVEN', '2025-02-06','2025-02-06 02:31:59', '2025-02-06 02:31:59', null),
22+
(2, 1, 1, '657가5202', 1234567891, 'TID003', 3, 1, 5, 927, 0, 37567987, 127014246, 'NOT_DRIVEN', '2025-02-06','2025-02-06 20:25:59', '2025-02-06 20:25:59', null),
23+
(3, 1, 2, '309가9777', 1234567892, 'TID004', 5, 8, 5, 20, 0, 37559948, 126968317, 'NOT_DRIVEN', '2025-02-06','2025-02-06 03:20:59', '2025-02-06 03:20:59', null),
24+
(4, 1, 2, '530가4820', 1234567893, 'TID005', 8, 10, 7, 142, 0, 37561026, 126977640, 'NOT_DRIVEN', '2025-02-06','2025-02-06 04:19:59', '2025-02-06 04:19:59', null),
2525
(5, 1, 2, '762나5310', 4443625351, 'TID006', 5, 3, 8, 986, 72284, 37577531, 126988260, 'NOT_REGISTERED', '2025-02-06', '2025-02-06 23:00:59', '2025-02-06 23:00:59', null),
2626
(6, 1, 1, '302가5423', 4214563846, 'TID007', 4, 5, 5, 13, 58468, 37572557, 127014216, 'NOT_DRIVEN', '2025-02-06', '2025-02-06 10:08:59', '2025-02-06 10:08:59', null),
2727
(7, 1, 2, '655가8023', 5698741960, 'TID008', 3, 8, 1, 125, 34811, 37560109, 126936964, 'NOT_REGISTERED', '2025-02-06', '2025-02-06 07:15:59', '2025-02-06 07:15:59', null),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM openjdk:21-jdk-slim
2+
ARG JAR_FILE=../build/libs/*.jar
3+
COPY ${JAR_FILE} /app/app.jar
4+
WORKDIR /app
5+
ENTRYPOINT ["java", "-jar", "app.jar"]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
container1:
3+
container_name: tomato
4+
build:
5+
context: ../
6+
dockerfile: simulation/Dockerfile
7+
ports:
8+
- "8091:8091"
9+
environment:
10+
- SPRING_PROFILES_ACTIVE=tomato
11+
12+
container2:
13+
container_name: banana
14+
build:
15+
context: ../
16+
dockerfile: simulation/Dockerfile
17+
ports:
18+
- "8092:8092"
19+
environment:
20+
- SPRING_PROFILES_ACTIVE=banana
21+
22+
container3:
23+
container_name: apple
24+
build:
25+
context: ../
26+
dockerfile: simulation/Dockerfile
27+
ports:
28+
- "8093:8093"
29+
environment:
30+
- SPRING_PROFILES_ACTIVE=apple
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "🛠️ Gradle 프로젝트 빌드 중..."
6+
../../gradlew :monicar-emulator:build --project-dir ../.. -x test
7+
8+
# .yml 확인하여 원하는 profile 이름으로 -f 뒤 값 수정 예) tomato -> banana
9+
docker rm -f tomato 2>/dev/null || true
10+
11+
# 선택한 profile로 -t 뒤 값 수정 예) tomato-image -> banana-image
12+
docker build -t tomato-image -f Dockerfile ../
13+
14+
# 선택한 profile로 --name 뒤 값과 마지막 xx-image 값 수정하기
15+
docker run -d --name tomato \
16+
-p 8091:8091 \
17+
-e SPRING_PROFILES_ACTIVE=tomato \
18+
tomato-image
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "🛠️ Gradle 프로젝트 빌드 중..."
6+
../../gradlew :monicar-emulator:build --project-dir ../..
7+
8+
echo "🐳 Docker Compose 빌드 및 컨테이너 실행..."
9+
docker compose up --build

monicar-emulator/src/main/java/org/emulator/device/VehicleConstant.java renamed to monicar-emulator/src/main/java/org/emulator/device/VehicleInfoConstant.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import org.emulator.device.common.exception.BusinessException;
44
import org.emulator.device.common.response.ErrorCode;
55

6-
public final class VehicleConstant {
7-
public static final long VEHICLE_PRIMARY_KEY = 1234567890L;
8-
public static final String VEHICLE_NUMBER = "123나1234";
6+
public class VehicleInfoConstant {
97
public static final String TERMINAL_ID = "TID001";
108
public static final long MANUFACTURER_ID = 1L;
119
public static final int PACKET_VERSION = 1;
@@ -15,7 +13,7 @@ public final class VehicleConstant {
1513

1614
public static final long MIL = 1_000_000;
1715

18-
private VehicleConstant() {
16+
private VehicleInfoConstant() {
1917
throw new BusinessException(ErrorCode.ILLEGAL_UTILITY_CLASS_ACCESS);
2018
}
2119
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.emulator.device;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
public record VehicleInfoDynamic(
8+
@Value("${fixed.vehicle-mdn}")
9+
long vehicleMdn,
10+
@Value("${fixed.vehicle-number}")
11+
String vehicleNumber
12+
) {}

monicar-emulator/src/main/java/org/emulator/device/common/response/ErrorCode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public enum ErrorCode {
1616
DATA_PROCESSING_ERROR(400, "An error occurred while processing data."),
1717
UNDEFINED_ERROR(500, "An undefined error has occurred"),
1818

19-
/* api 관련 */
2019
UNSUPPORTED_HEADER(1002, "지원하지 않는 헤더입니다"),
2120
ILLEGAL_UTILITY_CLASS_ACCESS(1003, "유틸리티 클래스에 대한 잘못된 접근입니다"),
22-
INTERNAL_SERVER_ERROR(1004, "서버 오류가 발생하였습니다"),
23-
UNSUPPORTED_RESPONSE(1005, "지원하지 않는 응답입니다"),
21+
UTILITY_CLASS_NOT_INITIALIZED_YET(1004, "유틸리티 클래스가 초기화되지 않았습니다"),
2422

23+
/* api 관련 */
2524
NO_GPS_DATA_FOUND(1006, "GPS 데이터 생성이 실패했습니다"),
2625
FAIL_RESPONSE_DELIVERED(1007, "요청 보낸 서버로부터 온 실패 응답입니다"),
26+
2727
FILE_LOAD_FILE(1008, "파일 읽기에 실패했습니다");
2828

2929
private final int code;

monicar-emulator/src/main/java/org/emulator/device/domain/CycleInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.time.LocalDateTime;
44

5-
import org.emulator.device.VehicleConstant;
5+
import org.emulator.device.VehicleInfoConstant;
66
import org.emulator.sensor.dto.GpsTime;
77
import org.emulator.device.infrastructure.external.command.vo.Direction;
88
import org.emulator.device.infrastructure.external.command.vo.Geo;
@@ -37,7 +37,7 @@ public static CycleInfo create(
3737
.direction(new Direction(direction))
3838
.speed(new Speed(speed))
3939
.totalDistance(new TotalDistance(totalDistance))
40-
.battery(VehicleConstant.BATTERY)
40+
.battery(VehicleInfoConstant.BATTERY)
4141
.build();
4242
}
4343
}

monicar-emulator/src/main/java/org/emulator/device/infrastructure/external/command/vo/FixedVehicleInfo.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
import lombok.Getter;
44

5-
import org.emulator.device.VehicleConstant;
5+
import org.emulator.device.VehicleInfoConstant;
6+
import org.emulator.device.VehicleInfoDynamic;
7+
import org.emulator.device.common.exception.BusinessException;
8+
import org.emulator.device.common.response.ErrorCode;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.stereotype.Component;
611

7-
/**
8-
* 차량의 기본 데이터를 담는 VO
9-
*
10-
* @field mdn 차량 번호 - 차량을 식별하는 고유 번호
11-
* @field num 차량 번호 - 번호판 번호
12-
* @field tid 터미널 아이디 - 터미널 장치의 고유 식별자
13-
* @field mid 제조사 아이디 - 제조사를 구분하는 식별자
14-
* @field pv 패킷 버전 - 데이터 패킷의 버전 정보
15-
* @field did 디바이스 아이디 - 설치된 디바이스의 고유 식별자
16-
*/
12+
@Component
1713
@Getter
1814
public class FixedVehicleInfo {
19-
private static final FixedVehicleInfo INSTANCE = new FixedVehicleInfo();
15+
private static FixedVehicleInfo INSTANCE;
2016

2117
private final long mdn;
2218
private final String num;
@@ -25,16 +21,21 @@ public class FixedVehicleInfo {
2521
private final int pv;
2622
private final long did;
2723

28-
private FixedVehicleInfo() {
29-
this.mdn = VehicleConstant.VEHICLE_PRIMARY_KEY;
30-
this.num = VehicleConstant.VEHICLE_NUMBER;
31-
this.tid = VehicleConstant.TERMINAL_ID;
32-
this.mid = VehicleConstant.MANUFACTURER_ID;
33-
this.pv = VehicleConstant.PACKET_VERSION;
34-
this.did = VehicleConstant.DEVICE_ID;
24+
@Autowired
25+
public FixedVehicleInfo(VehicleInfoDynamic vehicleInfoDynamic) {
26+
this.mdn = vehicleInfoDynamic.vehicleMdn();
27+
this.num = vehicleInfoDynamic.vehicleNumber();
28+
this.tid = VehicleInfoConstant.TERMINAL_ID;
29+
this.mid = VehicleInfoConstant.MANUFACTURER_ID;
30+
this.pv = VehicleInfoConstant.PACKET_VERSION;
31+
this.did = VehicleInfoConstant.DEVICE_ID;
32+
INSTANCE = this;
3533
}
3634

3735
public static FixedVehicleInfo getInstance() {
36+
if (INSTANCE == null) {
37+
throw new BusinessException(ErrorCode.UTILITY_CLASS_NOT_INITIALIZED_YET);
38+
}
3839
return INSTANCE;
3940
}
4041
}

0 commit comments

Comments
 (0)