@@ -345,26 +345,7 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException
345345 String type = pair .second ();
346346 String path = url .replace (apiURI .toString (), "" );
347347 if (type .equals ("RestoreSession" )) {
348- for (int j = 0 ; j < restoreTimeout ; j ++) {
349- HttpResponse relatedResponse = get (path );
350- RestoreSession session = parseRestoreSessionResponse (relatedResponse );
351- if (session .getResult ().equals ("Success" )) {
352- return true ;
353- }
354- if (session .getResult ().equalsIgnoreCase ("Failed" )) {
355- String sessionUid = session .getUid ();
356- LOG .error (String .format ("Failed to restore backup [%s] of VM [%s] due to [%s]." ,
357- sessionUid , session .getVmDisplayName (),
358- getRestoreVmErrorDescription (StringUtils .substringAfterLast (sessionUid , ":" ))));
359- throw new CloudRuntimeException (String .format ("Restore job [%s] failed." , sessionUid ));
360- }
361- LOG .debug (String .format ("Waiting %s seconds, out of a total of %s seconds, for the backup process to finish." , j , restoreTimeout ));
362- try {
363- Thread .sleep (1000 );
364- } catch (InterruptedException ignored ) {
365- }
366- }
367- throw new CloudRuntimeException ("Related job type: " + type + " was not successful" );
348+ checkIfRestoreSessionFinished (type , path );
368349 }
369350 }
370351 return true ;
@@ -380,17 +361,29 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException
380361 return false ;
381362 }
382363
364+
365+ /**
366+ * Checks the status of the restore session. Checked states are "Success" and "Failure".<br/>
367+ * There is also a timeout defined in the global configuration, backup.plugin.veeam.restore.timeout,<br/>
368+ * that is used to wait for the restore to complete before throwing a {@link CloudRuntimeException}.
369+ */
383370 protected boolean checkIfRestoreSessionFinished (String type , String path ) throws IOException {
384- for (int j = 0 ; j < this . restoreTimeout ; j ++) {
371+ for (int j = 0 ; j < restoreTimeout ; j ++) {
385372 HttpResponse relatedResponse = get (path );
386373 RestoreSession session = parseRestoreSessionResponse (relatedResponse );
387374 if (session .getResult ().equals ("Success" )) {
388375 return true ;
389376 }
377+
390378 if (session .getResult ().equalsIgnoreCase ("Failed" )) {
391379 String sessionUid = session .getUid ();
380+ LOG .error (String .format ("Failed to restore backup [%s] of VM [%s] due to [%s]." ,
381+ sessionUid , session .getVmDisplayName (),
382+ getRestoreVmErrorDescription (StringUtils .substringAfterLast (sessionUid , ":" ))));
392383 throw new CloudRuntimeException (String .format ("Restore job [%s] failed." , sessionUid ));
393384 }
385+ LOG .debug (String .format ("Waiting %s seconds, out of a total of %s seconds, for the backup process to finish." , j , restoreTimeout ));
386+
394387 try {
395388 Thread .sleep (1000 );
396389 } catch (InterruptedException ignored ) {
0 commit comments