Skip to content

Commit 317afb9

Browse files
committed
Merge remote-tracking branch 'origin/feature/mail-authentication' into feature/mail-authentication
2 parents 813dd59 + 31ba2c0 commit 317afb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1285
-375
lines changed

bm-common/src/main/java/org/benchmarker/bmagent/AgentInfo.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,36 @@
88
import lombok.NoArgsConstructor;
99
import lombok.Setter;
1010
import lombok.ToString;
11+
import org.benchmarker.bmcommon.util.RandomUtils;
12+
import org.benchmarker.util.Randomized;
1113

1214
@Getter
1315
@Setter
1416
@Builder
1517
@ToString
1618
@NoArgsConstructor
1719
@AllArgsConstructor
18-
public class AgentInfo {
20+
public class AgentInfo implements Randomized<AgentInfo> {
1921
private AgentStatus status;
2022
private Set<Long> templateId;
2123
private double cpuUsage;
2224
private double memoryUsage;
2325
private String serverUrl;
2426
private ZonedDateTime startedAt;
27+
28+
@Override
29+
public AgentInfo random() {
30+
return AgentInfo.builder()
31+
.status(AgentStatus.READY)
32+
.startedAt(ZonedDateTime.now())
33+
.memoryUsage(RandomUtils.randDouble(1,10))
34+
.cpuUsage(RandomUtils.randDouble(1,10))
35+
.serverUrl(RandomUtils.randString(10))
36+
.templateId(Set.of(
37+
RandomUtils.randLong(1,5),
38+
RandomUtils.randLong(6,10),
39+
RandomUtils.randLong(11,15)
40+
))
41+
.build();
42+
}
2543
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.benchmarker.bmcommon.dto;
2+
3+
import java.time.LocalDateTime;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
import lombok.Setter;
9+
import lombok.ToString;
10+
11+
@Builder
12+
@AllArgsConstructor
13+
@NoArgsConstructor
14+
@Setter
15+
@Getter
16+
@ToString
17+
public class MTTFBInfo {
18+
private LocalDateTime timestamp;
19+
private String mttbfb;
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.benchmarker.bmcommon.dto;
2+
3+
import java.time.LocalDateTime;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
import lombok.Setter;
9+
import lombok.ToString;
10+
11+
@Builder
12+
@Getter
13+
@Setter
14+
@AllArgsConstructor
15+
@NoArgsConstructor
16+
@ToString
17+
public class TPSInfo {
18+
private LocalDateTime timestamp;
19+
private double tps;
20+
}

bm-common/src/main/java/org/benchmarker/bmcommon/util/RandomUtils.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.benchmarker.bmcommon.util;
22

33
import java.util.HashMap;
4+
import java.util.Random;
45
import java.util.concurrent.ThreadLocalRandom;
56
import org.benchmarker.bmagent.AgentStatus;
67
import org.benchmarker.bmcommon.dto.CommonTestResult;
@@ -57,4 +58,30 @@ public static double randDouble(long min, long max) {
5758
return ThreadLocalRandom.current().nextDouble(min, max + 1);
5859
}
5960

61+
public static String randString(int length) {
62+
// Define the ASCII range for alphabetic characters
63+
int lowerBound = 65; // ASCII value for 'A'
64+
int upperBound = 122; // ASCII value for 'z'
65+
66+
// Create a StringBuilder to store the random string
67+
StringBuilder stringBuilder = new StringBuilder(length);
68+
69+
// Create a Random object
70+
Random random = new Random();
71+
72+
// Generate random characters and append them to the StringBuilder
73+
for (int i = 0; i < length; i++) {
74+
// Generate a random ASCII value within the range
75+
int asciiValue = lowerBound + random.nextInt(upperBound - lowerBound + 1);
76+
77+
// Convert the ASCII value to a character and append it to the StringBuilder
78+
stringBuilder.append((char) asciiValue);
79+
}
80+
81+
// Return the generated random string
82+
return stringBuilder.toString();
83+
}
84+
85+
86+
6087
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.benchmarker.util;
2+
3+
/**
4+
* For randomized object generation
5+
*
6+
* @param <T>
7+
*/
8+
public interface Randomized<T> {
9+
10+
/**
11+
* Generate randomized object
12+
*
13+
* @return T
14+
*/
15+
T random();
16+
}

bm-controller/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ java {
5757
sourceCompatibility = '17'
5858
}
5959

60+
tasks.withType(JavaCompile).configureEach {
61+
options.compilerArgs << '-parameters'
62+
}
63+
6064
configurations {
6165
asciidoctorExt
6266
compileOnly {
@@ -84,6 +88,8 @@ dependencies {
8488
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
8589
implementation 'org.springframework.boot:spring-boot-starter-webflux'
8690
implementation 'org.springframework.boot:spring-boot-starter-actuator'
91+
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
92+
8793
implementation "io.jsonwebtoken:jjwt-api:0.11.1"
8894

8995
testImplementation 'org.testng:testng:7.1.0'
@@ -100,8 +106,9 @@ dependencies {
100106
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
101107

102108
implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-client'
103-
104109
implementation 'org.springframework.boot:spring-boot-starter-mail' //mail
110+
implementation 'org.webjars:webjars-locator-core'
111+
implementation 'org.webjars:chartjs:2.9.3'
105112

106113
implementation 'org.springframework.boot:spring-boot-starter-validation'
107114
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'

bm-controller/src/main/java/org/benchmarker/BmControllerApplication.java

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

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cache.annotation.EnableCaching;
56

67
@SpringBootApplication
8+
@EnableCaching
79
public class BmControllerApplication {
810

911
public static void main(String[] args) {

bm-controller/src/main/java/org/benchmarker/bmcontroller/agent/AgentServerManager.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,45 @@
1313
@Getter
1414
@Slf4j
1515
public class AgentServerManager {
16+
17+
// store current status of all agents
1618
private final ConcurrentHashMap<String, AgentInfo> agentsUrl = new ConcurrentHashMap<>();
19+
20+
// key: running templateId, value: relate agent
1721
private final HashMap<Long, String> agentMapped = new HashMap<>();
22+
1823
public void add(String url, AgentInfo agentInfo) {
1924
agentsUrl.put(url, agentInfo);
2025
}
21-
public void update(String url, AgentInfo agentInfo){
22-
if (agentsUrl.get(agentInfo.getServerUrl())==null){
26+
27+
public void update(AgentInfo agentInfo) {
28+
if (agentsUrl.get(agentInfo.getServerUrl()) == null) {
2329
log.error("cannot find agent");
2430
return;
2531
}
2632
agentsUrl.put(agentInfo.getServerUrl(), agentInfo);
2733
}
2834

29-
public Optional<AgentInfo> getReadyAgent(){
30-
for (AgentInfo agentInfo : agentsUrl.values()){
31-
if (agentInfo.getStatus()== AgentStatus.READY){
35+
public Optional<AgentInfo> getReadyAgent() {
36+
for (AgentInfo agentInfo : agentsUrl.values()) {
37+
if (agentInfo.getStatus() == AgentStatus.READY) {
3238
return Optional.of(agentInfo);
3339
}
3440
}
3541
return Optional.empty();
3642
}
3743

38-
public void removeAgent(String url){
44+
public void remove(String url) {
3945
agentsUrl.remove(url);
4046
}
4147

42-
public void addTemplateRunnerAgent(Long id, String url){
43-
agentMapped.put(id,url);
48+
public void addTemplateRunnerAgent(Long id, String url) {
49+
agentMapped.put(id, url);
4450
}
4551

46-
public void removeTemplateRunnerAgent(Long id){
52+
public void removeTemplateRunnerAgent(Long id) {
4753
String url = agentMapped.get(id);
48-
if (url != null){
54+
if (url != null) {
4955
agentMapped.remove(id);
5056
agentsUrl.remove(url);
5157
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.benchmarker.bmcontroller.common.beans;
2+
3+
import java.time.Duration;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.context.annotation.Profile;
9+
import org.springframework.data.redis.cache.RedisCacheConfiguration;
10+
import org.springframework.data.redis.cache.RedisCacheManager;
11+
import org.springframework.data.redis.connection.RedisConnectionFactory;
12+
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
13+
import org.springframework.data.redis.core.RedisTemplate;
14+
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
15+
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
16+
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
17+
import org.springframework.data.redis.serializer.RedisSerializationContext;
18+
import org.springframework.data.redis.serializer.StringRedisSerializer;
19+
20+
@Slf4j
21+
@Configuration
22+
@EnableRedisRepositories
23+
@Profile("!test")
24+
public class RedisConfig {
25+
26+
@Value("${spring.data.redis.host}")
27+
private String redisHost;
28+
29+
@Value("${spring.data.redis.port}")
30+
private int redisPort;
31+
32+
/**
33+
* RedisConnectionFactory를 통해 내장 혹은 외부의 Redis를 연결합니다.
34+
* @return RedisConnectionFactory
35+
*/
36+
@Bean
37+
public RedisConnectionFactory redisConnectionFactory() {
38+
return new LettuceConnectionFactory(redisHost, redisPort);
39+
}
40+
41+
@Bean
42+
public RedisTemplate<String, Object> redisTemplate() {
43+
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
44+
redisTemplate.setConnectionFactory(redisConnectionFactory());
45+
redisTemplate.setKeySerializer(new StringRedisSerializer());
46+
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
47+
return redisTemplate;
48+
}
49+
50+
@Bean
51+
public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) {
52+
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
53+
.entryTtl(Duration.ofHours(1)) // 캐시 유효 기간 설정
54+
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));
55+
56+
return RedisCacheManager.builder(connectionFactory)
57+
.cacheDefaults(config)
58+
.build();
59+
}
60+
}

bm-controller/src/main/java/org/benchmarker/bmcontroller/common/error/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public enum ErrorCode {
4242
GROUP_NOT_FOUND(404, "그룹이 존재하지 않습니다."),
4343
TEMPLATE_NOT_FOUND(404, "탬플릿이 존재하지 않습니다."),
4444
TEMPLATE_RESULT_NOT_FOUND(404, "탬플릿에 대한 결과가 존재하지 않습니다."),
45+
TEST_NOT_FOUND(404, "테스트 결과가 존재하지 않습니다."),
4546

4647
/**
4748
* 500

bm-controller/src/main/java/org/benchmarker/bmcontroller/common/error/GlobalErrorResponse.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public static ResponseEntity<GlobalErrorResponse> toResponseEntity(ErrorCode err
4242

4343
public static ResponseEntity<GlobalErrorResponse> toResponseEntity(GlobalException e) {
4444
ErrorCode errorCode = e.getErrorCode();
45+
if (e.getMessage() != null){
46+
return ResponseEntity
47+
.status(errorCode.getHttpStatus())
48+
.body(GlobalErrorResponse.builder()
49+
.status(errorCode.getHttpStatus())
50+
.code(errorCode.name())
51+
.message(e.getMessage())
52+
.build()
53+
);
54+
}
4555
return ResponseEntity
4656
.status(errorCode.getHttpStatus())
4757
.body(GlobalErrorResponse.builder()

bm-controller/src/main/java/org/benchmarker/bmcontroller/common/error/GlobalException.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public class GlobalException extends RuntimeException {
1010

1111
private final ErrorCode errorCode;
12+
private String message = null;
1213

1314
public static ErrorCode toErrorCode(Throwable e) {
1415
GlobalException customException = (GlobalException) e;
@@ -22,4 +23,10 @@ public GlobalException(GlobalErrorResponse e) {
2223
public GlobalException(ErrorCode errorCode) {
2324
this.errorCode = errorCode;
2425
}
26+
27+
public GlobalException(ErrorCode errorCode, String message) {
28+
this.errorCode = errorCode;
29+
this.message = message;
30+
}
31+
2532
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.benchmarker.bmcontroller.preftest.common;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.UUID;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Getter;
8+
import lombok.NoArgsConstructor;
9+
import lombok.Setter;
10+
import lombok.ToString;
11+
import org.benchmarker.bmagent.AgentStatus;
12+
import org.benchmarker.bmcommon.util.RandomUtils;
13+
import org.benchmarker.util.Randomized;
14+
15+
@Getter
16+
@Setter
17+
@Builder
18+
@NoArgsConstructor
19+
@AllArgsConstructor
20+
@ToString
21+
public class TestInfo implements Randomized<TestInfo> {
22+
23+
private String groupId;
24+
private Integer templateId;
25+
private String testId;
26+
private AgentStatus testStatus;
27+
private LocalDateTime startedAt;
28+
29+
@Override
30+
public TestInfo random() {
31+
return TestInfo.builder()
32+
.testId(UUID.randomUUID().toString())
33+
.startedAt(LocalDateTime.now())
34+
.testStatus(AgentStatus.TESTING)
35+
.templateId(RandomUtils.randInt(0, 100))
36+
.groupId("defaultGroupId")
37+
.build();
38+
}
39+
}

0 commit comments

Comments
 (0)