@@ -933,16 +933,21 @@ public void start(final String vmUuid, final Map<VirtualMachineProfile.Param, Ob
933933 try {
934934 advanceStart (vmUuid , params , planToDeploy , planner );
935935 } catch (ConcurrentOperationException e ) {
936- throw new CloudRuntimeException (String .format ("Unable to start a VM [%s] due to [%s]." , vmUuid , e .getMessage ()), e ).add (VirtualMachine .class , vmUuid );
936+ final CallContext cctxt = CallContext .current ();
937+ final Account account = cctxt .getCallingAccount ();
938+ if (canExposeError (account )) {
939+ throw new CloudRuntimeException (String .format ("Unable to start a VM [%s] due to [%s]." , vmUuid , e .getMessage ()), e ).add (VirtualMachine .class , vmUuid );
940+ }
941+ throw new CloudRuntimeException (String .format ("Unable to start a VM [%s] due to concurrent operation." , vmUuid ), e ).add (VirtualMachine .class , vmUuid );
937942 } catch (final InsufficientCapacityException e ) {
938943 final CallContext cctxt = CallContext .current ();
939944 final Account account = cctxt .getCallingAccount ();
940- if (account . getType () == Account . Type . ADMIN ) {
941- throw new CloudRuntimeException ("Unable to start a VM due to insufficient capacity: " + e .getMessage (), e ).add (VirtualMachine .class , vmUuid );
945+ if (canExposeError ( account ) ) {
946+ throw new CloudRuntimeException (String . format ( "Unable to start a VM [%s] due to [%s]." , vmUuid , e .getMessage () ), e ).add (VirtualMachine .class , vmUuid );
942947 }
943- throw new CloudRuntimeException (String .format ("Unable to start a VM [%s] due to [%s] ." , vmUuid , e . getMessage () ), e ).add (VirtualMachine .class , vmUuid );
948+ throw new CloudRuntimeException (String .format ("Unable to start a VM [%s] due to insufficient capacity ." , vmUuid ), e ).add (VirtualMachine .class , vmUuid );
944949 } catch (final ResourceUnavailableException e ) {
945- if (e .getScope () != null && e .getScope ().equals (VirtualRouter .class )){
950+ if (e .getScope () != null && e .getScope ().equals (VirtualRouter .class )) {
946951 throw new CloudRuntimeException ("Network is unavailable. Please contact administrator" , e ).add (VirtualMachine .class , vmUuid );
947952 }
948953 throw new CloudRuntimeException (String .format ("Unable to start a VM [%s] due to [%s]." , vmUuid , e .getMessage ()), e ).add (VirtualMachine .class , vmUuid );
@@ -1461,7 +1466,7 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
14611466 continue ;
14621467 }
14631468 String message = String .format ("Unable to create a deployment for %s after %s attempts" , vmProfile , attemptNumber );
1464- if ((account . getType () == Account . Type . ADMIN || Boolean . TRUE . equals ( EXPOSE_ERRORS_TO_USER . value ()) ) && lastKnownError != null ) {
1469+ if (canExposeError (account ) && lastKnownError != null ) {
14651470 message += String .format (" Last known error: %s" , lastKnownError .getMessage ());
14661471 throw new CloudRuntimeException (message , lastKnownError );
14671472 } else {
@@ -1711,7 +1716,7 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
17111716 if (startedVm == null ) {
17121717 String messageTmpl = "Unable to start Instance '%s' (%s)%s" ;
17131718 String details ;
1714- if ((account . getType () == Account . Type . ADMIN || Boolean . TRUE . equals ( EXPOSE_ERRORS_TO_USER . value ()) ) && lastKnownError != null ) {
1719+ if (canExposeError (account ) && lastKnownError != null ) {
17151720 details = ": " + lastKnownError .getMessage ();
17161721 } else {
17171722 details = ", see management server log for details" ;
@@ -1721,6 +1726,10 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
17211726 }
17221727 }
17231728
1729+ private boolean canExposeError (Account account ) {
1730+ return (account != null && account .getType () == Account .Type .ADMIN ) || Boolean .TRUE .equals (EXPOSE_ERRORS_TO_USER .value ());
1731+ }
1732+
17241733 protected void updateStartCommandWithExternalDetails (Host host , VirtualMachineTO vmTO , StartCommand command ) {
17251734 if (!HypervisorType .External .equals (host .getHypervisorType ())) {
17261735 return ;
0 commit comments