2121import java .io .FileInputStream ;
2222import java .io .FileOutputStream ;
2323import java .io .OutputStreamWriter ;
24- import java .rmi .RemoteException ;
2524import java .util .ArrayList ;
2625import java .util .HashMap ;
2726import java .util .List ;
8584import com .cloud .storage .template .OVAProcessor ;
8685import com .cloud .utils .NumbersUtil ;
8786import com .cloud .utils .Pair ;
88- import com .cloud .utils .StringUtils ;
8987import com .cloud .utils .Ternary ;
9088import com .cloud .utils .exception .CloudRuntimeException ;
9189import com .cloud .utils .script .Script ;
@@ -96,6 +94,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
9694
9795 private String _nfsVersion ;
9896
97+
9998 @ Override
10099 public boolean execute (VmwareHostService hostService , CreateEntityDownloadURLCommand cmd ) {
101100 DataTO data = cmd .getData ();
@@ -296,13 +295,7 @@ public Answer execute(VmwareHostService hostService, PrimaryStorageDownloadComma
296295
297296 return new PrimaryStorageDownloadAnswer (templateUuidName , 0 );
298297 } catch (Throwable e ) {
299- if (e instanceof RemoteException ) {
300- hostService .invalidateServiceContext (context );
301- }
302-
303- String msg = "Unable to execute PrimaryStorageDownloadCommand due to exception" ;
304- s_logger .error (msg , e );
305- return new PrimaryStorageDownloadAnswer (msg );
298+ return new PrimaryStorageDownloadAnswer (hostService .createLogMessageException (e , cmd ));
306299 }
307300 }
308301
@@ -380,22 +373,14 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd)
380373
381374 try {
382375 if (workerVm != null ) {
383- // detach volume and destroy worker vm
384376 workerVm .detachAllDisksAndDestroy ();
385377 }
386378 } catch (Throwable e ) {
387- s_logger .warn ("Failed to destroy worker VM: " + workerVMName );
379+ s_logger .warn (String . format ( "Failed to destroy worker VM [%s] due to: [%s]." , workerVMName , e . getMessage ()), e );
388380 }
389381 }
390382 } catch (Throwable e ) {
391- if (e instanceof RemoteException ) {
392- hostService .invalidateServiceContext (context );
393- }
394-
395- s_logger .error ("Unexpecpted exception " , e );
396-
397- details = "BackupSnapshotCommand exception: " + StringUtils .getExceptionStackInfo (e );
398- return new BackupSnapshotAnswer (cmd , false , details , snapshotBackupUuid , true );
383+ return new BackupSnapshotAnswer (cmd , false , hostService .createLogMessageException (e , cmd ), snapshotBackupUuid , true );
399384 }
400385
401386 return new BackupSnapshotAnswer (cmd , success , details , snapshotBackupUuid , true );
@@ -433,14 +418,7 @@ public Answer execute(VmwareHostService hostService, CreatePrivateTemplateFromVo
433418 return new CreatePrivateTemplateAnswer (cmd , true , null , result .first (), result .third (), result .second (), cmd .getUniqueName (), ImageFormat .OVA );
434419
435420 } catch (Throwable e ) {
436- if (e instanceof RemoteException ) {
437- hostService .invalidateServiceContext (context );
438- }
439-
440- s_logger .error ("Unexpecpted exception " , e );
441-
442- details = "CreatePrivateTemplateFromVolumeCommand exception: " + StringUtils .getExceptionStackInfo (e );
443- return new CreatePrivateTemplateAnswer (cmd , false , details );
421+ return new CreatePrivateTemplateAnswer (cmd , false , hostService .createLogMessageException (e , cmd ));
444422 }
445423 }
446424
@@ -461,14 +439,7 @@ public Answer execute(VmwareHostService hostService, CreatePrivateTemplateFromSn
461439
462440 return new CreatePrivateTemplateAnswer (cmd , true , null , result .first (), result .third (), result .second (), uniqeName , ImageFormat .OVA );
463441 } catch (Throwable e ) {
464- if (e instanceof RemoteException ) {
465- hostService .invalidateServiceContext (context );
466- }
467-
468- s_logger .error ("Unexpecpted exception " , e );
469-
470- details = "CreatePrivateTemplateFromSnapshotCommand exception: " + StringUtils .getExceptionStackInfo (e );
471- return new CreatePrivateTemplateAnswer (cmd , false , details );
442+ return new CreatePrivateTemplateAnswer (cmd , false , hostService .createLogMessageException (e , cmd ));
472443 }
473444 }
474445
@@ -504,13 +475,7 @@ public Answer execute(VmwareHostService hostService, CopyVolumeCommand cmd) {
504475 }
505476 return new CopyVolumeAnswer (cmd , true , null , result .first (), result .second ());
506477 } catch (Throwable e ) {
507- if (e instanceof RemoteException ) {
508- hostService .invalidateServiceContext (context );
509- }
510-
511- String msg = "Unable to execute CopyVolumeCommand due to exception" ;
512- s_logger .error (msg , e );
513- return new CopyVolumeAnswer (cmd , false , "CopyVolumeCommand failed due to exception: " + StringUtils .getExceptionStackInfo (e ), null , null );
478+ return new CopyVolumeAnswer (cmd , false , hostService .createLogMessageException (e , cmd ), null , null );
514479 }
515480 }
516481
@@ -543,12 +508,7 @@ public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCom
543508 success = true ;
544509 }
545510 } catch (Throwable e ) {
546- if (e instanceof RemoteException ) {
547- hostService .invalidateServiceContext (context );
548- }
549-
550- s_logger .error ("Unexpecpted exception " , e );
551- details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils .getExceptionStackInfo (e );
511+ details = hostService .createLogMessageException (e , cmd );
552512 }
553513
554514 return new CreateVolumeFromSnapshotAnswer (cmd , success , details , newVolumeName );
@@ -946,8 +906,12 @@ private void exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volume
946906 Script command = new Script (false , "mkdir" , _timeout , s_logger );
947907 command .add ("-p" );
948908 command .add (exportPath );
949- if (command .execute () != null ) {
950- throw new Exception ("unable to prepare snapshot backup directory" );
909+
910+ String result = command .execute ();
911+ if (result != null ) {
912+ String errorMessage = String .format ("Unable to prepare snapshot backup directory: [%s] due to [%s]." , exportPath , result );
913+ s_logger .error (errorMessage );
914+ throw new Exception (errorMessage );
951915 }
952916 }
953917 }
@@ -968,7 +932,7 @@ private void exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volume
968932 vmMo .cloneFromCurrentSnapshot (workerVmName , 0 , 4 , volumeDeviceInfo .second (), VmwareHelper .getDiskDeviceDatastore (volumeDeviceInfo .first ()), vmxFormattedVirtualHardwareVersion );
969933 clonedVm = vmMo .getRunningHost ().findVmOnHyperHost (workerVmName );
970934 if (clonedVm == null ) {
971- String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath ;
935+ String msg = String . format ( "Unable to create dummy VM to export volume. volume path: [%s]." , volumePath ) ;
972936 s_logger .error (msg );
973937 throw new Exception (msg );
974938 }
@@ -1033,7 +997,6 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
1033997 vmMo .removeSnapshot (exportName , false );
1034998 }
1035999 if (workerVm != null ) {
1036- //detach volume and destroy worker vm
10371000 workerVm .detachAllDisksAndDestroy ();
10381001 }
10391002 }
0 commit comments