cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject git commit: updated refs/heads/master to f756d4a
Date Tue, 24 Jun 2014 23:33:24 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 3d9eaf075 -> f756d4aa3


Make job info universally available across management server and resource agents


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

Branch: refs/heads/master
Commit: f756d4aa334dfd9b0798a291061c9e1260a2d230
Parents: 3d9eaf0
Author: Kelven Yang <kelveny@gmail.com>
Authored: Mon Jun 23 16:44:59 2014 -0700
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Tue Jun 24 16:28:22 2014 -0700

----------------------------------------------------------------------
 .../cloud/agent/manager/AgentManagerImpl.java   | 21 +++++++++
 .../vmware/resource/VmwareResource.java         | 16 ++++++-
 .../VmwareSecondaryStorageResourceHandler.java  | 47 ++++++++++----------
 3 files changed, 59 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f756d4aa/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
index c0a87ad..fdb88d0 100755
--- a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
@@ -43,6 +43,8 @@ import org.apache.log4j.Logger;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.Configurable;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.framework.jobs.AsyncJob;
+import org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
 
@@ -379,6 +381,18 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager,
Handl
         return !txn.dbTxnStarted();
     }
 
+    private static void tagCommand(Command cmd) {
+        AsyncJobExecutionContext context = AsyncJobExecutionContext.getCurrentExecutionContext();
+        if (context != null && context.getJob() != null) {
+            AsyncJob job = context.getJob();
+
+            if (job.getRelated() != null && !job.getRelated().isEmpty())
+                cmd.setContextParam("job", "job-" + job.getRelated() + "/" + "job-" + job.getId());
+            else
+                cmd.setContextParam("job", "job-" + job.getId());
+        }
+    }
+
     @Override
     public Answer[] send(Long hostId, Commands commands, int timeout) throws AgentUnavailableException,
OperationTimedoutException {
         assert hostId != null : "Who's not checking the agent id before sending?  ... (finger
wagging)";
@@ -408,6 +422,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager,
Handl
             commands.setAnswers(new Answer[0]);
         }
 
+        for (Command cmd : cmds)
+            tagCommand(cmd);
+
         final AgentAttache agent = getAttache(hostId);
         if (agent == null || agent.isClosed()) {
             throw new AgentUnavailableException("agent not logged into this management server",
hostId);
@@ -466,6 +483,10 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager,
Handl
         if (cmds.length == 0) {
             throw new AgentUnavailableException("Empty command set for agent " + agent.getId(),
agent.getId());
         }
+
+        for (Command cmd : cmds)
+            tagCommand(cmd);
+
         Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(),
true);
         req.setSequence(agent.getNextSequence());
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f756d4aa/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 8dc2784..5b49e5b 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -354,6 +354,20 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
         _gson = GsonHelper.getGsonLogger();
     }
 
+    private String getCommandLogTitle(Command cmd) {
+        StringBuffer sb = new StringBuffer();
+        if (_hostName != null) {
+            sb.append(_hostName);
+        }
+
+        if (cmd.getContextParam("job") != null) {
+            sb.append(", ").append(cmd.getContextParam("job"));
+        }
+        sb.append(", cmd: ").append(cmd.getClass().getSimpleName());
+
+        return sb.toString();
+    }
+
     @Override
     public Answer executeRequest(Command cmd) {
 
@@ -361,7 +375,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             s_logger.trace("Begin executeRequest(), cmd: " + cmd.getClass().getSimpleName());
 
         Answer answer = null;
-        NDC.push(_hostName != null ? _hostName : _guid + "(" + this.getClass().getPackage().getImplementationVersion()
+ ")");
+        NDC.push(getCommandLogTitle(cmd));
         try {
             long cmdSequence = _cmdSequence++;
             Date startTime = DateUtil.currentGMTTime();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f756d4aa/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
index f633774..e67fed6 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
@@ -19,6 +19,7 @@ package com.cloud.storage.resource;
 import java.util.List;
 
 import org.apache.log4j.Logger;
+import org.apache.log4j.NDC;
 
 import com.google.gson.Gson;
 import com.vmware.vim25.ManagedObjectReference;
@@ -77,11 +78,27 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
         storageSubsystemHandler = vmwareStorageSubsystemCommandHandler;
     }
 
+    private static String getCommandLogTitle(Command cmd) {
+        StringBuffer sb = new StringBuffer();
+        if (cmd.getContextParam("job") != null) {
+            sb.append(cmd.getContextParam("job"));
+        }
+
+        sb.append(", cmd: ").append(cmd.getClass().getSimpleName());
+
+        return sb.toString();
+    }
+
     @Override
     public Answer executeRequest(Command cmd) {
 
         try {
             Answer answer;
+            NDC.push(getCommandLogTitle(cmd));
+
+            if (s_logger.isDebugEnabled())
+                s_logger.debug("Executing " + _gson.toJson(cmd));
+
             if (cmd instanceof PrimaryStorageDownloadCommand) {
                 answer = execute((PrimaryStorageDownloadCommand)cmd);
             } else if (cmd instanceof BackupSnapshotCommand) {
@@ -115,9 +132,15 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
                 answer.setContextParam("checkpoint2", cmd.getContextParam("checkpoint2"));
             }
 
+            if (s_logger.isDebugEnabled())
+                s_logger.debug("Command execution answer: " + _gson.toJson(answer));
+
             return answer;
         } finally {
+            if (s_logger.isDebugEnabled())
+                s_logger.debug("Done executing " + _gson.toJson(cmd));
             recycleServiceContext();
+            NDC.pop();
         }
     }
 
@@ -127,50 +150,26 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
     }
 
     private Answer execute(PrimaryStorageDownloadCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource PrimaryStorageDownloadCommand: " + _gson.toJson(cmd));
-        }
-
         return _storageMgr.execute(this, cmd);
     }
 
     private Answer execute(BackupSnapshotCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource BackupSnapshotCommand: " + _gson.toJson(cmd));
-        }
-
         return _storageMgr.execute(this, cmd);
     }
 
     private Answer execute(CreatePrivateTemplateFromVolumeCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource CreatePrivateTemplateFromVolumeCommand: "
+ _gson.toJson(cmd));
-        }
-
         return _storageMgr.execute(this, cmd);
     }
 
     private Answer execute(CreatePrivateTemplateFromSnapshotCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource CreatePrivateTemplateFromVolumeCommand: "
+ _gson.toJson(cmd));
-        }
-
         return _storageMgr.execute(this, cmd);
     }
 
     private Answer execute(CopyVolumeCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource CopyVolumeCommand: " + _gson.toJson(cmd));
-        }
-
         return _storageMgr.execute(this, cmd);
     }
 
     private Answer execute(CreateVolumeFromSnapshotCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource CreateVolumeFromSnapshotCommand: " + _gson.toJson(cmd));
-        }
-
         return _storageMgr.execute(this, cmd);
     }
 


Mime
View raw message