cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject git commit: updated refs/heads/vmsync to 688b047
Date Tue, 04 Jun 2013 00:08:00 GMT
Updated Branches:
  refs/heads/vmsync b8261b870 -> 688b047c2


Made it all work on startup


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

Branch: refs/heads/vmsync
Commit: 688b047c2a666388c0627f62a8aab212bdd1d9a0
Parents: b8261b8
Author: Alex Huang <alex.huang@gmail.com>
Authored: Mon Jun 3 17:10:28 2013 -0700
Committer: Alex Huang <alex.huang@gmail.com>
Committed: Mon Jun 3 17:10:28 2013 -0700

----------------------------------------------------------------------
 .../exception/ConcurrentOperationException.java    |    4 ++
 .../org/apache/cloudstack/context/CallContext.java |    2 +-
 client/tomcatconf/applicationContext.xml.in        |    1 -
 .../apache/cloudstack/framework/jobs/AsyncJob.java |    3 +
 .../src/com/cloud/async/AsyncJobManagerImpl.java   |    1 -
 .../src/com/cloud/servlet/CloudStartupServlet.java |   18 +++++++-
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |   34 ++++++++------
 server/src/com/cloud/vm/VmWorkConstants.java       |   28 ------------
 server/src/com/cloud/vm/VmWorkJobDispatcher.java   |    9 +++-
 .../com/cloud/vm/VmWorkTestApiJobDispatcher.java   |    6 +-
 10 files changed, 52 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/api/src/com/cloud/exception/ConcurrentOperationException.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/exception/ConcurrentOperationException.java b/api/src/com/cloud/exception/ConcurrentOperationException.java
