5454import javax .servlet .http .HttpSession ;
5555
5656import com .cloud .event .EventTypes ;
57+ import com .cloud .utils .ReflectUtil ;
58+ import com .cloud .vm .VirtualMachine ;
5759import org .apache .cloudstack .acl .APIChecker ;
5860import org .apache .cloudstack .api .APICommand ;
5961import org .apache .cloudstack .api .ApiConstants ;
@@ -503,6 +505,7 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
503505 final CallContext ctx = CallContext .current ();
504506 final Long callerUserId = ctx .getCallingUserId ();
505507 final Account caller = ctx .getCallingAccount ();
508+ String vmUUID = params .get (ApiConstants .VIRTUAL_MACHINE_ID );
506509
507510 // Queue command based on Cmd super class:
508511 // BaseCmd: cmd is dispatched to ApiDispatcher, executed, serialized and returned.
@@ -519,7 +522,7 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
519522 params .put ("id" , objectId .toString ());
520523 } else {
521524 // Extract the uuid before params are processed and id reflects internal db id
522- objectUuid = params .get ("id" );
525+ objectUuid = params .get (ApiConstants . ID );
523526 dispatchChainFactory .getStandardDispatchChain ().dispatch (new DispatchTask (cmdObj , params ));
524527 }
525528
@@ -538,9 +541,15 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
538541 long startEventId = ctx .getStartEventId ();
539542 asyncCmd .setStartEventId (startEventId );
540543
544+ // Add the resource id in the call context, also add some other first class object ids (for now vm) if available.
545+ // TODO - this should be done for all the uuids passed in the cmd - so should be moved where uuid to id conversion happens.
541546 if (EventTypes .getEntityForEvent (asyncCmd .getEventType ()) != null ){
542547 ctx .putContextParameter (EventTypes .getEntityForEvent (asyncCmd .getEventType ()), objectUuid );
543548 }
549+ if (vmUUID != null ){
550+ ctx .putContextParameter (ReflectUtil .getEntityName (VirtualMachine .class ), vmUUID );
551+ }
552+
544553 // save the scheduled event
545554 final Long eventId =
546555 ActionEventUtils .onScheduledActionEvent ((callerUserId == null ) ? User .UID_SYSTEM : callerUserId , asyncCmd .getEntityOwnerId (), asyncCmd .getEventType (),
0 commit comments