16
16
package com .navercorp .pinpoint .batch .flink ;
17
17
18
18
import com .navercorp .pinpoint .batch .common .BatchConfiguration ;
19
- import org .apache .logging .log4j .Logger ;
20
19
import org .apache .logging .log4j .LogManager ;
20
+ import org .apache .logging .log4j .Logger ;
21
21
import org .springframework .batch .core .StepContribution ;
22
22
import org .springframework .batch .core .scope .context .ChunkContext ;
23
23
import org .springframework .batch .core .step .tasklet .Tasklet ;
24
24
import org .springframework .batch .repeat .RepeatStatus ;
25
+ import org .springframework .core .ParameterizedTypeReference ;
25
26
import org .springframework .http .HttpMethod ;
26
27
import org .springframework .http .HttpStatus ;
27
28
import org .springframework .http .ResponseEntity ;
28
29
import org .springframework .web .client .RestTemplate ;
29
30
31
+ import javax .annotation .Nonnull ;
30
32
import java .util .ArrayList ;
31
33
import java .util .HashMap ;
32
34
import java .util .List ;
39
41
public class HealthCheckTaskletV2 implements Tasklet {
40
42
41
43
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" ;
43
45
private final static String NAME = "name" ;
44
46
private final static String STATE = "state" ;
45
47
private final static String RUNNING = "RUNNING" ;
@@ -58,7 +60,7 @@ public HealthCheckTaskletV2(BatchConfiguration batchConfiguration, RestTemplate
58
60
}
59
61
60
62
@ Override
61
- public RepeatStatus execute (StepContribution contribution , ChunkContext chunkContext ) throws Exception {
63
+ public RepeatStatus execute (@ Nonnull StepContribution contribution , @ Nonnull ChunkContext chunkContext ) throws Exception {
62
64
List <String > urlList = generatedFlinkManagerServerApi ();
63
65
64
66
if (urlList .isEmpty ()) {
@@ -69,7 +71,8 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
69
71
70
72
for (String url : urlList ) {
71
73
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 );
73
76
74
77
if (responseEntity .getStatusCode () != HttpStatus .OK ) {
75
78
continue ;
@@ -96,7 +99,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
96
99
return RepeatStatus .FINISHED ;
97
100
}
98
101
99
- private void checkJobExecuteStatus (ResponseEntity <Map > responseEntity , Map <String , Boolean > jobExecuteStatus ) {
102
+ private void checkJobExecuteStatus (ResponseEntity <Map <?, ?> > responseEntity , Map <String , Boolean > jobExecuteStatus ) {
100
103
Map <?, ?> responseData = responseEntity .getBody ();
101
104
if (responseData != null ) {
102
105
List <?> jobs = (List <?>)responseData .get ("jobs" );
@@ -115,13 +118,14 @@ private void checkJobExecuteStatus(ResponseEntity<Map> responseEntity, Map<Strin
115
118
}
116
119
}
117
120
118
-
119
- private List <String > generatedFlinkManagerServerApi () {
121
+ // @VisibleForTesting
122
+ List <String > generatedFlinkManagerServerApi () {
120
123
List <String > flinkServerList = batchConfiguration .getFlinkServerList ();
124
+ int flinkRestPort = batchConfiguration .getFlinkRestPort ();
121
125
List <String > urlList = new ArrayList <>(flinkServerList .size ());
122
126
123
127
for (String flinkServerIp : flinkServerList ) {
124
- urlList .add (String .format (URL_FORMAT , flinkServerIp ));
128
+ urlList .add (String .format (URL_FORMAT , flinkServerIp , flinkRestPort ));
125
129
}
126
130
127
131
return urlList ;
0 commit comments