index cfe6ba3..71d6302 100644
--- a/api/src/com/cloud/exception/ConcurrentOperationException.java
+++ b/api/src/com/cloud/exception/ConcurrentOperationException.java
@@ -25,4 +25,8 @@ public class ConcurrentOperationException extends CloudException {
     public ConcurrentOperationException(String msg) {
         super(msg);
     }
+
+    public ConcurrentOperationException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/api/src/org/apache/cloudstack/context/CallContext.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/context/CallContext.java b/api/src/org/apache/cloudstack/context/CallContext.java
index 11336f7..d0eaa25 100644
--- a/api/src/org/apache/cloudstack/context/CallContext.java
+++ b/api/src/org/apache/cloudstack/context/CallContext.java
@@ -29,7 +29,7 @@ import com.cloud.user.User;
 import com.cloud.utils.exception.CloudRuntimeException;
 
 /**
- * Calling Context records information about who is making this call.  This
+ * CallContext records information about the environment the call is made.  This
  * class must be always be available in all CloudStack code.  Every thread
  * entry point must set the context and remove it when the thread finishes.
  */

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/client/tomcatconf/applicationContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in
index 9cece35..bc443bc 100644
--- a/client/tomcatconf/applicationContext.xml.in
+++ b/client/tomcatconf/applicationContext.xml.in
@@ -768,7 +768,6 @@
   <bean id="templateInstallStrategyImpl" class="org.apache.cloudstack.storage.volume.TemplateInstallStrategyImpl"
/>
   <bean id="unknown" class="org.apache.cloudstack.storage.image.format.Unknown" />
   <bean id="usageEventUtils" class="com.cloud.event.UsageEventUtils" />
-  <bean id="userContextInitializer" class="com.cloud.user.UserContextInitializer" />
   <bean id="VHD" class="org.apache.cloudstack.storage.image.format.VHD" />
   <bean id="vMEntityManagerImpl" class="org.apache.cloudstack.engine.vm.VMEntityManagerImpl"
/>
   <bean id="virtualMachineEntityImpl" class="org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl"
/>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java
----------------------------------------------------------------------
diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java
index 35f4f3e..7a898e8 100644
--- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java
+++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java
@@ -69,6 +69,7 @@ public interface AsyncJob extends Job {
 
     @Override
     Long getInitMsid();
+
     void setInitMsid(Long msid);
 
     @Override
@@ -76,6 +77,7 @@ public interface AsyncJob extends Job {
     
     @Override
     Long getCompleteMsid();
+
     void setCompleteMsid(Long msid);
 
     @Override
@@ -98,5 +100,6 @@ public interface AsyncJob extends Job {
     String getShortUuid();
 
     SyncQueueItem getSyncSource();
+
     void setSyncSource(SyncQueueItem item);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/server/src/com/cloud/async/AsyncJobManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/async/AsyncJobManagerImpl.java b/server/src/com/cloud/async/AsyncJobManagerImpl.java
index 8251f69..bedeb43 100644
--- a/server/src/com/cloud/async/AsyncJobManagerImpl.java
+++ b/server/src/com/cloud/async/AsyncJobManagerImpl.java
@@ -199,7 +199,6 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager,
             txt.commit();
             return job.getId();
         } catch(Exception e) {
-            txt.rollback();
             String errMsg = "Unable to schedule async job for command " + job.getCmd() +
", unexpected exception.";
             s_logger.warn(errMsg, e);
             throw new CloudRuntimeException(errMsg);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/server/src/com/cloud/servlet/CloudStartupServlet.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/servlet/CloudStartupServlet.java b/server/src/com/cloud/servlet/CloudStartupServlet.java
index 2cabe15..d8ddc8a 100755
--- a/server/src/com/cloud/servlet/CloudStartupServlet.java
+++ b/server/src/com/cloud/servlet/CloudStartupServlet.java
@@ -26,12 +26,18 @@ import javax.servlet.http.HttpServlet;
 import org.apache.log4j.Logger;
 import org.springframework.web.context.support.SpringBeanAutowiringSupport;
 
+import org.apache.cloudstack.context.CallContext;
+
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.UserVO;
 import com.cloud.utils.LogUtils;
 import com.cloud.utils.SerialVersionUID;
 import com.cloud.utils.component.ComponentContext;
 
 public class CloudStartupServlet extends HttpServlet {
-    public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class.getName());
+    public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class);
     static final long serialVersionUID = SerialVersionUID.CloudStartupServlet;
     
     Timer _timer = new Timer();
@@ -39,12 +45,20 @@ public class CloudStartupServlet extends HttpServlet {
     @Override
     public void init(ServletConfig config) throws ServletException {
     	LogUtils.initLog4j("log4j-cloud.xml");
-    	SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
      	
+    	SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
     	
     	// wait when condition is ready for initialization
     	_timer.scheduleAtFixedRate(new TimerTask() {
 			@Override
 			public void run() {
+                AccountVO account = new AccountVO(Account.ACCOUNT_ID_SYSTEM);
+                UserVO user = new UserVO(User.UID_SYSTEM);
+                try {
+                    CallContext.register(user, account, null);
+                } catch (Exception e) {
+                    s_logger.error("Unable to initialize call context", e);
+                    System.exit(1);
+                }
 				if(ComponentContext.getApplicationContext() != null) {
 					_timer.cancel();
 					ComponentContext.initComponentsLifeCycle();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 2d744c8..db6ae65 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -35,6 +35,7 @@ import javax.naming.ConfigurationException;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
@@ -720,8 +721,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     
     @Override
     @DB
-    public void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object>
params, User caller, Account account, DeploymentPlan planToDeploy)
+    public void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object>
params, User callingUser, Account callingAccount, DeploymentPlan planToDeploy)
         throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException
{
+        CallContext context = CallContext.current();
+        callingUser = context.getCallingUser();
+        callingAccount = context.getCallingAccount();
+
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
     	
     	VmWorkJobVO workJob = null;
@@ -732,7 +737,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         	_vmDao.lockRow(vm.getId(), true);
         	
         	List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-        		VirtualMachine.Type.Instance, vm.getId(), VmWorkConstants.VM_WORK_START);
+                    VirtualMachine.Type.Instance, vm.getId(), VmWorkJobDispatcher.Start);
         	
         	if(pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
         		assert(pendingWorkJobs.size() == 1);
@@ -740,32 +745,31 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         	} else {
         		workJob = new VmWorkJobVO();
         	
-        		workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
-        		workJob.setCmd(VmWorkConstants.VM_WORK_START);
+                workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                workJob.setCmd(VmWorkJobDispatcher.Start);
         		
-        		workJob.setAccountId(account.getId());
-        		workJob.setUserId(caller.getId());
+                workJob.setAccountId(callingAccount.getId());
+        		workJob.setUserId(callingUser.getId());
         		workJob.setStep(VmWorkJobVO.Step.Starting);
         		workJob.setVmType(vm.getType());
         		workJob.setVmInstanceId(vm.getId());
 
         		// save work context info (there are some duplications)
         		VmWorkStart workInfo = new VmWorkStart();
-        		workInfo.setAccountId(account.getId());
-        		workInfo.setUserId(caller.getId());
+                workInfo.setAccountId(callingAccount.getId());
+        		workInfo.setUserId(callingUser.getId());
         		workInfo.setVmId(vm.getId());
         		workInfo.setPlan(planToDeploy);
         		workInfo.setParams(params);
         		workJob.setCmdInfo(ApiSerializerHelper.toSerializedString(workInfo));
         		
-        		_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
+                _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
         	}
     	
         	txn.commit();
     	} catch(Throwable e) {
     		s_logger.error("Unexpected exception", e);
-    		txn.rollback();
-    		throw new ConcurrentOperationException("Unhandled exception, converted to ConcurrentOperationException");
+            throw new ConcurrentOperationException("Unhandled exception, converted to ConcurrentOperationException",
e);
     	}
 
     	final long jobId = workJob.getId();
@@ -1186,7 +1190,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         	_vmDao.lockRow(vm.getId(), true);
         	
         	List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-        		VirtualMachine.Type.Instance, vm.getId(), VmWorkConstants.VM_WORK_STOP);
+                    VirtualMachine.Type.Instance, vm.getId(), VmWorkJobDispatcher.Start);
         	
         	if(pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
         		assert(pendingWorkJobs.size() == 1);
@@ -1194,8 +1198,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         	} else {
         		workJob = new VmWorkJobVO();
         	
-        		workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
-        		workJob.setCmd(VmWorkConstants.VM_WORK_STOP);
+                workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                workJob.setCmd(VmWorkJobDispatcher.Stop);
         		
         		workJob.setAccountId(account.getId());
         		workJob.setUserId(user.getId());
@@ -1211,7 +1215,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         		workInfo.setForceStop(forced);
         		workJob.setCmdInfo(ApiSerializerHelper.toSerializedString(workInfo));
         		
-        		_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
+                _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
         	}
     	
         	txn.commit();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/server/src/com/cloud/vm/VmWorkConstants.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VmWorkConstants.java b/server/src/com/cloud/vm/VmWorkConstants.java
deleted file mode 100644
index eb6ddc1..0000000
--- a/server/src/com/cloud/vm/VmWorkConstants.java
+++ /dev/null
@@ -1,28 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.vm;
-
-public interface VmWorkConstants {
-	// VmWork queue name
-	public static final String VM_WORK_QUEUE = "VmWorkJobQueue";
-	public static final String VM_WORK_JOB_DISPATCHER = "VmWorkJobDispatcher";
-	public static final String VM_WORK_JOB_WAKEUP_DISPATCHER = "VmWorkJobWakeupDispatcher";
-	
-	// work job commands
-	public static final String VM_WORK_START = "vmWorkStart";
-	public static final String VM_WORK_STOP = "vmWorkStop";
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/server/src/com/cloud/vm/VmWorkJobDispatcher.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VmWorkJobDispatcher.java b/server/src/com/cloud/vm/VmWorkJobDispatcher.java
index edc701d..c37e65d 100644
--- a/server/src/com/cloud/vm/VmWorkJobDispatcher.java
+++ b/server/src/com/cloud/vm/VmWorkJobDispatcher.java
@@ -35,6 +35,12 @@ import com.cloud.vm.dao.VMInstanceDao;
 public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatcher {
     private static final Logger s_logger = Logger.getLogger(VmWorkJobDispatcher.class);
 
+    public static final String VM_WORK_QUEUE = "VmWorkJobQueue";
+    public static final String VM_WORK_JOB_DISPATCHER = "VmWorkJobDispatcher";
+    public static final String VM_WORK_JOB_WAKEUP_DISPATCHER = "VmWorkJobWakeupDispatcher";
+    public final static String Start = "start";
+    public final static String Stop = "stop";
+
 	@Inject private VirtualMachineManager _vmMgr;
 	@Inject private AsyncJobManager _asyncJobMgr;
     @Inject private AccountDao _accountDao;
@@ -42,9 +48,6 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch
     @Inject
     private EntityManager _entityMgr;
     
-    public final static String Start = "start";
-    public final static String Stop = "stop";
-
 	@Override
     public void runJob(AsyncJob job) {
         try {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/688b047c/server/test/com/cloud/vm/VmWorkTestApiJobDispatcher.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/VmWorkTestApiJobDispatcher.java b/server/test/com/cloud/vm/VmWorkTestApiJobDispatcher.java
index 258f88d..064fab7 100644
--- a/server/test/com/cloud/vm/VmWorkTestApiJobDispatcher.java
+++ b/server/test/com/cloud/vm/VmWorkTestApiJobDispatcher.java
@@ -57,7 +57,7 @@ public class VmWorkTestApiJobDispatcher extends AdapterBase implements AsyncJobD
 		VmWorkJobVO workJob = new VmWorkJobVO();
     	
 		workJob.setDispatcher("TestWorkJobDispatcher");
-		workJob.setCmd(VmWorkConstants.VM_WORK_START);
+        workJob.setCmd(VmWorkJobDispatcher.Start);
 		
 		workJob.setAccountId(1L);
 		workJob.setUserId(1L);
@@ -74,10 +74,10 @@ public class VmWorkTestApiJobDispatcher extends AdapterBase implements
AsyncJobD
 		workInfo.setParams(null);
 		workJob.setCmdInfo(ApiSerializerHelper.toSerializedString(workInfo));
 		
-		_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, 1L);
+        _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, 1L);
 		
 		_jobMgr.joinJob(job.getId(), workJob.getId(), "processVmStartWakeup",
-				VmWorkConstants.VM_WORK_JOB_WAKEUP_DISPATCHER,
+                VmWorkJobDispatcher.VM_WORK_JOB_WAKEUP_DISPATCHER,
 				new String[] {},
 				3000, 120000);
 		AsyncJobExecutionContext.getCurrentExecutionContext().resetSyncSource();


Mime
View raw message