@@ -163,7 +163,7 @@ private void checkResponseOK(final HttpResponse response) {
163163 if (!(response .getStatusLine ().getStatusCode () == HttpStatus .SC_OK ||
164164 response .getStatusLine ().getStatusCode () == HttpStatus .SC_ACCEPTED ) &&
165165 response .getStatusLine ().getStatusCode () != HttpStatus .SC_NO_CONTENT ) {
166- LOG .debug ("HTTP request failed, status code is " + response .getStatusLine ().getStatusCode () + " , response is: " + response .toString ());
166+ LOG .debug (String . format ( "HTTP request failed, status code is [%s], response is: [%s]." , response .getStatusLine ().getStatusCode (), response .toString () ));
167167 throw new ServerApiException (ApiErrorCode .INTERNAL_ERROR , "Got invalid API status code returned by the Veeam server" );
168168 }
169169 }
@@ -175,10 +175,13 @@ private void checkResponseTimeOut(final Exception e) {
175175 }
176176
177177 private HttpResponse get (final String path ) throws IOException {
178- final HttpGet request = new HttpGet (apiURI .toString () + path );
178+ String url = apiURI .toString () + path ;
179+ final HttpGet request = new HttpGet (url );
179180 request .setHeader (SESSION_HEADER , veeamSessionId );
180181 final HttpResponse response = httpClient .execute (request );
181182 checkAuthFailure (response );
183+
184+ LOG .debug (String .format ("Response received in GET request is: [%s] for URL: [%s]." , response .toString (), url ));
182185 return response ;
183186 }
184187
@@ -193,7 +196,8 @@ private HttpResponse post(final String path, final Object obj) throws IOExceptio
193196 xml = xml .replace (" xmlns=\" \" " , "" );
194197 }
195198
196- final HttpPost request = new HttpPost (apiURI .toString () + path );
199+ String url = apiURI .toString () + path ;
200+ final HttpPost request = new HttpPost (url );
197201 request .setHeader (SESSION_HEADER , veeamSessionId );
198202 request .setHeader ("Content-type" , "application/xml" );
199203 if (StringUtils .isNotBlank (xml )) {
@@ -202,14 +206,19 @@ private HttpResponse post(final String path, final Object obj) throws IOExceptio
202206
203207 final HttpResponse response = httpClient .execute (request );
204208 checkAuthFailure (response );
209+
210+ LOG .debug (String .format ("Response received in POST request with body [%s] is: [%s] for URL [%s]." , xml , response .toString (), url ));
205211 return response ;
206212 }
207213
208214 private HttpResponse delete (final String path ) throws IOException {
209- final HttpDelete request = new HttpDelete (apiURI .toString () + path );
215+ String url = apiURI .toString () + path ;
216+ final HttpDelete request = new HttpDelete (url );
210217 request .setHeader (SESSION_HEADER , veeamSessionId );
211218 final HttpResponse response = httpClient .execute (request );
212219 checkAuthFailure (response );
220+
221+ LOG .debug (String .format ("Response received in DELETE request is: [%s] for URL [%s]." , response .toString (), url ));
213222 return response ;
214223 }
215224
@@ -524,11 +533,18 @@ protected String transformPowerShellCommandList(List<String> cmds) {
524533 */
525534 protected Pair <Boolean , String > executePowerShellCommands (List <String > cmds ) {
526535 try {
527- Pair <Boolean , String > pairResult = SshHelper .sshExecute (veeamServerIp , veeamServerPort ,
536+ String commands = transformPowerShellCommandList (cmds );
537+ Pair <Boolean , String > response = SshHelper .sshExecute (veeamServerIp , veeamServerPort ,
528538 veeamServerUsername , null , veeamServerPassword ,
529- transformPowerShellCommandList (cmds ),
530- 120000 , 120000 , 3600000 );
531- return pairResult ;
539+ commands , 120000 , 120000 , 3600000 );
540+
541+ if (response == null || !response .first ()) {
542+ LOG .error (String .format ("Veeam PowerShell commands [%s] failed due to: [%s]." , commands , response != null ? response .second () : "no PowerShell output returned" ));
543+ } else {
544+ LOG .debug (String .format ("Veeam response for PowerShell commands [%s] is: [%s]." , commands , response .second ()));
545+ }
546+
547+ return response ;
532548 } catch (Exception e ) {
533549 throw new CloudRuntimeException ("Error while executing PowerShell commands due to: " + e .getMessage ());
534550 }
@@ -595,6 +611,7 @@ public Map<String, Backup.Metric> getBackupMetrics() {
595611 }
596612
597613 private Backup .RestorePoint getRestorePointFromBlock (String [] parts ) {
614+ LOG .debug (String .format ("Processing block of restore points: [%s]." , StringUtils .join (parts , ", " )));
598615 String id = null ;
599616 String created = null ;
600617 String type = null ;
@@ -616,18 +633,20 @@ private Backup.RestorePoint getRestorePointFromBlock(String[] parts) {
616633 public List <Backup .RestorePoint > listRestorePoints (String backupName , String vmInternalName ) {
617634 final List <String > cmds = Arrays .asList (
618635 String .format ("$backup = Get-VBRBackup -Name \" %s\" " , backupName ),
619- String .format ("if ($backup) { (Get-VBRRestorePoint -Backup:$backup -Name \" %s\" ^| Where-Object {$_.IsConsistent -eq $true}) }" , vmInternalName )
636+ String .format ("if ($backup) { $restore = (Get-VBRRestorePoint -Backup:$backup -Name \" %s\" ^| Where-Object {$_.IsConsistent -eq $true})" , vmInternalName ),
637+ "if ($restore) { $restore ^| Format-List } }"
620638 );
621639 Pair <Boolean , String > response = executePowerShellCommands (cmds );
622640 final List <Backup .RestorePoint > restorePoints = new ArrayList <>();
623641 if (response == null || !response .first ()) {
624- LOG .debug ("Veeam restore point listing failed due to: " + (response != null ? response .second () : "no powershell output returned" ));
625642 return restorePoints ;
626643 }
644+
627645 for (final String block : response .second ().split ("\r \n \r \n " )) {
628646 if (block .isEmpty ()) {
629647 continue ;
630648 }
649+ LOG .debug (String .format ("Found restore points from [backupName: %s, vmInternalName: %s] which is: [%s]." , backupName , vmInternalName , block ));
631650 final String [] parts = block .split ("\r \n " );
632651 restorePoints .add (getRestorePointFromBlock (parts ));
633652 }
@@ -651,4 +670,4 @@ public Pair<Boolean, String> restoreVMToDifferentLocation(String restorePointId,
651670 }
652671 return new Pair <>(result .first (), restoreLocation );
653672 }
654- }
673+ }
0 commit comments