Repository: cloudstack
Updated Branches:
  refs/heads/master 120e1cc93 -> f888e93e4


CLOUDSTACK-8816 Fixed entityUuid missing in some cases is events

context parameters is Map<object,Object>. This has been used
interchangeably with String and class object resulting the param value
not being available in some cases if its put with object and get with
class.forName()

made the put and get consistent by using Object as key everywhere.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/37c3451a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/37c3451a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/37c3451a

Branch: refs/heads/master
Commit: 37c3451aaee5ca8ae385cd62a1b9f37cc44ad3fe
Parents: 28d18dc
Author: Rajani Karuturi <[email protected]>
Authored: Mon Sep 7 17:12:49 2015 +0530
Committer: Rajani Karuturi <[email protected]>
Committed: Wed Sep 9 14:23:27 2015 +0530

----------------------------------------------------------------------
 server/src/com/cloud/api/ApiServer.java         | 15 ++++----
 .../cloud/api/dispatch/ParamProcessWorker.java  |  4 +--
 .../src/com/cloud/event/ActionEventUtils.java   | 38 ++++----------------
 .../storage/snapshot/SnapshotManagerImpl.java   |  2 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java  |  2 +-
 5 files changed, 18 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37c3451a/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java 
b/server/src/com/cloud/api/ApiServer.java
index 4da8b1e..1459dc2 100644
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -277,11 +277,10 @@ public class ApiServer extends ManagerBase implements 
HttpRequestHandler, ApiSer
             }
         }
         // For some reason, the instanceType / instanceId are not abstract, 
which means we may get null values.
-        org.apache.cloudstack.framework.events.Event event = new 
org.apache.cloudstack.framework.events.Event(
-                "management-server",
-                EventCategory.ASYNC_JOB_CHANGE_EVENT.getName(),
-                jobEvent,
-                (job.getInstanceType() != null ? 
job.getInstanceType().toString() : "unknown"), null);
+        String instanceType = job.getInstanceType() != null ? 
job.getInstanceType() : "unknown";
+        String instanceUuid = job.getInstanceId() != null ? 
ApiDBUtils.findJobInstanceUuid(job) : "";
+        org.apache.cloudstack.framework.events.Event event = new 
org.apache.cloudstack.framework.events.Event("management-server", 
EventCategory.ASYNC_JOB_CHANGE_EVENT.getName(),
+                jobEvent, instanceType, instanceUuid);
 
         Map<String, String> eventDescription = new HashMap<String, String>();
         eventDescription.put("command", job.getCmd());
@@ -289,8 +288,8 @@ public class ApiServer extends ManagerBase implements 
HttpRequestHandler, ApiSer
         eventDescription.put("account", jobOwner.getUuid());
         eventDescription.put("processStatus", "" + job.getProcessStatus());
         eventDescription.put("resultCode", "" + job.getResultCode());
-        eventDescription.put("instanceUuid", (job.getInstanceId() != null ? 
ApiDBUtils.findJobInstanceUuid(job) : "" ) );
-        eventDescription.put("instanceType", (job.getInstanceType() != null ? 
job.getInstanceType().toString() : "unknown"));
+        eventDescription.put("instanceUuid", instanceUuid);
+        eventDescription.put("instanceType", instanceType);
         eventDescription.put("commandEventType", cmdEventType);
         eventDescription.put("jobId", job.getUuid());
         eventDescription.put("jobResult", job.getResult());
@@ -638,7 +637,7 @@ public class ApiServer extends ManagerBase implements 
HttpRequestHandler, ApiSer
                 params.put("id", objectId.toString());
                 Class entityClass = 
EventTypes.getEntityClassForEvent(createCmd.getEventType());
                 if (entityClass != null)
