stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject stratos git commit: Fixing mock statistics update issue
Date Thu, 11 Dec 2014 18:52:04 GMT
Repository: stratos
Updated Branches:
  refs/heads/4.1.0-test 98fd5479b -> 500c4af3b


Fixing mock statistics update issue


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

Branch: refs/heads/4.1.0-test
Commit: 500c4af3bfc18bbd51aca93fcac097e1dafa3737
Parents: 98fd547
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Fri Dec 12 00:21:54 2014 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Fri Dec 12 00:21:54 2014 +0530

----------------------------------------------------------------------
 .../controller/iaases/mock/MockIaasService.java | 16 +++++------
 .../controller/iaases/mock/MockMember.java      |  6 ++---
 .../MockHealthStatisticsGenerator.java          | 28 +++++++++++++++-----
 .../generator/MockHealthStatisticsUpdater.java  |  6 +++--
 .../publisher/MockHealthStatisticsNotifier.java |  2 +-
 .../CloudControllerServiceComponent.java        |  4 +--
 6 files changed, 38 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/500c4af3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java
index a68bab5..ee9394a 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java
@@ -85,18 +85,16 @@ public class MockIaasService {
     }
 
     /**
-     * Start mock members if present in registry
+     * Start mock members
      */
-    public static void startMockMembersIfPresentInRegistry() {
-        ConcurrentHashMap<String, MockMember> membersMap = readFromRegistry();
+    public void startMockMembers() {
         if((membersMap != null) && (membersMap.size() > 0)) {
             // Start existing mock members
-            ExecutorService executorService = StratosThreadPool.getExecutorService("MOCK_IAAS_THREAD_EXECUTOR",
100);
             for (MockMember mockMember : membersMap.values()) {
-                executorService.submit(mockMember);
+                mockMemberExecutorService.submit(mockMember);
             }
             // Schedule health statistics updaters
-            MockHealthStatisticsGenerator.scheduleStatisticsUpdaters();
+            MockHealthStatisticsGenerator.getInstance().scheduleStatisticsUpdaters();
         }
     }
 
@@ -117,8 +115,8 @@ public class MockIaasService {
             // Persist changes
             persistInRegistry();
 
-            if(!MockHealthStatisticsGenerator.isScheduled()) {
-                MockHealthStatisticsGenerator.scheduleStatisticsUpdaters();
+            if(!MockHealthStatisticsGenerator.getInstance().isScheduled()) {
+                MockHealthStatisticsGenerator.getInstance().scheduleStatisticsUpdaters();
             }
 
             return nodeMetadata;
@@ -197,7 +195,7 @@ public class MockIaasService {
             }
 
             if(membersMap.size() == 0) {
-                MockHealthStatisticsGenerator.stopStatisticsUpdaters();
+                MockHealthStatisticsGenerator.getInstance().stopStatisticsUpdaters();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/500c4af3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java
index e22ea57..bae22da 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java
@@ -42,11 +42,9 @@ public class MockMember implements Runnable, Serializable {
 
     private static final Log log = LogFactory.getLog(MockMember.class);
     private static final ExecutorService instanceNotifierExecutorService =
-            StratosThreadPool.getExecutorService("MOCK_MEMBER_INSTANCE_NOTIFIER_EXECUTOR_SERVICE",
-                    MockConstants.MAX_MOCK_MEMBER_COUNT);
+            StratosThreadPool.getExecutorService("MOCK_MEMBER_INSTANCE_NOTIFIER_EXECUTOR_SERVICE",
20);
     private static final ScheduledExecutorService healthStatNotifierExecutorService =
-            StratosThreadPool.getScheduledExecutorService("MOCK_MEMBER_HEALTH_STAT_NOTIFIER_EXECUTOR_SERVICE",
-                    MockConstants.MAX_MOCK_MEMBER_COUNT);
+            StratosThreadPool.getScheduledExecutorService("MOCK_MEMBER_HEALTH_STAT_NOTIFIER_EXECUTOR_SERVICE",
20);
     private static final int HEALTH_STAT_INTERVAL = 15; // 15 seconds
 
     private final MockMemberContext mockMemberContext;

http://git-wip-us.apache.org/repos/asf/stratos/blob/500c4af3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
index c4fe8fd..db72225 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
@@ -35,11 +35,27 @@ public class MockHealthStatisticsGenerator {
 
     private static final Log log = LogFactory.getLog(MockHealthStatisticsGenerator.class);
 
-    private static ScheduledExecutorService scheduledExecutorService =
-            StratosThreadPool.getScheduledExecutorService("MOCK_STATISTICS_GENERATOR_EXECUTOR_SERVICE",
100);
-    private static boolean scheduled;
+    private static volatile MockHealthStatisticsGenerator instance;
+    private static final ScheduledExecutorService scheduledExecutorService =
+            StratosThreadPool.getScheduledExecutorService("MOCK_STATISTICS_GENERATOR_EXECUTOR_SERVICE",
10);
 
-    public static void scheduleStatisticsUpdaters() {
+    private boolean scheduled;
+
+    public static MockHealthStatisticsGenerator getInstance() {
+        if (instance == null) {
+            synchronized (MockHealthStatisticsGenerator.class) {
+                if (instance == null) {
+                    instance = new MockHealthStatisticsGenerator();
+                }
+            }
+        }
+        return instance;
+    }
+
+    private MockHealthStatisticsGenerator() {
+    }
+
+    public void scheduleStatisticsUpdaters() {
         if(!scheduled) {
             synchronized (MockHealthStatisticsGenerator.class) {
                 if(!scheduled) {
@@ -60,13 +76,13 @@ public class MockHealthStatisticsGenerator {
         }
     }
 
-    public static void stopStatisticsUpdaters() {
+    public void stopStatisticsUpdaters() {
         synchronized (MockHealthStatisticsGenerator.class) {
             scheduledExecutorService.shutdownNow();
         }
     }
 
-    public static boolean isScheduled() {
+    public boolean isScheduled() {
         return scheduled;
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/500c4af3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
index 8d61887..fd697a2 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
@@ -29,7 +29,7 @@ import org.apache.stratos.cloud.controller.iaases.mock.statistics.MockHealthStat
  */
 public class MockHealthStatisticsUpdater implements Runnable {
 
-    private static final Log log = LogFactory.getLog(MockHealthStatisticsGenerator.class);
+    private static final Log log = LogFactory.getLog(MockHealthStatisticsUpdater.class);
 
     private MockHealthStatisticsPattern statisticsPattern;
 
@@ -47,9 +47,11 @@ public class MockHealthStatisticsUpdater implements Runnable {
                     statisticsPattern.getFactor(), nextSample);
 
             if (log.isInfoEnabled()) {
-                log.info(String.format("Mock statistics updated: [cartridge-type] %s [factor]
% [value] %d",
+                log.info(String.format("Mock statistics updated: [cartridge-type] %s [factor]
%s [value] %d",
                         statisticsPattern.getCartridgeType(), statisticsPattern.getFactor().toString(),
nextSample));
             }
+        } catch (Exception e) {
+            log.error("Could not update mock statistics", e);
         } finally {
             MockHealthStatistics.getInstance().releaseWriteLock(statisticsPattern.getCartridgeType());
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/500c4af3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
index eb61eaa..2fd33c4 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
@@ -55,7 +55,7 @@ public class MockHealthStatisticsNotifier implements Runnable {
                     double loadAvereage = MockHealthStatistics.getInstance().getStatistics(
                             mockMemberContext.getServiceName(), MockAutoscalingFactor.LoadAverage);
 
-                    if (log.isDebugEnabled()) {
+                     if (log.isDebugEnabled()) {
                         log.debug(String.format("Publishing memory consumption: [member-id]
%s [value] %f",
                                 mockMemberContext.getMemberId(), memoryConsumption));
                     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/500c4af3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java
index 5f7c9ff..820c979 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java
@@ -109,8 +109,8 @@ public class CloudControllerServiceComponent {
             }
 
             if(MockIaasConfig.getInstance().isEnabled()) {
-                // Start mock members if present in registry
-                MockIaasService.startMockMembersIfPresentInRegistry();
+                // Start mock members if they were in running state earlier
+                MockIaasService.getInstance().startMockMembers();
             }
 		} catch (Throwable e) {
 			log.error("******* Cloud Controller Service bundle is failed to activate ****", e);


Mime
View raw message