Skip to content

Commit 181481e

Browse files
committed
[#9558] Configurable flink rest port
1 parent 8c35e75 commit 181481e

File tree

4 files changed

+89
-24
lines changed

4 files changed

+89
-24
lines changed

batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchConfiguration.java

+21-16
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import com.navercorp.pinpoint.common.server.config.AnnotationVisitor;
1919
import com.navercorp.pinpoint.common.server.config.LoggingEvent;
20-
import org.apache.logging.log4j.Logger;
2120
import org.apache.logging.log4j.LogManager;
21+
import org.apache.logging.log4j.Logger;
2222
import org.springframework.beans.factory.annotation.Value;
2323
import org.springframework.stereotype.Component;
2424

@@ -52,6 +52,8 @@ public class BatchConfiguration {
5252
@Value("${batch.flink.server}")
5353
private String[] flinkServerList = new String[0];
5454

55+
@Value("${batch.flink.rest.port:8081}")
56+
private int flinkRestPort;
5557

5658
@Value("${job.cleanup.inactive.agents:false}")
5759
private boolean enableCleanupInactiveAgents;
@@ -75,7 +77,7 @@ public class BatchConfiguration {
7577
public void setup() {
7678
beforeLog();
7779

78-
if (enableCleanupInactiveAgents == false) {
80+
if (!enableCleanupInactiveAgents) {
7981
cleanupInactiveAgentsDurationDays = DEFAULT_CLEANUP_INACTIVE_AGENTS_DURATION_DAYS;
8082
cleanupInactiveAgentsCron = DISABLED_CLEANUP_INACTIVE_AGENTS_CRON;
8183
} else {
@@ -108,6 +110,10 @@ public List<String> getFlinkServerList() {
108110
return Arrays.asList(flinkServerList);
109111
}
110112

113+
public int getFlinkRestPort() {
114+
return flinkRestPort;
115+
}
116+
111117
public String getEmailServerUrl() {
112118
return emailServerUrl;
113119
}
@@ -135,21 +141,20 @@ public String getCleanupInactiveAgentsCron() {
135141
public boolean isWebhookEnable() {
136142
return webhookEnable;
137143
}
138-
144+
139145
@Override
140146
public String toString() {
141-
final StringBuilder sb = new StringBuilder("BatchConfiguration{");
142-
sb.append("emailServerUrl='").append(emailServerUrl).append('\'');
143-
sb.append(", senderEmailAddress='").append(senderEmailAddress).append('\'');
144-
sb.append(", enableWebhook='").append(webhookEnable).append('\'');
145-
sb.append(", pinpointUrl='").append(pinpointUrl).append('\'');
146-
sb.append(", batchEnv='").append(batchEnv).append('\'');
147-
sb.append(", flinkServerList=").append(Arrays.toString(flinkServerList));
148-
sb.append(", enableCleanupInactiveAgents=").append(enableCleanupInactiveAgents);
149-
sb.append(", cleanupInactiveAgentsDurationDays=").append(cleanupInactiveAgentsDurationDays);
150-
sb.append(", cleanupInactiveAgentsCron='").append(cleanupInactiveAgentsCron).append('\'');
151-
sb.append('}');
152-
return sb.toString();
147+
return "BatchConfiguration{" +
148+
"emailServerUrl='" + emailServerUrl + '\'' +
149+
", senderEmailAddress='" + senderEmailAddress + '\'' +
150+
", pinpointUrl='" + pinpointUrl + '\'' +
151+
", webhookEnable=" + webhookEnable +
152+
", batchEnv='" + batchEnv + '\'' +
153+
", flinkServerList=" + Arrays.toString(flinkServerList) +
154+
", flinkRestPort=" + flinkRestPort +
155+
", enableCleanupInactiveAgents=" + enableCleanupInactiveAgents +
156+
", cleanupInactiveAgentsDurationDays=" + cleanupInactiveAgentsDurationDays +
157+
", cleanupInactiveAgentsCron='" + cleanupInactiveAgentsCron + '\'' +
158+
'}';
153159
}
154-
155160
}

batch/src/main/java/com/navercorp/pinpoint/batch/flink/HealthCheckTaskletV2.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
package com.navercorp.pinpoint.batch.flink;
1717

1818
import com.navercorp.pinpoint.batch.common.BatchConfiguration;
19-
import org.apache.logging.log4j.Logger;
2019
import org.apache.logging.log4j.LogManager;
20+
import org.apache.logging.log4j.Logger;
2121
import org.springframework.batch.core.StepContribution;
2222
import org.springframework.batch.core.scope.context.ChunkContext;
2323
import org.springframework.batch.core.step.tasklet.Tasklet;
2424
import org.springframework.batch.repeat.RepeatStatus;
25+
import org.springframework.core.ParameterizedTypeReference;
2526
import org.springframework.http.HttpMethod;
2627
import org.springframework.http.HttpStatus;
2728
import org.springframework.http.ResponseEntity;
2829
import org.springframework.web.client.RestTemplate;
2930

31+
import javax.annotation.Nonnull;
3032
import java.util.ArrayList;
3133
import java.util.HashMap;
3234
import java.util.List;
@@ -39,7 +41,7 @@
3941
public class HealthCheckTaskletV2 implements Tasklet {
4042

4143
private final Logger logger = LogManager.getLogger(this.getClass());
42-
private final static String URL_FORMAT = "http://%s:8081/jobs/overview";
44+
private final static String URL_FORMAT = "http://%s:%d/jobs/overview";
4345
private final static String NAME = "name";
4446
private final static String STATE = "state";
4547
private final static String RUNNING = "RUNNING";
@@ -58,7 +60,7 @@ public HealthCheckTaskletV2(BatchConfiguration batchConfiguration, RestTemplate
5860
}
5961

6062
@Override
61-
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
63+
public RepeatStatus execute(@Nonnull StepContribution contribution, @Nonnull ChunkContext chunkContext) throws Exception {
6264
List<String> urlList = generatedFlinkManagerServerApi();
6365

6466
if (urlList.isEmpty()) {
@@ -69,7 +71,8 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
6971

7072
for (String url : urlList) {
7173
try {
72-
ResponseEntity<Map> responseEntity = this.restTemplate.exchange(url, HttpMethod.GET, null, Map.class);
74+
ParameterizedTypeReference<Map<?, ?>> type = new ParameterizedTypeReference<>() {};
75+
ResponseEntity<Map<?, ?>> responseEntity = this.restTemplate.exchange(url, HttpMethod.GET, null, type);
7376

7477
if (responseEntity.getStatusCode() != HttpStatus.OK) {
7578
continue;
@@ -96,7 +99,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
9699
return RepeatStatus.FINISHED;
97100
}
98101

99-
private void checkJobExecuteStatus(ResponseEntity<Map> responseEntity, Map<String, Boolean> jobExecuteStatus) {
102+
private void checkJobExecuteStatus(ResponseEntity<Map<?, ?>> responseEntity, Map<String, Boolean> jobExecuteStatus) {
100103
Map<?, ?> responseData = responseEntity.getBody();
101104
if(responseData != null) {
102105
List<?> jobs = (List<?>)responseData.get("jobs");
@@ -115,13 +118,14 @@ private void checkJobExecuteStatus(ResponseEntity<Map> responseEntity, Map<Strin
115118
}
116119
}
117120

118-
119-
private List<String> generatedFlinkManagerServerApi() {
121+
// @VisibleForTesting
122+
List<String> generatedFlinkManagerServerApi() {
120123
List<String> flinkServerList = batchConfiguration.getFlinkServerList();
124+
int flinkRestPort = batchConfiguration.getFlinkRestPort();
121125
List<String> urlList = new ArrayList<>(flinkServerList.size());
122126

123127
for (String flinkServerIp : flinkServerList) {
124-
urlList.add(String.format(URL_FORMAT, flinkServerIp));
128+
urlList.add(String.format(URL_FORMAT, flinkServerIp, flinkRestPort));
125129
}
126130

127131
return urlList;

batch/src/main/resources/batch-root.properties

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ webhook.enable=false
2121

2222
#flink server list
2323
batch.flink.server=
24+
batch.flink.rest.port=8081
2425

2526
#cleanup inactive agents job
2627
job.cleanup.inactive.agents=false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2022 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.batch.flink;
17+
18+
import com.navercorp.pinpoint.batch.common.BatchConfiguration;
19+
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.extension.ExtendWith;
21+
import org.mockito.Mock;
22+
import org.mockito.junit.jupiter.MockitoExtension;
23+
import org.springframework.web.client.RestTemplate;
24+
25+
import java.util.List;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.mockito.Mockito.when;
29+
30+
/**
31+
* @author youngjin.kim2
32+
*/
33+
@ExtendWith(MockitoExtension.class)
34+
public class HealthCheckTaskletV2Test {
35+
36+
@Mock
37+
private BatchConfiguration batchConfiguration;
38+
39+
@Mock
40+
RestTemplate restTemplate;
41+
42+
@Test
43+
public void testGeneratedFlinkManagerServerApi() {
44+
when(batchConfiguration.getFlinkServerList()).thenReturn(List.of("123.234.123.234"));
45+
when(batchConfiguration.getFlinkRestPort()).thenReturn(1919);
46+
47+
final HealthCheckTaskletV2 tasklet = new HealthCheckTaskletV2(batchConfiguration, restTemplate);
48+
final List<String> results = tasklet.generatedFlinkManagerServerApi();
49+
assertThat(results).hasSize(1);
50+
final String result = results.get(0);
51+
assertThat(result.indexOf("123.234.123.234:1919")).isGreaterThanOrEqualTo(0);
52+
assertThat(result.indexOf("DEAD-BEEF")).isLessThan(0);
53+
}
54+
55+
}

0 commit comments

Comments
 (0)