diff --git a/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml b/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
index 880002cd538..0c76f008c32 100644
--- a/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
+++ b/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
@@ -20,11 +20,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:util="http://www.springframework.org/schema/util"
+
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/aop
+ http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util-3.0.xsd"
>
+
+
+
+
+
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 164457ae682..841721df36c 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -4122,6 +4122,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
return null;
}
+ //
+ // TODO build a common pattern to reduce code duplication in following methods
+ // no time for this at current iteration
+ //
public Outcome startVmThroughJobQueue(final String vmUuid,
final Map params,
final DeploymentPlan planToDeploy) {
@@ -4166,7 +4170,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// Transaction syntax sugar has a cost here
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4216,7 +4220,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4268,7 +4272,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4318,7 +4322,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4372,7 +4376,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4383,10 +4387,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VirtualMachine.PowerState.PowerOn, vm.getId(), destHostId);
}
- //
- // TODO build a common pattern to reduce code duplication in following methods
- // no time for this at current iteration
- //
public Outcome migrateVmForScaleThroughJobQueue(
final String vmUuid, final long srcHostId, final DeployDestination dest, final Long newSvcOfferingId) {
@@ -4429,7 +4429,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4481,7 +4481,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4531,7 +4531,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4581,7 +4581,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4631,7 +4631,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
@@ -4683,7 +4683,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
- context.putContextParameter("jobId", new Long(vm.getId()));
+ context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
diff --git a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
index 2a080f90f18..bcb218a979a 100644
--- a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
+++ b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
@@ -158,7 +158,9 @@
-
+
+
+
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
index a113558882c..1f1c8aaa549 100644
--- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
@@ -72,8 +72,8 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
@Inject
protected AsyncJobDao _asyncJobDao;
- @Inject
protected AsyncJobDispatcher _asyncDispatcher;
+
@Inject protected SnapshotDao _snapshotDao;
@Inject protected SnapshotScheduleDao _snapshotScheduleDao;
@Inject protected SnapshotPolicyDao _snapshotPolicyDao;
@@ -86,7 +86,15 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
private Timer _testClockTimer;
private Date _currentTimestamp;
private TestClock _testTimerTask;
-
+
+ public AsyncJobDispatcher getAsyncJobDispatcher() {
+ return _asyncDispatcher;
+ }
+
+ public void setAsyncJobDispatcher(AsyncJobDispatcher dispatcher) {
+ _asyncDispatcher = dispatcher;
+ }
+
private Date getNextScheduledTime(long policyId, Date currentTimestamp) {
SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId);
Date nextTimestamp = null;
diff --git a/server/src/com/cloud/vm/SystemVmLoadScanner.java b/server/src/com/cloud/vm/SystemVmLoadScanner.java
index 6e5521632c2..11416648e09 100644
--- a/server/src/com/cloud/vm/SystemVmLoadScanner.java
+++ b/server/src/com/cloud/vm/SystemVmLoadScanner.java
@@ -21,6 +21,8 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import com.cloud.utils.Pair;
@@ -40,7 +42,7 @@ public class SystemVmLoadScanner {
private final SystemVmLoadScanHandler _scanHandler;
private final ScheduledExecutorService _capacityScanScheduler;
private final GlobalLock _capacityScanLock;
-
+
public SystemVmLoadScanner(SystemVmLoadScanHandler scanHandler) {
_scanHandler = scanHandler;
_capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory(scanHandler.getScanHandlerName()));
@@ -67,8 +69,16 @@ public class SystemVmLoadScanner {
@Override
protected void runInContext() {
- try {
+ try {
+ CallContext callContext = CallContext.current();
+ assert(callContext != null);
+
+ AsyncJobExecutionContext.registerPseudoExecutionContext(
+ callContext.getCallingAccountId(), callContext.getCallingUserId());
+
reallyRun();
+
+ AsyncJobExecutionContext.unregister();
} catch (Throwable e) {
s_logger.warn("Unexpected exception " + e.getMessage(), e);
}