-                    ctx.putContextParameter(entityClass.getName(), objectUuid);
+                    ctx.putContextParameter(entityClass, objectUuid);
             } else {
                 // Extract the uuid before params are processed and id 
reflects internal db id
                 objectUuid = params.get(ApiConstants.ID);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37c3451a/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/dispatch/ParamProcessWorker.java 
b/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
index eb3b77a..3c81ff6 100644
--- a/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
+++ b/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
@@ -410,7 +410,7 @@ public class ParamProcessWorker implements DispatchWorker {
             if (internalId != null){
                 // Populate CallContext for each of the entity.
                 for (final Class<?> entity : entities) {
-                    
CallContext.current().putContextParameter(entity.getName(), internalId);
+                    CallContext.current().putContextParameter(entity, 
internalId);
                 }
                 return internalId;
             }
@@ -434,7 +434,7 @@ public class ParamProcessWorker implements DispatchWorker {
             }
             // Return on first non-null Id for the uuid entity
             if (internalId != null){
-                CallContext.current().putContextParameter(entity.getName(), 
uuid);
+                CallContext.current().putContextParameter(entity, uuid);
                 break;
             }
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37c3451a/server/src/com/cloud/event/ActionEventUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/ActionEventUtils.java 
b/server/src/com/cloud/event/ActionEventUtils.java
index 2ac4303..29eade2 100644
--- a/server/src/com/cloud/event/ActionEventUtils.java
+++ b/server/src/com/cloud/event/ActionEventUtils.java
@@ -37,7 +37,6 @@ import org.apache.cloudstack.framework.events.EventBus;
 import org.apache.cloudstack.framework.events.EventBusException;
 
 import com.cloud.configuration.Config;
-import com.cloud.domain.Domain;
 import com.cloud.event.dao.EventDao;
 import com.cloud.server.ManagementService;
 import com.cloud.user.Account;
@@ -204,20 +203,15 @@ public class ActionEventUtils {
         String entityType = null;
         String entityUuid = null;
         CallContext context = CallContext.current();
-        Class<?> entityKey = getEntityKey(eventType);
-        if (entityKey != null){
-            //FIXME - Remove this since it should be covered by the else if 
condition below.
-            entityUuid = (String)context.getContextParameter(entityKey);
-            if (entityUuid != null)
-                entityType = entityKey.getName();
-        }else if (EventTypes.getEntityClassForEvent(eventType) != null){
-            //Get entity Class(Example - VirtualMachine.class) from the event 
Type eg. - VM.CREATE
-            Class<?> entityClass = 
EventTypes.getEntityClassForEvent(eventType);
-
+        //Get entity Class(Example - VirtualMachine.class) from the event Type 
eg. - VM.CREATE
+        Class<?> entityClass = EventTypes.getEntityClassForEvent(eventType);
+        if (entityClass != null){
             //Get uuid from id
-            if(context.getContextParameter(entityClass.getName()) != null){
+            Object param = context.getContextParameter(entityClass);
+            if(param != null){
                 try {
-                    entityUuid = getEntityUuid(entityClass, 
context.getContextParameter(entityClass.getName()));
+                    entityUuid = getEntityUuid(entityClass, param);
+                    entityType = entityClass.getName();
                 } catch (Exception e){
                     s_logger.debug("Caught exception while finding entityUUID, 
moving on");
                 }
@@ -312,22 +306,4 @@ public class ActionEventUtils {
 
     }
 
-    private static Class<?> getEntityKey(String eventType)
-    {
-        // FIXME - Remove this
-        if (eventType.startsWith("DOMAIN."))
-        {
-            return Domain.class;
-        }
-        else if (eventType.startsWith("ACCOUNT."))
-        {
-            return Account.class;
-        }
-        else if (eventType.startsWith("USER."))
-        {
-            return User.class;
-        }
-
-        return null;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37c3451a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java 
b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index c622c55..8a21014 100644
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -777,7 +777,7 @@ public class SnapshotManagerImpl extends ManagerBase 
implements SnapshotManager,
 
         }
         // TODO - Make createSnapshotPolicy - BaseAsyncCreate and remove this.
-        
CallContext.current().putContextParameter(SnapshotPolicy.class.getName(), 
policy.getUuid());
+        CallContext.current().putContextParameter(SnapshotPolicy.class, 
policy.getUuid());
         return policy;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37c3451a/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java 
b/server/src/com/cloud/vm/UserVmManagerImpl.java
index ee87ab4..97eceaf 100644
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -1212,7 +1212,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
         if (guestNic == null) {
             throw new CloudRuntimeException("Unable to add NIC to " + 
vmInstance);
         }
-        CallContext.current().putContextParameter(Nic.class.getName(), 
guestNic.getUuid());
+        CallContext.current().putContextParameter(Nic.class, 
guestNic.getUuid());
         s_logger.debug("Successful addition of " + network + " from " + 
vmInstance);
         return _vmDao.findById(vmInstance.getId());
     }

Reply via email to