cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject git commit: Fix singleton initialization in ApiServer/ApiDispatcher to make it work under Spring bootstraped environment
Date Mon, 14 Jan 2013 21:57:59 GMT
Updated Branches:
  refs/heads/javelin 64c947a9f -> 6dfbcee63


Fix singleton initialization in ApiServer/ApiDispatcher to make it work under Spring bootstraped
environment


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

Branch: refs/heads/javelin
Commit: 6dfbcee63da5ae9321677a7440c426a023db5f0d
Parents: 64c947a
Author: Kelven Yang <kelveny@gmail.com>
Authored: Mon Jan 14 13:57:30 2013 -0800
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Mon Jan 14 13:57:30 2013 -0800

----------------------------------------------------------------------
 client/tomcatconf/applicationContext.xml.in        |    1 +
 server/src/com/cloud/api/ApiDispatcher.java        |   14 ++++++---
 server/src/com/cloud/api/ApiServer.java            |   20 +++++---------
 server/src/com/cloud/api/ApiServlet.java           |    6 +++-
 .../src/com/cloud/projects/ProjectManagerImpl.java |    4 ++-
 .../src/com/cloud/vm/dao/DomainRouterDaoImpl.java  |    1 +
 6 files changed, 26 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6dfbcee6/client/tomcatconf/applicationContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in
index 2a367f6..186a168 100644
--- a/client/tomcatconf/applicationContext.xml.in
+++ b/client/tomcatconf/applicationContext.xml.in
@@ -50,6 +50,7 @@
   <!--
     RPC/Async/EventBus
   -->
+
   <bean id="onwireRegistry" class="org.apache.cloudstack.framework.serializer.OnwireClassRegistry"
     init-method="scan" >
     <property name="packages">

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6dfbcee6/server/src/com/cloud/api/ApiDispatcher.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java
index 67aa454..0df37f1 100755
--- a/server/src/com/cloud/api/ApiDispatcher.java
+++ b/server/src/com/cloud/api/ApiDispatcher.java
@@ -29,6 +29,7 @@ import java.util.Map;
 import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 
+import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 
 import org.apache.cloudstack.acl.ControlledEntity;
@@ -65,8 +66,8 @@ import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.UserContext;
 import com.cloud.utils.DateUtil;
-import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.ReflectUtil;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.exception.CSExceptionErrorCode;
 import com.cloud.utils.exception.CloudRuntimeException;
 
@@ -85,9 +86,12 @@ public class ApiDispatcher {
         return s_instance;
     }
 
-    protected ApiDispatcher() {
-        super();
-        s_instance = this;
+    public ApiDispatcher() {
+    }
+    
+    @PostConstruct
+    void init() {
+    	s_instance = this;
     }
 
     public void setCreateSnapshotQueueSizeLimit(Long snapshotLimit) {
@@ -475,7 +479,7 @@ public class ApiDispatcher {
         }
 
         //check access on the entities.
-        s_instance.doAccessChecks(cmd, entitiesToAccess);
+        getInstance().doAccessChecks(cmd, entitiesToAccess);
 
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6dfbcee6/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 e5b57e5..8a2c675 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -45,6 +45,7 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
+import javax.annotation.PostConstruct;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 import javax.inject.Inject;
@@ -131,7 +132,6 @@ import com.cloud.utils.Pair;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.ReflectUtil;
 import com.cloud.utils.StringUtils;
-import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.PluggableService;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.SearchCriteria;
@@ -165,22 +165,16 @@ public class ApiServer implements HttpRequestHandler {
 
     private static ExecutorService _executor = new ThreadPoolExecutor(10, 150, 60, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("ApiServer"));
 
-    protected ApiServer() {
-        super();
+    public ApiServer() {
     }
-
-    public static void initApiServer() {
-        if (s_instance == null) {
-            s_instance = new ApiServer();
-            s_instance = ComponentContext.inject(s_instance);
-            s_instance.init();
-        }
+    
+    @PostConstruct
+    void initComponent() {
+    	s_instance = this;
+    	init();
     }
 
     public static ApiServer getInstance() {
-        if (s_instance == null) {
-            ApiServer.initApiServer();
-        }
         return s_instance;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6dfbcee6/server/src/com/cloud/api/ApiServlet.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java
index 1a8a04e..e535030 100755
--- a/server/src/com/cloud/api/ApiServlet.java
+++ b/server/src/com/cloud/api/ApiServlet.java
@@ -32,25 +32,29 @@ import javax.servlet.http.HttpSession;
 import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.exception.CloudAuthenticationException;
 import com.cloud.user.Account;
 import com.cloud.user.AccountService;
 import com.cloud.user.UserContext;
 import com.cloud.utils.StringUtils;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.exception.CloudRuntimeException;
 
+@Component("apiServlet")
 @SuppressWarnings("serial")
 public class ApiServlet extends HttpServlet {
     public static final Logger s_logger = Logger.getLogger(ApiServlet.class.getName());
     private static final Logger s_accessLogger = Logger.getLogger("apiserver." + ApiServer.class.getName());
 
     ApiServer _apiServer;
-    @Inject AccountService _accountMgr;
+    AccountService _accountMgr;
 
     public ApiServlet() {
         super();
         _apiServer = ApiServer.getInstance();
+        _accountMgr = ComponentContext.getComponent(AccountService.class);
         if (_apiServer == null) {
             throw new CloudRuntimeException("ApiServer not initialized");
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6dfbcee6/server/src/com/cloud/projects/ProjectManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/projects/ProjectManagerImpl.java b/server/src/com/cloud/projects/ProjectManagerImpl.java
index 00b7716..ebe6d0c 100755
--- a/server/src/com/cloud/projects/ProjectManagerImpl.java
+++ b/server/src/com/cloud/projects/ProjectManagerImpl.java
@@ -131,7 +131,9 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
 
         Map<String, String> configs = _configDao.getConfiguration(params);
         _invitationRequired = Boolean.valueOf(configs.get(Config.ProjectInviteRequired.key()));
-        _invitationTimeOut = Long.valueOf(configs.get(Config.ProjectInvitationExpirationTime.key()))*1000;
+        
+        String value = configs.get(Config.ProjectInvitationExpirationTime.key());
+        _invitationTimeOut = Long.valueOf(value != null ? value : "86400")*1000;
         _allowUserToCreateProject = Boolean.valueOf(configs.get(Config.AllowUserToCreateProject.key()));
 
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6dfbcee6/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java
index 40c97e1..cfe9f43 100755
--- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java
+++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java
@@ -49,6 +49,7 @@ import com.cloud.vm.VirtualMachine.State;
 
 @Component
 @Local(value = { DomainRouterDao.class })
+@DB
 public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> implements
DomainRouterDao {
 
     protected SearchBuilder<DomainRouterVO> AllFieldsSearch;


Mime
View raw message