@@ -94,10 +94,13 @@ public class VeeamClient {
94
94
private String veeamServerUsername ;
95
95
private String veeamServerPassword ;
96
96
private String veeamSessionId = null ;
97
+ private int restoreTimeout ;
97
98
private final int veeamServerPort = 22 ;
98
99
99
- public VeeamClient (final String url , final String username , final String password , final boolean validateCertificate , final int timeout ) throws URISyntaxException , NoSuchAlgorithmException , KeyManagementException {
100
+ public VeeamClient (final String url , final String username , final String password , final boolean validateCertificate , final int timeout ,
101
+ final int restoreTimeout ) throws URISyntaxException , NoSuchAlgorithmException , KeyManagementException {
100
102
this .apiURI = new URI (url );
103
+ this .restoreTimeout = restoreTimeout ;
101
104
102
105
final RequestConfig config = RequestConfig .custom ()
103
106
.setConnectTimeout (timeout * 1000 )
@@ -173,7 +176,7 @@ private void checkResponseTimeOut(final Exception e) {
173
176
}
174
177
}
175
178
176
- private HttpResponse get (final String path ) throws IOException {
179
+ protected HttpResponse get (final String path ) throws IOException {
177
180
String url = apiURI .toString () + path ;
178
181
final HttpGet request = new HttpGet (url );
179
182
request .setHeader (SESSION_HEADER , veeamSessionId );
@@ -274,7 +277,7 @@ private Task parseTaskResponse(HttpResponse response) throws IOException {
274
277
return objectMapper .readValue (response .getEntity ().getContent (), Task .class );
275
278
}
276
279
277
- private RestoreSession parseRestoreSessionResponse (HttpResponse response ) throws IOException {
280
+ protected RestoreSession parseRestoreSessionResponse (HttpResponse response ) throws IOException {
278
281
checkResponseOK (response );
279
282
final ObjectMapper objectMapper = new XmlMapper ();
280
283
return objectMapper .readValue (response .getEntity ().getContent (), RestoreSession .class );
@@ -297,18 +300,7 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException
297
300
String type = pair .second ();
298
301
String path = url .replace (apiURI .toString (), "" );
299
302
if (type .equals ("RestoreSession" )) {
300
- for (int j = 0 ; j < 120 ; j ++) {
301
- HttpResponse relatedResponse = get (path );
302
- RestoreSession session = parseRestoreSessionResponse (relatedResponse );
303
- if (session .getResult ().equals ("Success" )) {
304
- return true ;
305
- }
306
- try {
307
- Thread .sleep (5000 );
308
- } catch (InterruptedException ignored ) {
309
- }
310
- }
311
- throw new CloudRuntimeException ("Related job type: " + type + " was not successful" );
303
+ return checkIfRestoreSessionFinished (type , path );
312
304
}
313
305
}
314
306
return true ;
@@ -324,6 +316,22 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException
324
316
return false ;
325
317
}
326
318
319
+ protected boolean checkIfRestoreSessionFinished (String type , String path ) throws IOException {
320
+ for (int j = 0 ; j < this .restoreTimeout ; j ++) {
321
+ HttpResponse relatedResponse = get (path );
322
+ RestoreSession session = parseRestoreSessionResponse (relatedResponse );
323
+ if (session .getResult ().equals ("Success" )) {
324
+ return true ;
325
+ }
326
+ try {
327
+ Thread .sleep (1000 );
328
+ } catch (InterruptedException ignored ) {
329
+ LOG .trace (String .format ("Ignoring InterruptedException [%s] when waiting for restore session finishes." , ignored .getMessage ()));
330
+ }
331
+ }
332
+ throw new CloudRuntimeException ("Related job type: " + type + " was not successful" );
333
+ }
334
+
327
335
private Pair <String , String > getRelatedLinkPair (List <Link > links ) {
328
336
for (Link link : links ) {
329
337
if (link .getRel ().equals ("Related" )) {
0 commit comments