17
17
18
18
package org .apache .gobblin .service .modules .orchestration ;
19
19
20
- import com .github .rholder .retry .AttemptTimeLimiters ;
21
- import com .github .rholder .retry .RetryException ;
22
- import com .github .rholder .retry .Retryer ;
23
- import com .github .rholder .retry .RetryerBuilder ;
24
- import com .github .rholder .retry .StopStrategies ;
25
- import com .github .rholder .retry .WaitStrategies ;
26
- import com .google .common .base .Preconditions ;
27
- import com .google .common .base .Throwables ;
28
- import com .google .common .io .Closer ;
29
- import com .google .gson .Gson ;
30
- import com .google .gson .JsonElement ;
31
- import com .google .gson .JsonObject ;
32
- import com .google .gson .JsonParser ;
33
20
import java .io .Closeable ;
34
21
import java .io .File ;
35
22
import java .io .IOException ;
42
29
import java .util .concurrent .ExecutorService ;
43
30
import java .util .concurrent .Executors ;
44
31
import java .util .concurrent .TimeUnit ;
45
- import lombok . Builder ;
32
+
46
33
import org .apache .commons .io .IOUtils ;
47
34
import org .apache .commons .lang3 .ObjectUtils ;
48
35
import org .apache .commons .lang3 .StringUtils ;
61
48
import org .slf4j .Logger ;
62
49
import org .slf4j .LoggerFactory ;
63
50
51
+ import com .github .rholder .retry .Attempt ;
52
+ import com .github .rholder .retry .AttemptTimeLimiters ;
53
+ import com .github .rholder .retry .RetryException ;
54
+ import com .github .rholder .retry .RetryListener ;
55
+ import com .github .rholder .retry .Retryer ;
56
+ import com .github .rholder .retry .RetryerBuilder ;
57
+ import com .github .rholder .retry .StopStrategies ;
58
+ import com .github .rholder .retry .WaitStrategies ;
59
+ import com .google .common .base .Preconditions ;
60
+ import com .google .common .base .Throwables ;
61
+ import com .google .common .io .Closer ;
62
+ import com .google .gson .Gson ;
63
+ import com .google .gson .JsonElement ;
64
+ import com .google .gson .JsonObject ;
65
+ import com .google .gson .JsonParser ;
66
+
67
+ import lombok .Builder ;
68
+
64
69
65
70
/**
66
71
* A simple http based client that uses Ajax API to communicate with Azkaban server.
@@ -80,9 +85,9 @@ public class AzkabanClient implements Closeable {
80
85
protected CloseableHttpClient httpClient ;
81
86
private ExecutorService executorService ;
82
87
private Closer closer = Closer .create ();
83
- private Retryer <AzkabanClientStatus > retryer ;
84
- private static Logger log = LoggerFactory .getLogger (AzkabanClient .class );
85
- private Duration requestTimeout ;
88
+ private Retryer <AzkabanClientStatus <?> > retryer ;
89
+ private static final Logger log = LoggerFactory .getLogger (AzkabanClient .class );
90
+ private final Duration requestTimeout ;
86
91
87
92
/**
88
93
* Child class should have a different builderMethodName.
@@ -109,13 +114,25 @@ protected AzkabanClient(String username,
109
114
this .initializeClient ();
110
115
this .initializeSessionManager ();
111
116
this .intializeExecutorService ();
117
+ RetryListener retryListener = new RetryListener () {
118
+ @ Override
119
+ public <V > void onRetry (Attempt <V > attempt ) {
120
+ if (attempt .hasException ()) {
121
+ String msg = String .format ("(Likely retryable) failure running Azkaban API [attempt: %d; %s after start]" ,
122
+ attempt .getAttemptNumber (), Duration .ofMillis (attempt .getDelaySinceFirstAttempt ()).toString ());
123
+ log .warn (msg , attempt .getExceptionCause ());
124
+ }
125
+ }
126
+ };
127
+
112
128
113
- this .retryer = RetryerBuilder .<AzkabanClientStatus >newBuilder ()
129
+ this .retryer = RetryerBuilder .<AzkabanClientStatus <?> >newBuilder ()
114
130
.retryIfExceptionOfType (InvalidSessionException .class )
115
131
.withAttemptTimeLimiter (AttemptTimeLimiters .fixedTimeLimit (this .requestTimeout .toMillis (), TimeUnit .MILLISECONDS ,
116
132
this .executorService ))
117
133
.withWaitStrategy (WaitStrategies .exponentialWait (60 , TimeUnit .SECONDS ))
118
134
.withStopStrategy (StopStrategies .stopAfterAttempt (3 ))
135
+ .withRetryListener (retryListener )
119
136
.build ();
120
137
try {
121
138
this .sessionId = this .sessionManager .fetchSession ();
0 commit comments