Updated Branches:
  refs/heads/4.3 3f526fb05 -> d931718ab

CLOUDSTACK-669: put system vm work under new vmsync model


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

Branch: refs/heads/4.3
Commit: d931718ab2d5149f7bbe61e137667d53ff832ca9
Parents: 3f526fb
Author: Kelven Yang <[email protected]>
Authored: Fri Dec 6 15:36:54 2013 -0800
Committer: Kelven Yang <[email protected]>
Committed: Fri Dec 6 15:48:10 2013 -0800

----------------------------------------------------------------------
 ...spring-engine-orchestration-core-context.xml | 14 +++++++--
 .../com/cloud/vm/VirtualMachineManagerImpl.java | 30 ++++++++++----------
 .../spring-server-core-managers-context.xml     |  4 ++-
 .../storage/snapshot/SnapshotSchedulerImpl.java | 12 ++++++--
 .../src/com/cloud/vm/SystemVmLoadScanner.java   | 14 +++++++--
 5 files changed, 52 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d931718a/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
----------------------------------------------------------------------
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 880002c..0c76f00 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";
                       >
 
     <bean id="clusterBasedAgentLoadBalancerPlanner"
@@ -68,5 +73,10 @@
     <bean id="virtualMachineEntityImpl" 
class="org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl" 
/>
     
     <bean id="virtualMachinePowerStateSyncImpl" 
class="com.cloud.vm.VirtualMachinePowerStateSyncImpl" />
+    <bean id= "vmWorkJobDispatcher" class="com.cloud.vm.VmWorkJobDispatcher">
+        <property name="name">
+            <util:constant 
static-field="com.cloud.vm.VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER"/>
+        </property>
+    </bean>
     
 </beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d931718a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java 
b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 164457a..841721d 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<VirtualMachine> startVmThroughJobQueue(final String vmUuid, 
        final Map<VirtualMachineProfile.Param, Object> 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<VirtualMachine> 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()));
                }
        });
        

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d931718a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
----------------------------------------------------------------------
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 2a080f9..bcb218a 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 @@
 
     <bean id="snapshotManagerImpl" 
class="com.cloud.storage.snapshot.SnapshotManagerImpl" />
 
-    <bean id="snapshotSchedulerImpl" 
class="com.cloud.storage.snapshot.SnapshotSchedulerImpl" />
+    <bean id="snapshotSchedulerImpl" 
class="com.cloud.storage.snapshot.SnapshotSchedulerImpl" >
+        <property name="asyncJobDispatcher" ref="ApiAsyncJobDispatcher" />
+    </bean>
     <bean id="storageNetworkManagerImpl" 
class="com.cloud.network.StorageNetworkManagerImpl" />
     <bean id="taggedResourceManagerImpl" 
class="com.cloud.tags.TaggedResourceManagerImpl" />
     <bean id="resourceMetaDataManagerImpl" 
class="com.cloud.metadata.ResourceMetaDataManagerImpl" />

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d931718a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java 
b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
index a113558..1f1c8aa 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;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d931718a/server/src/com/cloud/vm/SystemVmLoadScanner.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/SystemVmLoadScanner.java 
b/server/src/com/cloud/vm/SystemVmLoadScanner.java
index 6e55216..1141664 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<T> {
     private final SystemVmLoadScanHandler<T> _scanHandler;
     private final ScheduledExecutorService _capacityScanScheduler;
     private final GlobalLock _capacityScanLock;
-
+    
     public SystemVmLoadScanner(SystemVmLoadScanHandler<T> scanHandler) {
         _scanHandler = scanHandler;
         _capacityScanScheduler = Executors.newScheduledThreadPool(1, new 
NamedThreadFactory(scanHandler.getScanHandlerName()));
@@ -67,8 +69,16 @@ public class SystemVmLoadScanner<T> {
 
             @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);
                 }

Reply via email to