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.
This commit is contained in:
Nitin Mehta 2014-03-07 16:50:21 -08:00
parent 548c81082b
commit ded7e682dc
5 changed files with 30 additions and 6 deletions

View File

@ -493,10 +493,13 @@ public class EventTypes {
entityEventDetails.put(EVENT_VM_REBOOT, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_VM_UPDATE, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_VM_UPGRADE, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_VM_DYNAMIC_SCALE, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_VM_RESETPASSWORD, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_VM_RESETSSHKEY, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_VM_MIGRATE, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_VM_MOVE, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_VM_RESTORE, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_VM_EXPUNGE, VirtualMachine.class.getName());
entityEventDetails.put(EVENT_ROUTER_CREATE, VirtualRouter.class.getName());
entityEventDetails.put(EVENT_ROUTER_DESTROY, VirtualRouter.class.getName());
@ -544,9 +547,11 @@ public class EventTypes {
entityEventDetails.put(EVENT_LB_CERT_REMOVE, LoadBalancer.class.getName());
// Account events
entityEventDetails.put(EVENT_ACCOUNT_ENABLE, Account.class.getName());
entityEventDetails.put(EVENT_ACCOUNT_DISABLE, Account.class.getName());
entityEventDetails.put(EVENT_ACCOUNT_CREATE, Account.class.getName());
entityEventDetails.put(EVENT_ACCOUNT_DELETE, Account.class.getName());
entityEventDetails.put(EVENT_ACCOUNT_UPDATE, Account.class.getName());
entityEventDetails.put(EVENT_ACCOUNT_MARK_DEFAULT_ZONE, Account.class.getName());
// UserVO Events

View File

@ -21,6 +21,7 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import com.cloud.event.EventTypes;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
@ -82,8 +83,14 @@ public class ApiDispatcher {
final BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmd;
final String startEventId = params.get(ApiConstants.CTX_START_EVENT_ID);
String uuid = params.get("uuid");
ctx.setStartEventId(Long.valueOf(startEventId));
// Fow now use the key from EventTypes.java rather than getInstanceType bcz the later doesn't refer to the interfaces
if(EventTypes.getEntityForEvent(asyncCmd.getEventType()) != null){
ctx.putContextParameter(EventTypes.getEntityForEvent(asyncCmd.getEventType()), uuid);
}
// Synchronise job on the object if needed
if (asyncCmd.getJob() != null && asyncCmd.getSyncObjId() != null && asyncCmd.getSyncObjType() != null) {
Long queueSizeLimit = null;

View File

@ -53,6 +53,7 @@ import javax.naming.ConfigurationException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.cloud.event.EventTypes;
import org.apache.cloudstack.acl.APIChecker;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
@ -517,6 +518,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
objectUuid = createCmd.getEntityUuid();
params.put("id", objectId.toString());
} else {
// Extract the uuid before params are processed and id reflects internal db id
objectUuid = params.get("id");
dispatchChainFactory.getStandardDispatchChain().dispatch(new DispatchTask(cmdObj, params));
}
@ -528,10 +531,16 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
if (caller != null) {
params.put("ctxAccountId", String.valueOf(caller.getId()));
}
if(objectUuid != null){
params.put("uuid", objectUuid);
}
long startEventId = ctx.getStartEventId();
asyncCmd.setStartEventId(startEventId);
if(EventTypes.getEntityForEvent(asyncCmd.getEventType()) != null){
ctx.putContextParameter(EventTypes.getEntityForEvent(asyncCmd.getEventType()), objectUuid);
}
// save the scheduled event
final Long eventId =
ActionEventUtils.onScheduledActionEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(),
@ -577,7 +586,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
!(cmdObj instanceof ListVolumesCmd) && !(cmdObj instanceof ListUsersCmd) && !(cmdObj instanceof ListAccountsCmd) &&
!(cmdObj instanceof ListStoragePoolsCmd) && !(cmdObj instanceof ListDiskOfferingsCmd) && !(cmdObj instanceof ListServiceOfferingsCmd) &&
!(cmdObj instanceof ListZonesByCmd)) {
buildAsyncListResponse((BaseListCmd)cmdObj, caller);
buildAsyncListResponse((BaseListCmd) cmdObj, caller);
}
SerializationContext.current().setUuidTranslation(true);

View File

@ -25,7 +25,6 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import com.cloud.vm.VirtualMachine;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@ -186,13 +185,19 @@ public class ActionEventUtils {
// get the entity details for which ActionEvent is generated
String entityType = null;
String entityUuid = null;
CallContext context = CallContext.current();
Class entityKey = getEntityKey(eventType);
if (entityKey != null)
{
CallContext context = CallContext.current();
//FIXME - Remove this
entityUuid = (String)context.getContextParameter(entityKey);
if (entityUuid != null)
entityType = entityKey.getName();
}else if (EventTypes.getEntityForEvent(eventType) != null){
entityType = EventTypes.getEntityForEvent(eventType);
if (entityType != null){
entityUuid = (String)context.getContextParameter(entityType);
}
}
org.apache.cloudstack.framework.events.Event event =
@ -240,6 +245,7 @@ public class ActionEventUtils {
private static Class getEntityKey(String eventType)
{
// FIXME - Remove this
if (eventType.startsWith("DOMAIN."))
{
return Domain.class;
@ -251,8 +257,6 @@ public class ActionEventUtils {
else if (eventType.startsWith("USER."))
{
return User.class;
}else if (eventType.startsWith("VM.")){
return VirtualMachine.class;
}
return null;

View File

@ -2982,7 +2982,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
long vmId = cmd.getEntityId();
Long hostId = cmd.getHostId();
UserVmVO vm = _vmDao.findById(vmId);
CallContext.current().putContextParameter(VirtualMachine.class, vm.getUuid());
Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> vmParamPair = null;
try {