Skip to content

Commit ded7e68

Browse files
committed
CLOUDSTACK-5478: Enable publishing uuid for all the async apis in the CallContext.
The advantage would be that event publishing can pick up the uuid and publish them.
1 parent 548c810 commit ded7e68

5 files changed

Lines changed: 30 additions & 6 deletions

File tree

api/src/com/cloud/event/EventTypes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,13 @@ public class EventTypes {
493493
entityEventDetails.put(EVENT_VM_REBOOT, VirtualMachine.class.getName());
494494
entityEventDetails.put(EVENT_VM_UPDATE, VirtualMachine.class.getName());
495495
entityEventDetails.put(EVENT_VM_UPGRADE, VirtualMachine.class.getName());
496+
entityEventDetails.put(EVENT_VM_DYNAMIC_SCALE, VirtualMachine.class.getName());
496497
entityEventDetails.put(EVENT_VM_RESETPASSWORD, VirtualMachine.class.getName());
498+
entityEventDetails.put(EVENT_VM_RESETSSHKEY, VirtualMachine.class.getName());
497499
entityEventDetails.put(EVENT_VM_MIGRATE, VirtualMachine.class.getName());
498500
entityEventDetails.put(EVENT_VM_MOVE, VirtualMachine.class.getName());
499501
entityEventDetails.put(EVENT_VM_RESTORE, VirtualMachine.class.getName());
502+
entityEventDetails.put(EVENT_VM_EXPUNGE, VirtualMachine.class.getName());
500503

501504
entityEventDetails.put(EVENT_ROUTER_CREATE, VirtualRouter.class.getName());
502505
entityEventDetails.put(EVENT_ROUTER_DESTROY, VirtualRouter.class.getName());
@@ -544,9 +547,11 @@ public class EventTypes {
544547
entityEventDetails.put(EVENT_LB_CERT_REMOVE, LoadBalancer.class.getName());
545548

546549
// Account events
550+
entityEventDetails.put(EVENT_ACCOUNT_ENABLE, Account.class.getName());
547551
entityEventDetails.put(EVENT_ACCOUNT_DISABLE, Account.class.getName());
548552
entityEventDetails.put(EVENT_ACCOUNT_CREATE, Account.class.getName());
549553
entityEventDetails.put(EVENT_ACCOUNT_DELETE, Account.class.getName());
554+
entityEventDetails.put(EVENT_ACCOUNT_UPDATE, Account.class.getName());
550555
entityEventDetails.put(EVENT_ACCOUNT_MARK_DEFAULT_ZONE, Account.class.getName());
551556

552557
// UserVO Events

server/src/com/cloud/api/ApiDispatcher.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javax.annotation.PostConstruct;
2222
import javax.inject.Inject;
2323

24+
import com.cloud.event.EventTypes;
2425
import org.apache.cloudstack.api.ApiConstants;
2526
import org.apache.cloudstack.api.BaseAsyncCmd;
2627
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
@@ -82,8 +83,14 @@ public void dispatch(final BaseCmd cmd, final Map<String, String> params, final
8283

8384
final BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmd;
8485
final String startEventId = params.get(ApiConstants.CTX_START_EVENT_ID);
86+
String uuid = params.get("uuid");
8587
ctx.setStartEventId(Long.valueOf(startEventId));
8688

89+
// Fow now use the key from EventTypes.java rather than getInstanceType bcz the later doesn't refer to the interfaces
90+
if(EventTypes.getEntityForEvent(asyncCmd.getEventType()) != null){
91+
ctx.putContextParameter(EventTypes.getEntityForEvent(asyncCmd.getEventType()), uuid);
92+
}
93+
8794
// Synchronise job on the object if needed
8895
if (asyncCmd.getJob() != null && asyncCmd.getSyncObjId() != null && asyncCmd.getSyncObjType() != null) {
8996
Long queueSizeLimit = null;

server/src/com/cloud/api/ApiServer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import javax.servlet.http.HttpServletResponse;
5454
import javax.servlet.http.HttpSession;
5555

56+
import com.cloud.event.EventTypes;
5657
import org.apache.cloudstack.acl.APIChecker;
5758
import org.apache.cloudstack.api.APICommand;
5859
import org.apache.cloudstack.api.ApiConstants;
@@ -517,6 +518,8 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
517518
objectUuid = createCmd.getEntityUuid();
518519
params.put("id", objectId.toString());
519520
} else {
521+
// Extract the uuid before params are processed and id reflects internal db id
522+
objectUuid = params.get("id");
520523
dispatchChainFactory.getStandardDispatchChain().dispatch(new DispatchTask(cmdObj, params));
521524
}
522525

@@ -528,10 +531,16 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
528531
if (caller != null) {
529532
params.put("ctxAccountId", String.valueOf(caller.getId()));
530533
}
534+
if(objectUuid != null){
535+
params.put("uuid", objectUuid);
536+
}
531537

532538
long startEventId = ctx.getStartEventId();
533539
asyncCmd.setStartEventId(startEventId);
534540

541+
if(EventTypes.getEntityForEvent(asyncCmd.getEventType()) != null){
542+
ctx.putContextParameter(EventTypes.getEntityForEvent(asyncCmd.getEventType()), objectUuid);
543+
}
535544
// save the scheduled event
536545
final Long eventId =
537546
ActionEventUtils.onScheduledActionEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(),
@@ -577,7 +586,7 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
577586
!(cmdObj instanceof ListVolumesCmd) && !(cmdObj instanceof ListUsersCmd) && !(cmdObj instanceof ListAccountsCmd) &&
578587
!(cmdObj instanceof ListStoragePoolsCmd) && !(cmdObj instanceof ListDiskOfferingsCmd) && !(cmdObj instanceof ListServiceOfferingsCmd) &&
579588
!(cmdObj instanceof ListZonesByCmd)) {
580-
buildAsyncListResponse((BaseListCmd)cmdObj, caller);
589+
buildAsyncListResponse((BaseListCmd) cmdObj, caller);
581590
}
582591

583592
SerializationContext.current().setUuidTranslation(true);

server/src/com/cloud/event/ActionEventUtils.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import javax.annotation.PostConstruct;
2626
import javax.inject.Inject;
2727

28-
import com.cloud.vm.VirtualMachine;
2928
import org.apache.log4j.Logger;
3029
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
3130

@@ -186,13 +185,19 @@ private static void publishOnEventBus(long userId, long accountId, String eventC
186185
// get the entity details for which ActionEvent is generated
187186
String entityType = null;
188187
String entityUuid = null;
188+
CallContext context = CallContext.current();
189189
Class entityKey = getEntityKey(eventType);
190190
if (entityKey != null)
191191
{
192-
CallContext context = CallContext.current();
192+
//FIXME - Remove this
193193
entityUuid = (String)context.getContextParameter(entityKey);
194194
if (entityUuid != null)
195195
entityType = entityKey.getName();
196+
}else if (EventTypes.getEntityForEvent(eventType) != null){
197+
entityType = EventTypes.getEntityForEvent(eventType);
198+
if (entityType != null){
199+
entityUuid = (String)context.getContextParameter(entityType);
200+
}
196201
}
197202

198203
org.apache.cloudstack.framework.events.Event event =
@@ -240,6 +245,7 @@ private static long getDomainId(long accountId) {
240245

241246
private static Class getEntityKey(String eventType)
242247
{
248+
// FIXME - Remove this
243249
if (eventType.startsWith("DOMAIN."))
244250
{
245251
return Domain.class;
@@ -251,8 +257,6 @@ else if (eventType.startsWith("ACCOUNT."))
251257
else if (eventType.startsWith("USER."))
252258
{
253259
return User.class;
254-
}else if (eventType.startsWith("VM.")){
255-
return VirtualMachine.class;
256260
}
257261

258262
return null;

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2982,7 +2982,6 @@ protected UserVm startVirtualMachine(DeployVMCmd cmd, Map<VirtualMachineProfile.
29822982
long vmId = cmd.getEntityId();
29832983
Long hostId = cmd.getHostId();
29842984
UserVmVO vm = _vmDao.findById(vmId);
2985-
CallContext.current().putContextParameter(VirtualMachine.class, vm.getUuid());
29862985

29872986
Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> vmParamPair = null;
29882987
try {

0 commit comments

Comments
 (0)