cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dar...@apache.org
Subject [2/8] Managed Context
Date Mon, 30 Sep 2013 23:13:50 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/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 52e20f0..1cddfa7 100644
--- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
@@ -38,6 +38,8 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.cloudstack.framework.jobs.dao.AsyncJobDao;
 import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
+import org.apache.cloudstack.managed.context.ManagedContext;
+import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
 
 import com.cloud.api.ApiDispatcher;
 import com.cloud.api.ApiGsonHelper;
@@ -371,17 +373,14 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
             _testClockTimer.schedule(_testTimerTask, 100*1000L, 60*1000L);
         }
         else {
-            TimerTask timerTask = new TimerTask() {
+            TimerTask timerTask = new ManagedContextTimerTask() {
                 @Override
-                public void run() {
-                    ServerContexts.registerSystemContext();
+                protected void runInContext() {
                     try {
                         Date currentTimestamp = new Date();
                         poll(currentTimestamp);
                     } catch (Throwable t) {
                         s_logger.warn("Catch throwable in snapshot scheduler ", t);
-                    } finally {
-                        ServerContexts.unregisterSystemContext();
                     }
                 }
             };

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/server/src/com/cloud/storage/upload/UploadListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/upload/UploadListener.java b/server/src/com/cloud/storage/upload/UploadListener.java
index 09db421..add5877 100755
--- a/server/src/com/cloud/storage/upload/UploadListener.java
+++ b/server/src/com/cloud/storage/upload/UploadListener.java
@@ -27,7 +27,6 @@ import javax.inject.Inject;
 
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.command.user.iso.ExtractIsoCmd;
 import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd;
 import org.apache.cloudstack.api.command.user.volume.ExtractVolumeCmd;
@@ -38,6 +37,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.cloudstack.jobs.JobInfo;
+import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
 
 import com.cloud.agent.Listener;
 import com.cloud.agent.api.AgentControlAnswer;
@@ -63,7 +63,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
 
 public class UploadListener implements Listener {
 
-    private static final class StatusTask extends TimerTask {
+    private static final class StatusTask extends ManagedContextTimerTask {
         private final UploadListener ul;
         private final RequestType reqType;
 
@@ -73,13 +73,13 @@ public class UploadListener implements Listener {
         }
 
         @Override
-        public void run() {
+        protected void runInContext() {
             ul.sendCommand(reqType);
 
         }
     }
 
-    private static final class TimeoutTask extends TimerTask {
+    private static final class TimeoutTask extends ManagedContextTimerTask {
         private final UploadListener ul;
 
         public TimeoutTask(UploadListener ul) {
@@ -87,7 +87,7 @@ public class UploadListener implements Listener {
         }
 
         @Override
-        public void run() {
+        protected void runInContext() {
             ul.checkProgress();
         }
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/server/src/com/cloud/storage/upload/UploadMonitorImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/upload/UploadMonitorImpl.java b/server/src/com/cloud/storage/upload/UploadMonitorImpl.java
index 12378de..4eb4900 100755
--- a/server/src/com/cloud/storage/upload/UploadMonitorImpl.java
+++ b/server/src/com/cloud/storage/upload/UploadMonitorImpl.java
@@ -34,13 +34,13 @@ import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.jobs.AsyncJobManager;
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
@@ -441,13 +441,13 @@ public class UploadMonitorImpl extends ManagerBase implements UploadMonitor
{
 
 	}
 
-    protected class StorageGarbageCollector implements Runnable {
+    protected class StorageGarbageCollector extends ManagedContextRunnable {
 
         public StorageGarbageCollector() {
         }
 
         @Override
-        public void run() {
+        protected void runInContext() {
             try {
                 GlobalLock scanLock = GlobalLock.getInternLock("uploadmonitor.storageGC");
                 try {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index 5240102..c1ce892 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -73,6 +73,7 @@ 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.AsyncJobManager;
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.storage.command.AttachCommand;
 import org.apache.cloudstack.storage.command.CommandResult;
 import org.apache.cloudstack.storage.command.DettachCommand;
@@ -488,9 +489,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         for (final StoragePoolVO pool : pools) {
             if (pool.getDataCenterId() == zoneId) {
                 s_logger.info("Schedule to preload template " + template.getId() + " into
primary storage " + pool.getId());
-                _preloadExecutor.execute(new Runnable() {
+                _preloadExecutor.execute(new ManagedContextRunnable() {
                     @Override
-                    public void run() {
+                    protected void runInContext() {
                         try {
                             reallyRun();
                         } catch (Throwable e) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java
index 396319a..078ed34 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -53,6 +53,7 @@ import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.context.ServerContexts;
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleDao;
 
 import com.cloud.api.ApiDBUtils;
@@ -1492,18 +1493,10 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager,
M
         return _userDao.remove(id);
     }
 
-    public class ResourceCountCalculateTask implements Runnable {
+    protected class AccountCleanupTask extends ManagedContextRunnable {
         @Override
-        public void run() {
-
-        }
-    }
-
-    protected class AccountCleanupTask implements Runnable {
-        @Override
-        public void run() {
+        protected void runInContext() {
             try {
-                ServerContexts.registerSystemContext();
                 GlobalLock lock = GlobalLock.getInternLock("AccountCleanup");
                 if (lock == null) {
                     s_logger.debug("Couldn't get the global lock");
@@ -1585,7 +1578,6 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager,
M
                     s_logger.error("Exception ", e);
                 } finally {
                     lock.unlock();
-                    ServerContexts.unregisterSystemContext();
                 }
             } catch (Exception e) {
                 s_logger.error("Exception ", e);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/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 3932c3b..6e55216 100644
--- a/server/src/com/cloud/vm/SystemVmLoadScanner.java
+++ b/server/src/com/cloud/vm/SystemVmLoadScanner.java
@@ -21,8 +21,7 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.context.ServerContexts;
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 
 import com.cloud.utils.Pair;
 import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -64,17 +63,14 @@ public class SystemVmLoadScanner<T> {
     }
 
     private Runnable getCapacityScanTask() {
-        return new Runnable() {
+        return new ManagedContextRunnable() {
 
             @Override
-            public void run() {
-                ServerContexts.registerSystemContext();
+            protected void runInContext() {
                 try {
                     reallyRun();
                 } catch (Throwable e) {
                     s_logger.warn("Unexpected exception " + e.getMessage(), e);
-                } finally {
-                    ServerContexts.unregisterSystemContext();
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 9b694e1..aa2d98b 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -72,6 +72,7 @@ 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.AsyncJobManager;
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.storage.to.TemplateObjectTO;
@@ -1708,13 +1709,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         }
     }
 
-    protected class ExpungeTask implements Runnable {
+    protected class ExpungeTask extends ManagedContextRunnable {
         public ExpungeTask() {
         }
 
         @Override
-        public void run() {
-            ServerContexts.registerSystemContext();
+        protected void runInContext() {
             GlobalLock scanLock = GlobalLock.getInternLock("UserVMExpunge");
             try {
                 if (scanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
@@ -1748,7 +1748,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
                 }
             } finally {
                 scanLock.releaseRef();
-                ServerContexts.unregisterSystemContext();
             }
         }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/usage/src/com/cloud/usage/UsageManagerImpl.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/UsageManagerImpl.java b/usage/src/com/cloud/usage/UsageManagerImpl.java
index 90ce4db..d2a7cc0 100644
--- a/usage/src/com/cloud/usage/UsageManagerImpl.java
+++ b/usage/src/com/cloud/usage/UsageManagerImpl.java
@@ -35,10 +35,9 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.managed.context.ManagedContext;
 import org.apache.cloudstack.usage.UsageTypes;
-
 import org.springframework.stereotype.Component;
 
 import com.cloud.alert.AlertManager;
@@ -120,6 +119,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager,
Runna
     @Inject protected UsageEventDao _usageEventDao;
     @Inject ConfigurationDao _configDao;
     @Inject private UsageVMSnapshotDao m_usageVMSnapshotDao;
+    @Inject ManagedContext _managedContext;
     
     private String m_version = null;
     private final Calendar m_jobExecTime = Calendar.getInstance();
@@ -279,7 +279,17 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager,
Runna
         return true;
     }
 
+    @Override
     public void run() {
+        _managedContext.runWithContext(new Runnable() {
+            @Override
+            public void run() {
+                runInContext();
+            }
+        });
+    }
+    
+    protected void runInContext() {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("starting usage job...");
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/usage/src/com/cloud/usage/parser/UsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/UsageParser.java b/usage/src/com/cloud/usage/parser/UsageParser.java
index 410e876..80437d5 100644
--- a/usage/src/com/cloud/usage/parser/UsageParser.java
+++ b/usage/src/com/cloud/usage/parser/UsageParser.java
@@ -18,12 +18,13 @@ package com.cloud.usage.parser;
 
 import java.util.Date;
 
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.log4j.Logger;
 
-public abstract class UsageParser implements Runnable {
+public abstract class UsageParser extends ManagedContextRunnable {
     public static final Logger s_logger = Logger.getLogger(UsageParser.class.getName());
     
-    public void run() {
+    protected void runInContext() {
         try {
             parse(null);
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8c064c6/utils/pom.xml
----------------------------------------------------------------------
diff --git a/utils/pom.xml b/utils/pom.xml
index 09c9602..3eea8fe 100644
--- a/utils/pom.xml
+++ b/utils/pom.xml
@@ -26,16 +26,33 @@
     <version>4.3.0-SNAPSHOT</version>
     <relativePath>../pom.xml</relativePath>
   </parent>
-  <dependencies>  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-framework-managed-context</artifactId>
+      <version>${project.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-context</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.aspectj</groupId>
+      <artifactId>aspectjweaver</artifactId>
+    </dependency>
+    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+    </dependency>
+    <dependency>
       <groupId>cglib</groupId>
       <artifactId>cglib-nodep</artifactId>
     </dependency>


Mime
View raw message