@@ -94,10 +94,13 @@ public class VeeamClient {
9494 private String veeamServerUsername ;
9595 private String veeamServerPassword ;
9696 private String veeamSessionId = null ;
97+ private int restoreTimeout ;
9798 private final int veeamServerPort = 22 ;
9899
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 {
100102 this .apiURI = new URI (url );
103+ this .restoreTimeout = restoreTimeout ;
101104
102105 final RequestConfig config = RequestConfig .custom ()
103106 .setConnectTimeout (timeout * 1000 )
@@ -173,7 +176,7 @@ private void checkResponseTimeOut(final Exception e) {
173176 }
174177 }
175178
176- private HttpResponse get (final String path ) throws IOException {
179+ protected HttpResponse get (final String path ) throws IOException {
177180 String url = apiURI .toString () + path ;
178181 final HttpGet request = new HttpGet (url );
179182 request .setHeader (SESSION_HEADER , veeamSessionId );
@@ -274,7 +277,7 @@ private Task parseTaskResponse(HttpResponse response) throws IOException {
274277 return objectMapper .readValue (response .getEntity ().getContent (), Task .class );
275278 }
276279
277- private RestoreSession parseRestoreSessionResponse (HttpResponse response ) throws IOException {
280+ protected RestoreSession parseRestoreSessionResponse (HttpResponse response ) throws IOException {
278281 checkResponseOK (response );
279282 final ObjectMapper objectMapper = new XmlMapper ();
280283 return objectMapper .readValue (response .getEntity ().getContent (), RestoreSession .class );
@@ -297,18 +300,7 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException
297300 String type = pair .second ();
298301 String path = url .replace (apiURI .toString (), "" );
299302 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 );
312304 }
313305 }
314306 return true ;
@@ -324,6 +316,22 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException
324316 return false ;
325317 }
326318
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+
327335 private Pair <String , String > getRelatedLinkPair (List <Link > links ) {
328336 for (Link link : links ) {
329337 if (link .getRel ().equals ("Related" )) {
0 commit comments